use of com.jme3.scene.Node in project jmonkeyengine by jMonkeyEngine.
the class TestAttachGhostObject method setupJoint.
public void setupJoint() {
Node holderNode = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(.1f, .1f, .1f)), 0);
holderNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, 0, 0f));
rootNode.attachChild(holderNode);
getPhysicsSpace().add(holderNode);
Node hammerNode = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(.3f, .3f, .3f)), 1);
hammerNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(0f, -1, 0f));
rootNode.attachChild(hammerNode);
getPhysicsSpace().add(hammerNode);
//immovable
collisionNode = PhysicsTestHelper.createPhysicsTestNode(assetManager, new BoxCollisionShape(new Vector3f(.3f, .3f, .3f)), 0);
collisionNode.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(1.8f, 0, 0f));
rootNode.attachChild(collisionNode);
getPhysicsSpace().add(collisionNode);
//ghost node
ghostControl = new GhostControl(new SphereCollisionShape(0.7f));
hammerNode.addControl(ghostControl);
getPhysicsSpace().add(ghostControl);
joint = new HingeJoint(holderNode.getControl(RigidBodyControl.class), hammerNode.getControl(RigidBodyControl.class), Vector3f.ZERO, new Vector3f(0f, -1, 0f), Vector3f.UNIT_Z, Vector3f.UNIT_Z);
getPhysicsSpace().add(joint);
}
use of com.jme3.scene.Node in project jmonkeyengine by jMonkeyEngine.
the class TestCollisionShapeFactory method attachRandomGeometry.
private void attachRandomGeometry(Node node, Material mat) {
Box box = new Box(0.25f, 0.25f, 0.25f);
Torus torus = new Torus(16, 16, 0.2f, 0.8f);
Geometry[] boxes = new Geometry[] { new Geometry("box1", box), new Geometry("box2", box), new Geometry("box3", box), new Geometry("torus1", torus), new Geometry("torus2", torus), new Geometry("torus3", torus) };
for (int i = 0; i < boxes.length; i++) {
Geometry geometry = boxes[i];
geometry.setLocalTranslation((float) Math.random() * 10 - 10, (float) Math.random() * 10 - 10, (float) Math.random() * 10 - 10);
geometry.setLocalRotation(new Quaternion().fromAngles((float) Math.random() * FastMath.PI, (float) Math.random() * FastMath.PI, (float) Math.random() * FastMath.PI));
geometry.setLocalScale((float) Math.random() * 10 - 10, (float) Math.random() * 10 - 10, (float) Math.random() * 10 - 10);
geometry.setMaterial(mat);
node.attachChild(geometry);
}
}
use of com.jme3.scene.Node in project jmonkeyengine by jMonkeyEngine.
the class TestFancyCar method findGeom.
// public void setupFloor() {
// Material mat = assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall.j3m");
// mat.getTextureParam("DiffuseMap").getTextureValue().setWrap(WrapMode.Repeat);
//// mat.getTextureParam("NormalMap").getTextureValue().setWrap(WrapMode.Repeat);
//// mat.getTextureParam("ParallaxMap").getTextureValue().setWrap(WrapMode.Repeat);
//
// Box floor = new Box(Vector3f.ZERO, 140, 1f, 140);
// floor.scaleTextureCoordinates(new Vector2f(112.0f, 112.0f));
// Geometry floorGeom = new Geometry("Floor", floor);
// floorGeom.setShadowMode(ShadowMode.Receive);
// floorGeom.setMaterial(mat);
//
// PhysicsNode tb = new PhysicsNode(floorGeom, new MeshCollisionShape(floorGeom.getMesh()), 0);
// tb.setLocalTranslation(new Vector3f(0f, -6, 0f));
//// tb.attachDebugShape(assetManager);
// rootNode.attachChild(tb);
// getPhysicsSpace().add(tb);
// }
private Geometry findGeom(Spatial spatial, String name) {
if (spatial instanceof Node) {
Node node = (Node) spatial;
for (int i = 0; i < node.getQuantity(); i++) {
Spatial child = node.getChild(i);
Geometry result = findGeom(child, name);
if (result != null) {
return result;
}
}
} else if (spatial instanceof Geometry) {
if (spatial.getName().startsWith(name)) {
return (Geometry) spatial;
}
}
return null;
}
use of com.jme3.scene.Node 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.scene.Node in project jmonkeyengine by jMonkeyEngine.
the class PhysicsTestHelper method createPhysicsTestWorldSoccer.
public static void createPhysicsTestWorldSoccer(Node rootNode, AssetManager assetManager, PhysicsSpace space) {
AmbientLight light = new AmbientLight();
light.setColor(ColorRGBA.LightGray);
rootNode.addLight(light);
Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
material.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
Box floorBox = new Box(20, 0.25f, 20);
Geometry floorGeometry = new Geometry("Floor", floorBox);
floorGeometry.setMaterial(material);
floorGeometry.setLocalTranslation(0, -0.25f, 0);
// Plane plane = new Plane();
// plane.setOriginNormal(new Vector3f(0, 0.25f, 0), Vector3f.UNIT_Y);
// floorGeometry.addControl(new RigidBodyControl(new PlaneCollisionShape(plane), 0));
floorGeometry.addControl(new RigidBodyControl(0));
rootNode.attachChild(floorGeometry);
space.add(floorGeometry);
//movable spheres
for (int i = 0; i < 5; i++) {
Sphere sphere = new Sphere(16, 16, .5f);
Geometry ballGeometry = new Geometry("Soccer ball", sphere);
ballGeometry.setMaterial(material);
ballGeometry.setLocalTranslation(i, 2, -3);
//RigidBodyControl automatically uses Sphere collision shapes when attached to single geometry with sphere mesh
ballGeometry.addControl(new RigidBodyControl(.001f));
ballGeometry.getControl(RigidBodyControl.class).setRestitution(1);
rootNode.attachChild(ballGeometry);
space.add(ballGeometry);
}
{
//immovable Box with mesh collision shape
Box box = new Box(1, 1, 1);
Geometry boxGeometry = new Geometry("Box", box);
boxGeometry.setMaterial(material);
boxGeometry.setLocalTranslation(4, 1, 2);
boxGeometry.addControl(new RigidBodyControl(new MeshCollisionShape(box), 0));
rootNode.attachChild(boxGeometry);
space.add(boxGeometry);
}
{
//immovable Box with mesh collision shape
Box box = new Box(1, 1, 1);
Geometry boxGeometry = new Geometry("Box", box);
boxGeometry.setMaterial(material);
boxGeometry.setLocalTranslation(4, 3, 4);
boxGeometry.addControl(new RigidBodyControl(new MeshCollisionShape(box), 0));
rootNode.attachChild(boxGeometry);
space.add(boxGeometry);
}
}
Aggregations