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.

Dark Physics & Dark A.I. & Dark Dynamix / DarkPhysics // Gravity ...

Author
Message
Philip
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 14th Mar 2007 23:24 Edited at: 14th Mar 2007 23:26
Sir Sydney Smith once ruefully observed that as he had sunk by his levity, others seemed to have risen by their gravity.

That is not much to do with this post. But I admire wit and so I thought I'd quote it.

Anyway let me begin by saying how much I like DarkPhysics. I really think Mike has excelled himself and not just in coding this expansion pack but also in writing some of the best explanatory notes I have yet read for an expansion.

My question relates to gravity. As far as I can tell, DarkPhysics has one default command - set gravity. This sets a constant vector for the physics engine, i.e. it applies to all objects when the phy update command is called? By default it assumes the gravitational vector felt by objects on the surface of earth, i.e. downwards on their local Y axis.

My question is can DarkPhysics simulate a point gravity for multiple objects, i.e. the sort of gravity that planets endure from the sun or what a black hole produces?

Putting it another way, is there a command which allows me to say, for example, that XYZ coords 0, 0, 0 have a gravitational effect in every direction of x units per unit of time?

I know I could redefine the set gravity command each game loop by reference to the vector of one object towards the XYZ coords. But the problem with that is that it will produce an inaccurate result for an object at a different location, which has a different vector towards the same XYZ coords.

At present in my game I am producing the same mathematical result by calculating the vector from each object to the gravitational point each game loop, then applying the inverse square rule to the gravitational vector to give the vector representing the gravitational pull, which I turn apply to the momentum vector of the object.

Cheer if you like bears! Cheer if you like jam sandwiches!
"I highly recommend Philip" (Philip)
Philip
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 14th Mar 2007 23:47
EDIT: ok, the phy add rigid body force command does the business.

Here is an interesting example of point gravity acting (rather fast) on various objects moving under their own momentum


phy start
sync on
sync rate 0
autocam off
color backdrop 0

for i = 1 to 20

make object cube i, 5
position object i, rnd(20) - 20, rnd(20) - 20, rnd(20) - 20
phy make rigid body dynamic box i
phy set rigid body linear velocity i, rnd(10) - 10, rnd(10) - 10, rnd(10) - 10

next i

phy set gravity 0, 0, 0
position camera 0, 200, 30, 200
point camera 0, 0, 0

null = make vector3(1)

do

for i = 1 to 20

set vector3 1, 0 - object position x(i), 0 - object position y(i), 0 - object position z(i)
normalize vector3 1, 1
rem multiply vector3 1, 5
phy add rigid body force i, x vector3(1), y vector3(1), z vector3(1), 5

next i


phy update

sync

loop

phy end
flush video memory
end

Cheer if you like bears! Cheer if you like jam sandwiches!
"I highly recommend Philip" (Philip)
Codger
21
Years of Service
User Offline
Joined: 23rd Nov 2002
Location:
Posted: 15th Mar 2007 07:20
Philip
As you have already realized the gravity command is vector based rather than point based. I.e you can fall down a tunnel through the earth but you will never pass the center of mass. Also objects do not contain their own mass and therefore cannot create their own gravity. No black holes no neutron stars etc what a shame... maybe we can add it to our wish list for the update.

Codger

p.s cool demo

System
PIV 2.8 MZ 512 Mem
FX 5600 256 mem
zircher
21
Years of Service
User Offline
Joined: 27th Dec 2002
Location: Oklahoma
Posted: 16th Mar 2007 05:53
Still, it is a clever bit of code and I enjoyed watching the blocks go into orbit all on their own. It would make for a good start to a space war game.
--
TAZ

"My goal is to replace my soul with coffee and become immortal." -- Wally
Xarshi
18
Years of Service
User Offline
Joined: 25th Dec 2005
Location: Ohio
Posted: 16th Mar 2007 21:17
ok,thankyou so much for showing how to do that stuff. I have been trying to get gravity points for so long,and you just gave an example of how to do it. Thanks dude. This is another thing I wanna keep track of for something I'm working on. This makes me extremely happy btw

Hello
Philip
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 17th Mar 2007 18:30 Edited at: 17th Mar 2007 19:16
@Codger

Quote: "As you have already realized the gravity command is vector based rather than point based. I.e you can fall down a tunnel through the earth but you will never pass the center of mass. Also objects do not contain their own mass and therefore cannot create their own gravity. No black holes no neutron stars etc what a shame... maybe we can add it to our wish list for the update.
"


You can code black holes and neutron stars in DBPro. In fact, if you do a search of the forums, you'll find some simple code I posted a while ago that provides a simple simulation of a black hole's effect on particles. That was before DarkPhysics was published by TGC.

