animation errors

Started by
2 comments, last by Goran Milovanovic 11 years, 11 months ago
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 :)
Advertisement
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:

if (x1 > windowWidth - rsize || x1 < -windowWidth)
xstep = -xstep;

-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!
Curtis Clark
Software Engineer
Aerospace and Defence Industry
what i ment my almost identical is that i changed the colors of the background and the square
You have to set windowWidth and windowHeight:


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

glOrtho (-windowWidth, windowWidth, -windowHeight, windowHeight, 1.0, -1.0 );


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.

+---------------------------------------------------------------------+

| Game Dev video tutorials -> http://www.youtube.com/goranmilovano | +---------------------------------------------------------------------+

This topic is closed to new replies.

Advertisement