This is a small project I made for a presentation about orbital mechanics a while ago (I used a modified version of this though).
Don't expect this to be polished or working in any way - some of the comments in the code are in German.
Orbit stuff
Orbit stuff
- Attachments
-
- Orbit.love
- (430.98 KiB) Downloaded 338 times
Last edited by Garmelon on Sun Jul 19, 2015 4:00 pm, edited 1 time in total.
Re: Orbit stuff
Could I please ask you to lower your requirements a bit? I highly doubt that you actually need 16x MSAA or the biggest canvas possible in this thing, and the performance loss (as well as the hassle for some people to go and edit your code to actually run this) isn't exactly negligible.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
- qubodup
- Inner party member
- Posts: 775
- Joined: Sat Jun 21, 2008 9:21 pm
- Location: Berlin, Germany
- Contact:
Re: Orbit stuff
I like to use this for paining
http://youtu.be/AefcH3ilnaE
Strange, I thought there was something similar released on the love2d forums recently but I can't find it again.
http://youtu.be/AefcH3ilnaE
Strange, I thought there was something similar released on the love2d forums recently but I can't find it again.
lg.newImage("cat.png") -- made possible by lg = love.graphics
-- Don't force fullscreen (it frustrates those who want to try your game real quick) -- Develop for 1280x720 (so people can make HD videos)
-- Don't force fullscreen (it frustrates those who want to try your game real quick) -- Develop for 1280x720 (so people can make HD videos)
Re: Orbit stuff
Yep, I have seen that one too
Re: Orbit stuff
I have some actual orbital physics stuff written in Lua that you could use? I made it for moai but it would be really easy for you to port to LOVE2d, as all it does is take is two box2d bodies and their properties and outputs a table with a bunch of xy coordinates that you can plug into a line drawer.
Constant should be the universal gravitational constant.
The orbital physics are all from here which you may need to read to understand what is going on. http://www.braeunig.us/space/orbmech.htm
Constant should be the universal gravitational constant.
The orbital physics are all from here which you may need to read to understand what is going on. http://www.braeunig.us/space/orbmech.htm
Code: Select all
function PhysActor:CalculateOrbit()
--This function derives everything you need to know about a single orbiting body.
local bodyPos = Vector.new(self.body:getPosition())
local bodyVel = Vector.new(self.body:getLinearVelocity())
local celPos = Vector.new(self.currentCelestialB.body:getPosition())
--get the velocity of the body
local V = bodyVel:length()
--get the distance from the foci
local R = bodyPos:distanceTo(celPos)
--Get the Zenith Angle
local Anglefrombody = bodyPos:angleTo(celPos)
local bodyFromAngle = celPos:angleTo(bodyPos)
local Angle = math.deg( math.atan2(bodyVel.y,bodyVel.x))
local Zenith = Angle - Anglefrombody
local GM = (constant * self.currentCelestialB.body.fakeMass)
-- tan V = (r1 × v12 / GM) × sin × cos / [(r1 × v12 / GM) × sin2 - 1
--tanV = (6628140*math.pow(7900,2)/3.986005e14) * math.sin(math.rad(89)) * math.cos(math.rad(89)) / ((6628140*math.pow(7900,2)/3.986005e14) * math.pow(math.sin(math.rad(89)),2) - 1)
-- this formula is to locate where the body is from the perrigee
local tanVx = (R*math.pow(V,2)/GM) * math.sin(math.rad(Zenith)) * math.cos(math.rad(Zenith))
local tanVy = ((R*math.pow(V,2)/GM) * math.pow(math.sin(math.rad(Zenith)),2) - 1)
local tanV = math.atan2(tanVx,tanVy)
local tanVDeg = math.deg(tanV)
local PerigeeFromZeroAngle = bodyFromAngle - ( tanVDeg - 180) --WOOO!
local PerigeeFromZeroAngle = bodyFromAngle - tanVDeg --WOOO
local C = (2 * GM) / (R* math.pow(V,2))
local Rh = (-C + math.sqrt( math.pow(C,2) - 4 * (1-C) * -math.pow(math.sin(math.rad(Zenith)),2) )) / (2*(1-C))
local Rl = (-C - math.sqrt( math.pow(C,2) - 4 * (1-C) * -math.pow(math.sin(math.rad(Zenith)),2) )) / (2*(1-C))
local Rlower = math.min(Rh,Rl)
local Rhigher = math.max(Rh,Rl)
local PerigeeRadius = R * Rlower
local ApogeeRadius = R * Rhigher
--Eccentricity
--e = SQRT[ (r1 × v12 / GM - 1)2 × sin2 + cos2 ]
local E = math.sqrt( math.pow((R * math.pow(V,2)/ GM -1),2) * math.pow(math.sin(math.rad(Zenith)),2) + math.pow(math.cos(math.rad(Zenith)),2))
--SEMI MAJOR AXIS
--a = 1 / ( 2 / r1 - v12 / GM )
local SemiMajorAxis = 1/(2 / R - math.pow(V,2) / GM)
--theta = E * math.sin(math.rad(225)) / (1 + E * math.cos(math.rad(225)))
--theta = 0.1 * math.sin(math.rad(225)) / (1 + 0.1 * math.cos(math.rad(225)))
--theta = math.atan(theta)
self.predictedPoints = {}
self.predictedPoints2 = {}
self.perigee = {}
self.currentAng = {}
-- print("Vel:"..V)
-- print("initDist"..R)
--print("perigeeFromZero:"..PerigeeFromZeroAngle,tanVDeg)
-- print("eccentricity:"..E)
-- print("PerigeeRadius:"..PerigeeRadius)
-- print("ApogeeRadius:"..ApogeeRadius)
-- print("SemiMajorAxis:"..SemiMajorAxis)
-- print("C:"..C)
-- print("Zenith:"..Zenith)
-- print("Velocity:"..V)
self.perigee[1] = 0
self.perigee[2] = 0
self.perigee[3] = math.cos(math.rad(PerigeeFromZeroAngle))*(PerigeeRadius)
self.perigee[4] = math.sin(math.rad(PerigeeFromZeroAngle))*(PerigeeRadius)
self.currentAng[1] = 0
self.currentAng[2] = 0
self.currentAng[3] = math.cos(math.rad(PerigeeFromZeroAngle+tanVDeg))*(PerigeeRadius)
self.currentAng[4] = math.sin(math.rad(PerigeeFromZeroAngle+tanVDeg))*(PerigeeRadius)
for i=1,361 do
Vang = i
--V is angle from perrigee
PointDist = SemiMajorAxis * (1- math.pow(E,2)) / (1+ E * math.cos(math.rad(Vang)))
PointAngle = Vang + PerigeeFromZeroAngle
--PointAngle = Vang
Point = Vector.new(PointDist*math.cos(math.rad(PointAngle)),PointDist*math.sin(math.rad(PointAngle)))
table.insert(self.predictedPoints,Vang+800)
table.insert(self.predictedPoints,PointDist/10)
table.insert(self.predictedPoints2,Point.x)
table.insert(self.predictedPoints2,Point.y)
end
end
- Ranguna259
- Party member
- Posts: 911
- Joined: Tue Jun 18, 2013 10:58 pm
- Location: I'm right next to you
Re: Orbit stuff
This looks like this.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Orbit stuff
My computer (Mac Book Air) can't create the canvas your game requests.Nixola wrote:Could I please ask you to lower your requirements a bit? I highly doubt that you actually need 16x MSAA or the biggest canvas possible in this thing, and the performance loss (as well as the hassle for some people to go and edit your code to actually run this) isn't exactly negligible.
When I write def I mean function.
Re: Orbit stuff
I used the canvas initialisation part of that thing...Ranguna259 wrote:This looks like this.
Re: Orbit stuff
Same problem on latest XUbuntu with MSI GTX 650.
Who is online
Users browsing this forum: No registered users and 2 guests