Jump to content

Pivot and rotate at the same time


cartman
 Share

Recommended Posts

Hi guys, i've been scratching my head the past 5 hours, couldn't get past this :(

Step1: Basically, i have a cube rotating along the x-axis: http://www.babylonjs-playground.com/#H7V1D#19

Step2: I want that same cube, to pivot around the origin: http://www.babylonjs-playground.com/#H7V1D#18

The problem is, in Step2, the cube isn't rotating (along it's x-axis) like in Step1.

I guess my question is, how do I combine both Step1 and Step2?

Link to comment
Share on other sites

Hi cartman!  http://www.babylonjs-playground.com/#H7V1D#20

There is one way of doing it.  CurrentMesh is parented to the y-rotating gizmo box in line 35.  This causes currentMesh to get its position changed the rotating gizmo (currentMesh appears to "orbit" the gizmo).  Meantime, currentMesh is still rotating on its x-axis... line 48.  The gizmo is rotated in line 50.

I'm sure it can be done without a parenting gizmo, but maybe the gizmo is the easiest way.  If you want, you can make the gizmo invisible with line 33, and you could also use a plane (not box) for gizmo... to reduce scene size a bit.  Okay, I hope this helps.  Stay in touch.  :)

Link to comment
Share on other sites

@Wingnut thanks, but it's not working as I intended. 

I'm looking for the cube to rotate on it's x-axis, while the cube pivots around the origin (0,0,0).

Here's a more concrete example i'm trying to build. The rear (right side) wheel should keep spinning, while the car pivots around origin.

Screen Shot 2016-05-06 at 8.59.42 PM.jpg

See this animated gif too: http://recordit.co/yYYDHDaPHZ

The playground code you wrote, gave a different kind of rotation (http://g.recordit.co/UV1bNv998X.gif) - it looks twisted...

Any ideas? 

 

 

 

Link to comment
Share on other sites

@aWeirdo thanks, but i don't quite understand. can you post a playground example?

@Wingnut's solution http://www.babylonjs-playground.com/#H7V1D#20 doesn't have setPivotMatrix activated. It depends on the parent (gizmo) rotating along its y-axis, while currentMesh rotates along its x-axis. It's not the same result, as a car wheel pivoting.

I'll keep experimenting, thank you. Any ideas are welcome!

Link to comment
Share on other sites

http://www.babylonjs-playground.com/#H7V1D#22

Does that look better?  I needed to align the blue wheel box... with the gizmo.... by adjusting the x-factor in line 38, and then rotate the blue box around the Z axis and not the X axis.

Here's another fun one... http://www.babylonjs-playground.com/#H7V1D#23

Sometimes, BJS mesh are not created in the proper orientation for your project.  The cylinder (wheel) was such a case.  Lines 39 and 40 fixed that.

This system might dictate that there would be 3 invisible boxes inside the car.  First, a primary parent gizmo for the car... let's pretend it is named carGizmo.  There would also be a frontAxleGizmo and backAxleGizmo.  They are both parented to carGizmo.

You might even think about 5 total gizmos.  One for the carGizmo, and then one for each wheel.  All four wheelGizmo would be parented to carGizmo. 

Perhaps more gizmos... for trunk, hood, and door opening/closing.  Maybe another for the steering wheel.  Electric side mirrors?  Two more.  :)  Gizmos are similar to invisible puppet strings, eh?

A gizmo-per-wheel... would make it easier to steer the front wheels, yet keep them rotating on their Z-axis (rolling).  *shrug*  Just some ideas... not sure if they are good/wise ideas.  :)

Link to comment
Share on other sites

Excellent!  Very nice.  Glad I could help.  Help another when you get a chance.  :)  And... um... are you continuing work on your car?  Keep us updated, please.  That looks fun! 

In fact, talk talk talk right now, if you wish.  Tell us about you and your projects, right here, if you want-to.  What's your story, if you don't mind me asking?  Where do you live (if I may ask)? 

Do you have a website that tells about you and your dreams?  I would visit it.  :)

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