gluLookAt
I''m useing gluLookAt with my camera funtion but after i got a large part of the code done when i recompile i runs but without the objects on screen any suggestions?
A man walks into a bar.....ouch!?! Ya get it, do ya huh huh well....awww I give up.
Make sure you''re not drawing the object on the camera, maybe.
I don't have a signature
Perhaps the object is simply not on screen? You''re most likely not plugging in the right coordinates for gluLookAt.
_______________________________________Pixelante Game Studios - Fowl Language
Hi all,
I agree with you here but dont quite know how to solve this dilemma.

I am referring to this "Computer Graphics: Programming, Problem Solving, and Visual Communication(found here: "http://www.cs.csustan.edu/~rsc/CS3600F01/Syllabus.html)
In Chapter1, this is the exercise on Page 52. I have tried my level best to follow UPTIL the point that the author has suggested for the reader to try the exercise.
This is the code.
I agree with you here but dont quite know how to solve this dilemma.
quote:
Original post by LockePick
Perhaps the object is simply not on screen? You're most likely not plugging in the right coordinates for gluLookAt.

I am referring to this "Computer Graphics: Programming, Problem Solving, and Visual Communication(found here: "http://www.cs.csustan.edu/~rsc/CS3600F01/Syllabus.html)
In Chapter1, this is the exercise on Page 52. I have tried my level best to follow UPTIL the point that the author has suggested for the reader to try the exercise.
This is the code.
#include <gl\glut.h> //Integer Identifier for the window int myWin; void display(void); void reshape(int,int); void myInit(void); void drawHouse(void); void main(int argc, char **argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); glutInitWindowSize(500,500); glutInitWindowPosition(100,100); myWin = glutCreateWindow("My House"); myInit(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMainLoop(); } void drawHouse(void) { typedef GLfloat point [3]; int i,j; point myHouse[10] = { { -1.0, -1.0, 2.0 }, { -1.0, 1.0, 2.0 }, { 0.0, 2.0, 2.0 }, { 1.0, 1.0, 2.0 }, { 1.0, -1.0, 2.0 }, { -1.0, -1.0, -2.0 }, { -1.0, 1.0, -2.0 }, { 0.0, 2.0, -2.0 }, { 1.0, 1.0, -2.0 }, { 1.0, -1.0, -2.0 } }; glBegin(GL_LINE_STRIP); for ( i=0; i<5; i++) glVertex3fv(myHouse[i]); glVertex3fv(myHouse[0]); glEnd(); glBegin(GL_LINE_STRIP); for ( i=0; i<5; i++) glVertex3fv(myHouse[i+5]); glVertex3fv(myHouse[5]); glEnd(); for ( i=0; i<5; i++) { glBegin(GL_LINE_STRIP); glVertex3fv(myHouse[i]); glVertex3fv(myHouse[i+5]); glEnd(); } //Code that works /* point myHouse[4] = {{0.0, 0.0, 0.0} , {1.0,0.0,0.0}, {1.0,0.0,1.0}, {0.0,0.0,1.0}}; glBegin(GL_QUADS ); glColor3f(1.0,0.0,0.0); for(i = 0; i < 4; i++) { //glColor3f(0.0,0.0,0.0); glVertex3fv(myHouse); <br> } <br> glEnd(); <br> */</font> <br>} <br><br><font color="blue">void</font> myInit(void) <br>{ <br> glEnable(GL_DEPTH_TEST); <br> glClearColor(1.0,1.0,1.0,1.0); <br>} <br><br><font color="blue">void</font> display(void) <br>{ <br> glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); <br> glMatrixMode(GL_MODELVIEW); <br> glLoadIdentity(); <br><br> gluLookAt(20, 20/2., 20/4., 0.0, 0.0, 0.0, 0.0, 0.0, 1.0); <br> glPushMatrix(); <br> drawHouse(); <br> glPopMatrix(); <br> glutSwapBuffers(); <br>} <br><br><font color="blue">void</font> reshape(<font color="blue">int</font> width,<font color="blue">int</font> height) <br>{ <br> glViewport(0,0,width,height); <br> glMatrixMode(GL_PROJECTION); <br> glLoadIdentity(); <br> gluPerspective(60.0, (float)width/(float)height, 1.0, 100.0); <br>} <br> </pre></DIV><!–ENDSCRIPT–> <br> <br><br><br>I seem to be missing the big picture here and am unable to view anything. <br>In case, the code for the house is commented and only a quad is tried (with z-coords equal to 0), I can at least see soemthing on my window. <br><br>I dont know what I am doing wrong! <br><br>"Recovering Thinker" <br>!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! <br>"He conquers who endures." <br>-Persius <br>!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! <br><br><br><br><SPAN CLASS=editedby>[edited by - inrecovery on March 18, 2003 9:47:08 PM]</SPAN>
Could you please tell us with soem small example? or take a look at the code above.
PLEASE

