Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.strijar.vs;
- import com.jme3.bullet.control.RigidBodyControl;
- import com.jme3.bullet.control.SoftBodyControl;
- import com.jme3.bullet.joints.SixDofJoint;
- import com.jme3.bullet.objects.PhysicsSoftBody;
- import com.jme3.material.Material;
- import com.jme3.math.Vector3f;
- import com.jme3.scene.Node;
- import com.jme3.scene.Spatial;
- public class Fender {
- private final Spatial spatial;
- private RigidBodyControl rigidControl;
- public Fender(BoatApplication app) {
- spatial = app.getAssetManager().loadModel("Models/fender.j3o");
- Material mat = app.getAssetManager().loadMaterial("Materials/plastic.j3m");
- spatial.setMaterial(mat);
- }
- private void addSoft(BoatApplication app) {
- SoftBodyControl softControl;
- softControl = new SoftBodyControl(false);
- spatial.addControl(softControl);
- softControl.generateClusters(8);
- softControl.config().setDynamicFrictionCoef(0.5f);
- softControl.config().setPoseMatchingCoef(0.2f);
- softControl.config().setPositionIterations(2);
- /*
- softControl.config().setClusterSoftHardness(1);
- softControl.config().setClusterSoftImpulseSplitCoef(0);
- softControl.config().setClusterKineticHardness(0.1f);
- softControl.config().setClusterKineticImpulseSplitCoef(1);
- */
- softControl.config().setCollisionsFlags(PhysicsSoftBody.Config.CL_SS + PhysicsSoftBody.Config.CL_RS);
- softControl.setPose(false, true);
- softControl.setTotalMass(5, true);
- softControl.randomizeConstraints();
- softControl.setPhysicsLocation(new Vector3f(1.8f, 3f, 0));
- app.getBulletState().getPhysicsSoftSpace().add(softControl);
- }
- public void attach(BoatApplication app, RigidBodyControl rigid) {
- // addSoft(app);
- rigidControl = new RigidBodyControl(5f);
- Node node = new Node("FenderNode");
- app.getRootNode().attachChild(node);
- node.attachChild(spatial);
- rigidControl = new RigidBodyControl(5f);
- node.addControl(rigidControl);
- rigidControl.setPhysicsLocation(new Vector3f(1.8f, 3f, 0f));
- SixDofJoint joint = new SixDofJoint(
- rigidControl, rigid,
- new Vector3f(0, -1.5f, 0),
- new Vector3f(1.8f, 3, 0f),
- true
- );
- rigidControl.setDamping(0.1f, 0.2f);
- joint.setCollisionBetweenLinkedBodys(true);
- app.getBulletState().getPhysicsSpace().add(rigidControl);
- app.getBulletState().getPhysicsSpace().add(joint);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment