Jump to content

please help with local versus global positioning for orbiting meshes


elvisior
 Share

Recommended Posts

HI,

I've never done any 3d programming like this before so I'm probably doing something stupid.

I'm messing around with the idea of making an RTS and my stumbling block in developing that is that I can't work out how to place an object on the surface of the planets.  This may be a bad idea but it's fun learning regardless.  I'm blown away by how awesome babylonjs is.

I have made a playground which should place a green sphere on the surface of the planet where you click but the rotation is off...

https://www.babylonjs-playground.com/#7FXSG1#1

Any ideas what I'm doing wrong?  I've read a bunch of the forums posts here and tried some of the other things suggested but they don't seem to apply.

Thanks in advance....

Link to comment
Share on other sites

Hi elvisor, welcome to the forum.  https://www.babylonjs-playground.com/#MZDDK#7

Not a perfect playground, as it doesn't allow click-to-place boxes.  There is a better playground around, but I lost it.  :)

Lines 109-112 do it... rotationFromAxis is the secret, I think.

When you pick/click on a sphere, the pickingInfo object has some "stuff" on it.  One "stuff" is a method called .getNormal().   It is the angle (the normal) of the triangular face that you clicked-on (on the sphere).

That is the angle you need... to place a mesh "orthogonal" or "perpendicular" to the clicked face.  But there is also a pickingRay solution... but I don't know much about that.

Anyway, I did a bunch of forum and playground searching for rotationFromAxis, but again, I am hurried so I did a bad job.  I couldn't find the playground I had in mind.

But maybe... this is enough to help you.  At least you have more to try.  I hope I am on-subject. 

Usually, when programmers want to click mesh onto the surface of a planet, they want it to rotate so that it is perpendicular to the planet surface, and I think that's what you want.

You should use a tall cylinder for testing... instead of a sphere.  A telephone pole.  They are easy to test-with, because... the telephone pole must "stand upright" at the place you picked (for success).  It is easy to see when the rotation is right/wrong.

Hopefully, others are nearby to do further help.  I'll be back later, too... but it is unlikely that I will be any smarter.  :)

Link to comment
Share on other sites

Thanks Wingnut, I think you're helping with a future problem after my current problem though.  I've switched to cylinders as you suggested and regardless of which way the cylinders are standing on the planet surface they're not being placed in the location where I've clicked.

An interesting post I found which seems a little bit similar to the future problem.. but I'm still stuck on the current problem... https://stackoverflow.com/questions/26907686/babylon-js-place-a-plane-normal-to-the-clicked-surface

Edited by elvisior
added a link to another post
Link to comment
Share on other sites

Ohhh... ok, sorry.  When you said "the rotation was off", I thought you meant the rotation on the placed green sphere.  I asked myself "how does he know the rotation is off... when he's using a sphere?"  heh.

You meant... well, I now know what you meant.  Sorry about that.

https://www.babylonjs-playground.com/#7FXSG1#2

I ONLY tried to make your playground a bit simpler, so forum helpers would like it better.  When doing that, it started working better.  hmm.

Yeah, this rocks planet is not spinning/orbiting, and its 'orbitsAround' is disabled.  You are on the right track.  Good troubleshooting, E! 

I think picking... uses a pickingRay from camera to picked-point, and the camera alpha rotation in your renderLoop... may be causing some problems.  Not sure yet... still studying.  I and others may comment soon, and keep reporting discoveries, thx.

Link to comment
Share on other sites

https://www.babylonjs-playground.com/index.html#H6XJZ8#95

Yeah, its a big fat playground... difficult to troubleshoot.

Can you shrink it to super-slim size, and still show crash, Elvi?

Helpers:  Generally, just click on canvas, and then hit the 't' key to start/stop particle trail.

For me, in FF 52 ESR, stable BJS works, latest BJS version... crashes Firefox... "Your tab has crashed" screen... rare.

Further tests were inconsistent... no more crashes... but sometimes 't' key works, sometimes not.

 

elvisior... to help with bug-fix, can you try to make that playground TINY TINY TINY... and still have the 't' key work/crash like it is doing now?

Likely, it is something particles-related (duh). 

Elvi... if you can remove EVERYTHING from that playground... except the bug-causing code, and basic mesh/lights... then that would make bug-finding MUCH easier and faster.

Try for 30 lines of code, or less... and still show bug/crash.  Good luck.  I can help, too, but... kind of busy in real life right now.

Link to comment
Share on other sites

Hi again!  I get an instant "out of memory" error in firefox 52 ESR... but... if I change line 86 to be...

planets['planetTrail'] = new BABYLON.GPUParticleSystem("planetTrail", { capacity:100000, randomTextureSize: 4096 }, scene);

... it works for me, in FF.  1 million capacity was too big for my puppy-puter, apparently.  :)

In my IE 11.0.9600.18097, I get "invalid character" playground error, with no line number available (with 1 million capacity OR 100,000 capacity).

Let's ping @Deltakosh again... see if this playground is tolerable, see if he has some ideas.  Let's request info from others, too.  Maybe others have seen this problem and can offer help/info.

Elvisior, could you please try https://www.babylonjs-playground.com/index.html#M37848#7

That is the 100,000 capacity version.  Maybe we have found some evidence/secret to the problem, eh?  (Wingnut crosses fingers and toes for good luck.)  :)

PS:  Thanks for the reduced-size playground/tests... that was nice of you to do for us.  Bug-finding/limitation-finding... could be much easier, now.

Link to comment
Share on other sites

It is not a regression per se but I clearly get your point :)

We are fixing the way random works in the GPU but this requires a bit more memory than before

Link to comment
Share on other sites

  • 2 weeks later...

I've been off learning about electron and node for how I could possibly make this a cross platform app.

I've hit a weird issue.. I thought i had this kind of working as per: https://www.babylonjs-playground.com/indexStable.html#H6XJZ8#95

But if I hit save from the playground and then try and run it from the saved version the columns aren't being placed in the correct location.

So in summary... https://www.babylonjs-playground.com/indexStable.html#H6XJZ8#95 works but the zip attached below which is the result of having hit save from the playground does not.

I'm confused.. 

sample (2).zip

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...