movement

Started by
1 comment, last by treds1 22 years, 5 months ago
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
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
"The important thing to remember when programming is: When you're 90% complete, there's still 50% more to go."
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

This topic is closed to new replies.

Advertisement