Jump to content

Mesh Box Color Changes when rotating


aninja
 Share

Recommended Posts

Creating a rubix cube is no easy task.

Rather than parenting cubes to each other, I would create invisible meshes to use as a parent for each cube.  I'd then place each cube in the correct position in each of the cube's parents.  Then I would only do the rotations with the parent meshes.  All of the parent meshes should have the same position.  

And then so that you can move the rubix cube around, I'd parent all those parent meshes to one invisible mesh.

Link to comment
Share on other sites

Hi @adam can you please look this issue http://www.babylonjs-playground.com/#MRRQN#0 hear i try to animate the rubix 1 animation at a time is working fine but when i put multiple animation like if user rotate clockwise upper piece cube then rotate clockwise middle piece cube then it misbehaves just uncomment the line 86-97 and 103,104 please help and guide me :)

Link to comment
Share on other sites

21 hours ago, aninja said:

Hi @adam can you please look this issue http://www.babylonjs-playground.com/#MRRQN#0 hear i try to animate the rubix 1 animation at a time is working fine but when i put multiple animation like if user rotate clockwise upper piece cube then rotate clockwise middle piece cube then it misbehaves just uncomment the line 86-97 and 103,104 please help and guide me :)

 

Link to comment
Share on other sites

The array cubesToRotate2 does not have any entries hence the error message - Compilation error Cannot set property 'parent' of undefined×

Also note that rotation is like position and sets a particular rotation. This means that rotation A followed by rotation B results in rotation B only NOT A followed by B. To do cumulative rotations other methods are needed. Perhaps this tutorial might help http://doc.babylonjs.com/tutorials/Position,_Rotate,_Translate_and_Spaces

Link to comment
Share on other sites

Oh that compilation error is just because my code is not saved is't gives me "Code Too Long " error, and I'm not able to find any Clue about  cumulative rotations  the link describes the basic of rotation not the  cumulative rotations please guide me I am trying to make a rubix cube 

 

Link to comment
Share on other sites

I guess the way to cumulate successive rotations would be :

to set rotation 1

to compute and to store the related WorldMatrix

to set rotation 2

idem

etc

then to multiply all the intermediate stored rotation matrices and to aplly the result to the mesh

Just an idea (don't ask me how to do this ;))

 

Link to comment
Share on other sites

Hi Please look at this http://www.babylonjs-playground.com/#NDSST#0 there are 2 buttons for rotation both rotation works well independently but when i rotate one after another it got mixed 

A rotation1

B rotation2

if i press A or B N times it will rotate fine  

but if i rotate A->B or B->A then it will inherit previous rotation please check it and help me :(

 

Link to comment
Share on other sites

 

Cumulative rotations.

In tutorial http://doc.babylonjs.com/tutorials/Position,_Rotate,_Translate_and_Spaces   scroll down to where you see Figs 6a, 6b, 6c under the Rotate section. This shows rotations take place around the world-local-axes and are accumulative. This can be seen in Demo 7.  The mesh 'pilot' is rotated using the following code on lines 107 to 109. The difference between world-local-axes BABYLON.Space.WORLD and local-axes BABYLON.Space.LOCAL are explained in the tutorial. The cumulative nature of rotate can be seen by first commenting out lines 108 and 109, then only line 109 and then none of them.
 

pilot.rotate(BABYLON.Axis.Y, Math.PI / 2, BABYLON.Space.WORLD);
pilot.rotate(BABYLON.Axis.Y, Math.PI / 2, BABYLON.Space.WORLD);
pilot.rotate(BABYLON.Axis.X, Math.PI / 2, BABYLON.Space.WORLD);

Whether or not this is the way to go I am not clear on as you have complications of cubes switching faces when they are rotated.

Personally I think I would tackle the rubix cube by giving each of the 27 cubes its own individual parent then having decided on a face to rotate determine the 9 current cubes in that face and rotate their 9 parents as required using the rotate method above but then I often do not do things the best way possible.

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