• Advertisement

Archived

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

movement

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

how can i get an object to move n opengl in c++, can get it to move along x axis or y axis and xy, but not freely. any ideas?? cheers nick

Share this post


Link to post
Share on other sites
Advertisement
I''m not sure I know EXACTLY what you want to achieve but moving an object is quite simple.

When you draw an object, you have to know where to draw it, correct?

What I would do is create a structure called coordinate:

typedef struct
{
float xPos;
float yPos;
float zPos;
} coordinate;

then make an instance of it:

coordinate square;

initialize it:

square.xPos = 0.0f;
square.yPos = 0.0f;
square.zPos = 0.0f;

and when you draw your object:

...
glTranslatef(square.xPos, square.yPos, square.xPos);
...

and if you want it to move:

if (keyDown[VK_RIGHT]) {
...
square.xPos += 1.0f; // or whatever increment you want
...
}


Hope this helps

- Mike

Share this post


Link to post
Share on other sites
thats basically what i allready have.

basically i have a car which i want to be able to drive along but can not get it to turn

Share this post


Link to post
Share on other sites

  • Advertisement