This is my second question about 3D cubes in iphone using CALayer, Core Animation framework, written in Objective-c. For my first question, please visit the 3D Cube Problem! Part 1
I am using Brad Larson's code to rotate my 3D cube from this link.
http://www.sunsetlakesoftware.com/2008/10/22/3-d-rotation-without-trackball
The problem is that my cube rotates along the x axis along the pink line shown in the figure.

But I want to rotate it around the x axis along the black line shown in the figure.
Now in my code, I don't have any pink line or black line drawn in my view, so someone can help me with this.
If this helps here - this is the code to rotate my cube in the touchesMoved: method touchesMoved:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint location = [[touches anyObject] locationInView:self]; CATransform3D currentTransform = currentLayer.sublayerTransform; CGFloat displacementInX = location.x - previousLocation.x; CGFloat displacementInY = previousLocation.y - location.y; CGFloat totalRotation = sqrt(displacementInX * displacementInX + displacementInY * displacementInY); CGFloat x = (displacementInX/totalRotation) * currentTransform.m12 + (displacementInY/totalRotation) * currentTransform.m11; CATransform3D rotationalTransform = CATransform3DRotate(currentTransform, totalRotation * M_PI / 180.0, x, y, 0); currentLayer.sublayerTransform = rotationalTransform; }
previousLocation is a CGPoint initialized in the touchesBegan: method, and currentLayer is CALayer , where I created this cube.
Thanks for your help.
PS. If you want to know how I created this cube let me know
Robin source share