The “spec” package
1. Package description
The “spec” package implements the mechanisms for specifying the agent’s properties at creation time. The package contains 2 sub-packages and classes inside these sub packages as below:
- “agent” package
- “AgentSpecEnum” class
- “EvacuationAgentLoader” class
- “EvacuationAgentSpecEnum” class
- “env” package
- “DemoRoom” class
- “EvacuationEnvSpecEnum” class
- “RandomEvacRoom” class
- “SimpleRoom” class
2. The “agent” package
To implement the “AgentSpecEnum” class:
- Create a new class inside the “edu.utdallas.mavs.evacuation.simulation.spec.agent” package and name it “AgentSpecEnum”.
- Copy the code given below that describes the full implementation of a “AgentSpecEnum” class.
package edu.utdallas.mavs.evacuation.simulation.spec.agent; import edu.utdallas.mavs.divas.utils.ExtensibleEnum; /** * Enumeration with agent specification available to be used in the simulation. */ public class AgentSpecEnum extends ExtensibleEnum<AgentSpecEnum> { /** * Default agent spec */ public static final AgentSpecEnum Default = new AgentSpecEnum("Default", 0); protected AgentSpecEnum(String name) { super(name); } protected AgentSpecEnum(String name, int ordinal) { super(name, ordinal); } @Override public AgentSpecEnum[] getEnumValues() { return values(AgentSpecEnum.class); } public static AgentSpecEnum create(String name) { return new AgentSpecEnum(name); } }
To implement the “EvacuationAgentLoader” class:
- Create a new class inside the “edu.utdallas.mavs.evacuation.simulation.spec.agent” package and name it “EvacuationAgentLoader”.
- Copy the code given below that describes the full implementation of a “EvacuationAgentLoader” class.
package edu.utdallas.mavs.evacuation.simulation.spec.agent; import java.io.Serializable; import java.util.HashSet; import java.util.Random; import java.util.Set; import com.jme3.math.Vector3f; import edu.utdallas.mavs.divas.core.config.SimConfig; import edu.utdallas.mavs.divas.core.sim.common.state.AgentState; import edu.utdallas.mavs.divas.core.sim.common.state.HumanProperties.Gender; import edu.utdallas.mavs.divas.core.spec.agent.AgentLoader; import edu.utdallas.mavs.evacuation.simulation.sim.agent.task.FaceTask; import edu.utdallas.mavs.evacuation.simulation.sim.agent.task.MoveTask; import edu.utdallas.mavs.evacuation.simulation.sim.common.state.EHumanAgentState; public class EvacuationAgentLoader extends AgentLoader implements Serializable { /** * */ private static final long serialVersionUID = 1L; @Override public AgentState createAgent(String modelName) { EHumanAgentState agentState = createAgentState(modelName); agentState.setAgentType("EvacuationHuman"); agentState.setMaxSpeed(5f); agentState.setDesiredSpeed(1f); agentState.setVisibleDistance(30f); agentState.setFOV(30f); agentState.setMinAudibleThreshold(.2f); agentState.setAcousticEmission(0f); agentState.setSmellSensitivity(0.00000000001f); agentState.setReachDistance(3f); agentState.setScale(new Vector3f(1.001f, 5f, 1.001f)); agentState.setVisionAlgorithm(SimConfig.getInstance().default_Vision_Algorithm); Set<String> taskNames = new HashSet<String>(); taskNames.add(FaceTask.NAME); taskNames.add(MoveTask.NAME); agentState.setTaskNames(taskNames); return agentState; } /** * This is a factory method for generating random agents models. * @param model * * @param state * The agent state to be created * @return a spatial associated with the newly created visualized event */ public EHumanAgentState createAgentState(String model) { Random generator = new Random(); String modelNames[] = { "male_tough", "male_fat", "male_tall", "woman_fat", "woman_slim", "woman_bonus", "girl_kid", "boy_kid" }; // String modelNames[] = { "male_tough", "male_fat", "male_tall" }; String modelName = null; if(model == null || model.isEmpty()) { modelName = modelNames[generator.nextInt(3)]; } else { modelName = model; } int clothingSeed = 0; if(modelName.equals("male_tough") || modelName.equals("male_fat") || modelName.equals("male_tall")) { clothingSeed = 20; } else if(modelName.equals("woman_fat") || modelName.equals("woman_slim")) { clothingSeed = 11; } else if(modelName.equals("woman_bonus")) { clothingSeed = 3; } else if(modelName.equals("girl_kid")) { clothingSeed = 12; } else if(modelName.equals("boy_kid")) { clothingSeed = 6; } EHumanAgentState agentState = new EHumanAgentState(); int agentClothing = generator.nextInt(clothingSeed) + 1; agentState.setClothing(agentClothing); if(modelName.equals("male_tough") || modelName.equals("male_fat") || modelName.equals("male_tall") || modelName.equals("boy_kid")) { agentState.setGender(Gender.MALE); } else { agentState.setGender(Gender.FEMALE); } agentState.setModelName(modelName + agentClothing); return agentState; } /** * This is a factory method for getting the appropriate agent spec. * * @param modelName * The model name for the agent * @return The posture related to the agent */ public String getAgentSpecName(String modelName) { return AgentSpecEnum.Default.toString().toLowerCase(); } }
To implement the “EvacuationAgentSpecEnum” class:
- Create a new class inside the “edu.utdallas.mavs.evacuation.simulation.spec.agent” package and name it “EvacuationAgentSpecEnum”.
- Copy the code given below that describes the full implementation of a “EvacuationAgentSpecEnum” class.
package edu.utdallas.mavs.evacuation.simulation.spec.agent; /** * Enumeration with agent specification available to be used in the simulation. */ public class EvacuationAgentSpecEnum { /** * Agent woman spec */ public static final AgentSpecEnum Woman = AgentSpecEnum.create("Woman"); }
2.The “env” package
To implement the “DemoRoom” class:
- Create a new class inside the “edu.utdallas.mavs.evacuation.simulation.spec.env” package and name it “DemoRoom”.
- Copy the code given below that describes the full implementation of a “DemoRoom” class.
package edu.utdallas.mavs.evacuation.simulation.spec.env; import org.apache.log4j.PropertyConfigurator; import com.jme3.math.Quaternion; import com.jme3.math.Vector3f; import edu.utdallas.mavs.divas.core.sim.common.state.EnvObjectState; import edu.utdallas.mavs.divas.core.sim.env.CellBounds; import edu.utdallas.mavs.divas.core.sim.env.CellID; import edu.utdallas.mavs.divas.core.spec.env.CellStateSpec; import edu.utdallas.mavs.divas.core.spec.env.EnvLoader; import edu.utdallas.mavs.divas.core.spec.env.EnvSpec; public class DemoRoom { public static void main(String[] args) { // configure logging properties PropertyConfigurator.configure("log4j.properties"); EnvSpec envSpec = new EnvSpec(String.format("%s.xml", EvacuationEnvSpecEnum.DemoRoom), new EnvLoader()); CellStateSpec cell = new CellStateSpec(CellID.rootID(), new CellBounds(-200, 200, -200, 200, -200, 200)); envSpec.setCellState(cell); EnvObjectState state; state = new EnvObjectState(); state.setDescription("floor"); state.setModelName("floor"); state.setType("floor"); state.setMaterial("cement"); state.setPosition(new Vector3f(0, 0, 0)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(200, .01f, 200)); state.setCollidable(false); state.setVisualized(false); cell.addEnvObject(state); state = new EnvObjectState(); state.setDescription("floor"); state.setModelName("floor"); state.setType("floor"); state.setMaterial("cement"); state.setPosition(new Vector3f(0, 0, 0)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(50, .1f, 50)); state.setCollidable(false); cell.addEnvObject(state); state = new EnvObjectState(); state.setDescription("box"); state.setModelName("box"); state.setType("box"); state.setMaterial("brick"); state.setPosition(new Vector3f(0, 0, 20)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(4, 3, 4)); cell.addEnvObject(state); state = new EnvObjectState(); state.setDescription("box"); state.setModelName("box"); state.setType("wall"); state.setMaterial("cut20L"); state.setPosition(new Vector3f(-50, 0, 0)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(.5f, 8, 50)); cell.addEnvObject(state); state = new EnvObjectState(); state.setDescription("box"); state.setModelName("box"); state.setType("wall"); state.setMaterial("cut20L"); state.setPosition(new Vector3f(50, 0, 0)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(.5f, 8, 50)); cell.addEnvObject(state); state = new EnvObjectState(); state.setDescription("box"); state.setModelName("box"); state.setType("wall"); state.setMaterial("cut20L"); state.setPosition(new Vector3f(0, 0, -50)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(50, 8, .5f)); cell.addEnvObject(state); state = new EnvObjectState(); state.setDescription("box"); state.setModelName("box"); state.setType("wall"); state.setMaterial("cut20L"); state.setPosition(new Vector3f(-25.5f, 0, 50)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(24, 8, .5f)); cell.addEnvObject(state); state = new EnvObjectState(); state.setDescription("box"); state.setModelName("box"); state.setType("wall"); state.setMaterial("cut20L"); state.setPosition(new Vector3f(25.5f, 0, 50)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(24, 8, .5f)); cell.addEnvObject(state); state = new EnvObjectState(); state.setDescription("door"); state.setModelName("door"); state.setType("door"); state.setMaterial("door"); state.setPosition(new Vector3f(0, 0, 50)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(2, 20, 2)); state.setCollidable(false); cell.addEnvObject(state); state = new EnvObjectState(); state.setDescription("box"); state.setModelName("box"); state.setType("wall"); state.setMaterial("cut20L"); state.setPosition(new Vector3f(-25.5f, 0, -20)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(24, 8, .5f)); cell.addEnvObject(state); state = new EnvObjectState(); state.setDescription("box"); state.setModelName("box"); state.setType("wall"); state.setMaterial("cut20L"); state.setPosition(new Vector3f(25.5f, 0, -20)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(24, 8, .5f)); cell.addEnvObject(state); state = new EnvObjectState(); state.setDescription("door"); state.setModelName("door"); state.setType("door"); state.setMaterial("door"); state.setPosition(new Vector3f(0, 0, -20)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(2, 20, 2)); state.setCollidable(false); cell.addEnvObject(state); state = new EnvObjectState(); state.setDescription("box"); state.setModelName("box"); state.setType("wall"); state.setMaterial("cut20L"); state.setPosition(new Vector3f(-20, 0, -25.5f)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(.5f, 8, 24)); cell.addEnvObject(state); state = new EnvObjectState(); state.setDescription("box"); state.setModelName("box"); state.setType("wall"); state.setMaterial("cut20L"); state.setPosition(new Vector3f(-20, 0, 25.5f)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(.5f, 8, 24)); cell.addEnvObject(state); state = new EnvObjectState(); state.setDescription("door"); state.setModelName("door"); state.setType("door"); state.setMaterial("door"); state.setPosition(new Vector3f(-20, 0, 0)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(2, 20, 2)); state.setCollidable(false); cell.addEnvObject(state); state = new EnvObjectState(); state.setDescription("box"); state.setModelName("box"); state.setType("wall"); state.setMaterial("cut20L"); state.setPosition(new Vector3f(20, 0, -25.5f)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(.5f, 8, 24)); cell.addEnvObject(state); state = new EnvObjectState(); state.setDescription("box"); state.setModelName("box"); state.setType("wall"); state.setMaterial("cut20L"); state.setPosition(new Vector3f(20, 0, 25.5f)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(.5f, 8, 24)); cell.addEnvObject(state); state = new EnvObjectState(); state.setDescription("door"); state.setModelName("door"); state.setType("door"); state.setMaterial("door"); state.setPosition(new Vector3f(20, 0, 0)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(2, 20, 2)); state.setCollidable(false); cell.addEnvObject(state); state = new EnvObjectState(); state.setDescription("table"); state.setModelName("table"); state.setType("table"); state.setMaterial(""); state.setPosition(new Vector3f(40, 0, 40)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(2, 2, 2)); cell.addEnvObject(state); //envSpec.saveToFile(); envSpec.saveToXML(); } }
To implement the “EvacuationEnvSpecEnum” class:
- Create a new class inside the “edu.utdallas.mavs.evacuation.simulation.spec.env” package and name it “EvacuationEnvSpecEnum”.
- Copy the code given below that describes the full implementation of a “EvacuationEnvSpecEnum” class.
package edu.utdallas.mavs.evacuation.simulation.spec.env; import edu.utdallas.mavs.divas.core.spec.env.EnvSpecEnum; /** * Enumeration of environments available to be used in the simulation. */ public class EvacuationEnvSpecEnum { /** * Complex room containing 19 environment objects. */ public final static EnvSpecEnum DemoRoom = EnvSpecEnum.create("DemoRoom"); /** * Larger room containing random environment objects. */ public final static EnvSpecEnum RandomEvacRoom = EnvSpecEnum.create("RandomEvacRoom"); /** * Larger room containing random environment objects. */ public final static EnvSpecEnum SimpleRoom = EnvSpecEnum.create("SimpleRoom"); }
To implement the “RandomEvacRoom” class:
- Create a new class inside the “edu.utdallas.mavs.evacuation.simulation.spec.env” package and name it “RandomEvacRoom”.
- Copy the code given below that describes the full implementation of a “RandomEvacRoom” class.
package edu.utdallas.mavs.evacuation.simulation.spec.env; import java.util.HashMap; import java.util.Random; import org.apache.log4j.PropertyConfigurator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.jme3.math.Quaternion; import com.jme3.math.Vector3f; import edu.utdallas.mavs.divas.core.sim.common.state.EnvObjectState; import edu.utdallas.mavs.divas.core.sim.env.CellBounds; import edu.utdallas.mavs.divas.core.sim.env.CellID; import edu.utdallas.mavs.divas.core.spec.env.CellStateSpec; import edu.utdallas.mavs.divas.core.spec.env.EnvLoader; import edu.utdallas.mavs.divas.core.spec.env.EnvSpec; import edu.utdallas.mavs.evacuation.simulation.sim.common.state.ActivatedObjectState; import edu.utdallas.mavs.evacuation.simulation.sim.common.state.DoorObjectState; public class RandomEvacRoom { private static final Logger logger = LoggerFactory.getLogger(RandomEvacRoom.class); private static final int SEED = 4447; static CellStateSpec cell; static int wallSize = 180; static Random r; static float doorChance = .30f; static float blockChance = .40f; static float doorOpenChance = .00f; static int roomsize = 30; static float wallThickness = .5f; static float outsideWallThickness = 2; static HashMap<Integer, Boolean> slotv = new HashMap<Integer, Boolean>(); static HashMap<Integer, Boolean> sloth = new HashMap<Integer, Boolean>(); static HashMap<Integer, Boolean> wallv = new HashMap<Integer, Boolean>(); static HashMap<Integer, Boolean> wallh = new HashMap<Integer, Boolean>(); static int doorcount = 0; static int obstaclecount = 0; private static float noWallChance = .4f; private static float sirenChance = 1f; private static int sirenDistance = 120; public static void main(String[] args) { // configure logging properties PropertyConfigurator.configure("log4j.properties"); for(int i = -wallSize; i <= wallSize; i++) { slotv.put(i, false); sloth.put(i, false); wallv.put(i, false); wallh.put(i, false); } r = new Random(SEED); EnvSpec envSpec = new EnvSpec(String.format("%s.xml", EvacuationEnvSpecEnum.RandomEvacRoom), new EnvLoader()); cell = new CellStateSpec(CellID.rootID(), new CellBounds(-wallSize * 2, wallSize * 2, -wallSize * 2, wallSize * 2, -wallSize * 2, wallSize * 2)); envSpec.setCellState(cell); makeFloor(); makeRoom(); //envSpec.saveToFile(); envSpec.saveToXML(); logger.info("Created environment with {} doors, {} obstacles", doorcount, obstaclecount); } private static void makeVDooredSection(float location, float location2) { EnvObjectState state; state = new EnvObjectState(); state.setDescription("box"); state.setModelName("box"); state.setType("wall"); state.setMaterial("cut20L"); state.setPosition(new Vector3f(location, 0, location2 - 9)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(wallThickness, 8, 6)); cell.addEnvObject(state); state = new DoorObjectState(); state.setDescription("door"); state.setModelName("door"); state.setType("door"); state.setMaterial("door"); state.setPosition(new Vector3f(location, 0, location2)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(wallThickness, 8, 3)); state.setCollidable(false); if(r.nextFloat() > doorOpenChance) { ((DoorObjectState) state).setOpen(false); state.setCollidable(true); } cell.addEnvObject(state); doorcount++; state = new EnvObjectState(); state.setDescription("box"); state.setModelName("box"); state.setType("wall"); state.setMaterial("cut20L"); state.setPosition(new Vector3f(location, 0, location2 + 9)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(wallThickness, 8, 6)); cell.addEnvObject(state); } private static void makeVWalledSection(float location, float location2) { EnvObjectState state; state = new EnvObjectState(); state.setDescription("box"); state.setModelName("box"); state.setType("wall"); state.setMaterial("cut20L"); state.setPosition(new Vector3f(location, 0, location2)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(wallThickness, 8, 15)); cell.addEnvObject(state); } private static void makeHWalledSection(float location, float location2) { EnvObjectState state; state = new EnvObjectState(); state.setDescription("box"); state.setModelName("box"); state.setType("wall"); state.setMaterial("cut20L"); state.setPosition(new Vector3f(location2, 0, location)); state.setRotation(new Quaternion(0, 0, 0, 0)); // if(wallv.get((int) location2 + 15) && wallv.get((int) (location2 - 15))) // state.setScale(new Vector3f(15 - 1, 8, wallThickness)); // // if(!wallv.get((int) location2 + 15) && !wallv.get((int) (location2 - 15))) // state.setScale(new Vector3f(15, 8, wallThickness)); // // if(!wallv.get((int) location2 + 15) && wallv.get((int) (location2 - 15))) // { // state.setPosition(new Vector3f(location2 + .5f, 0, location)); // state.setScale(new Vector3f(15 - .5f, 8, wallThickness)); // } // // if(wallv.get((int) location2 + 15) && !wallv.get((int) (location2 - 15))) // { // state.setPosition(new Vector3f(location2 - .5f, 0, location)); // state.setScale(new Vector3f(15 - .5f, 8, wallThickness)); // } state.setScale(new Vector3f(15, 8, wallThickness)); cell.addEnvObject(state); } private static void makeHDooredSection(float location, float location2) { EnvObjectState state; state = new EnvObjectState(); state.setDescription("box"); state.setModelName("box"); state.setType("wall"); state.setMaterial("cut20L"); state.setPosition(new Vector3f(location2 - 9, 0, location)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(6, 8, wallThickness)); // if(wallv.get((int) (location2 - 15))) // { // state.setScale(new Vector3f(6.5f, 8, wallThickness)); // state.setPosition(new Vector3f(location2 - 8f, 0, location)); // } cell.addEnvObject(state); state = new DoorObjectState(); state.setDescription("door"); state.setModelName("door"); state.setType("door"); state.setMaterial("door"); state.setPosition(new Vector3f(location2, 0, location)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(3, 8, wallThickness)); state.setCollidable(false); if(r.nextFloat() > doorOpenChance) { ((DoorObjectState) state).setOpen(false); state.setCollidable(true); } cell.addEnvObject(state); doorcount++; state = new EnvObjectState(); state.setDescription("box"); state.setModelName("box"); state.setType("wall"); state.setMaterial("cut20L"); state.setPosition(new Vector3f(location2 + 9, 0, location)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(6, 8, wallThickness)); // if(wallv.get((int) (location2 + 15))) // { // state.setScale(new Vector3f(6.5f, 8, wallThickness)); // state.setPosition(new Vector3f(location2 + 8f, 0, location)); // } cell.addEnvObject(state); } private static void makeRoom() { for(int i = -wallSize + roomsize; i < wallSize; i = i + roomsize) { if(r.nextFloat() > noWallChance) { wallv.put(i, true); System.out.println(i); } if(r.nextFloat() > noWallChance) { wallh.put(i, true); } } for(int i = -wallSize + roomsize; i < wallSize; i = i + roomsize) { if(wallv.get(i)) { makeVWall(i); } if(wallh.get(i)) { makeHWall(i); } } makeOutsideWalls(); makeBlocks(); makeSirens(); } private static void makeSirens() { ActivatedObjectState siren; for(int i = -wallSize; i <= wallSize; i = i + sirenDistance) { for(int j = -wallSize; j <= wallSize; j = j + sirenDistance) { if(r.nextFloat() < sirenChance) { siren = new ActivatedObjectState(); siren.setDescription("siren"); siren.setModelName("siren"); siren.setType("siren"); siren.setMaterial("siren"); siren.setPosition(new Vector3f(i, 10, j)); siren.setRotation(new Quaternion(0, 0, 0, 0)); siren.setScale(new Vector3f(.3f, .3f, .3f)); siren.setOn(false); siren.setCollidable(false); cell.addEnvObject(siren); } } } } private static void makeBlocks() { EnvObjectState state; for(int i = -wallSize + 15; i < wallSize; i = i + roomsize) { for(int j = -wallSize + 15; j < wallSize; j = j + roomsize) { if(r.nextFloat() < blockChance) { state = new EnvObjectState(); state.setDescription("box"); state.setModelName("box"); state.setType("box"); state.setMaterial("brick"); state.setPosition(new Vector3f(i, 0, j)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(r.nextInt(3) + 1, 3, r.nextInt(3) + 1)); cell.addEnvObject(state); obstaclecount++; } } } } private static void makeOutsideWalls() { makeOutsideVWall(wallSize + 2); makeOutsideVWall(-wallSize - 2); makeOutsideHWall(wallSize + 2); makeOutsideHWall(-wallSize - 2); } private static void makeVWall(int location) { for(int i = -wallSize + 15; i < wallSize; i = i + roomsize) { if(i + roomsize > wallSize) { slotv.put(i, false); } if(slotv.get(i) == false) { makeVDooredSection(location, i); slotv.put(i, true); } else { if(r.nextFloat() > doorChance) { makeVWalledSection(location, i); slotv.put(i, false); } else { makeVDooredSection(location, i); slotv.put(i, true); } } } } private static void makeHWall(int location) { for(int i = -wallSize + 15; i < wallSize; i = i + roomsize) { if(i + roomsize > wallSize) { sloth.put(i, false); } if(sloth.get(i) == false) { makeHDooredSection(location, i); sloth.put(i, true); } else { if(r.nextFloat() > doorChance) { makeHWalledSection(location, i); sloth.put(i, false); } else { makeHDooredSection(location, i); sloth.put(i, true); } } } } private static void makeOutsideVWall(float location) { float wallThickness = outsideWallThickness; EnvObjectState state; state = new EnvObjectState(); state.setDescription("box"); state.setModelName("box"); state.setType("wall"); state.setMaterial("cut20L"); state.setPosition(new Vector3f(location, 0, wallSize / 2 + 8.5f)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(wallThickness, 10, wallSize / 2 - 8.5f)); cell.addEnvObject(state); state = new EnvObjectState(); state.setDescription("box"); state.setModelName("box"); state.setType("wall"); state.setMaterial("cut20L"); state.setPosition(new Vector3f(location, 0, -wallSize / 2 - 8.5f)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(wallThickness, 10, wallSize / 2 - 8.5f)); cell.addEnvObject(state); state = new EnvObjectState(); state.setDescription("box"); state.setModelName("box"); state.setType("wall"); state.setMaterial("cut20L"); state.setPosition(new Vector3f(location, 0, 0)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(wallThickness, 10, 5)); cell.addEnvObject(state); state = new DoorObjectState(); state.setDescription("outsidedoor"); state.setModelName("door"); state.setType("door"); state.setMaterial("door"); state.setPosition(new Vector3f(location, 0, -11)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(wallThickness, 10, 6)); state.setCollidable(false); cell.addEnvObject(state); state = new DoorObjectState(); state.setDescription("outsidedoor"); state.setModelName("door"); state.setType("door"); state.setMaterial("door"); state.setPosition(new Vector3f(location, 0, 11)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(wallThickness, 10, 6)); state.setCollidable(false); cell.addEnvObject(state); } private static void makeOutsideHWall(float location) { float wallThickness = outsideWallThickness; EnvObjectState state; state = new EnvObjectState(); state.setDescription("box"); state.setModelName("box"); state.setType("wall"); state.setMaterial("cut20L"); state.setPosition(new Vector3f(wallSize / 2 + 10.5f, 0, location)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(wallSize / 2 - 6.5f, 10, wallThickness)); cell.addEnvObject(state); state = new EnvObjectState(); state.setDescription("box"); state.setModelName("box"); state.setType("wall"); state.setMaterial("cut20L"); state.setPosition(new Vector3f(-wallSize / 2 - 10.5f, 0, location)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(wallSize / 2 - 6.5f, 10, wallThickness)); cell.addEnvObject(state); state = new EnvObjectState(); state.setDescription("box"); state.setModelName("box"); state.setType("wall"); state.setMaterial("cut20L"); state.setPosition(new Vector3f(0, 0, location)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(5, 10, wallThickness)); cell.addEnvObject(state); state = new DoorObjectState(); state.setDescription("outsidedoor"); state.setModelName("door"); state.setType("door"); state.setMaterial("door"); state.setPosition(new Vector3f(-11, 0, location)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(6, 10, wallThickness)); state.setCollidable(false); cell.addEnvObject(state); state = new DoorObjectState(); state.setDescription("outsidedoor"); state.setModelName("door"); state.setType("door"); state.setMaterial("door"); state.setPosition(new Vector3f(11, 0, location)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(6, 10, wallThickness)); state.setCollidable(false); cell.addEnvObject(state); } private static void makeFloor() { EnvObjectState state; state = new EnvObjectState(); state.setDescription("floor"); state.setModelName("floor"); state.setType("floor"); state.setMaterial("cement"); state.setPosition(new Vector3f(0, 0, 0)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(wallSize, .1f, wallSize)); state.setCollidable(false); cell.addEnvObject(state); state = new EnvObjectState(); state.setDescription("grass"); state.setModelName("grass"); state.setType("floor"); state.setMaterial("grass"); state.setPosition(new Vector3f(0, -.2f, 0)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(wallSize + 100, .1f, wallSize + 100)); state.setCollidable(false); cell.addEnvObject(state); } }
To implement the “SimpleRoom” class:
- Create a new class inside the “edu.utdallas.mavs.evacuation.simulation.spec.env” package and name it “SimpleRoom”.
- Copy the code given below that describes the full implementation of a “SimpleRoom” class.
package edu.utdallas.mavs.evacuation.simulation.spec.env; import org.apache.log4j.PropertyConfigurator; import com.jme3.math.Quaternion; import com.jme3.math.Vector3f; import edu.utdallas.mavs.divas.core.sim.common.state.EnvObjectState; import edu.utdallas.mavs.divas.core.sim.env.CellBounds; import edu.utdallas.mavs.divas.core.sim.env.CellID; import edu.utdallas.mavs.divas.core.spec.env.CellStateSpec; import edu.utdallas.mavs.divas.core.spec.env.EnvLoader; import edu.utdallas.mavs.divas.core.spec.env.EnvSpec; public class SimpleRoom { public static void main(String[] args) { // configure logging properties PropertyConfigurator.configure("log4j.properties"); EnvSpec envSpec = new EnvSpec(String.format("%s.xml", EvacuationEnvSpecEnum.SimpleRoom), new EnvLoader()); CellStateSpec cell = new CellStateSpec(CellID.rootID(), new CellBounds(-400, 400, -400, 400, -400, 400)); envSpec.setCellState(cell); EnvObjectState state; state = new EnvObjectState(); state.setDescription("floor"); state.setModelName("floor"); state.setType("floor"); state.setMaterial("cement"); state.setPosition(new Vector3f(0, 0, 0)); state.setRotation(new Quaternion(0, 0, 0, 0)); state.setScale(new Vector3f(400, .1f, 400)); state.setCollidable(false); cell.addEnvObject(state); //envSpec.saveToFile(); envSpec.saveToXML(); } }