Archived

This topic is now archived and is closed to further replies.

Movement in a 3D world

This topic is 5778 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

from a beginners point of view.

gluLookAt is very easy to use. (provided you''ve read a good tutorial on it...)

you''re best bet is to set up a class with 9 properties and methods you can call from you''re mouse and key pressing events.

and then call gluLookAt in the render loop using those 9 properties.

Share this post


Link to post
Share on other sites
quote:
Original post by Smurfwow
from a beginners point of view.

gluLookAt is very easy to use. (provided you''ve read a good tutorial on it...)

--> not easy each time: if your up vector is not good, let''s see what you''ll see ! all the drawing will be disturbed !

you''re best bet is to set up a class with 9 properties and methods you can call from you''re mouse and key pressing events.

and then call gluLookAt in the render loop using those 9 properties.


Share this post


Link to post
Share on other sites
it depends of what you want to do:

do you want to move the world ? or do you want to move a piece of the world ? or do you want to move the view ?

moving a world can be very fastidious for calculations, so maybe you only want to move the point of view.

using glRotate and glTranslate maybe more easier to know where you are in your world cause you always know what transformation you are doing. It''s not the case of gluLookAt which need the 3 coordinates of the eye of the camera, the 3 of the aim (where you are looking) and the up vector (how is the camera oriented).

i hope this will help you

Fratt

Share this post


Link to post
Share on other sites
quote:
Original post by Fratt

do you want to move the world ? or do you want to move a piece of the world ? or do you want to move the view ?




I actually want to move through the world.

Share this post


Link to post
Share on other sites
This is just a matter of thinking. The point is that you transform coordinates (hm..not very precise, anyway) - you can think of it as moving through the world or moving the world around the camera - you code will be the same.

gluLookAt, glTranslate/glRotate do all the "same" thing. They compute a modelview matrix and "upload" it to opengl. Since this is only done a few times per frame they are free in terms of performance (compared to the rest of the pipeline)

-Lev

Edited by - Lev Povalahev on February 19, 2002 10:44:30 AM

Share this post


Link to post
Share on other sites
I wrote these a long time ago when I was in my stage of 3D newbiehood =)

Check them out:

  
int moveFB(int direction){ //''1'' if forward ''-1'' if backwards

x += direction*(lx)*SPEED;
z += direction*(lz)*SPEED;
glLoadIdentity();
gluLookAt(x, y, z,
x + lx, y + ly, z + lz,
0,1,0);
return 0;
}

  
int moveLR(float angle){
lx = sin(angle);
lz = -cos(angle);
glLoadIdentity();
gluLookAt(x, y, z,
x + lx, y + ly, z + lz,
0,1,0);
return 0;
}


so you would just call ''if(keyPressed[UP]) moveFB(1);'' for example.


int MoveLR() requires a float angle, so do something like

float lrPos;
float speed = 0.09f
...
if(keypressed[VK_RIGHT]){
lrPos+=speed;
moveLR(lrPos);
}

~Dwarf

Share this post


Link to post
Share on other sites