Advertisement
Corosus

Untitled

Jan 12th, 2014
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.22 KB | None | 0 0
  1. @Override
  2.     public void populateStructureData() {
  3.         super.populateStructureData();
  4.        
  5.         //you're using box collision on legs, fix
  6.         //also, keep carefull watch on leg orientation to jbullet orientation, relative grid factoring etc
  7.        
  8.         int pieceIndex = 0;
  9.         StructurePiece mainBody = new StructurePiece(pieceIndex++, (IStructureUser)job, 0, 0, 0);
  10.         body = mainBody;
  11.        
  12.         //radius, 1 + this
  13.         int radX = 3;
  14.         int radY = 0;
  15.         int radZ = 2;
  16.        
  17.         int sizeX = radX*2;
  18.         int sizeY = radY*2;
  19.         int sizeZ = radZ*2;
  20.        
  21.         int radius = Math.max(1, Math.max(sizeX, sizeZ));
  22.        
  23.         //we cant generate the predicted capsule radius area here, because adding to the grid will extend that height we predicted, changing it
  24.        
  25.         //body
  26.         for (int x = -sizeX/2; x <= sizeX/2; x++) {
  27.             for (int z = -sizeZ/2; z <= sizeZ/2; z++) {
  28.                 for (int y = -sizeY/2; y <= sizeY/2; y++) {            
  29.                     mainBody.nodes.add(new StructureNode(mainBody, x, y, z));
  30.                     if (x == -sizeX/2 || x == sizeX/2 || z == -sizeZ/2 || z == sizeZ/2) {
  31.                         mainBody.nodes.add(new StructureNode(mainBody, x, y+1, z));
  32.                     }
  33.                 }
  34.             }
  35.         }
  36.        
  37.         float dampLinear = 0.2F;
  38.         float dampAngular = 0.2F;
  39.        
  40.         mainBody.calculateCenter();
  41.         //RigidBody rb = mainBody.initPhysicsObject(new CapsuleShape(mainBody.axisYRadius, mainBody.sizeHalf.y*2), new Vector3f((float)job.ent.posX, (float)job.ent.posY, (float)job.ent.posZ), 5F);
  42.         RigidBody rb = mainBody.initPhysicsObject(new BoxShape(new Vector3f(sizeX, sizeY, sizeZ)), new Vector3f((float)job.ent.posX, (float)job.ent.posY+10, (float)job.ent.posZ), 1F);
  43.         rb.setDamping(0, 0);
  44.        
  45.         //if (true) return;
  46.        
  47.         int armLength = 3;
  48.         int armLengthLower = 9;
  49.         int spaceBetweenArms = 2;
  50.        
  51.         int limbOffsetX = 2;//(sizeX/2)+1;
  52.         int limbOffsetZ = (sizeZ/2);
  53.        
  54.         //legA upper
  55.         StructurePiece limb1 = new StructurePiece(pieceIndex++, mainBody, limbOffsetX, 0, -limbOffsetZ);
  56.         for (int length = 0; length < armLength; length++) {
  57.             limb1.nodes.add(new StructureNode(limb1, 0, -length, 0));
  58.         }
  59.         mainBody.addChildPiece(limb1);
  60.         rb = limb1.initPhysicsObject(1F);
  61.         rb.setDamping(dampLinear, dampAngular);
  62.        
  63.         //legA lower
  64.         StructurePiece limb11 = new StructurePiece(pieceIndex++, limb1, 0, -armLength-spaceBetweenArms, 0);
  65.         for (int length = 0; length < armLengthLower; length++) {
  66.             limb11.nodes.add(new StructureNode(limb11, 0, -length, 0));
  67.         }
  68.         limb1.addChildPiece(limb11);
  69.         rb = limb11.initPhysicsObject(1F);
  70.         rb.setDamping(dampLinear, dampAngular);
  71.        
  72.         //legB upper
  73.         StructurePiece limb2 = new StructurePiece(pieceIndex++, mainBody, 0, 0, -limbOffsetZ);
  74.         for (int length = 0; length < armLength; length++) {
  75.             limb2.nodes.add(new StructureNode(limb2, 0, -length, 0));
  76.         }
  77.         mainBody.addChildPiece(limb2);
  78.         rb = limb2.initPhysicsObject(1F);
  79.         rb.setDamping(dampLinear, dampAngular);
  80.        
  81.         //legB lower
  82.         StructurePiece limb22 = new StructurePiece(pieceIndex++, limb2, 0, -armLength-spaceBetweenArms, 0);
  83.         for (int length = 0; length < armLengthLower; length++) {
  84.             limb22.nodes.add(new StructureNode(limb22, 0, -length, 0));
  85.         }
  86.         limb2.addChildPiece(limb22);
  87.         rb = limb22.initPhysicsObject(1F);
  88.         rb.setDamping(dampLinear, dampAngular);
  89.        
  90.         //legC upper
  91.         StructurePiece limb3 = new StructurePiece(pieceIndex++, mainBody, -limbOffsetX, 0, -limbOffsetZ);
  92.         for (int length = 0; length < armLength; length++) {
  93.             limb3.nodes.add(new StructureNode(limb3, 0, -length, 0));
  94.         }
  95.         mainBody.addChildPiece(limb3);
  96.         rb = limb3.initPhysicsObject(1F);
  97.         rb.setDamping(dampLinear, dampAngular);
  98.        
  99.         //legC lower
  100.         StructurePiece limb33 = new StructurePiece(pieceIndex++, limb3, 0, -armLength-spaceBetweenArms, 0);
  101.         for (int length = 0; length < armLengthLower; length++) {
  102.             limb33.nodes.add(new StructureNode(limb33, 0, -length, 0));
  103.         }
  104.         limb3.addChildPiece(limb33);
  105.         rb = limb33.initPhysicsObject(1F);
  106.         rb.setDamping(dampLinear, dampAngular);
  107.        
  108.         //legD upper
  109.         StructurePiece limb4 = new StructurePiece(pieceIndex++, mainBody, limbOffsetX, 0, limbOffsetZ);
  110.         for (int length = 0; length < armLength; length++) {
  111.             limb4.nodes.add(new StructureNode(limb4, 0, -length, 0));
  112.         }
  113.         mainBody.addChildPiece(limb4);
  114.         rb = limb4.initPhysicsObject(1F);
  115.         rb.setDamping(dampLinear, dampAngular);
  116.        
  117.         //legD lower
  118.         StructurePiece limb44 = new StructurePiece(pieceIndex++, limb4, 0, -armLength-spaceBetweenArms, 0);
  119.         for (int length = 0; length < armLengthLower; length++) {
  120.             limb44.nodes.add(new StructureNode(limb44, 0, -length, 0));
  121.         }
  122.         limb4.addChildPiece(limb44);
  123.         rb = limb44.initPhysicsObject(1F);
  124.         rb.setDamping(dampLinear, dampAngular);
  125.  
  126.         //legE upper
  127.         StructurePiece limb5 = new StructurePiece(pieceIndex++, mainBody, 0, 0, limbOffsetZ);
  128.         for (int length = 0; length < armLength; length++) {
  129.             limb5.nodes.add(new StructureNode(limb5, 0, -length, 0));
  130.         }
  131.         mainBody.addChildPiece(limb5);
  132.         rb = limb5.initPhysicsObject(1F);
  133.         rb.setDamping(dampLinear, dampAngular);
  134.        
  135.         //legE lower
  136.         StructurePiece limb55 = new StructurePiece(pieceIndex++, limb5, 0, -armLength-spaceBetweenArms, 0);
  137.         for (int length = 0; length < armLengthLower; length++) {
  138.             limb55.nodes.add(new StructureNode(limb55, 0, -length, 0));
  139.         }
  140.         limb5.addChildPiece(limb55);
  141.         rb = limb55.initPhysicsObject(1F);
  142.         rb.setDamping(dampLinear, dampAngular);
  143.        
  144.         //legF upper
  145.         StructurePiece limb6 = new StructurePiece(pieceIndex++, mainBody, -limbOffsetX, 0, limbOffsetZ);
  146.         for (int length = 0; length < armLength; length++) {
  147.             limb6.nodes.add(new StructureNode(limb6, 0, -length, 0));
  148.         }
  149.         mainBody.addChildPiece(limb6);
  150.         rb = limb6.initPhysicsObject(1F);
  151.         rb.setDamping(dampLinear, dampAngular);
  152.        
  153.         //legF lower
  154.         StructurePiece limb66 = new StructurePiece(pieceIndex++, limb6, 0, -armLength-spaceBetweenArms, 0);
  155.         for (int length = 0; length < armLengthLower; length++) {
  156.             limb66.nodes.add(new StructureNode(limb66, 0, -length, 0));
  157.         }
  158.         limb6.addChildPiece(limb66);
  159.         rb = limb66.initPhysicsObject(1F);
  160.         rb.setDamping(dampLinear, dampAngular);
  161.        
  162.         //everything needed for constraint setup:
  163.         //- bodyA
  164.         //- bodyB
  165.         //- local connection point for piece A
  166.         //- local connection point for piece B
  167.         //- might not need upper and lower angular limits, currently set to 0,0,0 then runtime muscle adjusters take control, everythings initialized downwards y
  168.         //-
  169.        
  170.        
  171.        
  172.        
  173.         //limb has issues reaching out to a 90 degree angle with this < 1, gets stuck just past 45 degrees upwards
  174.         //issues with 1 too
  175.         limbOffsetX += spaceBetweenArms;
  176.         limbOffsetZ += spaceBetweenArms;
  177.        
  178.         //notice: relative coords are inverted between structure piece inits and constraints (bug)
  179.        
  180.         setupConstraint(mainBody, limb1, new Vector3f(limbOffsetX, 0.0F, -limbOffsetZ), new Vector3f());
  181.         setupConstraint(limb1, limb11, new Vector3f(0, -armLength-spaceBetweenArms, 0), new Vector3f());
  182.        
  183.         setupConstraint(mainBody, limb2, new Vector3f(0, 0.0F, -limbOffsetZ), new Vector3f());
  184.         setupConstraint(limb2, limb22, new Vector3f(0, -armLength-spaceBetweenArms, 0), new Vector3f());
  185.        
  186.         setupConstraint(mainBody, limb3, new Vector3f(-limbOffsetX, 0.0F, -limbOffsetZ), new Vector3f());
  187.         setupConstraint(limb3, limb33, new Vector3f(0, -armLength-spaceBetweenArms, 0), new Vector3f());
  188.        
  189.         setupConstraint(mainBody, limb4, new Vector3f(limbOffsetX, 0.0F, limbOffsetZ), new Vector3f());
  190.         setupConstraint(limb4, limb44, new Vector3f(0, -armLength-spaceBetweenArms, 0), new Vector3f());
  191.        
  192.         setupConstraint(mainBody, limb5, new Vector3f(0, 0.0F, limbOffsetZ), new Vector3f());
  193.         setupConstraint(limb5, limb55, new Vector3f(0, -armLength-spaceBetweenArms, 0), new Vector3f());
  194.        
  195.         setupConstraint(mainBody, limb6, new Vector3f(-limbOffsetX, 0.0F, limbOffsetZ), new Vector3f());
  196.         setupConstraint(limb6, limb66, new Vector3f(0, -armLength-spaceBetweenArms, 0), new Vector3f());
  197.        
  198.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement