Jump to content
  • Advertisement


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


Two basic problems

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

Ok, im making a really simple biplanes style 2D game in OpenGL. (which im new to). Im using Visual Studio C++ v6. Currently I have a sky background and a plane image which i am trying to get moving around the screen. I want the plane to move constantly left (using the timer function), but the player can slow it down and speed it up with the A and D keys. First problem: Ive got a timer function that calls "glutDisplayFunc(UpdateEnvironment)", which draws the sky and plane. This should update the plane (and sky) every timer cycle. All well and good. However, in my keyboard function i have the following code: case ''a'': p.SetPlaneVel_x(0.025); glutPostRedisplay(); break; I want to call the SetPlaneVel_x method in the plane class, (created as object p). I want to pass it the value 0.025 to set the planes velocity as 0.025. This should then be accessed in the "glutDisplayFunc(UpdateEnvironment)" method. The above section of code fails to compile tho. It says something like line p.setPlaneVel_x(0.025) doesnt amount to a function. Why? All I want to do is pass is the new velocity. Any ideas? Second (brief and not as important) problem: I currently move my plane sprite around using the glTranslate function. This does not allow me easy access to the plane as an object though. How can I create the plane object and assign it values such as velocity, acceleration etc without having to keep specifying new co-ordinates in the translate function? Dave

Share this post

Link to post
Share on other sites
Your first problem:

Is p a global object? i.e. accessible in keyboard and display?

What''s the function look like?

Personally I dont postredisplay in any func other than idle or timer, I use all input callbacks to just set state vars, and when display runs it looks at them and takes the appropo action.


In c++ you should define your classes like real world objects. i.e. it is the plane class that stores/does everything relating to a plane, so it should have a position and velocity vector, orientation, etc (actually not true if you are using a controller class like I do!). Your input will only modify the velocity/position (and not in the callback!) and when time to render, the class will draw it using translate to move it to the current location.

In display, draw your screen from scratch everytime, it is the only way to have realtime drawing of input-modified and other time-based effects like particles, etc.


zintel.com - 3d graphics & more or less

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!