Hi,
I have encountered a somewhat weird problem:
I have a lot of small boxes which follows along an interpolation of a motionPath. I want the boxes to follow the orientation of the motionPath. To do this I use the lookAt method on each geometry object to look at the next geometry object on the path.
[java]public void createLines(int nbSubSegments) {
int length = (spline.getControlPoints().size() - 1) * nbSubSegments + 1;
Geometry[] geoms = new Geometry[length];
Vector3f[] vectors = new Vector3f[length];
int i = 0;
int cptCP = 0;
for (Iterator<Vector3f> it = spline.getControlPoints().iterator(); it.hasNext() {
Vector3f vector3f = it.next();
Box b = new Box(vector3f, 0.2f, 0.2f, 0.2f);
Geometry geom = new Geometry(“linesegment”,b);
Material mat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
mat.setColor(“Color”,ColorRGBA.Magenta);
geom.setMaterial(mat);
rootNode.attachChild(geom);
geoms = geom;
vectors = vector3f;
geom.setLocalTranslation(vector3f);
i++;
if (it.hasNext()) {
for (int j = 1; j < nbSubSegments; j++) {
Vector3f temp = new Vector3f();
spline.interpolate((float) j / nbSubSegments, cptCP, temp);
Box c = new Box(temp, 0.2f, 0.2f, 0.2f);
Geometry geomTemp = new Geometry(“linesegment”,c);
geomTemp.setMaterial(mat);
rootNode.attachChild(geomTemp);
geoms = geomTemp;
vectors = temp;
i++;
}
}
cptCP++;
}
for(int n = 0; n < i; n++){
if(n == 0){
geoms[n].lookAt(vectors[i-1], Vector3f.UNIT_Y);
}else{
geoms[n].lookAt(vectors[n-1], Vector3f.UNIT_Y);
}
}
}[/java]
As you can see in the very last part of the code, this is where I try to change the orientation of each of the boxes. However, when I do this not only is the rotation of the boxes changed, their position is also changed!
Here is the boxes without the last for-loop:
http://i.imgur.com/Bw3iv.png
Here is the boxes WITH the last for-loop:
(Disregard the lone box)
http://i.imgur.com/j6lUV.png
Any idea what the hell is going on here? :s
You create the box mesh off-center, hence when you rotate the geometry the box orbits the center. https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:scenegraph_for_dummies
1 Like
@normen said:
You create the box mesh off-center, hence when you rotate the geometry the box orbits the center. https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:scenegraph_for_dummies
................ Thanks - I got the idea now and fixed it :)