Skip to main content
GameDev.net gamedev.net
🔒 Locked

open gl game programming book

Started by fatherjohn666 Jul 22, 2002 at 6:23 AM 2 replies 650+ views
Original Post
fatherjohn666
fatherjohn666
Hi again, thanks for the help you have given me so far. I have yet another question This is page 688 of the open gl game programming book. In chapter 19, we have a mini game called air hockey. One of the classes created is called Cpuck and has a function called animate. In the animate function you loop through 4 Cplanes (walls around the hockey table) while testing for collision. In the function you declare three variables of type double, a, b and c. To these, you set them as: double a, b, c; // dot product - quadratic equation a = plane->N % (acceleration * 0.5); b = plane->N % velocity; c = plane->N % position + plane->D - radius; OK. Are we saying that a is the “dot product” (this is according to the CVector operator overloading function we have set for the symbol %) of N and acceleration * 0.5 OR Are we saying that a is the remainder after N (a vector) is divided by acceleration * 0.5? Either way, the function I am thinking it is using in the CVector class accepts 2 CVectors as the argument: const scalar_t operator%(const CVector &vec) const { return x*vec.x + y*vec.x + z*vec.z; } or am I totally thinking in the wrong way? To me that looks like it wants 2 CVec’s (according to what I have learned with operator overloading) and returns a single value, which if I use some standard logic is like saying : a = N.x*vec.x + N.y*vec.x + N.z*vec.z; but what is vec.x, vec.y, vec.z? Where is the vector? Am I looking in the completely wrong spot? Please don’t make me realise something so obvious… hmmm I hope I have made sense about my problem. Im just a beginner!!! http://www.actsofgord.com
~~~~~~~~~~~~~~~~~~~~~~~~~http://on.to/oni
Stealth2000
Stealth2000
fatherjohn666,

I''m reading the same book, but I''m a little behind you (chapter 18). However, I think I can help.

acceleration is a vector. (acceleration * 0.5) is a scalar multiplication of the acceleration vector, which would reduce each of the x, y, z properties by half, the result is still a vector. () has higher precedence than %, so this is done first (you probably knew that).

a is then the dot product of plane->N and the resulting vector from above.

I don''t know what ''a'' is without really looking through the code, but I''ll take a shot in the dark and guess its the acceleration of the puck or something.

Hope that helped... I''ll probably be in the same spot as you in a day or so.
khawk
quote:
Original post by fatherjohn666
double a, b, c;

// dot product - quadratic equation
a = plane->N % (acceleration * 0.5);
b = plane->N % velocity;
c = plane->N % position + plane->D - radius;

Are we saying that a is the “dot product” (this is according to the CVector operator overloading function we have set for the symbol %) of N and acceleration * 0.5 OR
Are we saying that a is the remainder after N (a vector) is divided by acceleration * 0.5?
Either way, the function I am thinking it is using in the CVector class accepts 2 CVectors as the argument:

const scalar_t operator%(const CVector &vec) const
{
return x*vec.x + y*vec.x + z*vec.z;
}

or am I totally thinking in the wrong way? To me that looks like it wants 2 CVec’s (according to what I have learned with operator overloading)
and returns a single value, which if I use some standard logic is like saying :

a = N.x*vec.x + N.y*vec.x + N.z*vec.z;

but what is vec.x, vec.y, vec.z? Where is the vector? Am I looking in the completely wrong spot? Please don’t make me realise something so obvious…



The acceleration variable is defined as CVector, which is being multiplied by a scalar (the * operator is overloaded with CVector for vector-scalar multiplication). You are then calculating the dot product of the plane normal and this halved acceleration vector. So your original thought is correct.

The vec.x, vec.y, and vec.z are equal to acceleration.x*0.5, acceleration.y*0.5, and acceleration.z*0.5, respectively.


Kevin "Khawk" Hawkins
CEO and News Director, GameDev.net
Author, OpenGL Game Programming
Developer Diary

Admin for GameDev.net.
fatherjohn666
fatherjohn666
*slaps his head*

I cant believe I missed that one.
so obviously (book not here at work heh)
D (if i remember correctly) was a double representing plane distance for our plane equation.
lol hahaha yeah velocity and position were CVectors weren't they?

Ok Im getting a better tab on whats going on now YAY.


cheers guys.

[edited by - fatherjohn666 on July 22, 2002 6:57:46 PM]
~~~~~~~~~~~~~~~~~~~~~~~~~http://on.to/oni

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.