public static javax.vecmath.Vector3f to(Vector3f v) { return new javax.vecmath.Vector3f(v.x, v.y, v.z); }
@Override public void processTriangle(Vector3f[] triangle, int partId, int triangleIndex) { // Three sets of individual lines // The new Vector is needed as the given triangle reference is from a pool vertices.add(new Vector3f(triangle[0])); vertices.add(new Vector3f(triangle[1])); vertices.add(new Vector3f(triangle[2])); }
public static javax.vecmath.Vector3f convert(com.jme3.math.Vector3f oldVec) { javax.vecmath.Vector3f newVec = new javax.vecmath.Vector3f(); convert(oldVec, newVec); return newVec; }
@Override public void awakenArea(org.terasology.math.geom.Vector3f pos, float radius) { Vector3f min = new Vector3f(VecMath.to(pos)); min.sub(new Vector3f(0.6f, 0.6f, 0.6f)); Vector3f max = new Vector3f(VecMath.to(pos)); max.add(new Vector3f(0.6f, 0.6f, 0.6f)); discreteDynamicsWorld.awakenRigidBodiesInArea(min, max); }
@Override public Vector3f getHalfExtentsWithoutMargin() { javax.vecmath.Vector3f out = new javax.vecmath.Vector3f(); return VecMath.from(boxShape.getHalfExtentsWithoutMargin(out)); } }
/** * Gets the gravity of the PhysicsSpace * @param gravity */ public Vector3f getGravity(Vector3f gravity) { javax.vecmath.Vector3f tempVec = new javax.vecmath.Vector3f(); dynamicsWorld.getGravity(tempVec); return Converter.convert(tempVec, gravity); }
@Override public AABB getAABB(org.terasology.math.Transform transform) { Transform t = toBulletTransform(transform); javax.vecmath.Vector3f min = new javax.vecmath.Vector3f(); javax.vecmath.Vector3f max = new javax.vecmath.Vector3f(); underlyingShape.getAabb(t, min, max); return AABB.createMinMax(VecMath.from(min), VecMath.from(max)); }
@Override public boolean removeRigidBody(EntityRef entity) { BulletRigidBody rigidBody = entityRigidBodies.remove(entity); if (rigidBody != null) { removeRigidBody(rigidBody); // wake up this entities neighbors float[] radius = new float[1]; rigidBody.rb.getCollisionShape().getBoundingSphere(new Vector3f(), radius); awakenArea(rigidBody.getLocation(new org.terasology.math.geom.Vector3f()), radius[0]); return true; } else { logger.warn("Deleting non existing rigidBody from physics engine?! Entity: {}", entity); return false; } }
@Override public CollisionShape rotate(Quat4f rot) { javax.vecmath.Vector3f halfExtentsWithMargin = boxShape.getHalfExtentsWithMargin(new javax.vecmath.Vector3f()); com.bulletphysics.linearmath.QuaternionUtil.quatRotate(VecMath.to(rot), halfExtentsWithMargin, halfExtentsWithMargin); halfExtentsWithMargin.absolute(); return new BulletBoxShape(halfExtentsWithMargin); }
public BulletPhysics(WorldProvider world) { broadphase = new DbvtBroadphase(); broadphase.getOverlappingPairCache().setInternalGhostPairCallback(new GhostPairCallback()); CollisionConfiguration defaultCollisionConfiguration = new DefaultCollisionConfiguration(); dispatcher = new CollisionDispatcher(defaultCollisionConfiguration); SequentialImpulseConstraintSolver sequentialImpulseConstraintSolver = new SequentialImpulseConstraintSolver(); discreteDynamicsWorld = new DiscreteDynamicsWorld(dispatcher, broadphase, sequentialImpulseConstraintSolver, defaultCollisionConfiguration); discreteDynamicsWorld.setGravity(new Vector3f(0f, -15f, 0f)); blockEntityRegistry = CoreRegistry.get(BlockEntityRegistry.class); wrapper = new PhysicsWorldWrapper(world); VoxelWorldShape worldShape = new VoxelWorldShape(wrapper); liquidWrapper = new PhysicsLiquidWrapper(world); VoxelWorldShape liquidShape = new VoxelWorldShape(liquidWrapper); Matrix3f rot = new Matrix3f(); rot.setIdentity(); DefaultMotionState blockMotionState = new DefaultMotionState(new Transform(new Matrix4f(rot, new Vector3f(0, 0, 0), 1.0f))); RigidBodyConstructionInfo blockConsInf = new RigidBodyConstructionInfo(0, blockMotionState, worldShape, new Vector3f()); BulletRigidBody rigidBody = new BulletRigidBody(blockConsInf); rigidBody.rb.setCollisionFlags(CollisionFlags.STATIC_OBJECT | rigidBody.rb.getCollisionFlags()); short mask = (short) (~(CollisionFilterGroups.STATIC_FILTER | StandardCollisionGroup.LIQUID.getFlag())); discreteDynamicsWorld.addRigidBody(rigidBody.rb, combineGroups(StandardCollisionGroup.WORLD), mask); RigidBodyConstructionInfo liquidConsInfo = new RigidBodyConstructionInfo(0, blockMotionState, liquidShape, new Vector3f()); BulletRigidBody liquidBody = new BulletRigidBody(liquidConsInfo); liquidBody.rb.setCollisionFlags(CollisionFlags.STATIC_OBJECT | rigidBody.rb.getCollisionFlags()); discreteDynamicsWorld.addRigidBody(liquidBody.rb, combineGroups(StandardCollisionGroup.LIQUID), CollisionFilterGroups.SENSOR_TRIGGER); }
@Override public CollisionShape rotate(Quat4f rot) { ObjectArrayList<javax.vecmath.Vector3f> transformedVerts = new ObjectArrayList<>(); for (javax.vecmath.Vector3f vert : convexHullShape.getPoints()) { transformedVerts.add(com.bulletphysics.linearmath.QuaternionUtil.quatRotate(VecMath.to(rot), vert, new javax.vecmath.Vector3f())); } return new BulletConvexHullShape(transformedVerts); } }
protected void createShape() { HeightfieldTerrainShape shape = new HeightfieldTerrainShape(heightStickWidth, heightStickLength, heightfieldData, heightScale, minHeight, maxHeight, upAxis, flipQuadEdges); shape.setLocalScaling(new javax.vecmath.Vector3f(scale.x, scale.y, scale.z)); cShape = shape; cShape.setLocalScaling(Converter.convert(getScale())); cShape.setMargin(margin); }
protected void createShape(float[] points) { ObjectArrayList<Vector3f> pointList = new ObjectArrayList<Vector3f>(); for (int i = 0; i < points.length; i += 3) { pointList.add(new Vector3f(points[i], points[i + 1], points[i + 2])); } cShape = new ConvexHullShape(pointList); cShape.setLocalScaling(Converter.convert(getScale())); cShape.setMargin(margin); }
if (shape != null && location != null && trigger != null) { float scale = location.getWorldScale(); shape.setLocalScaling(new Vector3f(scale, scale, scale)); List<CollisionGroup> detectGroups = Lists.newArrayList(trigger.detectGroups); CollisionGroup collisionGroup = trigger.collisionGroup;
@Override //TODO: update if detectGroups changed public boolean updateTrigger(EntityRef entity) { LocationComponent location = entity.getComponent(LocationComponent.class); PairCachingGhostObject triggerObj = entityTriggers.get(entity); if (location == null) { logger.warn("Trying to update or create trigger of entity that has no LocationComponent?! Entity: {}", entity); return false; } if (triggerObj != null) { float scale = location.getWorldScale(); if (Math.abs(triggerObj.getCollisionShape().getLocalScaling(new Vector3f()).x - scale) > BulletGlobals.SIMD_EPSILON) { discreteDynamicsWorld.removeCollisionObject(triggerObj); newTrigger(entity); } else { Quat4f worldRotation = VecMath.to(location.getWorldRotation()); Vector3f worldPosition = VecMath.to(location.getWorldPosition()); triggerObj.setWorldTransform(new Transform(new Matrix4f(worldRotation, worldPosition, 1.0f))); } return true; } else { newTrigger(entity); return false; } }
} else if (rigidBody != null) { float scale = location.getWorldScale(); if (Math.abs(rigidBody.rb.getCollisionShape().getLocalScaling(new Vector3f()).x - scale) > BulletGlobals.SIMD_EPSILON || rigidBody.collidesWith != combineGroups(rb.collidesWith)) { removeRigidBody(rigidBody);
@Override public CollisionShape rotate(Quat4f rot) { CompoundShape newShape = new CompoundShape(); for (BulletCompoundShapeChild child : childList) { CollisionShape rotatedChild = child.childShape.rotate(rot); javax.vecmath.Vector3f offset = com.bulletphysics.linearmath.QuaternionUtil.quatRotate(VecMath.to(rot), child.transform.origin, new javax.vecmath.Vector3f()); newShape.addChildShape(new Transform(new javax.vecmath.Matrix4f(VecMath.to(Rotation.none().getQuat4f()), offset, 1.0f)), ((BulletCollisionShape) rotatedChild).underlyingShape); } return new BulletCompoundShape(newShape); }
boolean hitStep = false; float stepSlope = 1f; Vector3f lookAheadOffset = new Vector3f(direction.x, direction.y, direction.z); lookAheadOffset.y = 0; lookAheadOffset.normalize(); lookAheadOffset.scale(checkForwardDistance); Vector3f fromWorld = new Vector3f(hitPointWorld); fromWorld.y += stepHeight + 0.05f; fromWorld.add(lookAheadOffset); Vector3f toWorld = new Vector3f(hitPointWorld); toWorld.y -= 0.05f; toWorld.add(lookAheadOffset); if (rayResult.hasHit()) { hitStep = true; stepSlope = rayResult.hitNormalWorld.dot(new Vector3f(0, 1, 0)); if (rayResult.hasHit()) { hitStep = true; stepSlope = Math.min(stepSlope, rayResult.hitNormalWorld.dot(new Vector3f(0, 1, 0)));