PDA

View Full Version : OpenGL Display "issues"



Powersoft
03-31-2010, 04:03 AM
Hi there.

Well this is my first post to the forums as I have recently been getting involved with OpenGL and all the exciting things that goes with it. I have been writing a C++ wrapper for Glut to go alongside my course and am having a reasonable amount of success.

What I am having issues with however is getting my head around displaying onto the screen and the order in which I'm doing things. Chances are that the code is working how it is expected to but not how I expect it to.

In my code I have a camera class and a draw class (to name a few) and am trying to create an 'FPS' style camera so that I can view my scene fully. To keep things simple I am displaying a glutSolidTeapot() as it will help me with orientation etc.

The code in the display() call back looks like:



// Check for an OpenGL errror
glObj->checkError();

// Set the colour to be used to clear the background - and clear it
glClearColor(this->clearCol[0], this->clearCol[1], this->clearCol[2], this->clearCol[3]);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


// Reset the matrix

glLoadIdentity();


cameraObj->refreshCamera();
cameraObj->printCamera();


glPushMatrix();
glTranslatef(0.0, 0.0, 5.0);
glutSolidTeapot(1);
glPopMatrix();
glutSwapBuffers();



With refresh camera being:

// Update the camera

void cgvCamera::refreshCamera()

{
// Wrap angles
this->ang.X = this->wrapAngle(this->ang.X);
this->ang.Y = this->wrapAngle(this->ang.Y);

// Rotate the camera
glRotatef(this->ang.X, 1.0, 0.0, 0.0);
glRotatef(this->ang.Y, 0.0, 1.0, 0.0);


// Move the world
glTranslatef(-this->eye.X, -this->eye.Y, -this->eye.Z);

}

It may be the maths are wrong of course.


I have also uploaded the source.

I would really appreciate any help.


Regards,
Richard

http://www.megaupload.com/?d=NOINWR3R

cgvLib Source Code (http://www.megaupload.com/?d=NOINWR3R)

Powersoft
03-31-2010, 04:21 AM
On looking back I wasn't very specific on the problem.

What happens is that the camera should be looking down at the teapot at a 45 degree angle from (0, 5, 0) with the teapot at (0, 0, 5).

This doesn't happen, even though the maths suggest it should, and I appear to be merely looking into black space.

Furthermore the camera controls don't seem to work with the arrow keys seemingly deciding which way I want the camera to move and not going along with the code I have written.

Rich