Hi again,
I’ve encountered another problem:
I am trying to write a procedural indoor level generator that dynamically creates simple level modules and places them adjacent to another, forming a random maze.
The problem that I have with that is, that I cannot rotate any Node that I created before or in the first update.
This is the code:
level module:
[java]
public class LevelModule extends Node {
private static final float w = 10f, h = 10f;
private LinkedList<LevelModuleConnector> connectors = new LinkedList<LevelModuleConnector>();
private Material wallMat, floorMat, ceilMat, debugMat;
private RigidBodyControl phys;
public LevelModule(AssetManager am) {
[... init materials ...]
addBlock(0f, 0f, w, w, WALL, NONE, NONE, NONE);
//addBlock(w, 0f, w, w, CONN, WALL, NONE, WALL);
addBlock(0f, -w, w, w, WALL, CONN, WALL, NONE);
addBlock(-w, 0f, w, w, NONE, WALL, CONN, WALL);
addBlock(0f, w, w, w, WALL, NONE, WALL, CONN);
GeometryBatchFactory.optimize(this);
CollisionShape col = CollisionShapeFactory.createMeshShape(this);
phys = new RigidBodyControl(col, 0f);
addControl(phys);
}
private enum Wall { wall, connect, none }
private static final Wall WALL = Wall.wall;
private static final Wall CONN = Wall.connect;
private static final Wall NONE = Wall.none;
private void addDebugMarker(LevelModuleConnector c){
Box b = new Box(0.2f, 0.2f, 0.2f);
Geometry g = new Geometry("conbox", b);
g.setMaterial(debugMat);
g.move(c.getDir());
c.attachChild(g);
}
private void addConnector(Vector3f pos, Vector3f dir){
LevelModuleConnector c = new LevelModuleConnector(this, pos, dir);
connectors.add(c);
attachChild(c);
addDebugMarker(c);
}
private void addBlock(float centerx, float centerz, float sizex, float sizez,
Wall weast, Wall wnorth, Wall wwest, Wall wsouth){
[... creates a block with floor, ceiling and walls as quads wrapped in a geometry, adds them with this.attachChild(Geometry) ...]
}
public void add(Node root, BulletAppState bullet){
root.attachChild(this);
bullet.getPhysicsSpace().add(phys);
}
public void remove(Node root, BulletAppState bullet){
root.detachChild(this);
bullet.getPhysicsSpace().remove(phys);
}
public int getConnectorCount(){
return connectors.size();
}
}
[/java]
In simpleInitApp():
[java]
LevelModule m = new LevelModule(assetManager);
m.add(rootNode, bullet);
modules.add(m);
m.rotate(0, 1, 0); // this rotate has no effect on the actual rotation of m
[/java]
in simpleUpdate(float tpf):
[java]
// b is a boolean initialized with true
if(b){
b = false;
modules.getFirst().rotate(0, 1, 0); // this rotate does nothing either
}
// t is a float initialized with 0f
if(t < 2){
t += tpf;
if(t >= 2) modules.getFirst().rotate(0, 1, 0); // this rotate really rotates the module
}
[/java]
Did I do something wrong? The tutorials all rotate nodes in simpleInitApp().
Thanks for your time <3
Bunkertor