public static javax.vecmath.Matrix3f convert(com.jme3.math.Matrix3f oldMatrix) { javax.vecmath.Matrix3f newMatrix = new javax.vecmath.Matrix3f(); convert(oldMatrix, newMatrix); return newMatrix; }
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); }
public Transformer(TRSRTransformation transformation, VertexFormat format) { super(new UnpackedBakedQuad.Builder(format)); // position transform this.transformation = transformation.getMatrix(); // normal transform this.normalTransformation = new Matrix3f(); this.transformation.getRotationScale(this.normalTransformation); this.normalTransformation.invert(); this.normalTransformation.transpose(); }
private static Vector3d rotate(Vector3d vector, Vector3d axis, double angle) { Matrix3f rotate = new Matrix3f(); rotate.set(new AxisAngle4f(new Vector3f(axis), (float) Math.toRadians(angle))); Vector3f result = new Vector3f(); Vector3f vector3f = new Vector3f(vector); rotate.transform(vector3f, result); return new Vector3d(result); }
/** * Utility method to rotate a given mesh using a given rotation matrix. * @param input the mesh to rotate. Not modified. * @param axisAngle the axis-angle describing the rotation to apply to the mesh. Not Modified. * @return the rotated mesh. */ public static MeshDataHolder rotate(MeshDataHolder input, AxisAngle4d axisAngle) { Matrix3f matrix = new Matrix3f(); matrix.set(axisAngle); return rotate(input, matrix); }
/** * Utility method to rotate a given mesh using a given rotation matrix. * @param input the mesh to rotate. Not modified. * @param matrix the rotation to apply to the mesh. Not Modified. * @return the rotated mesh. */ public static MeshDataHolder rotate(MeshDataHolder input, Matrix3f matrix) { TexCoord2f[] texturePoints = input.getTexturePoints(); int[] triangleIndices = input.getTriangleIndices(); Point3f[] inputVertices = input.getVertices(); Vector3f[] inputNormals = input.getVertexNormals(); Point3f[] outputVertices = new Point3f[inputVertices.length]; Vector3f[] outputNormals = new Vector3f[inputNormals.length]; for (int i = 0; i < inputVertices.length; i++) { outputVertices[i] = new Point3f(); outputNormals[i] = new Vector3f(); matrix.transform(inputVertices[i], outputVertices[i]); matrix.transform(inputNormals[i], outputNormals[i]); } return new MeshDataHolder(outputVertices, texturePoints, triangleIndices, outputNormals); }
public static Matrix3f generateRandomMatrix3f(Random random, float maxAbsolute) { Matrix3f ret = new Matrix3f(); for(int row = 0; row < 3; row++) { for (int column = 0; column < 3; column++) { ret.setElement(row, column, generateRandomFloatInRange(random, -maxAbsolute, maxAbsolute)); } } return ret; }
@Override public void getOrientationMeasurement(Matrix3f orientationToPack) { orientationToPack.set(orientationMeasurement); }
/** * Sets the value of this matrix to the transpose of the argument matrix. * @param m1 the matrix to be transposed */ public final void transpose(Matrix3f m1) { if (this != m1) { this.m00 = m1.m00; this.m01 = m1.m10; this.m02 = m1.m20; this.m10 = m1.m01; this.m11 = m1.m11; this.m12 = m1.m21; this.m20 = m1.m02; this.m21 = m1.m12; this.m22 = m1.m22; } else this.transpose(); }
final Orientation orientation = orientations[i]; final Matrix3f mat = orientation.getLocalToWorldMatrix(); if (invert) mat.invert();
public Transformer(TRSRTransformation transformation, VertexFormat format) { super(new UnpackedBakedQuad.Builder(format)); // position transform this.transformation = transformation.getMatrix(); // normal transform this.normalTransformation = new Matrix3f(); this.transformation.getRotationScale(this.normalTransformation); this.normalTransformation.invert(); this.normalTransformation.transpose(); }
private static Vector3d rotate(Vector3d vector, Vector3d axis, double angle) { Matrix3f rotate = new Matrix3f(); rotate.set(new AxisAngle4f(new Vector3f(axis), (float) Math.toRadians(angle))); Vector3f result = new Vector3f(); Vector3f vector3f = new Vector3f(vector); rotate.transform(vector3f, result); return new Vector3d(result); }
/** * Utility method to rotate a given mesh using a given rotation matrix. * @param input the mesh to rotate. Not modified. * @param quaternion the quaternion describing the rotation to apply to the mesh. Not Modified. * @return the rotated mesh. */ public static MeshDataHolder rotate(MeshDataHolder input, Quat4f quaternion) { Matrix3f matrix = new Matrix3f(); matrix.set(quaternion); return rotate(input, matrix); }
@Override public void put(int element, float... data) { VertexFormatElement.EnumUsage usage = parent.getVertexFormat().getElement(element).getUsage(); // transform normals and position if(usage == VertexFormatElement.EnumUsage.POSITION && data.length >= 3) { Vector4f vec = new Vector4f(data[0], data[1], data[2], 1f); transformation.transform(vec); data = new float[4]; vec.get(data); } else if(usage == VertexFormatElement.EnumUsage.NORMAL && data.length >= 3) { Vector3f vec = new Vector3f(data); normalTransformation.transform(vec); vec.normalize(); data = new float[4]; vec.get(data); } super.put(element, data); }
public void getMatrix3f(Matrix3f matrixToPack) { matrixToPack.set(quaternion); }
public Transformer(TRSRTransformation transformation, VertexFormat format) { super(new UnpackedBakedQuad.Builder(format)); // position transform this.transformation = transformation.getMatrix(); // normal transform this.normalTransformation = new Matrix3f(); this.transformation.getRotationScale(this.normalTransformation); this.normalTransformation.invert(); this.normalTransformation.transpose(); }
/** * Utility method to rotate a given mesh using a given rotation matrix. * @param input the mesh to rotate. Not modified. * @param matrix the rotation to apply to the mesh. Not Modified. * @return the rotated mesh. */ public static MeshDataHolder rotate(MeshDataHolder input, Matrix3d matrix) { return rotate(input, new Matrix3f(matrix)); }
private static Multimap<Orientation, XYZRotation> calculateXyzRotations(Map<Matrix3f, Orientation> fromMatrix) { final Multimap<Orientation, XYZRotation> toXYZRotation = HashMultimap.create(); for (Rotation x : Rotation.values()) for (Rotation y : Rotation.values()) for (Rotation z : Rotation.values()) { final XYZRotation rotation = new XYZRotation(x, y, z); Quat4f q = new Quat4f(0, 0, 0, 1); Quat4f tmp = new Quat4f(); tmp.set(new AxisAngle4f(0, 0, 1, z.angle)); q.mul(tmp); tmp.set(new AxisAngle4f(0, 1, 0, y.angle)); q.mul(tmp); tmp.set(new AxisAngle4f(1, 0, 0, x.angle)); q.mul(tmp); Matrix3f m = new Matrix3f(); m.set(q); roundMatrixElements(m); final Orientation orientation = fromMatrix.get(m); Preconditions.checkNotNull(orientation, rotation); toXYZRotation.put(orientation, rotation); } return toXYZRotation; }
@Override public void put(int element, float... data) { VertexFormatElement.EnumUsage usage = parent.getVertexFormat().getElement(element).getUsage(); // transform normals and position if (usage == VertexFormatElement.EnumUsage.POSITION && data.length >= 3) { Vector4f vec = new Vector4f(data[0], data[1], data[2], 1f); transformation.transform(vec); data = new float[4]; vec.get(data); } else if (usage == VertexFormatElement.EnumUsage.NORMAL && data.length >= 3) { Vector3f vec = new Vector3f(data); normalTransformation.transform(vec); vec.normalize(); data = new float[4]; vec.get(data); } super.put(element, data); }
public Transformer(TRSRTransformation transformation, VertexFormat format) { super(new UnpackedBakedQuad.Builder(format)); // position transform this.transformation = transformation.getMatrix(); // normal transform this.normalTransformation = new Matrix3f(); this.transformation.getRotationScale(this.normalTransformation); this.normalTransformation.invert(); this.normalTransformation.transpose(); }