Orbit stuff

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
Garmelon
Prole
Posts: 19
Joined: Tue Jun 02, 2015 5:25 pm

Orbit stuff

Post by Garmelon »

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.
Attachments
Orbit.love
(430.98 KiB) Downloaded 321 times
Last edited by Garmelon on Sun Jul 19, 2015 4:00 pm, edited 1 time in total.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Orbit stuff

Post by Nixola »

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
User avatar
qubodup
Inner party member
Posts: 775
Joined: Sat Jun 21, 2008 9:21 pm
Location: Berlin, Germany
Contact:

Re: Orbit stuff

Post by qubodup »

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.
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)
User avatar
Garmelon
Prole
Posts: 19
Joined: Tue Jun 02, 2015 5:25 pm

Re: Orbit stuff

Post by Garmelon »

Yep, I have seen that one too
Muzz
Citizen
Posts: 54
Joined: Sun Jun 28, 2015 1:24 pm

Re: Orbit stuff

Post by Muzz »

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

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
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: Orbit stuff

Post by Ranguna259 »

This looks like this.
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Orbit stuff

Post by kikito »

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.
My computer (Mac Book Air) can't create the canvas your game requests.
When I write def I mean function.
User avatar
Garmelon
Prole
Posts: 19
Joined: Tue Jun 02, 2015 5:25 pm

Re: Orbit stuff

Post by Garmelon »

Ranguna259 wrote:This looks like this.
I used the canvas initialisation part of that thing...
User avatar
raingloom
Prole
Posts: 36
Joined: Wed Apr 22, 2015 12:35 am
Location: Always elsewhere

Re: Orbit stuff

Post by raingloom »

Same problem on latest XUbuntu with MSI GTX 650.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 1 guest