I must be crazy, so far as I know the standard(?) format for geometry is new Cube(1,1,1) makes a cube a single unit in size from the upper left (front?) corner.
It took me, I want to say three or more hours to realize/remember that jMonkeyEngine uses the center of a mesh for all calculations and there is (so far as I know and/or could find) absolutely no way to change this.
What I was doing, I believed, was simple. I wanted to create a procedure to generate a specified number of rows and columns in the form of nodes with associated meshes. (Iāll be the first to admit that some fo this is less than intelligentā¦ please forgive me)
As follows:
private void createRows(){
for(int i = 0; i<height;i++){
Node row = new Node("Row " + i);
Box box = new Box((height/2)-0.5f,0.5f,0.5f);
Geometry rowGeom = new Geometry("Row", box);
rowGeom.setMaterial(nul);
row.attachChild(rowGeom);
row.setLocalTranslation(new Vector3f(0,i,0));
if(i == 0){
createColumn(row);
}
rootNode.attachChild(row);
}
}
private void createColumn(Node row){
for(int i = 0; i<width;i++){
Node col = new Node("Col " + i);
Box box = new Box(0.5f,(width/2)+1f,0.5f);
Geometry rowGeom = new Geometry("Column", box);
rowGeom.setMaterial(nul);
col.attachChild(rowGeom);
col.setLocalTranslation(new Vector3f(2f-i,2.5f,0));
row.attachChild(col);
}
And yet, for some reason, these did not align, in any way, as I believed they should.
After tweaking them by adding additional translation (the 2f-i,2.5f seen in createColumn), I decided to recheck my understanding of geometry in jMonkey.
Sure enough, the tutorials explicitly specify that new Cube(1,1,1): āmakes the box 2x2x2 world units big.ā However it takes going into the JavaDoc to understand why:
Cube a = new Cube(1,1,1);
Cube b = new Cube(1,1,1);
b.setLocalTranslation(new Vector3f(1,0,0);
causes the cubes to intersect. From my experience using 3D modeling, and programming in general, the above should move the second cube exactly one unit to the side of the first. Instead, it moves the center of the second cube one unit to the side of the center of the first.
Alright, fair enough, but this means that any time I want to align two objects I have to calculate their center (mentally) from the location I want to allign them. If, say, I want to create overlapping rectangles in a grid pattern (see original code), I have to tell the secondary rectangles to be adjusted by 1/2 their width and height.
Again, fiar enough. I can see plenty of times this would be usefulā¦ but there is absolutely no explanation as to why this design choice was made and absolutely no warning that it was made. Believe me, I went looking for it before registering to create this book of a postā¦
Soā¦ tl;dr:
Is there a simple, built in way to define meshes/shapes by their standard (upper-left) origin and not their center? (is the upper-left-front actually standard? This, jMonkeyEngine, is literally the only thing that Iāve seen that uses the center.)