The Concepts behind the explanations
Alrighty, before we go on, please dont send me to a vector math site, or a matrix math site, or anything like that. I have been there so many times. Also the sites that tell you like the fractions for each of the cos, sin, and tang functions, i have already memorized them and all that. So without me rambling, lets go on so i can try to understand this stuff.
Alot of the times in game programming tutorials, especially at gametutorials.com, they say things like, lets take the dot product of the normal of the object. Ok, i know what the dot product is, i know what the normal is, but why do i need the dot product of the normal, what value is being returned that i need? What is happeneing when i take the dot product to it pretty much is my question.
Also, alot of times, they say lets normalize the vector, thats giving it a length of 1 right? Why on earth would you do that? You are taking away information from the vector..
And last but not least, on movment like:
velocity.x += speed*cos(PlayerDir.y * DEGTORAD);
I get what you are doing, you are taking the direction moved on the x-axis by the mouse and putting it in here to change the direction of which you are moving, the mystery to this is the ''cos'' function, i know it is explained at the hypontonus/base, but what on earth is it doing here, what value is it returning that we need in this example?
Also, if you tackle the problem above for me, could you also try to explain what the sin and tan are also used for? Thanks TONS
Any help on those topcis would help alot, these are pretty much the last things to which i dont understand, the programming is so easy to me, its just things like this, they drive me nuts.
Any help would be very very appreciated! Thanks
Performing a dot product with a normal gives you a distance out from the normal in the direction it is pointing. For example, points that are 2.0 above a surface will always be get a result of 2.0 when they are dp'ed with the surface's normal (assuming it is unit length 1.0). That might not always be what the returned value is used as - it depends on the algebra behind the overall operation.
Results of dot products with normals are used for things like lighting (how intensely is a surface illuminated), collision detection (did that point cross the barrier of the surface?), and hidden surface removal (can we see that side of the polygon?).
Normals are made unit length 1.0 so that there doesn't need to be a division to get an accurate distance out from it. In the example above, if the normal was of length 3.0, we would have to divide the dot product by 3.0 to get the distance out. Knowing the normal is length 1.0 keeps us from having to do this, which speeds up CPU operations. Making a normal length 1.0 doesn't take information away because a normal is only meant to represent a direction, not a position. Altering a vector's magnitude does not alter its direction, so we are able to keep the relevent information. But don't do that with vectors that represent a position in space, as opposed to a direction.
As for your cos question, I'm not sure what context the formula is being used. But in a 2D game, cos() is used to handle the x movement and sin() is used to handle y movement, when movement direction is based on an angle. Those movement routines are likely ready to send the object in any possible direction on the screen depending on the angle.
[edited by - Waverider on June 13, 2003 6:43:48 PM]
Results of dot products with normals are used for things like lighting (how intensely is a surface illuminated), collision detection (did that point cross the barrier of the surface?), and hidden surface removal (can we see that side of the polygon?).
Normals are made unit length 1.0 so that there doesn't need to be a division to get an accurate distance out from it. In the example above, if the normal was of length 3.0, we would have to divide the dot product by 3.0 to get the distance out. Knowing the normal is length 1.0 keeps us from having to do this, which speeds up CPU operations. Making a normal length 1.0 doesn't take information away because a normal is only meant to represent a direction, not a position. Altering a vector's magnitude does not alter its direction, so we are able to keep the relevent information. But don't do that with vectors that represent a position in space, as opposed to a direction.
As for your cos question, I'm not sure what context the formula is being used. But in a 2D game, cos() is used to handle the x movement and sin() is used to handle y movement, when movement direction is based on an angle. Those movement routines are likely ready to send the object in any possible direction on the screen depending on the angle.
[edited by - Waverider on June 13, 2003 6:43:48 PM]
It's not what you're taught, it's what you learn.
quote:
Original post by TheManWithoutACD
...but why do i need the dot product of the normal...
If u and v are not normalized, then the dot product gives you |u||v| cos x.
But normalized: |u|=1 and |v|=1 so the dot product is simply cos x.
If you want to know the angle between 2 normalized vectors, then do a dot product and take the acos of the answer.
You use normalized vectors when you want to keep track of the direction of something, for example the face of a surface. When light hits the surface, the normal is used to get the angle to determine how much reflects towards you so it can be lit appropriately.
quote:
Original post by TheManWithoutACD
Also, alot of times, they say lets normalize the vector, thats giving it a length of 1 right? Why on earth would you do that? You are taking away information from the vector..
Makes finding the angle between them easier, as stated above.
quote:
Original post by TheManWithoutACD
velocity.x += speed*cos(PlayerDir.y * DEGTORAD);
...what value is it returning that we need in this example?...
anytime you have an direction and magnitude and want to convert it into a vector (x,y) you do this:
x= magnitude * cos(angle)
y= magnitude * sin(angle)
So in your example, you are taking the player''s direction, converting it to radians, then finding the x part of the velocity vector.
quote:
Original post by TheManWithoutACD
Also, if you tackle the problem above for me, could you also try to explain what the sin and tan are also used for? Thanks TONS
Not sure when you use tan, but atan comes in handy a bunch. If you have a vector (x,y) and want to convert it to the angle and magnitude, then:
magnitude= sqrt(x^2+y^2);
angle=atan(y/x)
-solo (my site)
-solo (my site)
Thanks for the replys.
I have seen charts before for a quick look up, they are cos and sin tables. The values that are in there, what do the actually repesant, i know they are the output of the cos function put in a table for better access but what do the values actually mean?
Thanks
I have seen charts before for a quick look up, they are cos and sin tables. The values that are in there, what do the actually repesant, i know they are the output of the cos function put in a table for better access but what do the values actually mean?
Thanks
Imagine a circle of radius 1.0 around the origin of an (x,y) system.
Now draw a line at a given angle(a) out from the origin until it hits the circle.
The point on the circle at the position the line strikes is, of course, of a type (x,y)...
cos() of the angle(a) will be the x coordinate.
sin() of the angle(a) will be the y coordinate.
tan() would be sin()/cos()
That's one way of thinking of it.
sin(a)^2 + cos(a)^2 always equals 1.0, by the way, supporting that the points generated do in fact lie on a circle of radius 1.0
[edited by - Waverider on June 13, 2003 7:59:55 PM]
Now draw a line at a given angle(a) out from the origin until it hits the circle.
The point on the circle at the position the line strikes is, of course, of a type (x,y)...
cos() of the angle(a) will be the x coordinate.
sin() of the angle(a) will be the y coordinate.
tan() would be sin()/cos()
That's one way of thinking of it.
sin(a)^2 + cos(a)^2 always equals 1.0, by the way, supporting that the points generated do in fact lie on a circle of radius 1.0
[edited by - Waverider on June 13, 2003 7:59:55 PM]
It's not what you're taught, it's what you learn.
Really quick "proof":
a2 + b2 = c2
a2/c2 + b2/c2 = c2/c2 // divide by c2
(a/c)2 + (b/c)2 = 1
sin(A)2 + cos(A)2 = 1
I realize it's nice to see something like that when you haven't had much trigonometry.
Anyways, notice how that looks similar to a circle equation centered at the origin and of radius 1 (x2 + y2 = 1)? It's fairly easy to see how x = cos(A) and y = sin(A) at this point (if you assume that angle A starts along the vector (1, 0) and ends along the vector (x, y))
______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________
[edited by - Thunder_Hawk on June 13, 2003 8:21:21 PM]
a2 + b2 = c2
a2/c2 + b2/c2 = c2/c2 // divide by c2
(a/c)2 + (b/c)2 = 1
sin(A)2 + cos(A)2 = 1
I realize it's nice to see something like that when you haven't had much trigonometry.

