bouncing

Blitz3D Forums/Blitz3D Programming/bouncing

Ben(t)(Posted 2008) [#1]
How can i do it in blitz3d?


Matty(Posted 2008) [#2]
http://blitzbasic.com/codearcs/codearcs.php?code=670


Ben(t)(Posted 2008) [#3]
umm I feel dumb, how would i implement that code?


Charrua(Posted 2008) [#4]
hi

any one gets in that state with vectors at first!

the dot product (this formula) if both vectors are normalized (have a length of 1) gives the asin of the angle between both vectors

if you know the angle that forms the way the ball is going respect of the face of the bodie wiht it has collided, then you can calculate the angle of going out.

That is the part of: NFx# = -2.0 * Nx# * VdotN# in each axis
(i dont analize the code totaly, but I supose that -2.0 is to get the reverse angle)

finally, sum the original motion vector (that your program keeps track?) to the calculated to obtain the new motion vector

Juan


note:
lenght as pitagoras say is sqrt(x*x + y*y + z*z)

(hope my traslation to english do not confuse, more than the vectors themselves)


Charrua(Posted 2008) [#5]
Hi again
I keep bouncing with this question
last month i've done some research in the 3d maths and as a test I write some functions to work with vectors, that's the first real application that I have so, this is the code:

hope you enjoy

probably I've to put in the code archives (?)



thank jv-ode for the floor (i stole from)
sorry, is in spanish, but the names are practically the same.

Rebote : gives the bouncing factor
VelocidadLineal: is afected (reduced if Rbote is less than 1) in each bounce.

the rest I think is self explanatory (??)

best regards

Juan


Axel Wheeler(Posted 2008) [#6]
ben(t):

Bouncing can be easy or hard, depending on the complexity of the bouncing you want.

If you don't need to consider the shape of the bouncing object (i.e. a ball) AND the object it is hitting is flat and not moving (i.e. the floor or a wall) then you just need to:

1. Detect when the ball has passed into the wall (and how far) using collisions or your own checking.

2. Move the ball that same distance away from the wall and switch the sign of the speed in that direction (x,y, or z).

At the opposite extreme of complexity, for example if the bouncing object must rotate depending on where it is hit, you are probably better off with a physics engine like Tokamak.

The two approaches posted above by Matty and Charrua seem to be somewhere in the middle; the surface(s) are convoluted and you need to figure the new direction of the object(s), but not the new rotation speed.

That's three different scenarios with different solutions!

Hope this helps.


Charrua(Posted 2008) [#7]
I agree,
I just try to explain the code refered by the link proposed, and forgot the purpose of the post, thank's axel!

Juan


Ben(t)(Posted 2008) [#8]
Im still a little confused.
Im trying to do physics with balls that bounce by changing their pitch and yaw.
I know angle in equals angle out, but i dont know how to implement that in my code


Charrua(Posted 2008) [#9]
hi

Ok, you have the pitch, yaw and roll of your ball, and probably you use moveentity ball,0,0,ForwardVel so it moves in the direction it faces.

You check for collisions, then, you get the normal: x,y,z wich you can translate to pitch, yaw and roll (see VectorYaw and VectorPitch), with this info, you can calculate the angle out.

Realign the ball and adjust ForwardVel according to the bouncing_factor you wish from the material of the ball and the object that has collided.

As Axel say, with this method, we only change direction and say nothing about angular velocity: the ball don't rotate relative to it's center due to the collisions.

Hope that helps

Juan