Strijar

Untitled

Jan 6th, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.66 KB | None | 0 0
  1. package ru.strijar.vs;
  2.  
  3. import com.jme3.bullet.control.RigidBodyControl;
  4. import com.jme3.bullet.control.SoftBodyControl;
  5. import com.jme3.bullet.joints.SixDofJoint;
  6. import com.jme3.bullet.objects.PhysicsSoftBody;
  7. import com.jme3.material.Material;
  8. import com.jme3.math.Vector3f;
  9. import com.jme3.scene.Node;
  10. import com.jme3.scene.Spatial;
  11.  
  12. public class Fender {
  13.     private final Spatial           spatial;
  14.     private RigidBodyControl        rigidControl;
  15.    
  16.     public Fender(BoatApplication app) {
  17.         spatial = app.getAssetManager().loadModel("Models/fender.j3o");
  18.        
  19.         Material mat = app.getAssetManager().loadMaterial("Materials/plastic.j3m");
  20.         spatial.setMaterial(mat);
  21.     }
  22.    
  23.     private void addSoft(BoatApplication app) {
  24.         SoftBodyControl   softControl;
  25.  
  26.         softControl = new SoftBodyControl(false);
  27.  
  28.         spatial.addControl(softControl);
  29.  
  30.         softControl.generateClusters(8);
  31.         softControl.config().setDynamicFrictionCoef(0.5f);
  32.         softControl.config().setPoseMatchingCoef(0.2f);
  33.         softControl.config().setPositionIterations(2);    
  34.  
  35.         /*
  36.         softControl.config().setClusterSoftHardness(1);
  37.         softControl.config().setClusterSoftImpulseSplitCoef(0);
  38.         softControl.config().setClusterKineticHardness(0.1f);
  39.         softControl.config().setClusterKineticImpulseSplitCoef(1);
  40.         */
  41.  
  42.         softControl.config().setCollisionsFlags(PhysicsSoftBody.Config.CL_SS + PhysicsSoftBody.Config.CL_RS);
  43.  
  44.         softControl.setPose(false, true);
  45.         softControl.setTotalMass(5, true);
  46.         softControl.randomizeConstraints();
  47.         softControl.setPhysicsLocation(new Vector3f(1.8f, 3f, 0));
  48.  
  49.         app.getBulletState().getPhysicsSoftSpace().add(softControl);
  50.     }
  51.    
  52.     public void attach(BoatApplication app, RigidBodyControl rigid) {
  53.         // addSoft(app);
  54.  
  55.         rigidControl = new RigidBodyControl(5f);
  56.         Node node = new Node("FenderNode");
  57.        
  58.         app.getRootNode().attachChild(node);
  59.         node.attachChild(spatial);
  60.  
  61.         rigidControl = new RigidBodyControl(5f);
  62.         node.addControl(rigidControl);
  63.        
  64.         rigidControl.setPhysicsLocation(new Vector3f(1.8f, 3f, 0f));
  65.        
  66.         SixDofJoint joint = new SixDofJoint(
  67.             rigidControl, rigid,
  68.             new Vector3f(0, -1.5f, 0),
  69.             new Vector3f(1.8f, 3, 0f),
  70.             true
  71.         );
  72.        
  73.         rigidControl.setDamping(0.1f, 0.2f);
  74.         joint.setCollisionBetweenLinkedBodys(true);
  75.  
  76.         app.getBulletState().getPhysicsSpace().add(rigidControl);
  77.         app.getBulletState().getPhysicsSpace().add(joint);
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment