256 CHAPTER 8: Putting It All Together^
Now you can make some tweaks to Planet.mm. Since we’re using the new vector/point
objects, the instance variable, m_Pos, will be converted from a simple array to a
GLKVector3 type. Listing 8-7 shows those changes, and remember to change its
definition in the header as well and the initialization line in the initialization routine.
Listing 8-7. Some small helper functions for Planet.mm
-(GLKVector3)getPosition
{
return m_Pos;
}
-(void)setPosition:(GLKVector3)position
{
m_Pos=position;
}
-(void)getPositionX:(GLfloat *)x Y:(GLfloat *)y Z:(GLfloat *)z
{
*x=m_Pos.x;
*y=m_Pos.y;
*z=m_Pos.z;
}
-(void)setPositionX:(GLfloat)x Y:(GLfloat)y Z:(GLfloat)z
{
m_Pos.x=x;
m_Pos.y=y;
m_Pos.z=z;
}
Next is the heart of this hover stuff. Replace the stub for setHoverPostion() in the view
controller with the code from Listing 8-8 and add miniglu.h.
Listing 8-8. Adding the view’s rotation code
-(void)setHoverPosition:(unsigned)nFlags location:(CGPoint)location
prevLocation:(CGPoint)prevLocation
{
int dx;
int dy;
GLKQuaternion orientation,tempQ;
GLKVector3 offset,objectLoc,vpLoc;
GLKVector3 offsetv=GLKVector3Make(0.0,0.0,0.0);
float reference=300;
float scale=4.0;
GLKMatrix3 matrix3;
CGRect frame = [[UIScreen mainScreen] bounds];
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();