Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Orbit ?  (Read 533 times)
0 Members and 1 Guest are viewing this topic.
Offline GNecro1
« Posted 2013-08-27 21:37:54 »

I cant find and cant think of how do make one object orbit another and another object orbit that object
it is to complex look at planet simulator http://dan-ball.jp/en/javagame/planet/ doesn't matter how much objects are there it runs smooth and it is stable. I was always been interested in simulation games and sandbox games
but to make one that is so hard
does any of you people know any way to make this kind of simulator work ?

JAVAAAAAAAAAAAAAAAA Freak Cheesy!
Offline lcass
« Reply #1 - Posted 2013-08-27 21:56:13 »

You would need to understand basic phsyics principles such orbital mechanics, something like that would just assume the data.
Offline GNecro1
« Reply #2 - Posted 2013-08-27 22:53:35 »

yea i can make something orbit but when i have like 5 objects my frame rate drops by half

JAVAAAAAAAAAAAAAAAA Freak Cheesy!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline PaidGEEK

Senior Member


Medals: 5
Projects: 3


twitter.com/PaidGEEK


« Reply #3 - Posted 2013-08-27 23:16:36 »

Just make a "planet" class where you have vector for position and velocity. In update method you can iterate through other planets, calculate angle to this one and apply some speed into that direction (of course you have to keep in mind that a=m/s^2). You could also work with mass for more realistic simulations. For user's control you'd just apply some custom speed to any planet.

Improvisational programmer.
Offline namrog84

JGO Ninja


Medals: 46
Projects: 4


Keep programming!


« Reply #4 - Posted 2013-08-27 23:34:29 »

If you are having 5 objects and dropping frame rates like that, there is something much more seriously wrong there.

you should be able to many hundreds, possibly thousands without too much of an issue.


Post some sample code and maybe we can help identify the issue?  Huh

"Experience is what you get when you did not get what you wanted"
Offline Several Kilo-Bytes

Senior Member


Medals: 11



« Reply #5 - Posted 2013-08-27 23:56:51 »

position = x
velocity = x'
acceleration = x''

Newton's first law: F/m = x''

Force due to gravity is proportional to the mass of each object and inversely proportional to the square of the distance between two objects.

The equations work for scalar and vector numbers. Use vectors and you won't have to worry about angles. The number of interactions is O(n^2), so something is wrong if that is too slow for values between 1 and 30. You could choose to ignore the pull of small or very distant planets and make very massive objects unaffected by acceleration, but that should not be necessary for small numbers of planets.

Edit: What namrog84 said.
Offline kramin42
« Reply #6 - Posted 2013-08-28 05:27:08 »

For each planet/star have at least position, velocity and mass. Also have a gravitational constant, G (just arbitrarily set this to something that works).

Then you can update the objects like so (pseudocode):

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
for i=1 to n: //go through all the planets
   for j = 1 to n: //add up the gravitational effects of all the other planets
       if i==j:
            continue
        end
        dist = sqrt((planet[i].x - planet[j].x)^2 + (planet[i].y - planet[j].y)^2)
        accMag = G*planet[j].mass/(dist^2)
        accX = accMag*(planet[j].x - planet[i].x)/dist
        accY = accMag*(planet[j].y - planet[i].y)/dist
        planet[i].vx += accX
        planet[i].vy += accY
    end
    planet[i].x += planet[i].vx
    planet[i].y += planet[i].vy
end

dist = distance between the planets, accMag = acceleration magnitude, accX = x component of the acceleration, vx = x velocity

Remember, planet i is the planet you are calculating the acceleration of, and planet j is the planet it is being attracted to.

Also, I'm not sure what you're doing already, but x and y need to be floating point numbers, not integers.

Check out these wikipedia articles too:
http://en.wikipedia.org/wiki/Orbital_mechanics
http://en.wikipedia.org/wiki/Orbit_equation
http://en.wikipedia.org/wiki/Newton's_law_of_universal_gravitation

"All science is either physics or stamp collecting." - Ernest Rutherford.
CodeGolf4k
M4nkala
Offline zngga
« Reply #7 - Posted 2013-08-28 05:37:54 »

http://www.java-gaming.org/topics/planet-orbiting-algorithm/26788/msg/236703/view.html#msg236703

My code never has bugs... it just develops unexpected features!
Offline kramin42
« Reply #8 - Posted 2013-08-28 05:54:15 »

That works perfectly for two bodies, but if you want a simulation of three or more its not as simple as that.

"All science is either physics or stamp collecting." - Ernest Rutherford.
CodeGolf4k
M4nkala
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (18 views)
2014-07-30 21:08:39

Riven (24 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (33 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (43 views)
2014-07-24 01:59:36

Riven (43 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!