Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
Ok Niko that was a quick fix.Now It's working. Now can you please point me on how can i move a rotated object let's say 100 units away at the X vector (The rotated X object's vector not the Horizontal). Thanks |
||||
|
Take the vector of the object, normalize it, set it's length to 100 (you can use CL3D.Vect3D.setLength(100) do do both at the same time) and add that vector to the current position of your object. |
||||
|
It's not working right.Here is what i do: (the SelSceneNode is the object that i want to move) var NewSelSceneNodePos = SelSceneNode.Pos; NewSelSceneNodePos.setLength(100); SelSceneNode.Pos.addToThis(NewSelSceneNodePos); But the object is not moving only in X direction but also in Y and Z. |
||||
|
I'm not exactly sure anymore by what you mean by 'rotated' object. I meant something like this:
|
||||
|
ok let me explain it a litlle bit more I have an object that it's rotated 45 degrees.And i want to move it from it's current position 100 units away but in the same direction that the object is rotated. |
||||
|
Ah. The only hard part there is to get a direction vector from your rotation, the yourMovementDirection vector in the code above. You can for example use a matrix to do this for you. Something like this should work: var mat = new CL3D.Matrix4(); I didn't try this out, so it could be that the rotation is wrong by 90 or 180 degrees, you can adjust this by changing the vector with which you are starting from (0,1,0) to for example (1,0,0) and similar. |
||||
|
Niko it's not working.The object disappears. I also tried this. SelSceneNode.updateAbsolutePosition(); var mat = SelSceneNode.getAbsoluteTransformation(); //var SelSceneNodeRot = mat.getRotationDegrees(); var MovementDirection = new CL3D.Vect3d(0,1,0); // create a vector mat.rotateVect(MovementDirection); // rotate your vector by the matrix MovementDirection.setLength(100); // to make your object move 100 in the direction you specified above SelSceneNode.Pos.addToThis(MovementDirection); The var SelSceneNodeRot = mat.getRotationDegrees(); brings the right degrees.The new CL3D.Vect3d(0,1,0) is the right direction. And speaking for matrices how can i make an object's Matrix to be another's object Matrix? Thanks |
||||
|
Yeah, you need to try around a bit probably if it's not exactly what you need. It's simple math after all. :) And speaking for matrices how can i make an object's Matrix to be another's object Matrix? You would simply copy the Pos, Rot and Scale attributes of one scenenode to the other one (using either clone() or copyTo()). If you really want this to be based on a matrix, you can extract those values from one by calling the matrix functions getRotationDegrees() for the rotation, getTranslation() for the translation, and getScale() for the scale. |
||||
|
For the matrix woudn't be easier to have SelSceneNode.setAbsoluteTransformation(NewMatrix); ??? for future updates of the library.................. And something else i want to ask. If you change an object's matrix translation or rotation or something shoudn't the object's position or rotation e.t.c be updated? If so then you must check the set.......... functions of Matrix4 because the SomeMatrix.setTranslation(100,0,0) SomeMatrix.setRotationDegrees(0,45,0) are not working and i don't know if the others set..... are working too. |
||||
|
It doesn't work like that, you have a position, rotation and scale per object. The transformation matrix is generated on the fly. |
|