Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm doing a C++ exercise for university. Basically it's supposed to be a golfball going into a hole. I've tried to implement the gluLookAt function but it produces a blank screen and I have no idea what I'm doing wrong. I'm guessing I'm not using it properly with Projection mode. Any help would be very much appreciated. Thanks.

code here: http://pastebin.com/RqTxNf9U

share|improve this question

closed as too localized by bummzack, Nicol Bolas, Josh Petrie, Byte56, Jonathan Hobbs Nov 15 '12 at 1:13

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

2 Answers

You are not pointing the camera at the ball. You are looking at {0, 0, 10} but the ball's initial position is at {0, 0.4, 0.8}. Change the lookat point (param 4-6) to something like {0, 0, 0}, so you are looking near the ball, i.e:

gluLookAt(
    // eye position:     
    0.0, 2.0, -3.0, 
    // look at point (this was wrong)
    0.0, 0.0, 0.0, 
    // up-vector
    0.0, 1.0, 0.0);

or even better, use the ball's position directly for the lookat point, this will move the camera each frame to point to the ball:

gluLookAt(
    // eye position:     
    0.0, 2.0, -3.0, 
    // look at point, look at the ball each frame
    golfball.getpx(), golfball.getpy(), golfball.getpz(), 
    // up-vector
    0.0, 1.0, 0.0);

But for this to work, you have to fix the rendering of the ball's position, remove startdispzotherwise you are not redering the ball on the correct position, change it to:

    glTranslatef(golfball.getpx(),golfball.getpy(), golfball.getpz());
    glutSolidSphere(golfball.getballsize(),20,20);
share|improve this answer

You're telling gluLookAt to look up into the sky. Check the documentation.

Your screen will be slightly less blank if you look at the ball. Or alternately, almost anywhere that isn't ten meters up in the air, precisely away from where the interesting stuff in the scene might be.

share|improve this answer
He is not looking into the sky. eye is at {0, 2, -3} looking at {0, 0, 10} with an up vector {0, 1, 0}. The up vector is pointing into the sky, not the look at direction. However, looking at the ball is a good advice anyway :) – Maik Semder Nov 13 '12 at 10:59
@MaikSemder Apparently you don't know that there are people who (with good reasons) prefer to use Z as the vertical axis. – snake5 Nov 13 '12 at 11:16
@MaikSemder Whoops, you're right. I hate these functions which just take a list of floats for the different components of unrelated vectors; I always wind up grouping them incorrectly. Regardless, if you change the 10.0 to a 0.0, you can see the ball moving. (I did actually test the fix, before posting my answer) So not looking up into the sky; just off to one side. – Trevor Powell Nov 13 '12 at 11:34
Hehe @Trevor .. yeah endless parameter-lists are painful :) – Maik Semder Nov 13 '12 at 16:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.