ShimShamSam Posted November 21, 2013 Share Posted November 21, 2013 Unity has a built-in function on transforms called "TransformDirection" which you pass in a Vector3 and it makes the direction relative to the transform. If you call this on the camera, you have an easy way to handle movement relative to the view. Does Babylon have something similar? I could probably replicate it if I had access to the camera's view normal. Quote Link to comment Share on other sites More sharing options...
ShimShamSam Posted November 21, 2013 Author Share Posted November 21, 2013 I think I have figured it out. For future reference, here is the code I used:// This is just some random movement vector.// Your code will probably use inputs to determine the movementsvar movement_vector = new BABYLON.Vector3(0.8, 12, 4);// This is the important partvar direction = BABYLON.Vector3.TransformNormal(movement_vector, camera.getWorldMatrix());Let me know if there is a better way to do it. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 21, 2013 Share Posted November 21, 2013 This is a good solution Babylon.js also provides you a setLocalTranslation function:https://github.com/BabylonJS/Babylon.js/wiki/How-to-handle-rotations-and-translations Quote Link to comment Share on other sites More sharing options...
MackeyK24 Posted August 21, 2017 Share Posted August 21, 2017 On 11/21/2013 at 4:38 AM, Deltakosh said: This is a good solution Babylon.js also provides you a setLocalTranslation function: https://github.com/BabylonJS/Babylon.js/wiki/How-to-handle-rotations-and-translations Yo @Deltakosh I can't seem to find setLocalTranslation... How would I handle a TransformDirection unity like function in BabylonJS ? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted August 21, 2017 Share Posted August 21, 2017 You can use mesh.translate(BABYLON.Axis.X, 1.0, BABYLON.Space.LOCAL) for instance Quote Link to comment Share on other sites More sharing options...
MackeyK24 Posted August 22, 2017 Share Posted August 22, 2017 23 hours ago, Deltakosh said: You can use mesh.translate(BABYLON.Axis.X, 1.0, BABYLON.Space.LOCAL) for instance Yo @Deltakosh ... If I can bug you for a bit... I checked out the mesh.translate But this returns a Mesh... not the 'Transformed Direction' What I am trying to do is provide a unity like api for come of the common feature of unity. Like getUserInput And moveWithPhysics Can you PLEASE - PLEASE (When you get a chance) fill in these three functions so that I can add to the scene manager api: // ************************************ // // * Public Transform Tools Support * // // ************************************ // /** Transforms position from local space to world space. */ public transformPoint(owner: BABYLON.AbstractMesh | BABYLON.Camera, position:BABYLON.Vector3):BABYLON.Vector3 { return position.clone(); // TODO: Transform position from local to world space } /** Transforms vector from local space to world space */ public transformVector(owner: BABYLON.AbstractMesh | BABYLON.Camera, vector:BABYLON.Vector3):BABYLON.Vector3 { return vector.clone(); // TODO: Transform vector from local to world space } /** Transforms direction from local space to world space. */ public transformDirection(owner: BABYLON.AbstractMesh | BABYLON.Camera, direction:BABYLON.Vector3):BABYLON.Vector3 { return direction.clone(); // TODO: Transform direction from local to world space } Thank You Very Mesh Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted August 22, 2017 Share Posted August 22, 2017 /** Transforms position from local space to world space. */ public transformPoint(owner: BABYLON.AbstractMesh | BABYLON.Camera, position:BABYLON.Vector3):BABYLON.Vector3 { return BABYLON.Vector3.TransformCoordinates(owner.getWorldMatrix(), position); } /** Transforms vector from local space to world space */ public transformVector(owner: BABYLON.AbstractMesh | BABYLON.Camera, vector:BABYLON.Vector3):BABYLON.Vector3 { return BABYLON.Vector3.TransformNormal(owner.getWorldMatrix(), position); } I did not test it and did it from memory but should be good. Few warnings: - transformDirection and transformVector are the same (unless I did not get what is the difference) - This will generate a new Vector3 on each call. You may want to add a xxxToRef as well Quote Link to comment Share on other sites More sharing options...
MackeyK24 Posted August 23, 2017 Share Posted August 23, 2017 7 hours ago, Deltakosh said: /** Transforms position from local space to world space. */ public transformPoint(owner: BABYLON.AbstractMesh | BABYLON.Camera, position:BABYLON.Vector3):BABYLON.Vector3 { return BABYLON.Vector3.TransformCoordinates(owner.getWorldMatrix(), position); } /** Transforms vector from local space to world space */ public transformVector(owner: BABYLON.AbstractMesh | BABYLON.Camera, vector:BABYLON.Vector3):BABYLON.Vector3 { return BABYLON.Vector3.TransformNormal(owner.getWorldMatrix(), position); } I did not test it and did it from memory but should be good. Few warnings: - transformDirection and transformVector are the same (unless I did not get what is the difference) - This will generate a new Vector3 on each call. You may want to add a xxxToRef as well Very Kool.... This is what I have now for get Forward, right and up vector and transform position and direction: // ************************************ // // * Public Transform Tools Support * // // ************************************ // /** Transforms position from local space to world space. */ public transformPosition(owner: BABYLON.AbstractMesh | BABYLON.Camera, position:BABYLON.Vector3):BABYLON.Vector3 { return BABYLON.Vector3.TransformCoordinates(position, owner.getWorldMatrix()); } /** Transforms direction from local space to world space. */ public transformDirection(owner: BABYLON.AbstractMesh | BABYLON.Camera, direction:BABYLON.Vector3):BABYLON.Vector3 { return BABYLON.Vector3.TransformNormal(direction, owner.getWorldMatrix()); } // ************************************ // // * Scene Direction Helper Support * // // ************************************ // /** Gets the blue axis of the owner in world space. */ public getForwardVector(owner: BABYLON.AbstractMesh | BABYLON.Camera):BABYLON.Vector3 { return owner.getDirection(BABYLON.Vector3.Forward()) } /** Gets the red axis of the owner in world space. */ public getRightVector(owner: BABYLON.AbstractMesh | BABYLON.Camera):BABYLON.Vector3 { return owner.getDirection(BABYLON.Vector3.Right()); } /** Gets the green axis of the owner in world space. */ public getUpVector(owner: BABYLON.AbstractMesh | BABYLON.Camera):BABYLON.Vector3 { return owner.getDirection(BABYLON.Vector3.Up()); } Thanks @Deltakosh ... Yet Again Quote Link to comment Share on other sites More sharing options...
MackeyK24 Posted August 23, 2017 Share Posted August 23, 2017 9 hours ago, Deltakosh said: /** Transforms position from local space to world space. */ public transformPoint(owner: BABYLON.AbstractMesh | BABYLON.Camera, position:BABYLON.Vector3):BABYLON.Vector3 { return BABYLON.Vector3.TransformCoordinates(owner.getWorldMatrix(), position); } /** Transforms vector from local space to world space */ public transformVector(owner: BABYLON.AbstractMesh | BABYLON.Camera, vector:BABYLON.Vector3):BABYLON.Vector3 { return BABYLON.Vector3.TransformNormal(owner.getWorldMatrix(), position); } I did not test it and did it from memory but should be good. Few warnings: - transformDirection and transformVector are the same (unless I did not get what is the difference) - This will generate a new Vector3 on each call. You may want to add a xxxToRef as well xxxToRef.... that like a "In-Place" type deal where I don't create and return a new vector but instead pass in existing vector and just change the x, y and z ??? ... hardly use the xxxRef unless I saw some example code using it... I assume it was some 'In-Place' update type deal Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted August 23, 2017 Share Posted August 23, 2017 Correct xxxToRef takes an additional parameter which will define the target (where to save the result) xxxInPlace will save the result locally as you mentioned 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.