Pro OpenGL ES for iOS

(singke) #1

CHAPTER 8: Putting It All Together (^257)
orientation=gluGetOrientation(); //1
vpLoc=[m_SolarSystem getEyeposition]; //2
objectLoc=[m_SolarSystem getTargetLocation]; //3
offset.x=(objectLoc.x-vpLoc.x);
offset.y=(objectLoc.y-vpLoc.y);
offset.z=(objectLoc.z-vpLoc.z);
offsetv.z=GLKVector3Distance(objectLoc,vpLoc); //4
dx=location.x-prevLocation.x; //5
dy=location.y-prevLocation.y;
float multiplier;
multiplier=frame.size.width/reference;
glMatrixMode(GL_MODELVIEW);
float c,s;
float rad=scalemultiplierdy/reference;
s=sinf(rad.5); //6
c=cosf(rad
.5);
tempQ=GLKQuaternionMake(s,0.0,0.0,c); //Rotate around the X-axis.
orientation=GLKQuaternionMultiply(tempQ,orientation);
rad=scalemultiplierdx/reference;
s=sinf(rad.5);
c=cosf(rad
.5);
tempQ=GLKQuaternionMake(0.0,s,0.0,c); //Rotate around the Y-axis.
orientation=GLKQuaternionMultiply(tempQ,orientation);
matrix3=GLKMatrix3MakeWithQuaternion(orientation);
matrix3=GLKMatrix3Transpose(matrix3); //7
offsetv=GLKMatrix3MultiplyVector3(matrix3, offsetv);
vpLoc.x=objectLoc.x+offsetv.x; //8
vpLoc.y=objectLoc.y+offsetv.y;
vpLoc.z=objectLoc.z+offsetv.z;
[m_SolarSystem setEyeposition:vpLoc];
[m_SolarSystem lookAtTarget]; //9
}
So, what’s going on here?

Free download pdf