Rotating and Moving?

Hello Xith3d users,

I’m new to xith3d and have a probably easy question:

I want to rotate and move an object, but if I try it this way:

//move and rotate the object
Vector3f V = new Vector3f( -300, -50 , 6000 ); 
mTransform = new Transform3D();
mTransform.rotY(-90); //rotate the object
mTransform.set(V); //move the object 
TG.setTransform( mTransform ); 

It only moves the object. I can’t see the rotation ???

What am I doing wrong?

Hi , I’m a newbie too,

but I think I can help you :

This is the function I use for Moving forward :



public void doMove(TransformGroup transformGroup, Vector3f theMove) 
  {              Transform3D transform3D = new Transform3D()
		transformGroup.getTransform(transform3D);
		Transform3D toMove = new Transform3D();
		toMove.setTranslation(theMove);
		transform3D.mul(toMove);
		transformGroup.setTransform(transform3D);
 }


and for a Rotation I use:


 public void doRotateY(TransformGroup transformGroup,float radians) 
  { 
                      Transform3D transform3D = new Transform3D()
		transformGroup.getTransform(transform3D);
		Transform3D toMove = new Transform3D();
		toMove.rotY(radians);
		transform3D.mul(toMove);
		transformGroup.setTransform(transform3D);
}

I hope this helps

Cheers

Rmdire

Bobke, what you want to do is to apply 2 successive transformations.
For that you should create 2 TransformGroups.
It can be done simply like that :


//move and rotate the object
Vector3f V = new Vector3f( -300, -50 , 6000 );
mTransform = new Transform3D();
mTransform.rotY(-90); //rotate the object
mTransform 2 = new Transform3D();
mTransform.setTranslation(V); //move the object
TG.setTransform( mTransform );
TG2.setTransform( mTransform );
scene.addChild( TG );
TG.addChild( TG2 );
TG2.addChild( BG );

Note : you can find very useful informations on basic scenegraph hierarchy usage in the “Xith Getting Started Guide”, in the “Docs” section of http://xith.org

Thank you,

They are both very useful :slight_smile:

Bobke

Hello again,

I use the first way now, because I like the idea of moving and rotating with only 2 lines.

With this code the object will move every frame 1 pixel over the X

V = new Vector3f( 1, 0, 0);
doMove( TG, V);

Now my question is: How can I get the value of the X, Y and Z back?

TransformGroup.getTransform().get(Vector3f d)
The result gets written into d.

The order that you multiply them matters too. Both examples given work because inside the Xith3D renderer, when there is a Transform3D that is a child of another Transform3D the matricies are indeed multiplied at render time (and cached).

The Transform3D chaining option is very handy when you are constantly changing one of the components. The “manual” multiplication method is nice when you just need to do it once (reduced scenegraph overhead).

It would be good to read up on Matrices - you can’t avoid them when coding 3D.

Tricks of 3D Game Programming Guru’s chapter 4 has some great stuff on Matrices, Vectors, Quaternions etc. The book is huge, I bought it primarily for that chapter which had more pages and better content (and the book was the same price) as a book I saw soley dedicated to game maths.

I also found the Java 3D API Jump Start useful when learning about the Java3D scenegraph (which Xith3D was modelled on). Good stuff on transform’s, etc. Less hard core maths than the other book, but more specific to the scenegraph.

Cheers,

Will.

May we do something kinda like that for Xith ? Or maybe a shared document for both scenegraphs, with some “difference tips” in it ?

Sounds good - probably would be best to expand on the Getting Started Guide I suppose, that already has a lot of good stuff in there (though it does assume some basic scenegraph/maths knowledge).

I am happy to help anyone wishing to contribute a Getting Started Guide chapter to get Latex up and running.

Will.

(I personally wouldn’t have difficulty to get Latex running)
I propose we could rewrite a bit the Getting Started Guide before adding content. The informations contained are very useful, but could be more organized and clearer.