nabla at January 1st, 2012 22:45 — #1
I am trying to programm a thrid person view in opengl for weeks. Unfortunately it still doesnt work as I expected. My idea was to use the normal rotate and translate functions and calculate the direction vector and
the new position from the camera. With my code i get the following behavior the object is rotating around its center and the camera is rotating around the object but with a different speed. And if you move the object along the direction vector it disappears (this was working in a earlier version I changed something and... ).
// Set coordinates for the camera and for the direction vector of the object
//the new eye coordinates for the lookat function
//set lookat function
gluLookAt(set_lookat_eye.x,set_lookat_eye.y,set_lookat_eye.z, koord.x,0 ,koord.z,0.0f,1.0f,0.0f);
//rotate object and cam
void side(float ang)
//move the object along the direction vector
void forw(int a)
set_lookat_eye.x=koord.x + a*lx*MOVE;
set_lookat_eye.z=koord.z + a*lz*MOVE;
koord.x = koord.x + a*lx*MOVE;
koord.z = koord.z + a*lz*MOVE;
and the display function
draw_sk(); //draw the object
//draw the rest
Thanks for looking at my code!
stainless at January 2nd, 2012 06:54 — #2
Try changing this
nabla at January 2nd, 2012 10:17 — #3
Thanks for your suggestion but it doesnt work. I think its the math in here unfortunately i dont get the problem.
thenut at January 2nd, 2012 22:36 — #4
Your camera is looking down the Y-axis at the object, but you are setting the Y-axis as the up-vector in your gluLookAt function. Set your up-vector along the X or Z axis instead.
mmakrzem at February 6th, 2012 05:57 — #5
For some sample code showing 3rd person view working in OpenGL, have a look at this video tutorial: http://www.marek-knows.com/downloads.php5?vmk=gameEng44a