Sign in to follow this  

animation errors

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

hello, i have been reading opengl superbible version 4 and im confused about one of the projects. Aside from the colors used my project is almost identical to the code in the book and im getting a weird resault. the yellow square is supposed to bounce around the edges but instead it rapidly flips over the oragin. i have no idea whats wrong and would like some help. ive included the code. thanks for any responces :)

Share this post


Link to post
Share on other sites
Almost identical? If you look for what you have done differently that could be your answer!

As far as I can see, what you got looks good... I haven't touched much graphics code in the last 6 months mind you! The only thing I would say that looks out of place is this:
[CODE]
if (x1 > windowWidth - rsize || x1 < -windowWidth)
xstep = -xstep;
[/CODE]
-windowWidth (in a few places). As far as I'm aware, in OpenGL the origin is bottom left, so -windowWidth would be off the screen! I believe this should be 0.

Also it seems that the rect is initially being drawn off the screen with y - rsize: 0 - 25 = -25 which is below the window.

Hope this is helpful! Edited by CurtisJC

Share this post


Link to post
Share on other sites
You have to set windowWidth and windowHeight:

[code]
if (w<=h){
windowWidth = 100;
windowHeight = 100 / aspectRatio;
}else{
windowWidth = 100 * aspectRatio;
windowHeight = 100;
}

glOrtho (-windowWidth, windowWidth, -windowHeight, windowHeight, 1.0, -1.0 );
[/code]

That said: I don't think that "windowWidth" and "windowHeight" are proper variable names in this case, because their values represent the limits of your visible coordinate system.

Share this post


Link to post
Share on other sites

This topic is 2034 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this