Pro OpenGL ES for iOS

(singke) #1

254 CHAPTER 8: Putting It All Together^


gluLookAt(m_Eyeposition.x,m_Eyeposition.y,m_Eyeposition.z,
targetLocation.x,targetLocation.y,targetLocation.z,
0.0,1.0,0.0);
}

-(GLKVector3)getEyeposition
{
return m_Eyeposition;
}

-(void)setEyeposition:(GLKVector3)loc
{
m_Eyeposition=loc;
}
In normal OpenGL, I’ve mentioned the existence of a utility library called GLUT.
Unfortunately, there is no complete GLUT library for iOS as of this writing, so I’ve had to
create my own where I stuff most any basic 3D utility method. With that in mind, create
a new object called miniglu.mm (the ‘‘mm’’ suffix lets the Objective C compiler
understand straight C code mixed with ObjC), add the the contents of Listing 8-6, and
add static GLKQuaternion m_Quaternion to the top of the file. And make sure to add
miniglu.h where needed.
This is kept as generic-C because GLUT is meant to be as portable as possible.
Listing 8-6. Two routines for miniGLU.mm

void gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez,
GLfloat centerx, GLfloat centery, GLfloat centerz,
GLfloat upx, GLfloat upy, GLfloat upz)
{
GLKVector3 up; //1
GLKVector3 from,to;
GLKVector3 lookat;
GLKVector3 axis;
float angle;

lookat.x=centerx; //2
lookat.y=centery;
lookat.z=centerz;

from.x=eyex;
from.y=eyey;
from.z=eyez;

to.x=lookat.x;
to.y=lookat.y;
to.z=lookat.z;

up.x=upx;
up.y=upy;
up.z=upz;
Free download pdf