use of com.jme3.bounding.BoundingBox in project jmonkeyengine by jMonkeyEngine.
the class TestFancyCar method buildPlayer.
private void buildPlayer() {
//200=f1 car
float stiffness = 120.0f;
//(lower than damp!)
float compValue = 0.2f;
float dampValue = 0.3f;
final float mass = 400;
//Load model and get chassis Geometry
carNode = (Node) assetManager.loadModel("Models/Ferrari/Car.scene");
carNode.setShadowMode(ShadowMode.Cast);
Geometry chasis = findGeom(carNode, "Car");
BoundingBox box = (BoundingBox) chasis.getModelBound();
//Create a hull collision shape for the chassis
CollisionShape carHull = CollisionShapeFactory.createDynamicMeshShape(chasis);
//Create a vehicle control
player = new VehicleControl(carHull, mass);
carNode.addControl(player);
//Setting default values for wheels
player.setSuspensionCompression(compValue * 2.0f * FastMath.sqrt(stiffness));
player.setSuspensionDamping(dampValue * 2.0f * FastMath.sqrt(stiffness));
player.setSuspensionStiffness(stiffness);
player.setMaxSuspensionForce(10000);
//Create four wheels and add them at their locations
//note that our fancy car actually goes backwards..
Vector3f wheelDirection = new Vector3f(0, -1, 0);
Vector3f wheelAxle = new Vector3f(-1, 0, 0);
Geometry wheel_fr = findGeom(carNode, "WheelFrontRight");
wheel_fr.center();
box = (BoundingBox) wheel_fr.getModelBound();
wheelRadius = box.getYExtent();
float back_wheel_h = (wheelRadius * 1.7f) - 1f;
float front_wheel_h = (wheelRadius * 1.9f) - 1f;
player.addWheel(wheel_fr.getParent(), box.getCenter().add(0, -front_wheel_h, 0), wheelDirection, wheelAxle, 0.2f, wheelRadius, true);
Geometry wheel_fl = findGeom(carNode, "WheelFrontLeft");
wheel_fl.center();
box = (BoundingBox) wheel_fl.getModelBound();
player.addWheel(wheel_fl.getParent(), box.getCenter().add(0, -front_wheel_h, 0), wheelDirection, wheelAxle, 0.2f, wheelRadius, true);
Geometry wheel_br = findGeom(carNode, "WheelBackRight");
wheel_br.center();
box = (BoundingBox) wheel_br.getModelBound();
player.addWheel(wheel_br.getParent(), box.getCenter().add(0, -back_wheel_h, 0), wheelDirection, wheelAxle, 0.2f, wheelRadius, false);
Geometry wheel_bl = findGeom(carNode, "WheelBackLeft");
wheel_bl.center();
box = (BoundingBox) wheel_bl.getModelBound();
player.addWheel(wheel_bl.getParent(), box.getCenter().add(0, -back_wheel_h, 0), wheelDirection, wheelAxle, 0.2f, wheelRadius, false);
player.getWheel(2).setFrictionSlip(4);
player.getWheel(3).setFrictionSlip(4);
rootNode.attachChild(carNode);
getPhysicsSpace().add(player);
}
use of com.jme3.bounding.BoundingBox in project jmonkeyengine by jMonkeyEngine.
the class TestBatchNode method updateBoindPoints.
//
public void updateBoindPoints(Vector3f[] points) {
BoundingBox bb = (BoundingBox) batch.getWorldBound();
float xe = bb.getXExtent();
float ye = bb.getYExtent();
float ze = bb.getZExtent();
float x = bb.getCenter().x;
float y = bb.getCenter().y;
float z = bb.getCenter().z;
points[0].set(new Vector3f(x - xe, y - ye, z - ze));
points[1].set(new Vector3f(x - xe, y + ye, z - ze));
points[2].set(new Vector3f(x + xe, y + ye, z - ze));
points[3].set(new Vector3f(x + xe, y - ye, z - ze));
points[4].set(new Vector3f(x + xe, y - ye, z + ze));
points[5].set(new Vector3f(x - xe, y - ye, z + ze));
points[6].set(new Vector3f(x - xe, y + ye, z + ze));
points[7].set(new Vector3f(x + xe, y + ye, z + ze));
}
use of com.jme3.bounding.BoundingBox in project jmonkeyengine by jMonkeyEngine.
the class TestHoveringTank method makeMissile.
public void makeMissile() {
Vector3f pos = spaceCraft.getWorldTranslation().clone();
Quaternion rot = spaceCraft.getWorldRotation();
Vector3f dir = rot.getRotationColumn(2);
Spatial missile = assetManager.loadModel("Models/SpaceCraft/Rocket.mesh.xml");
missile.scale(0.5f);
missile.rotate(0, FastMath.PI, 0);
missile.updateGeometricState();
BoundingBox box = (BoundingBox) missile.getWorldBound();
final Vector3f extent = box.getExtent(null);
BoxCollisionShape boxShape = new BoxCollisionShape(extent);
missile.setName("Missile");
missile.rotate(rot);
missile.setLocalTranslation(pos.addLocal(0, extent.y * 4.5f, 0));
missile.setLocalRotation(hoverControl.getPhysicsRotation());
missile.setShadowMode(ShadowMode.Cast);
RigidBodyControl control = new BombControl(assetManager, boxShape, 20);
control.setLinearVelocity(dir.mult(100));
control.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_03);
missile.addControl(control);
rootNode.attachChild(missile);
getPhysicsSpace().add(missile);
}
use of com.jme3.bounding.BoundingBox in project jmonkeyengine by jMonkeyEngine.
the class TerrainTestAdvanced method createAxisMarker.
protected Node createAxisMarker(float arrowSize) {
Material redMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
redMat.getAdditionalRenderState().setWireframe(true);
redMat.setColor("Color", ColorRGBA.Red);
Material greenMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
greenMat.getAdditionalRenderState().setWireframe(true);
greenMat.setColor("Color", ColorRGBA.Green);
Material blueMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
blueMat.getAdditionalRenderState().setWireframe(true);
blueMat.setColor("Color", ColorRGBA.Blue);
Node axis = new Node();
// create arrows
Geometry arrowX = new Geometry("arrowX", new Arrow(new Vector3f(arrowSize, 0, 0)));
arrowX.setMaterial(redMat);
Geometry arrowY = new Geometry("arrowY", new Arrow(new Vector3f(0, arrowSize, 0)));
arrowY.setMaterial(greenMat);
Geometry arrowZ = new Geometry("arrowZ", new Arrow(new Vector3f(0, 0, arrowSize)));
arrowZ.setMaterial(blueMat);
axis.attachChild(arrowX);
axis.attachChild(arrowY);
axis.attachChild(arrowZ);
//axis.setModelBound(new BoundingBox());
return axis;
}
use of com.jme3.bounding.BoundingBox in project jmonkeyengine by jMonkeyEngine.
the class TestTexture3D method simpleInitApp.
@Override
public void simpleInitApp() {
//mouseInput.setCursorVisible(true);
flyCam.setMoveSpeed(10);
//creating a sphere
Sphere sphere = new Sphere(32, 32, 1);
//getting the boundingbox
sphere.updateBound();
BoundingBox bb = (BoundingBox) sphere.getBound();
Vector3f min = bb.getMin(null);
float[] ext = new float[] { bb.getXExtent() * 2, bb.getYExtent() * 2, bb.getZExtent() * 2 };
//we need to change the UV coordinates (the sphere is assumet to be inside the 3D image box)
sphere.clearBuffer(Type.TexCoord);
VertexBuffer vb = sphere.getBuffer(Type.Position);
FloatBuffer fb = (FloatBuffer) vb.getData();
float[] uvCoordinates = BufferUtils.getFloatArray(fb);
//now transform the coordinates so that they are in the range of <0; 1>
for (int i = 0; i < uvCoordinates.length; i += 3) {
uvCoordinates[i] = (uvCoordinates[i] - min.x) / ext[0];
uvCoordinates[i + 1] = (uvCoordinates[i + 1] - min.y) / ext[1];
uvCoordinates[i + 2] = (uvCoordinates[i + 2] - min.z) / ext[2];
}
//apply new texture coordinates
VertexBuffer uvCoordsBuffer = new VertexBuffer(Type.TexCoord);
uvCoordsBuffer.setupData(Usage.Static, 3, com.jme3.scene.VertexBuffer.Format.Float, BufferUtils.createFloatBuffer(uvCoordinates));
sphere.setBuffer(uvCoordsBuffer);
//create geometry, and apply material and our 3D texture
Geometry g = new Geometry("sphere", sphere);
Material material = new Material(assetManager, "jme3test/texture/tex3D.j3md");
try {
Texture texture = this.getTexture();
material.setTexture("Texture", texture);
} catch (IOException e) {
e.printStackTrace();
}
g.setMaterial(material);
rootNode.attachChild(g);
//add some light so that it is visible
PointLight light = new PointLight();
light.setColor(ColorRGBA.White);
light.setPosition(new Vector3f(5, 5, 5));
light.setRadius(20);
rootNode.addLight(light);
light = new PointLight();
light.setColor(ColorRGBA.White);
light.setPosition(new Vector3f(-5, -5, -5));
light.setRadius(20);
rootNode.addLight(light);
}
Aggregations