Please don't read too much into my use of the word "point" above. I was being sloppy in my use of terminology. What I should have accurately said is the centre of mass of the object generating its gravitational field. Naturally gravity is invariably expressed as a vector because it is essentially equivalent to acceleration, applying Newtonian classical physics.

Cheer if you like bears! Cheer if you like jam sandwiches!
"I highly recommend Philip" (Philip)
Philip
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 17th Mar 2007 19:16
And here is some code showing the effect of multiple gravity vectors on multiple objects. The arrow keys alter the gravity of two of the spheres.

phy start
sync on
sync rate 60
autocam off
color backdrop 0

make matrix 1, 500, 500, 100, 100
position matrix 1, -200, -50, -200

Rem PJY - we're going to have 20 cube objects plus 4 sphere objects.
Rem PJY - the 20 cube objects are low mass things flying about in space whereas
rem PJY - the 4 sphere objects are large mass things of fixed XYZ location.
Rem PJY - the spheres will be coloured red
Rem PJY - essentially this code simulates the effect of the 4 spheres' gravity
Rem PJY - on the 20 cubes

for i = 1 to 20

make object cube i, 5
position object i, rnd(20) - 20, rnd(20) - 20, rnd(20) - 20
color object i, rgb(rnd(255), rnd(255), rnd(255))
set object light i, 1
set object ambient i, 1
phy make rigid body dynamic box i
phy set rigid body linear velocity i, rnd(10) - 10, rnd(10) - 10, rnd(10) - 10
phy set rigid body mass i, rnd(6) + 1

next i

for i = 21 to 24

make object sphere i, 10
position object i, rnd(50) - 50, rnd(50) - 50, rnd(50) - 50
color object i, rgb(255, 0, 0)
set object light i, 1
set object ambient i, 1
phy make rigid body dynamic sphere i
phy set rigid body mass i, 100

next i

Rem PJY - get rid of the default gravity
phy set gravity 0, 0, 0
position camera 0, 150, 30, 150
point camera 0, 0, 0

mass = 100
mass1 = 100
mass2 = 100
null = make vector3(1)

repeat

Rem PJY - update the boxes
for i = 1 to 20

for j = 1 to 4

set vector3 1, object position x(25 - j) - object position x(i), object position y(25 - j) - object position y(i), object position z(25 - j) - object position z(i)
normalize vector3 1, 1
if j = 1 then multiply vector3 1, mass
if j = 2 then multiply vector3 1, mass
if j = 3 then multiply vector3 1, mass2
if j = 4 then multiply vector3 1, mass1
phy add rigid body force i, x vector3(1), y vector3(1), z vector3(1), 5

next j

next i

if upkey() > 0

color object 21, rgb(0, 255, 0)
mass1 = 200
phy set rigid body mass 21, mass1

endif

if downkey() > 0

color object 21, rgb(255, 0, 0)
mass1 = 100
phy set rigid body mass 21, mass1

endif

if leftkey() > 0

color object 22, rgb(0, 255, 255)
mass2 = 400
phy set rigid body mass 22, mass2

endif

if rightkey() > 0

color object 22, rgb(255, 0, 0)
mass2 = 100
phy set rigid body mass 22, mass2

endif

text 0, 0, "mass1 & 2: " + str$(mass1) + " " + str$(mass2)

phy update

sync

until spacekey() > 0

null = delete vector3(1)

phy end
flush video memory
end

Cheer if you like bears! Cheer if you like jam sandwiches!
"I highly recommend Philip" (Philip)
Codger
21
Years of Service
User Offline
Joined: 23rd Nov 2002
Location:
Posted: 17th Mar 2007 21:35 Edited at: 17th Mar 2007 22:01
here is my version of the gravity effect i have included mass in the equation. As it is set up now I have used object 1 and 2 as massive objects to demonstrate a binary system.



@Phillip
I noticed that you have posted a new example i will test that next


codger

edit I modified code to remove binary system code

System
PIV 2.8 MZ 512 Mem
FX 5600 256 mem
Codger
21
Years of Service
User Offline
Joined: 23rd Nov 2002
Location:
Posted: 17th Mar 2007 22:12 Edited at: 17th Mar 2007 22:13
@phillip

You need to test all object against all objects. this is the effect that causes stars to wobble. (Theoretically the smallest grain of sand pulls on distant galaxies .. is that cool or what)

I am unsure of how to apply the mode which is the last parameter in

[quote]phy add rigid body force ID, forceX#, forceY#, forceZ#, mode

so i chose 3 instead of the 5 I thought it was closer to visually acurate

