Problem in rotX function

Hi ,
I am getting unusual problem in my project while using rotZ function ,its not setting rotation by 90 degree but around 70-75 deg.
I am posting a sample code depicting this problem …


import javax.vecmath.Vector3f;
import com.xith3d.render.CanvasPeer;
import com.xith3d.render.Option;
import com.xith3d.render.RenderOptions;
import com.xith3d.render.RenderPeer;
import com.xith3d.render.jogl.RenderPeerImpl;
import com.xith3d.scenegraph.BranchGroup;
import com.xith3d.scenegraph.Canvas3D;
import com.xith3d.scenegraph.Geometry;
import com.xith3d.scenegraph.Locale;
import com.xith3d.scenegraph.Shape3D;
import com.xith3d.scenegraph.Transform3D;
import com.xith3d.scenegraph.TransformGroup;
import com.xith3d.scenegraph.View;
import com.xith3d.scenegraph.VirtualUniverse;
import com.xith3d.test.TestUtils;

public class Test {
private TransformGroup mainSceneTransform;
private Transform3D mainSceneTranslate;
private TransformGroup planeXTransform;
private Transform3D planeXRotate;
private TransformGroup planeYTransform;
private Transform3D planeYRotate;

public static void main(String[] args) {
	new Test();
}

public Test() {

	VirtualUniverse universe = new VirtualUniverse();
	View view = new View();
	universe.addView(view);
	Locale locale = new Locale();
	universe.addLocale(locale);
	BranchGroup scene = new BranchGroup();
	scene.setPickable(true);
	locale.addBranchGraph(scene);

	mainSceneTranslate = new Transform3D();
	mainSceneTransform = new TransformGroup(mainSceneTranslate);
	mainSceneTransform.setPickable(true);
	scene.addChild(mainSceneTransform);
	
	Geometry g=TestUtils.createPlane(0,0,0,1,1);		
	Shape3D planeX = new Shape3D(g);
	planeXRotate = new Transform3D();
	planeXTransform = new TransformGroup(planeXRotate);
	planeXTransform.addChild(planeX);
	mainSceneTransform.addChild(planeXTransform);
		
	Shape3D planeY = new Shape3D(g);
	planeYRotate = new Transform3D();
	planeYTransform = new TransformGroup(planeYRotate);
	planeYRotate.rotZ(90);
	planeYTransform.setTransform(planeYRotate);
	planeYTransform.addChild(planeY);
	mainSceneTransform.addChild(planeYTransform);
	
	RenderPeer rp = new RenderPeerImpl();
	CanvasPeer cp = rp.makeCanvas(null, 640, 480, 32, false);
	Canvas3D canvas = new Canvas3D();
	canvas.set3DPeer(cp);
	RenderOptions renderOption = new RenderOptions();
	renderOption.setOption(Option.ENABLE_WIREFRAME_MODE, true);
	cp.setRenderOptions(renderOption);

	view.addCanvas3D(canvas);
	view.setProjectionPolicy(View.PARALLEL_PROJECTION);
	view.getTransform().lookAt(new Vector3f(0, 0, 1.5f), // location of eye
			new Vector3f(0, 0, 0), // center of view
			new Vector3f(0, 1, 0)); // vector pointing up
	
	while(true){
	view.renderOnce();
	}
}

}

are you using radians?

Arne

PS: normal black text color is ok - you don’t have to make it blue

planeYRotate.rotZ((float)(Math.PI/2));

90 = 90 radians

Thanks that was the problem , :slight_smile:
but in the Java Docs it was written that rotX take degree as a parameter


/** * Set the value of this matrix to a rotation matrix about the * specified axis. The angle to rotate is specified in degrees. * The non-rotational components are set as if this were an * identity matrix. All values are changed. */ public void rotX(float angle) { setIdentity(); matrix.rotX(angle); }

Hmm that is a bug in the docs.

Rule of thumb is use radians for everything (with some exceptions, raw OpenGL for one IIRC).

Will.