Need a small Clarification…
If i set a translation in Transform3D funtion setTranslation , say my object is at (0,0,0 ) and now i tranaslate it to (10,10,0) now again i want to translate it by in X axis = 2units and in Y axis= 2units ,right now what is happening is previous transformation is not been set permanently so in next translation i have to translate by (12,12,0) for the same effect.
Why everytinme we translate ,it translate from (0,0,0).Is their a way to set previous traslation permanently…
I hope i am clear but if its not clear i can code a sample program to demonstrate my confusion.
Thanks in advance
Each time you call setTranslation, you are setting the translation component of the 4x4 transform matrix.
One option is to call getTranslation and use the “add” fuction. E.g.:
// additionalTranslation is your extra translation
//t3d is your Transform3D
Vector3f translation = new Vector3f();
t3d.getTranslation(translation);
translation.add(additionalTranslation);
t3d.setTranslation(translation);
Don’t forget to use the Java3D Javadocs for vecmath classes like Vector3f.
Regards,
Will.
ok i got it basically we have to get the current translation and than add new translation to it and again set it back ,
thanks for explanation .I am new to scenegraph and graphics so i have no idea of java3d ,i directly started using Xith so sometimes dont know where exactly to look for…thanks for the help
By the way, isn’t there somewhere I can download a zip archive of these javadocs ? Because I can’t have vecmath javadocs in Eclipse without.
Have you checked out java.com or the Java3D project at java.net?
BTW: I use a downloaded javadoc, but I don’t know anymore, wher I’ve got it from…
Hii Denniss ,
One more thing how the same effect can be done for rotation ,i mean to get current rotation and add extra rotation in X,Y or Z axis and than set it back.
Thier is so much in forum on rotation but not exactly this thing …also when i use rotX function the translation get set to initial positon to overcome this in my code i am again setting the current translation …I am posting my code so please tell me how to go about it
Vector3f position = new Vector3f();
transformGroup.getTransform().getTranslation(position); // getting the current Translation
Transform3D rotation = new Transform3D();
Transform3D transform = new Transform3D();
transform.set(position);
// Here i want to add 0.25f to already occured rotation in previous cycle so how to get that previous rotation in X and Y axis
rotation.rotX(0.25f);
transform.mul(rotation);
rotation.rotY(0.25f);
transform.mul(rotation);
transformGroup.setTransform(transform);
the solun fr the above problem i posted …what i figured out …
Matrix3f m = new Matrix3f();
transformGroup.getTransform().getRotation(m);
Matrix3f temp = new Matrix3f();
temp.rotX(0.25f);
m.mul(temp);
transformGroup.getTransform().setRotation(m);
transformGroup.setTransform(transformGroup.getTransform());
any comments are welcome