#### Archived

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

# movement

This topic is 6141 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 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.

thanks

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

##### Share on other sites
Check out NeHe''s Game Tutorial 7...

##### Share on other sites

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

/*-------- Macros ----------------------------------------*/

// ..

- Sean

##### 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 ' O ' ' ^ ' ' ' ' ' ' 0.....>O ' \/

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

thanks

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

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633660
• Total Posts
3013224
×