Jump to content

How to rotate perplexus mesh around current center of playBall (sphere mesh) ?


ian
 Share

Recommended Posts

Hi,

Here is my example.

Code works so that perplexus(mesh) is rotated around it's center. With Key 1,2 around Y, with key 3,4 around X and key 5,6 aroudn Z.

Can anybody help me to solve how to rotate perplexus(mesh) around current center of payBall(mesh)?

http://86.58.118.110:8080/BabylonBall/Main.html

if I add code

var currentCenterPlayBall = perplexusRef.playBall.getBoundingInfo().boundingSphere.center;
I get currentCenterPlayBall (x,y,z). How can I rotate perplexus Mesh around currentCenterPlayBall this current (x,y,z) ?

        
     

 
    	
        switch (keycode) {
        	// user inputs
	        case 49: // 1  
	        	
	        	perplexusRef.perplexus.rotate(BABYLON.Axis.Y, Math.PI / +512, BABYLON.Space.LOCAL);
	        	perplexusRef.perplexus.updatePhysicsBodyPosition();
	    		brake;    	    		
	        case 50 : // 2   	        	
	        	perplexusRef.perplexus.rotate(BABYLON.Axis.Y, Math.PI / -512, BABYLON.Space.LOCAL);
	        	perplexusRef.perplexus.updatePhysicsBodyPosition();
	    		
	            break;
	        case 51 : // 3
	        	
	        	perplexusRef.perplexus.rotate(BABYLON.Axis.X, Math.PI / +512, BABYLON.Space.LOCAL);
	        	perplexusRef.perplexus.updatePhysicsBodyPosition();
	        	
	            break;
	        case 52 : // 4    	        	    	                	    		
	        	perplexusRef.perplexus.rotate(BABYLON.Axis.X, Math.PI / -512, BABYLON.Space.LOCAL);
	        	perplexusRef.perplexus.updatePhysicsBodyPosition();
	            break;    	    		
	        case 53 : // 5    	        	
	        	perplexusRef.perplexus.rotate(BABYLON.Axis.Z, Math.PI / +512, BABYLON.Space.LOCAL);
	        	perplexusRef.perplexus.updatePhysicsBodyPosition();
	        	
	            break;
	        case 54 : // 6    	        	    	                	    		
	        	perplexusRef.perplexus.rotate(BABYLON.Axis.Z, Math.PI / -512, BABYLON.Space.LOCAL);
	        	perplexusRef.perplexus.updatePhysicsBodyPosition()
	        	
	            break;	  



Any help?

greetings

 

Any help?

greetings
 

Link to comment
Share on other sites

Parenting? On physics objects?  (Wingy checks Deltakosh's temperature)  :)

Hi Ian!

Maybe start with a forum search for 'pivot'.  After you get tired of reading all 123 returns, you might find...

mesh.setPivotMatrix(BABYLON.Matrix.Translation(xDistance, yDistance, zDistance));

BUT... sigh.  We're all screwed.  heh

(I'm a jerk sometimes, eh?)

You will probably need to change the pivot matrix on your track's meshImpostor, as well.  The BJS meshImpostor is a Cannon.Trimesh.  Visit that link, if you please.   Look at the methods listed.  I don't see any methods that could change the pivot point of the meshImpostor.

There MIGHT be a method using mesh.bakeCurrentTransformIntoVertices() and then mesh.updatePhysicsBodyPosition, but I can't imagine the needed code.  Also, you will need to do this constantly, in the renderLoop.  Every moment that the ball rolls down the track, you must translate mesh's pivot... the correct distance to be located at ball.position, and then ????  

This is very complicated, as best I can tell.  What you REALLY need is mesh.updatePhysicsPivotTransform()... which is the same as Cannon.Trimesh.setPivotMatrix() which... doesn't exist.

Also, I don't know if you WANT to rotate the track around the current ball position.  Allow me to show you a playground from a friend... which will give you the idea of what this might "feel" like... http://www.babylonjs-playground.com/#1HH4OJ#6 .  Wait for the camera to get fully-zoomed, and then wait and watch some more.    

See how that "feels" like we are rolling the track... along the surface of a car/ball?  (opposite of what you might desire)  I think if you rotate your perplexus track around your ball, you will get the same effect.  Instead, your game needs to "feel" like rolling a ball/car... along the surface of a track. 

I bet I know what is happening in your project, Ian.  The user tilts the perplexus track too fast, and the ball makes a "fall" to the track far below and causes trouble.  Maybe try limiting the allowed track rotation speed?  I don't know.  This is not an easy issue.  MeshImpostors (Trimesh) are real new, and your project is not simple.  I could be wrong... in MANY ways.  But maybe not.  I wish I could help more.  Others will comment.  Sorry that I didn't have better news for you, Ian.

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