Jump to content
  • Advertisement


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

the origin


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

i want to move a sphere trough an terrain. the sphere is in 3dspace and i want to move it in viewing direction. when i rotate the sphere now i want to move in the new viewing direction. i made a little test with this code in an normal nehe code but it dont make what i want. glTranslatef(0.0,0.0,-z); gluSphere(q,1,20,20); glTranslatef(0.0,0.0,z); glTranslatef(0.0,0.0,-z); glRotatef(rot,0.0,1.0,0.0); glTranslatef(0.0,0.0,z); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(-10.0, 0.0, -10.0); glTexCoord2f(1.0f, 0.0f); glVertex3f( 10.0, 0.0, -10.0); glTexCoord2f(1.0f, 1.0f); glVertex3f( 10.0, 0.0, 10.0); glTexCoord2f(0.0f, 1.0f); glVertex3f(-10.0, 0.0, 10.0); glEnd(); glTranslatef(0.0,0.0,-z); glRotatef(-rot,0.0,1.0,0.0); glTranslatef(0.0,0.0,z); if(keys[VK_LEFT]) rot -= .01; if(keys[VK_RIGHT]) rot += .01; if(keys[VK_UP]) z += .01; if(keys[VK_DOWN]) z -= .01; please help me

Share this post

Link to post
Share on other sites
You need to store the current x,y and modify them by (cos(rot), sin(rot)) when you try to move forward or backward.

Make a right clean schema (on paper!) of the general case (object not at origin, moving in a random direction) and figure out from it the transforms you need to view the object.

Share this post

Link to post
Share on other sites
oh i told it in a stange way

i want to make a carrace
and now i have an object on in the space
when i press forwd the object shold move forward.
now i rotate the object (drive left or right)
and now when i pres forwd i must have a new direction to move

but when i use the code i made the object rotates but the direction is still the same (the object drives with sidestep )

and now i need new help but in easy english please.


Edited by - the origin on February 16, 2002 2:13:28 PM

Share this post

Link to post
Share on other sites
remember sin() and cos() use radians.. you can use this macro I made to convert your args to rads:

/*-------- Defines ---------------------------------------*/
#define PI 3.14159265

/*-------- Macros ----------------------------------------*/
#define NUM_TO_RAD(number) (number*PI)/180

// ..

/*..*/ sin( NUM_TO_RAD(90) ) /*..*/

- Sean

Share this post

Link to post
Share on other sites
i tried it with sin and cos but i cant get a good movement

may somebody post the view lines of code thtat i can move over the QUAD and when i rotate i get a new direction to move
and when i move again in the new direction i can rotate again and move in the new direction again ?

' O
' ' ^
' ' '
' '
' 0.....>O

like a car forwd drive right; forwd; left ; forwd and so on.


Edited by - the origin on February 17, 2002 5:23:14 AM

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!