Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rel can you pls explain something in your bouncing ball demo
#1
I became intrested in understanding how balls bounce when i downloaded your demo.. I read your comments and check Hugo Elias for a tutorial but i won't be happy just because i can do it by copying your code.. I wanna understand how it works and why some calculations are there..

balls(0).xv = COS(balls(0).angle * PI / 180) * balls(0).speed
balls(0).yv = SIN(balls(0).angle * PI / 180) * balls(0).speed

ok, here you split the direction and speed in to two vectors, that i understand..

impactx! = balls(1).xv - balls(0).xv
impacty! = balls(1).yv - balls(0).yv

then you calculate the resulting "force", now the things i don't understand begings..

what do you do when you normalize and what do you do when you returns the dot product between 2 vectors??

can you or somebody else be kind and explain why and what you are doing..
and also the following lines

impulsex! = impulsex! * ImpactSpeed! * balls(0).mass * balls(1).mass / 2
impulsey! = impulsey! * ImpactSpeed! * balls(0).mass * balls(1).mass / 2

xva! = balls(0).xv + impulsex! / balls(0).mass
yva! = balls(0).yv + impulsey! / balls(0).mass

xvb! = balls(1).xv - impulsex! / balls(1).mass
yvb! = balls(1).yv - impulsey! / balls(1).mass

Rel's code can be found at http://forum.qbasicnews.com/viewtopic.php?t=3408

Hope you find some time to explain it to me =)
thx!
ttp://hem.passagen.se/qb.basta
Reply
#2
this:

Code:
balls(0).xv = COS(balls(0).angle * PI / 180) * balls(0).speed
balls(0).yv = SIN(balls(0).angle * PI / 180) * balls(0).speed

Calculates the Balls' x/y velocities(components of the vector)

Balls.speed is just the *Magnitude*/Length of the vector. ie. Speed


I had to divide by 2(Hugo did not) to compensate for the resulting force as it would geometrically speed itself up if I do not.

Code:
impulsex! = impulsex! * ImpactSpeed! * balls(0).mass * balls(1).mass / 2
impulsey! = impulsey! * ImpactSpeed! * balls(0).mass * balls(1).mass / 2

This just calculates the new direction:

Code:
xva! = balls(0).xv + impulsex! / balls(0).mass
yva! = balls(0).yv + impulsey! / balls(0).mass

xvb! = balls(1).xv - impulsex! / balls(1).mass
yvb! = balls(1).yv - impulsey! / balls(1).mass


About:

Normalizing: Normalizing is just making a vector a *unit* vector much like your Unit circle it has a length of 1. Making a vector a unit vector simplifies calcs.

Dot product:

If I remember it's also called the scalar product. The dot product returns the *cosine* of the angle.

Code:
Dot! = (ax! * bx!) + (ay! * by!)

Therefore it returns a scalar and not a vector.

Don't confuse this with the cross product as its returns a vector instead of a scalar.

Makes sense as x or y directions can either be negative,positive or zero. And that's what the dot returns. ;*)

The principle is like lambert's shading but in this case we do not need the NORMAL(perpendicular vector to a plane) as we treated each balls on the pixel they collided as perpendicular.

Perpendicular means it has a union of 90 degrees. 2 vectors intersecting that produces a 90 degree angle.


Scalar means it has no direction just and exact number/value.

I hope I made sense out of it. ;*)

If not just shout. ;*)
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)