Advertisement

reflection vectors for bouncing

Started by May 03, 2002 08:05 AM
38 comments, last by endo 22 years, 9 months ago
possible cause dotproduct(a,b) = ab * cos of the angle

but i finally went to code. q3 has this for finding the orth angle

  void MakeNormalVectors( const vec3_t forward, vec3_t right, vec3_t up) {	float		d;	// this rotate and negate guarantees a vector	// not colinear with the original	right[1] = -forward[0];	right[2] = forward[1];	right[0] = forward[2];	d = DotProduct (right, forward);	VectorMA (right, -d, forward, right);	VectorNormalize (right);	CrossProduct (right, forward, up);}  

VectorMA stands for VectorMultiply then Add. outputs with ID software are always the last part of the function call.
so vectorMA is multiply right by -d then add forward to it and save it in right.

ok so this function takes forward and gives you right. from there its a dotproduct op for projections.

using the above it would be

  MakeNormalVectors(normal,right,junk);scale.x = DotProduct(move,right);scale.y = -DotProduct(move,normal);//notice the negnewmove = scale.x*right;newmove += scale.y*normal;  

if that doesnt do it i just dont know... but its exactly the same as the one i gave before sooo.




I think actually I''ll leave it for a few days and look for some books on vector maths. It appears this is a necessity so that I can understand the words you type :D

I''ll be sure to keep track of whats been said on this thread and check back in a couple of days when I''ve had a break from the code (this is best before I throw the whole pc out the window with frustration!!)

Thanks for the help anyways...
Advertisement
Sorry, since you said you were headed to a library for books I thought I would show you how to derive it. The basic idea is just that (x,y)=(x,0)+(0,y). So v=o+p. Your reflected vector is 2o-v, o-p or v-2p. They are all equivalent. The component parallel is reversed while the component orthogonal remains unchanged. If you are axis aligned then finding o and p are simple as the example above shows. If you are not then you have to use the properties of the dot or cross product to find one of them. Since v=o+p and you start with v then if you can find either o or p you can find the other. The cross product provides a rather direct way to find o first and the dot product a slightly less direct way to find p first. The dot product approach works in any number of dimensions while the cross product works only in 3D since the cross product of two vectors is only defined in 3D.
Keys to success: Ability, ambition and opportunity.
Just a side note to LilBudyWizer: Do you know why the cross product is only defined in 3D? I read that it is defined as

(a,b,c) X (e,f,g) = |i j k||a b c||e f g| 

And this would scale nicely to 4D or even 2D (although I don't know if it would be useful)

Cédric

[edited by - cedricl on May 7, 2002 8:52:22 AM]
well if you scale this to 2d the result is this:
|i j||a b|where i and j are the identities of the dimensions (i = 1 step in x-direction, j = 1 step in y-direction)result: the cross"product" is an operator on 1 vector..makes sence..causeif you have a vector you always have a normal vector for this on 2d, just like this:x'' = -y;y'' = x;or switch the -for 4d, you have 3 vecs involfed, as it has to be 0 with 3 other vector-dotproducts..it only makes sence for 3d really(i know there is a crossproduct for 5d as well but dunno how, dunno why, dunno where i would need it anyways)    


"take a look around" - limp bizkit
www.google.com
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

That is why I said for two vectors. Timkin gave me a link to a paper on defining a cross product in other dimensions. It is pretty much what you are saying, but the (i,j,...) needs to be the last row to work as expected. It takes two row swaps in 3D to move it there so it makes no differance. In an even number of dimensions it causes the vector to be the reverse of what you expect, i.e. in 2D you get (y,-x) instead of (-y,x). I think they went into what the magnitude would be for n dimensions by working from 2D up to like 4D to arrive at a generalization. I forget the details though.

It gets a little confusing in higher dimensions, but if you use the standard basis vectors you can establish what order they should be listed in the cross product to obtain another axis. Then by using scaling you can get how the magnitude of the resulting vector generally relates. I''m pretty sure the magnitude is the product of the magnitudes when the vectors are orthogonal. When they are not it is the product of some set of sines, but I forget which. All combinations seems a reasonable guess so with vectors a, b and c then ab, ac and bc.
Keys to success: Ability, ambition and opportunity.
Advertisement
1. Are your collisions entirely elastic?
2. Has your collision detection scheme accounted for ALL cases properly. (i.e. traveling parallel to a surface and striking a triangles edge...etc...etc)
3. Have you reviewed basic oblique collision in your physics book? (if you dont have a physics book, that is your first problem)
4. Is it possible that the desired effect you want the "bounce" function to produce doesnt need any fancy mathematics at all. (i.e. could you make the angle of approach the same as the angle of departure?)
Anonymous Poster : This is all about the collision detection needed for a breakout type game, where the ball needs to bounce off the sides of the paddle and the blocks. I have copied most of the collision detection stuff from gametutorials.com and have tailored it to meet my own needs (eg using my classes and functions). This being the case it would be perfectly ok for the angle of reflection to be equal to the angle of incidence, except I dont know how this is done either. Do you know if there is a simpler approach?
It would seem most of your reflections could be done by just negating one of the components, i.e. the reflection of (x,y,z) off a surface with normal (0,1,0) is (x,-y,z), (1,0,0) is (-x,y,z) and (0,0,1) is (x,y,-z). If you want to have motion of the paddle affect the direction of the bounce that won''t help much, but it sounds like you would be happy just to have it working reasonably right now.
Keys to success: Ability, ambition and opportunity.
I'd be glad to have it working now but I have 3 paddles, 1 flat, 1 triangular and one other (I've called them convex and concave, but they're proabbaly not the best names). Therefore I really want something that can handle reflections of a polygon at any orientation - otherwise I would have taken the easy approach long ago!

[edited by - endo on May 7, 2002 7:22:58 PM]

This topic is closed to new replies.

Advertisement