Jump to content
  • Advertisement

Archived

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

mstein

light position question

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

This is a performance related question i think... I have a simple 2d car that moves around the screen. Everytime it is updated I also update the position of a light so that it is within the bounds of the current viewing area. Therefore, to me that would mean the light should be flickering around the screen at a seizure inducing rate, pretty much when the car moves, the light should move. Instead, the light seems to move about once per second, whereas I have had the car clamped anywhere between 22 fps and 80 fps (ie the car is getting updated that fast, but the light doesnt seem to be ). My question is: does changing the position of the light have a drastic performance hit in regards to the fact that my machine would not be able to handle the light changing position 22 - 80 times a second. I am very interested in your responses.

Share this post


Link to post
Share on other sites
Advertisement
does anyone have any ideas on this . . . someone has had to have some experience with this perhaps . . .

Share this post


Link to post
Share on other sites
I have no idea what is causing your problem; your description seems unclear. It is nothing to do with performance anyway; if updating the position of the light took a second, it would affect the overall framerate (ie, the car would update at 1fps).

I suspect the problem lies in your code which updates the light position.

Just out of interest, how are you implementing lighting in 2D? 2D usually implies uniform normals (straight down the Z axis), and that makes lighting pretty pointless, since the light distribution would be uniform too.

Share this post


Link to post
Share on other sites
sorry, didnt mean 2d, the car itself is a flat polygon and the camera is lookng top-down, so in my mind, everything is pretty flat and well 2d. I understand what you are saying. i just realized that the headlights of the car are updated every frame properly, so i must be updating my other lights position incorrectly. I want to say that the car''s lights move with it because I update them in the car''s draw method, whereas the other lights are updated in the glutTimerFunction. what do you think about that . . .

Share this post


Link to post
Share on other sites
in my timer function i keep track of a boolean that tells me whether or not the right click menu has been accessed. If it has not then we are animating and in that function i move everything, the car, other objects, and the lights.

What main loop do you mean.

I have my display function, timer function, mouse, keyboard, and special char functions.

Share this post


Link to post
Share on other sites
I meant somewhere in the glut main loop. The display function is probably a good idea.

Just make sure you''re not putting anything which needs to be done per frame in the timer function. This includes updating animated light positions, drawing code, physics etc. The timer function, as you probably know, isn''t guaranteed to be executed once per frame.

Share this post


Link to post
Share on other sites
well that is my problem them. I was actually under the impression that the timer function is what controlled the frame-rate, therefore it would have to be invoked once per frame. In my mind I was thinking timer() --> move() --> draw() --> timer() --> move() . . . etc.

Would you care to elaborate more on the more probably flow of events.

thanks again.

Share this post


Link to post
Share on other sites
THe event structure has nothing to do with your issue. But rather that you are using glut and its timer. the timer will update at the time you say give or take 1.00001 second or something. just because the drawing is occuring does not mean that your lights will be updated in that frame. because if you have something like a your car that is running at 80 fps then your timer would have something like 0.012 seconds to update the lights and return.

Note: that it is best to update your values while in the main loop of your program. the main loop is the control loop or what ever someone might call it.

while(!done){
draw(*myObject);

}

The way you are building your application you must have hundreds of global variables. that have keystate, mouse, menu and render state.

It would be best to not use glut. but obviously this is not going to be a highend game so it should be ok. However functions with parameters and pointers to data structures should be used when ever possible. Its easier to push a pointer unto the stack of a function than copy the whole variable from one function to another.

Before continuing RTMF .... ANSI C v2 ... or better known by the best c programmers as R&K reference manual. They wrote the language at AT&T. So best to read from the guys who thought of it first than to read a interputation of the original.









Share this post


Link to post
Share on other sites
You mean you have your glutPostRedesplay call in your timer function? In that case, yes, it should be called once per frame. However, that approach is likely to have a negative impact on your framerate overall, as event driven timers are not usually very accurate. Whenever I''m forced to use GLUT, I put a glutPostRedisplay int the display function. The reason is, when you''re coding a game, you always want the window to be redrawn every frame. I''m not sure what the cause of your problem is, but perhaps you should try this approach.

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!