What the heck man...

Started by
8 comments, last by AfroFire 18 years, 3 months ago
Can anyone tell me why: Note: The blank spaces are + signs, and for some reason aren't showing up...

glVertex2d(((box->mX*pMatrix[0])/2.41421 - 0.5), ((box->mY*pMatrix[5])/2.41421 - 0.5));
glVertex2d(((box->mX*pMatrix[0])/2.41421 + 0.5), ((box->mY*pMatrix[5])/2.41421 - 0.5));
glVertex2d(((box->mX*pMatrix[0])/2.41421 + 0.5), ((box->mY*pMatrix[5])/2.41421 + 0.5));
glVertex2d(((box->mX*pMatrix[0])/2.41421 - 0.5), ((box->mY*pMatrix[5])/2.41421 + 0.5));

Gives me the desired result, while the following doesnt? Especially since pMatrix[0] AND pMatrix[5] are both == 2.41421? In theory they should cancel eachother out no matter what, but the one above is actually doing what I want it to do which is nice (I just wish I knew why).

glVertex2d(((box->mX*pMatrix[0])/pMatrix[0] - 0.5), ((box->mY*pMatrix[5])/pMatrix[5] - 0.5));
glVertex2d(((box->mX*pMatrix[0])/pMatrix[0] + 0.5), ((box->mY*pMatrix[5])/pMatrix[5] - 0.5));
glVertex2d(((box->mX*pMatrix[0])/pMatrix[0] + 0.5), ((box->mY*pMatrix[5])/pMatrix[5] + 0.5));
glVertex2d(((box->mX*pMatrix[0])/pMatrix[0] - 0.5), ((box->mY*pMatrix[5])/pMatrix[5] + 0.5));

Thanks.
AfroFire | Brin"The only thing that interferes with my learning is my education."-Albert Einstein
Advertisement
Are you sure that pMatrix[0] and pMatrix[5] == 2.41421? Run through with the debugger (F5 usually) to be sure.

Is the matrix a class? Maybe something is wrong with the assessors.
What do box->mX*pMatrix[0])/pMatrix[0] - 0.5 and box->mY*pMatrix[5])/pMatrix[5] - 0.5 give you? What is the desired result?

If the desired result is 0 and you get something like -3.589387e-09, then there is nothing wrong.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
rpg_code_master - when I output the data to a file they are...

JohnBolton - the desired effect is to just have a box follow a polygon without rotating or anything along with the polygon.

Is it possible that the compiler is just cancelling the numbers out ahead of time? Even then the order of operations should still have these numbers cancelled out. I'm just not grasping what is happening here, and I can't keep dividing by a constant number, since this number is one that changes often.
AfroFire | Brin"The only thing that interferes with my learning is my education."-Albert Einstein
Quote:Original post by AfroFire
rpg_code_master - when I output the data to a file they are...

Not good enough. There are a dozen ways that can go wrong. Check it in the debugger.

I have a question regarding your code:
(box->mX * pMatrix[0])/pMatrix[0] + 0.5

is just the same as simply writing
box->mX + 0.5

So why are you doing that?
well initially I was playin around with the projection matrix to get this effect I wanted, and I found it worked when I multiplied the projection matrix while I was drawing the point, by the points location, then it was slightly offset, so initially I divided by 2, and it was offset just a little, and I looked in the file where i print output and found 2.4... and so I just typed it in - and it corrected the offset completely, then I went and looked specifically at where the number came from, and sure enough it came from the projection matrix.... so technically speaking --- pMatrix[0]/2.4 --- is the same thing as 1.... however, its result is completely different then pMatrix[0]/pMatrix[0] - which is returning 1 btw..

.... So as Im typing this response - I wondered what would happen if I just did pMatrix[0]/2.4---- and output the difference -- initially it is 1.0, however then it degrades before (eventually) resetting back to one (after a full rotation). Interesting...
AfroFire | Brin"The only thing that interferes with my learning is my education."-Albert Einstein
Here is a screenshot of what I'm essentialy trying to do - This is it rotating on a single axis at a time:


However, here is the problem I experience now on multiple axis -- it gets confused and moves to the upper right and back to the lower left - back and forth... anyone know of a tutorial on how to actually do this properly? I'm just playing guess-work with numbers...
AfroFire | Brin"The only thing that interferes with my learning is my education."-Albert Einstein
I don't think theres much we can do yo help you with the information at hand. Only tell you potential problems.
Either pMatrix doesn't contain the values you think it contains (look in it with the debugger rather than write to a file). OR the error lies elsewhere in your code. OR the mathematics you posted are fundamentally wrong for what you're trying to achieve (actualy someone maybe able to verify this one, but I can't sorry)
The mathematics are without a doubt wrong - Just wondering what the right one is.
I think the effect I'm going for though is called billboarding.
AfroFire | Brin"The only thing that interferes with my learning is my education."-Albert Einstein

This topic is closed to new replies.

Advertisement