- (void)drawRect:(NSRect)rect { //In combination draw this is where the drawing happens.
[super drawRect:rect];
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport( 0,0,[self frame].size.width,[self frame].size.height );
glMatrixMode(GL_MODELVIEW);
[self draw];
glFlush();
}
- (void)draw {
glTranslatef(horiVec, 0, vertVec);
[newTerrain updateTerrain];
}
It worked fine I could move my character around with the arrow keys (vertVec is kind of a misnomer, it is a 3D game and the person is moving forward not actually up, also quick side note: the game is being updated with a NSTimer every 0.017 secs). Ok, but now I need to add mouse rotation so I changed the code to this:
- (void)drawRect:(NSRect)rect { //In combination draw this is where the drawing happens.
[super drawRect:rect];
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport( 0,0,[self frame].size.width,[self frame].size.height );
glMatrixMode(GL_MODELVIEW);
[self draw];
glFlush();
}
- (void)draw {
glTranslatef(horiVec, 0, vertVec);
eyex += horiVec;
eyez += vertVec;
gluLookAt(eyex, 0, eyez, rotX, rotY, 0, 1, 1, 0);
[newTerrain updateTerrain];
}
To make some notes: horiVec and vertVec alternate between 0.1, 0.0, and -0.1, for movement. To get rotX and rotY I use the following method which is invoked through an NSTimer every 0.017 sec:
-(void)getMouse:(id)sender {
NSPoint tempMouseLoc;
tempMouseLoc = [NSEvent mouseLocation]; //get current mouse position
rotX = mouseLoc.y - tempMouseLoc.y;
rotY = mouseLoc.x - tempMouseLoc.x;
mouseLoc = tempMouseLoc;
}
Basically, rotX and rotY are the vector components of the delta of the mouse. I am having a little problem understanding gluLookAt (and that might be part of the problem) but basically what I am aiming for is a way to handle the camera for an FPS style game. But nothing shows up on the screen with the updated draw method. Any ideas why? If you need any more code just ask. Thanks