Implementing the “state” package
1. Implementing the “Posture” enumerator
The posture enumerator contains the list of animations that can be assigned to an agent during the simulation. This list corresponds to the actual list of animations that comes with the animated 3D model.
- Create a new “enum” inside the “state” package and name it “Posture”.
- Write the list of animation inside the “Posture” enum. For instance, the agent 3D model that we will use in this tutorial has the following set of animations:
package edu.utdallas.mavs.evacuation.simulation.sim.common.state; /** * An enumeration of possible human agent postures. Agents can walk, run, be idle, etc. */ public enum Posture { Act_1, Act_2, Act_3, Act_4, Act_5, Act_6, Act_7, Act_8, Applaude1, Applaude2, Applaude3, Attack_axe, Attack_hand, Attack_kick, Carry, Carry_idle, Death_backward, Death_forward, Dodge_end, Dodge_loop, Dodge_start, Down, Hit_back, Hit_front, Hit_left, Idle1, Idle2, Idle_speak, // Idle_speak2, // Jump, Pick_up, Placed, Run, Run_panic, Sit_down_1, Sit_down_2, Sitting_2, Sitting_1, Stand_up_1, Stand_up_2, Strafe_left, Strafe_right, T_pose, // Walk, Walk_back, Walk_down, Walk_left_side, Walk_panic, Walk_right_side, Walk_stealth, WEARING_HAT, // GRABBING_TREASURE, // RUNNING_TREASURE, // sit_g_start }
2. Implementing the “EHumanAgentState” class
This class describes the human agent’s state, in other words, it describes the physical conditions of a human agent. As illustrated in the below figure, the “EHumanAgentState” class extends the class “edu.utdallas.mavs.divas.core.sim.common.state.HumanAgentState”.
To implement the “EHumanAgentState” class:
- Create a new class inside the “state” package and name it “EHumanAgentState”.
- Copy the code given below that describes the full implementation of a “EHumanAgentState” class.
package edu.utdallas.mavs.evacuation.simulation.sim.common.state; import java.util.List; import com.jme3.math.Vector3f; import edu.utdallas.mavs.divas.core.config.SimConfig; import edu.utdallas.mavs.divas.core.sim.common.state.HumanAgentState; import edu.utdallas.mavs.divas.core.sim.common.state.HumanProperties.AgeCategory; import edu.utdallas.mavs.divas.core.sim.common.state.HumanProperties.BodyBuild; import edu.utdallas.mavs.divas.core.sim.common.state.HumanProperties.Gender; public class EHumanAgentState extends HumanAgentState { private static final long serialVersionUID = 1L; /** * The current posture of the agent. */ protected Posture posture = Posture.Idle1; /** * The reachable distance between the agent and another entity in the simulation. */ protected float reachDistance; /** * The body build of the agent. */ protected BodyBuild bodyBuild; /** * The gender of the agent. */ protected Gender gender; /** * The age category the agent belongs to (i.e., child, young, adult) */ protected AgeCategory ageCategory; /** * An integer representing the clothing (skin) of the agent. */ protected int clothing; /** * Debug information related to planning. To be removed. */ private String planningDetails; /** * Agent Plan for display in visualizer */ private List<Vector3f> agentPath; /** * Gets the posture of the agent. * * @return The agent posture. */ public Posture getPosture() { return posture; } /** * Changes the posture of the agent. * * @param posture * The agent posture. */ public void setPosture(Posture posture) { this.posture = posture; } /** * The reachable distance between the agent and another entity in the simulation * * @return the reachable distance to this agent. */ public float getReachDistance() { return reachDistance; } /** * Changes the distance to reach this agent. * * @param reachDistance * The new reach distance for the agent. */ public void setReachDistance(float reachDistance) { this.reachDistance = reachDistance; } /** * Gets the body build of the agent. * * @return The agent body build. */ public BodyBuild getBodyBuild() { return bodyBuild; } /** * Changes the body build of the agent. * * @param bodyBuild * The new body build for the agent. */ public void setBodyBuild(BodyBuild bodyBuild) { this.bodyBuild = bodyBuild; } /** * Gets the gender of the agent. * * @return the agent gender. */ public Gender getGender() { return gender; } /** * Sets the agent gender when the agent is first created. * * @param gender * the gender of the agent. */ public void setGender(Gender gender) { this.gender = gender; } /** * Gets the age category the agent belongs to. * * @return the agent age category. */ public AgeCategory getAgeCategory() { return ageCategory; } /** * Changes the age category the agent belongs to. * * @param ageCategory * The age category of the agent. */ public void setAgeCategory(AgeCategory ageCategory) { this.ageCategory = ageCategory; } /** * Gets the clothing of the agent. * * @return an integer representing the agent clothing. */ public int getClothing() { return clothing; } /** * Changes the agent clothing. * * @param clothing * The new agent clothing. */ public void setClothing(int clothing) { this.clothing = clothing; } /** * Sets the debug info for planning. To be removed. * * @param planningDetails */ public void setPlanningDetails(String planningDetails) { this.planningDetails = planningDetails; } /** * This method is to be used to debug purposes only. To be removed. * * @return planning debug information */ public String getPlanningDetails() { return planningDetails; } // FIXME hardcoded! public float getRadius() { return SimConfig.getInstance().agent_Radius; } public List<Vector3f> getAgentPath() { return agentPath; } public void setAgentPath(List<Vector3f> agentPath) { this.agentPath = agentPath; } /** * Changes the agent type, control type, heading, max speed, desired speed, visible distance, field of view, min * audible threshold, acoustic emission, * smell sensitivity, reach distance, posture, vision algorithm, olfactory enabled and auditory enabled of the agent * with such properties from the * given agent state. * * @param agent * The agent state to copy properties from (i.e., agent type, control type, heading) to this agent state. */ public void copyFrom(EHumanAgentState agent) { super.copyFrom(agent); reachDistance = agent.reachDistance; posture = agent.posture; clothing = agent.clothing; bodyBuild = agent.bodyBuild; ageCategory = agent.ageCategory; gender = agent.gender; } }
3. Implementing the “DoorObjectState” class
This class describes the door object’s state, in other words, it describes the physical conditions of a door object. As illustrated in the below figure, the “DoorObjectState” class extends the class “edu.utdallas.mavs.divas.core.sim.common.state.EnvObjectState”.
To implement the “DoorObjectState” class:
- Create a new class inside the “state” package and name it “DoorObjectState”.
- Copy the code given below that describes the full implementation of a “DoorObjectState” class.
package edu.utdallas.mavs.evacuation.simulation.sim.common.state; import edu.utdallas.mavs.divas.core.sim.common.state.EnvObjectState; /** * This class represents the current state of a door */ public class DoorObjectState extends EnvObjectState { private static final long serialVersionUID = -2950808581541129266L; private boolean isOpen = true; /** * Whether the door is open or not. * * @return True if open, otherwise false. */ public boolean isOpen() { return isOpen; } /** * Set whether a door is open or not * * @param isOpen * True if open, otherwise false. */ public void setOpen(boolean isOpen) { this.isOpen = isOpen; } @Override public EnvObjectState copy() { DoorObjectState copy = new DoorObjectState(); copy.setPosition(position.clone()); copy.setModelName(modelName); copy.setMaterial(material); copy.setScale(scale.clone()); copy.setRotation(rotation.clone()); copy.setType(type); copy.setOpen(isOpen); return copy; } }
4. Implementing the “ActivatedObjectState” class
This class describes the actived object ‘s state. As illustrated in the below figure, the “ActivatedObjectState” class extends the class “edu.utdallas.mavs.divas.core.sim.common.state.EnvObjectState”.
To implement the “ActivatedObjectState” class:
- Create a new class inside the “state” package and name it “ActivatedObjectState”.
- Copy the code given below that describes the full implementation of a “ActivatedObjectState” class.
package edu.utdallas.mavs.evacuation.simulation.sim.common.state; import edu.utdallas.mavs.divas.core.sim.common.state.EnvObjectState; /** * This class represents the current state of a object. */ public class ActivatedObjectState extends EnvObjectState { private static final long serialVersionUID = 0; private boolean isOn = true; ActiveObjectType activeObjectType = ActiveObjectType.SIREN; public enum ActiveObjectType { SIREN } /** * Whether is on or not. * * @return True if on, otherwise false. */ public boolean isOn() { return isOn; } /** * Set whether on or not * * @param isOn * True if on, otherwise false. */ public void setOn(boolean isOn) { this.isOn = isOn; } public ActiveObjectType getActiveObjectType() { return activeObjectType; } public void setActiveObjectType(ActiveObjectType activeObjectType) { this.activeObjectType = activeObjectType; } /** * Changes the description, type, material, rotation, available, onFire and scale of the environment object with such properties from the * given env object state. * * @param eo * The environment object state to copy properties from (i.e., description, type, material) to this environment object state. */ @Override public void copyFrom(EnvObjectState eo) { super.copyFrom(eo); if(eo instanceof ActivatedObjectState) { isOn = ((ActivatedObjectState) eo).isOn(); } } @Override public EnvObjectState copy() { ActivatedObjectState copy = new ActivatedObjectState(); copy.setPosition(position.clone()); copy.setModelName(modelName); copy.setMaterial(material); copy.setScale(scale.clone()); copy.setRotation(rotation.clone()); copy.setType(type); copy.setOn(isOn); return copy; } }