jerome Posted May 22, 2015 Author Share Posted May 22, 2015 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() functionThe name could be changed also : VectorsToEuler ? SystemToEuler ? RotationFromVectors ? RotationFromAxis ? etcI 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 Quote Link to comment Share on other sites More sharing options...
JohnK Posted May 22, 2015 Share Posted May 22, 2015 Been following your progress on this. I am truly impressed. As you are obtaining a rotation from an orthogonal axis system then I would agree on RotationFromAxis() . Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 22, 2015 Share Posted May 22, 2015 Agree! And my favorite is RotationFromAxis Quote Link to comment Share on other sites More sharing options...
jerome Posted May 22, 2015 Author Share Posted May 22, 2015 sold ! RotationFromAxis() in Vector3 class. @JohnKI 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 Temechon 1 Quote Link to comment Share on other sites More sharing options...
Alby Posted May 23, 2015 Share Posted May 23, 2015 Hip, hip, hip, hooray! Hats off to Jerome!!How to kill a nightmare in one week! 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 Quote Link to comment Share on other sites More sharing options...
jerome Posted May 23, 2015 Author Share Posted May 23, 2015 @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. Quote Link to comment Share on other sites More sharing options...
jerome Posted May 23, 2015 Author Share Posted May 23, 2015 @Alby about showAxis(size) : yep, it was mineMaybe the name would be rather showWorldAxis(size)cleaned up here : http://www.babylonjs-playground.com/#2L9DCA here, you've got the Temechon's one : http://www.babylonjs-playground.com/#UTDZFshowing any mesh local system Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 23, 2015 Share Posted May 23, 2015 @Jerome: please document it directly inside the code. THis will be easier for users to discover it Quote Link to comment Share on other sites More sharing options...
jerome Posted May 23, 2015 Author Share Posted May 23, 2015 ok boss Quote Link to comment Share on other sites More sharing options...
jerome Posted May 26, 2015 Author Share Posted May 26, 2015 PRed Quote Link to comment Share on other sites More sharing options...
jerome Posted May 27, 2015 Author Share Posted May 27, 2015 demo : http://www.babylonjs-playground.com/#VYM1E#2 I have here two spheres at given positions.I want to set a textured plane from one to the other sphere and I want this plane to always "face" the cam.I don't know anything about angles or whatever : Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 27, 2015 Share Posted May 27, 2015 Vector3.RotationFromAxis is now live. You can use it on the playground jerome 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.