Anyways, notice how that looks similar to a circle equation centered at the origin and of radius 1 (x2 + y2 = 1)? It's fairly easy to see how x = cos(A) and y = sin(A) at this point (if you assume that angle A starts along the vector (1, 0) and ends along the vector (x, y))
______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________
[edited by - Thunder_Hawk on June 13, 2003 8:21:21 PM]
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________
I can help with this, I use it all the time.
velocity.x += speed*cos(PlayerDir.y * DEGTORAD);
Alright, cos theta = x length/radius,
or cos theta = adjacent / hypoteneuse, if you like Trigonometry terms.
Now, with algebra, you can rearrange it so you are finding the x length, the x part of a vector, and theta is our angle.
cos theta = x length / radius
(radius) * cos theta = (x length / radius) * (radius)
radius * cos theta = x length
To get x length alone, multiply both sides by radius, thus cancelling radius on the right side, leaving the right side with only x length.
This is helpful if you know the speed of a car and its direction, but you want to know how far it will move on the x and y axes or find the parts of a vector.
I really hopes this helps, and if you nees help with this type of thing in three dimensions, check out a post called "Raise your hand if vectors hate you." I posted it a while back, so check it out before it''s gone.
"Donkey, if it were me, you''d be dead."
I cna ytpe 300 wrods pre mniute.
velocity.x += speed*cos(PlayerDir.y * DEGTORAD);
Alright, cos theta = x length/radius,
or cos theta = adjacent / hypoteneuse, if you like Trigonometry terms.
Now, with algebra, you can rearrange it so you are finding the x length, the x part of a vector, and theta is our angle.
cos theta = x length / radius
(radius) * cos theta = (x length / radius) * (radius)
radius * cos theta = x length
To get x length alone, multiply both sides by radius, thus cancelling radius on the right side, leaving the right side with only x length.
This is helpful if you know the speed of a car and its direction, but you want to know how far it will move on the x and y axes or find the parts of a vector.
I really hopes this helps, and if you nees help with this type of thing in three dimensions, check out a post called "Raise your hand if vectors hate you." I posted it a while back, so check it out before it''s gone.
"Donkey, if it were me, you''d be dead."
I cna ytpe 300 wrods pre mniute.
"Donkey, if it were me, you'd be dead."I cna ytpe 300 wrods pre mniute.
Oh yeah, and it might be help ful to normalize a vector in some situations. For one, you can take a normalized vector and make it any length you want just by multiplying by the desired length. That way you can have the vector you want, the length you want. For instance, if you have a car, you can normalize the vector that represents its direction, and then multiply it by the car''s speed to get the right vector. Hope this helped.
"Donkey, if it were me, you''d be dead."
I cna ytpe 300 wrods pre mniute.
"Donkey, if it were me, you''d be dead."
I cna ytpe 300 wrods pre mniute.
"Donkey, if it were me, you'd be dead."I cna ytpe 300 wrods pre mniute.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement