Jump to content
  • Advertisement
Sign in to follow this  
thyrgle

Adding gluLookAt causes everything to disapear.

This topic is 2591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I was using the two following methods to draw:

- (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

Share this post


Link to post
Share on other sites
Advertisement
gluLookAt is the camera matrix. So you have to place (glTranslate) all your objects where they belong in the 3D world first, the apply the matrix that actually draw it relative to FPS. In GL this would be:

LookAt() <------------this happens 2nd
Translate() <---------this happens 1st

This is because it is a stack.


eyex += horiVec;
eyez += vertVec;[/quote]
That looks very suspicious as you use it to move your model into the 3D world, and you use it to describe where your camera is.

Share this post


Link to post
Share on other sites
Thanks for the response, I tried changing my -(void)draw method to this:

glTranslatef(horiVec, 0, vertVec);
[newTerrain updateTerrain];
gluLookAt(0, 0, 0, rotX, rotY, 0, 0, 1, 0);


I disregarded the eyex and eyez since nothing is moving, and I placed the gluLookAt after I had translated the stuff, but it still isn't working, I just see a blank screen. If I do this:

glTranslatef(horiVec, 0, vertVec);
[newTerrain updateTerrain];
glLoadIdentity();
gluLookAt(0, 0, 0, rotX, rotY, 0, 0, 1, 0);


The background shows, but continually flashes around and the thing doesn't rotate right. Any ideas?

Share this post


Link to post
Share on other sites
Well first to draw your terrain and put it in the world, you take the model and then translate it to where it needs to be. So in the real world your mountains never move, so the fact you have a variable in there makes me think that you are trying to move them based on input. So the fact that you even want to translate your terrain at all is most likely wrong.

Eye, Center, and Up. So your camera is at zero, up is towards the sky, but you have rotx and roty. Center is a 3d Point in space that you are looking at, so I'm thinking your using an angle to achieve something and its not correct.
http://www.opengl.or...l/gluLookAt.xml

Do you have a picture of your terrain as a 3D model or did you create it with code? Either way post whatever your terrain is code or a picture.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!