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.

Newcomers DBPro Corner / Evil Physics (those who are mathematically minded help)

Author
Message
KamaKase
21
Years of Service
User Offline
Joined: 29th Oct 2002
Location:
Posted: 15th Apr 2003 15:06
Hmmm, gosh darn it.
I have spent the last few nights working on some "bounce" physics.
I have an object in 3d space (it only moves along the x and y axis though so ignore the z). There is also a panel, who's angle rotates.
(If it's possible) I need a general formula from this:


I've spent ages on it. I've worked out a few things, but I can't seem to get my head round it. I only know basic trig. Please help!!
trager
21
Years of Service
User Offline
Joined: 5th Feb 2003
Location: United Kingdom
Posted: 15th Apr 2003 16:40
I can't quite work out what you're after from this diagram, but I did write a tutuorial a while back demonstrating high speed physics reactions and collision testing and it look kinda simular take a look.

http://www.darkbasicpro.com/apollo/view.php?t=5699&b=6
I never finished it, noone was interested.

Hope it helps though
ST

There is no answer only more questions.
kevil
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: Netherlands
Posted: 15th Apr 2003 16:58
Well, I know a bounce formula (I used it for my grenade physics snippet in the darkbasic discussion board.)
If you have a speed vector and a normal vector of the object to bounce of (can be easily calculated), Then you can find the new vector using the following formula:

-2.00 * n * dot(n,v) + v

In this formula, n is the normal vector, v is the speed vector and dot(n,v) is the dot product of the two vectors (vx*nx + vy*ny).

I hope you understand this. Maybe you could take a look at my snippet to understand it better.

Kevil

KamaKase
21
Years of Service
User Offline
Joined: 29th Oct 2002
Location:
Posted: 15th Apr 2003 17:10
ARGH!!! I looked at your code and...blimey. grrrrrr...
The black line is the object that the ball will hit, which is rotated around the z axis.
The red lines are x and y axis.
The object is basically a flat line and is then rotated from there.
The ball is situated in the center of the axis (which don't actually exist).
It has collided with the flat object.
I'm using the point object and move object commands to move the ball (is that wrong, would it be easier if I did something else??).
I need the co-ordinates of the point object (the lower green blob) to move to the co-ordionates of the one of the left by a general formula.

Hmmmmm, dang that sounds hard.
Flashing Blade
21
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 15th Apr 2003 18:00
i don't know exactly what you trying to do but point and move object for something like a ball is not best way to control its physics.
You'd probably be best having 3 variables for each velocity ie xvel# yvel# zvel#. Then manipulating the velocities of the ball rather than the angles.
trager
21
Years of Service
User Offline
Joined: 5th Feb 2003
Location: United Kingdom
Posted: 15th Apr 2003 18:04
thats what my demo does isnt it?
whats the problem with it?

There is no answer only more questions.
kevil
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: Netherlands
Posted: 15th Apr 2003 18:09
Ow, obviously you don't know much about vectors. Let's give you an easier method. Let me think.

First you need to know the speed vector. Normally if you want to use physics in a game, it's not very easy if you use the point object command. You should use vectors (x-speed and y-speed), but I'll show you a way without them. We can get the speed vector with the following code. (DB-code, I don't have DBPro, I hope it's the same)
If the object number is 1:

vx#=sin(object angle z(1))
vy#=cos(object angle z(1))

Now we need to get the normal of the line. If the line is the same as in the picture, the z-rotation should be zero.
If the line is object 2:

nx#=sin(object angle z(2))
ny#=cos(object angle z(2))

Now we can calculate the dot product of the two vectors:

dot#=(vx#*nx#)+(vy#*ny#)

With that we can calculate the new vector with the formula above.

nvx#=(-2.00*nx#*dot#)+vx#
nvy#=(-2.00*ny#*dot#)+vy#

And now to use the point command again (with object 1).

point object 1,object position x(1)+nvx#,object position y(1)+nvy#,object position z(1)

And that should be it. I hope you understand it a bit now, and I hope I haven't made any mistakes here.

Kevil

trager
21
Years of Service
User Offline
Joined: 5th Feb 2003
Location: United Kingdom
Posted: 15th Apr 2003 18:16
Kevil the demo I asked him to look at is simular a few tricks thrown in for good measure.

This is it

There is no answer only more questions.
kevil
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: Netherlands
Posted: 15th Apr 2003 18:30
Ok, the way I described in my post above is a bit overcomplicated for what you want. I posted it, because it can be used in 3d too to bounce of a plane. I believe the formula your looking for is:

zrotate object 1,180-object angle z(1)+(2.0*object angle z(2))

That looks a lot easier, doesn't it.

trager:
This is it? What is "this"?


Kevil

KamaKase
21
Years of Service
User Offline
Joined: 29th Oct 2002
Location:
Posted: 15th Apr 2003 19:53
I saw your code trager. Didn't understand a word of it. Rather than being shown what to do, (if it's complicated). I like to know why you do what. It's good code though. A bit too much for me though...
KamaKase
21
Years of Service
User Offline
Joined: 29th Oct 2002
Location:
Posted: 15th Apr 2003 19:58
Thnx for the help kevil. I guess my method was impractical, hmmm. I'll try the vectors.
Thanx everyone!
trager
21
Years of Service
User Offline
Joined: 5th Feb 2003
Location: United Kingdom
Posted: 15th Apr 2003 20:37
@kevil
attached source code

@KamaKase
np

There is no answer only more questions.
kevil
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: Netherlands
Posted: 15th Apr 2003 22:01
trager:
Hehe, didn't know about the source button yet, didn't know it existed LOL . Now I see it though. Nice example code, but I think it would appeal to more people if it was actually moving.

Kevil

trager
21
Years of Service
User Offline
Joined: 5th Feb 2003
Location: United Kingdom
Posted: 16th Apr 2003 00:23
@Kevil
I think the source button is new, added in the last week or so.

Yeah it probably would be more appealling I do have a simpler version that does move only the static version was meant as a tutorial and is easier to understand. Well I think so anyhow.

Thanks
ST

There is no answer only more questions.
Richard Barnes
21
Years of Service
User Offline
Joined: 15th Apr 2003
Location: Canada
Posted: 16th Apr 2003 02:40 Edited at: 16th Apr 2003 02:44
When you say, "bounce", do you mean degrading ballistics arcs? For example a ball throw against the ground will rebound with a force representative of the elastic properties of the object until gravity pulls it back down causing a collision with the ground to send the object back up along the path with decreased force. Kind of like this



You will need to track the following in your program

Force (Velocity)
Gravity
Angle

I suspect to keep it simple you could say that every time your object hits the ground plain it looses X amount of force (depending upon the object elasticity and density) this will give you the amount of force to use in a the second calculation. (You allready have the angle that it will follow out for all rebounds happen at an equel angle as the incoming hit.)



Above is the formula for ballistics as we use it here at the shop. I will be posting an article over on DBDN soon, and once everybody has told me where I screwed it up I will post it over here.

Richard

"Aut viam inveniam aut faciam."
(I'll either find a way or make one.)
trager
21
Years of Service
User Offline
Joined: 5th Feb 2003
Location: United Kingdom
Posted: 16th Apr 2003 12:11
I think he means collision reaction

Nice post though

There is no answer only more questions.
Richard Barnes
21
Years of Service
User Offline
Joined: 15th Apr 2003
Location: Canada
Posted: 16th Apr 2003 17:54
Collison reaction is quite a bit diffrent, sorry guess I lost the thread.

Richard

"Aut viam inveniam aut faciam."
(I'll either find a way or make one.)
KamaKase
21
Years of Service
User Offline
Joined: 29th Oct 2002
Location:
Posted: 17th Apr 2003 02:55
I'm kinda glad that wasn't what I was looking for. It looks like I've got quite a few hellish Physics lessons ahead of me. THx any way though!!

Login to post a reply

Server time is: 2024-09-20 06:37:54
Your offset time is: 2024-09-20 06:37:54