com.jme3.bullet.control.RigidBodyControl Java Examples
The following examples show how to use
com.jme3.bullet.control.RigidBodyControl.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestAttachGhostObject.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
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); }
Example #2
Source File: WorldOfInception.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
private Geometry getRandomBall(Vector3f location) { Vector3f localLocation = new Vector3f(); localLocation.set(location); localLocation.addLocal(new Vector3f(random.nextFloat() - 0.5f, random.nextFloat() - 0.5f, random.nextFloat() - 0.5f).normalize().mult(3)); Geometry poiGeom = new Geometry("ball", ballMesh); poiGeom.setLocalTranslation(localLocation); poiGeom.setMaterial(ballMaterial); RigidBodyControl control = new RigidBodyControl(ballCollisionShape, 1); //!!! Important control.setApplyPhysicsLocal(true); poiGeom.addControl(control); float x = (random.nextFloat() - 0.5f) * 100; float y = (random.nextFloat() - 0.5f) * 100; float z = (random.nextFloat() - 0.5f) * 100; control.setLinearVelocity(new Vector3f(x, y, z)); return poiGeom; }
Example #3
Source File: PhysicsSpace.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Add all collision objects and joints in the specified subtree of the * scene graph to this space (e.g. after loading from disk). Note: * recursive! * * @param spatial the root of the subtree (not null) */ public void addAll(Spatial spatial) { add(spatial); if (spatial.getControl(RigidBodyControl.class) != null) { RigidBodyControl physicsNode = spatial.getControl(RigidBodyControl.class); //add joints with physicsNode as BodyA List<PhysicsJoint> joints = physicsNode.getJoints(); for (Iterator<PhysicsJoint> it1 = joints.iterator(); it1.hasNext();) { PhysicsJoint physicsJoint = it1.next(); if (physicsNode.equals(physicsJoint.getBodyA())) { //add(physicsJoint.getBodyB()); add(physicsJoint); } } } //recursion if (spatial instanceof Node) { List<Spatial> children = ((Node) spatial).getChildren(); for (Iterator<Spatial> it = children.iterator(); it.hasNext();) { Spatial spat = it.next(); addAll(spat); } } }
Example #4
Source File: PhysicsSpace.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Removes all physics controls and joints in the given spatial from the physics space * (e.g. before saving to disk) - recursive if node * @param spatial the rootnode containing the physics objects */ public void removeAll(Spatial spatial) { if (spatial.getControl(RigidBodyControl.class) != null) { RigidBodyControl physicsNode = spatial.getControl(RigidBodyControl.class); //remove joints with physicsNode as BodyA List<PhysicsJoint> joints = physicsNode.getJoints(); for (Iterator<PhysicsJoint> it1 = joints.iterator(); it1.hasNext();) { PhysicsJoint physicsJoint = it1.next(); if (physicsNode.equals(physicsJoint.getBodyA())) { removeJoint(physicsJoint); //remove(physicsJoint.getBodyB()); } } } remove(spatial); //recursion if (spatial instanceof Node) { List<Spatial> children = ((Node) spatial).getChildren(); for (Iterator<Spatial> it = children.iterator(); it.hasNext();) { Spatial spat = it.next(); removeAll(spat); } } }
Example #5
Source File: HelloPhysics.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** This method creates one individual physical cannon ball. * By defaul, the ball is accelerated and flies * from the camera position in the camera direction.*/ public void makeCannonBall() { /** Create a cannon ball geometry and attach to scene graph. */ Geometry ball_geo = new Geometry("cannon ball", sphere); ball_geo.setMaterial(stone_mat); rootNode.attachChild(ball_geo); /** Position the cannon ball */ ball_geo.setLocalTranslation(cam.getLocation()); /** Make the ball physical with a mass > 0.0f */ ball_phy = new RigidBodyControl(1f); /** Add physical ball to physics space. */ ball_geo.addControl(ball_phy); bulletAppState.getPhysicsSpace().add(ball_phy); /** Accelerate the physical ball to shoot it. */ ball_phy.setLinearVelocity(cam.getDirection().mult(25)); }
Example #6
Source File: PhysicsSpace.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Remove all physics controls and joints in the specified subtree of the * scene graph from the physics space (e.g. before saving to disk) Note: * recursive! * * @param spatial the root of the subtree (not null) */ public void removeAll(Spatial spatial) { if (spatial.getControl(RigidBodyControl.class) != null) { RigidBodyControl physicsNode = spatial.getControl(RigidBodyControl.class); //remove joints with physicsNode as BodyA List<PhysicsJoint> joints = physicsNode.getJoints(); for (Iterator<PhysicsJoint> it1 = joints.iterator(); it1.hasNext();) { PhysicsJoint physicsJoint = it1.next(); if (physicsNode.equals(physicsJoint.getBodyA())) { removeJoint(physicsJoint); //remove(physicsJoint.getBodyB()); } } } remove(spatial); //recursion if (spatial instanceof Node) { List<Spatial> children = ((Node) spatial).getChildren(); for (Iterator<Spatial> it = children.iterator(); it.hasNext();) { Spatial spat = it.next(); removeAll(spat); } } }
Example #7
Source File: TestIssue1120.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void initializeNewTest() { bulletAppState = new BulletAppState(); bulletAppState.setDebugEnabled(physicsDebug); stateManager.attach(bulletAppState); bulletAppState.setSpeed(bulletSpeed); dropTest(); Geometry leftFloor = PhysicsTestHelper.createMeshTestFloor(assetManager, 20, new Vector3f(-11, -5, -10)); addObject(leftFloor); //Hide physics debug visualization for floors if (physicsDebug) { BulletDebugAppState bulletDebugAppState = stateManager.getState(BulletDebugAppState.class); bulletDebugAppState.setFilter((Object obj) -> { return !(obj.equals(leftFloor.getControl(RigidBodyControl.class))); }); } }
Example #8
Source File: TestGimpactShape.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
private RigidBodyControl drop(Vector3f offset, String model, float scale, float mass) { scale *= scaleMod; Node n = (Node) assetManager.loadModel(model); n.setLocalTranslation(offset); n.rotate(0, 0, -FastMath.HALF_PI); Geometry tp = ((Geometry) n.getChild(0)); tp.scale(scale); Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); tp.setMaterial(mat); Mesh mesh = tp.getMesh(); GImpactCollisionShape shape = new GImpactCollisionShape(mesh); shape.setScale(new Vector3f(scale, scale, scale)); RigidBodyControl control = new RigidBodyControl(shape, mass); n.addControl(control); addObject(n); return control; }
Example #9
Source File: TestPhysicsRayCast.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void simpleInitApp() { stateManager.attach(bulletAppState); initCrossHair(); Spatial s = assetManager.loadModel("Models/Elephant/Elephant.mesh.xml"); s.setLocalScale(0.1f); CollisionShape collisionShape = CollisionShapeFactory.createMeshShape(s); Node n = new Node("elephant"); n.addControl(new RigidBodyControl(collisionShape, 1)); n.getControl(RigidBodyControl.class).setKinematic(true); bulletAppState.getPhysicsSpace().add(n); rootNode.attachChild(n); bulletAppState.setDebugEnabled(true); }
Example #10
Source File: TestAttachDriver.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void setupFloor() { Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); TextureKey key = new TextureKey("Interface/Logo/Monkey.jpg", true); key.setGenerateMips(true); Texture tex = assetManager.loadTexture(key); tex.setMinFilter(Texture.MinFilter.Trilinear); mat.setTexture("ColorMap", tex); Box floor = new Box(100, 1f, 100); Geometry floorGeom = new Geometry("Floor", floor); floorGeom.setMaterial(mat); floorGeom.setLocalTranslation(new Vector3f(0f, -3, 0f)); floorGeom.addControl(new RigidBodyControl(new MeshCollisionShape(floorGeom.getMesh()), 0)); rootNode.attachChild(floorGeom); getPhysicsSpace().add(floorGeom); }
Example #11
Source File: TestBrickWall.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void onAction(String name, boolean keyPressed, float tpf) { if (name.equals("shoot") && !keyPressed) { Geometry bulletg = new Geometry("bullet", bullet); bulletg.setMaterial(mat2); bulletg.setShadowMode(ShadowMode.CastAndReceive); bulletg.setLocalTranslation(cam.getLocation()); SphereCollisionShape bulletCollisionShape = new SphereCollisionShape(0.4f); RigidBodyControl bulletNode = new BombControl(assetManager, bulletCollisionShape, 1); // RigidBodyControl bulletNode = new RigidBodyControl(bulletCollisionShape, 1); bulletNode.setLinearVelocity(cam.getDirection().mult(25)); bulletg.addControl(bulletNode); rootNode.attachChild(bulletg); getPhysicsSpace().add(bulletNode); } if (name.equals("gc") && !keyPressed) { System.gc(); } }
Example #12
Source File: HelloPhysics.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** This method creates one individual physical cannon ball. * By defaul, the ball is accelerated and flies * from the camera position in the camera direction.*/ public void makeCannonBall() { /** Create a cannon ball geometry and attach to scene graph. */ Geometry ball_geo = new Geometry("cannon ball", sphere); ball_geo.setMaterial(stone_mat); rootNode.attachChild(ball_geo); /** Position the cannon ball */ ball_geo.setLocalTranslation(cam.getLocation()); /** Make the ball physcial with a mass > 0.0f */ ball_phy = new RigidBodyControl(1f); /** Add physical ball to physics space. */ ball_geo.addControl(ball_phy); bulletAppState.getPhysicsSpace().add(ball_phy); /** Accelerate the physcial ball to shoot it. */ ball_phy.setLinearVelocity(cam.getDirection().mult(25)); }
Example #13
Source File: TestAttachGhostObject.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
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); }
Example #14
Source File: TestBrickWall.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public void onAction(String name, boolean keyPressed, float tpf) { if (name.equals("shoot") && !keyPressed) { Geometry bulletg = new Geometry("bullet", bullet); bulletg.setMaterial(mat2); bulletg.setShadowMode(ShadowMode.CastAndReceive); bulletg.setLocalTranslation(cam.getLocation()); SphereCollisionShape bulletCollisionShape = new SphereCollisionShape(0.4f); RigidBodyControl bulletNode = new BombControl(assetManager, bulletCollisionShape, 1); // RigidBodyControl bulletNode = new RigidBodyControl(bulletCollisionShape, 1); bulletNode.setLinearVelocity(cam.getDirection().mult(25)); bulletg.addControl(bulletNode); rootNode.attachChild(bulletg); getPhysicsSpace().add(bulletNode); } if (name.equals("gc") && !keyPressed) { System.gc(); } }
Example #15
Source File: SceneToolController.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
protected void attachPhysicsSelection(Spatial geom) { PhysicsCollisionObject control = geom.getControl(RigidBodyControl.class); if (control == null) { control = geom.getControl(VehicleControl.class); } if (control == null) { control = geom.getControl(GhostControl.class); } if (control == null) { control = geom.getControl(CharacterControl.class); } if (control == null) { return; } Spatial selectionGeometry = DebugShapeFactory.getDebugShape(control.getCollisionShape()); if (selectionGeometry != null) { selectionGeometry.setMaterial(blueMat); selectionGeometry.setLocalTransform(geom.getWorldTransform()); toolsNode.attachChild(selectionGeometry); selectionShape = selectionGeometry; } }
Example #16
Source File: TestBrickTower.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void addBrick(Vector3f ori) { Geometry reBoxg = new Geometry("brick", brick); reBoxg.setMaterial(mat); reBoxg.setLocalTranslation(ori); reBoxg.rotate(0f, (float)Math.toRadians(angle) , 0f ); reBoxg.addControl(new RigidBodyControl(1.5f)); reBoxg.setShadowMode(ShadowMode.CastAndReceive); reBoxg.getControl(RigidBodyControl.class).setFriction(1.6f); this.rootNode.attachChild(reBoxg); this.getPhysicsSpace().add(reBoxg); }
Example #17
Source File: TestBrickTower.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void initFloor() { Box floorBox = new Box(10f, 0.1f, 5f); floorBox.scaleTextureCoordinates(new Vector2f(3, 6)); Geometry floor = new Geometry("floor", floorBox); floor.setMaterial(mat3); floor.setShadowMode(ShadowMode.Receive); floor.setLocalTranslation(0, 0, 0); floor.addControl(new RigidBodyControl(0)); this.rootNode.attachChild(floor); this.getPhysicsSpace().add(floor); }
Example #18
Source File: TestRagDoll.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
private Node createLimb(float width, float height, Vector3f location, boolean rotate) { int axis = rotate ? PhysicsSpace.AXIS_X : PhysicsSpace.AXIS_Y; CapsuleCollisionShape shape = new CapsuleCollisionShape(width, height, axis); Node node = new Node("Limb"); RigidBodyControl rigidBodyControl = new RigidBodyControl(shape, 1); node.setLocalTranslation(location); node.addControl(rigidBodyControl); return node; }
Example #19
Source File: PhysicsTestHelper.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * creates a sphere geometry with a RigidBodyControl * @param assetManager * @return */ public static Geometry createPhysicsTestSphere(AssetManager assetManager) { Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); material.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg")); Sphere sphere = new Sphere(8, 8, 0.25f); Geometry boxGeometry = new Geometry("Sphere", sphere); boxGeometry.setMaterial(material); //RigidBodyControl automatically uses sphere collision shapes when attached to single geometry with sphere mesh boxGeometry.addControl(new RigidBodyControl(2)); return boxGeometry; }
Example #20
Source File: TestBatchNodeTower.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public void addBrick(Vector3f ori) { Geometry reBoxg = new Geometry("brick", brick); reBoxg.setMaterial(mat); reBoxg.setLocalTranslation(ori); reBoxg.rotate(0f, (float)Math.toRadians(angle) , 0f ); reBoxg.addControl(new RigidBodyControl(1.5f)); reBoxg.setShadowMode(ShadowMode.CastAndReceive); reBoxg.getControl(RigidBodyControl.class).setFriction(1.6f); this.batchNode.attachChild(reBoxg); this.getPhysicsSpace().add(reBoxg); nbBrick++; }
Example #21
Source File: TestBrickWall.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void addBrick(Vector3f ori) { Geometry reBoxg = new Geometry("brick", brick); reBoxg.setMaterial(mat); reBoxg.setLocalTranslation(ori); //for geometry with sphere mesh the physics system automatically uses a sphere collision shape reBoxg.addControl(new RigidBodyControl(1.5f)); reBoxg.setShadowMode(ShadowMode.CastAndReceive); reBoxg.getControl(RigidBodyControl.class).setFriction(0.6f); this.rootNode.attachChild(reBoxg); this.getPhysicsSpace().add(reBoxg); }
Example #22
Source File: TestBatchNodeTower.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void initFloor() { Box floorBox = new Box(10f, 0.1f, 5f); floorBox.scaleTextureCoordinates(new Vector2f(3, 6)); Geometry floor = new Geometry("floor", floorBox); floor.setMaterial(mat3); floor.setShadowMode(ShadowMode.Receive); floor.setLocalTranslation(0, 0, 0); floor.addControl(new RigidBodyControl(0)); this.rootNode.attachChild(floor); this.getPhysicsSpace().add(floor); }
Example #23
Source File: PhysicsTestHelper.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * creates a box geometry with a RigidBodyControl * * @param assetManager for loading assets * @return a new Geometry */ public static Geometry createPhysicsTestBox(AssetManager assetManager) { Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); material.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg")); Box box = new Box(0.25f, 0.25f, 0.25f); Geometry boxGeometry = new Geometry("Box", box); boxGeometry.setMaterial(material); //RigidBodyControl automatically uses box collision shapes when attached to single geometry with box mesh boxGeometry.addControl(new RigidBodyControl(2)); return boxGeometry; }
Example #24
Source File: JmeRigidBodyControl.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
@Override protected Sheet createSheet() { Sheet sheet = super.createSheet(); Sheet.Set set = Sheet.createPropertiesSet(); set.setDisplayName("RigidBodyControl"); set.setName(RigidBodyControl.class.getName()); RigidBodyControl obj = geom;//getLookup().lookup(Spatial.class); if (obj == null) { return sheet; } set.put(makeProperty(obj, Vector3f.class, "getPhysicsLocation", "setPhysicsLocation", "Physics Location")); set.put(makeProperty(obj, Quaternion.class, "getPhysicsRotation", "setPhysicsRotation", "Physics Rotation")); set.put(makeProperty(obj, CollisionShape.class, "getCollisionShape", "setCollisionShape", "Collision Shape")); set.put(makeProperty(obj, int.class, "getCollisionGroup", "setCollisionGroup", "Collision Group")); set.put(makeProperty(obj, int.class, "getCollideWithGroups", "setCollideWithGroups", "Collide With Groups")); set.put(makeProperty(obj, float.class, "getFriction", "setFriction", "Friction")); set.put(makeProperty(obj, float.class, "getMass", "setMass", "Mass")); set.put(makeProperty(obj, boolean.class, "isKinematic", "setKinematic", "Kinematic")); set.put(makeProperty(obj, Vector3f.class, "getGravity", "setGravity", "Gravity")); set.put(makeProperty(obj, float.class, "getLinearDamping", "setLinearDamping", "Linear Damping")); set.put(makeProperty(obj, float.class, "getAngularDamping", "setAngularDamping", "Angular Damping")); set.put(makeProperty(obj, float.class, "getRestitution", "setRestitution", "Restitution")); set.put(makeProperty(obj, float.class, "getLinearSleepingThreshold", "setLinearSleepingThreshold", "Linear Sleeping Threshold")); set.put(makeProperty(obj, float.class, "getAngularSleepingThreshold", "setAngularSleepingThreshold", "Angular Sleeping Threshold")); sheet.put(set); return sheet; }
Example #25
Source File: TestBatchNodeTower.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void addBrick(Vector3f ori) { Geometry reBoxg = new Geometry("brick", brick); reBoxg.setMaterial(mat); reBoxg.setLocalTranslation(ori); reBoxg.rotate(0f, (float)Math.toRadians(angle) , 0f ); reBoxg.addControl(new RigidBodyControl(1.5f)); reBoxg.setShadowMode(ShadowMode.CastAndReceive); reBoxg.getControl(RigidBodyControl.class).setFriction(1.6f); this.batchNode.attachChild(reBoxg); this.getPhysicsSpace().add(reBoxg); nbBrick++; }
Example #26
Source File: TestIssue1125.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Add 3x3 terrain to the scene and the PhysicsSpace. */ private void addTerrain() { int patchSize = 3; int mapSize = 3; TerrainQuad quad = new TerrainQuad("terrain", patchSize, mapSize, nineHeights); rootNode.attachChild(quad); quad.setMaterial(quadMaterial); CollisionShape shape = CollisionShapeFactory.createMeshShape(quad); float massForStatic = 0f; RigidBodyControl rbc = new RigidBodyControl(shape, massForStatic); rbc.setPhysicsSpace(physicsSpace); quad.addControl(rbc); }
Example #27
Source File: TestIssue877.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
Node createTestNode(float mass, Vector3f location) { float size = 0.1f; Vector3f halfExtents = new Vector3f(size, size, size); CollisionShape shape = new BoxCollisionShape(halfExtents); RigidBodyControl control = new RigidBodyControl(shape, mass); Node node = new Node(); node.addControl(control); rootNode.attachChild(node); bulletAppState.getPhysicsSpace().add(node); control.setPhysicsLocation(location); return node; }
Example #28
Source File: TestRagDoll.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void onAction(String string, boolean bln, float tpf) { if ("Pull ragdoll up".equals(string)) { if (bln) { shoulders.getControl(RigidBodyControl.class).activate(); applyForce = true; } else { applyForce = false; } } }
Example #29
Source File: TestGimpactShape.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void attachTestObject(Mesh mesh, Vector3f position, float mass) { Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); material.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg")); Geometry g = new Geometry("mesh", mesh); g.scale(scaleMod); g.setLocalTranslation(position); g.setMaterial(material); GImpactCollisionShape shape = new GImpactCollisionShape(mesh); shape.setScale(new Vector3f(scaleMod, scaleMod, scaleMod)); RigidBodyControl control = new RigidBodyControl(shape, mass); g.addControl(control); addObject(g); }
Example #30
Source File: TestRagdollCharacter.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public void initWall(float bLength, float bWidth, float bHeight) { Box brick = new Box(Vector3f.ZERO, bLength, bHeight, bWidth); brick.scaleTextureCoordinates(new Vector2f(1f, .5f)); Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); TextureKey key = new TextureKey("Textures/Terrain/BrickWall/BrickWall.jpg"); key.setGenerateMips(true); Texture tex = assetManager.loadTexture(key); mat2.setTexture("ColorMap", tex); float startpt = bLength / 4; float height = -5; for (int j = 0; j < 15; j++) { for (int i = 0; i < 4; i++) { Vector3f ori = new Vector3f(i * bLength * 2 + startpt, bHeight + height, -10); Geometry reBoxg = new Geometry("brick", brick); reBoxg.setMaterial(mat2); reBoxg.setLocalTranslation(ori); //for geometry with sphere mesh the physics system automatically uses a sphere collision shape reBoxg.addControl(new RigidBodyControl(1.5f)); reBoxg.setShadowMode(ShadowMode.CastAndReceive); reBoxg.getControl(RigidBodyControl.class).setFriction(0.6f); this.rootNode.attachChild(reBoxg); this.getPhysicsSpace().add(reBoxg); } startpt = -startpt; height += 2 * bHeight; } }