Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public void populateStructureData() {
- super.populateStructureData();
- //you're using box collision on legs, fix
- //also, keep carefull watch on leg orientation to jbullet orientation, relative grid factoring etc
- int pieceIndex = 0;
- StructurePiece mainBody = new StructurePiece(pieceIndex++, (IStructureUser)job, 0, 0, 0);
- body = mainBody;
- //radius, 1 + this
- int radX = 3;
- int radY = 0;
- int radZ = 2;
- int sizeX = radX*2;
- int sizeY = radY*2;
- int sizeZ = radZ*2;
- int radius = Math.max(1, Math.max(sizeX, sizeZ));
- //we cant generate the predicted capsule radius area here, because adding to the grid will extend that height we predicted, changing it
- //body
- for (int x = -sizeX/2; x <= sizeX/2; x++) {
- for (int z = -sizeZ/2; z <= sizeZ/2; z++) {
- for (int y = -sizeY/2; y <= sizeY/2; y++) {
- mainBody.nodes.add(new StructureNode(mainBody, x, y, z));
- if (x == -sizeX/2 || x == sizeX/2 || z == -sizeZ/2 || z == sizeZ/2) {
- mainBody.nodes.add(new StructureNode(mainBody, x, y+1, z));
- }
- }
- }
- }
- float dampLinear = 0.2F;
- float dampAngular = 0.2F;
- mainBody.calculateCenter();
- //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);
- 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);
- rb.setDamping(0, 0);
- //if (true) return;
- int armLength = 3;
- int armLengthLower = 9;
- int spaceBetweenArms = 2;
- int limbOffsetX = 2;//(sizeX/2)+1;
- int limbOffsetZ = (sizeZ/2);
- //legA upper
- StructurePiece limb1 = new StructurePiece(pieceIndex++, mainBody, limbOffsetX, 0, -limbOffsetZ);
- for (int length = 0; length < armLength; length++) {
- limb1.nodes.add(new StructureNode(limb1, 0, -length, 0));
- }
- mainBody.addChildPiece(limb1);
- rb = limb1.initPhysicsObject(1F);
- rb.setDamping(dampLinear, dampAngular);
- //legA lower
- StructurePiece limb11 = new StructurePiece(pieceIndex++, limb1, 0, -armLength-spaceBetweenArms, 0);
- for (int length = 0; length < armLengthLower; length++) {
- limb11.nodes.add(new StructureNode(limb11, 0, -length, 0));
- }
- limb1.addChildPiece(limb11);
- rb = limb11.initPhysicsObject(1F);
- rb.setDamping(dampLinear, dampAngular);
- //legB upper
- StructurePiece limb2 = new StructurePiece(pieceIndex++, mainBody, 0, 0, -limbOffsetZ);
- for (int length = 0; length < armLength; length++) {
- limb2.nodes.add(new StructureNode(limb2, 0, -length, 0));
- }
- mainBody.addChildPiece(limb2);
- rb = limb2.initPhysicsObject(1F);
- rb.setDamping(dampLinear, dampAngular);
- //legB lower
- StructurePiece limb22 = new StructurePiece(pieceIndex++, limb2, 0, -armLength-spaceBetweenArms, 0);
- for (int length = 0; length < armLengthLower; length++) {
- limb22.nodes.add(new StructureNode(limb22, 0, -length, 0));
- }
- limb2.addChildPiece(limb22);
- rb = limb22.initPhysicsObject(1F);
- rb.setDamping(dampLinear, dampAngular);
- //legC upper
- StructurePiece limb3 = new StructurePiece(pieceIndex++, mainBody, -limbOffsetX, 0, -limbOffsetZ);
- for (int length = 0; length < armLength; length++) {
- limb3.nodes.add(new StructureNode(limb3, 0, -length, 0));
- }
- mainBody.addChildPiece(limb3);
- rb = limb3.initPhysicsObject(1F);
- rb.setDamping(dampLinear, dampAngular);
- //legC lower
- StructurePiece limb33 = new StructurePiece(pieceIndex++, limb3, 0, -armLength-spaceBetweenArms, 0);
- for (int length = 0; length < armLengthLower; length++) {
- limb33.nodes.add(new StructureNode(limb33, 0, -length, 0));
- }
- limb3.addChildPiece(limb33);
- rb = limb33.initPhysicsObject(1F);
- rb.setDamping(dampLinear, dampAngular);
- //legD upper
- StructurePiece limb4 = new StructurePiece(pieceIndex++, mainBody, limbOffsetX, 0, limbOffsetZ);
- for (int length = 0; length < armLength; length++) {
- limb4.nodes.add(new StructureNode(limb4, 0, -length, 0));
- }
- mainBody.addChildPiece(limb4);
- rb = limb4.initPhysicsObject(1F);
- rb.setDamping(dampLinear, dampAngular);
- //legD lower
- StructurePiece limb44 = new StructurePiece(pieceIndex++, limb4, 0, -armLength-spaceBetweenArms, 0);
- for (int length = 0; length < armLengthLower; length++) {
- limb44.nodes.add(new StructureNode(limb44, 0, -length, 0));
- }
- limb4.addChildPiece(limb44);
- rb = limb44.initPhysicsObject(1F);
- rb.setDamping(dampLinear, dampAngular);
- //legE upper
- StructurePiece limb5 = new StructurePiece(pieceIndex++, mainBody, 0, 0, limbOffsetZ);
- for (int length = 0; length < armLength; length++) {
- limb5.nodes.add(new StructureNode(limb5, 0, -length, 0));
- }
- mainBody.addChildPiece(limb5);
- rb = limb5.initPhysicsObject(1F);
- rb.setDamping(dampLinear, dampAngular);
- //legE lower
- StructurePiece limb55 = new StructurePiece(pieceIndex++, limb5, 0, -armLength-spaceBetweenArms, 0);
- for (int length = 0; length < armLengthLower; length++) {
- limb55.nodes.add(new StructureNode(limb55, 0, -length, 0));
- }
- limb5.addChildPiece(limb55);
- rb = limb55.initPhysicsObject(1F);
- rb.setDamping(dampLinear, dampAngular);
- //legF upper
- StructurePiece limb6 = new StructurePiece(pieceIndex++, mainBody, -limbOffsetX, 0, limbOffsetZ);
- for (int length = 0; length < armLength; length++) {
- limb6.nodes.add(new StructureNode(limb6, 0, -length, 0));
- }
- mainBody.addChildPiece(limb6);
- rb = limb6.initPhysicsObject(1F);
- rb.setDamping(dampLinear, dampAngular);
- //legF lower
- StructurePiece limb66 = new StructurePiece(pieceIndex++, limb6, 0, -armLength-spaceBetweenArms, 0);
- for (int length = 0; length < armLengthLower; length++) {
- limb66.nodes.add(new StructureNode(limb66, 0, -length, 0));
- }
- limb6.addChildPiece(limb66);
- rb = limb66.initPhysicsObject(1F);
- rb.setDamping(dampLinear, dampAngular);
- //everything needed for constraint setup:
- //- bodyA
- //- bodyB
- //- local connection point for piece A
- //- local connection point for piece B
- //- might not need upper and lower angular limits, currently set to 0,0,0 then runtime muscle adjusters take control, everythings initialized downwards y
- //-
- //limb has issues reaching out to a 90 degree angle with this < 1, gets stuck just past 45 degrees upwards
- //issues with 1 too
- limbOffsetX += spaceBetweenArms;
- limbOffsetZ += spaceBetweenArms;
- //notice: relative coords are inverted between structure piece inits and constraints (bug)
- setupConstraint(mainBody, limb1, new Vector3f(limbOffsetX, 0.0F, -limbOffsetZ), new Vector3f());
- setupConstraint(limb1, limb11, new Vector3f(0, -armLength-spaceBetweenArms, 0), new Vector3f());
- setupConstraint(mainBody, limb2, new Vector3f(0, 0.0F, -limbOffsetZ), new Vector3f());
- setupConstraint(limb2, limb22, new Vector3f(0, -armLength-spaceBetweenArms, 0), new Vector3f());
- setupConstraint(mainBody, limb3, new Vector3f(-limbOffsetX, 0.0F, -limbOffsetZ), new Vector3f());
- setupConstraint(limb3, limb33, new Vector3f(0, -armLength-spaceBetweenArms, 0), new Vector3f());
- setupConstraint(mainBody, limb4, new Vector3f(limbOffsetX, 0.0F, limbOffsetZ), new Vector3f());
- setupConstraint(limb4, limb44, new Vector3f(0, -armLength-spaceBetweenArms, 0), new Vector3f());
- setupConstraint(mainBody, limb5, new Vector3f(0, 0.0F, limbOffsetZ), new Vector3f());
- setupConstraint(limb5, limb55, new Vector3f(0, -armLength-spaceBetweenArms, 0), new Vector3f());
- setupConstraint(mainBody, limb6, new Vector3f(-limbOffsetX, 0.0F, limbOffsetZ), new Vector3f());
- setupConstraint(limb6, limb66, new Vector3f(0, -armLength-spaceBetweenArms, 0), new Vector3f());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement