Jump to content

mesh.rebase()


jerome
 Share

Recommended Posts

After some tests in many directions, included the usual blocking ones (+PI / 2, + PI /2, + PI/2, etc), it seems to keep coherent and working.

 

Well, some more tests this week-end... and if nothing wrong happens, there will be a new candidate for math.ts next week

// axis1 to 3 are three orthogonal vectors, oriented left-handed// they are the target system to set a mesh along for instancevar rot = BABYLON.Vector3.AxisToEuler(axis1, axis2, axis3); // returns a vector3 : (pitch, yaw, roll)mesh.rotation = rot;mesh.position = new_position;  // these two last lines are now the former rebase() function

The name could be changed also : VectorsToEuler ? SystemToEuler ? RotationFromVectorsRotationFromAxis ? etc

I believe I prefer RotationFromAxis() 

 

Any ideas, people ?

 

 

@DK : should this function be in Vector3 or in Axis class ?

Imho, it's vector handling, so it would be better in Vector3

Link to comment
Share on other sites

sold ! RotationFromAxis() in Vector3 class.

 

@JohnK

I really feel proud of this algo because I spent almost a full week of charge (not duration what is about 2+ weeks) upon and it was really difficult for me despite the process validation from two different math profs.

Process is just... a concept.

Implementation is really harder because we face some unpredicted behavior or many process/concept oversights/failures (easy to say : "choose the best of 4 possible solutions, then do this"... very hard to define/implement what is the best of 4 possible solutions, the best in terms of what ?)

 

Maybe is there a best way to do, a shorter way, a smarter way, a simpler way ? Probably. I don't know. 

I wish someone tells me some day the most elegant or the most computational way.

The lone I found so far on the web (maybe I don't write the right request...despite decades of using web search engine ?) was the one about angles/atan2 approach and had an all ready C implementation. But it didn't work for negative angles (or > PI) and had really bad approximation about roll angle (+/- 2 degrees !), unless I did big mistakes in copying it. So far, mine is accurate about 0.001 degrees in average tests.

 

 

I guess my sleep will become quiet back now :)  

Link to comment
Share on other sites

Hip, hip, hip, hooray! Hats off to Jerome!!

How to kill a nightmare in one week! :D

Hope you will not hate us too much (Wingy and me) to cause you such sufferings by our request, watch out  little light's candles ! ;)

 

Really thank you for the time you spent, torturing your brain, finding this solution. Hope it will be useful for a lot of people!

 

Of course, if you agree, I will put it in "my" centralisation of user functions, if you could just give me a short explanation not too abstract (think about newbies ;) ) of what it exactly do and the link to last demo , like you did before :

 

"a localRebase(origin, axis1, axis2, axis3) method : this will need to set mesh as updatable and will allow to change the mesh position/orientation after building in its local space. The mesh is modified in its local space. This is quite the prototype function.

If this function could be called within the mesh constructor, it wouldn't be necessary to set the mesh as updatable... but it would need an extra parameter to pass the target base.

Hard choice.

 

a worldRebase(origin, axis1, axis2, axis3) method (not yet even thought, too busy mind) : this will allow to keep a mesh non-updatable and will rebase the mesh in the world in the same way that the former method does. This will not modify the mesh in its local space. This should only modify the mesh.worldMatrix."

 

I will do the same with showAxis(size), just to know who is the "creator', is it you?

 

Well hope you had a good rest , after climbing ( and succeeding) that hard joyfull math mountain!

 

Be well

Link to comment
Share on other sites

@Alby :

 

about : RotationFromAxis()

I hope this function will be helpful to many people as it is a recurrent need (it's one fo mines) : how to rotate something in order to set in this know orientation.

Don't put it in your personal collection as it will be integrated soon in BJS.

I will write the relating doc which is quite simple : give the function 3 left-handed orthogonal vectors (target system) in space and it returns you the 3 rotation angles needed to reach this target system from the world system.

 

about rebase() :

Well, it's not needed any longer, because rebase() is now just :

var rot = BABYLON.Vector3.AxisToEuler(axis1, axis2, axis3); // returns a vector3 : (pitch, yaw, roll)mesh.rotation = rot;mesh.position = new_position;

However you can keep the old PG rebase(). Just remember it modifies the mesh itself, in its local space, instead of simply rotating it : it just rebuilds the mesh ... rotated.

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