package javara.world.physical;
import javara.world.VisibleObject;
import javara.world.World;
import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
public class Hector extends VisibleObject {
protected ColorRGBA mainMatColor;
protected ColorRGBA secondaryMatColor;
protected ColorRGBA tertiaryMatColor;
protected Node hectorNode, headNode, legsNode;
protected Spatial leftLegTop, leftLegBottom;
protected Spatial rightLegTop, rightLegBottom;
protected CollisionShape collisionShape;
public Hector(World world, ColorRGBA mainColor, ColorRGBA trimColor, ColorRGBA cockpitColor) {
super(mainColor);
collisionShape = new CapsuleCollisionShape(1.5f, 0.7f, 1);
mainMatColor = mainColor;
secondaryMatColor = trimColor;
tertiaryMatColor = cockpitColor;
hectorNode = new Node(identifier);
headNode = new Node(identifier + "-Head");
legsNode = new Node(identifier + "-Legs");
Node headGeo = (Node)world.getAssetManager().loadModel("Models/hull.mesh.xml");
headGeo.rotate(0, 0, 0);
headNode.attachChild(headGeo);
Geometry barrelTrim = (Geometry)headGeo.getChild("hull-geom-1");
barrelTrim.setMaterial(world.materialForColor(trimColor));
Geometry hull = (Geometry)headGeo.getChild("hull-geom-2");
hull.setMaterial(world.materialForColor(mainColor));
Geometry cockpit = (Geometry)headGeo.getChild("hull-geom-3");
cockpit.setMaterial(world.materialForColor(cockpitColor));
Geometry crotch = (Geometry)headGeo.getChild("hull-geom-4");
crotch.setMaterial(world.materialForColor(mainColor));
// Geometry barrels = (Geometry) HeadNode.getChild("hull-geom-5");
// barrels.setMaterial(materialForColor(am,trimColor));
leftLegTop = world.getAssetManager().loadModel("Models/legHigh.mesh.xml");
rightLegTop = leftLegTop.clone();
leftLegTop.setMaterial(world.materialForColor(mainColor));
rightLegTop.setMaterial(world.materialForColor(mainColor));
leftLegBottom = world.getAssetManager().loadModel("Models/legLow.mesh.xml");
rightLegBottom = leftLegBottom.clone();
leftLegBottom.setMaterial(world.materialForColor(trimColor));
rightLegBottom.setMaterial(world.materialForColor(trimColor));
leftLegTop.setLocalTranslation(-.45f, -.45f, -.2f);
leftLegTop.setLocalRotation(new Quaternion().fromAngles(-(FastMath.PI / 4.4f), 0, 0));
rightLegTop.setLocalRotation(new Quaternion().fromAngles((FastMath.PI / 4.4f), 0, FastMath.PI));
rightLegTop.setLocalTranslation(.45f, -.45f, -.2f);
leftLegBottom.setLocalTranslation(.43f, -1.18f, -.9f);
leftLegBottom.setLocalRotation(new Quaternion().fromAngles((FastMath.PI / 4.1f), 0, 0));
rightLegBottom.setLocalTranslation(-.43f, -1.18f, -.9f);
rightLegBottom.setLocalRotation(new Quaternion().fromAngles(-(FastMath.PI / 4.1f), 0, FastMath.PI));
hectorNode.attachChild(headNode);
legsNode.attachChild(leftLegTop);
legsNode.attachChild(rightLegTop);
legsNode.attachChild(leftLegBottom);
legsNode.attachChild(rightLegBottom);
hectorNode.attachChild(legsNode);
}
public CollisionShape getCollisionShape() {
return collisionShape;
}
public Node getHectorNode() {
return hectorNode;
}
public Node getHeadNode() {
return headNode;
}
public Node getLegsNode() {
return legsNode;
}
protected float crouchFactor = 0;
protected static float CROUCH_SPEED = 4.0f;
public boolean isCrouched() {
return crouchFactor > 0.0f;
}
protected void repositionForCrouching() {
float a = 4.4f + (crouchFactor * 2.0f);
float y = -0.45f - (crouchFactor * 0.35f);
leftLegTop.setLocalTranslation(-.45f, y, -.2f);
leftLegTop.setLocalRotation(new Quaternion().fromAngles(-(FastMath.PI / a), 0, 0));
rightLegTop.setLocalRotation(new Quaternion().fromAngles((FastMath.PI / a), 0, FastMath.PI));
rightLegTop.setLocalTranslation(.45f, y, -.2f);
a = 4.1f + (crouchFactor * 2.0f);
y = -1.18f - (crouchFactor * 0.2f);
leftLegBottom.setLocalTranslation(.43f, y, -.9f);
leftLegBottom.setLocalRotation(new Quaternion().fromAngles((FastMath.PI / a), 0, 0));
rightLegBottom.setLocalTranslation(-.43f, y, -.9f);
rightLegBottom.setLocalRotation(new Quaternion().fromAngles(-(FastMath.PI / a), 0, FastMath.PI));
y = 0.0f - (crouchFactor * 0.45f);
headNode.setLocalTranslation(0, y, 0);
}
public void crouch(float tpf) {
crouchFactor = Math.min(crouchFactor + (tpf * CROUCH_SPEED), 1.0f);
repositionForCrouching();
}
public void uncrouch(float tpf) {
crouchFactor = Math.max(crouchFactor - (tpf * CROUCH_SPEED), 0.0f);
repositionForCrouching();
}
}