Jump to content

Orbiting planets...


webGLmmk
 Share

Recommended Posts

Using a playground scene originating from this post/thread: @wingnut

 

adding another planet:

https://www.babylonjs-playground.com/#2FPT1A#157

and I'm trying to figure out how to get  the planets to start at different locations along the orbit. I understand how adjusting the x and z parameters inside the planet.position =Vector3  INSIDE the registerBeforeRender adjusts the orbit path itself, making it oblong etc....right now im just sticking with the same circular orbit. I just want the outer green planet to start at a different place, perhaps off to the right. Setting the position outside the registerBeforeRender does nothing - it gets overridden by the position inside RegisterBeforeRender. Im not sure if what Im missing is related to that function, or what....i tried a few things but without 100% understanding of whats going on here...Trig skills a bit weak, working on that...

 

Link to comment
Share on other sites

Ok so simply by playing with the numbers, I got it to do what I wanted to do. https://www.babylonjs-playground.com/#2FPT1A#158

There are now two variables, alpha, and alpha 2, they both store Math.PI. Outside the renderBeforeeRegister function.

Inside the rendereBeforeRegister function, lines 87 and 90. set the  planet into orbit  with the parameters passed into X Y and Z.

I got what I wanted it to do by increasing the number of radians passed into Math.sin & Math.cos: (alpha + 2, or whatever).  Going to be struggling for a while to understand this entire line of code, and why it works...any direction or insight on that would be very much appreciated,  like, Why is it that If these lines are NOT inside registerBeforeRender, the planets don't orbit......tho I"m sure other posts have more pressing issues ... :D

back to the unit circle...?

 

Link to comment
Share on other sites

Sorry you have had to wait for a while for a reply.

Hope this helps.

Babylon.js draws or renders a frame up to 60 times a second. Where and at what angle a mesh is drawn depends on values you have set for position and rotation. RegisterBeforeRender updates any values set within this loop before drawing the next frame. So anything out side this loop is set on the first render call unless registerBeforeRender updates it. If registerBeforeRender does not change a particular value then this remains the same for every frame.

By incrementing the angle inside the registerBeforeRender loop this increments the rotation each frame for an orbiting planet.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...