quote:
Original post by LockePick
Perhaps the object is simply not on screen? You''re most likely not plugging in the right coordinates for gluLookAt.
Heres the actual gluLookAt snippet.
[edited by - ARID on March 18, 2003 11:18:59 PM]
[edited by - ARID on March 18, 2003 11:22:16 PM]
gl_Camera.CameraPosition(0.0f, -10.0f, -6.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f);........gluLookAt(gl_Camera.cur_vPosition.X, gl_Camera.cur_vPosition.Y, gl_Camera.cur_vPosition.Z, gl_Camera.cur_vView.X, gl_Camera.cur_vView.Y, gl_Camera.cur_vView.Z, gl_Camera.cur_vVectorUp.X, gl_Camera.cur_vVectorUp.Y, gl_Camera.cur_vVectorUp.Z); glBegin (GL_QUADS); for(float i = 0; i < 100; i += 5) { glColor3ub(255, 255, 0); glVertex3f(-10 + i/5, i, 10 - i/5); glColor3ub(255, 0, 0); glVertex3f(-10 + i/5, i, -10 + i/5); glColor3ub(0, 255, 255); glVertex3f(10 - i/5, i, -10 + i/5); glColor3ub(0, 0, 255); glVertex3f(10 - i/5, i, 10 - i/5); } glEnd(); glFlush();
[edited by - ARID on March 18, 2003 11:18:59 PM]
[edited by - ARID on March 18, 2003 11:22:16 PM]
A man walks into a bar.....ouch!?! Ya get it, do ya huh huh well....awww I give up.
Here is the Camera itself.
[edited by - ARID on March 18, 2003 11:26:45 PM]
// CROSS PRODUCT CVector3 Cross(CVector3 vVector1, CVector3 vVector2){ CVector3 vNormal; // Storage for the cross product // X value of the vector is (V1.Y * V2.Z) - (V1.Z * V2.Y) vNormal.X = ((vVector1.Y * vVector2.Z) - (vVector1.Z * vVector2.Y)); // Y value of the vector is (V1.Z * V2.X) - (V1.X * V2.Z) vNormal.Y = ((vVector1.Z * vVector2.X) - (vVector1.X * vVector2.Z)); // Z value of the vector is (V1.X * V2.Y) - (V1.Y * V2.X) vNormal.Z = ((vVector1.X * vVector2.Y) - (vVector1.Y * vVector2.X)); return vNormal;}// MAGNITUDEfloat Magnitude(CVector3 vNormal){ return (float)sqrt( (vNormal.X * vNormal.X) + (vNormal.Y * vNormal.Y) + (vNormal.Z * vNormal.Z) );}// NORMALIZECVector3 Normalize(CVector3 vVector){ // Get the magnitude of the normal float magnitude = Magnitude(vVector); // Make unit vector vVector = vVector / magnitude; return vVector;}// Camera class constructor.CCamera::CCamera(){ CVector3 vZero = CVector3(0.0f, 0.0f, 0.0f); // Zero out the position CVector3 vView = CVector3(0.0f, 1.0f, 0.5f); // View looking up and out CVector3 vUp = CVector3(0.0f, 0.0f, 1.0f); // Standard up vector. cur_vPosition = vZero; // Initilize the position cur_vView = vView; // Initilize the view vector cur_vVectorUp = vUp; // Initilize the up vector};// Initilize the CameraGLvoid CCamera::CameraPosition(float X_Position, float Y_Position, float Z_Position, float X_View, float Y_View, float Z_View, float X_VectorUp, float Y_VectorUp, float Z_VectorUp){ CVector3 vPosition = CVector3(X_Position, Y_Position, Z_Position); CVector3 vView = CVector3(X_View, Y_View, Z_View); CVector3 vVectorUp = CVector3(X_VectorUp, Y_VectorUp, Z_VectorUp); // Assign position view and up vector cur_vPosition = vPosition; cur_vView = vView; cur_vVectorUp = vVectorUp;}// Mouse Viewing void CCamera::SetViewByMouse(){ POINT mousePos; int middleX = SCREEN_WIDTH >> 1; int middleY = SCREEN_HEIGHT >> 1; float angleY = 0.0f; float angleZ = 0.0f; static float currentRotX = 0.0f; // Find the mouse GetCursorPos(&mousePos); // See if the mouse moved if((mousePos.x == middleX) && (mousePos.y == middleY)) return; // Reset the mouse position to the center. SetCursorPos(middleX, middleY); // Get the vector the mouse moved angleY = (float)((middleX - mousePos.x))/1000.0f; angleZ = (float)((middleY - mousePos.y))/1000.0f; // Restrict the vertical tilt currentRotX -= angleZ; // If the current rotation in radians is greater then 1,0 cap it. if(currentRotX > 1.0f) currentRotX = 1.0f; // If the current rotation in radians is less then -1.0 cap it else if(currentRotX < -1.0f) currentRotX = -1.0f; // Otherwise rotate the view else { // Normalize CVector3 vAxis = Cross(cur_vView - cur_vPosition, cur_vVectorUp); vAxis = Normalize(vAxis); // Rotate view CameraRotate(angleZ, vAxis.X, vAxis.Y, vAxis.Z); CameraRotate(angleY, 0.0f, 1.0f, 0.0f); }}// Camera Rotation void CCamera::CameraRotate(float angle, float X, float Y, float Z){ CVector3 vNewView; // Get view vector CVector3 vView = cur_vView - cur_vPosition; // Calculate the sin and cos of the angle float cosTheta = (float)cos(angle); float sinTheta = (float)sin(angle); // Find the X position for the rotated point. vNewView.X = (cosTheta + (1 - cosTheta) * X * X) * vView.X; vNewView.X += ((1 - cosTheta) * X * Y - Z * sinTheta) * vView.Y; vNewView.X += ((1 - cosTheta) * X * Z + Y * sinTheta) * vView.Z; // Find the Y position for the rotated point vNewView.Y = ((1 - cosTheta) * X * Y + Z * sinTheta) * vView.X; vNewView.Y += (cosTheta + (1 - cosTheta) * Y * Y) * vView.Y; vNewView.Y += ((1 - cosTheta) * Y * Z - X * sinTheta) * vView.Z; // Find the Z position for the rotated point vNewView.Z = ((1 - cosTheta) * X * Z - Y * sinTheta) * vView.X; vNewView.Z += ((1 - cosTheta) * Y * Z + X * sinTheta) * vView.Y; vNewView.Z += (cosTheta + (1 - cosTheta) * Z * Z) * vView.Z; // Add new rotated vector to the current position to set the new rotated view. cur_vView = cur_vPosition + vNewView;}// Camera Movement GLvoid CCamera::CameraMovement(float speed){ CVector3 vVector = cur_vView - cur_vPosition; // Init view vector. // Move Camera based on acceleration and vector cur_vPosition.X += vVector.X * speed; // acceleration added to positions X cur_vPosition.Z += vVector.Z * speed; // acceleration added to positions Z cur_vView.X += vVector.X * speed; // acceleration added to view X cur_vView.Z += vVector.Z * speed; // acceleration added to view Z}
[edited by - ARID on March 18, 2003 11:26:45 PM]
A man walks into a bar.....ouch!?! Ya get it, do ya huh huh well....awww I give up.
Here is the Camera class
[edited by - ARID on March 18, 2003 11:27:35 PM]
#include "Vectors.h" // Vector Header#include "AggressiveOptimize.h" // Optimization Headerclass CCamera{public: CVector3 cur_vPosition; // Cameras position CVector3 cur_vView; // Cameras view CVector3 cur_vVectorUp; // Cameras Up Vector CCamera(); // Constructor void CameraPosition(float X_Position, float Y_Position, float Z_Position, float X_View, float Y_View, float Z_View, float X_VectorUp, float Y_VectorUp, float Z_VectorUp); void SetViewByMouse(); void CameraRotate(float angle, float X, float Y, float Z); void CameraMovement(float speed);};extern CCamera gl_Camera;
[edited by - ARID on March 18, 2003 11:27:35 PM]
A man walks into a bar.....ouch!?! Ya get it, do ya huh huh well....awww I give up.
Here is the Vector class.
[edited by - ARID on March 18, 2003 11:28:07 PM]
class CVector3 // The camera vector{public: CVector3() {} // This is our constructor that allows us to initialize our data upon creating an instance CVector3(float X, float Y, float Z) { } // Here we overload the + operator so we can add vectors together CVector3 operator+(CVector3 vVector) { // Return the added vectors result. return CVector3(vVector.X + X, vVector.Y + Y, vVector.Z + Z); } // Here we overload the - operator so we can subtract vectors CVector3 operator-(CVector3 vVector) { // Return the subtracted vectors result return CVector3(X - vVector.X, Y - vVector.Y, Z - vVector.Z); } // Here we overload the * operator so we can multiply by scalars CVector3 operator*(float num) { // Return the scaled vector return CVector3(X * num, Y * num, Z * num); } // Here we overload the / operator so we can divide by a scalar CVector3 operator/(float num) { // Return the scale vector return CVector3(X / num, Y / num, Z / num); } float X, Y, Z;};
[edited by - ARID on March 18, 2003 11:28:07 PM]
A man walks into a bar.....ouch!?! Ya get it, do ya huh huh well....awww I give up.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement