ambiera logo

Ambiera Forum

Discussions, Help and Support.

folder icon Ambiera Forum > CopperLicht
forum topic indicator Move a rotated Object?
person icon
bagg
Registered User
Quote
2010-10-31 20:05:50

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

person icon
niko
Moderator
Quote
2010-11-01 06:24:12

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.

person icon
bagg
Registered User
Quote
2010-11-02 20:02:51

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.

person icon
niko
Moderator
Quote
2010-11-03 07:05:20

I'm not exactly sure anymore by what you mean by 'rotated' object. I meant something like this:


var yourMovementDirection = new CL3D.Vect3d(2,2,0); // the direction you want your object to move
yourMovementDirection.setLength(100); // to make your object move 100 in the direction you specified above
SelSceneNode.Pos.addToThis(yourMovementDirection);


person icon
bagg
Registered User
Quote
2010-11-03 09:16:14

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.

person icon
niko
Moderator
Quote
2010-11-03 10:15:04

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();
mat.setRotationDegrees(yourSceneNode.Rot); // set the rotation of your scene node into the matrix

var yourMovementDirection = new CL3D.Vect3d(0,1,0); // create a vector
mat.rotateVect(yourMovementDirection); // rotate your vector by the matrix

yourMovementDirection.setLength(100); // to make your object move 100 in the direction you specified above
SelSceneNode.Pos.addToThis(yourMovementDirection);


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.

person icon
bagg
Registered User
Quote
2010-11-03 19:07:41

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

person icon
niko
Moderator
Quote
2010-11-04 07:04:47

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.

person icon
bagg
Registered User
Quote
2010-11-04 09:00:19

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.

person icon
niko
Moderator
Quote
2010-11-05 05:42:16

It doesn't work like that, you have a position, rotation and scale per object. The transformation matrix is generated on the fly.


Create reply:










 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


icon_holyicon_cryicon_devilicon_lookicon_grinicon_kissicon_monkeyicon_hmpf
icon_sadicon_happyicon_smileicon_uhicon_blink   






Copyright© Ambiera e.U. all rights reserved.
Contact | Imprint | Products | Privacy Policy | Terms and Conditions |