com.bulletphysics.linearmath.Transform Java Examples
The following examples show how to use
com.bulletphysics.linearmath.Transform.
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: RigidBodyMotionState.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * called from bullet when the transform of the rigidbody changes * @param worldTrans */ @Override public void setWorldTransform(Transform worldTrans) { if (jmeLocationDirty) { return; } motionStateTrans.set(worldTrans); Converter.convert(worldTrans.origin, worldLocation); Converter.convert(worldTrans.basis, worldRotation); worldRotationQuat.fromRotationMatrix(worldRotation); // for (Iterator<PhysicsMotionStateListener> it = listeners.iterator(); it.hasNext();) { // PhysicsMotionStateListener physicsMotionStateListener = it.next(); // physicsMotionStateListener.stateChanged(worldLocation, worldRotation); // } physicsLocationDirty = true; if (vehicle != null) { vehicle.updateWheels(); } }
Example #2
Source File: SixDofJoint.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * @param pivotA local translation of the joint connection point in node A * @param pivotB local translation of the joint connection point in node B */ public SixDofJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, Matrix3f rotA, Matrix3f rotB, boolean useLinearReferenceFrameA) { super(nodeA, nodeB, pivotA, pivotB); this.useLinearReferenceFrameA = useLinearReferenceFrameA; Transform transA = new Transform(Converter.convert(rotA)); Converter.convert(pivotA, transA.origin); Converter.convert(rotA, transA.basis); Transform transB = new Transform(Converter.convert(rotB)); Converter.convert(pivotB, transB.origin); Converter.convert(rotB, transB.basis); constraint = new Generic6DofConstraint(nodeA.getObjectId(), nodeB.getObjectId(), transA, transB, useLinearReferenceFrameA); gatherMotors(); }
Example #3
Source File: SixDofJoint.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * @param pivotA local translation of the joint connection point in node A * @param pivotB local translation of the joint connection point in node B */ public SixDofJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, Matrix3f rotA, Matrix3f rotB, boolean useLinearReferenceFrameA) { super(nodeA, nodeB, pivotA, pivotB); this.useLinearReferenceFrameA = useLinearReferenceFrameA; Transform transA = new Transform(Converter.convert(rotA)); Converter.convert(pivotA, transA.origin); Converter.convert(rotA, transA.basis); Transform transB = new Transform(Converter.convert(rotB)); Converter.convert(pivotB, transB.origin); Converter.convert(rotB, transB.basis); constraint = new Generic6DofConstraint(nodeA.getObjectId(), nodeB.getObjectId(), transA, transB, useLinearReferenceFrameA); gatherMotors(); }
Example #4
Source File: RigidBodyMotionState.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * called from bullet when the transform of the rigidbody changes * @param worldTrans */ public synchronized void setWorldTransform(Transform worldTrans) { if (jmeLocationDirty) { return; } motionStateTrans.set(worldTrans); Converter.convert(worldTrans.origin, worldLocation); Converter.convert(worldTrans.basis, worldRotation); worldRotationQuat.fromRotationMatrix(worldRotation); // for (Iterator<PhysicsMotionStateListener> it = listeners.iterator(); it.hasNext();) { // PhysicsMotionStateListener physicsMotionStateListener = it.next(); // physicsMotionStateListener.stateChanged(worldLocation, worldRotation); // } physicsLocationDirty = true; if (vehicle != null) { vehicle.updateWheels(); } }
Example #5
Source File: Skylight_BulletPhysics_Breakable.java From PixelFlow with MIT License | 6 votes |
public void addGround(){ { Vector3f pos = new Vector3f(0,0,10); BObject body = new BBox(this, 0, 650, 650, 20); Transform transform = new Transform(); body.rigidBody.getWorldTransform(transform); transform.origin.set(pos); body.rigidBody.setWorldTransform(transform); body.rigidBody.getMotionState().setWorldTransform(transform); body.displayShape = createShape(BOX, 650, 650, 20); body.displayShape.setStroke(false); body.displayShape.setFill(true); body.displayShape.setFill(color(180,255,32)); body.displayShape.setStrokeWeight(1); body.displayShape.setStroke(color(0)); physics.addBody(body); group_bulletbodies.addChild(body.displayShape); body.displayShape.setName("ground_box"); } }
Example #6
Source File: Skylight_BulletPhysics_Breakable_VideoExport.java From PixelFlow with MIT License | 6 votes |
public void addGround(){ { Vector3f pos = new Vector3f(0,0,10); BObject body = new BBox(this, 0, 650, 650, 20); Transform transform = new Transform(); body.rigidBody.getWorldTransform(transform); transform.origin.set(pos); body.rigidBody.setWorldTransform(transform); body.rigidBody.getMotionState().setWorldTransform(transform); body.displayShape = createShape(BOX, 650, 650, 20); body.displayShape.setStroke(false); body.displayShape.setFill(true); body.displayShape.setFill(color(180,255,32)); body.displayShape.setStrokeWeight(1); body.displayShape.setStroke(color(0)); physics.addBody(body); group_bulletbodies.addChild(body.displayShape); body.displayShape.setName("ground_box"); } }
Example #7
Source File: CompoundCollisionShape.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * adds a child shape at the given local translation * @param shape the child shape to add * @param location the local location of the child shape */ public void addChildShape(CollisionShape shape, Vector3f location, Matrix3f rotation) { if(shape instanceof CompoundCollisionShape){ throw new IllegalStateException("CompoundCollisionShapes cannot have CompoundCollisionShapes as children!"); } Transform transA = new Transform(Converter.convert(rotation)); Converter.convert(location, transA.origin); Converter.convert(rotation, transA.basis); children.add(new ChildCollisionShape(location.clone(), rotation.clone(), shape)); ((CompoundShape) cShape).addChildShape(transA, shape.getCShape()); }
Example #8
Source File: ConeJoint.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected void createJoint() { Transform transA = new Transform(Converter.convert(rotA)); Converter.convert(pivotA, transA.origin); Converter.convert(rotA, transA.basis); Transform transB = new Transform(Converter.convert(rotB)); Converter.convert(pivotB, transB.origin); Converter.convert(rotB, transB.basis); constraint = new ConeTwistConstraint(nodeA.getObjectId(), nodeB.getObjectId(), transA, transB); ((ConeTwistConstraint) constraint).setLimit(swingSpan1, swingSpan2, twistSpan); ((ConeTwistConstraint) constraint).setAngularOnly(angularOnly); }
Example #9
Source File: SixDofJoint.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @param pivotA local translation of the joint connection point in node A * @param pivotB local translation of the joint connection point in node B */ public SixDofJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, boolean useLinearReferenceFrameA) { super(nodeA, nodeB, pivotA, pivotB); this.useLinearReferenceFrameA = useLinearReferenceFrameA; Transform transA = new Transform(Converter.convert(new Matrix3f())); Converter.convert(pivotA, transA.origin); Transform transB = new Transform(Converter.convert(new Matrix3f())); Converter.convert(pivotB, transB.origin); constraint = new Generic6DofConstraint(nodeA.getObjectId(), nodeB.getObjectId(), transA, transB, useLinearReferenceFrameA); gatherMotors(); }
Example #10
Source File: SixDofJoint.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void read(JmeImporter im) throws IOException { super.read(im); InputCapsule capsule = im.getCapsule(this); Transform transA = new Transform(Converter.convert(new Matrix3f())); Converter.convert(pivotA, transA.origin); Transform transB = new Transform(Converter.convert(new Matrix3f())); Converter.convert(pivotB, transB.origin); constraint = new Generic6DofConstraint(nodeA.getObjectId(), nodeB.getObjectId(), transA, transB, useLinearReferenceFrameA); gatherMotors(); setAngularUpperLimit((Vector3f) capsule.readSavable("angularUpperLimit", new Vector3f(Vector3f.POSITIVE_INFINITY))); setAngularLowerLimit((Vector3f) capsule.readSavable("angularLowerLimit", new Vector3f(Vector3f.NEGATIVE_INFINITY))); setLinearUpperLimit((Vector3f) capsule.readSavable("linearUpperLimit", new Vector3f(Vector3f.POSITIVE_INFINITY))); setLinearLowerLimit((Vector3f) capsule.readSavable("linearLowerLimit", new Vector3f(Vector3f.NEGATIVE_INFINITY))); for (int i = 0; i < 3; i++) { RotationalLimitMotor rotationalLimitMotor = getRotationalLimitMotor(i); rotationalLimitMotor.setBounce(capsule.readFloat("rotMotor" + i + "_Bounce", 0.0f)); rotationalLimitMotor.setDamping(capsule.readFloat("rotMotor" + i + "_Damping", 1.0f)); rotationalLimitMotor.setERP(capsule.readFloat("rotMotor" + i + "_ERP", 0.5f)); rotationalLimitMotor.setHiLimit(capsule.readFloat("rotMotor" + i + "_HiLimit", Float.POSITIVE_INFINITY)); rotationalLimitMotor.setLimitSoftness(capsule.readFloat("rotMotor" + i + "_LimitSoftness", 0.5f)); rotationalLimitMotor.setLoLimit(capsule.readFloat("rotMotor" + i + "_LoLimit", Float.NEGATIVE_INFINITY)); rotationalLimitMotor.setMaxLimitForce(capsule.readFloat("rotMotor" + i + "_MaxLimitForce", 300.0f)); rotationalLimitMotor.setMaxMotorForce(capsule.readFloat("rotMotor" + i + "_MaxMotorForce", 0.1f)); rotationalLimitMotor.setTargetVelocity(capsule.readFloat("rotMotor" + i + "_TargetVelocity", 0)); rotationalLimitMotor.setEnableMotor(capsule.readBoolean("rotMotor" + i + "_EnableMotor", false)); } getTranslationalLimitMotor().setAccumulatedImpulse((Vector3f) capsule.readSavable("transMotor_AccumulatedImpulse", Vector3f.ZERO)); getTranslationalLimitMotor().setDamping(capsule.readFloat("transMotor_Damping", 1.0f)); getTranslationalLimitMotor().setLimitSoftness(capsule.readFloat("transMotor_LimitSoftness", 0.7f)); getTranslationalLimitMotor().setLowerLimit((Vector3f) capsule.readSavable("transMotor_LowerLimit", Vector3f.ZERO)); getTranslationalLimitMotor().setRestitution(capsule.readFloat("transMotor_Restitution", 0.5f)); getTranslationalLimitMotor().setUpperLimit((Vector3f) capsule.readSavable("transMotor_UpperLimit", Vector3f.ZERO)); }
Example #11
Source File: SliderJoint.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected void createJoint(){ Transform transA = new Transform(Converter.convert(rotA)); Converter.convert(pivotA, transA.origin); Converter.convert(rotA, transA.basis); Transform transB = new Transform(Converter.convert(rotB)); Converter.convert(pivotB, transB.origin); Converter.convert(rotB, transB.basis); constraint = new SliderConstraint(nodeA.getObjectId(), nodeB.getObjectId(), transA, transB, useLinearReferenceFrameA); }
Example #12
Source File: CompoundCollisionShape.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * adds a child shape at the given local translation * @param shape the child shape to add * @param location the local location of the child shape */ public void addChildShape(CollisionShape shape, Vector3f location) { Transform transA = new Transform(Converter.convert(new Matrix3f())); Converter.convert(location, transA.origin); children.add(new ChildCollisionShape(location.clone(), new Matrix3f(), shape)); ((CompoundShape) cShape).addChildShape(transA, shape.getCShape()); }
Example #13
Source File: SliderJoint.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
protected void createJoint(){ Transform transA = new Transform(Converter.convert(rotA)); Converter.convert(pivotA, transA.origin); Converter.convert(rotA, transA.basis); Transform transB = new Transform(Converter.convert(rotB)); Converter.convert(pivotB, transB.origin); Converter.convert(rotB, transB.basis); constraint = new SliderConstraint(nodeA.getObjectId(), nodeB.getObjectId(), transA, transB, useLinearReferenceFrameA); }
Example #14
Source File: CompoundCollisionShape.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
private void addChildShapeDirect(CollisionShape shape, Vector3f location, Matrix3f rotation) { if(shape instanceof CompoundCollisionShape){ throw new IllegalStateException("CompoundCollisionShapes cannot have CompoundCollisionShapes as children!"); } Transform transA = new Transform(Converter.convert(rotation)); Converter.convert(location, transA.origin); Converter.convert(rotation, transA.basis); ((CompoundShape) cShape).addChildShape(transA, shape.getCShape()); }
Example #15
Source File: ConeJoint.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
protected void createJoint() { Transform transA = new Transform(Converter.convert(rotA)); Converter.convert(pivotA, transA.origin); Converter.convert(rotA, transA.basis); Transform transB = new Transform(Converter.convert(rotB)); Converter.convert(pivotB, transB.origin); Converter.convert(rotB, transB.basis); constraint = new ConeTwistConstraint(nodeA.getObjectId(), nodeB.getObjectId(), transA, transB); ((ConeTwistConstraint) constraint).setLimit(swingSpan1, swingSpan2, twistSpan); ((ConeTwistConstraint) constraint).setAngularOnly(angularOnly); }
Example #16
Source File: SixDofJoint.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
/** * @param pivotA local translation of the joint connection point in node A * @param pivotB local translation of the joint connection point in node B */ public SixDofJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, boolean useLinearReferenceFrameA) { super(nodeA, nodeB, pivotA, pivotB); this.useLinearReferenceFrameA = useLinearReferenceFrameA; Transform transA = new Transform(Converter.convert(new Matrix3f())); Converter.convert(pivotA, transA.origin); Transform transB = new Transform(Converter.convert(new Matrix3f())); Converter.convert(pivotB, transB.origin); constraint = new Generic6DofConstraint(nodeA.getObjectId(), nodeB.getObjectId(), transA, transB, useLinearReferenceFrameA); gatherMotors(); }
Example #17
Source File: SixDofJoint.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void read(JmeImporter im) throws IOException { super.read(im); InputCapsule capsule = im.getCapsule(this); Transform transA = new Transform(Converter.convert(new Matrix3f())); Converter.convert(pivotA, transA.origin); Transform transB = new Transform(Converter.convert(new Matrix3f())); Converter.convert(pivotB, transB.origin); constraint = new Generic6DofConstraint(nodeA.getObjectId(), nodeB.getObjectId(), transA, transB, useLinearReferenceFrameA); gatherMotors(); setAngularUpperLimit((Vector3f) capsule.readSavable("angularUpperLimit", new Vector3f(Vector3f.POSITIVE_INFINITY))); setAngularLowerLimit((Vector3f) capsule.readSavable("angularLowerLimit", new Vector3f(Vector3f.NEGATIVE_INFINITY))); setLinearUpperLimit((Vector3f) capsule.readSavable("linearUpperLimit", new Vector3f(Vector3f.POSITIVE_INFINITY))); setLinearLowerLimit((Vector3f) capsule.readSavable("linearLowerLimit", new Vector3f(Vector3f.NEGATIVE_INFINITY))); for (int i = 0; i < 3; i++) { RotationalLimitMotor rotationalLimitMotor = getRotationalLimitMotor(i); rotationalLimitMotor.setBounce(capsule.readFloat("rotMotor" + i + "_Bounce", 0.0f)); rotationalLimitMotor.setDamping(capsule.readFloat("rotMotor" + i + "_Damping", 1.0f)); rotationalLimitMotor.setERP(capsule.readFloat("rotMotor" + i + "_ERP", 0.5f)); rotationalLimitMotor.setHiLimit(capsule.readFloat("rotMotor" + i + "_HiLimit", Float.POSITIVE_INFINITY)); rotationalLimitMotor.setLimitSoftness(capsule.readFloat("rotMotor" + i + "_LimitSoftness", 0.5f)); rotationalLimitMotor.setLoLimit(capsule.readFloat("rotMotor" + i + "_LoLimit", Float.NEGATIVE_INFINITY)); rotationalLimitMotor.setMaxLimitForce(capsule.readFloat("rotMotor" + i + "_MaxLimitForce", 300.0f)); rotationalLimitMotor.setMaxMotorForce(capsule.readFloat("rotMotor" + i + "_MaxMotorForce", 0.1f)); rotationalLimitMotor.setTargetVelocity(capsule.readFloat("rotMotor" + i + "_TargetVelocity", 0)); rotationalLimitMotor.setEnableMotor(capsule.readBoolean("rotMotor" + i + "_EnableMotor", false)); } getTranslationalLimitMotor().setAccumulatedImpulse((Vector3f) capsule.readSavable("transMotor_AccumulatedImpulse", Vector3f.ZERO)); getTranslationalLimitMotor().setDamping(capsule.readFloat("transMotor_Damping", 1.0f)); getTranslationalLimitMotor().setLimitSoftness(capsule.readFloat("transMotor_LimitSoftness", 0.7f)); getTranslationalLimitMotor().setLowerLimit((Vector3f) capsule.readSavable("transMotor_LowerLimit", Vector3f.ZERO)); getTranslationalLimitMotor().setRestitution(capsule.readFloat("transMotor_Restitution", 0.5f)); getTranslationalLimitMotor().setUpperLimit((Vector3f) capsule.readSavable("transMotor_UpperLimit", Vector3f.ZERO)); }
Example #18
Source File: CompoundCollisionShape.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void addChildShapeDirect(CollisionShape shape, Vector3f location, Matrix3f rotation) { if(shape instanceof CompoundCollisionShape){ throw new IllegalStateException("CompoundCollisionShapes cannot have CompoundCollisionShapes as children!"); } Transform transA = new Transform(Converter.convert(rotation)); Converter.convert(location, transA.origin); Converter.convert(rotation, transA.basis); ((CompoundShape) cShape).addChildShape(transA, shape.getCShape()); }
Example #19
Source File: CompoundCollisionShape.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * adds a child shape at the given local translation * @param shape the child shape to add * @param location the local location of the child shape */ public void addChildShape(CollisionShape shape, Vector3f location, Matrix3f rotation) { if(shape instanceof CompoundCollisionShape){ throw new IllegalStateException("CompoundCollisionShapes cannot have CompoundCollisionShapes as children!"); } Transform transA = new Transform(Converter.convert(rotation)); Converter.convert(location, transA.origin); Converter.convert(rotation, transA.basis); children.add(new ChildCollisionShape(location.clone(), rotation.clone(), shape)); ((CompoundShape) cShape).addChildShape(transA, shape.getCShape()); }
Example #20
Source File: CompoundCollisionShape.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * adds a child shape at the given local translation * @param shape the child shape to add * @param location the local location of the child shape */ public void addChildShape(CollisionShape shape, Vector3f location) { Transform transA = new Transform(Converter.convert(new Matrix3f())); Converter.convert(location, transA.origin); children.add(new ChildCollisionShape(location.clone(), new Matrix3f(), shape)); ((CompoundShape) cShape).addChildShape(transA, shape.getCShape()); }
Example #21
Source File: PhysicsWorldJBullet.java From gama with GNU General Public License v3.0 | 5 votes |
public RigidBody addCollisionObject(final CollisionShape shape, final float mass, final Vector3f position, final Vector3f velocity, float friction, float lin_damping, float ang_damping, float restitution) { final Transform startTransform = new Transform(); startTransform.setIdentity(); startTransform.origin.set(position); final boolean isDynamic = mass != 0f; final Vector3f localInertia = new Vector3f(0, 0, 0); if (isDynamic) { shape.calculateLocalInertia(mass, localInertia); } // using motionstate is recommended, it provides // interpolation capabilities, and only synchronizes // 'active' objects final DefaultMotionState myMotionState = new DefaultMotionState(startTransform); final RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, myMotionState, shape, localInertia); final RigidBody body = new RigidBody(rbInfo); // DEBUG.OUT(velocity); // body.applyCentralForce(velocity); body.setLinearVelocity(velocity); body.setFriction(friction); body.setDamping(lin_damping, ang_damping); body.setRestitution(restitution); dynamicsWorld.addRigidBody(body); return body; }
Example #22
Source File: Skylight_BulletPhysics_Breakable3.java From PixelFlow with MIT License | 5 votes |
public Transform asBulletTransform(PMatrix3D mat_p5){ Matrix4f mat = new Matrix4f(); mat.setRow(0, mat_p5.m00, mat_p5.m01, mat_p5.m02, mat_p5.m03); mat.setRow(1, mat_p5.m10, mat_p5.m11, mat_p5.m12, mat_p5.m13); mat.setRow(2, mat_p5.m20, mat_p5.m21, mat_p5.m22, mat_p5.m23); mat.setRow(3, mat_p5.m30, mat_p5.m31, mat_p5.m32, mat_p5.m33); return new Transform(mat); }
Example #23
Source File: Skylight_BulletPhysics_Breakable_VideoExport.java From PixelFlow with MIT License | 5 votes |
public Transform asBulletTransform(PMatrix3D mat_p5){ Matrix4f mat = new Matrix4f(); mat.setRow(0, mat_p5.m00, mat_p5.m01, mat_p5.m02, mat_p5.m03); mat.setRow(1, mat_p5.m10, mat_p5.m11, mat_p5.m12, mat_p5.m13); mat.setRow(2, mat_p5.m20, mat_p5.m21, mat_p5.m22, mat_p5.m23); mat.setRow(3, mat_p5.m30, mat_p5.m31, mat_p5.m32, mat_p5.m33); return new Transform(mat); }
Example #24
Source File: BreakableBody.java From PixelFlow with MIT License | 5 votes |
public Transform asBulletTransform(PMatrix3D mat_p5){ mat_tmp.setRow(0, mat_p5.m00, mat_p5.m01, mat_p5.m02, mat_p5.m03); mat_tmp.setRow(1, mat_p5.m10, mat_p5.m11, mat_p5.m12, mat_p5.m13); mat_tmp.setRow(2, mat_p5.m20, mat_p5.m21, mat_p5.m22, mat_p5.m23); mat_tmp.setRow(3, mat_p5.m30, mat_p5.m31, mat_p5.m32, mat_p5.m33); return new Transform(mat_tmp); }
Example #25
Source File: Skylight_BulletPhysics_Breakable.java From PixelFlow with MIT License | 5 votes |
public Transform asBulletTransform(PMatrix3D mat_p5){ Matrix4f mat = new Matrix4f(); mat.setRow(0, mat_p5.m00, mat_p5.m01, mat_p5.m02, mat_p5.m03); mat.setRow(1, mat_p5.m10, mat_p5.m11, mat_p5.m12, mat_p5.m13); mat.setRow(2, mat_p5.m20, mat_p5.m21, mat_p5.m22, mat_p5.m23); mat.setRow(3, mat_p5.m30, mat_p5.m31, mat_p5.m32, mat_p5.m33); return new Transform(mat); }
Example #26
Source File: Jbullet.java From BowlerStudio with GNU General Public License v3.0 | 4 votes |
public static void main(String[] args) { BroadphaseInterface broadphase = new DbvtBroadphase(); DefaultCollisionConfiguration collisionConfiguration = new DefaultCollisionConfiguration(); CollisionDispatcher dispatcher = new CollisionDispatcher(collisionConfiguration); SequentialImpulseConstraintSolver solver = new SequentialImpulseConstraintSolver(); DiscreteDynamicsWorld dynamicsWorld = new DiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration); // set the gravity of our world dynamicsWorld.setGravity(new Vector3f(0, -10, 0)); // setup our collision shapes CollisionShape groundShape = new StaticPlaneShape(new Vector3f(0, 1, 0), 1); CollisionShape fallShape = new SphereShape(1); // setup the motion state DefaultMotionState groundMotionState = new DefaultMotionState( new Transform(new Matrix4f(new Quat4f(0, 0, 0, 1), new Vector3f(0, -1, 0), 1.0f))); RigidBodyConstructionInfo groundRigidBodyCI = new RigidBodyConstructionInfo(0, groundMotionState, groundShape, new Vector3f(0, 0, 0)); RigidBody groundRigidBody = new RigidBody(groundRigidBodyCI); dynamicsWorld.addRigidBody(groundRigidBody); // add our ground to the // dynamic world.. // setup the motion state for the ball DefaultMotionState fallMotionState = new DefaultMotionState( new Transform(new Matrix4f(new Quat4f(0, 0, 0, 1), new Vector3f(0, 100, 0), 1.0f))); // This we're going to give mass so it responds to gravity int mass = 1; Vector3f fallInertia = new Vector3f(0, 0, 0); fallShape.calculateLocalInertia(mass, fallInertia); RigidBodyConstructionInfo fallRigidBodyCI = new RigidBodyConstructionInfo(mass, fallMotionState, fallShape, fallInertia); RigidBody fallRigidBody = new RigidBody(fallRigidBodyCI); // now we add it to our physics simulation dynamicsWorld.addRigidBody(fallRigidBody); for (int i = 0; i < 300; i++) { dynamicsWorld.stepSimulation(1 / 60.f, 10); Transform trans = new Transform(); fallRigidBody.getMotionState().getWorldTransform(trans); System.out.println("sphere height: " + trans.origin.y); } }
Example #27
Source File: RigidBodyMotionState.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * called from bullet when creating the rigidbody * @param t caller-provided storage for the Transform * @return t */ @Override public Transform getWorldTransform(Transform t) { t.set(motionStateTrans); return t; }
Example #28
Source File: RotationTest.java From BowlerStudio with GNU General Public License v3.0 | 4 votes |
@Test public void compareBullet() throws FileNotFoundException { int failCount = 0; int iterations = 100; Log.enableDebugPrint(); for (RotationConvention conv : conventions) { RotationNR.setConvention(conv); System.out.println("\n\nUsing convention " + conv.toString()); for (RotationOrder ro : list) { RotationNR.setOrder(ro); System.out.println("\n\nUsing rotationOrder " + ro.toString()); failCount = 0; for (int i = 0; i < iterations; i++) { double rotationAngleDegrees = (Math.random() * 360) - 180; double rotationAngleRadians = Math.PI / 180 * rotationAngleDegrees; double[][] rotation = new double[3][3]; // Rotation matrix, 1st column rotation[0][0] = Math.cos(rotationAngleRadians); rotation[1][0] = Math.sin(rotationAngleRadians); rotation[2][0] = 0; // Rotation matrix, 2nd column rotation[0][1] = -Math.sin(rotationAngleRadians); rotation[1][1] = Math.cos(rotationAngleRadians); rotation[2][1] = 0; // Rotation matrix, 3rd column rotation[0][2] = 0; rotation[1][2] = 0; rotation[2][2] = 1; // pure rotation in azumuth RotationNR newRot = new RotationNR(rotation); // Convert to Affine and back Transform bulletTrans = new Transform(); TransformFactory.nrToBullet(new TransformNR(0, 0, 0, newRot), bulletTrans); RotationNR oldRot = TransformFactory.bulletToNr(bulletTrans).getRotation(); double[][] rotationMatrix = newRot.getRotationMatrix(); System.out.println("Testing pure azumeth \nrotation " + rotationAngleDegrees + "\n as radian " + Math.toRadians(rotationAngleDegrees) + "\n Az " + oldRot.getRotationAzimuth() + "\n El " + oldRot.getRotationElevation() + "\n Tl " + oldRot.getRotationTilt() + "\n New Az " + newRot.getRotationAzimuth() + "\n New El " + newRot.getRotationElevation() + "\n New Tl " + newRot.getRotationTilt()); assertArrayEquals(rotation[0], rotationMatrix[0], 0.001); assertArrayEquals(rotation[1], rotationMatrix[1], 0.001); assertArrayEquals(rotation[2], rotationMatrix[2], 0.001); System.out.println( "Testing Quaturnion \nrotation " + "\n qw " + oldRot.getRotationMatrix2QuaturnionW() + "\n qx " + oldRot.getRotationMatrix2QuaturnionX() + "\n qy " + oldRot.getRotationMatrix2QuaturnionY() + "\n qz " + oldRot.getRotationMatrix2QuaturnionZ() + "\nNEW qw " + newRot.getRotationMatrix2QuaturnionW() + "\nNEW qx " + newRot.getRotationMatrix2QuaturnionX() + "\nNEW qy " + newRot.getRotationMatrix2QuaturnionY() + "\nNEW qz " + newRot.getRotationMatrix2QuaturnionZ()); assertArrayEquals( new double[] { Math.abs(oldRot.getRotationMatrix2QuaturnionW()), Math.abs(oldRot.getRotationMatrix2QuaturnionX()), Math.abs(oldRot.getRotationMatrix2QuaturnionY()), Math.abs(oldRot.getRotationMatrix2QuaturnionZ()), }, new double[] { Math.abs(newRot.getRotationMatrix2QuaturnionW()), Math.abs(newRot.getRotationMatrix2QuaturnionX()), Math.abs(newRot.getRotationMatrix2QuaturnionY()), Math.abs(newRot.getRotationMatrix2QuaturnionZ()), }, 0.001); // Check Euler angles // this check is needed to work around a known bug in the // legact implementation assertArrayEquals( new double[] { oldRot.getRotationAzimuth(), oldRot.getRotationElevation(), oldRot.getRotationTilt() }, new double[] { newRot.getRotationAzimuth(), newRot.getRotationElevation(), newRot.getRotationTilt() }, 0.001); // Check the old rotation against the known value assertArrayEquals(new double[] { Math.toRadians(rotationAngleDegrees), 0, 0 }, new double[] { oldRot.getRotationAzimuth(), oldRot.getRotationElevation(), oldRot.getRotationTilt() }, 0.001); // Check the new rotation against the known value assertArrayEquals(new double[] { Math.toRadians(rotationAngleDegrees), 0, 0 }, new double[] { newRot.getRotationAzimuth(), newRot.getRotationElevation(), newRot.getRotationTilt() }, 0.001); } // frame(); // frame2(); System.out.println("Frame test passed with " + ro); // return; } } }
Example #29
Source File: RotationTest.java From BowlerStudio with GNU General Public License v3.0 | 4 votes |
@Test public void compareBulletElevation() throws FileNotFoundException { int failCount = 0; int iterations = 100; Log.enableDebugPrint(); for (RotationConvention conv : conventions) { RotationNR.setConvention(conv); System.out.println("\n\nUsing convention " + conv.toString()); for (RotationOrder ro : list) { RotationNR.setOrder(ro); System.out.println("\n\nUsing rotationOrder " + ro.toString()); failCount = 0; for (int i = 0; i < iterations; i++) { double rotationAngleDegrees = (Math.random() * 180) - 90; double rotationAngleRadians = Math.PI / 180 * rotationAngleDegrees; double[][] rotation = new double[3][3]; // Rotation matrix, 1st column rotation[0][0] = Math.cos(rotationAngleRadians); rotation[1][0] = 0; rotation[2][0] = -Math.sin(rotationAngleRadians); // Rotation matrix, 2nd column rotation[0][1] = 0; rotation[1][1] = 1; rotation[2][1] = 0; // Rotation matrix, 3rd column rotation[0][2] = Math.sin(rotationAngleRadians); rotation[1][2] = 0; rotation[2][2] = Math.cos(rotationAngleRadians); RotationNR newRot = new RotationNR(rotation); // Convert to Affine and back Transform bulletTrans = new Transform(); TransformFactory.nrToBullet(new TransformNR(0, 0, 0, newRot), bulletTrans); RotationNR oldRot = TransformFactory.bulletToNr(bulletTrans).getRotation(); double[][] rotationMatrix = newRot.getRotationMatrix(); System.out.println("Testing pure Elevation \nrotation " + rotationAngleDegrees + "\n as radian " + Math.toRadians(rotationAngleDegrees) + "\n Az " + oldRot.getRotationAzimuth() + "\n El " + oldRot.getRotationElevation() + "\n Tl " + oldRot.getRotationTilt() + "\n New Az " + newRot.getRotationAzimuth() + "\n New El " + newRot.getRotationElevation() + "\n New Tl " + newRot.getRotationTilt()); assertArrayEquals(rotation[0], rotationMatrix[0], 0.001); assertArrayEquals(rotation[1], rotationMatrix[1], 0.001); assertArrayEquals(rotation[2], rotationMatrix[2], 0.001); System.out.println( "Testing Quaturnion \nrotation " + "\n qw " + oldRot.getRotationMatrix2QuaturnionW() + "\n qx " + oldRot.getRotationMatrix2QuaturnionX() + "\n qy " + oldRot.getRotationMatrix2QuaturnionY() + "\n qz " + oldRot.getRotationMatrix2QuaturnionZ() + "\nNEW qw " + newRot.getRotationMatrix2QuaturnionW() + "\nNEW qx " + newRot.getRotationMatrix2QuaturnionX() + "\nNEW qy " + newRot.getRotationMatrix2QuaturnionY() + "\nNEW qz " + newRot.getRotationMatrix2QuaturnionZ()); assertArrayEquals( new double[] { Math.abs(oldRot.getRotationMatrix2QuaturnionW()), Math.abs(oldRot.getRotationMatrix2QuaturnionX()), Math.abs(oldRot.getRotationMatrix2QuaturnionY()), Math.abs(oldRot.getRotationMatrix2QuaturnionZ()), }, new double[] { Math.abs(newRot.getRotationMatrix2QuaturnionW()), Math.abs(newRot.getRotationMatrix2QuaturnionX()), Math.abs(newRot.getRotationMatrix2QuaturnionY()), Math.abs(newRot.getRotationMatrix2QuaturnionZ()), }, 0.001); // Check Euler angles // this check is needed to work around a known bug in the // legact implementation // Check Euler angles assertArrayEquals( new double[] { oldRot.getRotationAzimuth(), oldRot.getRotationElevation(), oldRot.getRotationTilt() }, new double[] { newRot.getRotationAzimuth(), newRot.getRotationElevation(), newRot.getRotationTilt() }, 0.001); // Check the old rotation against the known value assertArrayEquals(new double[] { 0, Math.toRadians(rotationAngleDegrees), 0 }, new double[] { oldRot.getRotationAzimuth(), oldRot.getRotationElevation(), oldRot.getRotationTilt() }, 0.001); // Check the new rotation against the known value assertArrayEquals(new double[] { 0, Math.toRadians(rotationAngleDegrees), 0 }, new double[] { newRot.getRotationAzimuth(), newRot.getRotationElevation(), newRot.getRotationTilt() }, 0.001); } // frame(); // frame2(); System.out.println("Frame test passed with " + ro); // return; } } }
Example #30
Source File: Skylight_BulletPhysics_Cubes.java From PixelFlow with MIT License | 4 votes |
public void createFractureShape(){ reset(); float pos_z = 20f; int numx = 15; int numy = 5; int numz = 10; float dim = 20; float boundsx = numx * dim; float boundsy = numy * dim; // float boundsz = numz * dim; float mass = dim*dim*dim; float tx = -boundsx * 0.5f; float ty = -boundsy * 0.5f; float tz = pos_z + 0; colorMode(HSB, 360, 100,100); for(int z = 0; z < numz; z++){ for(int y = 0; y < numy; y++){ for(int x = 0; x < numx; x++){ float cx = dim *0.5f + x * dim; float cy = dim *0.5f + y * dim; float cz = dim *0.5f + z * dim; BObject body = new BBox(this, mass, dim, dim, dim); // setup initial body transform-matrix PMatrix3D mat_p5 = new PMatrix3D(); mat_p5.translate(tx, ty, tz); mat_p5.translate(cx, cy, cz); Matrix4f mat = new Matrix4f(); mat.setRow(0, mat_p5.m00, mat_p5.m01, mat_p5.m02, mat_p5.m03); mat.setRow(1, mat_p5.m10, mat_p5.m11, mat_p5.m12, mat_p5.m13); mat.setRow(2, mat_p5.m20, mat_p5.m21, mat_p5.m22, mat_p5.m23); mat.setRow(3, mat_p5.m30, mat_p5.m31, mat_p5.m32, mat_p5.m33); Transform transform = new Transform(mat); // rigid-body properties body.rigidBody.setWorldTransform(transform); body.rigidBody.setRestitution(.1f); body.rigidBody.setFriction(0.85f); body.rigidBody.setDamping(0.2f, 0.2f); body.displayShape = createShape(BOX, dim, dim, dim); body.displayShape.setStroke(false); body.displayShape.setFill(true); // float r = random(80, 130); float r = random(220, 270); float g = random(20,70); float b = 100; body.displayShape.setFill(color(r,g,b)); physics.addBody(body); group_bulletbodies.addChild(body.displayShape); } } } colorMode(RGB, 255, 255,255); }