Very nice work, i am no e2 programmer but i am learning but just look on wikipedia for all your physics related things
Sorry if it is broken but here is the forumla
I'm currently working on an orbital simulator based on Newton's gravity equation, where you can set the mass and initial velocities of multiple planets. It's working really well so far, but I would like it if someone would look my code over and make sure it implements the laws of physics properly before I add all of the arrays and loops necessary for this to work. It would also be a great help if someone would give me some tips on optimization, because I'm a bit worried about keeping this efficient enough to calculate the gravity between five or six planets at once.
Here's my code so far:
As soon as I get the loops going, that stationary planet will be able to move.Code:@name Orbiter @inputs @outputs @persist Ent:entity GravConstant Pos:vector Vel:vector Mass1 Mass2 @trigger if(first()|duped()){ runOnTick(1) holoCreate(1) holoCreate(2) holoModel(1,"sphere") holoModel(2,"sphere") holoScale(1,vec(2,2,2)) holoScale(2,vec(1,1,1)) Ent = entity() GravConstant = 1 Pos = vec(100,0,100) Mass1 = 500 Mass2 = 1 Vel = vec(-1,2,1) } holoPos(1,Ent:pos()+vec(0,0,100)) Force = (GravConstant*Mass1)/(Pos:distance(vec(0,0,100))^2) Oldpos = Pos Pos = Vel+Pos+(vec(0,0,100)-Pos):normalized()*Force Vel = Pos-Oldpos holoPos(2,Ent:pos()+Pos)
Any help at all would be greatly appreciated.![]()
Last edited by SamPerson12345; 09-05-2009 at 08:40 AM.
I code best at 3 A.M.
Very nice work, i am no e2 programmer but i am learning but just look on wikipedia for all your physics related things
Sorry if it is broken but here is the forumla
Questions, Comments and Concerns about any of
my posts can be directed to my website which is at
http://vbitz.wordpress.com on the comments post
i made a orbiter.
but i used sin() and cos()
e2 Code:
@name Planets @inputs @outputs @persist Counter Spin @trigger all interval(10) if(first()){ holoCreate(1) holoCreate(2) holoCreate(3) } Spin+=2 Counter++ Sinearth = sin(Counter*1.2) Cosearth = cos(Counter*1.2) SinMoon = sin(Counter*10) CosMoon = cos(Counter*10) #Sun Pos1 = entity():pos() + entity():up()*50 holoPos(1,Pos1) holoModel(1,"sphere3") holoColor(1,vec(255,255,0)) holoScale(1,vec(5,5,5)) holoMaterial(1,"debug/debugdrawflat") #Earth Pos2 = entity():pos() + entity():up()*50 + vec(Sinearth*100,Cosearth*100,0) holoPos(2,Pos2 ) holoModel(2,"sphere3") holoColor(2,vec(0,255,150)) holoScale(2,vec(1.2,1.2,1.2)) holoAng(2,ang(0,Spin,0)) holoMaterial(2,"debug/debugdrawflat") #Moon Pos3 = Pos2 + vec( SinMoon*15,CosMoon*15,0) holoPos(3,Pos3) holoModel(3,"sphere3") holoColor(3,vec(255,255,255)) holoScale(3,vec(0.2,0.2,0.2)) holoAng(3,ang(0,Spin,0)) holoMaterial(3,"debug/debugdrawflat")
Is it gravitationally correct?
.siht daer ot gniyrt emit detsaw ev'uoY
Force = (GravConstant*Mass)/(Pos:distance(vec(0,0,100))^2)
You did *Mass nor *Mass1 or *Mass2
.siht daer ot gniyrt emit detsaw ev'uoY
Yes, I know. I did that because I think the gravitational force would be spread out through all of the mass in the planet, so you only need the mass of what it's orbiting around to find out how the gravity would change the velocity. Also, If I had put in both masses, then objects with different masses would fall at different speeds.
I code best at 3 A.M.
I actually already made a basic orbiter, using props though, not holos. The Source engine pretty much does all the work for me.
Heres the code, feel free to modify it. Just give me some credit.
Note that this was made for spacebuild, so it will only work for props if they have no gravity. You do have to manually throw the prop into orbit thoughCode:@name Haloguy's Orbiter @inputs @outputs B @persist R:array A @trigger interval(1) E=entity() O=owner() Rand=(cos(curtime()*10)*127.5)+127.5 timer("update",500) if(first()){holoCreate(1)} if(clk("update")){ holoScale(1,vec(15,15,15)) holoModel(1,"sphere3") findInSphere(E:pos(),100000) findClipToClass("prop_physics") findIncludePlayerProps(O) R=findToArray() } holoPos(1,E:pos()) A++ if(A>R:count()){A=0} Prop=R:entity(A) Vec=E:pos()-Prop:pos() Prop:applyForce(Vec*Prop:mass()/600) holoColor(1,vec(Rand,255-Rand,Rand)) B=R:count()![]()
Originally Posted by Ehmmett
Bookmarks