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

Bounce vector, please help!

Started by dmitbcpitew Dec 4, 2001 at 8:17 AM 7 replies 1k views
Original Post
dmitbcpitew
dmitbcpitew
Hi all, I've got two normalized vectors; one corresponding to a direction of movement (A), the other to the face normal (N) of a polygon (P) with which the moving object has collided. I just want to derive from these two vectors a third, corresponding to the vector with which the object should bounce off of the collided polygon (X); \A.....|N....X/ .\.....|...../. ..\....|..../.. ...\...|.../... ....\..|../.... .....\.|./..... ......\|/.....P --------------- At the moment I'm just using N, which is OK, but doesn't result in really believeable collisions. Please help! I guess this should be easy if only I knew my maths a bit better! thanks, dm. Edited by - dmitbcpitew on December 4, 2001 9:19:46 AM Edited by - dmitbcpitew on December 4, 2001 9:22:09 AM
henryx
henryx
X = 2.N - A
HenryLecturer in Computer Games TechnologyUniversity of Abertay DundeeScotlandUK
Fruny
Fruny
X = 2(N.A)N - A, assuming N is normalized.
If A points towards the surface, so will X.
If A points away from the surface, so will X.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
dmitbcpitew
dmitbcpitew
Thanks guys, I''ll try this out!
Vlion
Vlion
angle of incoming to normal is the angle of the outgoing to the normal.

I came, I saw, I got programmers block.
~V''''lion
~V'lionBugle4d
Fruny
Fruny
Yeah, but with the dot product equation, you don''t even need to know the angle (nor use a trig function!)
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
dmitbcpitew
dmitbcpitew
Thanks for the feedback; I''ve tried the following

Fruny, I tried:

D3DXVECTOR3 vNew ;
float fDot ;
fDot = D3DXVec3Dot( &vnAvg, &m_vDirectionOfTravel );
vNew = vnAvg * fDot * 2.0f ;
vNew -= m_vDirectionOfTravel ;
//vNew *= -1.0f ;

Doesn''t produce the expected rebound. Have I got the precendence right? I''m assuming

2(N.A)N - A == (2.0f * (N.A) * N) - A

I''ve tried with and without vNew*=-1 (trying to reverse the direction of the vector)... doesn''t seem to work.

henryx: 2.N? Doesn''t dot product take two vectors, not one vector and a number?! Confused!

Thanks for the help guys,

dm.
henryx
henryx
.......|\......
.......|.\.....
.......|..\....
.......|...\...
.......|....\..
.......|.....\.
.......|......\
\A.....|2N...X/
.\.....|...../.
..\....|..../..
...\...|.../...
....\..|../....
.....\.|./.....
......\|/.....P
---------------

Sorry I took so long to get back but the diagram above is what I meant by X=2.N - A. i.e 2 times the vestor N - which as Fruny points out N = (A.n)n where n is the *normalised* surface normal.

This only works correctly if the A vector is pointing away from the surface then the result X is also pointing away from the surface.

If A is pointing towards the surface then X=2.N + A and X is pointing away from the surface - which is probably the most real situation to model.

henryx
HenryLecturer in Computer Games TechnologyUniversity of Abertay DundeeScotlandUK
dmitbcpitew
dmitbcpitew
Thanks v. much! I''ll try this out at once!

Topic Locked

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

Sign in to reply to this topic.