# BUG in Geometry.setLocalRotation

I guess I have found a really annoying bug in the methode setLocalRotation from Geometry.

When I create a new Box while using an centerPoint and then let it rotate, it doesn’t only rotate but translate too.

I wrote a methode which added a grid(all boxes) over a ground plate without any rotations.

As u see there is no disliked translation.

[java]

public void showGrid() {

Node gridNode = new Node(“GridNode”);

Material mat1 = new Material(assetManager, “Common/MatDefs/Misc/SolidColor.j3md”);

mat1.setColor(“m_Color”, ColorRGBA.Green);

for (int x = -floorLenght; x <= floorLenght; x++) {

Box tempBox = new Box(new Vector3f(x, -2, 0), 0.1f, 0.1f, floorWidht);

Geometry tempGeometry = new Geometry(“TempGeoX” + x, tempBox);

tempGeometry.setMaterial(mat1);

gridNode.attachChild(tempGeometry);

}

for (int z = -floorWidht; z <= floorWidht; z++) {

Box tempBox = new Box(new Vector3f(0, -2, z), floorLenght, 0.1f, 0.1f);

Geometry tempGeometry = new Geometry(“TempGeoZ” + z, tempBox);

tempGeometry.setMaterial(mat1);

gridNode.attachChild(tempGeometry);

}

rootNode.attachChild(gridNode);

}

[/java]

I made a workaround by using spheres as dotlike steps between A and B.

EDIT: U have a really weird forum-sw problem with showing 2 java-codelets.

Then I wrote a second methode which had to build a box that should show the way of the model.

The calculation of the centerPoint-Vector3f is OK as u see at point C(between A and B).

Obviously the generation of the box mesh is OK too, cause when it’s not rotated the box hits the Point C.

After rotating the box to show the true angle of the model-way, the whole box is shifted in x- and z-direction to A’-B’, instead of only rotated.

[java]

private void addHelperNodes() { //method of another class

Node helper = new Node(“Helper”);

Material mat1 = new Material(assetmanager, “Common/MatDefs/Misc/SolidColor.j3md”);

mat1.setColor(“m_Color”, ColorRGBA.Red);

Sphere sphere = new Sphere(30, 30, turnRadius);

Geometry cicleGeo = new Geometry(“CircleGeo”, sphere);

cicleGeo.setMaterial(mat1);

cicleGeo.setLocalTranslation(circleCenter.x, 0, circleCenter.z);

cicleGeo.setLocalScale(1, 0.1f, 1);

float waylenght = new Double(Math.sqrt(((aimPoint.x - _2ndStartPoint.x) * (aimPoint.x - _2ndStartPoint.x)) + ((aimPoint.z - _2ndStartPoint.z) * (aimPoint.z - _2ndStartPoint.z)))).floatValue();

System.out.println(aimPoint.x + “>” + aimPoint.z + “>>>” + _2ndStartPoint.x + “>” + _2ndStartPoint.z + “>>>” + waylenght);

float xMiddleWay = new Double((Math.cos(Math.toRadians(alpha)) * waylenght / 2) + _2ndStartPoint.x).floatValue();

float zMiddleWay = new Double((Math.sin(Math.toRadians(alpha)) * waylenght / 2) + _2ndStartPoint.z).floatValue();

Vector3f middleWay = new Vector3f(xMiddleWay, -2, zMiddleWay);

Box directWay = new Box(middleWay, 0.1f, 0.1f, waylenght / 2);

Geometry boxGeo = new Geometry(“BoxGeo”, directWay);

boxGeo.setMaterial(mat1);

// boxGeo.setLocalRotation(new Quaternion(new float[] { 0, new Double((Math.toRadians(90 - alpha))).floatValue(), 0 }));

float xDifference = new Double(aimPoint.x - _2ndStartPoint.x).floatValue();

float zDifference = new Double(aimPoint.z - _2ndStartPoint.z).floatValue();

Vector3f middleWay2 = new Vector3f(_2ndStartPoint.x + xDifference / 2f, -2, _2ndStartPoint.z + zDifference / 2f);

Box directWay2 = new Box(middleWay2, 0.1f, 0.1f, waylenght / 2);

Geometry boxGeo2 = new Geometry(“BoxGeo”, directWay2);

boxGeo2.setMaterial(mat1);

// boxGeo2.setLocalRotation(new Quaternion(new float[] { 0, new Double((Math.toRadians(90 - alpha))).floatValue(), 0 }));

Sphere centerPoint = new Sphere(30, 30, 0.2f);

Geometry centerGeometry = new Geometry(“CenterGeo”, centerPoint);

centerGeometry.setMaterial(mat1);

centerGeometry.setLocalTranslation(middleWay2.x, -2, middleWay2.z);

helper.attachChild(centerGeometry);

helper.attachChild(cicleGeo);

helper.attachChild(boxGeo);

helper.attachChild(boxGeo2);

parent.attachChild(helper);

}

[/java]

It will always rotate around the center, so of course it looks like the box was moving when its center is off…

Did u mean the center of the Box? in this case the pic shows that it doesn’t only rotate around point C(it’s centerPoint).

As u can see it’s shifted too.

When i tested it with a centerPoint at (0,0,0) I was only aware of a rotation without translation.

So i guess that the problem is related to the distance from the center of the coodinate system.

When you create the box with its center off that is normal, imagine you add a box in the middle of a plate and turn the plate, the box will just rotate, but if you place it on the edge of the plate it will “move” in a circle.

OK, you said that the red box rotates around a point outside of its own shape.

But, what is the intension of this???

Am I right, when I say, that the only way to rotate an Geo correctly is to create it at point (0,0,0), then rotate it and only after that translate it.

When I think of rotation of a shape I certainly let the shape rotate around its centerpoint, if there isn’t another point specified.

As I heard just now, this rotation-behaviour is caused by jme’s orientation at David H. Eberly’s book “3D Game engine design”, right.

You dont get the concept of the Geometry and Mesh. The geometry always rotates around the center. So when you create the mesh with an offset, you have defined another point.

Yes, I think that’s my problem.

I can’t remember to have this problem in jme2 where I only translated/rotated meshes.

When I understand You correctly then the centerpoints of the mesh and its Geo aren’t necessarily at the same coords.

Caused by an initial offset of the mesh the rotation of the Geo shifts the mesh another time on a circular path around Y(in this case).

Right??

And the correct way is to create a mesh without offset and make all transformations with the geo??

Right, Geometry and Mesh were kinda the same thing in jME2, in jME3 that isnt so. A Mesh is a sub-item of the Geometry.

Thanks 4 ur help.