System
PIV 2.8 MZ 512 Mem
FX 5600 256 mem
Philip
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 17th Mar 2007 23:33 Edited at: 17th Mar 2007 23:36
Quote: "You need to test all object against all objects. this is the effect that causes stars to wobble."


Yes, the famous Einsteinian gravitational lensing effect. Don't worry - I do understand most physics up to about M theory, where I got lost with Ed Wittens' equations! My example doesn't go as far as applying gravity to everything in the model for the simple reasons that I couldn't be bothered to go to much effort for a very simple demo.

It might be nice to see if anyone would like to set up a simple example of our solar system, shown to scale and with correct masses included, to see if they can model the ways the planets elliptically orbit the sun. Angular momentum would have to be included of course.

Cheer if you like bears! Cheer if you like jam sandwiches!
"I highly recommend Philip" (Philip)
Codger
21
Years of Service
User Offline
Joined: 23rd Nov 2002
Location:
Posted: 17th Mar 2007 23:57
Quote: "It might be nice to see if anyone would like to set up a simple example of our solar system, shown to scale and with correct masses included, to see if they can model the ways the planets elliptically orbit the sun. Angular momentum would have to be included of course"


The real snag would be the time scale to view it over. I would hate to have to wait for 5 billion years to see if it came out correctly. Or even a year to see if the orbit of the earth is approximately correct

Basically you can readily test all object against each other in a nested loop as I did in my code snippet which does show the more massive object wobbling

System
PIV 2.8 MZ 512 Mem
FX 5600 256 mem
Philip
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 18th Mar 2007 00:47
Time doesn't have to be a snag. I'm not suggesting that the model be in real time. Its fairly straightforward to recalculate the results of the Kepler equations assuming different time periods are passing, i.e. one game loop = 1 second or one game loop = 1 year. Lots of programmes do this. See, for example, Celestia or even David Braben's Frontier.

Cheer if you like bears! Cheer if you like jam sandwiches!
"I highly recommend Philip" (Philip)
Hoozer
17
Years of Service
User Offline
Joined: 8th Sep 2006
Location: Bremerhaven (Germany)
Posted: 18th Mar 2007 02:09 Edited at: 18th Mar 2007 02:22
What a cool thread!

@ Philip: Well, as far as I had a look at your code (from the "Upgrade-Thread"), I must say it is (more or less) exactly the way I did it in my "PhysiX-Brick-Breakout"-game! (I only used one grav-field at a time, so no "grav-field-array" was used!) But the array is exactly what I was thinking about today!

For a long time I have thought about making a solar-system-experiment with gravity, but never had time to try it out! Just about 3 hours ago I was thinking how it would look like, if it is done right, and made some plans (which probably will never be executed)! If someone of you two tries it, please show the demo to us all! (The source-code isn't that important, I just would like to see it in action!)

(I'm sure this thread will grow soon! Seems like already some of the "grav-fans" have found together and I think there are more to come!)


Hoozer

AMD 64X2 4800+ (939); 2GB; GF 6800LE (@12PS, 6VS; 380 MHz, RAM: 434 MHz)
DP-Sw-Mode-Comp-Entry (updated to V. 1.3):
http://forum.thegamecreators.com/?m=forum_view&t=93582&b=5
Philip
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 18th Mar 2007 13:09
Take a look at Morcilla's MPL3D program in the program announcements forum. He's already modelled the solar system using DBPro.

Cheer if you like bears! Cheer if you like jam sandwiches!
"I highly recommend Philip" (Philip)
Hoozer
17
Years of Service
User Offline
Joined: 8th Sep 2006
Location: Bremerhaven (Germany)
Posted: 18th Mar 2007 15:15 Edited at: 18th Mar 2007 15:16
@ Philip: I had a look at it, as far as I can say it simulates no physics or am I wrong? It simulates "everything" (rotations, distances, etc.) else, but without physics or not?

Nevertheless there are some really nice pictures, infos and ideas in that thread!


Hoozer

AMD 64X2 4800+ (939); 2GB; GF 6800LE (@12PS, 6VS; 380 MHz, RAM: 434 MHz)
DP-Sw-Mode-Comp-Entry (updated to V. 1.3):
http://forum.thegamecreators.com/?m=forum_view&t=93582&b=5
Philip
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 18th Mar 2007 15:27
Morcilla is obviously the person to talk to but I understood that it did simulate using classical physics the movement of the planets around the suns etc.

Cheer if you like bears! Cheer if you like jam sandwiches!
"I highly recommend Philip" (Philip)

Login to post a reply

Server time is: 2024-04-19 17:18:04
Your offset time is: 2024-04-19 17:18:04