Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / True Rebound of walls

Author
Message
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 8th Feb 2011 16:50 Edited at: 8th Feb 2011 16:53
Hi, I'm trying to figure out the maths for a true rebound off a spherical wall. When my sphere pass the distance 500 from centre, I want them to bounce off an invisible membrane. I don't know how to tell if it's the X,Y, or Z that I need to reverse, or mixtures of them. ParticleCount + 1 is an object at the centre of the screen 0,0,0. I store the X,Y,Z point direction in Particle(n,1),Particle(n,2),Particle(n,3), and then move the particles 0.1 in random directions.



Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 8th Feb 2011 21:26 Edited at: 8th Feb 2011 21:32
well... it's easy to do with vector math. Instead of having a vector that you point your object to each time, I'd have a vector that represents velocity: You add that vector to the object's position each frame. The length of this vector would be the velocity of the object!

So here's the above code written in that format.


The function "distsquared" gets the distance of the particle from the center, squared, and so the if statement checks if the distance is greater than 500 squared.

Okay, so now... The "normal" of a collision is a vector length 1, that is *tangent* to the surface of collision. The great thing with a circle whose center is zero, is that the normal of the collision is just the negative point of collision, normalized! (normalizing a vector is when you divide it by its length, so its length is one.)

So where P is the point of collision (and the position of the particle), the normal, N, =-P/length(P).

If you think about it, what we really want is so that the object's velocity is negated, but in the direction of N. The dot product of a normalized vector (N), and a non-normalized vector (V, velocity), is "The magnitude of V in the direction N", so to zero the object's velocity in the direction of N: V'=V-N*(N.V). To make it so that the object *bounces*, just double the amount you're subtracting! V'=V-N*(2*N.V)

If you're too unfamiliar with vector math, you might want to check out SvenB's tutorials:
http://forum.thegamecreators.com/?m=forum_view&t=180223&b=7

Here's what I came up with for the code:




[edit]


Even better: instead of making spheres, instance planes, and in the move code point them towards the camera! way faster!

Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 9th Feb 2011 13:49
Thanks! Will try it all out.

Login to post a reply

Server time is: 2026-07-16 04:36:18
Your offset time is: 2026-07-16 04:36:18