I am using OpenGL ES 2.0 to display a 3-dimensional cube which I display in a certain perspective with rotations around the x,y,z axes.
@interface OpenGLView : UIView
OpenGLView *openGLRotate = [[OpenGLView alloc] initWithFrame:screenBounds];
[openGLRotate setupDisplayLink:NO Face:face Direction:direct];
- (void)setupDisplayLink:(BOOL)bFlag Face:(CubeFace)f Direction:(CubeDirection)d
{
CADisplayLink* displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(renderRotate:)];
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
}
I would like to rotate the cube around an axis perpendicular to the face, which is NOT the x, y, or z axis.
Seeing as the default perspective of the cube has been rotated around the x,y,z axes, rotating around an axes relative to a specific face involves varying the x,y,z axes values at the same time to achieve the effect I am looking for.
// code in renderRotate
//[modelView rotateBy:CC3VectorMake(20, -45, -20)]; // default perspective
[modelView rotateBy:CC3VectorMake(20 + x, -45 + y, -20 + z)];
I’ve read about vectors and matrices and quaternions and euler angles and I feel more confused instead of less.
I’m not exactly sure how to determine the x,y,z values for the rotation. Any guidance on how to calculate these values would be appreciated, or is there another approach I should take?
It occurred to me I was trying to do two separate and different things in a single statement.
I am trying to rotate the cube to display in a certain perspective, and rotate the cube for a dynamic animation.
Those are actually unrelated rotations and need to be done separately.
First I apply the rotation to display the cube in the desired perspective;
Then I apply the necessary rotation for the animation:
I believe (and I may be wrong about the specifics here) that the actual rotations are applied in the reverse order (LIFO) so the animation rotation is applied in the standard xyz coordinate system first, followed by the rotation to display in the desired perspective.
Works perfectly.