diff --git a/jme3-android/src/main/java/jme3test/android/TestMovingParticle.java b/jme3-android/src/main/java/jme3test/android/TestMovingParticle.java index b6b7922c7e..93a59be446 100644 --- a/jme3-android/src/main/java/jme3test/android/TestMovingParticle.java +++ b/jme3-android/src/main/java/jme3test/android/TestMovingParticle.java @@ -33,7 +33,7 @@ import com.jme3.app.SimpleApplication; import com.jme3.effect.ParticleEmitter; -import com.jme3.effect.ParticleMesh.Type; +import com.jme3.effect.ParticleTriMesh; import com.jme3.input.KeyInput; import com.jme3.input.controls.ActionListener; import com.jme3.input.controls.KeyTrigger; @@ -60,7 +60,7 @@ public static void main(String[] args) { @Override public void simpleInitApp() { - emit = new ParticleEmitter("Emitter", Type.Triangle, 300); + emit = new ParticleEmitter("Emitter", new ParticleTriMesh(), 300); emit.setGravity(0, 0, 0); emit.setVelocityVariation(1); emit.setLowLife(1); diff --git a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/animations/BoneContext.java b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/animations/BoneContext.java index adc0a5c4cc..2f2bc152ea 100644 --- a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/animations/BoneContext.java +++ b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/animations/BoneContext.java @@ -5,7 +5,8 @@ import com.jme3.animation.Bone; import com.jme3.animation.Skeleton; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.math.Quaternion; import com.jme3.math.Vector3f; import com.jme3.scene.Spatial; @@ -36,7 +37,8 @@ public class BoneContext { * The bones' matrices have, unlike objects', the coordinate system identical to JME's (Y axis is UP, X to the right and Z toward us). * So in order to have them loaded properly we need to transform their armature matrix (which blender sees as rotated) to make sure we get identical results. */ - public static final Matrix4f BONE_ARMATURE_TRANSFORMATION_MATRIX = new Matrix4f(1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1); + public static final float[] data = {1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1}; + public static final Matrixable BONE_ARMATURE_TRANSFORMATION_MATRIX = new Matrix(data); private static final int IKFLAG_LOCK_X = 0x01; private static final int IKFLAG_LOCK_Y = 0x02; @@ -57,9 +59,9 @@ public class BoneContext { /** The bone's flag. */ private int flag; /** The bone's matrix in world space. */ - private Matrix4f globalBoneMatrix; + private Matrixable globalBoneMatrix; /** The bone's matrix in the model space. */ - private Matrix4f boneMatrixInModelSpace; + private Matrixable boneMatrixInModelSpace; /** The parent context. */ private BoneContext parent; /** The children of this context. */ @@ -139,7 +141,7 @@ private BoneContext(Structure boneStructure, Long armatureObjectOMA, BoneContext Structure armatureStructure = blenderContext.getFileBlock(armatureObjectOMA).getStructure(blenderContext); Spatial armature = (Spatial) objectHelper.toObject(armatureStructure, blenderContext); ConstraintHelper constraintHelper = blenderContext.getHelper(ConstraintHelper.class); - Matrix4f armatureWorldMatrix = constraintHelper.toMatrix(armature.getWorldTransform(), new Matrix4f()); + Matrixable armatureWorldMatrix = constraintHelper.toMatrix(armature.getWorldTransform(), new Matrix(4)); // and now compute the final bone matrix in world space globalBoneMatrix = armatureWorldMatrix.mult(globalBoneMatrix); @@ -207,14 +209,14 @@ public Bone buildBone(List bones, Long skeletonOwnerOma, BlenderContext bl Structure skeletonOwnerObjectStructure = (Structure) blenderContext.getLoadedFeature(skeletonOwnerOma, LoadedDataType.STRUCTURE); // I could load 'imat' here, but apparently in some older blenders there were bugs or unfinished functionalities that stored ZERO matrix in imat field // loading 'obmat' and inverting it makes us avoid errors in such cases - Matrix4f invertedObjectOwnerGlobalMatrix = objectHelper.getMatrix(skeletonOwnerObjectStructure, "obmat", blenderContext.getBlenderKey().isFixUpAxis()).invertLocal(); + Matrixable invertedObjectOwnerGlobalMatrix = objectHelper.getMatrix(skeletonOwnerObjectStructure, "obmat", blenderContext.getBlenderKey().isFixUpAxis()).invertLocal(); if (objectHelper.isParent(skeletonOwnerOma, armatureObjectOMA)) { boneMatrixInModelSpace = globalBoneMatrix.mult(invertedObjectOwnerGlobalMatrix); } else { boneMatrixInModelSpace = invertedObjectOwnerGlobalMatrix.mult(globalBoneMatrix); } - Matrix4f boneLocalMatrix = parent == null ? boneMatrixInModelSpace : parent.boneMatrixInModelSpace.invert().multLocal(boneMatrixInModelSpace); + Matrixable boneLocalMatrix = parent == null ? boneMatrixInModelSpace : parent.boneMatrixInModelSpace.invert().multLocal(boneMatrixInModelSpace); Vector3f poseLocation = parent == null || !this.is(CONNECTED_TO_PARENT) ? boneLocalMatrix.toTranslationVector() : new Vector3f(0, parent.length, 0); Quaternion rotation = boneLocalMatrix.toRotationQuat().normalizeLocal(); @@ -278,7 +280,7 @@ public Skeleton getSkeleton() { /** * @return the initial bone's matrix in model space */ - public Matrix4f getBoneMatrixInModelSpace() { + public Matrixable getBoneMatrixInModelSpace() { return boneMatrixInModelSpace; } diff --git a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/animations/BoneEnvelope.java b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/animations/BoneEnvelope.java index 83e708dc10..6099ce97ef 100644 --- a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/animations/BoneEnvelope.java +++ b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/animations/BoneEnvelope.java @@ -1,6 +1,6 @@ package com.jme3.scene.plugins.blender.animations; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrixable; import com.jme3.math.Vector3f; import com.jme3.scene.plugins.blender.file.DynamicArray; import com.jme3.scene.plugins.blender.file.Structure; @@ -36,7 +36,7 @@ public class BoneEnvelope { * a variable that tells if we use the Y-is up axis orientation */ @SuppressWarnings("unchecked") - public BoneEnvelope(Structure boneStructure, Matrix4f armatureWorldMatrix, boolean fixUpAxis) { + public BoneEnvelope(Structure boneStructure, Matrixable armatureWorldMatrix, boolean fixUpAxis) { distance = ((Number) boneStructure.getFieldValue("dist")).floatValue(); weight = ((Number) boneStructure.getFieldValue("weight")).floatValue(); boneHeadRadius = ((Number) boneStructure.getFieldValue("rad_head")).floatValue(); diff --git a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/ConstraintHelper.java b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/ConstraintHelper.java index 6d3058ed27..5daf644ad0 100644 --- a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/ConstraintHelper.java +++ b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/ConstraintHelper.java @@ -10,7 +10,7 @@ import com.jme3.animation.Bone; import com.jme3.animation.Skeleton; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrixable; import com.jme3.math.Quaternion; import com.jme3.math.Transform; import com.jme3.math.Vector3f; @@ -224,9 +224,9 @@ public Transform getTransform(Long oma, String subtargetName, Space space) { switch (space) { case CONSTRAINT_SPACE_WORLD: Spatial model = (Spatial) blenderContext.getLoadedFeature(targetBoneContext.getSkeletonOwnerOma(), LoadedDataType.FEATURE); - Matrix4f boneModelMatrix = this.toMatrix(bone.getModelSpacePosition(), bone.getModelSpaceRotation(), bone.getModelSpaceScale(), tempVars.tempMat4); - Matrix4f modelWorldMatrix = this.toMatrix(model.getWorldTransform(), tempVars.tempMat42); - Matrix4f boneMatrixInWorldSpace = modelWorldMatrix.multLocal(boneModelMatrix); + Matrixable boneModelMatrix = this.toMatrix(bone.getModelSpacePosition(), bone.getModelSpaceRotation(), bone.getModelSpaceScale(), tempVars.tempMat4); + Matrixable modelWorldMatrix = this.toMatrix(model.getWorldTransform(), tempVars.tempMat42); + Matrixable boneMatrixInWorldSpace = modelWorldMatrix.multLocal(boneModelMatrix); result = new Transform(boneMatrixInWorldSpace.toTranslationVector(), boneMatrixInWorldSpace.toRotationQuat(), boneMatrixInWorldSpace.toScaleVector()); break; case CONSTRAINT_SPACE_LOCAL: @@ -234,16 +234,16 @@ public Transform getTransform(Long oma, String subtargetName, Space space) { result = new Transform(bone.getLocalPosition(), bone.getLocalRotation(), bone.getLocalScale()); break; case CONSTRAINT_SPACE_POSE: { - Matrix4f boneWorldMatrix = this.toMatrix(this.getTransform(oma, subtargetName, Space.CONSTRAINT_SPACE_WORLD), tempVars.tempMat4); - Matrix4f armatureInvertedWorldMatrix = this.toMatrix(feature.getWorldTransform(), tempVars.tempMat42).invertLocal(); - Matrix4f bonePoseMatrix = armatureInvertedWorldMatrix.multLocal(boneWorldMatrix); + Matrixable boneWorldMatrix = this.toMatrix(this.getTransform(oma, subtargetName, Space.CONSTRAINT_SPACE_WORLD), tempVars.tempMat4); + Matrixable armatureInvertedWorldMatrix = this.toMatrix(feature.getWorldTransform(), tempVars.tempMat42).invertLocal(); + Matrixable bonePoseMatrix = armatureInvertedWorldMatrix.multLocal(boneWorldMatrix); result = new Transform(bonePoseMatrix.toTranslationVector(), bonePoseMatrix.toRotationQuat(), bonePoseMatrix.toScaleVector()); break; } case CONSTRAINT_SPACE_PARLOCAL: { - Matrix4f boneWorldMatrix = this.toMatrix(this.getTransform(oma, subtargetName, Space.CONSTRAINT_SPACE_WORLD), tempVars.tempMat4); - Matrix4f armatureInvertedWorldMatrix = this.toMatrix(feature.getWorldTransform(), tempVars.tempMat42).invertLocal(); - Matrix4f bonePoseMatrix = armatureInvertedWorldMatrix.multLocal(boneWorldMatrix); + Matrixable boneWorldMatrix = this.toMatrix(this.getTransform(oma, subtargetName, Space.CONSTRAINT_SPACE_WORLD), tempVars.tempMat4); + Matrixable armatureInvertedWorldMatrix = this.toMatrix(feature.getWorldTransform(), tempVars.tempMat42).invertLocal(); + Matrixable bonePoseMatrix = armatureInvertedWorldMatrix.multLocal(boneWorldMatrix); result = new Transform(bonePoseMatrix.toTranslationVector(), bonePoseMatrix.toRotationQuat(), bonePoseMatrix.toScaleVector()); Bone parent = bone.getParent(); if(parent != null) { @@ -308,48 +308,48 @@ public void applyTransform(Long oma, String subtargetName, Space space, Transfor bone.setBindTransforms(transform.getTranslation(), transform.getRotation(), transform.getScale()); break; case CONSTRAINT_SPACE_WORLD: { - Matrix4f boneMatrixInWorldSpace = this.toMatrix(transform, tempVars.tempMat4); - Matrix4f modelWorldMatrix = this.toMatrix(this.getTransform(targetBoneContext.getSkeletonOwnerOma(), null, Space.CONSTRAINT_SPACE_WORLD), tempVars.tempMat42); - Matrix4f boneMatrixInModelSpace = modelWorldMatrix.invertLocal().multLocal(boneMatrixInWorldSpace); + Matrixable boneMatrixInWorldSpace = this.toMatrix(transform, tempVars.tempMat4); + Matrixable modelWorldMatrix = this.toMatrix(this.getTransform(targetBoneContext.getSkeletonOwnerOma(), null, Space.CONSTRAINT_SPACE_WORLD), tempVars.tempMat42); + Matrixable boneMatrixInModelSpace = modelWorldMatrix.invertLocal().multLocal(boneMatrixInWorldSpace); Bone parent = bone.getParent(); if (parent != null) { - Matrix4f parentMatrixInModelSpace = this.toMatrix(parent.getModelSpacePosition(), parent.getModelSpaceRotation(), parent.getModelSpaceScale(), tempVars.tempMat4); + Matrixable parentMatrixInModelSpace = this.toMatrix(parent.getModelSpacePosition(), parent.getModelSpaceRotation(), parent.getModelSpaceScale(), tempVars.tempMat4); boneMatrixInModelSpace = parentMatrixInModelSpace.invertLocal().multLocal(boneMatrixInModelSpace); } bone.setBindTransforms(boneMatrixInModelSpace.toTranslationVector(), boneMatrixInModelSpace.toRotationQuat(), boneMatrixInModelSpace.toScaleVector()); break; } case CONSTRAINT_SPACE_POSE: { - Matrix4f armatureWorldMatrix = this.toMatrix(feature.getWorldTransform(), tempVars.tempMat4); - Matrix4f boneMatrixInWorldSpace = armatureWorldMatrix.multLocal(this.toMatrix(transform, tempVars.tempMat42)); - Matrix4f invertedModelMatrix = this.toMatrix(this.getTransform(targetBoneContext.getSkeletonOwnerOma(), null, Space.CONSTRAINT_SPACE_WORLD), tempVars.tempMat42).invertLocal(); - Matrix4f boneMatrixInModelSpace = invertedModelMatrix.multLocal(boneMatrixInWorldSpace); + Matrixable armatureWorldMatrix = this.toMatrix(feature.getWorldTransform(), tempVars.tempMat4); + Matrixable boneMatrixInWorldSpace = armatureWorldMatrix.multLocal(this.toMatrix(transform, tempVars.tempMat42)); + Matrixable invertedModelMatrix = this.toMatrix(this.getTransform(targetBoneContext.getSkeletonOwnerOma(), null, Space.CONSTRAINT_SPACE_WORLD), tempVars.tempMat42).invertLocal(); + Matrixable boneMatrixInModelSpace = invertedModelMatrix.multLocal(boneMatrixInWorldSpace); Bone parent = bone.getParent(); if (parent != null) { - Matrix4f parentMatrixInModelSpace = this.toMatrix(parent.getModelSpacePosition(), parent.getModelSpaceRotation(), parent.getModelSpaceScale(), tempVars.tempMat4); + Matrixable parentMatrixInModelSpace = this.toMatrix(parent.getModelSpacePosition(), parent.getModelSpaceRotation(), parent.getModelSpaceScale(), tempVars.tempMat4); boneMatrixInModelSpace = parentMatrixInModelSpace.invertLocal().multLocal(boneMatrixInModelSpace); } bone.setBindTransforms(boneMatrixInModelSpace.toTranslationVector(), boneMatrixInModelSpace.toRotationQuat(), boneMatrixInModelSpace.toScaleVector()); break; } case CONSTRAINT_SPACE_PARLOCAL: - Matrix4f armatureWorldMatrix = this.toMatrix(feature.getWorldTransform(), tempVars.tempMat4); - Matrix4f boneMatrixInWorldSpace = armatureWorldMatrix.multLocal(this.toMatrix(transform, tempVars.tempMat42)); - Matrix4f invertedModelMatrix = this.toMatrix(this.getTransform(targetBoneContext.getSkeletonOwnerOma(), null, Space.CONSTRAINT_SPACE_WORLD), tempVars.tempMat42).invertLocal(); - Matrix4f boneMatrixInModelSpace = invertedModelMatrix.multLocal(boneMatrixInWorldSpace); + Matrixable armatureWorldMatrix = this.toMatrix(feature.getWorldTransform(), tempVars.tempMat4); + Matrixable boneMatrixInWorldSpace = armatureWorldMatrix.multLocal(this.toMatrix(transform, tempVars.tempMat42)); + Matrixable invertedModelMatrix = this.toMatrix(this.getTransform(targetBoneContext.getSkeletonOwnerOma(), null, Space.CONSTRAINT_SPACE_WORLD), tempVars.tempMat42).invertLocal(); + Matrixable boneMatrixInModelSpace = invertedModelMatrix.multLocal(boneMatrixInWorldSpace); Bone parent = bone.getParent(); if (parent != null) { //first add the initial parent matrix to the bone's model matrix BoneContext parentContext = blenderContext.getBoneContext(parent); - Matrix4f initialParentMatrixInModelSpace = parentContext.getBoneMatrixInModelSpace(); - Matrix4f currentParentMatrixInModelSpace = this.toMatrix(parent.getModelSpacePosition(), parent.getModelSpaceRotation(), parent.getModelSpaceScale(), tempVars.tempMat4); + Matrixable initialParentMatrixInModelSpace = parentContext.getBoneMatrixInModelSpace(); + Matrixable currentParentMatrixInModelSpace = this.toMatrix(parent.getModelSpacePosition(), parent.getModelSpaceRotation(), parent.getModelSpaceScale(), tempVars.tempMat4); //the bone will now move with its parent in model space //now we need to subtract the difference between current parent's model matrix and its initial model matrix boneMatrixInModelSpace = initialParentMatrixInModelSpace.mult(boneMatrixInModelSpace); - Matrix4f diffMatrix = initialParentMatrixInModelSpace.mult(currentParentMatrixInModelSpace.invert()); + Matrixable diffMatrix = initialParentMatrixInModelSpace.mult(currentParentMatrixInModelSpace.invert()); boneMatrixInModelSpace.multLocal(diffMatrix); //now the bone will have its position in model space with initial parent's model matrix added } @@ -373,8 +373,8 @@ public void applyTransform(Long oma, String subtargetName, Space space, Transfor Transform parentWorldTransform = feature.getParent().getWorldTransform(); TempVars tempVars = TempVars.get(); - Matrix4f parentInverseMatrix = this.toMatrix(parentWorldTransform, tempVars.tempMat4).invertLocal(); - Matrix4f m = this.toMatrix(transform, tempVars.tempMat42); + Matrixable parentInverseMatrix = this.toMatrix(parentWorldTransform, tempVars.tempMat4).invertLocal(); + Matrixable m = this.toMatrix(transform, tempVars.tempMat42); m = m.multLocal(parentInverseMatrix); tempVars.release(); @@ -400,7 +400,7 @@ public void applyTransform(Long oma, String subtargetName, Space space, Transfor * the matrix where the result will be stored * @return the store matrix */ - public Matrix4f toMatrix(Transform transform, Matrix4f store) { + public Matrixable toMatrix(Transform transform, Matrixable store) { if (transform != null) { return this.toMatrix(transform.getTranslation(), transform.getRotation(), transform.getScale(), store); } @@ -421,7 +421,7 @@ public Matrix4f toMatrix(Transform transform, Matrix4f store) { * the matrix where the result will be stored * @return the store matrix */ - private Matrix4f toMatrix(Vector3f position, Quaternion rotation, Vector3f scale, Matrix4f store) { + private Matrixable toMatrix(Vector3f position, Quaternion rotation, Vector3f scale, Matrixable store) { store.loadIdentity(); store.setTranslation(position); store.setRotationQuaternion(rotation); diff --git a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionTransLike.java b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionTransLike.java index b388572794..d647824ab4 100644 --- a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionTransLike.java +++ b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionTransLike.java @@ -2,7 +2,7 @@ import com.jme3.animation.Bone; import com.jme3.animation.Skeleton; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrixable; import com.jme3.math.Transform; import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.BlenderContext.LoadedDataType; @@ -44,7 +44,7 @@ public void bake(Space ownerSpace, Space targetSpace, Transform targetTransform, ConstraintHelper constraintHelper = blenderContext.getHelper(ConstraintHelper.class); TempVars tempVars = TempVars.get(); - Matrix4f m = constraintHelper.toMatrix(targetTransform, tempVars.tempMat4); + Matrixable m = constraintHelper.toMatrix(targetTransform, tempVars.tempMat4); tempVars.tempMat42.set(BoneContext.BONE_ARMATURE_TRANSFORMATION_MATRIX); if (target instanceof Bone) { tempVars.tempMat42.invertLocal(); diff --git a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/curves/CurvesHelper.java b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/curves/CurvesHelper.java index dd033d3dca..1c05ae82cc 100644 --- a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/curves/CurvesHelper.java +++ b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/curves/CurvesHelper.java @@ -34,7 +34,8 @@ import java.util.logging.Logger; import com.jme3.math.FastMath; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.math.Quaternion; import com.jme3.math.Vector3f; import com.jme3.scene.plugins.blender.AbstractBlenderHelper; @@ -145,7 +146,7 @@ protected Vector3f[] transformToFirstLineOfBevelPoints(Vector3f[] startingLinePo float angle = FastMath.acos(planeNormal.dot(Vector3f.UNIT_X)); Vector3f rotationVector = Vector3f.UNIT_X.cross(planeNormal).normalizeLocal(); - Matrix4f m = new Matrix4f(); + Matrixable m = new Matrix(4); m.setRotationQuaternion(new Quaternion().fromAngleAxis(angle, rotationVector)); m.setTranslation(firstCurvePoint); diff --git a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/modifiers/MirrorModifier.java b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/modifiers/MirrorModifier.java index 36538afc35..41ebce09c8 100644 --- a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/modifiers/MirrorModifier.java +++ b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/modifiers/MirrorModifier.java @@ -4,7 +4,8 @@ import java.util.logging.Level; import java.util.logging.Logger; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.math.Vector3f; import com.jme3.scene.Node; import com.jme3.scene.plugins.blender.BlenderContext; @@ -172,8 +173,8 @@ public void apply(Node node, BlenderContext blenderContext) { * the node * @return the node's world transformation matrix */ - private Matrix4f getWorldMatrix(Node node) { - Matrix4f result = new Matrix4f(); + private Matrixable getWorldMatrix(Node node) { + Matrixable result = new Matrix(4); result.setTranslation(node.getWorldTranslation()); result.setRotationQuaternion(node.getWorldRotation()); result.setScale(node.getWorldScale()); diff --git a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/objects/ObjectHelper.java b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/objects/ObjectHelper.java index 17c0d421e9..9f6fd85d45 100644 --- a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/objects/ObjectHelper.java +++ b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/objects/ObjectHelper.java @@ -42,7 +42,8 @@ import com.jme3.light.Light; import com.jme3.math.FastMath; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.math.Transform; import com.jme3.math.Vector3f; import com.jme3.renderer.Camera; @@ -366,7 +367,7 @@ public boolean isParent(Long supposedParentOMA, Long spatialOMA) { public Transform getTransformation(Structure objectStructure, BlenderContext blenderContext) { TempVars tempVars = TempVars.get(); - Matrix4f parentInv = tempVars.tempMat4; + Matrix parentInv = tempVars.tempMat4; Pointer pParent = (Pointer) objectStructure.getFieldValue("parent"); if (pParent.isNotNull()) { Structure parentObjectStructure = (Structure) blenderContext.getLoadedFeature(pParent.getOldMemoryAddress(), LoadedDataType.STRUCTURE); @@ -375,8 +376,8 @@ public Transform getTransformation(Structure objectStructure, BlenderContext ble parentInv.loadIdentity(); } - Matrix4f globalMatrix = this.getMatrix(objectStructure, "obmat", fixUpAxis, tempVars.tempMat42); - Matrix4f localMatrix = parentInv.multLocal(globalMatrix); + Matrix globalMatrix = this.getMatrix(objectStructure, "obmat", fixUpAxis, tempVars.tempMat42); + Matrixable localMatrix = parentInv.multLocal(globalMatrix); this.getSizeSignums(objectStructure, tempVars.vect1); @@ -439,7 +440,7 @@ private void getSizeSignums(Structure objectStructure, Vector3f store) { * @return the required matrix */ @SuppressWarnings("unchecked") - private Matrix4f getMatrix(Structure structure, String matrixName, boolean fixUpAxis, Matrix4f store) { + private Matrix getMatrix(Structure structure, String matrixName, boolean fixUpAxis, Matrix store) { DynamicArray obmat = (DynamicArray) structure.getFieldValue(matrixName); // the matrix must be square int rowAndColumnSize = Math.abs((int) Math.sqrt(obmat.getTotalSize())); @@ -468,16 +469,16 @@ private Matrix4f getMatrix(Structure structure, String matrixName, boolean fixUp } // multiply the values in the third row by -1 - store.m20 *= -1; - store.m21 *= -1; - store.m22 *= -1; - store.m23 *= -1; + store.getMatrix()[2][0] *= -1; + store.getMatrix()[2][1] *= -1; + store.getMatrix()[2][2] *= -1; + store.getMatrix()[2][3] *= -1; // multiply the values in the third column by -1 - store.m02 *= -1; - store.m12 *= -1; - store.m22 *= -1; - store.m32 *= -1; + store.getMatrix()[0][2] *= -1; + store.getMatrix()[1][2] *= -1; + store.getMatrix()[2][2] *= -1; + store.getMatrix()[3][2] *= -1; } return store; @@ -495,8 +496,8 @@ private Matrix4f getMatrix(Structure structure, String matrixName, boolean fixUp * tells if the Y axis is a UP axis * @return the required matrix */ - public Matrix4f getMatrix(Structure structure, String matrixName, boolean fixUpAxis) { - return this.getMatrix(structure, matrixName, fixUpAxis, new Matrix4f()); + public Matrix getMatrix(Structure structure, String matrixName, boolean fixUpAxis) { + return this.getMatrix(structure, matrixName, fixUpAxis, new Matrix(4)); } private static enum ObjectType { diff --git a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/particles/ParticlesHelper.java b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/particles/ParticlesHelper.java index 85c093f664..56d7ad05d6 100644 --- a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/particles/ParticlesHelper.java +++ b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/particles/ParticlesHelper.java @@ -1,7 +1,7 @@ package com.jme3.scene.plugins.blender.particles; import com.jme3.effect.ParticleEmitter; -import com.jme3.effect.ParticleMesh.Type; +import com.jme3.effect.ParticleTriMesh; import com.jme3.effect.influencers.EmptyParticleInfluencer; import com.jme3.effect.influencers.NewtonianParticleInfluencer; import com.jme3.effect.influencers.ParticleInfluencer; @@ -125,7 +125,7 @@ public ParticleEmitter toParticleEmitter(Structure particleSystem) throws Blende default:// all others are rendered as points in blender nameSuffix = 'P'; } - result = new ParticleEmitter(particleSettings.getName() + nameSuffix, Type.Triangle, totPart); + result = new ParticleEmitter(particleSettings.getName() + nameSuffix, new ParticleTriMesh(), totPart); if (nameSuffix == 'N') { return result;// no need to set anything else } diff --git a/jme3-bullet/src/common/java/com/jme3/bullet/collision/shapes/infos/ChildCollisionShape.java b/jme3-bullet/src/common/java/com/jme3/bullet/collision/shapes/infos/ChildCollisionShape.java index ac71962585..111f9cea43 100644 --- a/jme3-bullet/src/common/java/com/jme3/bullet/collision/shapes/infos/ChildCollisionShape.java +++ b/jme3-bullet/src/common/java/com/jme3/bullet/collision/shapes/infos/ChildCollisionShape.java @@ -34,7 +34,8 @@ import com.jme3.bullet.collision.shapes.BoxCollisionShape; import com.jme3.bullet.collision.shapes.CollisionShape; import com.jme3.export.*; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.math.Vector3f; import java.io.IOException; @@ -45,13 +46,13 @@ public class ChildCollisionShape implements Savable { public Vector3f location; - public Matrix3f rotation; + public Matrixable rotation; public CollisionShape shape; public ChildCollisionShape() { } - public ChildCollisionShape(Vector3f location, Matrix3f rotation, CollisionShape shape) { + public ChildCollisionShape(Vector3f location, Matrixable rotation, CollisionShape shape) { this.location = location; this.rotation = rotation; this.shape = shape; @@ -60,14 +61,14 @@ public ChildCollisionShape(Vector3f location, Matrix3f rotation, CollisionShape public void write(JmeExporter ex) throws IOException { OutputCapsule capsule = ex.getCapsule(this); capsule.write(location, "location", new Vector3f()); - capsule.write(rotation, "rotation", new Matrix3f()); + capsule.write(rotation, "rotation", new Matrix(3)); capsule.write(shape, "shape", new BoxCollisionShape(new Vector3f(1, 1, 1))); } public void read(JmeImporter im) throws IOException { InputCapsule capsule = im.getCapsule(this); location = (Vector3f) capsule.readSavable("location", new Vector3f()); - rotation = (Matrix3f) capsule.readSavable("rotation", new Matrix3f()); + rotation = (Matrixable) capsule.readSavable("rotation", new Matrix(3)); shape = (CollisionShape) capsule.readSavable("shape", new BoxCollisionShape(new Vector3f(1, 1, 1))); } } diff --git a/jme3-bullet/src/common/java/com/jme3/bullet/util/CollisionShapeFactory.java b/jme3-bullet/src/common/java/com/jme3/bullet/util/CollisionShapeFactory.java index de28aba02d..be63d4636f 100644 --- a/jme3-bullet/src/common/java/com/jme3/bullet/util/CollisionShapeFactory.java +++ b/jme3-bullet/src/common/java/com/jme3/bullet/util/CollisionShapeFactory.java @@ -31,17 +31,27 @@ */ package com.jme3.bullet.util; +import java.util.Iterator; +import java.util.LinkedList; + import com.jme3.bounding.BoundingBox; -import com.jme3.bullet.collision.shapes.*; +import com.jme3.bullet.collision.shapes.BoxCollisionShape; +import com.jme3.bullet.collision.shapes.CollisionShape; +import com.jme3.bullet.collision.shapes.CompoundCollisionShape; +import com.jme3.bullet.collision.shapes.HeightfieldCollisionShape; +import com.jme3.bullet.collision.shapes.HullCollisionShape; +import com.jme3.bullet.collision.shapes.MeshCollisionShape; import com.jme3.bullet.collision.shapes.infos.ChildCollisionShape; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrixable; import com.jme3.math.Transform; import com.jme3.math.Vector3f; -import com.jme3.scene.*; +import com.jme3.scene.Geometry; +import com.jme3.scene.Mesh; +import com.jme3.scene.Node; +import com.jme3.scene.Spatial; +import com.jme3.scene.UserData; import com.jme3.terrain.geomipmap.TerrainPatch; import com.jme3.terrain.geomipmap.TerrainQuad; -import java.util.Iterator; -import java.util.LinkedList; /** * @@ -255,7 +265,7 @@ public static void shiftCompoundShapeContents(CompoundCollisionShape compoundSha ChildCollisionShape childCollisionShape = it.next(); CollisionShape child = childCollisionShape.shape; Vector3f location = childCollisionShape.location; - Matrix3f rotation = childCollisionShape.rotation; + Matrixable rotation = childCollisionShape.rotation; compoundShape.removeChildShape(child); compoundShape.addChildShape(child, location.add(vector), rotation); } diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/CompoundCollisionShape.java b/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/CompoundCollisionShape.java index 9faf7f68bc..2c26591d50 100644 --- a/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/CompoundCollisionShape.java +++ b/jme3-bullet/src/main/java/com/jme3/bullet/collision/shapes/CompoundCollisionShape.java @@ -36,7 +36,8 @@ import com.jme3.export.JmeExporter; import com.jme3.export.JmeImporter; import com.jme3.export.OutputCapsule; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.math.Vector3f; import java.io.IOException; import java.util.ArrayList; @@ -69,7 +70,7 @@ public void addChildShape(CollisionShape shape, Vector3f location) { // Converter.convert(location, transA.origin); // children.add(new ChildCollisionShape(location.clone(), new Matrix3f(), shape)); // ((CompoundShape) objectId).addChildShape(transA, shape.getObjectId()); - addChildShape(shape, location, new Matrix3f()); + addChildShape(shape, location, new Matrix(3)); } /** @@ -77,7 +78,7 @@ public void addChildShape(CollisionShape shape, Vector3f location) { * @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) { + public void addChildShape(CollisionShape shape, Vector3f location, Matrixable rotation) { if(shape instanceof CompoundCollisionShape){ throw new IllegalStateException("CompoundCollisionShapes cannot have CompoundCollisionShapes as children!"); } @@ -89,7 +90,7 @@ public void addChildShape(CollisionShape shape, Vector3f location, Matrix3f rota // ((CompoundShape) objectId).addChildShape(transA, shape.getObjectId()); } - private void addChildShapeDirect(CollisionShape shape, Vector3f location, Matrix3f rotation) { + private void addChildShapeDirect(CollisionShape shape, Vector3f location, Matrixable rotation) { if(shape instanceof CompoundCollisionShape){ throw new IllegalStateException("CompoundCollisionShapes cannot have CompoundCollisionShapes as children!"); } @@ -129,7 +130,7 @@ public void setScale(Vector3f scale) { private native long createShape(); - private native long addChildShape(long objectId, long childId, Vector3f location, Matrix3f rotation); + private native long addChildShape(long objectId, long childId, Vector3f location, Matrixable rotation); private native long removeChildShape(long objectId, long childId); diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/joints/ConeJoint.java b/jme3-bullet/src/main/java/com/jme3/bullet/joints/ConeJoint.java index 4284e7ad3c..e7cc9b99e7 100644 --- a/jme3-bullet/src/main/java/com/jme3/bullet/joints/ConeJoint.java +++ b/jme3-bullet/src/main/java/com/jme3/bullet/joints/ConeJoint.java @@ -36,7 +36,8 @@ import com.jme3.export.JmeExporter; import com.jme3.export.JmeImporter; import com.jme3.export.OutputCapsule; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.math.Vector3f; import java.io.IOException; import java.util.logging.Level; @@ -51,7 +52,7 @@ */ public class ConeJoint extends PhysicsJoint { - protected Matrix3f rotA, rotB; + protected Matrix rotA, rotB; protected float swingSpan1 = 1e30f; protected float swingSpan2 = 1e30f; protected float twistSpan = 1e30f; @@ -66,8 +67,8 @@ public ConeJoint() { */ public ConeJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB) { super(nodeA, nodeB, pivotA, pivotB); - this.rotA = new Matrix3f(); - this.rotB = new Matrix3f(); + this.rotA = new Matrix(3); + this.rotB = new Matrix(3); createJoint(); } @@ -75,7 +76,7 @@ public ConeJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA * @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 ConeJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, Matrix3f rotA, Matrix3f rotB) { + public ConeJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, Matrix rotA, Matrix rotB) { super(nodeA, nodeB, pivotA, pivotB); this.rotA = rotA; this.rotB = rotB; @@ -102,8 +103,8 @@ public void setAngularOnly(boolean value) { public void write(JmeExporter ex) throws IOException { super.write(ex); OutputCapsule capsule = ex.getCapsule(this); - capsule.write(rotA, "rotA", new Matrix3f()); - capsule.write(rotB, "rotB", new Matrix3f()); + capsule.write(rotA, "rotA", new Matrix(3)); + capsule.write(rotB, "rotB", new Matrix(3)); capsule.write(angularOnly, "angularOnly", false); capsule.write(swingSpan1, "swingSpan1", 1e30f); @@ -115,8 +116,8 @@ public void write(JmeExporter ex) throws IOException { public void read(JmeImporter im) throws IOException { super.read(im); InputCapsule capsule = im.getCapsule(this); - this.rotA = (Matrix3f) capsule.readSavable("rotA", new Matrix3f()); - this.rotB = (Matrix3f) capsule.readSavable("rotB", new Matrix3f()); + this.rotA = (Matrix) capsule.readSavable("rotA", new Matrix(3)); + this.rotB = (Matrix) capsule.readSavable("rotB", new Matrix(3)); this.angularOnly = capsule.readBoolean("angularOnly", false); this.swingSpan1 = capsule.readFloat("swingSpan1", 1e30f); @@ -132,5 +133,5 @@ protected void createJoint() { setAngularOnly(objectId, angularOnly); } - private native long createJoint(long objectIdA, long objectIdB, Vector3f pivotA, Matrix3f rotA, Vector3f pivotB, Matrix3f rotB); + private native long createJoint(long objectIdA, long objectIdB, Vector3f pivotA, Matrixable rotA, Vector3f pivotB, Matrixable rotB); } diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/joints/SixDofJoint.java b/jme3-bullet/src/main/java/com/jme3/bullet/joints/SixDofJoint.java index 648398149d..f604b314e1 100644 --- a/jme3-bullet/src/main/java/com/jme3/bullet/joints/SixDofJoint.java +++ b/jme3-bullet/src/main/java/com/jme3/bullet/joints/SixDofJoint.java @@ -38,7 +38,8 @@ import com.jme3.export.JmeExporter; import com.jme3.export.JmeImporter; import com.jme3.export.OutputCapsule; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.math.Vector3f; import java.io.IOException; import java.util.Iterator; @@ -59,7 +60,7 @@ */ public class SixDofJoint extends PhysicsJoint { - Matrix3f rotA, rotB; + Matrixable rotA, rotB; boolean useLinearReferenceFrameA; LinkedList rotationalMotors = new LinkedList(); TranslationalLimitMotor translationalMotor; @@ -75,7 +76,7 @@ public SixDofJoint() { * @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) { + public SixDofJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, Matrixable rotA, Matrixable rotB, boolean useLinearReferenceFrameA) { super(nodeA, nodeB, pivotA, pivotB); this.useLinearReferenceFrameA = useLinearReferenceFrameA; this.rotA = rotA; @@ -93,8 +94,8 @@ public SixDofJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivo public SixDofJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, boolean useLinearReferenceFrameA) { super(nodeA, nodeB, pivotA, pivotB); this.useLinearReferenceFrameA = useLinearReferenceFrameA; - rotA = new Matrix3f(); - rotB = new Matrix3f(); + rotA = new Matrix(3); + rotB = new Matrix(3); objectId = createJoint(nodeA.getObjectId(), nodeB.getObjectId(), pivotA, rotA, pivotB, rotB, useLinearReferenceFrameA); Logger.getLogger(this.getClass().getName()).log(Level.FINE, "Created Joint {0}", Long.toHexString(objectId)); @@ -160,7 +161,7 @@ public void setAngularLowerLimit(Vector3f vector) { private native void setAngularLowerLimit(long objctId, Vector3f vector); - native long createJoint(long objectIdA, long objectIdB, Vector3f pivotA, Matrix3f rotA, Vector3f pivotB, Matrix3f rotB, boolean useLinearReferenceFrameA); + native long createJoint(long objectIdA, long objectIdB, Vector3f pivotA, Matrixable rotA, Vector3f pivotB, Matrixable rotB, boolean useLinearReferenceFrameA); @Override public void read(JmeImporter im) throws IOException { diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/joints/SixDofSpringJoint.java b/jme3-bullet/src/main/java/com/jme3/bullet/joints/SixDofSpringJoint.java index e52f9836c7..62d89d297d 100644 --- a/jme3-bullet/src/main/java/com/jme3/bullet/joints/SixDofSpringJoint.java +++ b/jme3-bullet/src/main/java/com/jme3/bullet/joints/SixDofSpringJoint.java @@ -32,7 +32,7 @@ package com.jme3.bullet.joints; import com.jme3.bullet.objects.PhysicsRigidBody; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrixable; import com.jme3.math.Vector3f; /** @@ -60,7 +60,7 @@ public SixDofSpringJoint() { * @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 SixDofSpringJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, Matrix3f rotA, Matrix3f rotB, boolean useLinearReferenceFrameA) { + public SixDofSpringJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, Matrixable rotA, Matrixable rotB, boolean useLinearReferenceFrameA) { super(nodeA, nodeB, pivotA, pivotB, rotA, rotB, useLinearReferenceFrameA); } public void enableSpring(int index, boolean onOff) { @@ -87,6 +87,6 @@ public void setEquilibriumPoint(int index){ // set the current constraint positi } native void setEquilibriumPoint(long objctId, int index); @Override - native long createJoint(long objectIdA, long objectIdB, Vector3f pivotA, Matrix3f rotA, Vector3f pivotB, Matrix3f rotB, boolean useLinearReferenceFrameA); + native long createJoint(long objectIdA, long objectIdB, Vector3f pivotA, Matrixable rotA, Vector3f pivotB, Matrixable rotB, boolean useLinearReferenceFrameA); } diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/joints/SliderJoint.java b/jme3-bullet/src/main/java/com/jme3/bullet/joints/SliderJoint.java index b51c5d849b..a8ff2ebdbc 100644 --- a/jme3-bullet/src/main/java/com/jme3/bullet/joints/SliderJoint.java +++ b/jme3-bullet/src/main/java/com/jme3/bullet/joints/SliderJoint.java @@ -36,7 +36,8 @@ import com.jme3.export.JmeExporter; import com.jme3.export.JmeImporter; import com.jme3.export.OutputCapsule; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.math.Vector3f; import java.io.IOException; import java.util.logging.Level; @@ -49,7 +50,7 @@ */ public class SliderJoint extends PhysicsJoint { - protected Matrix3f rotA, rotB; + protected Matrixable rotA, rotB; protected boolean useLinearReferenceFrameA; public SliderJoint() { @@ -59,7 +60,7 @@ public SliderJoint() { * @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 SliderJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, Matrix3f rotA, Matrix3f rotB, boolean useLinearReferenceFrameA) { + public SliderJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, Matrixable rotA, Matrixable rotB, boolean useLinearReferenceFrameA) { super(nodeA, nodeB, pivotA, pivotB); this.rotA = rotA; this.rotB = rotB; @@ -73,8 +74,8 @@ public SliderJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivo */ public SliderJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, boolean useLinearReferenceFrameA) { super(nodeA, nodeB, pivotA, pivotB); - this.rotA = new Matrix3f(); - this.rotB = new Matrix3f(); + this.rotA = new Matrix(3); + this.rotB = new Matrix(3); this.useLinearReferenceFrameA = useLinearReferenceFrameA; createJoint(); } @@ -534,5 +535,5 @@ protected void createJoint() { // = new SliderConstraint(nodeA.getObjectId(), nodeB.getObjectId(), transA, transB, useLinearReferenceFrameA); } - private native long createJoint(long objectIdA, long objectIdB, Vector3f pivotA, Matrix3f rotA, Vector3f pivotB, Matrix3f rotB, boolean useLinearReferenceFrameA); + private native long createJoint(long objectIdA, long objectIdB, Vector3f pivotA, Matrixable rotA, Vector3f pivotB, Matrixable rotB, boolean useLinearReferenceFrameA); } diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsGhostObject.java b/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsGhostObject.java index 052e280e43..5b3dc1395b 100644 --- a/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsGhostObject.java +++ b/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsGhostObject.java @@ -37,7 +37,8 @@ import com.jme3.export.JmeExporter; import com.jme3.export.JmeImporter; import com.jme3.export.OutputCapsule; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.math.Quaternion; import com.jme3.math.Vector3f; import com.jme3.scene.Spatial; @@ -117,11 +118,11 @@ public void setPhysicsLocation(Vector3f location) { * Sets the physics object rotation * @param rotation the rotation of the actual physics object */ - public void setPhysicsRotation(Matrix3f rotation) { + public void setPhysicsRotation(Matrixable rotation) { setPhysicsRotation(objectId, rotation); } - private native void setPhysicsRotation(long objectId, Matrix3f rotation); + private native void setPhysicsRotation(long objectId, Matrixable rotation); /** * Sets the physics object rotation @@ -162,15 +163,15 @@ public Quaternion getPhysicsRotation(Quaternion rot) { /** * @return the physicsLocation */ - public Matrix3f getPhysicsRotationMatrix(Matrix3f rot) { + public Matrix getPhysicsRotationMatrix(Matrix rot) { if (rot == null) { - rot = new Matrix3f(); + rot = new Matrix(3); } getPhysicsRotationMatrix(objectId, rot); return rot; } - private native void getPhysicsRotationMatrix(long objectId, Matrix3f rot); + private native void getPhysicsRotationMatrix(long objectId, Matrixable rot); /** * @return the physicsLocation @@ -190,8 +191,8 @@ public Quaternion getPhysicsRotation() { return quat; } - public Matrix3f getPhysicsRotationMatrix() { - Matrix3f mtx = new Matrix3f(); + public Matrixable getPhysicsRotationMatrix() { + Matrixable mtx = new Matrix(3); getPhysicsRotationMatrix(objectId, mtx); return mtx; } @@ -283,7 +284,7 @@ public void write(JmeExporter e) throws IOException { super.write(e); OutputCapsule capsule = e.getCapsule(this); capsule.write(getPhysicsLocation(new Vector3f()), "physicsLocation", new Vector3f()); - capsule.write(getPhysicsRotationMatrix(new Matrix3f()), "physicsRotation", new Matrix3f()); + capsule.write(getPhysicsRotationMatrix(new Matrix(3)), "physicsRotation", new Matrix(3)); capsule.write(getCcdMotionThreshold(), "ccdMotionThreshold", 0); capsule.write(getCcdSweptSphereRadius(), "ccdSweptSphereRadius", 0); } @@ -294,7 +295,7 @@ public void read(JmeImporter e) throws IOException { InputCapsule capsule = e.getCapsule(this); buildObject(); setPhysicsLocation((Vector3f) capsule.readSavable("physicsLocation", new Vector3f())); - setPhysicsRotation(((Matrix3f) capsule.readSavable("physicsRotation", new Matrix3f()))); + setPhysicsRotation(((Matrixable) capsule.readSavable("physicsRotation", new Matrix(3)))); setCcdMotionThreshold(capsule.readFloat("ccdMotionThreshold", 0)); setCcdSweptSphereRadius(capsule.readFloat("ccdSweptSphereRadius", 0)); } diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java b/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java index 0342f4c772..1abf1be024 100644 --- a/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java +++ b/jme3-bullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java @@ -41,7 +41,8 @@ import com.jme3.export.JmeExporter; import com.jme3.export.JmeImporter; import com.jme3.export.OutputCapsule; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.math.Quaternion; import com.jme3.math.Vector3f; import java.io.IOException; @@ -146,11 +147,11 @@ public void setPhysicsLocation(Vector3f location) { * Sets the physics object rotation * @param rotation the rotation of the actual physics object */ - public void setPhysicsRotation(Matrix3f rotation) { + public void setPhysicsRotation(Matrixable rotation) { setPhysicsRotation(objectId, rotation); } - private native void setPhysicsRotation(long objectId, Matrix3f rotation); + private native void setPhysicsRotation(long objectId, Matrixable rotation); /** * Sets the physics object rotation @@ -191,15 +192,15 @@ public Quaternion getPhysicsRotation(Quaternion rot) { /** * @return the physicsLocation */ - public Matrix3f getPhysicsRotationMatrix(Matrix3f rot) { + public Matrix getPhysicsRotationMatrix(Matrix rot) { if (rot == null) { - rot = new Matrix3f(); + rot = new Matrix(3); } getPhysicsRotationMatrix(objectId, rot); return rot; } - private native void getPhysicsRotationMatrix(long objectId, Matrix3f rot); + private native void getPhysicsRotationMatrix(long objectId, Matrixable rot); /** * @return the physicsLocation @@ -219,8 +220,8 @@ public Quaternion getPhysicsRotation() { return quat; } - public Matrix3f getPhysicsRotationMatrix() { - Matrix3f mtx = new Matrix3f(); + public Matrixable getPhysicsRotationMatrix() { + Matrixable mtx = new Matrix(3); getPhysicsRotationMatrix(objectId, mtx); return mtx; } @@ -719,7 +720,7 @@ public void write(JmeExporter e) throws IOException { capsule.write(getCcdSweptSphereRadius(), "ccdSweptSphereRadius", 0); capsule.write(getPhysicsLocation(new Vector3f()), "physicsLocation", new Vector3f()); - capsule.write(getPhysicsRotationMatrix(new Matrix3f()), "physicsRotation", new Matrix3f()); + capsule.write(getPhysicsRotationMatrix(new Matrix(3)), "physicsRotation", new Matrix(3)); capsule.writeSavableArrayList(joints, "joints", null); } @@ -750,7 +751,7 @@ public void read(JmeImporter e) throws IOException { setCcdSweptSphereRadius(capsule.readFloat("ccdSweptSphereRadius", 0)); setPhysicsLocation((Vector3f) capsule.readSavable("physicsLocation", new Vector3f())); - setPhysicsRotation((Matrix3f) capsule.readSavable("physicsRotation", new Matrix3f())); + setPhysicsRotation((Matrixable) capsule.readSavable("physicsRotation", new Matrix(3))); joints = capsule.readSavableArrayList("joints", null); } diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/objects/VehicleWheel.java b/jme3-bullet/src/main/java/com/jme3/bullet/objects/VehicleWheel.java index 1e86cc2566..eaae2cc8a3 100644 --- a/jme3-bullet/src/main/java/com/jme3/bullet/objects/VehicleWheel.java +++ b/jme3-bullet/src/main/java/com/jme3/bullet/objects/VehicleWheel.java @@ -33,7 +33,8 @@ import com.jme3.bullet.collision.PhysicsCollisionObject; import com.jme3.export.*; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.math.Quaternion; import com.jme3.math.Vector3f; import com.jme3.scene.Spatial; @@ -63,7 +64,7 @@ public class VehicleWheel implements Savable { protected Vector3f wheelWorldLocation = new Vector3f(); protected Quaternion wheelWorldRotation = new Quaternion(); protected Spatial wheelSpatial; - protected Matrix3f tmp_Matrix = new com.jme3.math.Matrix3f(); + protected Matrix tmp_Matrix = new Matrix(3); protected final Quaternion tmp_inverseWorldRotation = new Quaternion(); private boolean applyLocal = false; @@ -94,7 +95,7 @@ public void updatePhysicsState() { private native void getWheelLocation(long vehicleId, int wheelId, Vector3f location); - private native void getWheelRotation(long vehicleId, int wheelId, Matrix3f location); + private native void getWheelRotation(long vehicleId, int wheelId, Matrixable location); public void applyWheelTransform() { if (wheelSpatial == null) { diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/objects/infos/RigidBodyMotionState.java b/jme3-bullet/src/main/java/com/jme3/bullet/objects/infos/RigidBodyMotionState.java index 3406e7ae5c..3120b55cf6 100644 --- a/jme3-bullet/src/main/java/com/jme3/bullet/objects/infos/RigidBodyMotionState.java +++ b/jme3-bullet/src/main/java/com/jme3/bullet/objects/infos/RigidBodyMotionState.java @@ -32,7 +32,8 @@ package com.jme3.bullet.objects.infos; import com.jme3.bullet.objects.PhysicsVehicle; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.math.Quaternion; import com.jme3.math.Vector3f; import com.jme3.scene.Spatial; @@ -47,7 +48,7 @@ public class RigidBodyMotionState { long motionStateId = 0; private Vector3f worldLocation = new Vector3f(); - private Matrix3f worldRotation = new Matrix3f(); + private Matrix worldRotation = new Matrix(3); private Quaternion worldRotationQuat = new Quaternion(); private Quaternion tmp_inverseWorldRotation = new Quaternion(); private PhysicsVehicle vehicle; @@ -109,12 +110,12 @@ public Vector3f getWorldLocation() { /** * @return the worldRotation */ - public Matrix3f getWorldRotation() { + public Matrixable getWorldRotation() { getWorldRotation(motionStateId, worldRotation); return worldRotation; } - private native void getWorldRotation(long stateId, Matrix3f vec); + private native void getWorldRotation(long stateId, Matrixable vec); /** * @return the worldRotationQuat diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/util/DebugShapeFactory.java b/jme3-bullet/src/main/java/com/jme3/bullet/util/DebugShapeFactory.java index c731035ca0..84a5ff2609 100644 --- a/jme3-bullet/src/main/java/com/jme3/bullet/util/DebugShapeFactory.java +++ b/jme3-bullet/src/main/java/com/jme3/bullet/util/DebugShapeFactory.java @@ -34,7 +34,7 @@ import com.jme3.bullet.collision.shapes.CollisionShape; import com.jme3.bullet.collision.shapes.CompoundCollisionShape; import com.jme3.bullet.collision.shapes.infos.ChildCollisionShape; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrixable; import com.jme3.scene.Geometry; import com.jme3.scene.Mesh; import com.jme3.scene.Node; @@ -80,7 +80,7 @@ public static Spatial getDebugShape(CollisionShape collisionShape) { // apply rotation TempVars vars = TempVars.get(); - Matrix3f tempRot = vars.tempMat3; + Matrixable tempRot = vars.tempMat3; tempRot.set(geometry.getLocalRotation()); childCollisionShape.rotation.mult(tempRot, tempRot); diff --git a/jme3-core/src/main/java/com/jme3/animation/Bone.java b/jme3-core/src/main/java/com/jme3/animation/Bone.java index fcbacb337c..6538b7ab2e 100644 --- a/jme3-core/src/main/java/com/jme3/animation/Bone.java +++ b/jme3-core/src/main/java/com/jme3/animation/Bone.java @@ -537,7 +537,7 @@ final void reset() { * * @param outTransform */ - void getOffsetTransform(Matrix4f outTransform, Quaternion tmp1, Vector3f tmp2, Vector3f tmp3, Matrix3f tmp4) { + void getOffsetTransform(Matrixable outTransform, Quaternion tmp1, Vector3f tmp2, Vector3f tmp3, Matrix tmp4) { // Computing scale Vector3f scale = modelScale.mult(modelBindInverseScale, tmp3); diff --git a/jme3-core/src/main/java/com/jme3/animation/Skeleton.java b/jme3-core/src/main/java/com/jme3/animation/Skeleton.java index b0d3419d87..f43c8d86ec 100644 --- a/jme3-core/src/main/java/com/jme3/animation/Skeleton.java +++ b/jme3-core/src/main/java/com/jme3/animation/Skeleton.java @@ -32,7 +32,8 @@ package com.jme3.animation; import com.jme3.export.*; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.util.TempVars; import java.io.IOException; import java.util.ArrayList; @@ -54,7 +55,7 @@ public final class Skeleton implements Savable { * Contains the skinning matrices, multiplying it by a vertex effected by a bone * will cause it to go to the animated position. */ - private transient Matrix4f[] skinningMatrixes; + private transient Matrixable[] skinningMatrixes; /** * Creates a skeleton from a bone list. @@ -119,9 +120,9 @@ public Skeleton() { } private void createSkinningMatrices() { - skinningMatrixes = new Matrix4f[boneList.length]; + skinningMatrixes = new Matrixable[boneList.length]; for (int i = 0; i < skinningMatrixes.length; i++) { - skinningMatrixes[i] = new Matrix4f(); + skinningMatrixes[i] = new Matrix(4); } } @@ -243,7 +244,7 @@ public int getBoneIndex(String name) { * Compute the skining matrices for each bone of the skeleton that would be used to transform vertices of associated meshes * @return */ - public Matrix4f[] computeSkinningMatrices() { + public Matrixable[] computeSkinningMatrices() { TempVars vars = TempVars.get(); for (int i = 0; i < boneList.length; i++) { boneList[i].getOffsetTransform(skinningMatrixes[i], vars.quat1, vars.vect1, vars.vect2, vars.tempMat3); diff --git a/jme3-core/src/main/java/com/jme3/animation/SkeletonControl.java b/jme3-core/src/main/java/com/jme3/animation/SkeletonControl.java index b1f3d02df5..c7286d8d0f 100644 --- a/jme3-core/src/main/java/com/jme3/animation/SkeletonControl.java +++ b/jme3-core/src/main/java/com/jme3/animation/SkeletonControl.java @@ -35,7 +35,7 @@ import com.jme3.material.MatParam; import com.jme3.material.Material; import com.jme3.math.FastMath; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrixable; import com.jme3.renderer.RenderManager; import com.jme3.renderer.RendererException; import com.jme3.renderer.ViewPort; @@ -104,7 +104,7 @@ public class SkeletonControl extends AbstractControl implements Cloneable { /** * Bone offset matrices, recreated each frame */ - private transient Matrix4f[] offsetMatrices; + private transient Matrixable[] offsetMatrices; /** * Material references used for hardware skinning */ @@ -427,7 +427,7 @@ public Mesh[] getTargets() { * @param mesh then mesh * @param offsetMatrices the transformation matrices to apply */ - private void softwareSkinUpdate(Mesh mesh, Matrix4f[] offsetMatrices) { + private void softwareSkinUpdate(Mesh mesh, Matrixable[] offsetMatrices) { VertexBuffer tb = mesh.getBuffer(Type.Tangent); if (tb == null) { @@ -447,7 +447,7 @@ private void softwareSkinUpdate(Mesh mesh, Matrix4f[] offsetMatrices) { * @param mesh the mesh * @param offsetMatrices the offset matices to apply */ - private void applySkinning(Mesh mesh, Matrix4f[] offsetMatrices) { + private void applySkinning(Mesh mesh, Matrixable[] offsetMatrices) { int maxWeightsPerVert = mesh.getMaxNumWeights(); if (maxWeightsPerVert <= 0) { throw new IllegalStateException("Max weights per vert is incorrectly set!"); @@ -511,15 +511,15 @@ private void applySkinning(Mesh mesh, Matrix4f[] offsetMatrices) { for (int w = maxWeightsPerVert - 1; w >= 0; w--) { float weight = weights[idxWeights]; - Matrix4f mat = offsetMatrices[indices[idxWeights++] & 0xff]; + Matrixable mat = offsetMatrices[indices[idxWeights++] & 0xff]; - rx += (mat.m00 * vtx + mat.m01 * vty + mat.m02 * vtz + mat.m03) * weight; - ry += (mat.m10 * vtx + mat.m11 * vty + mat.m12 * vtz + mat.m13) * weight; - rz += (mat.m20 * vtx + mat.m21 * vty + mat.m22 * vtz + mat.m23) * weight; + rx += (mat.getMatrix()[0][0] * vtx + mat.getMatrix()[0][1] * vty + mat.getMatrix()[0][2] * vtz + mat.getMatrix()[0][3]) * weight; + ry += (mat.getMatrix()[1][0] * vtx + mat.getMatrix()[1][1] * vty + mat.getMatrix()[1][2] * vtz + mat.getMatrix()[1][3]) * weight; + rz += (mat.getMatrix()[2][0] * vtx + mat.getMatrix()[2][1] * vty + mat.getMatrix()[2][2] * vtz + mat.getMatrix()[2][3]) * weight; - rnx += (nmx * mat.m00 + nmy * mat.m01 + nmz * mat.m02) * weight; - rny += (nmx * mat.m10 + nmy * mat.m11 + nmz * mat.m12) * weight; - rnz += (nmx * mat.m20 + nmy * mat.m21 + nmz * mat.m22) * weight; + rnx += (nmx * mat.getMatrix()[0][0] + nmy * mat.getMatrix()[0][1] + nmz * mat.getMatrix()[0][2]) * weight; + rny += (nmx * mat.getMatrix()[1][0] + nmy * mat.getMatrix()[1][1] + nmz * mat.getMatrix()[1][2]) * weight; + rnz += (nmx * mat.getMatrix()[2][0] + nmy * mat.getMatrix()[2][1] + nmz * mat.getMatrix()[2][2]) * weight; } idxWeights += fourMinusMaxWeights; @@ -558,7 +558,7 @@ private void applySkinning(Mesh mesh, Matrix4f[] offsetMatrices) { * @param offsetMatrices the offsetMaytrices to apply * @param tb the tangent vertexBuffer */ - private void applySkinningTangents(Mesh mesh, Matrix4f[] offsetMatrices, VertexBuffer tb) { + private void applySkinningTangents(Mesh mesh, Matrixable[] offsetMatrices, VertexBuffer tb) { int maxWeightsPerVert = mesh.getMaxNumWeights(); if (maxWeightsPerVert <= 0) { @@ -644,19 +644,19 @@ private void applySkinningTangents(Mesh mesh, Matrix4f[] offsetMatrices, VertexB for (int w = maxWeightsPerVert - 1; w >= 0; w--) { float weight = weights[idxWeights]; - Matrix4f mat = offsetMatrices[indices[idxWeights++] & 0xff]; + Matrixable mat = offsetMatrices[indices[idxWeights++] & 0xff]; - rx += (mat.m00 * vtx + mat.m01 * vty + mat.m02 * vtz + mat.m03) * weight; - ry += (mat.m10 * vtx + mat.m11 * vty + mat.m12 * vtz + mat.m13) * weight; - rz += (mat.m20 * vtx + mat.m21 * vty + mat.m22 * vtz + mat.m23) * weight; + rx += (mat.getMatrix()[0][0] * vtx + mat.getMatrix()[0][1] * vty + mat.getMatrix()[0][2] * vtz + mat.getMatrix()[0][3]) * weight; + ry += (mat.getMatrix()[1][0] * vtx + mat.getMatrix()[1][1] * vty + mat.getMatrix()[1][2] * vtz + mat.getMatrix()[1][3]) * weight; + rz += (mat.getMatrix()[2][0] * vtx + mat.getMatrix()[2][1] * vty + mat.getMatrix()[2][2] * vtz + mat.getMatrix()[2][3]) * weight; - rnx += (nmx * mat.m00 + nmy * mat.m01 + nmz * mat.m02) * weight; - rny += (nmx * mat.m10 + nmy * mat.m11 + nmz * mat.m12) * weight; - rnz += (nmx * mat.m20 + nmy * mat.m21 + nmz * mat.m22) * weight; + rnx += (nmx * mat.getMatrix()[0][0] + nmy * mat.getMatrix()[0][1] + nmz * mat.getMatrix()[0][2]) * weight; + rny += (nmx * mat.getMatrix()[1][0] + nmy * mat.getMatrix()[1][1] + nmz * mat.getMatrix()[1][2]) * weight; + rnz += (nmx * mat.getMatrix()[2][0] + nmy * mat.getMatrix()[2][1] + nmz * mat.getMatrix()[2][2]) * weight; - rtx += (tnx * mat.m00 + tny * mat.m01 + tnz * mat.m02) * weight; - rty += (tnx * mat.m10 + tny * mat.m11 + tnz * mat.m12) * weight; - rtz += (tnx * mat.m20 + tny * mat.m21 + tnz * mat.m22) * weight; + rtx += (tnx * mat.getMatrix()[0][0] + tny * mat.getMatrix()[0][1] + tnz * mat.getMatrix()[0][2]) * weight; + rty += (tnx * mat.getMatrix()[1][0] + tny * mat.getMatrix()[1][1] + tnz * mat.getMatrix()[1][2]) * weight; + rtz += (tnx * mat.getMatrix()[2][0] + tny * mat.getMatrix()[2][1] + tnz * mat.getMatrix()[2][2]) * weight; } idxWeights += fourMinusMaxWeights; diff --git a/jme3-core/src/main/java/com/jme3/bounding/BoundingBox.java b/jme3-core/src/main/java/com/jme3/bounding/BoundingBox.java index c087950a38..01a8e9e54a 100644 --- a/jme3-core/src/main/java/com/jme3/bounding/BoundingBox.java +++ b/jme3-core/src/main/java/com/jme3/bounding/BoundingBox.java @@ -308,7 +308,7 @@ public BoundingVolume transform(Transform trans, BoundingVolume store) { TempVars vars = TempVars.get(); - Matrix3f transMatrix = vars.tempMat3; + Matrixable transMatrix = vars.tempMat3; transMatrix.set(trans.getRotation()); // Make the rotation matrix all positive to get the maximum x/y/z extent transMatrix.absoluteLocal(); @@ -326,7 +326,7 @@ public BoundingVolume transform(Transform trans, BoundingVolume store) { return box; } - public BoundingVolume transform(Matrix4f trans, BoundingVolume store) { + public BoundingVolume transform(Matrixable trans, BoundingVolume store) { BoundingBox box; if (store == null || store.getType() != Type.AABB) { box = new BoundingBox(); @@ -339,7 +339,7 @@ public BoundingVolume transform(Matrix4f trans, BoundingVolume store) { float w = trans.multProj(center, box.center); box.center.divideLocal(w); - Matrix3f transMatrix = vars.tempMat3; + Matrixable transMatrix = vars.tempMat3; trans.toRotationMatrix(transMatrix); // Make the rotation matrix all positive to get the maximum x/y/z extent diff --git a/jme3-core/src/main/java/com/jme3/bounding/BoundingSphere.java b/jme3-core/src/main/java/com/jme3/bounding/BoundingSphere.java index 3137f2cbf7..dbed91dd7b 100644 --- a/jme3-core/src/main/java/com/jme3/bounding/BoundingSphere.java +++ b/jme3-core/src/main/java/com/jme3/bounding/BoundingSphere.java @@ -398,7 +398,7 @@ public BoundingVolume transform(Transform trans, BoundingVolume store) { return sphere; } - public BoundingVolume transform(Matrix4f trans, BoundingVolume store) { + public BoundingVolume transform(Matrixable trans, BoundingVolume store) { BoundingSphere sphere; if (store == null || store.getType() != BoundingVolume.Type.Sphere) { sphere = new BoundingSphere(1, new Vector3f(0, 0, 0)); diff --git a/jme3-core/src/main/java/com/jme3/bounding/BoundingVolume.java b/jme3-core/src/main/java/com/jme3/bounding/BoundingVolume.java index 4491fcedf1..abe9d9fb94 100644 --- a/jme3-core/src/main/java/com/jme3/bounding/BoundingVolume.java +++ b/jme3-core/src/main/java/com/jme3/bounding/BoundingVolume.java @@ -128,7 +128,7 @@ public final BoundingVolume transform(Transform trans) { */ public abstract BoundingVolume transform(Transform trans, BoundingVolume store); - public abstract BoundingVolume transform(Matrix4f trans, BoundingVolume store); + public abstract BoundingVolume transform(Matrixable trans, BoundingVolume store); /** * diff --git a/jme3-core/src/main/java/com/jme3/collision/bih/BIHNode.java b/jme3-core/src/main/java/com/jme3/collision/bih/BIHNode.java index 52e4f91ca8..8663422a57 100644 --- a/jme3-core/src/main/java/com/jme3/collision/bih/BIHNode.java +++ b/jme3-core/src/main/java/com/jme3/collision/bih/BIHNode.java @@ -36,7 +36,8 @@ import com.jme3.collision.CollisionResult; import com.jme3.collision.CollisionResults; import com.jme3.export.*; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.math.Ray; import com.jme3.math.Triangle; import com.jme3.math.Vector3f; @@ -147,7 +148,7 @@ public static final class BIHStackData { public final int intersectWhere(Collidable col, BoundingBox box, - Matrix4f worldMatrix, + Matrixable worldMatrix, BIHTree tree, CollisionResults results) { @@ -234,7 +235,7 @@ public final int intersectWhere(Collidable col, } public final int intersectBrute(Ray r, - Matrix4f worldMatrix, + Matrixable worldMatrix, BIHTree tree, float sceneMin, float sceneMax, @@ -294,7 +295,7 @@ public final int intersectBrute(Ray r, } public final int intersectWhere(Ray r, - Matrix4f worldMatrix, + Matrix worldMatrix, BIHTree tree, float sceneMin, float sceneMax, @@ -309,7 +310,7 @@ public final int intersectWhere(Ray r, Vector3f o = vars.vect1.set(r.getOrigin()); Vector3f d = vars.vect2.set(r.getDirection()); - Matrix4f inv =vars.tempMat4.set(worldMatrix).invertLocal(); + Matrixable inv =vars.tempMat4.set(worldMatrix).invertLocal(); inv.mult(r.getOrigin(), r.getOrigin()); diff --git a/jme3-core/src/main/java/com/jme3/collision/bih/BIHTree.java b/jme3-core/src/main/java/com/jme3/collision/bih/BIHTree.java index 2d7a4dc24e..56255ff126 100644 --- a/jme3-core/src/main/java/com/jme3/collision/bih/BIHTree.java +++ b/jme3-core/src/main/java/com/jme3/collision/bih/BIHTree.java @@ -42,7 +42,8 @@ import com.jme3.export.JmeImporter; import com.jme3.export.OutputCapsule; import com.jme3.math.FastMath; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.math.Ray; import com.jme3.math.Vector3f; import com.jme3.scene.CollisionData; @@ -403,7 +404,7 @@ public void swapTriangles(int index1, int index2) { } private int collideWithRay(Ray r, - Matrix4f worldMatrix, + Matrix worldMatrix, BoundingVolume worldBound, CollisionResults results) { @@ -443,7 +444,7 @@ private int collideWithRay(Ray r, } private int collideWithBoundingVolume(BoundingVolume bv, - Matrix4f worldMatrix, + Matrixable worldMatrix, CollisionResults results) { BoundingBox bbox; if (bv instanceof BoundingSphere) { @@ -462,7 +463,7 @@ private int collideWithBoundingVolume(BoundingVolume bv, } public int collideWith(Collidable other, - Matrix4f worldMatrix, + Matrix worldMatrix, BoundingVolume worldBound, CollisionResults results) { diff --git a/jme3-core/src/main/java/com/jme3/effect/ParticleEmitter.java b/jme3-core/src/main/java/com/jme3/effect/ParticleEmitter.java index ca3467781a..ae48696e6b 100644 --- a/jme3-core/src/main/java/com/jme3/effect/ParticleEmitter.java +++ b/jme3-core/src/main/java/com/jme3/effect/ParticleEmitter.java @@ -32,7 +32,6 @@ package com.jme3.effect; import com.jme3.bounding.BoundingBox; -import com.jme3.effect.ParticleMesh.Type; import com.jme3.effect.influencers.DefaultParticleInfluencer; import com.jme3.effect.influencers.ParticleInfluencer; import com.jme3.effect.shapes.EmitterPointShape; @@ -43,7 +42,8 @@ import com.jme3.export.OutputCapsule; import com.jme3.math.ColorRGBA; import com.jme3.math.FastMath; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.math.Vector3f; import com.jme3.renderer.Camera; import com.jme3.renderer.RenderManager; @@ -80,7 +80,6 @@ public class ParticleEmitter extends Geometry { private EmitterShape shape = DEFAULT_SHAPE; private ParticleMesh particleMesh; private ParticleInfluencer particleInfluencer = DEFAULT_INFLUENCER; - private ParticleMesh.Type meshType; private Particle[] particles; private int firstUnUsed; private int lastUsed; @@ -176,25 +175,15 @@ public ParticleEmitter clone(boolean cloneMaterial) { clone.controls.add(clone.control); // Reinitialize particle mesh - switch (meshType) { - case Point: - clone.particleMesh = new ParticlePointMesh(); - clone.setMesh(clone.particleMesh); - break; - case Triangle: - clone.particleMesh = new ParticleTriMesh(); - clone.setMesh(clone.particleMesh); - break; - default: - throw new IllegalStateException("Unrecognized particle type: " + meshType); - } + clone.particleMesh = particleMesh; + clone.setMesh(clone.particleMesh); clone.particleMesh.initParticleData(clone, clone.particles.length); clone.particleMesh.setImagesXY(clone.imagesX, clone.imagesY); return clone; } - public ParticleEmitter(String name, Type type, int numParticles) { + public ParticleEmitter(String name, ParticleMesh particleMesh, int numParticles) { super(name); setBatchHint(BatchHint.Never); // ignore world transform, unless user sets inLocalSpace @@ -206,9 +195,7 @@ public ParticleEmitter(String name, Type type, int numParticles) { // particles are usually transparent this.setQueueBucket(Bucket.Transparent); - meshType = type; - - // Must create clone of shape/influencer so that a reference to a static is + // Must create clone of shape/influencer so that a reference to a static is // not maintained shape = shape.deepClone(); particleInfluencer = particleInfluencer.clone(); @@ -216,18 +203,8 @@ public ParticleEmitter(String name, Type type, int numParticles) { control = new ParticleEmitterControl(this); controls.add(control); - switch (meshType) { - case Point: - particleMesh = new ParticlePointMesh(); - this.setMesh(particleMesh); - break; - case Triangle: - particleMesh = new ParticleTriMesh(); - this.setMesh(particleMesh); - break; - default: - throw new IllegalStateException("Unrecognized particle type: " + meshType); - } + this.particleMesh = particleMesh; + this.setMesh(this.particleMesh); this.setNumParticles(numParticles); // particleMesh.initParticleData(this, particles.length); } @@ -273,40 +250,6 @@ public ParticleInfluencer getParticleInfluencer() { return particleInfluencer; } - /** - * Returns the mesh type used by the particle emitter. - * - * - * @return the mesh type used by the particle emitter. - * - * @see #setMeshType(com.jme3.effect.ParticleMesh.Type) - * @see ParticleEmitter#ParticleEmitter(java.lang.String, com.jme3.effect.ParticleMesh.Type, int) - */ - public ParticleMesh.Type getMeshType() { - return meshType; - } - - /** - * Sets the type of mesh used by the particle emitter. - * @param meshType The mesh type to use - */ - public void setMeshType(ParticleMesh.Type meshType) { - this.meshType = meshType; - switch (meshType) { - case Point: - particleMesh = new ParticlePointMesh(); - this.setMesh(particleMesh); - break; - case Triangle: - particleMesh = new ParticleTriMesh(); - this.setMesh(particleMesh); - break; - default: - throw new IllegalStateException("Unrecognized particle type: " + meshType); - } - this.setNumParticles(particles.length); - } - /** * Returns true if particles should spawn in world space. * @@ -1088,15 +1031,9 @@ public void updateFromControl(float tpf) { private void renderFromControl(RenderManager rm, ViewPort vp) { Camera cam = vp.getCamera(); - if (meshType == ParticleMesh.Type.Point) { - float C = cam.getProjectionMatrix().m00; - C *= cam.getWidth() * 0.5f; - - // send attenuation params - this.getMaterial().setFloat("Quadratic", C); - } + particleMesh.setQuadraticFloat(cam, this.getMaterial()); - Matrix3f inverseRotation = Matrix3f.IDENTITY; + Matrixable inverseRotation = new Matrix(3); TempVars vars = null; if (!worldSpace) { vars = TempVars.get(); @@ -1111,7 +1048,7 @@ private void renderFromControl(RenderManager rm, ViewPort vp) { public void preload(RenderManager rm, ViewPort vp) { this.updateParticleState(0); - particleMesh.updateParticleData(particles, vp.getCamera(), Matrix3f.IDENTITY); + particleMesh.updateParticleData(particles, vp.getCamera(), new Matrix(3)); } @Override @@ -1119,7 +1056,6 @@ public void write(JmeExporter ex) throws IOException { super.write(ex); OutputCapsule oc = ex.getCapsule(this); oc.write(shape, "shape", DEFAULT_SHAPE); - oc.write(meshType, "meshType", ParticleMesh.Type.Triangle); oc.write(enabled, "enabled", true); oc.write(particles.length, "numParticles", 0); oc.write(particlesPerSec, "particlesPerSec", 0); @@ -1154,7 +1090,6 @@ public void read(JmeImporter im) throws IOException { shape = shape.deepClone(); } - meshType = ic.readEnum("meshType", ParticleMesh.Type.class, ParticleMesh.Type.Triangle); int numParticles = ic.readInt("numParticles", 0); @@ -1178,18 +1113,8 @@ public void read(JmeImporter im) throws IOException { randomAngle = ic.readBoolean("randomAngle", false); rotateSpeed = ic.readFloat("rotateSpeed", 0); - switch (meshType) { - case Point: - particleMesh = new ParticlePointMesh(); - this.setMesh(particleMesh); - break; - case Triangle: - particleMesh = new ParticleTriMesh(); - this.setMesh(particleMesh); - break; - default: - throw new IllegalStateException("Unrecognized particle type: " + meshType); - } + particleMesh = new ParticleTriMesh(); + this.setMesh(particleMesh); this.setNumParticles(numParticles); // particleMesh.initParticleData(this, particles.length); // particleMesh.setImagesXY(imagesX, imagesY); diff --git a/jme3-core/src/main/java/com/jme3/effect/ParticleMesh.java b/jme3-core/src/main/java/com/jme3/effect/ParticleMesh.java index ed1b80d2a1..79cb1991a9 100644 --- a/jme3-core/src/main/java/com/jme3/effect/ParticleMesh.java +++ b/jme3-core/src/main/java/com/jme3/effect/ParticleMesh.java @@ -31,8 +31,9 @@ */ package com.jme3.effect; +import com.jme3.material.Material; import com.jme3.material.RenderState; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrixable; import com.jme3.renderer.Camera; import com.jme3.scene.Mesh; @@ -44,24 +45,6 @@ */ public abstract class ParticleMesh extends Mesh { - /** - * Type of particle mesh - */ - public enum Type { - /** - * The particle mesh is composed of points. Each particle is a point. - * This can be used in conjuction with {@link RenderState#setPointSprite(boolean) point sprites} - * to render particles the usual way. - */ - Point, - - /** - * The particle mesh is composed of triangles. Each particle is - * two triangles making a single quad. - */ - Triangle; - } - /** * Initialize mesh data. * @@ -80,6 +63,8 @@ public enum Type { /** * Update the particle visual data. Typically called every frame. */ - public abstract void updateParticleData(Particle[] particles, Camera cam, Matrix3f inverseRotation); + public abstract void updateParticleData(Particle[] particles, Camera cam, Matrixable inverseRotation); + + public void setQuadraticFloat(Camera cam, Material material) { } } diff --git a/jme3-core/src/main/java/com/jme3/effect/ParticlePointMesh.java b/jme3-core/src/main/java/com/jme3/effect/ParticlePointMesh.java index 3f56e483b4..0fedc681ca 100644 --- a/jme3-core/src/main/java/com/jme3/effect/ParticlePointMesh.java +++ b/jme3-core/src/main/java/com/jme3/effect/ParticlePointMesh.java @@ -31,7 +31,8 @@ */ package com.jme3.effect; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrixable; +import com.jme3.material.Material; import com.jme3.renderer.Camera; import com.jme3.scene.VertexBuffer; import com.jme3.scene.VertexBuffer.Format; @@ -113,7 +114,7 @@ public void initParticleData(ParticleEmitter emitter, int numParticles) { } @Override - public void updateParticleData(Particle[] particles, Camera cam, Matrix3f inverseRotation) { + public void updateParticleData(Particle[] particles, Camera cam, Matrixable inverseRotation) { VertexBuffer pvb = getBuffer(VertexBuffer.Type.Position); FloatBuffer positions = (FloatBuffer) pvb.getData(); @@ -164,4 +165,13 @@ public void updateParticleData(Particle[] particles, Camera cam, Matrix3f invers svb.updateData(sizes); tvb.updateData(texcoords); } + + @Override + public void setQuadraticFloat(Camera cam, Material material) { + float C = cam.getProjectionMatrix().get(0, 0); + C *= cam.getWidth() * 0.5f; + + // send attenuation params + material.setFloat("Quadratic", C); + } } diff --git a/jme3-core/src/main/java/com/jme3/effect/ParticleTriMesh.java b/jme3-core/src/main/java/com/jme3/effect/ParticleTriMesh.java index 8002197b04..1eeacbe703 100644 --- a/jme3-core/src/main/java/com/jme3/effect/ParticleTriMesh.java +++ b/jme3-core/src/main/java/com/jme3/effect/ParticleTriMesh.java @@ -31,8 +31,9 @@ */ package com.jme3.effect; +import com.jme3.material.Material; import com.jme3.math.FastMath; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrixable; import com.jme3.math.Vector3f; import com.jme3.renderer.Camera; import com.jme3.scene.VertexBuffer; @@ -145,7 +146,7 @@ public void setImagesXY(int imagesX, int imagesY) { } @Override - public void updateParticleData(Particle[] particles, Camera cam, Matrix3f inverseRotation) { + public void updateParticleData(Particle[] particles, Camera cam, Matrixable inverseRotation) { // System.arraycopy(particles, 0, particlesCopy, 0, particlesCopy.length); // comparator.setCamera(cam); // Arrays.sort(particlesCopy, comparator); diff --git a/jme3-core/src/main/java/com/jme3/effect/influencers/NewtonianParticleInfluencer.java b/jme3-core/src/main/java/com/jme3/effect/influencers/NewtonianParticleInfluencer.java index b2f81f9a8d..ebf0fba7f3 100644 --- a/jme3-core/src/main/java/com/jme3/effect/influencers/NewtonianParticleInfluencer.java +++ b/jme3-core/src/main/java/com/jme3/effect/influencers/NewtonianParticleInfluencer.java @@ -38,7 +38,9 @@ import com.jme3.export.JmeImporter; import com.jme3.export.OutputCapsule; import com.jme3.math.FastMath; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; + import java.io.IOException; /** @@ -71,7 +73,7 @@ public void influenceParticle(Particle particle, EmitterShape emitterShape) { // calculating surface tangent (velocity contains the 'normal' value) temp.set(particle.velocity.z * surfaceTangentFactor, particle.velocity.y * surfaceTangentFactor, -particle.velocity.x * surfaceTangentFactor); if (surfaceTangentRotation != 0.0f) {// rotating the tangent - Matrix3f m = new Matrix3f(); + Matrixable m = new Matrix(3); m.fromAngleNormalAxis(FastMath.PI * surfaceTangentRotation, particle.velocity); temp = m.multLocal(temp); } diff --git a/jme3-core/src/main/java/com/jme3/input/FlyByCamera.java b/jme3-core/src/main/java/com/jme3/input/FlyByCamera.java index dd9f00dc11..dbea7c55d7 100644 --- a/jme3-core/src/main/java/com/jme3/input/FlyByCamera.java +++ b/jme3-core/src/main/java/com/jme3/input/FlyByCamera.java @@ -34,7 +34,8 @@ import com.jme3.collision.MotionAllowedListener; import com.jme3.input.controls.*; import com.jme3.math.FastMath; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.math.Quaternion; import com.jme3.math.Vector3f; import com.jme3.renderer.Camera; @@ -311,7 +312,7 @@ protected void rotateCamera(float value, Vector3f axis){ } } - Matrix3f mat = new Matrix3f(); + Matrixable mat = new Matrix(3); mat.fromAngleNormalAxis(rotationSpeed * value, axis); Vector3f up = cam.getUp(); diff --git a/jme3-core/src/main/java/com/jme3/material/Material.java b/jme3-core/src/main/java/com/jme3/material/Material.java index 2aabbd6676..bad319bf5e 100644 --- a/jme3-core/src/main/java/com/jme3/material/Material.java +++ b/jme3-core/src/main/java/com/jme3/material/Material.java @@ -610,7 +610,7 @@ public void setTexture(String name, Texture value) { * @param name the name of the matrix defined in the material definition (j3md) * @param value the Matrix4f object */ - public void setMatrix4(String name, Matrix4f value) { + public void setMatrix4(String name, Matrixable value) { setParam(name, VarType.Matrix4, value); } diff --git a/jme3-core/src/main/java/com/jme3/math/Eigen3f.java b/jme3-core/src/main/java/com/jme3/math/Eigen3f.java index b43731badc..a7dedc5aaa 100644 --- a/jme3-core/src/main/java/com/jme3/math/Eigen3f.java +++ b/jme3-core/src/main/java/com/jme3/math/Eigen3f.java @@ -52,17 +52,17 @@ public Eigen3f() { } - public Eigen3f(Matrix3f data) { + public Eigen3f(Matrix data) { calculateEigen(data); } - public void calculateEigen(Matrix3f data) { + public void calculateEigen(Matrix data) { // prep work... eigenVectors[0] = new Vector3f(); eigenVectors[1] = new Vector3f(); eigenVectors[2] = new Vector3f(); - Matrix3f scaledData = new Matrix3f(data); + Matrix scaledData = new Matrix(data); float maxMagnitude = scaleMatrix(scaledData); // Compute the eigenvalues using double-precision arithmetic. @@ -79,10 +79,10 @@ public void calculateEigen(Matrix3f data) { maxRows[2] = new Vector3f(); for (int i = 0; i < 3; i++) { - Matrix3f tempMatrix = new Matrix3f(scaledData); - tempMatrix.m00 -= eigenValues[i]; - tempMatrix.m11 -= eigenValues[i]; - tempMatrix.m22 -= eigenValues[i]; + Matrixable tempMatrix = new Matrix(scaledData); + tempMatrix.getMatrix()[0][0] -= eigenValues[i]; + tempMatrix.getMatrix()[1][1] -= eigenValues[i]; + tempMatrix.getMatrix()[2][2] -= eigenValues[i]; float[] val = new float[1]; val[0] = maxValues[i]; if (!positiveRank(tempMatrix, val, maxRows[i])) { @@ -142,27 +142,27 @@ public void calculateEigen(Matrix3f data) { * * @return the max magnitude in this matrix */ - private float scaleMatrix(Matrix3f mat) { + private float scaleMatrix(Matrixable mat) { - float max = FastMath.abs(mat.m00); - float abs = FastMath.abs(mat.m01); + float max = FastMath.abs(mat.getMatrix()[0][0]); + float abs = FastMath.abs(mat.getMatrix()[0][1]); if (abs > max) { max = abs; } - abs = FastMath.abs(mat.m02); + abs = FastMath.abs(mat.getMatrix()[0][2]); if (abs > max) { max = abs; } - abs = FastMath.abs(mat.m11); + abs = FastMath.abs(mat.getMatrix()[1][1]); if (abs > max) { max = abs; } - abs = FastMath.abs(mat.m12); + abs = FastMath.abs(mat.getMatrix()[1][2]); if (abs > max) { max = abs; } - abs = FastMath.abs(mat.m22); + abs = FastMath.abs(mat.getMatrix()[2][2]); if (abs > max) { max = abs; } @@ -183,7 +183,7 @@ private float scaleMatrix(Matrix3f mat) { * @param index2 * @param index3 */ - private void computeVectors(Matrix3f mat, Vector3f vect, int index1, + private void computeVectors(Matrixable mat, Vector3f vect, int index1, int index2, int index3) { Vector3f vectorU = new Vector3f(), vectorV = new Vector3f(); Vector3f.generateComplementBasis(vectorU, vectorV, vect); @@ -282,7 +282,7 @@ private void computeVectors(Matrix3f mat, Vector3f vect, int index1, * containing the max magnitude entry. * @return true if the given matrix has a non 0 rank. */ - private boolean positiveRank(Matrix3f matrix, float[] maxMagnitudeStore, Vector3f maxRowStore) { + private boolean positiveRank(Matrixable matrix, float[] maxMagnitudeStore, Vector3f maxRowStore) { // Locate the maximum-magnitude entry of the matrix. maxMagnitudeStore[0] = -1f; int iRow, iCol, iMaxRow = -1; @@ -313,11 +313,11 @@ private boolean positiveRank(Matrix3f matrix, float[] maxMagnitudeStore, Vector3 * a double array to store the results in. Must be at least * length 3. */ - private void computeRoots(Matrix3f mat, double[] rootsStore) { + private void computeRoots(Matrixable mat, double[] rootsStore) { // Convert the unique matrix entries to double precision. - double a = mat.m00, b = mat.m01, c = mat.m02, - d = mat.m11, e = mat.m12, - f = mat.m22; + double a = mat.getMatrix()[0][0], b = mat.getMatrix()[0][1], c = mat.getMatrix()[0][2], + d = mat.getMatrix()[1][1], e = mat.getMatrix()[1][2], + f = mat.getMatrix()[2][2]; // The characteristic equation is x^3 - c2*x^2 + c1*x - c0 = 0. The // eigenvalues are the roots to this equation, all guaranteed to be @@ -379,7 +379,8 @@ private void computeRoots(Matrix3f mat, double[] rootsStore) { } public static void main(String[] args) { - Matrix3f mat = new Matrix3f(2, 1, 1, 1, 2, 1, 1, 1, 2); + float[] data = {2, 1, 1, 1, 2, 1, 1, 1, 2}; + Matrix mat = new Matrix(data); Eigen3f eigenSystem = new Eigen3f(mat); logger.info("eigenvalues = "); diff --git a/jme3-core/src/main/java/com/jme3/math/Line.java b/jme3-core/src/main/java/com/jme3/math/Line.java index 1ca99b4be7..f5814ee72e 100644 --- a/jme3-core/src/main/java/com/jme3/math/Line.java +++ b/jme3-core/src/main/java/com/jme3/math/Line.java @@ -136,7 +136,7 @@ public void orthogonalLineFit(FloatBuffer points) { Vector3f compVec1 = vars.vect1; Vector3f compVec2 = vars.vect2; - Matrix3f compMat1 = vars.tempMat3; + Matrix compMat1 = vars.tempMat3; Eigen3f compEigen1 = vars.eigen; points.rewind(); @@ -169,15 +169,15 @@ public void orthogonalLineFit(FloatBuffer points) { } //find the smallest eigen vector for the direction vector - compMat1.m00 = sumYY + sumZZ; - compMat1.m01 = -sumXY; - compMat1.m02 = -sumXZ; - compMat1.m10 = -sumXY; - compMat1.m11 = sumXX + sumZZ; - compMat1.m12 = -sumYZ; - compMat1.m20 = -sumXZ; - compMat1.m21 = -sumYZ; - compMat1.m22 = sumXX + sumYY; + compMat1.getMatrix()[0][0] = sumYY + sumZZ; + compMat1.getMatrix()[0][1] = -sumXY; + compMat1.getMatrix()[0][2] = -sumXZ; + compMat1.getMatrix()[1][0] = -sumXY; + compMat1.getMatrix()[1][1] = sumXX + sumZZ; + compMat1.getMatrix()[1][2] = -sumYZ; + compMat1.getMatrix()[2][0] = -sumXZ; + compMat1.getMatrix()[2][1] = -sumYZ; + compMat1.getMatrix()[2][2] = sumXX + sumYY; compEigen1.calculateEigen(compMat1); direction = compEigen1.getEigenVector(0); diff --git a/jme3-core/src/main/java/com/jme3/math/Matrix.java b/jme3-core/src/main/java/com/jme3/math/Matrix.java new file mode 100644 index 0000000000..0b3c70f2cb --- /dev/null +++ b/jme3-core/src/main/java/com/jme3/math/Matrix.java @@ -0,0 +1,2521 @@ +package com.jme3.math; + +import java.io.IOException; +import java.io.Serializable; +import java.nio.FloatBuffer; +import java.util.logging.Logger; + +import com.jme3.export.InputCapsule; +import com.jme3.export.JmeExporter; +import com.jme3.export.JmeImporter; +import com.jme3.export.OutputCapsule; +import com.jme3.export.Savable; +import com.jme3.util.BufferUtils; +import com.jme3.util.TempVars; + +public final class Matrix implements Matrixable { + private static final Logger logger = Logger.getLogger(Matrix.class.getName()); + private int M = 0; // number of rows & columns + public float[][] matrix = null; // M-by-N array + + /** + * Constructor instantiates a new Matrix that is set to the + * identity matrix. + * @return + * + * @param row + * the row size to make m x m matrix + */ + public Matrix(int row) + { + this.M = row; + this.matrix = new float[M][M]; + loadIdentity(); + } + + /** + * constructs a matrix with the given values. + */ + public Matrix(float[] data) + { + int count = 0; + M = (int) Math.sqrt(data.length); + this.matrix = new float[M][M]; + for (int c = 0; c < M; c++) + { + for (int r = 0; r < M; r++) + { + this.matrix[r][c] = data[count]; + count++; + } + } + } + + /** + * Constructor instantiates a new Matrix that is set to the + * provided matrix. This constructor copies a given Matrix. If the provided + * matrix is null, the constructor sets the matrix to the identity. + * + * @param mat + * the matrix to copy. + */ + public Matrix(Matrixable mat) + { + this.M = mat.getM(); + this.matrix = new float[M][M]; + copy(mat); + } + + @Override + public void copy(Matrixable matrix) { + if (null == matrix) { + loadIdentity(); + } else { + this.matrix = matrix.getMatrix(); + } + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#absoluteLocal() + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#absoluteLocal() + */ + @Override + public void absoluteLocal() { + for (int i = 0; i < M; i++) { + for (int j = 0; j < M; j++) { + matrix[i][j] = FastMath.abs(matrix[i][j]); + } + } + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#normalizeLocal() + */ + + @Override + public Matrixable normalizeLocal() { + return normalize(this); + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#normalize(com.jme3.math.Matrix) + */ + + @Override + public Matrixable normalize(Matrixable store) { + if (store == null) { + store = new Matrix(M); + } + float[][] matrixstore = new float[store.getM()][store.getM()]; + for (int i = 0; i < M; i++) { + float mag = 1.0f / FastMath + .sqrt(matrix[i][0] * matrix[i][0] + matrix[i][1] * matrix[i][1] + matrix[i][2] * matrix[i][2]); + for (int j = 0; j < M; j++) { + matrixstore[i][j] = matrix[i][j] * mag; + } + matrixstore[2][0] = matrixstore[0][1] * matrixstore[1][2] - matrixstore[1][1] * matrixstore[0][2]; + matrixstore[2][1] = matrixstore[1][0] * matrixstore[0][2] - matrixstore[0][0] * matrixstore[1][2]; + matrixstore[2][2] = matrixstore[0][0] * matrixstore[1][1] - matrixstore[1][0] * matrixstore[0][1]; + } + store.set(matrixstore); + return store; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#fromFrame(com.jme3.math.Vector3f, + * com.jme3.math.Vector3f, com.jme3.math.Vector3f, com.jme3.math.Vector3f) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#fromFrame(com.jme3.math.Vector3f, + * com.jme3.math.Vector3f, com.jme3.math.Vector3f, com.jme3.math.Vector3f) + */ + @Override + public void fromFrame(Vector3f location, Vector3f direction, Vector3f up, Vector3f left) { + TempVars vars = TempVars.get(); + try { + loadIdentity(); + + Vector3f fwdVector = vars.vect1.set(direction); + float[] fwdVectorValues = { -fwdVector.x, -fwdVector.y, -fwdVector.z, fwdVector.dot(location) }; + + Vector3f leftVector = vars.vect2.set(fwdVector).crossLocal(up); + float[] leftVectorValues = { leftVector.x, leftVector.y, leftVector.z, -leftVector.dot(location) }; + + Vector3f upVector = vars.vect3.set(leftVector).crossLocal(fwdVector); + float[] upVectorValues = { upVector.x, upVector.y, upVector.z, -upVector.dot(location) }; + + for (int c = 0; c < 4; c++) { + matrix[c][0] = leftVectorValues[c]; + } + + for (int c = 0; c < 4; c++) { + matrix[c][1] = upVectorValues[c]; + } + + for (int c = 0; c < 4; c++) { + matrix[c][2] = fwdVectorValues[c]; + } + } finally { + vars.release(); + } + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#get(float[]) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#get(float[]) + */ + @Override + public void get(float[] matrix) { + get(matrix, true); + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#get(float[], boolean) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#get(float[], boolean) + */ + @Override + public void get(float[] matrix, boolean rowMajor) { + if (matrix.length != M * M) { + throw new IllegalArgumentException("Array is incorrect size."); + } + int count = 0; + if (rowMajor) { + for (int c = 0; c < M; c++) { + for (int r = 0; r < M; r++) { + matrix[count] = this.matrix[r][c]; + count++; + } + } + } else { + for (int r = 0; r < M; r++) { + for (int c = 0; c < M; c++) { + matrix[count] = this.matrix[r][c]; + count++; + } + } + } + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#get(int, int) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#get(int, int) + */ + @Override + @SuppressWarnings("fallthrough") + public float get(int i, int j) { + for (int c = 0; c < M; c++) { + for (int r = 0; r < M; r++) { + if (r == i && c == j) { + return matrix[c][r]; + } + } + } + logger.warning("Invalid matrix index."); + throw new IllegalArgumentException("Invalid indices into matrix."); + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#getColumn(int) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#getColumn(int) + */ + @Override + public float[] getColumn(int i) { + float[] nullValues = null; + return getColumn(i, nullValues); + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#getColumn(int, float[]) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#getColumn(int, float[]) + */ + @Override + public float[] getColumn(int i, float[] store) { + if (store == null) { + store = new float[M]; + } + if (i > M) { + logger.warning("Invalid column index."); + throw new IllegalArgumentException("Invalid column index. " + i); + } + for (int r = 0; r < M; r++) { + store[r] = matrix[i][r]; + } + return store; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#getColumn(int, com.jme3.math.Vector3f) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#getColumn(int, com.jme3.math.Vector3f) + */ + @Override + public Vector3f getColumn(int i, Vector3f store) { + if (store == null) { + store = new Vector3f(); + } + float[] values = new float[M]; + for (int r = 0; r < 3; r++) { + values[r] = matrix[i][r]; + } + store.x = values[0]; + store.y = values[1]; + store.z = values[2]; + return store; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#getRow(int) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#getRow(int) + */ + @Override + public Vector3f getRow(int i) { + return getRow(i, null); + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#getRow(int, com.jme3.math.Vector3f) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#getRow(int, com.jme3.math.Vector3f) + */ + @Override + public Vector3f getRow(int i, Vector3f store) { + if (store == null) { + store = new Vector3f(); + } + if (i > M) { + logger.warning("Invalid row index."); + throw new IllegalArgumentException("Invalid row index. " + i); + } + float[] values = new float[M]; + for (int r = 0; r < 3; r++) { + values[r] = matrix[r][i]; + } + store.x = values[0]; + store.y = values[1]; + store.z = values[2]; + + return store; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#setColumn(int, float[]) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#setColumn(int, float[]) + */ + @Override + public void setColumn(int i, float[] column) { + if (column == null) { + logger.warning("Column is null. Ignoring."); + return; + } + if (i > M) { + logger.warning("Invalid column index."); + throw new IllegalArgumentException("Invalid column index. " + i); + } + for (int r = 0; r < M; r++) { + matrix[i][r] = column[r]; + } + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#setColumn(int, com.jme3.math.Vector3f) + */ + + @Override + public Matrixable setColumn(int i, Vector3f column) { + if (column == null) { + logger.warning("Column is null. Ignoring."); + return this; + } + if (i > M) { + logger.warning("Invalid column index."); + throw new IllegalArgumentException("Invalid column index. " + i); + } + float[] values = { column.x, column.y, column.z }; + for (int r = 0; r < values.length; r++) { + matrix[i][r] = values[r]; + } + return this; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#setRow(int, com.jme3.math.Vector3f) + */ + + @Override + public Matrixable setRow(int i, Vector3f row) { + if (row == null) { + logger.warning("Column is null. Ignoring."); + return this; + } + if (i > M) { + logger.warning("Invalid column index."); + throw new IllegalArgumentException("Invalid column index. " + i); + } + float[] values = { row.x, row.y, row.z }; + for (int r = 0; r < values.length; r++) { + matrix[r][i] = values[r]; + } + return this; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#set(int, int, float) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#set(int, int, float) + */ + @Override + @SuppressWarnings("fallthrough") + public void set(int i, int j, float value) { + if (i > M || j > M) { + logger.warning("Invalid matrix index."); + throw new IllegalArgumentException("Invalid indices into matrix."); + } + matrix[j][i] = value; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#set(float[][]) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#set(float[][]) + */ + @Override + public void set(float[][] matrix) { + if (matrix.length != M || matrix[0].length != M) { + throw new IllegalArgumentException("Array must be of size of M."); + } + this.matrix = matrix; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#set(com.jme3.math.Matrix) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#set(com.jme3.math.Matrix) + */ + @Override + public Matrix set(Matrixable matrix) { + if (null == matrix) { + loadIdentity(); + } + this.matrix = matrix.getMatrix(); + this.M = matrix.getM(); + return this; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#set(float[]) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#set(float[]) + */ + @Override + public void set(float[] matrix) { + set(matrix, true); + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#set(float[], boolean) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#set(float[], boolean) + */ + @Override + public void set(float[] matrix, boolean rowMajor) { + if (matrix.length != M * M) { + throw new IllegalArgumentException("Array must be of size " + (M * M)); + } + if (rowMajor) { + int count = 0; + for (int c = 0; c < M; c++) { + for (int r = 0; r < M; r++) { + this.matrix[r][c] = matrix[count]; + count++; + } + } + } else { + int count = 0; + for (int c = 0; c < M; c++) { + for (int r = 0; r < M; r++) { + this.matrix[c][r] = matrix[count]; + count++; + } + } + } + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#set(com.jme3.math.Quaternion) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#set(com.jme3.math.Quaternion) + */ + @Override + public Matrix set(Quaternion quaternion) { + return quaternion.toRotationMatrix(this); + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#transpose() + */ + + @Override + public Matrixable transpose() { + float[] tmp = new float[M * M]; + get(tmp, true); + Matrixable mat = new Matrix(tmp); + return mat; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#fromAxes(com.jme3.math.Vector3f, + * com.jme3.math.Vector3f, com.jme3.math.Vector3f) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#fromAxes(com.jme3.math.Vector3f, + * com.jme3.math.Vector3f, com.jme3.math.Vector3f) + */ + @Override + public void fromAxes(Vector3f uAxis, Vector3f vAxis, Vector3f wAxis) { + + setColumn(0, uAxis); + setColumn(1, vAxis); + setColumn(2, wAxis); + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#transposeLocal() + */ + + @Override + public Matrixable transposeLocal() { + float[][] matrixT = new float[M][M]; + for (int c = 0; c < M; c++) { + for (int r = 0; r < M; r++) { + matrixT[r][c] = this.matrix[c][r]; + } + } + this.matrix = matrixT; + return this; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#transposeNew() + */ + + @Override + public Matrixable transposeNew() { + Matrixable ret = new Matrix(M); + ret.set(this); + ret.transposeLocal(); + return ret; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#toFloatBuffer() + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#toFloatBuffer() + */ + @Override + public FloatBuffer toFloatBuffer() { + return toFloatBuffer(false); + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#toFloatBuffer(boolean) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#toFloatBuffer(boolean) + */ + @Override + public FloatBuffer toFloatBuffer(boolean columnMajor) { + FloatBuffer fb = BufferUtils.createFloatBuffer(16); + fillFloatBuffer(fb, columnMajor); + fb.rewind(); + return fb; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#fillFloatBuffer(java.nio.FloatBuffer) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#fillFloatBuffer(java.nio.FloatBuffer) + */ + @Override + public FloatBuffer fillFloatBuffer(FloatBuffer fb) { + return fillFloatBuffer(fb, false); + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#fillFloatBuffer(java.nio.FloatBuffer, + * boolean) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#fillFloatBuffer(java.nio.FloatBuffer, + * boolean) + */ + @Override + public FloatBuffer fillFloatBuffer(FloatBuffer fb, boolean columnMajor) { + + TempVars vars = TempVars.get(); + + fillFloatArray(vars.matrixWrite, columnMajor); + + fb.put(vars.matrixWrite, 0, 16); + vars.release(); + + return fb; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#fillFloatArray(float[], boolean) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#fillFloatArray(float[], boolean) + */ + @Override + public void fillFloatArray(float[] f, boolean columnMajor) { + int count = 0; + if (columnMajor) { + for (int r = 0; r < M; r++) { + for (int c = 0; c < M; c++) { + f[count] = this.matrix[r][c]; + count++; + } + } + } else { + for (int c = 0; c < M; c++) { + for (int r = 0; r < M; r++) { + f[count] = this.matrix[r][c]; + count++; + } + } + } + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#readFloatBuffer(java.nio.FloatBuffer) + */ + + @Override + public Matrixable readFloatBuffer(FloatBuffer fb) { + return readFloatBuffer(fb, false); + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#readFloatBuffer(java.nio.FloatBuffer, + * boolean) + */ + + @Override + public Matrixable readFloatBuffer(FloatBuffer fb, boolean columnMajor) { + float[] bfArray = new float[M * M]; + float[] buffArray = new float[M * M]; + bfArray = fb.array(); + for (int i = 0; i < M * M; i++) { + buffArray[i] = bfArray[i]; + } + + this.set(buffArray, columnMajor); + + return this; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#loadIdentity() + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#loadIdentity() + */ + @Override + public void loadIdentity() { + for (int c = 0; c < M; c++) { + for (int r = 0; r < M; r++) + this.matrix[r][c] = 0; + } + for (int i = 0; i < M; i++) { + this.matrix[i][i] = 1; + } + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#fromFrustum(float, float, float, float, + * float, float, boolean) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#fromFrustum(float, float, float, float, + * float, float, boolean) + */ + @Override + public void fromFrustum(float near, float far, float left, float right, float top, float bottom, boolean parallel) { + loadIdentity(); + if (parallel) { + // scale + matrix[0][0] = 2.0f / (right - left); + matrix[1][1] = 2.0f / (top - bottom); + matrix[2][2] = -2.0f / (far - near); + matrix[3][3] = 1f; + + // translation + matrix[3][0] = -(right + left) / (right - left); + matrix[3][1] = -(top + bottom) / (top - bottom); + matrix[3][2] = -(far + near) / (far - near); + } else { + matrix[0][0] = (2.0f * near) / (right - left); + matrix[1][1] = (2.0f * near) / (top - bottom); + matrix[2][3] = -1.0f; + matrix[3][3] = -0.0f; + + // A + matrix[2][0] = (right + left) / (right - left); + + // B + matrix[2][1] = (top + bottom) / (top - bottom); + + // C + matrix[2][2] = -(far + near) / (far - near); + + // D + matrix[3][2] = -(2.0f * far * near) / (far - near); + } + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#fromAngleAxis(float, + * com.jme3.math.Vector3f) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#fromAngleAxis(float, + * com.jme3.math.Vector3f) + */ + @Override + public void fromAngleAxis(float angle, Vector3f axis) { + Vector3f normAxis = axis.normalize(); + fromAngleNormalAxis(angle, normAxis); + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#fromAngleNormalAxis(float, + * com.jme3.math.Vector3f) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#fromAngleNormalAxis(float, + * com.jme3.math.Vector3f) + */ + @Override + public void fromAngleNormalAxis(float angle, Vector3f axis) { + zero(); + float fCos = FastMath.cos(angle); + float fSin = FastMath.sin(angle); + float fOneMinusCos = ((float) 1.0) - fCos; + float fX2 = axis.x * axis.x; + float fY2 = axis.y * axis.y; + float fZ2 = axis.z * axis.z; + float fXYM = axis.x * axis.y * fOneMinusCos; + float fXZM = axis.x * axis.z * fOneMinusCos; + float fYZM = axis.y * axis.z * fOneMinusCos; + float fXSin = axis.x * fSin; + float fYSin = axis.y * fSin; + float fZSin = axis.z * fSin; + + matrix[0][0] = fX2 * fOneMinusCos + fCos; + matrix[1][0] = fXYM - fZSin; + matrix[2][0] = fXZM + fYSin; + + matrix[0][1] = fXYM + fZSin; + matrix[1][1] = fY2 * fOneMinusCos + fCos; + matrix[2][1] = fYZM - fXSin; + + matrix[0][2] = fXZM - fYSin; + matrix[1][2] = fYZM + fXSin; + matrix[2][2] = fZ2 * fOneMinusCos + fCos; + if (M == 4) { + matrix[3][3] = 1; + } + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#multLocal(float) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#multLocal(float) + */ + @Override + public void multLocal(float scalar) { + for (int c = 0; c < M; c++) { + for (int r = 0; r < M; r++) { + matrix[r][c] *= scalar; + } + } + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#multLocal(com.jme3.math.Vector3f) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#multLocal(com.jme3.math.Vector3f) + */ + @Override + public Vector3f multLocal(Vector3f vec) { + if (vec == null) { + return null; + } + mult(vec, vec); + return vec; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#mult(float) + */ + + @Override + public Matrixable mult(float scalar) { + Matrixable out = new Matrix(M); + out.set(this); + out.multLocal(scalar); + return out; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#mult(float, com.jme3.math.Matrixable) + */ + + @Override + public Matrixable mult(float scalar, Matrixable store) { + store.set(this); + store.multLocal(scalar); + return store; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#mult(com.jme3.math.Matrix) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#mult(com.jme3.math.Matrix) + */ + @Override + public Matrixable mult(Matrixable in2) { + return mult(in2, null); + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#mult(com.jme3.math.Matrix, + * com.jme3.math.Matrix) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#mult(com.jme3.math.Matrix, + * com.jme3.math.Matrix) + */ + @Override + public Matrixable mult(Matrixable in2, Matrixable store) { + if (store == null) { + store = new Matrix(M); + } + store.zero(); + float[][] storeMatrix = new float[M][M]; + for (int r = 0; r < M; r++) { + for (int c = 0; c < M; c++) { + storeMatrix[r][c] += matrix[r][c] * in2.getMatrix()[r][c]; + + } + } + store.set(storeMatrix); + return store; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#multLocal(com.jme3.math.Matrix) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#multLocal(com.jme3.math.Matrix) + */ + @Override + public Matrixable multLocal(Matrixable in2) { + Matrixable store = mult(in2, null); + matrix = store.getMatrix(); + return this; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#mult(com.jme3.math.Vector3f) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#mult(com.jme3.math.Vector3f) + */ + @Override + public Vector3f mult(Vector3f vec) { + return mult(vec, null); + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#mult(com.jme3.math.Vector3f, + * com.jme3.math.Vector3f) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#mult(com.jme3.math.Vector3f, + * com.jme3.math.Vector3f) + */ + @Override + public Vector3f mult(Vector3f vec, Vector3f store) { + if (store == null) { + store = new Vector3f(); + } + float[] storeArray = new float[3]; + float vx = vec.x, vy = vec.y, vz = vec.z; + + for (int r = 0; r < 3; r++) { + if (M < 4) { + storeArray[r] = (matrix[0][r] * vx) + (matrix[1][r] * vy) + (matrix[2][r] * vz); + } else { + storeArray[r] = (matrix[0][r] * vx) + (matrix[1][r] * vy) + (matrix[2][r] * vz) + matrix[3][r]; + } + + } + store.x = storeArray[0]; + store.y = storeArray[1]; + store.z = storeArray[2]; + return store; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#mult(com.jme3.math.Vector4f) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#mult(com.jme3.math.Vector4f) + */ + @Override + public Vector4f mult(Vector4f vec) { + return mult(vec, null); + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#mult(com.jme3.math.Vector4f, + * com.jme3.math.Vector4f) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#mult(com.jme3.math.Vector4f, + * com.jme3.math.Vector4f) + */ + @Override + public Vector4f mult(Vector4f vec, Vector4f store) { + if (null == vec) { + logger.warning("Source vector is null, null result returned."); + return null; + } + if (store == null) { + store = new Vector4f(); + } + + float[] storeArray = new float[4]; + float vx = vec.x, vy = vec.y, vz = vec.z, vw = vec.w; + + for (int r = 0; r < 4; r++) { + storeArray[r] = (matrix[0][r] * vx) + (matrix[1][r] * vy) + (matrix[2][r] * vz) + (matrix[3][r] * vw); + } + store.x = storeArray[0]; + store.y = storeArray[1]; + store.z = storeArray[2]; + store.w = storeArray[3]; + return store; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#multAcross(com.jme3.math.Vector4f) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#multAcross(com.jme3.math.Vector4f) + */ + @Override + public Vector4f multAcross(Vector4f vec) { + return multAcross(vec, null); + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#multAcross(com.jme3.math.Vector4f, + * com.jme3.math.Vector4f) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#multAcross(com.jme3.math.Vector4f, + * com.jme3.math.Vector4f) + */ + @Override + public Vector4f multAcross(Vector4f vec, Vector4f store) { + if (null == vec) { + logger.warning("Source vector is null, null result returned."); + return null; + } + if (store == null) { + store = new Vector4f(); + } + + float[] storeArray = new float[4]; + float vx = vec.x, vy = vec.y, vz = vec.z, vw = vec.w; + + for (int r = 0; r < 4; r++) { + storeArray[r] = (matrix[r][0] * vx) + (matrix[r][1] * vy) + (matrix[r][2] * vz) + (matrix[r][3] * vw); + } + store.x = storeArray[0]; + store.y = storeArray[1]; + store.z = storeArray[2]; + store.w = storeArray[3]; + return store; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#multNormal(com.jme3.math.Vector3f, + * com.jme3.math.Vector3f) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#multNormal(com.jme3.math.Vector3f, + * com.jme3.math.Vector3f) + */ + @Override + public Vector3f multNormal(Vector3f vec, Vector3f store) { + if (store == null) { + store = new Vector3f(); + } + float[] storeArray = new float[3]; + float vx = vec.x, vy = vec.y, vz = vec.z; + + for (int r = 0; r < 3; r++) { + storeArray[r] = (matrix[0][r] * vx) + (matrix[1][r] * vy) + (matrix[2][r] * vz); + } + store.x = storeArray[0]; + store.y = storeArray[1]; + store.z = storeArray[2]; + + return store; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#multNormalAcross(com.jme3.math.Vector3f, + * com.jme3.math.Vector3f) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#multNormalAcross(com.jme3.math.Vector3f, + * com.jme3.math.Vector3f) + */ + @Override + public Vector3f multNormalAcross(Vector3f vec, Vector3f store) { + if (store == null) { + store = new Vector3f(); + } + float[] storeArray = new float[3]; + float vx = vec.x, vy = vec.y, vz = vec.z; + + for (int r = 0; r < 3; r++) { + storeArray[r] = (matrix[r][0] * vx) + (matrix[r][1] * vy) + (matrix[r][2] * vz); + } + store.x = storeArray[0]; + store.y = storeArray[1]; + store.z = storeArray[2]; + + return store; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#multProj(com.jme3.math.Vector3f, + * com.jme3.math.Vector3f) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#multProj(com.jme3.math.Vector3f, + * com.jme3.math.Vector3f) + */ + @Override + public float multProj(Vector3f vec, Vector3f store) { + float vx = vec.x, vy = vec.y, vz = vec.z; + mult(vec, store); + return matrix[0][3] * vx + matrix[1][3] * vy + matrix[2][3] * vz + matrix[3][3]; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#multAcross(com.jme3.math.Vector3f, + * com.jme3.math.Vector3f) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#multAcross(com.jme3.math.Vector3f, + * com.jme3.math.Vector3f) + */ + @Override + public Vector3f multAcross(Vector3f vec, Vector3f store) { + if (null == vec) { + logger.warning("Source vector is null, null result returned."); + return null; + } + if (store == null) { + store = new Vector3f(); + } + float[] storeArray = new float[3]; + float vx = vec.x, vy = vec.y, vz = vec.z; + + for (int r = 0; r < 3; r++) { + storeArray[r] = (matrix[r][0] * vx) + (matrix[r][1] * vy) + (matrix[r][2] * vz) + matrix[r][3]; + } + store.x = storeArray[0]; + store.y = storeArray[1]; + store.z = storeArray[2]; + return store; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#mult(com.jme3.math.Quaternion, + * com.jme3.math.Quaternion) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#mult(com.jme3.math.Quaternion, + * com.jme3.math.Quaternion) + */ + @Override + public Quaternion mult(Quaternion vec, Quaternion store) { + if (null == vec) { + logger.warning("Source vector is null, null result returned."); + return null; + } + if (store == null) { + store = new Quaternion(); + } + + float[] storeArray = new float[4]; + for (int r = 0; r < 4; r++) { + storeArray[r] = (matrix[r][0] * vec.x) + (matrix[r][1] * vec.y) + (matrix[r][2] * vec.z) + + (matrix[r][3] * vec.w); + } + store.x = storeArray[0]; + store.y = storeArray[1]; + store.z = storeArray[2]; + store.w = storeArray[3]; + return store; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#mult(float[]) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#mult(float[]) + */ + @Override + public float[] mult(float[] vec4f) { + if (null == vec4f || vec4f.length != 4) { + logger.warning("invalid array given, must be nonnull and length 4"); + return null; + } + float vx = vec4f[0], vy = vec4f[1], vz = vec4f[2], vw = vec4f[3]; + for (int r = 0; r < 4; r++) { + vec4f[r] = (matrix[0][r] * vx) + (matrix[1][r] * vy) + (matrix[2][r] * vz) + (matrix[3][r] * vw); + } + return vec4f; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#multAcross(float[]) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#multAcross(float[]) + */ + @Override + public float[] multAcross(float[] vec4f) { + if (null == vec4f || vec4f.length != 4) { + logger.warning("invalid array given, must be nonnull and length 4"); + return null; + } + float x = vec4f[0], y = vec4f[1], z = vec4f[2], w = vec4f[3]; + for (int r = 0; r < 4; r++) { + vec4f[r] = (matrix[r][0] * x) + (matrix[r][1] * y) + (matrix[r][2] * z) + (matrix[r][3] * w); + } + return vec4f; + } + + @Override + public Matrixable invert() { + return invert(null); + } + + @Override + public Matrixable invert(Matrixable store) { + if (store == null) { + store = new Matrix(M); + } + float det = determinant(); + if (FastMath.abs(det) <= FastMath.FLT_EPSILON) { + return store.zero(); + } + float x[][] = new float[M][M]; + float b[][] = new float[M][M]; + int index[] = new int[M]; + for (int i = 0; i < M; ++i) + b[i][i] = 1; + + gaussian(matrix, index); + + for (int i = 0; i < M - 1; ++i) { + for (int j = i + 1; j < M; ++j) { + for (int k = 0; k < M; ++k) { + b[index[j]][k] -= matrix[index[j]][i] * b[index[i]][k]; + } + } + } + + for (int i = 0; i < M; ++i) { + x[M - 1][i] = b[index[M - 1]][i] / matrix[index[M - 1]][M - 1]; + for (int j = M - 2; j >= 0; --j) { + x[j][i] = b[index[j]][i]; + for (int k = j + 1; k < M; ++k) { + x[j][i] -= matrix[index[j]][k] * x[k][i]; + } + x[j][i] /= matrix[index[j]][j]; + } + } + store.set(x); + return store; + } + + public static void gaussian(float a[][], int index[]) { + int n = index.length; + float c[] = new float[n]; + + for (int i = 0; i < n; ++i) + index[i] = i; + + for (int i = 0; i < n; ++i) { + float c1 = 0; + for (int j = 0; j < n; ++j) { + float c0 = Math.abs(a[i][j]); + if (c0 > c1) + c1 = c0; + } + c[i] = c1; + } + + int k = 0; + for (int j = 0; j < n - 1; ++j) { + float pi1 = 0; + for (int i = j; i < n; ++i) { + float pi0 = Math.abs(a[index[i]][j]); + pi0 /= c[index[i]]; + if (pi0 > pi1) { + pi1 = pi0; + k = i; + } + } + + int itmp = index[j]; + index[j] = index[k]; + index[k] = itmp; + for (int i = j + 1; i < n; ++i) { + float pj = a[index[i]][j] / a[index[j]][j]; + + a[index[i]][j] = pj; + + for (int l = j + 1; l < n; ++l) + a[index[i]][l] -= pj * a[index[j]][l]; + } + } + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#invertLocal() + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#invertLocal() + */ + @Override + public Matrixable invertLocal() { + + return invert(this); + } + + @Override + public Matrixable adjoint() { + return adjoint(null); + } + + @Override + public Matrixable adjoint(Matrixable store) { + if (store == null) { + store = new Matrix(M); + } + cofactor(store); + return store; + } + + @Override + public Matrixable cofactor(Matrixable store) { + float[][] storeMatrix = new float[store.getM()][store.getM()]; + + for (int c = 0; c < M; c++) { + for (int r = 0; r < M; r++) { + Matrixable tmp = removeRowCol(c, r); + storeMatrix[r][c] = (int) (Math.pow(-1, c + r) * tmp.determinant()); + } + } + store.set(storeMatrix); + return store; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#removeRowCol(int, int) + */ + + @Override + public Matrixable removeRowCol(int row, int col) { + Matrix result = new Matrix(M - 1); + + int k = 0, l = 0; + for (int i = 0; i < M; i++) { + if (i == row) + continue; + for (int j = 0; j < M; j++) { + if (j == col) + continue; + result.matrix[l][k] = matrix[i][j]; + + k = (k + 1) % (M - 1); + if (k == 0) + l++; + } + } + + return result; + } + + @Override + public void setTransform(Vector3f position, Vector3f scale, Matrixable rotMat) { + // Ordering: + // 1. Scale + // 2. Rotate + // 3. Translate + + // Set up final matrix with scale, rotation and translation + + float[] scaleArray = { scale.x, scale.y, scale.z }; + float[] positionArray = { position.x, position.y, position.z }; + for (int c = 0; c < M; c++) { + for (int r = 0; r < M; r++) { + if (c == 3) { + matrix[r][c] = 0; + if (r == 3) { + matrix[3][3] = 1; + } + } else { + try { + matrix[c][r] = scaleArray[c] * rotMat.getMatrix()[c][r]; + } catch (Exception e) { + matrix[r][c] = positionArray[c]; + } + } + } + } + } + + @Override + public float determinant() { + float det = 0, sign = 1; + int p = 0, q = 0; + int n = M; + if (n == 1) { + det = matrix[0][0]; + } else { + Matrix b = new Matrix(n - 1); + for (int x = 0; x < n; x++) { + p = 0; + q = 0; + for (int i = 1; i < n; i++) { + for (int j = 0; j < n; j++) { + if (j != x) { + b.matrix[p][q++] = matrix[i][j]; + if (q % (n - 1) == 0) { + p++; + q = 0; + } + } + } + } + det = det + matrix[0][x] * b.determinant() * sign; + sign = -sign; + } + } + return det; + } + + @Override + public Matrix zero() { + for (int c = 0; c < M; c++) { + for (int r = 0; r < M; r++) { + matrix[r][c] = 0; + } + } + return this; + } + + @Override + public Matrixable add(Matrixable mat) { + Matrix result = new Matrix(M); + for (int i = 0; i < M; i++) + for (int j = 0; j < M; j++) + result.matrix[i][j] = matrix[i][j] + mat.getMatrix()[i][j]; + return result; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#addLocal(com.jme3.math.Matrix) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#addLocal(com.jme3.math.Matrix) + */ + @Override + public void addLocal(Matrixable mat) { + for (int i = 0; i < M; i++) + for (int j = 0; j < M; j++) + matrix[i][j] += mat.getMatrix()[i][j]; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#toTranslationVector() + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#toTranslationVector() + */ + @Override + public Vector3f toTranslationVector() { + float[] vectorArray = new float[3]; + for (int j = 0; j < 3; j++) { + vectorArray[j] = matrix[3][j]; + } + Vector3f vector = new Vector3f(vectorArray[0], vectorArray[1], vectorArray[2]); + return vector; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#toTranslationVector(com.jme3.math.Vector3f) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#toTranslationVector(com.jme3.math.Vector3f) + */ + @Override + public void toTranslationVector(Vector3f vector) { + float[] vectorArray = new float[3]; + for (int j = 0; j < 3; j++) { + vectorArray[j] = matrix[3][j]; + } + vector.set(vectorArray[0], vectorArray[1], vectorArray[2]); + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#toRotationQuat() + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#toRotationQuat() + */ + @Override + public Quaternion toRotationQuat() { + Quaternion quat = new Quaternion(); + quat.fromRotationMatrix(toRotationMatrix()); + return quat; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#toRotationQuat(com.jme3.math.Quaternion) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#toRotationQuat(com.jme3.math.Quaternion) + */ + @Override + public void toRotationQuat(Quaternion q) { + q.fromRotationMatrix(toRotationMatrix()); + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#toRotationMatrix() + */ + + @Override + public Matrixable toRotationMatrix() { + float[] data = new float[(M - 1) * (M - 1)]; + int count = 0; + for (int i = 0; i < M - 1; i++) { + for (int j = 0; j < M - 1; j++) { + data[count] = matrix[j][i]; + count++; + } + } + return new Matrix(data); + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#toRotationMatrix(com.jme3.math.Matrixable) + */ + + @Override + public void toRotationMatrix(Matrixable mat) { + float[] data = new float[(M - 1) * (M - 1)]; + int count = 0; + for (int i = 0; i < M - 1; i++) { + for (int j = 0; j < M - 1; j++) { + data[count] = matrix[j][i]; + count++; + } + } + Matrix newMatrix = new Matrix(data); + mat.set(newMatrix); + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#toScaleVector() + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#toScaleVector() + */ + @Override + public Vector3f toScaleVector() { + Vector3f result = new Vector3f(); + this.toScaleVector(result); + return result; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#toScaleVector(com.jme3.math.Vector3f) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#toScaleVector(com.jme3.math.Vector3f) + */ + @Override + public void toScaleVector(Vector3f vector) { + float[] vectorArray = new float[3]; + + for (int i = 0; i < 3; i++) { + vectorArray[i] = (float) Math + .sqrt(matrix[i][0] * matrix[i][0] + matrix[i][1] * matrix[i][1] + matrix[i][2] * matrix[i][2]); + } + vector.set(vectorArray[0], vectorArray[1], vectorArray[2]); + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#setScale(float, float, float) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#setScale(float, float, float) + */ + @Override + public void setScale(float x, float y, float z) { + TempVars vars = TempVars.get(); + + float[] values = { x, y, z }; + + for (int i = 0; i < 3; i++) { + vars.vect1.set(matrix[i][0], matrix[i][1], matrix[i][2]); + vars.vect1.normalizeLocal().multLocal(values[i]); + float[] versValues = { vars.vect1.x, vars.vect1.y, vars.vect1.z }; + for (int j = 0; j < 3; j++) { + matrix[i][j] = versValues[j]; + } + } + vars.release(); + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#setScale(com.jme3.math.Vector3f) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#setScale(com.jme3.math.Vector3f) + */ + @Override + public void setScale(Vector3f scale) { + this.setScale(scale.x, scale.y, scale.z); + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#setTranslation(float[]) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#setTranslation(float[]) + */ + @Override + public void setTranslation(float[] translation) { + if (translation.length != 3) { + throw new IllegalArgumentException("Translation size must be 3."); + } + for (int i = 0; i < translation.length; i++) { + matrix[3][i] = translation[i]; + } + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#setTranslation(float, float, float) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#setTranslation(float, float, float) + */ + @Override + public void setTranslation(float x, float y, float z) { + float[] values = { x, y, z }; + for (int i = 0; i < values.length; i++) { + matrix[3][i] = values[i]; + } + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#setTranslation(com.jme3.math.Vector3f) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#setTranslation(com.jme3.math.Vector3f) + */ + @Override + public void setTranslation(Vector3f translation) { + float[] values = { translation.x, translation.y, translation.z }; + for (int i = 0; i < values.length; i++) { + matrix[3][i] = values[i]; + } + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#setInverseTranslation(float[]) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#setInverseTranslation(float[]) + */ + @Override + public void setInverseTranslation(float[] translation) { + for (int i = 0; i < translation.length; i++) { + translation[i] = -translation[i]; + } + setTranslation(translation); + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#angleRotation(com.jme3.math.Vector3f) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#angleRotation(com.jme3.math.Vector3f) + */ + @Override + public void angleRotation(Vector3f angles) { + float angle; + float sr, sp, sy, cr, cp, cy; + + angle = (angles.z * FastMath.DEG_TO_RAD); + sy = FastMath.sin(angle); + cy = FastMath.cos(angle); + angle = (angles.y * FastMath.DEG_TO_RAD); + sp = FastMath.sin(angle); + cp = FastMath.cos(angle); + angle = (angles.x * FastMath.DEG_TO_RAD); + sr = FastMath.sin(angle); + cr = FastMath.cos(angle); + float[] values = { cp * cy, cp * sy, -sp, sr * sp * cy + cr * -sy, sr * sp * sy + cr * cy, sr * cp, + (cr * sp * cy + -sr * -sy), (cr * sp * sy + -sr * cy), cr * cp, 0.0f, 0.0f, 0.0f }; + int count = 0; + for (int i = 0; i < M; i++) { + for (int j = 0; j < 3; j++) { + matrix[i][j] = values[count]; + count++; + } + } + } + + /* + * (non-Javadoc) + * + * @see + * com.jme3.math.Matrixable#setRotationQuaternion(com.jme3.math.Quaternion) + */ + + /* + * (non-Javadoc) + * + * @see + * com.jme3.math.Matrixable#setRotationQuaternion(com.jme3.math.Quaternion) + */ + @Override + public void setRotationQuaternion(Quaternion quat) { + quat.toRotationMatrix(this); + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#setInverseRotationRadians(float[]) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#setInverseRotationRadians(float[]) + */ + @Override + public void setInverseRotationRadians(float[] angles) { + if (angles.length != 3) { + throw new IllegalArgumentException("Angles must be of size 3."); + } + double cr = FastMath.cos(angles[0]); + double sr = FastMath.sin(angles[0]); + double cp = FastMath.cos(angles[1]); + double sp = FastMath.sin(angles[1]); + double cy = FastMath.cos(angles[2]); + double sy = FastMath.sin(angles[2]); + + double[] values = { (cp * cy), (cp * sy), (-sp), ((sr * sp) * cy - cr * sy), ((sr * sp) * sy + cr * cy), + (sr * cp), ((cr * sp) * cy + sr * sy), ((cr * sp) * sy - sr * cy), (cr * cp) }; + int count = 0; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + matrix[i][j] = (float) values[count]; + count++; + } + } + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#setInverseRotationDegrees(float[]) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#setInverseRotationDegrees(float[]) + */ + @Override + public void setInverseRotationDegrees(float[] angles) { + if (angles.length != 3) { + throw new IllegalArgumentException("Angles must be of size 3."); + } + float vec[] = new float[3]; + for (int i = 0; i < 3; i++) { + vec[i] = (angles[i] * FastMath.RAD_TO_DEG); + } + setInverseRotationRadians(vec); + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#inverseTranslateVect(float[]) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#inverseTranslateVect(float[]) + */ + @Override + public void inverseTranslateVect(float[] vec) { + if (vec.length != 3) { + throw new IllegalArgumentException("vec must be of size 3."); + } + for (int i = 0; i < vec.length; i++) { + vec[i] = vec[i] - matrix[3][i]; + } + } + + /* + * (non-Javadoc) + * + * @see + * com.jme3.math.Matrixable#inverseTranslateVect(com.jme3.math.Vector3f) + */ + + /* + * (non-Javadoc) + * + * @see + * com.jme3.math.Matrixable#inverseTranslateVect(com.jme3.math.Vector3f) + */ + @Override + public void inverseTranslateVect(Vector3f data) { + data.x -= matrix[3][0]; + data.y -= matrix[3][1]; + data.z -= matrix[3][2]; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#translateVect(com.jme3.math.Vector3f) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#translateVect(com.jme3.math.Vector3f) + */ + @Override + public void translateVect(Vector3f data) { + data.x += matrix[3][0]; + data.y += matrix[3][1]; + data.z += matrix[3][2]; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#inverseRotateVect(com.jme3.math.Vector3f) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#inverseRotateVect(com.jme3.math.Vector3f) + */ + @Override + public void inverseRotateVect(Vector3f vec) { + float vx = vec.x, vy = vec.y, vz = vec.z; + float[] values = new float[3]; + for (int i = 0; i < 3; i++) { + values[i] = vx * matrix[i][0] + vy * matrix[i][1] + vz * matrix[i][2]; + } + vec.x = values[0]; + vec.y = values[1]; + vec.z = values[2]; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#rotateVect(com.jme3.math.Vector3f) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#rotateVect(com.jme3.math.Vector3f) + */ + @Override + public void rotateVect(Vector3f vec) { + float vx = vec.x, vy = vec.y, vz = vec.z; + float[] values = new float[3]; + for (int i = 0; i < 3; i++) { + values[i] = vx * matrix[0][i] + vy * matrix[1][i] + vz * matrix[2][i]; + } + vec.x = values[0]; + vec.y = values[1]; + vec.z = values[2]; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#toString() + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#toString() + */ + @Override + public String toString() { + StringBuilder result = new StringBuilder("Matrix" + M + "f\n[\n"); + for (int c = 0; c < M; c++) { + result.append(" "); + for (int r = 0; r < M; r++) { + result.append(matrix[r][c]); + result.append(" "); + } + result.deleteCharAt(result.length() - 1); + result.append("\n"); + } + result.append("]"); + return result.toString(); + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#hashCode() + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#hashCode() + */ + @Override + public int hashCode() { + int hash = 37; + + for (int c = 0; c < M; c++) { + for (int r = 0; r < M; r++) { + hash = 37 * hash + Float.floatToIntBits(matrix[r][c]); + } + } + return hash; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#equals(java.lang.Object) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#equals(java.lang.Object) + */ + @Override + public boolean equals(Object o) { + if (!(o instanceof Matrix) || o == null) { + return false; + } + if (this.matrix == ((Matrix) o).matrix) { + return true; + } + + Matrix comp = (Matrix) o; + + if (comp.M != M) { + return false; + } + + for (int c = 0; c < M; c++) + for (int r = 0; r < M; r++) + if (matrix[r][c] != comp.matrix[r][c]) + return false; + return true; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#write(com.jme3.export.JmeExporter) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#write(com.jme3.export.JmeExporter) + */ + @Override + public void write(JmeExporter e) throws IOException { + OutputCapsule cap = e.getCapsule(this); + Matrix tmpIdentity = new Matrix(M); + for (int c = 0; c < M; c++) { + for (int r = 0; r < M; r++) { + cap.write(matrix[r][c], String.valueOf(r) + String.valueOf(c), (int) tmpIdentity.matrix[r][c]); + } + } + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#read(com.jme3.export.JmeImporter) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#read(com.jme3.export.JmeImporter) + */ + @Override + public void read(JmeImporter e) throws IOException { + InputCapsule cap = e.getCapsule(this); + Matrix tmpIdentity = new Matrix(M); + for (int c = 0; c < M; c++) { + for (int r = 0; r < M; r++) { + matrix[r][c] = cap.readFloat(String.valueOf(r) + String.valueOf(c), (int) tmpIdentity.matrix[r][c]); + } + } + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#isIdentity() + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#isIdentity() + */ + @Override + public boolean isIdentity() { + Matrix tmpIdentity = new Matrix(M); + if (tmpIdentity.M != M) { + throw new RuntimeException("Illegal matrix dimensions."); + } + + for (int c = 0; c < M; c++) { + for (int r = 0; r < M; r++) { + if (matrix[r][c] != tmpIdentity.matrix[r][c]) { + return false; + } + } + } + return true; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#scale(com.jme3.math.Vector3f) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#scale(com.jme3.math.Vector3f) + */ + @Override + public void scale(Vector3f scale) { + float[] scaleValues = { scale.getX(), scale.getY(), scale.getZ() }; + for (int c = 0; c < 3; c++) { + for (int r = 0; r < M; r++) { + matrix[c][r] *= scaleValues[c]; + } + } + } + + static boolean equalIdentity(Matrixable mat) { + return mat.isIdentity(); + } + + // XXX: This tests more solid than converting the q to a matrix and + // multiplying... why? + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#multLocal(com.jme3.math.Quaternion) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#multLocal(com.jme3.math.Quaternion) + */ + @Override + public void multLocal(Quaternion rotation) { + Vector3f axis = new Vector3f(); + float angle = rotation.toAngleAxis(axis); + Matrix matrix = new Matrix(M); + matrix.fromAngleAxis(angle, axis); + multLocal(matrix); + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#clone() + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#clone() + */ + @Override + public Matrix clone() { + try { + return (Matrix) super.clone(); + } catch (CloneNotSupportedException e) { + throw new AssertionError(); // can not happen + } + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#fromStartEndVectors(com.jme3.math.Vector3f, + * com.jme3.math.Vector3f) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#fromStartEndVectors(com.jme3.math.Vector3f, + * com.jme3.math.Vector3f) + */ + @Override + public void fromStartEndVectors(Vector3f start, Vector3f end) { + Vector3f v = new Vector3f(); + float e, h, f; + + start.cross(end, v); + e = start.dot(end); + f = (e < 0) ? -e : e; + + // if "from" and "to" vectors are nearly parallel + if (f > 1.0f - FastMath.ZERO_TOLERANCE) { + Vector3f u = new Vector3f(); + Vector3f x = new Vector3f(); + float c1, c2, c3; /* coefficients for later use */ + int i, j; + + x.x = (start.x > 0.0) ? start.x : -start.x; + x.y = (start.y > 0.0) ? start.y : -start.y; + x.z = (start.z > 0.0) ? start.z : -start.z; + + if (x.x < x.y) { + if (x.x < x.z) { + x.x = 1.0f; + x.y = x.z = 0.0f; + } else { + x.z = 1.0f; + x.x = x.y = 0.0f; + } + } else { + if (x.y < x.z) { + x.y = 1.0f; + x.x = x.z = 0.0f; + } else { + x.z = 1.0f; + x.x = x.y = 0.0f; + } + } + + u.x = x.x - start.x; + u.y = x.y - start.y; + u.z = x.z - start.z; + v.x = x.x - end.x; + v.y = x.y - end.y; + v.z = x.z - end.z; + + c1 = 2.0f / u.dot(u); + c2 = 2.0f / v.dot(v); + c3 = c1 * c2 * u.dot(v); + + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { + float val = -c1 * u.get(i) * u.get(j) - c2 * v.get(i) * v.get(j) + c3 * v.get(i) * u.get(j); + set(i, j, val); + } + float val = get(i, i); + set(i, i, val + 1.0f); + } + } else { + // the most common case, unless "start"="end", or "start"=-"end" + float hvx, hvz, hvxy, hvxz, hvyz; + h = 1.0f / (1.0f + e); + hvx = h * v.x; + hvz = h * v.z; + hvxy = hvx * v.y; + hvxz = hvx * v.z; + hvyz = hvz * v.y; + set(0, 0, e + hvx * v.x); + set(0, 1, hvxy - v.z); + set(0, 2, hvxz + v.y); + + set(1, 0, hvxy + v.z); + set(1, 1, e + h * v.y * v.y); + set(1, 2, hvyz - v.x); + + set(2, 0, hvxz - v.y); + set(2, 1, hvyz + v.x); + set(2, 2, e + hvz * v.z); + + } + transposeLocal(); + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#getM() + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#getM() + */ + @Override + public int getM() { + return M; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#setM(int) + */ + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#setM(int) + */ + @Override + public void setM(int m) { + M = m; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#getMatrix() + */ + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#getMatrix() + */ + @Override + public float[][] getMatrix() { + return matrix; + } + + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#setMatrix(float[][]) + */ + /* + * (non-Javadoc) + * + * @see com.jme3.math.Matrixable#setMatrix(float[][]) + */ + @Override + public void setMatrix(float[][] matrix) { + this.matrix = matrix; + } +} diff --git a/jme3-core/src/main/java/com/jme3/math/Matrix3f.java b/jme3-core/src/main/java/com/jme3/math/Matrix3f.java deleted file mode 100644 index ca9e7287b8..0000000000 --- a/jme3-core/src/main/java/com/jme3/math/Matrix3f.java +++ /dev/null @@ -1,1434 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.math; - -import com.jme3.export.*; -import com.jme3.util.BufferUtils; -import com.jme3.util.TempVars; -import java.io.IOException; -import java.nio.FloatBuffer; -import java.util.logging.Logger; - -/** - * Matrix3f defines a 3x3 matrix. Matrix data is maintained - * internally and is accessible via the get and set methods. Convenience methods - * are used for matrix operations as well as generating a matrix from a given - * set of values. - * - * @author Mark Powell - * @author Joshua Slack - */ -public final class Matrix3f implements Savable, Cloneable, java.io.Serializable { - - static final long serialVersionUID = 1; - - private static final Logger logger = Logger.getLogger(Matrix3f.class.getName()); - protected float m00, m01, m02; - protected float m10, m11, m12; - protected float m20, m21, m22; - public static final Matrix3f ZERO = new Matrix3f(0, 0, 0, 0, 0, 0, 0, 0, 0); - public static final Matrix3f IDENTITY = new Matrix3f(); - - /** - * Constructor instantiates a new Matrix3f object. The - * initial values for the matrix is that of the identity matrix. - * - */ - public Matrix3f() { - loadIdentity(); - } - - /** - * constructs a matrix with the given values. - * - * @param m00 - * 0x0 in the matrix. - * @param m01 - * 0x1 in the matrix. - * @param m02 - * 0x2 in the matrix. - * @param m10 - * 1x0 in the matrix. - * @param m11 - * 1x1 in the matrix. - * @param m12 - * 1x2 in the matrix. - * @param m20 - * 2x0 in the matrix. - * @param m21 - * 2x1 in the matrix. - * @param m22 - * 2x2 in the matrix. - */ - public Matrix3f(float m00, float m01, float m02, float m10, float m11, - float m12, float m20, float m21, float m22) { - - this.m00 = m00; - this.m01 = m01; - this.m02 = m02; - this.m10 = m10; - this.m11 = m11; - this.m12 = m12; - this.m20 = m20; - this.m21 = m21; - this.m22 = m22; - } - - /** - * Copy constructor that creates a new Matrix3f object that - * is the same as the provided matrix. - * - * @param mat - * the matrix to copy. - */ - public Matrix3f(Matrix3f mat) { - set(mat); - } - - /** - * Takes the absolute value of all matrix fields locally. - */ - public void absoluteLocal() { - m00 = FastMath.abs(m00); - m01 = FastMath.abs(m01); - m02 = FastMath.abs(m02); - m10 = FastMath.abs(m10); - m11 = FastMath.abs(m11); - m12 = FastMath.abs(m12); - m20 = FastMath.abs(m20); - m21 = FastMath.abs(m21); - m22 = FastMath.abs(m22); - } - - /** - * copy transfers the contents of a given matrix to this - * matrix. If a null matrix is supplied, this matrix is set to the identity - * matrix. - * - * @param matrix - * the matrix to copy. - * @return this - */ - public Matrix3f set(Matrix3f matrix) { - if (null == matrix) { - loadIdentity(); - } else { - m00 = matrix.m00; - m01 = matrix.m01; - m02 = matrix.m02; - m10 = matrix.m10; - m11 = matrix.m11; - m12 = matrix.m12; - m20 = matrix.m20; - m21 = matrix.m21; - m22 = matrix.m22; - } - return this; - } - - /** - * get retrieves a value from the matrix at the given - * position. If the position is invalid a JmeException is - * thrown. - * - * @param i - * the row index. - * @param j - * the colum index. - * @return the value at (i, j). - */ - @SuppressWarnings("fallthrough") - public float get(int i, int j) { - switch (i) { - case 0: - switch (j) { - case 0: - return m00; - case 1: - return m01; - case 2: - return m02; - } - case 1: - switch (j) { - case 0: - return m10; - case 1: - return m11; - case 2: - return m12; - } - case 2: - switch (j) { - case 0: - return m20; - case 1: - return m21; - case 2: - return m22; - } - } - - logger.warning("Invalid matrix index."); - throw new IllegalArgumentException("Invalid indices into matrix."); - } - - /** - * get(float[]) returns the matrix in row-major or column-major order. - * - * @param data - * The array to return the data into. This array can be 9 or 16 floats in size. - * Only the upper 3x3 are assigned to in the case of a 16 element array. - * @param rowMajor - * True for row major storage in the array (translation in elements 3, 7, 11 for a 4x4), - * false for column major (translation in elements 12, 13, 14 for a 4x4). - */ - public void get(float[] data, boolean rowMajor) { - if (data.length == 9) { - if (rowMajor) { - data[0] = m00; - data[1] = m01; - data[2] = m02; - data[3] = m10; - data[4] = m11; - data[5] = m12; - data[6] = m20; - data[7] = m21; - data[8] = m22; - } else { - data[0] = m00; - data[1] = m10; - data[2] = m20; - data[3] = m01; - data[4] = m11; - data[5] = m21; - data[6] = m02; - data[7] = m12; - data[8] = m22; - } - } else if (data.length == 16) { - if (rowMajor) { - data[0] = m00; - data[1] = m01; - data[2] = m02; - data[4] = m10; - data[5] = m11; - data[6] = m12; - data[8] = m20; - data[9] = m21; - data[10] = m22; - } else { - data[0] = m00; - data[1] = m10; - data[2] = m20; - data[4] = m01; - data[5] = m11; - data[6] = m21; - data[8] = m02; - data[9] = m12; - data[10] = m22; - } - } else { - throw new IndexOutOfBoundsException("Array size must be 9 or 16 in Matrix3f.get()."); - } - } - - /** - * Normalize this matrix and store the result in the store parameter that is - * returned. - * - * Note that the original matrix is not altered. - * - * @param store the matrix to store the result of the normalization. If this - * parameter is null a new one is created - * @return the normalized matrix - */ - public Matrix3f normalize(Matrix3f store) { - if (store == null) { - store = new Matrix3f(); - } - - float mag = 1.0f / FastMath.sqrt( - m00 * m00 - + m10 * m10 - + m20 * m20); - - store.m00 = m00 * mag; - store.m10 = m10 * mag; - store.m20 = m20 * mag; - - mag = 1.0f / FastMath.sqrt( - m01 * m01 - + m11 * m11 - + m21 * m21); - - store.m01 = m01 * mag; - store.m11 = m11 * mag; - store.m21 = m21 * mag; - - store.m02 = store.m10 * store.m21 - store.m11 * store.m20; - store.m12 = store.m01 * store.m20 - store.m00 * store.m21; - store.m22 = store.m00 * store.m11 - store.m01 * store.m10; - return store; - } - - /** - * Normalize this matrix - * @return this matrix once normalized. - */ - public Matrix3f normalizeLocal() { - return normalize(this); - } - - /** - * getColumn returns one of three columns specified by the - * parameter. This column is returned as a Vector3f object. - * - * @param i - * the column to retrieve. Must be between 0 and 2. - * @return the column specified by the index. - */ - public Vector3f getColumn(int i) { - return getColumn(i, null); - } - - /** - * getColumn returns one of three columns specified by the - * parameter. This column is returned as a Vector3f object. - * - * @param i - * the column to retrieve. Must be between 0 and 2. - * @param store - * the vector object to store the result in. if null, a new one - * is created. - * @return the column specified by the index. - */ - public Vector3f getColumn(int i, Vector3f store) { - if (store == null) { - store = new Vector3f(); - } - switch (i) { - case 0: - store.x = m00; - store.y = m10; - store.z = m20; - break; - case 1: - store.x = m01; - store.y = m11; - store.z = m21; - break; - case 2: - store.x = m02; - store.y = m12; - store.z = m22; - break; - default: - logger.warning("Invalid column index."); - throw new IllegalArgumentException("Invalid column index. " + i); - } - return store; - } - - /** - * getColumn returns one of three rows as specified by the - * parameter. This row is returned as a Vector3f object. - * - * @param i - * the row to retrieve. Must be between 0 and 2. - * @return the row specified by the index. - */ - public Vector3f getRow(int i) { - return getRow(i, null); - } - - /** - * getRow returns one of three rows as specified by the - * parameter. This row is returned as a Vector3f object. - * - * @param i - * the row to retrieve. Must be between 0 and 2. - * @param store - * the vector object to store the result in. if null, a new one - * is created. - * @return the row specified by the index. - */ - public Vector3f getRow(int i, Vector3f store) { - if (store == null) { - store = new Vector3f(); - } - switch (i) { - case 0: - store.x = m00; - store.y = m01; - store.z = m02; - break; - case 1: - store.x = m10; - store.y = m11; - store.z = m12; - break; - case 2: - store.x = m20; - store.y = m21; - store.z = m22; - break; - default: - logger.warning("Invalid row index."); - throw new IllegalArgumentException("Invalid row index. " + i); - } - return store; - } - - /** - * toFloatBuffer returns a FloatBuffer object that contains - * the matrix data. - * - * @return matrix data as a FloatBuffer. - */ - public FloatBuffer toFloatBuffer() { - FloatBuffer fb = BufferUtils.createFloatBuffer(9); - - fb.put(m00).put(m01).put(m02); - fb.put(m10).put(m11).put(m12); - fb.put(m20).put(m21).put(m22); - fb.rewind(); - return fb; - } - - /** - * fillFloatBuffer fills a FloatBuffer object with the matrix - * data. - * - * @param fb - * the buffer to fill, starting at current position. Must have - * room for 9 more floats. - * @return matrix data as a FloatBuffer. (position is advanced by 9 and any - * limit set is not changed). - */ - public FloatBuffer fillFloatBuffer(FloatBuffer fb, boolean columnMajor) { -// if (columnMajor){ -// fb.put(m00).put(m10).put(m20); -// fb.put(m01).put(m11).put(m21); -// fb.put(m02).put(m12).put(m22); -// }else{ -// fb.put(m00).put(m01).put(m02); -// fb.put(m10).put(m11).put(m12); -// fb.put(m20).put(m21).put(m22); -// } - - TempVars vars = TempVars.get(); - - - fillFloatArray(vars.matrixWrite, columnMajor); - fb.put(vars.matrixWrite, 0, 9); - - vars.release(); - - return fb; - } - - public void fillFloatArray(float[] f, boolean columnMajor) { - if (columnMajor) { - f[ 0] = m00; - f[ 1] = m10; - f[ 2] = m20; - f[ 3] = m01; - f[ 4] = m11; - f[ 5] = m21; - f[ 6] = m02; - f[ 7] = m12; - f[ 8] = m22; - } else { - f[ 0] = m00; - f[ 1] = m01; - f[ 2] = m02; - f[ 3] = m10; - f[ 4] = m11; - f[ 5] = m12; - f[ 6] = m20; - f[ 7] = m21; - f[ 8] = m22; - } - } - - /** - * - * setColumn sets a particular column of this matrix to that - * represented by the provided vector. - * - * @param i - * the column to set. - * @param column - * the data to set. - * @return this - */ - public Matrix3f setColumn(int i, Vector3f column) { - - if (column == null) { - logger.warning("Column is null. Ignoring."); - return this; - } - switch (i) { - case 0: - m00 = column.x; - m10 = column.y; - m20 = column.z; - break; - case 1: - m01 = column.x; - m11 = column.y; - m21 = column.z; - break; - case 2: - m02 = column.x; - m12 = column.y; - m22 = column.z; - break; - default: - logger.warning("Invalid column index."); - throw new IllegalArgumentException("Invalid column index. " + i); - } - return this; - } - - /** - * - * setRow sets a particular row of this matrix to that - * represented by the provided vector. - * - * @param i - * the row to set. - * @param row - * the data to set. - * @return this - */ - public Matrix3f setRow(int i, Vector3f row) { - - if (row == null) { - logger.warning("Row is null. Ignoring."); - return this; - } - switch (i) { - case 0: - m00 = row.x; - m01 = row.y; - m02 = row.z; - break; - case 1: - m10 = row.x; - m11 = row.y; - m12 = row.z; - break; - case 2: - m20 = row.x; - m21 = row.y; - m22 = row.z; - break; - default: - logger.warning("Invalid row index."); - throw new IllegalArgumentException("Invalid row index. " + i); - } - return this; - } - - /** - * set places a given value into the matrix at the given - * position. If the position is invalid a JmeException is - * thrown. - * - * @param i - * the row index. - * @param j - * the colum index. - * @param value - * the value for (i, j). - * @return this - */ - @SuppressWarnings("fallthrough") - public Matrix3f set(int i, int j, float value) { - switch (i) { - case 0: - switch (j) { - case 0: - m00 = value; - return this; - case 1: - m01 = value; - return this; - case 2: - m02 = value; - return this; - } - case 1: - switch (j) { - case 0: - m10 = value; - return this; - case 1: - m11 = value; - return this; - case 2: - m12 = value; - return this; - } - case 2: - switch (j) { - case 0: - m20 = value; - return this; - case 1: - m21 = value; - return this; - case 2: - m22 = value; - return this; - } - } - - logger.warning("Invalid matrix index."); - throw new IllegalArgumentException("Invalid indices into matrix."); - } - - /** - * - * set sets the values of the matrix to those supplied by the - * 3x3 two dimenion array. - * - * @param matrix - * the new values of the matrix. - * @throws JmeException - * if the array is not of size 9. - * @return this - */ - public Matrix3f set(float[][] matrix) { - if (matrix.length != 3 || matrix[0].length != 3) { - throw new IllegalArgumentException( - "Array must be of size 9."); - } - - m00 = matrix[0][0]; - m01 = matrix[0][1]; - m02 = matrix[0][2]; - m10 = matrix[1][0]; - m11 = matrix[1][1]; - m12 = matrix[1][2]; - m20 = matrix[2][0]; - m21 = matrix[2][1]; - m22 = matrix[2][2]; - - return this; - } - - /** - * Recreate Matrix using the provided axis. - * - * @param uAxis - * Vector3f - * @param vAxis - * Vector3f - * @param wAxis - * Vector3f - */ - public void fromAxes(Vector3f uAxis, Vector3f vAxis, Vector3f wAxis) { - m00 = uAxis.x; - m10 = uAxis.y; - m20 = uAxis.z; - - m01 = vAxis.x; - m11 = vAxis.y; - m21 = vAxis.z; - - m02 = wAxis.x; - m12 = wAxis.y; - m22 = wAxis.z; - } - - /** - * set sets the values of this matrix from an array of - * values assuming that the data is rowMajor order; - * - * @param matrix - * the matrix to set the value to. - * @return this - */ - public Matrix3f set(float[] matrix) { - return set(matrix, true); - } - - /** - * set sets the values of this matrix from an array of - * values; - * - * @param matrix - * the matrix to set the value to. - * @param rowMajor - * whether the incoming data is in row or column major order. - * @return this - */ - public Matrix3f set(float[] matrix, boolean rowMajor) { - if (matrix.length != 9) { - throw new IllegalArgumentException( - "Array must be of size 9."); - } - - if (rowMajor) { - m00 = matrix[0]; - m01 = matrix[1]; - m02 = matrix[2]; - m10 = matrix[3]; - m11 = matrix[4]; - m12 = matrix[5]; - m20 = matrix[6]; - m21 = matrix[7]; - m22 = matrix[8]; - } else { - m00 = matrix[0]; - m01 = matrix[3]; - m02 = matrix[6]; - m10 = matrix[1]; - m11 = matrix[4]; - m12 = matrix[7]; - m20 = matrix[2]; - m21 = matrix[5]; - m22 = matrix[8]; - } - return this; - } - - /** - * - * set defines the values of the matrix based on a supplied - * Quaternion. It should be noted that all previous values - * will be overridden. - * - * @param quaternion - * the quaternion to create a rotational matrix from. - * @return this - */ - public Matrix3f set(Quaternion quaternion) { - return quaternion.toRotationMatrix(this); - } - - /** - * loadIdentity sets this matrix to the identity matrix. - * Where all values are zero except those along the diagonal which are one. - * - */ - public void loadIdentity() { - m01 = m02 = m10 = m12 = m20 = m21 = 0; - m00 = m11 = m22 = 1; - } - - /** - * @return true if this matrix is identity - */ - public boolean isIdentity() { - return (m00 == 1 && m01 == 0 && m02 == 0) - && (m10 == 0 && m11 == 1 && m12 == 0) - && (m20 == 0 && m21 == 0 && m22 == 1); - } - - /** - * fromAngleAxis sets this matrix4f to the values specified - * by an angle and an axis of rotation. This method creates an object, so - * use fromAngleNormalAxis if your axis is already normalized. - * - * @param angle - * the angle to rotate (in radians). - * @param axis - * the axis of rotation. - */ - public void fromAngleAxis(float angle, Vector3f axis) { - Vector3f normAxis = axis.normalize(); - fromAngleNormalAxis(angle, normAxis); - } - - /** - * fromAngleNormalAxis sets this matrix4f to the values - * specified by an angle and a normalized axis of rotation. - * - * @param angle - * the angle to rotate (in radians). - * @param axis - * the axis of rotation (already normalized). - */ - public void fromAngleNormalAxis(float angle, Vector3f axis) { - float fCos = FastMath.cos(angle); - float fSin = FastMath.sin(angle); - float fOneMinusCos = ((float) 1.0) - fCos; - float fX2 = axis.x * axis.x; - float fY2 = axis.y * axis.y; - float fZ2 = axis.z * axis.z; - float fXYM = axis.x * axis.y * fOneMinusCos; - float fXZM = axis.x * axis.z * fOneMinusCos; - float fYZM = axis.y * axis.z * fOneMinusCos; - float fXSin = axis.x * fSin; - float fYSin = axis.y * fSin; - float fZSin = axis.z * fSin; - - m00 = fX2 * fOneMinusCos + fCos; - m01 = fXYM - fZSin; - m02 = fXZM + fYSin; - m10 = fXYM + fZSin; - m11 = fY2 * fOneMinusCos + fCos; - m12 = fYZM - fXSin; - m20 = fXZM - fYSin; - m21 = fYZM + fXSin; - m22 = fZ2 * fOneMinusCos + fCos; - } - - /** - * mult multiplies this matrix by a given matrix. The result - * matrix is returned as a new object. If the given matrix is null, a null - * matrix is returned. - * - * @param mat - * the matrix to multiply this matrix by. - * @return the result matrix. - */ - public Matrix3f mult(Matrix3f mat) { - return mult(mat, null); - } - - /** - * mult multiplies this matrix by a given matrix. The result - * matrix is returned as a new object. - * - * @param mat - * the matrix to multiply this matrix by. - * @param product - * the matrix to store the result in. if null, a new matrix3f is - * created. It is safe for mat and product to be the same object. - * @return a matrix3f object containing the result of this operation - */ - public Matrix3f mult(Matrix3f mat, Matrix3f product) { - - float temp00, temp01, temp02; - float temp10, temp11, temp12; - float temp20, temp21, temp22; - - if (product == null) { - product = new Matrix3f(); - } - temp00 = m00 * mat.m00 + m01 * mat.m10 + m02 * mat.m20; - temp01 = m00 * mat.m01 + m01 * mat.m11 + m02 * mat.m21; - temp02 = m00 * mat.m02 + m01 * mat.m12 + m02 * mat.m22; - temp10 = m10 * mat.m00 + m11 * mat.m10 + m12 * mat.m20; - temp11 = m10 * mat.m01 + m11 * mat.m11 + m12 * mat.m21; - temp12 = m10 * mat.m02 + m11 * mat.m12 + m12 * mat.m22; - temp20 = m20 * mat.m00 + m21 * mat.m10 + m22 * mat.m20; - temp21 = m20 * mat.m01 + m21 * mat.m11 + m22 * mat.m21; - temp22 = m20 * mat.m02 + m21 * mat.m12 + m22 * mat.m22; - - product.m00 = temp00; - product.m01 = temp01; - product.m02 = temp02; - product.m10 = temp10; - product.m11 = temp11; - product.m12 = temp12; - product.m20 = temp20; - product.m21 = temp21; - product.m22 = temp22; - - return product; - } - - /** - * mult multiplies this matrix by a given - * Vector3f object. The result vector is returned. If the - * given vector is null, null will be returned. - * - * @param vec - * the vector to multiply this matrix by. - * @return the result vector. - */ - public Vector3f mult(Vector3f vec) { - return mult(vec, null); - } - - /** - * Multiplies this 3x3 matrix by the 1x3 Vector vec and stores the result in - * product. - * - * @param vec - * The Vector3f to multiply. - * @param product - * The Vector3f to store the result, it is safe for this to be - * the same as vec. - * @return The given product vector. - */ - public Vector3f mult(Vector3f vec, Vector3f product) { - - if (null == product) { - product = new Vector3f(); - } - - float x = vec.x; - float y = vec.y; - float z = vec.z; - - product.x = m00 * x + m01 * y + m02 * z; - product.y = m10 * x + m11 * y + m12 * z; - product.z = m20 * x + m21 * y + m22 * z; - return product; - } - - /** - * multLocal multiplies this matrix internally by - * a given float scale factor. - * - * @param scale - * the value to scale by. - * @return this Matrix3f - */ - public Matrix3f multLocal(float scale) { - m00 *= scale; - m01 *= scale; - m02 *= scale; - m10 *= scale; - m11 *= scale; - m12 *= scale; - m20 *= scale; - m21 *= scale; - m22 *= scale; - return this; - } - - /** - * multLocal multiplies this matrix by a given - * Vector3f object. The result vector is stored inside the - * passed vector, then returned . If the given vector is null, null will be - * returned. - * - * @param vec - * the vector to multiply this matrix by. - * @return The passed vector after multiplication - */ - public Vector3f multLocal(Vector3f vec) { - if (vec == null) { - return null; - } - float x = vec.x; - float y = vec.y; - vec.x = m00 * x + m01 * y + m02 * vec.z; - vec.y = m10 * x + m11 * y + m12 * vec.z; - vec.z = m20 * x + m21 * y + m22 * vec.z; - return vec; - } - - /** - * mult multiplies this matrix by a given matrix. The result - * matrix is saved in the current matrix. If the given matrix is null, - * nothing happens. The current matrix is returned. This is equivalent to - * this*=mat - * - * @param mat - * the matrix to multiply this matrix by. - * @return This matrix, after the multiplication - */ - public Matrix3f multLocal(Matrix3f mat) { - return mult(mat, this); - } - - /** - * Transposes this matrix in place. Returns this matrix for chaining - * - * @return This matrix after transpose - */ - public Matrix3f transposeLocal() { -// float[] tmp = new float[9]; -// get(tmp, false); -// set(tmp, true); - - float tmp = m01; - m01 = m10; - m10 = tmp; - - tmp = m02; - m02 = m20; - m20 = tmp; - - tmp = m12; - m12 = m21; - m21 = tmp; - - return this; - } - - /** - * Inverts this matrix as a new Matrix3f. - * - * @return The new inverse matrix - */ - public Matrix3f invert() { - return invert(null); - } - - /** - * Inverts this matrix and stores it in the given store. - * - * @return The store - */ - public Matrix3f invert(Matrix3f store) { - if (store == null) { - store = new Matrix3f(); - } - - float det = determinant(); - if (FastMath.abs(det) <= FastMath.FLT_EPSILON) { - return store.zero(); - } - - store.m00 = m11 * m22 - m12 * m21; - store.m01 = m02 * m21 - m01 * m22; - store.m02 = m01 * m12 - m02 * m11; - store.m10 = m12 * m20 - m10 * m22; - store.m11 = m00 * m22 - m02 * m20; - store.m12 = m02 * m10 - m00 * m12; - store.m20 = m10 * m21 - m11 * m20; - store.m21 = m01 * m20 - m00 * m21; - store.m22 = m00 * m11 - m01 * m10; - - store.multLocal(1f / det); - return store; - } - - /** - * Inverts this matrix locally. - * - * @return this - */ - public Matrix3f invertLocal() { - float det = determinant(); - if (FastMath.abs(det) <= 0f) { - return zero(); - } - - float f00 = m11 * m22 - m12 * m21; - float f01 = m02 * m21 - m01 * m22; - float f02 = m01 * m12 - m02 * m11; - float f10 = m12 * m20 - m10 * m22; - float f11 = m00 * m22 - m02 * m20; - float f12 = m02 * m10 - m00 * m12; - float f20 = m10 * m21 - m11 * m20; - float f21 = m01 * m20 - m00 * m21; - float f22 = m00 * m11 - m01 * m10; - - m00 = f00; - m01 = f01; - m02 = f02; - m10 = f10; - m11 = f11; - m12 = f12; - m20 = f20; - m21 = f21; - m22 = f22; - - multLocal(1f / det); - return this; - } - - /** - * Returns a new matrix representing the adjoint of this matrix. - * - * @return The adjoint matrix - */ - public Matrix3f adjoint() { - return adjoint(null); - } - - /** - * Places the adjoint of this matrix in store (creates store if null.) - * - * @param store - * The matrix to store the result in. If null, a new matrix is created. - * @return store - */ - public Matrix3f adjoint(Matrix3f store) { - if (store == null) { - store = new Matrix3f(); - } - - store.m00 = m11 * m22 - m12 * m21; - store.m01 = m02 * m21 - m01 * m22; - store.m02 = m01 * m12 - m02 * m11; - store.m10 = m12 * m20 - m10 * m22; - store.m11 = m00 * m22 - m02 * m20; - store.m12 = m02 * m10 - m00 * m12; - store.m20 = m10 * m21 - m11 * m20; - store.m21 = m01 * m20 - m00 * m21; - store.m22 = m00 * m11 - m01 * m10; - - return store; - } - - /** - * determinant generates the determinant of this matrix. - * - * @return the determinant - */ - public float determinant() { - float fCo00 = m11 * m22 - m12 * m21; - float fCo10 = m12 * m20 - m10 * m22; - float fCo20 = m10 * m21 - m11 * m20; - float fDet = m00 * fCo00 + m01 * fCo10 + m02 * fCo20; - return fDet; - } - - /** - * Sets all of the values in this matrix to zero. - * - * @return this matrix - */ - public Matrix3f zero() { - m00 = m01 = m02 = m10 = m11 = m12 = m20 = m21 = m22 = 0.0f; - return this; - } - - /** - * transpose locally transposes this Matrix. - * This is inconsistent with general value vs local semantics, but is - * preserved for backwards compatibility. Use transposeNew() to transpose - * to a new object (value). - * - * @return this object for chaining. - */ - public Matrix3f transpose() { - return transposeLocal(); - } - - /** - * transposeNew returns a transposed version of this matrix. - * - * @return The new Matrix3f object. - */ - public Matrix3f transposeNew() { - Matrix3f ret = new Matrix3f(m00, m10, m20, m01, m11, m21, m02, m12, m22); - return ret; - } - - /** - * toString returns the string representation of this object. - * It is in a format of a 3x3 matrix. For example, an identity matrix would - * be represented by the following string. com.jme.math.Matrix3f
[
- * 1.0 0.0 0.0
- * 0.0 1.0 0.0
- * 0.0 0.0 1.0
]
- * - * @return the string representation of this object. - */ - @Override - public String toString() { - StringBuilder result = new StringBuilder("Matrix3f\n[\n"); - result.append(" "); - result.append(m00); - result.append(" "); - result.append(m01); - result.append(" "); - result.append(m02); - result.append(" \n"); - result.append(" "); - result.append(m10); - result.append(" "); - result.append(m11); - result.append(" "); - result.append(m12); - result.append(" \n"); - result.append(" "); - result.append(m20); - result.append(" "); - result.append(m21); - result.append(" "); - result.append(m22); - result.append(" \n]"); - return result.toString(); - } - - /** - * - * hashCode returns the hash code value as an integer and is - * supported for the benefit of hashing based collection classes such as - * Hashtable, HashMap, HashSet etc. - * - * @return the hashcode for this instance of Matrix4f. - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - int hash = 37; - hash = 37 * hash + Float.floatToIntBits(m00); - hash = 37 * hash + Float.floatToIntBits(m01); - hash = 37 * hash + Float.floatToIntBits(m02); - - hash = 37 * hash + Float.floatToIntBits(m10); - hash = 37 * hash + Float.floatToIntBits(m11); - hash = 37 * hash + Float.floatToIntBits(m12); - - hash = 37 * hash + Float.floatToIntBits(m20); - hash = 37 * hash + Float.floatToIntBits(m21); - hash = 37 * hash + Float.floatToIntBits(m22); - - return hash; - } - - /** - * are these two matrices the same? they are is they both have the same mXX values. - * - * @param o - * the object to compare for equality - * @return true if they are equal - */ - @Override - public boolean equals(Object o) { - if (!(o instanceof Matrix3f) || o == null) { - return false; - } - - if (this == o) { - return true; - } - - Matrix3f comp = (Matrix3f) o; - if (Float.compare(m00, comp.m00) != 0) { - return false; - } - if (Float.compare(m01, comp.m01) != 0) { - return false; - } - if (Float.compare(m02, comp.m02) != 0) { - return false; - } - - if (Float.compare(m10, comp.m10) != 0) { - return false; - } - if (Float.compare(m11, comp.m11) != 0) { - return false; - } - if (Float.compare(m12, comp.m12) != 0) { - return false; - } - - if (Float.compare(m20, comp.m20) != 0) { - return false; - } - if (Float.compare(m21, comp.m21) != 0) { - return false; - } - if (Float.compare(m22, comp.m22) != 0) { - return false; - } - - return true; - } - - public void write(JmeExporter e) throws IOException { - OutputCapsule cap = e.getCapsule(this); - cap.write(m00, "m00", 1); - cap.write(m01, "m01", 0); - cap.write(m02, "m02", 0); - cap.write(m10, "m10", 0); - cap.write(m11, "m11", 1); - cap.write(m12, "m12", 0); - cap.write(m20, "m20", 0); - cap.write(m21, "m21", 0); - cap.write(m22, "m22", 1); - } - - public void read(JmeImporter e) throws IOException { - InputCapsule cap = e.getCapsule(this); - m00 = cap.readFloat("m00", 1); - m01 = cap.readFloat("m01", 0); - m02 = cap.readFloat("m02", 0); - m10 = cap.readFloat("m10", 0); - m11 = cap.readFloat("m11", 1); - m12 = cap.readFloat("m12", 0); - m20 = cap.readFloat("m20", 0); - m21 = cap.readFloat("m21", 0); - m22 = cap.readFloat("m22", 1); - } - - /** - * A function for creating a rotation matrix that rotates a vector called - * "start" into another vector called "end". - * - * @param start - * normalized non-zero starting vector - * @param end - * normalized non-zero ending vector - * @see "Tomas M�ller, John Hughes \"Efficiently Building a Matrix to Rotate \ - * One Vector to Another\" Journal of Graphics Tools, 4(4):1-4, 1999" - */ - public void fromStartEndVectors(Vector3f start, Vector3f end) { - Vector3f v = new Vector3f(); - float e, h, f; - - start.cross(end, v); - e = start.dot(end); - f = (e < 0) ? -e : e; - - // if "from" and "to" vectors are nearly parallel - if (f > 1.0f - FastMath.ZERO_TOLERANCE) { - Vector3f u = new Vector3f(); - Vector3f x = new Vector3f(); - float c1, c2, c3; /* coefficients for later use */ - int i, j; - - x.x = (start.x > 0.0) ? start.x : -start.x; - x.y = (start.y > 0.0) ? start.y : -start.y; - x.z = (start.z > 0.0) ? start.z : -start.z; - - if (x.x < x.y) { - if (x.x < x.z) { - x.x = 1.0f; - x.y = x.z = 0.0f; - } else { - x.z = 1.0f; - x.x = x.y = 0.0f; - } - } else { - if (x.y < x.z) { - x.y = 1.0f; - x.x = x.z = 0.0f; - } else { - x.z = 1.0f; - x.x = x.y = 0.0f; - } - } - - u.x = x.x - start.x; - u.y = x.y - start.y; - u.z = x.z - start.z; - v.x = x.x - end.x; - v.y = x.y - end.y; - v.z = x.z - end.z; - - c1 = 2.0f / u.dot(u); - c2 = 2.0f / v.dot(v); - c3 = c1 * c2 * u.dot(v); - - for (i = 0; i < 3; i++) { - for (j = 0; j < 3; j++) { - float val = -c1 * u.get(i) * u.get(j) - c2 * v.get(i) - * v.get(j) + c3 * v.get(i) * u.get(j); - set(i, j, val); - } - float val = get(i, i); - set(i, i, val + 1.0f); - } - } else { - // the most common case, unless "start"="end", or "start"=-"end" - float hvx, hvz, hvxy, hvxz, hvyz; - h = 1.0f / (1.0f + e); - hvx = h * v.x; - hvz = h * v.z; - hvxy = hvx * v.y; - hvxz = hvx * v.z; - hvyz = hvz * v.y; - set(0, 0, e + hvx * v.x); - set(0, 1, hvxy - v.z); - set(0, 2, hvxz + v.y); - - set(1, 0, hvxy + v.z); - set(1, 1, e + h * v.y * v.y); - set(1, 2, hvyz - v.x); - - set(2, 0, hvxz - v.y); - set(2, 1, hvyz + v.x); - set(2, 2, e + hvz * v.z); - } - } - - /** - * scale scales the operation performed by this matrix on a - * per-component basis. - * - * @param scale - * The scale applied to each of the X, Y and Z output values. - */ - public void scale(Vector3f scale) { - m00 *= scale.x; - m10 *= scale.x; - m20 *= scale.x; - m01 *= scale.y; - m11 *= scale.y; - m21 *= scale.y; - m02 *= scale.z; - m12 *= scale.z; - m22 *= scale.z; - } - - static boolean equalIdentity(Matrix3f mat) { - if (Math.abs(mat.m00 - 1) > 1e-4) { - return false; - } - if (Math.abs(mat.m11 - 1) > 1e-4) { - return false; - } - if (Math.abs(mat.m22 - 1) > 1e-4) { - return false; - } - - if (Math.abs(mat.m01) > 1e-4) { - return false; - } - if (Math.abs(mat.m02) > 1e-4) { - return false; - } - - if (Math.abs(mat.m10) > 1e-4) { - return false; - } - if (Math.abs(mat.m12) > 1e-4) { - return false; - } - - if (Math.abs(mat.m20) > 1e-4) { - return false; - } - if (Math.abs(mat.m21) > 1e-4) { - return false; - } - - return true; - } - - @Override - public Matrix3f clone() { - try { - return (Matrix3f) super.clone(); - } catch (CloneNotSupportedException e) { - throw new AssertionError(); // can not happen - } - } -} diff --git a/jme3-core/src/main/java/com/jme3/math/Matrix4f.java b/jme3-core/src/main/java/com/jme3/math/Matrix4f.java deleted file mode 100644 index 159e399321..0000000000 --- a/jme3-core/src/main/java/com/jme3/math/Matrix4f.java +++ /dev/null @@ -1,2366 +0,0 @@ -/* - * Copyright (c) 2009-2012 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package com.jme3.math; - -import com.jme3.export.*; -import com.jme3.util.BufferUtils; -import com.jme3.util.TempVars; -import java.io.IOException; -import java.nio.FloatBuffer; -import java.util.logging.Logger; - -/** - * Matrix4f defines and maintains a 4x4 matrix in row major order. - * This matrix is intended for use in a translation and rotational capacity. - * It provides convenience methods for creating the matrix from a multitude - * of sources. - * - * Matrices are stored assuming column vectors on the right, with the translation - * in the rightmost column. Element numbering is row,column, so m03 is the zeroth - * row, third column, which is the "x" translation part. This means that the implicit - * storage order is column major. However, the get() and set() functions on float - * arrays default to row major order! - * - * @author Mark Powell - * @author Joshua Slack - */ -public final class Matrix4f implements Savable, Cloneable, java.io.Serializable { - - static final long serialVersionUID = 1; - - private static final Logger logger = Logger.getLogger(Matrix4f.class.getName()); - public float m00, m01, m02, m03; - public float m10, m11, m12, m13; - public float m20, m21, m22, m23; - public float m30, m31, m32, m33; - public static final Matrix4f ZERO = new Matrix4f(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); - public static final Matrix4f IDENTITY = new Matrix4f(); - - /** - * Constructor instantiates a new Matrix that is set to the - * identity matrix. - * - */ - public Matrix4f() { - loadIdentity(); - } - - /** - * constructs a matrix with the given values. - */ - public Matrix4f(float m00, float m01, float m02, float m03, - float m10, float m11, float m12, float m13, - float m20, float m21, float m22, float m23, - float m30, float m31, float m32, float m33) { - - this.m00 = m00; - this.m01 = m01; - this.m02 = m02; - this.m03 = m03; - this.m10 = m10; - this.m11 = m11; - this.m12 = m12; - this.m13 = m13; - this.m20 = m20; - this.m21 = m21; - this.m22 = m22; - this.m23 = m23; - this.m30 = m30; - this.m31 = m31; - this.m32 = m32; - this.m33 = m33; - } - - /** - * Create a new Matrix4f, given data in column-major format. - * - * @param array - * An array of 16 floats in column-major format (translation in elements 12, 13 and 14). - */ - public Matrix4f(float[] array) { - set(array, false); - } - - /** - * Constructor instantiates a new Matrix that is set to the - * provided matrix. This constructor copies a given Matrix. If the provided - * matrix is null, the constructor sets the matrix to the identity. - * - * @param mat - * the matrix to copy. - */ - public Matrix4f(Matrix4f mat) { - copy(mat); - } - - /** - * copy transfers the contents of a given matrix to this - * matrix. If a null matrix is supplied, this matrix is set to the identity - * matrix. - * - * @param matrix - * the matrix to copy. - */ - public void copy(Matrix4f matrix) { - if (null == matrix) { - loadIdentity(); - } else { - m00 = matrix.m00; - m01 = matrix.m01; - m02 = matrix.m02; - m03 = matrix.m03; - m10 = matrix.m10; - m11 = matrix.m11; - m12 = matrix.m12; - m13 = matrix.m13; - m20 = matrix.m20; - m21 = matrix.m21; - m22 = matrix.m22; - m23 = matrix.m23; - m30 = matrix.m30; - m31 = matrix.m31; - m32 = matrix.m32; - m33 = matrix.m33; - } - } - - public void fromFrame(Vector3f location, Vector3f direction, Vector3f up, Vector3f left) { - TempVars vars = TempVars.get(); - try { - Vector3f fwdVector = vars.vect1.set(direction); - Vector3f leftVector = vars.vect2.set(fwdVector).crossLocal(up); - Vector3f upVector = vars.vect3.set(leftVector).crossLocal(fwdVector); - - m00 = leftVector.x; - m01 = leftVector.y; - m02 = leftVector.z; - m03 = -leftVector.dot(location); - - m10 = upVector.x; - m11 = upVector.y; - m12 = upVector.z; - m13 = -upVector.dot(location); - - m20 = -fwdVector.x; - m21 = -fwdVector.y; - m22 = -fwdVector.z; - m23 = fwdVector.dot(location); - - m30 = 0f; - m31 = 0f; - m32 = 0f; - m33 = 1f; - } finally { - vars.release(); - } - } - - /** - * get retrieves the values of this object into - * a float array in row-major order. - * - * @param matrix - * the matrix to set the values into. - */ - public void get(float[] matrix) { - get(matrix, true); - } - - /** - * set retrieves the values of this object into - * a float array. - * - * @param matrix - * the matrix to set the values into. - * @param rowMajor - * whether the outgoing data is in row or column major order. - */ - public void get(float[] matrix, boolean rowMajor) { - if (matrix.length != 16) { - throw new IllegalArgumentException( - "Array must be of size 16."); - } - - if (rowMajor) { - matrix[0] = m00; - matrix[1] = m01; - matrix[2] = m02; - matrix[3] = m03; - matrix[4] = m10; - matrix[5] = m11; - matrix[6] = m12; - matrix[7] = m13; - matrix[8] = m20; - matrix[9] = m21; - matrix[10] = m22; - matrix[11] = m23; - matrix[12] = m30; - matrix[13] = m31; - matrix[14] = m32; - matrix[15] = m33; - } else { - matrix[0] = m00; - matrix[4] = m01; - matrix[8] = m02; - matrix[12] = m03; - matrix[1] = m10; - matrix[5] = m11; - matrix[9] = m12; - matrix[13] = m13; - matrix[2] = m20; - matrix[6] = m21; - matrix[10] = m22; - matrix[14] = m23; - matrix[3] = m30; - matrix[7] = m31; - matrix[11] = m32; - matrix[15] = m33; - } - } - - /** - * get retrieves a value from the matrix at the given - * position. If the position is invalid a JmeException is - * thrown. - * - * @param i - * the row index. - * @param j - * the colum index. - * @return the value at (i, j). - */ - @SuppressWarnings("fallthrough") - public float get(int i, int j) { - switch (i) { - case 0: - switch (j) { - case 0: - return m00; - case 1: - return m01; - case 2: - return m02; - case 3: - return m03; - } - case 1: - switch (j) { - case 0: - return m10; - case 1: - return m11; - case 2: - return m12; - case 3: - return m13; - } - case 2: - switch (j) { - case 0: - return m20; - case 1: - return m21; - case 2: - return m22; - case 3: - return m23; - } - case 3: - switch (j) { - case 0: - return m30; - case 1: - return m31; - case 2: - return m32; - case 3: - return m33; - } - } - - logger.warning("Invalid matrix index."); - throw new IllegalArgumentException("Invalid indices into matrix."); - } - - /** - * getColumn returns one of three columns specified by the - * parameter. This column is returned as a float array of length 4. - * - * @param i - * the column to retrieve. Must be between 0 and 3. - * @return the column specified by the index. - */ - public float[] getColumn(int i) { - return getColumn(i, null); - } - - /** - * getColumn returns one of three columns specified by the - * parameter. This column is returned as a float[4]. - * - * @param i - * the column to retrieve. Must be between 0 and 3. - * @param store - * the float array to store the result in. if null, a new one - * is created. - * @return the column specified by the index. - */ - public float[] getColumn(int i, float[] store) { - if (store == null) { - store = new float[4]; - } - switch (i) { - case 0: - store[0] = m00; - store[1] = m10; - store[2] = m20; - store[3] = m30; - break; - case 1: - store[0] = m01; - store[1] = m11; - store[2] = m21; - store[3] = m31; - break; - case 2: - store[0] = m02; - store[1] = m12; - store[2] = m22; - store[3] = m32; - break; - case 3: - store[0] = m03; - store[1] = m13; - store[2] = m23; - store[3] = m33; - break; - default: - logger.warning("Invalid column index."); - throw new IllegalArgumentException("Invalid column index. " + i); - } - return store; - } - - /** - * - * setColumn sets a particular column of this matrix to that - * represented by the provided vector. - * - * @param i - * the column to set. - * @param column - * the data to set. - */ - public void setColumn(int i, float[] column) { - - if (column == null) { - logger.warning("Column is null. Ignoring."); - return; - } - switch (i) { - case 0: - m00 = column[0]; - m10 = column[1]; - m20 = column[2]; - m30 = column[3]; - break; - case 1: - m01 = column[0]; - m11 = column[1]; - m21 = column[2]; - m31 = column[3]; - break; - case 2: - m02 = column[0]; - m12 = column[1]; - m22 = column[2]; - m32 = column[3]; - break; - case 3: - m03 = column[0]; - m13 = column[1]; - m23 = column[2]; - m33 = column[3]; - break; - default: - logger.warning("Invalid column index."); - throw new IllegalArgumentException("Invalid column index. " + i); - } - } - - /** - * set places a given value into the matrix at the given - * position. If the position is invalid a JmeException is - * thrown. - * - * @param i - * the row index. - * @param j - * the colum index. - * @param value - * the value for (i, j). - */ - @SuppressWarnings("fallthrough") - public void set(int i, int j, float value) { - switch (i) { - case 0: - switch (j) { - case 0: - m00 = value; - return; - case 1: - m01 = value; - return; - case 2: - m02 = value; - return; - case 3: - m03 = value; - return; - } - case 1: - switch (j) { - case 0: - m10 = value; - return; - case 1: - m11 = value; - return; - case 2: - m12 = value; - return; - case 3: - m13 = value; - return; - } - case 2: - switch (j) { - case 0: - m20 = value; - return; - case 1: - m21 = value; - return; - case 2: - m22 = value; - return; - case 3: - m23 = value; - return; - } - case 3: - switch (j) { - case 0: - m30 = value; - return; - case 1: - m31 = value; - return; - case 2: - m32 = value; - return; - case 3: - m33 = value; - return; - } - } - - logger.warning("Invalid matrix index."); - throw new IllegalArgumentException("Invalid indices into matrix."); - } - - /** - * set sets the values of this matrix from an array of - * values. - * - * @param matrix - * the matrix to set the value to. - * @throws JmeException - * if the array is not of size 16. - */ - public void set(float[][] matrix) { - if (matrix.length != 4 || matrix[0].length != 4) { - throw new IllegalArgumentException( - "Array must be of size 16."); - } - - m00 = matrix[0][0]; - m01 = matrix[0][1]; - m02 = matrix[0][2]; - m03 = matrix[0][3]; - m10 = matrix[1][0]; - m11 = matrix[1][1]; - m12 = matrix[1][2]; - m13 = matrix[1][3]; - m20 = matrix[2][0]; - m21 = matrix[2][1]; - m22 = matrix[2][2]; - m23 = matrix[2][3]; - m30 = matrix[3][0]; - m31 = matrix[3][1]; - m32 = matrix[3][2]; - m33 = matrix[3][3]; - } - - - /** - * Sets the values of this matrix - */ - public void set(float m00, float m01, float m02, float m03, - float m10, float m11, float m12, float m13, - float m20, float m21, float m22, float m23, - float m30, float m31, float m32, float m33) { - - this.m00 = m00; - this.m01 = m01; - this.m02 = m02; - this.m03 = m03; - this.m10 = m10; - this.m11 = m11; - this.m12 = m12; - this.m13 = m13; - this.m20 = m20; - this.m21 = m21; - this.m22 = m22; - this.m23 = m23; - this.m30 = m30; - this.m31 = m31; - this.m32 = m32; - this.m33 = m33; - } - - /** - * set sets the values of this matrix from another matrix. - * - * @param matrix - * the matrix to read the value from. - */ - public Matrix4f set(Matrix4f matrix) { - m00 = matrix.m00; - m01 = matrix.m01; - m02 = matrix.m02; - m03 = matrix.m03; - m10 = matrix.m10; - m11 = matrix.m11; - m12 = matrix.m12; - m13 = matrix.m13; - m20 = matrix.m20; - m21 = matrix.m21; - m22 = matrix.m22; - m23 = matrix.m23; - m30 = matrix.m30; - m31 = matrix.m31; - m32 = matrix.m32; - m33 = matrix.m33; - return this; - } - - /** - * set sets the values of this matrix from an array of - * values assuming that the data is rowMajor order; - * - * @param matrix - * the matrix to set the value to. - */ - public void set(float[] matrix) { - set(matrix, true); - } - - /** - * set sets the values of this matrix from an array of - * values; - * - * @param matrix - * the matrix to set the value to. - * @param rowMajor - * whether the incoming data is in row or column major order. - */ - public void set(float[] matrix, boolean rowMajor) { - if (matrix.length != 16) { - throw new IllegalArgumentException( - "Array must be of size 16."); - } - - if (rowMajor) { - m00 = matrix[0]; - m01 = matrix[1]; - m02 = matrix[2]; - m03 = matrix[3]; - m10 = matrix[4]; - m11 = matrix[5]; - m12 = matrix[6]; - m13 = matrix[7]; - m20 = matrix[8]; - m21 = matrix[9]; - m22 = matrix[10]; - m23 = matrix[11]; - m30 = matrix[12]; - m31 = matrix[13]; - m32 = matrix[14]; - m33 = matrix[15]; - } else { - m00 = matrix[0]; - m01 = matrix[4]; - m02 = matrix[8]; - m03 = matrix[12]; - m10 = matrix[1]; - m11 = matrix[5]; - m12 = matrix[9]; - m13 = matrix[13]; - m20 = matrix[2]; - m21 = matrix[6]; - m22 = matrix[10]; - m23 = matrix[14]; - m30 = matrix[3]; - m31 = matrix[7]; - m32 = matrix[11]; - m33 = matrix[15]; - } - } - - public Matrix4f transpose() { - float[] tmp = new float[16]; - get(tmp, true); - Matrix4f mat = new Matrix4f(tmp); - return mat; - } - - /** - * transpose locally transposes this Matrix. - * - * @return this object for chaining. - */ - public Matrix4f transposeLocal() { - float tmp = m01; - m01 = m10; - m10 = tmp; - - tmp = m02; - m02 = m20; - m20 = tmp; - - tmp = m03; - m03 = m30; - m30 = tmp; - - tmp = m12; - m12 = m21; - m21 = tmp; - - tmp = m13; - m13 = m31; - m31 = tmp; - - tmp = m23; - m23 = m32; - m32 = tmp; - - return this; - } - - /** - * toFloatBuffer returns a FloatBuffer object that contains - * the matrix data. - * - * @return matrix data as a FloatBuffer. - */ - public FloatBuffer toFloatBuffer() { - return toFloatBuffer(false); - } - - /** - * toFloatBuffer returns a FloatBuffer object that contains the - * matrix data. - * - * @param columnMajor - * if true, this buffer should be filled with column major data, - * otherwise it will be filled row major. - * @return matrix data as a FloatBuffer. The position is set to 0 for - * convenience. - */ - public FloatBuffer toFloatBuffer(boolean columnMajor) { - FloatBuffer fb = BufferUtils.createFloatBuffer(16); - fillFloatBuffer(fb, columnMajor); - fb.rewind(); - return fb; - } - - /** - * fillFloatBuffer fills a FloatBuffer object with - * the matrix data. - * @param fb the buffer to fill, must be correct size - * @return matrix data as a FloatBuffer. - */ - public FloatBuffer fillFloatBuffer(FloatBuffer fb) { - return fillFloatBuffer(fb, false); - } - - /** - * fillFloatBuffer fills a FloatBuffer object with the matrix - * data. - * - * @param fb - * the buffer to fill, starting at current position. Must have - * room for 16 more floats. - * @param columnMajor - * if true, this buffer should be filled with column major data, - * otherwise it will be filled row major. - * @return matrix data as a FloatBuffer. (position is advanced by 16 and any - * limit set is not changed). - */ - public FloatBuffer fillFloatBuffer(FloatBuffer fb, boolean columnMajor) { -// if (columnMajor) { -// fb.put(m00).put(m10).put(m20).put(m30); -// fb.put(m01).put(m11).put(m21).put(m31); -// fb.put(m02).put(m12).put(m22).put(m32); -// fb.put(m03).put(m13).put(m23).put(m33); -// } else { -// fb.put(m00).put(m01).put(m02).put(m03); -// fb.put(m10).put(m11).put(m12).put(m13); -// fb.put(m20).put(m21).put(m22).put(m23); -// fb.put(m30).put(m31).put(m32).put(m33); -// } - - TempVars vars = TempVars.get(); - - - fillFloatArray(vars.matrixWrite, columnMajor); - fb.put(vars.matrixWrite, 0, 16); - - vars.release(); - - return fb; - } - - public void fillFloatArray(float[] f, boolean columnMajor) { - if (columnMajor) { - f[ 0] = m00; - f[ 1] = m10; - f[ 2] = m20; - f[ 3] = m30; - f[ 4] = m01; - f[ 5] = m11; - f[ 6] = m21; - f[ 7] = m31; - f[ 8] = m02; - f[ 9] = m12; - f[10] = m22; - f[11] = m32; - f[12] = m03; - f[13] = m13; - f[14] = m23; - f[15] = m33; - } else { - f[ 0] = m00; - f[ 1] = m01; - f[ 2] = m02; - f[ 3] = m03; - f[ 4] = m10; - f[ 5] = m11; - f[ 6] = m12; - f[ 7] = m13; - f[ 8] = m20; - f[ 9] = m21; - f[10] = m22; - f[11] = m23; - f[12] = m30; - f[13] = m31; - f[14] = m32; - f[15] = m33; - } - } - - /** - * readFloatBuffer reads value for this matrix from a FloatBuffer. - * @param fb the buffer to read from, must be correct size - * @return this data as a FloatBuffer. - */ - public Matrix4f readFloatBuffer(FloatBuffer fb) { - return readFloatBuffer(fb, false); - } - - /** - * readFloatBuffer reads value for this matrix from a FloatBuffer. - * @param fb the buffer to read from, must be correct size - * @param columnMajor if true, this buffer should be filled with column - * major data, otherwise it will be filled row major. - * @return this data as a FloatBuffer. - */ - public Matrix4f readFloatBuffer(FloatBuffer fb, boolean columnMajor) { - - if (columnMajor) { - m00 = fb.get(); - m10 = fb.get(); - m20 = fb.get(); - m30 = fb.get(); - m01 = fb.get(); - m11 = fb.get(); - m21 = fb.get(); - m31 = fb.get(); - m02 = fb.get(); - m12 = fb.get(); - m22 = fb.get(); - m32 = fb.get(); - m03 = fb.get(); - m13 = fb.get(); - m23 = fb.get(); - m33 = fb.get(); - } else { - m00 = fb.get(); - m01 = fb.get(); - m02 = fb.get(); - m03 = fb.get(); - m10 = fb.get(); - m11 = fb.get(); - m12 = fb.get(); - m13 = fb.get(); - m20 = fb.get(); - m21 = fb.get(); - m22 = fb.get(); - m23 = fb.get(); - m30 = fb.get(); - m31 = fb.get(); - m32 = fb.get(); - m33 = fb.get(); - } - return this; - } - - /** - * loadIdentity sets this matrix to the identity matrix, - * namely all zeros with ones along the diagonal. - * - */ - public void loadIdentity() { - m01 = m02 = m03 = 0.0f; - m10 = m12 = m13 = 0.0f; - m20 = m21 = m23 = 0.0f; - m30 = m31 = m32 = 0.0f; - m00 = m11 = m22 = m33 = 1.0f; - } - - public void fromFrustum(float near, float far, float left, float right, float top, float bottom, boolean parallel) { - loadIdentity(); - if (parallel) { - // scale - m00 = 2.0f / (right - left); - //m11 = 2.0f / (bottom - top); - m11 = 2.0f / (top - bottom); - m22 = -2.0f / (far - near); - m33 = 1f; - - // translation - m03 = -(right + left) / (right - left); - //m31 = -(bottom + top) / (bottom - top); - m13 = -(top + bottom) / (top - bottom); - m23 = -(far + near) / (far - near); - } else { - m00 = (2.0f * near) / (right - left); - m11 = (2.0f * near) / (top - bottom); - m32 = -1.0f; - m33 = -0.0f; - - // A - m02 = (right + left) / (right - left); - - // B - m12 = (top + bottom) / (top - bottom); - - // C - m22 = -(far + near) / (far - near); - - // D - m23 = -(2.0f * far * near) / (far - near); - } - } - - /** - * fromAngleAxis sets this matrix4f to the values specified - * by an angle and an axis of rotation. This method creates an object, so - * use fromAngleNormalAxis if your axis is already normalized. - * - * @param angle - * the angle to rotate (in radians). - * @param axis - * the axis of rotation. - */ - public void fromAngleAxis(float angle, Vector3f axis) { - Vector3f normAxis = axis.normalize(); - fromAngleNormalAxis(angle, normAxis); - } - - /** - * fromAngleNormalAxis sets this matrix4f to the values - * specified by an angle and a normalized axis of rotation. - * - * @param angle - * the angle to rotate (in radians). - * @param axis - * the axis of rotation (already normalized). - */ - public void fromAngleNormalAxis(float angle, Vector3f axis) { - zero(); - m33 = 1; - - float fCos = FastMath.cos(angle); - float fSin = FastMath.sin(angle); - float fOneMinusCos = ((float) 1.0) - fCos; - float fX2 = axis.x * axis.x; - float fY2 = axis.y * axis.y; - float fZ2 = axis.z * axis.z; - float fXYM = axis.x * axis.y * fOneMinusCos; - float fXZM = axis.x * axis.z * fOneMinusCos; - float fYZM = axis.y * axis.z * fOneMinusCos; - float fXSin = axis.x * fSin; - float fYSin = axis.y * fSin; - float fZSin = axis.z * fSin; - - m00 = fX2 * fOneMinusCos + fCos; - m01 = fXYM - fZSin; - m02 = fXZM + fYSin; - m10 = fXYM + fZSin; - m11 = fY2 * fOneMinusCos + fCos; - m12 = fYZM - fXSin; - m20 = fXZM - fYSin; - m21 = fYZM + fXSin; - m22 = fZ2 * fOneMinusCos + fCos; - } - - /** - * mult multiplies this matrix by a scalar. - * - * @param scalar - * the scalar to multiply this matrix by. - */ - public void multLocal(float scalar) { - m00 *= scalar; - m01 *= scalar; - m02 *= scalar; - m03 *= scalar; - m10 *= scalar; - m11 *= scalar; - m12 *= scalar; - m13 *= scalar; - m20 *= scalar; - m21 *= scalar; - m22 *= scalar; - m23 *= scalar; - m30 *= scalar; - m31 *= scalar; - m32 *= scalar; - m33 *= scalar; - } - - public Matrix4f mult(float scalar) { - Matrix4f out = new Matrix4f(); - out.set(this); - out.multLocal(scalar); - return out; - } - - public Matrix4f mult(float scalar, Matrix4f store) { - store.set(this); - store.multLocal(scalar); - return store; - } - - /** - * mult multiplies this matrix with another matrix. The - * result matrix will then be returned. This matrix will be on the left hand - * side, while the parameter matrix will be on the right. - * - * @param in2 - * the matrix to multiply this matrix by. - * @return the resultant matrix - */ - public Matrix4f mult(Matrix4f in2) { - return mult(in2, null); - } - - /** - * mult multiplies this matrix with another matrix. The - * result matrix will then be returned. This matrix will be on the left hand - * side, while the parameter matrix will be on the right. - * - * @param in2 - * the matrix to multiply this matrix by. - * @param store - * where to store the result. It is safe for in2 and store to be - * the same object. - * @return the resultant matrix - */ - public Matrix4f mult(Matrix4f in2, Matrix4f store) { - if (store == null) { - store = new Matrix4f(); - } - - float temp00, temp01, temp02, temp03; - float temp10, temp11, temp12, temp13; - float temp20, temp21, temp22, temp23; - float temp30, temp31, temp32, temp33; - - temp00 = m00 * in2.m00 - + m01 * in2.m10 - + m02 * in2.m20 - + m03 * in2.m30; - temp01 = m00 * in2.m01 - + m01 * in2.m11 - + m02 * in2.m21 - + m03 * in2.m31; - temp02 = m00 * in2.m02 - + m01 * in2.m12 - + m02 * in2.m22 - + m03 * in2.m32; - temp03 = m00 * in2.m03 - + m01 * in2.m13 - + m02 * in2.m23 - + m03 * in2.m33; - - temp10 = m10 * in2.m00 - + m11 * in2.m10 - + m12 * in2.m20 - + m13 * in2.m30; - temp11 = m10 * in2.m01 - + m11 * in2.m11 - + m12 * in2.m21 - + m13 * in2.m31; - temp12 = m10 * in2.m02 - + m11 * in2.m12 - + m12 * in2.m22 - + m13 * in2.m32; - temp13 = m10 * in2.m03 - + m11 * in2.m13 - + m12 * in2.m23 - + m13 * in2.m33; - - temp20 = m20 * in2.m00 - + m21 * in2.m10 - + m22 * in2.m20 - + m23 * in2.m30; - temp21 = m20 * in2.m01 - + m21 * in2.m11 - + m22 * in2.m21 - + m23 * in2.m31; - temp22 = m20 * in2.m02 - + m21 * in2.m12 - + m22 * in2.m22 - + m23 * in2.m32; - temp23 = m20 * in2.m03 - + m21 * in2.m13 - + m22 * in2.m23 - + m23 * in2.m33; - - temp30 = m30 * in2.m00 - + m31 * in2.m10 - + m32 * in2.m20 - + m33 * in2.m30; - temp31 = m30 * in2.m01 - + m31 * in2.m11 - + m32 * in2.m21 - + m33 * in2.m31; - temp32 = m30 * in2.m02 - + m31 * in2.m12 - + m32 * in2.m22 - + m33 * in2.m32; - temp33 = m30 * in2.m03 - + m31 * in2.m13 - + m32 * in2.m23 - + m33 * in2.m33; - - store.m00 = temp00; - store.m01 = temp01; - store.m02 = temp02; - store.m03 = temp03; - store.m10 = temp10; - store.m11 = temp11; - store.m12 = temp12; - store.m13 = temp13; - store.m20 = temp20; - store.m21 = temp21; - store.m22 = temp22; - store.m23 = temp23; - store.m30 = temp30; - store.m31 = temp31; - store.m32 = temp32; - store.m33 = temp33; - - return store; - } - - /** - * mult multiplies this matrix with another matrix. The - * results are stored internally and a handle to this matrix will - * then be returned. This matrix will be on the left hand - * side, while the parameter matrix will be on the right. - * - * @param in2 - * the matrix to multiply this matrix by. - * @return the resultant matrix - */ - public Matrix4f multLocal(Matrix4f in2) { - return mult(in2, this); - } - - /** - * mult multiplies a vector about a rotation matrix. The - * resulting vector is returned as a new Vector3f. - * - * @param vec - * vec to multiply against. - * @return the rotated vector. - */ - public Vector3f mult(Vector3f vec) { - return mult(vec, null); - } - - /** - * mult multiplies a vector about a rotation matrix and adds - * translation. The resulting vector is returned. - * - * @param vec - * vec to multiply against. - * @param store - * a vector to store the result in. Created if null is passed. - * @return the rotated vector. - */ - public Vector3f mult(Vector3f vec, Vector3f store) { - if (store == null) { - store = new Vector3f(); - } - - float vx = vec.x, vy = vec.y, vz = vec.z; - store.x = m00 * vx + m01 * vy + m02 * vz + m03; - store.y = m10 * vx + m11 * vy + m12 * vz + m13; - store.z = m20 * vx + m21 * vy + m22 * vz + m23; - - return store; - } - - /** - * mult multiplies a Vector4f about a rotation - * matrix. The resulting vector is returned as a new Vector4f. - * - * @param vec - * vec to multiply against. - * @return the rotated vector. - */ - public Vector4f mult(Vector4f vec) { - return mult(vec, null); - } - - /** - * mult multiplies a Vector4f about a rotation - * matrix. The resulting vector is returned. - * - * @param vec - * vec to multiply against. - * @param store - * a vector to store the result in. Created if null is passed. - * @return the rotated vector. - */ - public Vector4f mult(Vector4f vec, Vector4f store) { - if (null == vec) { - logger.warning("Source vector is null, null result returned."); - return null; - } - if (store == null) { - store = new Vector4f(); - } - - float vx = vec.x, vy = vec.y, vz = vec.z, vw = vec.w; - store.x = m00 * vx + m01 * vy + m02 * vz + m03 * vw; - store.y = m10 * vx + m11 * vy + m12 * vz + m13 * vw; - store.z = m20 * vx + m21 * vy + m22 * vz + m23 * vw; - store.w = m30 * vx + m31 * vy + m32 * vz + m33 * vw; - - return store; - } - - /** - * mult multiplies a vector about a rotation matrix. The - * resulting vector is returned. - * - * @param vec - * vec to multiply against. - * - * @return the rotated vector. - */ - public Vector4f multAcross(Vector4f vec) { - return multAcross(vec, null); - } - - /** - * mult multiplies a vector about a rotation matrix. The - * resulting vector is returned. - * - * @param vec - * vec to multiply against. - * @param store - * a vector to store the result in. created if null is passed. - * @return the rotated vector. - */ - public Vector4f multAcross(Vector4f vec, Vector4f store) { - if (null == vec) { - logger.warning("Source vector is null, null result returned."); - return null; - } - if (store == null) { - store = new Vector4f(); - } - - float vx = vec.x, vy = vec.y, vz = vec.z, vw = vec.w; - store.x = m00 * vx + m10 * vy + m20 * vz + m30 * vw; - store.y = m01 * vx + m11 * vy + m21 * vz + m31 * vw; - store.z = m02 * vx + m12 * vy + m22 * vz + m32 * vw; - store.w = m03 * vx + m13 * vy + m23 * vz + m33 * vw; - - return store; - } - - /** - * multNormal multiplies a vector about a rotation matrix, but - * does not add translation. The resulting vector is returned. - * - * @param vec - * vec to multiply against. - * @param store - * a vector to store the result in. Created if null is passed. - * @return the rotated vector. - */ - public Vector3f multNormal(Vector3f vec, Vector3f store) { - if (store == null) { - store = new Vector3f(); - } - - float vx = vec.x, vy = vec.y, vz = vec.z; - store.x = m00 * vx + m01 * vy + m02 * vz; - store.y = m10 * vx + m11 * vy + m12 * vz; - store.z = m20 * vx + m21 * vy + m22 * vz; - - return store; - } - - /** - * multNormal multiplies a vector about a rotation matrix, but - * does not add translation. The resulting vector is returned. - * - * @param vec - * vec to multiply against. - * @param store - * a vector to store the result in. Created if null is passed. - * @return the rotated vector. - */ - public Vector3f multNormalAcross(Vector3f vec, Vector3f store) { - if (store == null) { - store = new Vector3f(); - } - - float vx = vec.x, vy = vec.y, vz = vec.z; - store.x = m00 * vx + m10 * vy + m20 * vz; - store.y = m01 * vx + m11 * vy + m21 * vz; - store.z = m02 * vx + m12 * vy + m22 * vz; - - return store; - } - - /** - * mult multiplies a vector about a rotation matrix and adds - * translation. The w value is returned as a result of - * multiplying the last column of the matrix by 1.0 - * - * @param vec - * vec to multiply against. - * @param store - * a vector to store the result in. - * @return the W value - */ - public float multProj(Vector3f vec, Vector3f store) { - float vx = vec.x, vy = vec.y, vz = vec.z; - store.x = m00 * vx + m01 * vy + m02 * vz + m03; - store.y = m10 * vx + m11 * vy + m12 * vz + m13; - store.z = m20 * vx + m21 * vy + m22 * vz + m23; - return m30 * vx + m31 * vy + m32 * vz + m33; - } - - /** - * mult multiplies a vector about a rotation matrix. The - * resulting vector is returned. - * - * @param vec - * vec to multiply against. - * @param store - * a vector to store the result in. created if null is passed. - * @return the rotated vector. - */ - public Vector3f multAcross(Vector3f vec, Vector3f store) { - if (null == vec) { - logger.warning("Source vector is null, null result returned."); - return null; - } - if (store == null) { - store = new Vector3f(); - } - - float vx = vec.x, vy = vec.y, vz = vec.z; - store.x = m00 * vx + m10 * vy + m20 * vz + m30 * 1; - store.y = m01 * vx + m11 * vy + m21 * vz + m31 * 1; - store.z = m02 * vx + m12 * vy + m22 * vz + m32 * 1; - - return store; - } - - /** - * mult multiplies a quaternion about a matrix. The - * resulting vector is returned. - * - * @param vec - * vec to multiply against. - * @param store - * a quaternion to store the result in. created if null is passed. - * @return store = this * vec - */ - public Quaternion mult(Quaternion vec, Quaternion store) { - - if (null == vec) { - logger.warning("Source vector is null, null result returned."); - return null; - } - if (store == null) { - store = new Quaternion(); - } - - float x = m00 * vec.x + m10 * vec.y + m20 * vec.z + m30 * vec.w; - float y = m01 * vec.x + m11 * vec.y + m21 * vec.z + m31 * vec.w; - float z = m02 * vec.x + m12 * vec.y + m22 * vec.z + m32 * vec.w; - float w = m03 * vec.x + m13 * vec.y + m23 * vec.z + m33 * vec.w; - store.x = x; - store.y = y; - store.z = z; - store.w = w; - - return store; - } - - /** - * mult multiplies an array of 4 floats against this rotation - * matrix. The results are stored directly in the array. (vec4f x mat4f) - * - * @param vec4f - * float array (size 4) to multiply against the matrix. - * @return the vec4f for chaining. - */ - public float[] mult(float[] vec4f) { - if (null == vec4f || vec4f.length != 4) { - logger.warning("invalid array given, must be nonnull and length 4"); - return null; - } - - float x = vec4f[0], y = vec4f[1], z = vec4f[2], w = vec4f[3]; - - vec4f[0] = m00 * x + m01 * y + m02 * z + m03 * w; - vec4f[1] = m10 * x + m11 * y + m12 * z + m13 * w; - vec4f[2] = m20 * x + m21 * y + m22 * z + m23 * w; - vec4f[3] = m30 * x + m31 * y + m32 * z + m33 * w; - - return vec4f; - } - - /** - * mult multiplies an array of 4 floats against this rotation - * matrix. The results are stored directly in the array. (vec4f x mat4f) - * - * @param vec4f - * float array (size 4) to multiply against the matrix. - * @return the vec4f for chaining. - */ - public float[] multAcross(float[] vec4f) { - if (null == vec4f || vec4f.length != 4) { - logger.warning("invalid array given, must be nonnull and length 4"); - return null; - } - - float x = vec4f[0], y = vec4f[1], z = vec4f[2], w = vec4f[3]; - - vec4f[0] = m00 * x + m10 * y + m20 * z + m30 * w; - vec4f[1] = m01 * x + m11 * y + m21 * z + m31 * w; - vec4f[2] = m02 * x + m12 * y + m22 * z + m32 * w; - vec4f[3] = m03 * x + m13 * y + m23 * z + m33 * w; - - return vec4f; - } - - /** - * Inverts this matrix as a new Matrix4f. - * - * @return The new inverse matrix - */ - public Matrix4f invert() { - return invert(null); - } - - /** - * Inverts this matrix and stores it in the given store. - * - * @return The store - */ - public Matrix4f invert(Matrix4f store) { - if (store == null) { - store = new Matrix4f(); - } - - float fA0 = m00 * m11 - m01 * m10; - float fA1 = m00 * m12 - m02 * m10; - float fA2 = m00 * m13 - m03 * m10; - float fA3 = m01 * m12 - m02 * m11; - float fA4 = m01 * m13 - m03 * m11; - float fA5 = m02 * m13 - m03 * m12; - float fB0 = m20 * m31 - m21 * m30; - float fB1 = m20 * m32 - m22 * m30; - float fB2 = m20 * m33 - m23 * m30; - float fB3 = m21 * m32 - m22 * m31; - float fB4 = m21 * m33 - m23 * m31; - float fB5 = m22 * m33 - m23 * m32; - float fDet = fA0 * fB5 - fA1 * fB4 + fA2 * fB3 + fA3 * fB2 - fA4 * fB1 + fA5 * fB0; - - if (FastMath.abs(fDet) <= 0f) { - throw new ArithmeticException("This matrix cannot be inverted"); - } - - store.m00 = +m11 * fB5 - m12 * fB4 + m13 * fB3; - store.m10 = -m10 * fB5 + m12 * fB2 - m13 * fB1; - store.m20 = +m10 * fB4 - m11 * fB2 + m13 * fB0; - store.m30 = -m10 * fB3 + m11 * fB1 - m12 * fB0; - store.m01 = -m01 * fB5 + m02 * fB4 - m03 * fB3; - store.m11 = +m00 * fB5 - m02 * fB2 + m03 * fB1; - store.m21 = -m00 * fB4 + m01 * fB2 - m03 * fB0; - store.m31 = +m00 * fB3 - m01 * fB1 + m02 * fB0; - store.m02 = +m31 * fA5 - m32 * fA4 + m33 * fA3; - store.m12 = -m30 * fA5 + m32 * fA2 - m33 * fA1; - store.m22 = +m30 * fA4 - m31 * fA2 + m33 * fA0; - store.m32 = -m30 * fA3 + m31 * fA1 - m32 * fA0; - store.m03 = -m21 * fA5 + m22 * fA4 - m23 * fA3; - store.m13 = +m20 * fA5 - m22 * fA2 + m23 * fA1; - store.m23 = -m20 * fA4 + m21 * fA2 - m23 * fA0; - store.m33 = +m20 * fA3 - m21 * fA1 + m22 * fA0; - - float fInvDet = 1.0f / fDet; - store.multLocal(fInvDet); - - return store; - } - - /** - * Inverts this matrix locally. - * - * @return this - */ - public Matrix4f invertLocal() { - - float fA0 = m00 * m11 - m01 * m10; - float fA1 = m00 * m12 - m02 * m10; - float fA2 = m00 * m13 - m03 * m10; - float fA3 = m01 * m12 - m02 * m11; - float fA4 = m01 * m13 - m03 * m11; - float fA5 = m02 * m13 - m03 * m12; - float fB0 = m20 * m31 - m21 * m30; - float fB1 = m20 * m32 - m22 * m30; - float fB2 = m20 * m33 - m23 * m30; - float fB3 = m21 * m32 - m22 * m31; - float fB4 = m21 * m33 - m23 * m31; - float fB5 = m22 * m33 - m23 * m32; - float fDet = fA0 * fB5 - fA1 * fB4 + fA2 * fB3 + fA3 * fB2 - fA4 * fB1 + fA5 * fB0; - - if (FastMath.abs(fDet) <= 0f) { - return zero(); - } - - float f00 = +m11 * fB5 - m12 * fB4 + m13 * fB3; - float f10 = -m10 * fB5 + m12 * fB2 - m13 * fB1; - float f20 = +m10 * fB4 - m11 * fB2 + m13 * fB0; - float f30 = -m10 * fB3 + m11 * fB1 - m12 * fB0; - float f01 = -m01 * fB5 + m02 * fB4 - m03 * fB3; - float f11 = +m00 * fB5 - m02 * fB2 + m03 * fB1; - float f21 = -m00 * fB4 + m01 * fB2 - m03 * fB0; - float f31 = +m00 * fB3 - m01 * fB1 + m02 * fB0; - float f02 = +m31 * fA5 - m32 * fA4 + m33 * fA3; - float f12 = -m30 * fA5 + m32 * fA2 - m33 * fA1; - float f22 = +m30 * fA4 - m31 * fA2 + m33 * fA0; - float f32 = -m30 * fA3 + m31 * fA1 - m32 * fA0; - float f03 = -m21 * fA5 + m22 * fA4 - m23 * fA3; - float f13 = +m20 * fA5 - m22 * fA2 + m23 * fA1; - float f23 = -m20 * fA4 + m21 * fA2 - m23 * fA0; - float f33 = +m20 * fA3 - m21 * fA1 + m22 * fA0; - - m00 = f00; - m01 = f01; - m02 = f02; - m03 = f03; - m10 = f10; - m11 = f11; - m12 = f12; - m13 = f13; - m20 = f20; - m21 = f21; - m22 = f22; - m23 = f23; - m30 = f30; - m31 = f31; - m32 = f32; - m33 = f33; - - float fInvDet = 1.0f / fDet; - multLocal(fInvDet); - - return this; - } - - /** - * Returns a new matrix representing the adjoint of this matrix. - * - * @return The adjoint matrix - */ - public Matrix4f adjoint() { - return adjoint(null); - } - - public void setTransform(Vector3f position, Vector3f scale, Matrix3f rotMat) { - // Ordering: - // 1. Scale - // 2. Rotate - // 3. Translate - - // Set up final matrix with scale, rotation and translation - m00 = scale.x * rotMat.m00; - m01 = scale.y * rotMat.m01; - m02 = scale.z * rotMat.m02; - m03 = position.x; - m10 = scale.x * rotMat.m10; - m11 = scale.y * rotMat.m11; - m12 = scale.z * rotMat.m12; - m13 = position.y; - m20 = scale.x * rotMat.m20; - m21 = scale.y * rotMat.m21; - m22 = scale.z * rotMat.m22; - m23 = position.z; - - // No projection term - m30 = 0; - m31 = 0; - m32 = 0; - m33 = 1; - } - - /** - * Places the adjoint of this matrix in store (creates store if null.) - * - * @param store - * The matrix to store the result in. If null, a new matrix is created. - * @return store - */ - public Matrix4f adjoint(Matrix4f store) { - if (store == null) { - store = new Matrix4f(); - } - - float fA0 = m00 * m11 - m01 * m10; - float fA1 = m00 * m12 - m02 * m10; - float fA2 = m00 * m13 - m03 * m10; - float fA3 = m01 * m12 - m02 * m11; - float fA4 = m01 * m13 - m03 * m11; - float fA5 = m02 * m13 - m03 * m12; - float fB0 = m20 * m31 - m21 * m30; - float fB1 = m20 * m32 - m22 * m30; - float fB2 = m20 * m33 - m23 * m30; - float fB3 = m21 * m32 - m22 * m31; - float fB4 = m21 * m33 - m23 * m31; - float fB5 = m22 * m33 - m23 * m32; - - store.m00 = +m11 * fB5 - m12 * fB4 + m13 * fB3; - store.m10 = -m10 * fB5 + m12 * fB2 - m13 * fB1; - store.m20 = +m10 * fB4 - m11 * fB2 + m13 * fB0; - store.m30 = -m10 * fB3 + m11 * fB1 - m12 * fB0; - store.m01 = -m01 * fB5 + m02 * fB4 - m03 * fB3; - store.m11 = +m00 * fB5 - m02 * fB2 + m03 * fB1; - store.m21 = -m00 * fB4 + m01 * fB2 - m03 * fB0; - store.m31 = +m00 * fB3 - m01 * fB1 + m02 * fB0; - store.m02 = +m31 * fA5 - m32 * fA4 + m33 * fA3; - store.m12 = -m30 * fA5 + m32 * fA2 - m33 * fA1; - store.m22 = +m30 * fA4 - m31 * fA2 + m33 * fA0; - store.m32 = -m30 * fA3 + m31 * fA1 - m32 * fA0; - store.m03 = -m21 * fA5 + m22 * fA4 - m23 * fA3; - store.m13 = +m20 * fA5 - m22 * fA2 + m23 * fA1; - store.m23 = -m20 * fA4 + m21 * fA2 - m23 * fA0; - store.m33 = +m20 * fA3 - m21 * fA1 + m22 * fA0; - - return store; - } - - /** - * determinant generates the determinate of this matrix. - * - * @return the determinate - */ - public float determinant() { - float fA0 = m00 * m11 - m01 * m10; - float fA1 = m00 * m12 - m02 * m10; - float fA2 = m00 * m13 - m03 * m10; - float fA3 = m01 * m12 - m02 * m11; - float fA4 = m01 * m13 - m03 * m11; - float fA5 = m02 * m13 - m03 * m12; - float fB0 = m20 * m31 - m21 * m30; - float fB1 = m20 * m32 - m22 * m30; - float fB2 = m20 * m33 - m23 * m30; - float fB3 = m21 * m32 - m22 * m31; - float fB4 = m21 * m33 - m23 * m31; - float fB5 = m22 * m33 - m23 * m32; - float fDet = fA0 * fB5 - fA1 * fB4 + fA2 * fB3 + fA3 * fB2 - fA4 * fB1 + fA5 * fB0; - return fDet; - } - - /** - * Sets all of the values in this matrix to zero. - * - * @return this matrix - */ - public Matrix4f zero() { - m00 = m01 = m02 = m03 = 0.0f; - m10 = m11 = m12 = m13 = 0.0f; - m20 = m21 = m22 = m23 = 0.0f; - m30 = m31 = m32 = m33 = 0.0f; - return this; - } - - public Matrix4f add(Matrix4f mat) { - Matrix4f result = new Matrix4f(); - result.m00 = this.m00 + mat.m00; - result.m01 = this.m01 + mat.m01; - result.m02 = this.m02 + mat.m02; - result.m03 = this.m03 + mat.m03; - result.m10 = this.m10 + mat.m10; - result.m11 = this.m11 + mat.m11; - result.m12 = this.m12 + mat.m12; - result.m13 = this.m13 + mat.m13; - result.m20 = this.m20 + mat.m20; - result.m21 = this.m21 + mat.m21; - result.m22 = this.m22 + mat.m22; - result.m23 = this.m23 + mat.m23; - result.m30 = this.m30 + mat.m30; - result.m31 = this.m31 + mat.m31; - result.m32 = this.m32 + mat.m32; - result.m33 = this.m33 + mat.m33; - return result; - } - - /** - * add adds the values of a parameter matrix to this matrix. - * - * @param mat - * the matrix to add to this. - */ - public void addLocal(Matrix4f mat) { - m00 += mat.m00; - m01 += mat.m01; - m02 += mat.m02; - m03 += mat.m03; - m10 += mat.m10; - m11 += mat.m11; - m12 += mat.m12; - m13 += mat.m13; - m20 += mat.m20; - m21 += mat.m21; - m22 += mat.m22; - m23 += mat.m23; - m30 += mat.m30; - m31 += mat.m31; - m32 += mat.m32; - m33 += mat.m33; - } - - public Vector3f toTranslationVector() { - return new Vector3f(m03, m13, m23); - } - - public void toTranslationVector(Vector3f vector) { - vector.set(m03, m13, m23); - } - - public Quaternion toRotationQuat() { - Quaternion quat = new Quaternion(); - quat.fromRotationMatrix(toRotationMatrix()); - return quat; - } - - public void toRotationQuat(Quaternion q) { - q.fromRotationMatrix(toRotationMatrix()); - } - - public Matrix3f toRotationMatrix() { - return new Matrix3f(m00, m01, m02, m10, m11, m12, m20, m21, m22); - } - - public void toRotationMatrix(Matrix3f mat) { - mat.m00 = m00; - mat.m01 = m01; - mat.m02 = m02; - mat.m10 = m10; - mat.m11 = m11; - mat.m12 = m12; - mat.m20 = m20; - mat.m21 = m21; - mat.m22 = m22; - } - - /** - * Retreives the scale vector from the matrix. - * - * @return the scale vector - */ - public Vector3f toScaleVector() { - Vector3f result = new Vector3f(); - this.toScaleVector(result); - return result; - } - - /** - * Retreives the scale vector from the matrix and stores it into a given - * vector. - * - * @param the - * vector where the scale will be stored - */ - public void toScaleVector(Vector3f vector) { - float scaleX = (float) Math.sqrt(m00 * m00 + m10 * m10 + m20 * m20); - float scaleY = (float) Math.sqrt(m01 * m01 + m11 * m11 + m21 * m21); - float scaleZ = (float) Math.sqrt(m02 * m02 + m12 * m12 + m22 * m22); - vector.set(scaleX, scaleY, scaleZ); - } - - /** - * Sets the scale. - * - * @param x - * the X scale - * @param y - * the Y scale - * @param z - * the Z scale - */ - public void setScale(float x, float y, float z) { - TempVars vars = TempVars.get(); - vars.vect1.set(m00, m10, m20); - vars.vect1.normalizeLocal().multLocal(x); - m00 = vars.vect1.x; - m10 = vars.vect1.y; - m20 = vars.vect1.z; - - vars.vect1.set(m01, m11, m21); - vars.vect1.normalizeLocal().multLocal(y); - m01 = vars.vect1.x; - m11 = vars.vect1.y; - m21 = vars.vect1.z; - - vars.vect1.set(m02, m12, m22); - vars.vect1.normalizeLocal().multLocal(z); - m02 = vars.vect1.x; - m12 = vars.vect1.y; - m22 = vars.vect1.z; - vars.release(); - } - - /** - * Sets the scale. - * - * @param scale - * the scale vector to set - */ - public void setScale(Vector3f scale) { - this.setScale(scale.x, scale.y, scale.z); - } - - /** - * setTranslation will set the matrix's translation values. - * - * @param translation - * the new values for the translation. - * @throws JmeException - * if translation is not size 3. - */ - public void setTranslation(float[] translation) { - if (translation.length != 3) { - throw new IllegalArgumentException( - "Translation size must be 3."); - } - m03 = translation[0]; - m13 = translation[1]; - m23 = translation[2]; - } - - /** - * setTranslation will set the matrix's translation values. - * - * @param x - * value of the translation on the x axis - * @param y - * value of the translation on the y axis - * @param z - * value of the translation on the z axis - */ - public void setTranslation(float x, float y, float z) { - m03 = x; - m13 = y; - m23 = z; - } - - /** - * setTranslation will set the matrix's translation values. - * - * @param translation - * the new values for the translation. - */ - public void setTranslation(Vector3f translation) { - m03 = translation.x; - m13 = translation.y; - m23 = translation.z; - } - - /** - * setInverseTranslation will set the matrix's inverse - * translation values. - * - * @param translation - * the new values for the inverse translation. - * @throws JmeException - * if translation is not size 3. - */ - public void setInverseTranslation(float[] translation) { - if (translation.length != 3) { - throw new IllegalArgumentException( - "Translation size must be 3."); - } - m03 = -translation[0]; - m13 = -translation[1]; - m23 = -translation[2]; - } - - /** - * angleRotation sets this matrix to that of a rotation about - * three axes (x, y, z). Where each axis has a specified rotation in - * degrees. These rotations are expressed in a single Vector3f - * object. - * - * @param angles - * the angles to rotate. - */ - public void angleRotation(Vector3f angles) { - float angle; - float sr, sp, sy, cr, cp, cy; - - angle = (angles.z * FastMath.DEG_TO_RAD); - sy = FastMath.sin(angle); - cy = FastMath.cos(angle); - angle = (angles.y * FastMath.DEG_TO_RAD); - sp = FastMath.sin(angle); - cp = FastMath.cos(angle); - angle = (angles.x * FastMath.DEG_TO_RAD); - sr = FastMath.sin(angle); - cr = FastMath.cos(angle); - - // matrix = (Z * Y) * X - m00 = cp * cy; - m10 = cp * sy; - m20 = -sp; - m01 = sr * sp * cy + cr * -sy; - m11 = sr * sp * sy + cr * cy; - m21 = sr * cp; - m02 = (cr * sp * cy + -sr * -sy); - m12 = (cr * sp * sy + -sr * cy); - m22 = cr * cp; - m03 = 0.0f; - m13 = 0.0f; - m23 = 0.0f; - } - - /** - * setRotationQuaternion builds a rotation from a - * Quaternion. - * - * @param quat - * the quaternion to build the rotation from. - * @throws NullPointerException - * if quat is null. - */ - public void setRotationQuaternion(Quaternion quat) { - quat.toRotationMatrix(this); - } - - /** - * setInverseRotationRadians builds an inverted rotation from - * Euler angles that are in radians. - * - * @param angles - * the Euler angles in radians. - * @throws JmeException - * if angles is not size 3. - */ - public void setInverseRotationRadians(float[] angles) { - if (angles.length != 3) { - throw new IllegalArgumentException( - "Angles must be of size 3."); - } - double cr = FastMath.cos(angles[0]); - double sr = FastMath.sin(angles[0]); - double cp = FastMath.cos(angles[1]); - double sp = FastMath.sin(angles[1]); - double cy = FastMath.cos(angles[2]); - double sy = FastMath.sin(angles[2]); - - m00 = (float) (cp * cy); - m10 = (float) (cp * sy); - m20 = (float) (-sp); - - double srsp = sr * sp; - double crsp = cr * sp; - - m01 = (float) (srsp * cy - cr * sy); - m11 = (float) (srsp * sy + cr * cy); - m21 = (float) (sr * cp); - - m02 = (float) (crsp * cy + sr * sy); - m12 = (float) (crsp * sy - sr * cy); - m22 = (float) (cr * cp); - } - - /** - * setInverseRotationDegrees builds an inverted rotation from - * Euler angles that are in degrees. - * - * @param angles - * the Euler angles in degrees. - * @throws JmeException - * if angles is not size 3. - */ - public void setInverseRotationDegrees(float[] angles) { - if (angles.length != 3) { - throw new IllegalArgumentException( - "Angles must be of size 3."); - } - float vec[] = new float[3]; - vec[0] = (angles[0] * FastMath.RAD_TO_DEG); - vec[1] = (angles[1] * FastMath.RAD_TO_DEG); - vec[2] = (angles[2] * FastMath.RAD_TO_DEG); - setInverseRotationRadians(vec); - } - - /** - * - * inverseTranslateVect translates a given Vector3f by the - * translation part of this matrix. - * - * @param vec - * the Vector3f data to be translated. - * @throws JmeException - * if the size of the Vector3f is not 3. - */ - public void inverseTranslateVect(float[] vec) { - if (vec.length != 3) { - throw new IllegalArgumentException( - "vec must be of size 3."); - } - - vec[0] = vec[0] - m03; - vec[1] = vec[1] - m13; - vec[2] = vec[2] - m23; - } - - /** - * - * inverseTranslateVect translates a given Vector3f by the - * translation part of this matrix. - * - * @param data - * the Vector3f to be translated. - * @throws JmeException - * if the size of the Vector3f is not 3. - */ - public void inverseTranslateVect(Vector3f data) { - data.x -= m03; - data.y -= m13; - data.z -= m23; - } - - /** - * - * inverseTranslateVect translates a given Vector3f by the - * translation part of this matrix. - * - * @param data - * the Vector3f to be translated. - * @throws JmeException - * if the size of the Vector3f is not 3. - */ - public void translateVect(Vector3f data) { - data.x += m03; - data.y += m13; - data.z += m23; - } - - /** - * - * inverseRotateVect rotates a given Vector3f by the rotation - * part of this matrix. - * - * @param vec - * the Vector3f to be rotated. - */ - public void inverseRotateVect(Vector3f vec) { - float vx = vec.x, vy = vec.y, vz = vec.z; - - vec.x = vx * m00 + vy * m10 + vz * m20; - vec.y = vx * m01 + vy * m11 + vz * m21; - vec.z = vx * m02 + vy * m12 + vz * m22; - } - - public void rotateVect(Vector3f vec) { - float vx = vec.x, vy = vec.y, vz = vec.z; - - vec.x = vx * m00 + vy * m01 + vz * m02; - vec.y = vx * m10 + vy * m11 + vz * m12; - vec.z = vx * m20 + vy * m21 + vz * m22; - } - - /** - * toString returns the string representation of this object. - * It is in a format of a 4x4 matrix. For example, an identity matrix would - * be represented by the following string. com.jme.math.Matrix3f
[
- * 1.0 0.0 0.0 0.0
- * 0.0 1.0 0.0 0.0
- * 0.0 0.0 1.0 0.0
- * 0.0 0.0 0.0 1.0
]
- * - * @return the string representation of this object. - */ - @Override - public String toString() { - StringBuilder result = new StringBuilder("Matrix4f\n[\n"); - result.append(" "); - result.append(m00); - result.append(" "); - result.append(m01); - result.append(" "); - result.append(m02); - result.append(" "); - result.append(m03); - result.append(" \n"); - result.append(" "); - result.append(m10); - result.append(" "); - result.append(m11); - result.append(" "); - result.append(m12); - result.append(" "); - result.append(m13); - result.append(" \n"); - result.append(" "); - result.append(m20); - result.append(" "); - result.append(m21); - result.append(" "); - result.append(m22); - result.append(" "); - result.append(m23); - result.append(" \n"); - result.append(" "); - result.append(m30); - result.append(" "); - result.append(m31); - result.append(" "); - result.append(m32); - result.append(" "); - result.append(m33); - result.append(" \n]"); - return result.toString(); - } - - /** - * - * hashCode returns the hash code value as an integer and is - * supported for the benefit of hashing based collection classes such as - * Hashtable, HashMap, HashSet etc. - * - * @return the hashcode for this instance of Matrix4f. - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - int hash = 37; - hash = 37 * hash + Float.floatToIntBits(m00); - hash = 37 * hash + Float.floatToIntBits(m01); - hash = 37 * hash + Float.floatToIntBits(m02); - hash = 37 * hash + Float.floatToIntBits(m03); - - hash = 37 * hash + Float.floatToIntBits(m10); - hash = 37 * hash + Float.floatToIntBits(m11); - hash = 37 * hash + Float.floatToIntBits(m12); - hash = 37 * hash + Float.floatToIntBits(m13); - - hash = 37 * hash + Float.floatToIntBits(m20); - hash = 37 * hash + Float.floatToIntBits(m21); - hash = 37 * hash + Float.floatToIntBits(m22); - hash = 37 * hash + Float.floatToIntBits(m23); - - hash = 37 * hash + Float.floatToIntBits(m30); - hash = 37 * hash + Float.floatToIntBits(m31); - hash = 37 * hash + Float.floatToIntBits(m32); - hash = 37 * hash + Float.floatToIntBits(m33); - - return hash; - } - - /** - * are these two matrices the same? they are is they both have the same mXX values. - * - * @param o - * the object to compare for equality - * @return true if they are equal - */ - @Override - public boolean equals(Object o) { - if (!(o instanceof Matrix4f) || o == null) { - return false; - } - - if (this == o) { - return true; - } - - Matrix4f comp = (Matrix4f) o; - if (Float.compare(m00, comp.m00) != 0) { - return false; - } - if (Float.compare(m01, comp.m01) != 0) { - return false; - } - if (Float.compare(m02, comp.m02) != 0) { - return false; - } - if (Float.compare(m03, comp.m03) != 0) { - return false; - } - - if (Float.compare(m10, comp.m10) != 0) { - return false; - } - if (Float.compare(m11, comp.m11) != 0) { - return false; - } - if (Float.compare(m12, comp.m12) != 0) { - return false; - } - if (Float.compare(m13, comp.m13) != 0) { - return false; - } - - if (Float.compare(m20, comp.m20) != 0) { - return false; - } - if (Float.compare(m21, comp.m21) != 0) { - return false; - } - if (Float.compare(m22, comp.m22) != 0) { - return false; - } - if (Float.compare(m23, comp.m23) != 0) { - return false; - } - - if (Float.compare(m30, comp.m30) != 0) { - return false; - } - if (Float.compare(m31, comp.m31) != 0) { - return false; - } - if (Float.compare(m32, comp.m32) != 0) { - return false; - } - if (Float.compare(m33, comp.m33) != 0) { - return false; - } - - return true; - } - - public void write(JmeExporter e) throws IOException { - OutputCapsule cap = e.getCapsule(this); - cap.write(m00, "m00", 1); - cap.write(m01, "m01", 0); - cap.write(m02, "m02", 0); - cap.write(m03, "m03", 0); - cap.write(m10, "m10", 0); - cap.write(m11, "m11", 1); - cap.write(m12, "m12", 0); - cap.write(m13, "m13", 0); - cap.write(m20, "m20", 0); - cap.write(m21, "m21", 0); - cap.write(m22, "m22", 1); - cap.write(m23, "m23", 0); - cap.write(m30, "m30", 0); - cap.write(m31, "m31", 0); - cap.write(m32, "m32", 0); - cap.write(m33, "m33", 1); - } - - public void read(JmeImporter e) throws IOException { - InputCapsule cap = e.getCapsule(this); - m00 = cap.readFloat("m00", 1); - m01 = cap.readFloat("m01", 0); - m02 = cap.readFloat("m02", 0); - m03 = cap.readFloat("m03", 0); - m10 = cap.readFloat("m10", 0); - m11 = cap.readFloat("m11", 1); - m12 = cap.readFloat("m12", 0); - m13 = cap.readFloat("m13", 0); - m20 = cap.readFloat("m20", 0); - m21 = cap.readFloat("m21", 0); - m22 = cap.readFloat("m22", 1); - m23 = cap.readFloat("m23", 0); - m30 = cap.readFloat("m30", 0); - m31 = cap.readFloat("m31", 0); - m32 = cap.readFloat("m32", 0); - m33 = cap.readFloat("m33", 1); - } - - /** - * @return true if this matrix is identity - */ - public boolean isIdentity() { - return (m00 == 1 && m01 == 0 && m02 == 0 && m03 == 0) - && (m10 == 0 && m11 == 1 && m12 == 0 && m13 == 0) - && (m20 == 0 && m21 == 0 && m22 == 1 && m23 == 0) - && (m30 == 0 && m31 == 0 && m32 == 0 && m33 == 1); - } - - /** - * Apply a scale to this matrix. - * - * @param scale - * the scale to apply - */ - public void scale(Vector3f scale) { - m00 *= scale.getX(); - m10 *= scale.getX(); - m20 *= scale.getX(); - m30 *= scale.getX(); - m01 *= scale.getY(); - m11 *= scale.getY(); - m21 *= scale.getY(); - m31 *= scale.getY(); - m02 *= scale.getZ(); - m12 *= scale.getZ(); - m22 *= scale.getZ(); - m32 *= scale.getZ(); - } - - static boolean equalIdentity(Matrix4f mat) { - if (Math.abs(mat.m00 - 1) > 1e-4) { - return false; - } - if (Math.abs(mat.m11 - 1) > 1e-4) { - return false; - } - if (Math.abs(mat.m22 - 1) > 1e-4) { - return false; - } - if (Math.abs(mat.m33 - 1) > 1e-4) { - return false; - } - - if (Math.abs(mat.m01) > 1e-4) { - return false; - } - if (Math.abs(mat.m02) > 1e-4) { - return false; - } - if (Math.abs(mat.m03) > 1e-4) { - return false; - } - - if (Math.abs(mat.m10) > 1e-4) { - return false; - } - if (Math.abs(mat.m12) > 1e-4) { - return false; - } - if (Math.abs(mat.m13) > 1e-4) { - return false; - } - - if (Math.abs(mat.m20) > 1e-4) { - return false; - } - if (Math.abs(mat.m21) > 1e-4) { - return false; - } - if (Math.abs(mat.m23) > 1e-4) { - return false; - } - - if (Math.abs(mat.m30) > 1e-4) { - return false; - } - if (Math.abs(mat.m31) > 1e-4) { - return false; - } - if (Math.abs(mat.m32) > 1e-4) { - return false; - } - - return true; - } - - // XXX: This tests more solid than converting the q to a matrix and multiplying... why? - public void multLocal(Quaternion rotation) { - Vector3f axis = new Vector3f(); - float angle = rotation.toAngleAxis(axis); - Matrix4f matrix4f = new Matrix4f(); - matrix4f.fromAngleAxis(angle, axis); - multLocal(matrix4f); - } - - @Override - public Matrix4f clone() { - try { - return (Matrix4f) super.clone(); - } catch (CloneNotSupportedException e) { - throw new AssertionError(); // can not happen - } - } -} diff --git a/jme3-core/src/main/java/com/jme3/math/Matrixable.java b/jme3-core/src/main/java/com/jme3/math/Matrixable.java new file mode 100644 index 0000000000..412889a82e --- /dev/null +++ b/jme3-core/src/main/java/com/jme3/math/Matrixable.java @@ -0,0 +1,231 @@ +package com.jme3.math; + +import java.io.IOException; +import java.io.Serializable; +import java.nio.FloatBuffer; + +import com.jme3.export.JmeExporter; +import com.jme3.export.JmeImporter; +import com.jme3.export.Savable; + +public interface Matrixable extends Savable, Cloneable, Serializable { + + void copy(Matrixable expected); + + void absoluteLocal(); + + Matrixable normalizeLocal(); + + Matrixable normalize(Matrixable store); + + void fromFrame(Vector3f location, Vector3f direction, Vector3f up, Vector3f left); + + void get(float[] matrix); + + void get(float[] matrix, boolean rowMajor); + + float get(int i, int j); + + float[] getColumn(int i); + + float[] getColumn(int i, float[] store); + + Vector3f getColumn(int i, Vector3f store); + + Vector3f getRow(int i); + + Vector3f getRow(int i, Vector3f store); + + void setColumn(int i, float[] column); + + Matrixable setColumn(int i, Vector3f column); + + Matrixable setRow(int i, Vector3f row); + + void set(int i, int j, float value); + + void set(float[][] matrix); + + Matrixable set(Matrixable matrix); + + void set(float[] matrix); + + void set(float[] matrix, boolean rowMajor); + + Matrixable set(Quaternion quaternion); + + Matrixable transpose(); + + void fromAxes(Vector3f uAxis, Vector3f vAxis, Vector3f wAxis); + + Matrixable transposeLocal(); + + Matrixable transposeNew(); + + FloatBuffer toFloatBuffer(); + + FloatBuffer toFloatBuffer(boolean columnMajor); + + FloatBuffer fillFloatBuffer(FloatBuffer fb); + + FloatBuffer fillFloatBuffer(FloatBuffer fb, boolean columnMajor); + + void fillFloatArray(float[] f, boolean columnMajor); + + Matrixable readFloatBuffer(FloatBuffer fb); + + Matrixable readFloatBuffer(FloatBuffer fb, boolean columnMajor); + + void loadIdentity(); + + void fromFrustum(float near, float far, float left, float right, float top, float bottom, boolean parallel); + + void fromAngleAxis(float angle, Vector3f axis); + + void fromAngleNormalAxis(float angle, Vector3f axis); + + void multLocal(float scalar); + + Vector3f multLocal(Vector3f vec); + + Matrixable mult(float scalar); + + Matrixable mult(float scalar, Matrixable store); + + Matrixable mult(Matrixable in2); + + Matrixable mult(Matrixable in2, Matrixable store); + + Matrixable multLocal(Matrixable in2); + + Vector3f mult(Vector3f vec); + + Vector3f mult(Vector3f vec, Vector3f store); + + Vector4f mult(Vector4f vec); + + Vector4f mult(Vector4f vec, Vector4f store); + + Vector4f multAcross(Vector4f vec); + + Vector4f multAcross(Vector4f vec, Vector4f store); + + Vector3f multNormal(Vector3f vec, Vector3f store); + + Vector3f multNormalAcross(Vector3f vec, Vector3f store); + + float multProj(Vector3f vec, Vector3f store); + + Vector3f multAcross(Vector3f vec, Vector3f store); + + Quaternion mult(Quaternion vec, Quaternion store); + + float[] mult(float[] vec4f); + + float[] multAcross(float[] vec4f); + + Matrixable invert(); + + Matrixable invert(Matrixable store); + + Matrixable invertLocal(); + + Matrixable adjoint(); + + Matrixable adjoint(Matrixable store); + + Matrixable cofactor(Matrixable store); + + Matrixable removeRowCol(int row, int col); + + void setTransform(Vector3f position, Vector3f scale, Matrixable rotMat); + + float determinant(); + + Matrixable zero(); + + Matrixable add(Matrixable mat); + + void addLocal(Matrixable mat); + + Vector3f toTranslationVector(); + + void toTranslationVector(Vector3f vector); + + Quaternion toRotationQuat(); + + void toRotationQuat(Quaternion q); + + Matrixable toRotationMatrix(); + + void toRotationMatrix(Matrixable mat); + + Vector3f toScaleVector(); + + void toScaleVector(Vector3f vector); + + void setScale(float x, float y, float z); + + void setScale(Vector3f scale); + + void setTranslation(float[] translation); + + void setTranslation(float x, float y, float z); + + void setTranslation(Vector3f translation); + + void setInverseTranslation(float[] translation); + + void angleRotation(Vector3f angles); + + void setRotationQuaternion(Quaternion quat); + + void setInverseRotationRadians(float[] angles); + + void setInverseRotationDegrees(float[] angles); + + void inverseTranslateVect(float[] vec); + + void inverseTranslateVect(Vector3f data); + + void translateVect(Vector3f data); + + void inverseRotateVect(Vector3f vec); + + void rotateVect(Vector3f vec); + + String toString(); + + int hashCode(); + + boolean equals(Object o); + + void write(JmeExporter e) throws IOException; + + void read(JmeImporter e) throws IOException; + + boolean isIdentity(); + + void scale(Vector3f scale); + + void multLocal(Quaternion rotation); + + Matrixable clone(); + + void fromStartEndVectors(Vector3f start, Vector3f end); + + int getM(); + + void setM(int m); + + /* (non-Javadoc) + * @see com.jme3.math.Matrixable#getMatrix() + */ + float[][] getMatrix(); + + /* (non-Javadoc) + * @see com.jme3.math.Matrixable#setMatrix(float[][]) + */ + void setMatrix(float[][] matrix); + +} \ No newline at end of file diff --git a/jme3-core/src/main/java/com/jme3/math/Quaternion.java b/jme3-core/src/main/java/com/jme3/math/Quaternion.java index 1ee1305d2d..e68372007c 100644 --- a/jme3-core/src/main/java/com/jme3/math/Quaternion.java +++ b/jme3-core/src/main/java/com/jme3/math/Quaternion.java @@ -324,9 +324,9 @@ public float[] toAngles(float[] angles) { * @param matrix * the matrix that defines the rotation. */ - public Quaternion fromRotationMatrix(Matrix3f matrix) { - return fromRotationMatrix(matrix.m00, matrix.m01, matrix.m02, matrix.m10, - matrix.m11, matrix.m12, matrix.m20, matrix.m21, matrix.m22); + public Quaternion fromRotationMatrix(Matrixable matrix) { + return fromRotationMatrix(matrix.getMatrix()[0][0], matrix.getMatrix()[0][1], matrix.getMatrix()[0][2], matrix.getMatrix()[1][0], + matrix.getMatrix()[1][1], matrix.getMatrix()[1][2], matrix.getMatrix()[2][0], matrix.getMatrix()[2][1], matrix.getMatrix()[2][2]); } public Quaternion fromRotationMatrix(float m00, float m01, float m02, @@ -403,8 +403,8 @@ public Quaternion fromRotationMatrix(float m00, float m01, float m02, * * @return the rotation matrix representation of this quaternion. */ - public Matrix3f toRotationMatrix() { - Matrix3f matrix = new Matrix3f(); + public Matrixable toRotationMatrix() { + Matrix matrix = new Matrix(3); return toRotationMatrix(matrix); } @@ -416,7 +416,7 @@ public Matrix3f toRotationMatrix() { * The Matrix3f to store the result in. * @return the rotation matrix representation of this quaternion. */ - public Matrix3f toRotationMatrix(Matrix3f result) { + public Matrix toRotationMatrix(Matrix result) { float norm = norm(); // we explicitly test norm against one here, saving a division @@ -439,15 +439,15 @@ public Matrix3f toRotationMatrix(Matrix3f result) { float zw = w * zs; // using s=2/norm (instead of 1/norm) saves 9 multiplications by 2 here - result.m00 = 1 - (yy + zz); - result.m01 = (xy - zw); - result.m02 = (xz + yw); - result.m10 = (xy + zw); - result.m11 = 1 - (xx + zz); - result.m12 = (yz - xw); - result.m20 = (xz - yw); - result.m21 = (yz + xw); - result.m22 = 1 - (xx + yy); + result.getMatrix()[0][0] = 1 - (yy + zz); + result.getMatrix()[0][1] = (xy - zw); + result.getMatrix()[0][2] = (xz + yw); + result.getMatrix()[1][0] = (xy + zw); + result.getMatrix()[1][1] = 1 - (xx + zz); + result.getMatrix()[1][2] = (yz - xw); + result.getMatrix()[2][0] = (xz - yw); + result.getMatrix()[2][1] = (yz + xw); + result.getMatrix()[2][2] = 1 - (xx + yy); return result; } @@ -461,7 +461,7 @@ public Matrix3f toRotationMatrix(Matrix3f result) { * The Matrix4f to store the result in. * @return the rotation matrix representation of this quaternion. */ - public Matrix4f toRotationMatrix(Matrix4f result) { + public Matrixable toRotationMatrix(Matrixable result) { TempVars tempv = TempVars.get(); Vector3f originalScale = tempv.vect1; @@ -488,15 +488,15 @@ public Matrix4f toRotationMatrix(Matrix4f result) { float zw = w * zs; // using s=2/norm (instead of 1/norm) saves 9 multiplications by 2 here - result.m00 = 1 - (yy + zz); - result.m01 = (xy - zw); - result.m02 = (xz + yw); - result.m10 = (xy + zw); - result.m11 = 1 - (xx + zz); - result.m12 = (yz - xw); - result.m20 = (xz - yw); - result.m21 = (yz + xw); - result.m22 = 1 - (xx + yy); + result.getMatrix()[0][0] = 1 - (yy + zz); + result.getMatrix()[0][1] = (xy - zw); + result.getMatrix()[0][2] = (xz + yw); + result.getMatrix()[1][0] = (xy + zw); + result.getMatrix()[1][1] = 1 - (xx + zz); + result.getMatrix()[1][2] = (yz - xw); + result.getMatrix()[2][0] = (xz - yw); + result.getMatrix()[2][1] = (yz + xw); + result.getMatrix()[2][2] = 1 - (xx + yy); result.setScale(originalScale); @@ -885,7 +885,7 @@ public Quaternion mult(Quaternion q, Quaternion res) { * @param matrix * the matrix to apply to this quaternion. */ - public void apply(Matrix3f matrix) { + public void apply(Matrixable matrix) { float oldX = x, oldY = y, oldZ = z, oldW = w; fromRotationMatrix(matrix); float tempX = x, tempY = y, tempZ = z, tempW = w; @@ -943,7 +943,7 @@ public Quaternion fromAxes(Vector3f xAxis, Vector3f yAxis, Vector3f zAxis) { * the array of vectors to be filled. */ public void toAxes(Vector3f axis[]) { - Matrix3f tempMat = toRotationMatrix(); + Matrixable tempMat = toRotationMatrix(); axis[0] = tempMat.getColumn(0, axis[0]); axis[1] = tempMat.getColumn(1, axis[1]); axis[2] = tempMat.getColumn(2, axis[2]); diff --git a/jme3-core/src/main/java/com/jme3/math/Transform.java b/jme3-core/src/main/java/com/jme3/math/Transform.java index 9d8a72a1e8..e02f794cca 100644 --- a/jme3-core/src/main/java/com/jme3/math/Transform.java +++ b/jme3-core/src/main/java/com/jme3/math/Transform.java @@ -259,15 +259,15 @@ public Vector3f transformInverseVector(final Vector3f in, Vector3f store){ return store; } - public Matrix4f toTransformMatrix() { - Matrix4f trans = new Matrix4f(); + public Matrixable toTransformMatrix() { + Matrixable trans = new Matrix(4); trans.setTranslation(translation); trans.setRotationQuaternion(rot); trans.setScale(scale); return trans; } - public void fromTransformMatrix(Matrix4f mat) { + public void fromTransformMatrix(Matrixable mat) { translation.set(mat.toTranslationVector()); rot.set(mat.toRotationQuat()); scale.set(mat.toScaleVector()); diff --git a/jme3-core/src/main/java/com/jme3/math/Vector.java b/jme3-core/src/main/java/com/jme3/math/Vector.java new file mode 100644 index 0000000000..52bf8806d4 --- /dev/null +++ b/jme3-core/src/main/java/com/jme3/math/Vector.java @@ -0,0 +1,204 @@ +package com.jme3.math; + +public class Vector implements Vectorable { + + private float[] vector; + + public Vector(float[] f) { + vector = f; + } + + public Vectorable add(Vectorable v) { + checkEqualVectorLength(v); + float[] result = new float[vector.length]; + for (int i = 0; i < vector.length; i++) + result[i] = get(i) + v.get(i); + return new Vector(result); + } + + public Vectorable addLocal(Vectorable v) { + checkEqualVectorLength(v); + for (int i = 0; i < vector.length; i++) + vector[i] = get(i) + v.get(i); + return this; + } + + public float angleBetween(Vectorable v) { + checkEqualVectorLength(v); + float dotProduct = dot(v); + float angle = FastMath.acos(dotProduct); + return angle; + } + + private void checkEqualVectorLength(Vectorable v) { + if (!isValidVector(v)) + throw new IllegalArgumentException("Vector length is not equal."); + } + + public Vectorable cross(Vectorable v) { + // TODO: To be implemented. + return null; + } + + public float determinant(Vectorable v) { + // TODO: To be implemented. + return 0; + } + + public float distance(Vectorable v) { + checkEqualVectorLength(v); + return FastMath.sqrt(distanceSquared(v)); + } + + public float distanceSquared(Vectorable v) { + checkEqualVectorLength(v); + float result = 0; + for (int i = 0; i < vector.length; i++) + result += (get(i) - v.get(i)) * (get(i) - v.get(i)); + return result; + } + + public Vectorable divide(float d) { + float[] result = new float[vector.length]; + for (int i = 0; i < vector.length; i++) + result[i] = get(i) / d; + return new Vector(result); + } + + public Vectorable divideLocal(float d) { + for (int i = 0; i < vector.length; i++) + vector[i] = get(i) / d; + return this; + } + + public float dot(Vectorable v) { + checkEqualVectorLength(v); + if (v == null) return 0; + float result = 0; + for (int i = 0; i < vector.length; i++) + result += get(i) * v.get(i); + return result; + } + + public float get(int i) { + if (i < 0 || i >= vector.length) + throw new IllegalArgumentException(); + return vector[i]; + } + + public float[] getVector() { + return vector; + } + + public Vectorable interpolateLocal(Vectorable v, float changeAmount) { + checkEqualVectorLength(v); + for (int i = 0; i < vector.length; i++) + vector[i] = (1 - changeAmount) * get(i) + changeAmount * v.get(i); + return this; + } + + public boolean isValidVector(Vectorable v) { + if (v == null) return false; + if (vector.length != v.getVector().length) return false; + for (float f : vector) + if (Float.isNaN(f) || Float.isInfinite(f)) + return false; + return true; + } + + public float length() { + return FastMath.sqrt(lengthSquared()); + } + + public float lengthSquared() { + float result = 0; + for (float f : vector) + result += f * f; + return result; + } + + public Vectorable mult(float m) { + float[] result = new float[vector.length]; + for (int i = 0; i < vector.length; i++) + result[i] = m * get(i); + return new Vector(result); + } + + public Vectorable multLocal(float m) { + for (int i = 0; i < vector.length; i++) + vector[i] = m * get(i); + return this; + } + + public Vectorable negate() { + float[] result = new float[vector.length]; + for (int i = 0; i < vector.length; i++) + result[i] = -get(i); + return new Vector(result); + } + + public Vectorable negateLocal() { + for (int i = 0; i < vector.length; i++) + vector[i] = -get(i); + return this; + } + + public Vectorable normalize() { + float length = length(); + if (length != 0) { + return divide(length); + } + + return divide(1); + } + + public Vectorable normalizeLocal() { + float length = length(); + if (length != 0) { + return divideLocal(length); + } + + return divideLocal(1); + } + + public Vectorable set(Vectorable v) { + checkEqualVectorLength(v); + for (int i = 0; i < vector.length; i++) + vector[i] = v.get(i); + return this; + } + + public Vectorable substract(Vectorable v) { + checkEqualVectorLength(v); + float[] result = new float[vector.length]; + for (int i = 0; i < vector.length; i++) + result[i] = get(i) - v.get(i); + return new Vector(result); + } + + public Vectorable substractLocal(Vectorable v) { + checkEqualVectorLength(v); + for (int i = 0; i < vector.length; i++) + vector[i] = get(i) - v.get(i); + return this; + } + + public Vectorable zero() { + for (int i = 0; i < vector.length; i++) + vector[i] = 0; + return this; + } + + public boolean equals(Object o) { + Vectorable that; + if (o instanceof Vectorable) + that = (Vectorable) o; + else return false; + for (int i = 0; i < vector.length; i++) + if (get(i) != that.get(i)) + return false; + + return true; + } + +} diff --git a/jme3-core/src/main/java/com/jme3/math/Vectorable.java b/jme3-core/src/main/java/com/jme3/math/Vectorable.java new file mode 100644 index 0000000000..b1a6fea0ff --- /dev/null +++ b/jme3-core/src/main/java/com/jme3/math/Vectorable.java @@ -0,0 +1,32 @@ +package com.jme3.math; + +public interface Vectorable { + + Vectorable add(Vectorable v); + Vectorable addLocal(Vectorable v); + float angleBetween(Vectorable v); + Vectorable cross(Vectorable v); + float determinant(Vectorable v); + float distance(Vectorable v); + float distanceSquared(Vectorable v); + Vectorable divide(float d); + Vectorable divideLocal(float d); + float dot(Vectorable v); + float get(int i); + float[] getVector(); + Vectorable interpolateLocal(Vectorable v, float changeAmount); + boolean isValidVector(Vectorable v); + float length(); + float lengthSquared(); + Vectorable mult(float m); + Vectorable multLocal(float m); + Vectorable negate(); + Vectorable negateLocal(); + Vectorable normalize(); + Vectorable normalizeLocal(); + Vectorable set(Vectorable v); + Vectorable substract(Vectorable v); + Vectorable substractLocal(Vectorable v); + Vectorable zero(); + +} diff --git a/jme3-core/src/main/java/com/jme3/renderer/Camera.java b/jme3-core/src/main/java/com/jme3/renderer/Camera.java index 0ce5bafd73..919de41d90 100644 --- a/jme3-core/src/main/java/com/jme3/renderer/Camera.java +++ b/jme3-core/src/main/java/com/jme3/renderer/Camera.java @@ -195,11 +195,11 @@ public enum FrustumIntersect { * store the value for field parallelProjection */ private boolean parallelProjection = true; - protected Matrix4f projectionMatrixOverride = new Matrix4f(); + protected Matrix projectionMatrixOverride = new Matrix(4); private boolean overrideProjection; - protected Matrix4f viewMatrix = new Matrix4f(); - protected Matrix4f projectionMatrix = new Matrix4f(); - protected Matrix4f viewProjectionMatrix = new Matrix4f(); + protected Matrix viewMatrix = new Matrix(4); + protected Matrix projectionMatrix = new Matrix(4); + protected Matrix viewProjectionMatrix = new Matrix(4); private BoundingBox guiBounding = new BoundingBox(); /** The camera's name. */ protected String name; @@ -390,9 +390,9 @@ public void setClipPlane(Plane clipPlane, Plane.Side side) { TempVars vars = TempVars.get(); try { - Matrix4f p = projectionMatrixOverride.set(projectionMatrix); + Matrix p = projectionMatrixOverride.set(projectionMatrix); - Matrix4f ivm = viewMatrix; + Matrixable ivm = viewMatrix; Vector3f point = clipPlane.getNormal().mult(clipPlane.getConstant(), vars.vect1); Vector3f pp = ivm.mult(point, vars.vect2); @@ -401,18 +401,18 @@ public void setClipPlane(Plane clipPlane, Plane.Side side) { Vector4f v = vars.vect4f2.set(0, 0, 0, 0); - v.x = (Math.signum(clipPlaneV.x) + p.m02) / p.m00; - v.y = (Math.signum(clipPlaneV.y) + p.m12) / p.m11; + v.x = (Math.signum(clipPlaneV.x) + p.getMatrix()[0][2]) / p.getMatrix()[0][0]; + v.y = (Math.signum(clipPlaneV.y) + p.getMatrix()[1][2]) / p.getMatrix()[1][1]; v.z = -1.0f; - v.w = (1.0f + p.m22) / p.m23; + v.w = (1.0f + p.getMatrix()[2][2]) / p.getMatrix()[2][3]; float dot = clipPlaneV.dot(v);//clipPlaneV.x * v.x + clipPlaneV.y * v.y + clipPlaneV.z * v.z + clipPlaneV.w * v.w; Vector4f c = clipPlaneV.multLocal(2.0f / dot); - p.m20 = c.x - p.m30; - p.m21 = c.y - p.m31; - p.m22 = c.z - p.m32; - p.m23 = c.w - p.m33; + p.getMatrix()[2][0] = c.x - p.getMatrix()[3][0]; + p.getMatrix()[2][1] = c.y - p.getMatrix()[3][1]; + p.getMatrix()[2][2] = c.z - p.getMatrix()[3][2]; + p.getMatrix()[2][3] = c.w - p.getMatrix()[3][3]; setProjectionMatrix(p); } finally { vars.release(); @@ -1078,7 +1078,7 @@ public boolean containsGui(BoundingVolume bound) { * This matrix is usually defined by the position and * orientation of the camera. */ - public Matrix4f getViewMatrix() { + public Matrix getViewMatrix() { return viewMatrix; } @@ -1089,7 +1089,7 @@ public Matrix4f getViewMatrix() { * * @param projMatrix */ - public void setProjectionMatrix(Matrix4f projMatrix) { + public void setProjectionMatrix(Matrixable projMatrix) { if (projMatrix == null) { overrideProjection = false; projectionMatrixOverride.loadIdentity(); @@ -1106,7 +1106,7 @@ public void setProjectionMatrix(Matrix4f projMatrix) { * This matrix is usually defined by the viewport and perspective settings * of the camera. */ - public Matrix4f getProjectionMatrix() { + public Matrix getProjectionMatrix() { if (overrideProjection) { return projectionMatrixOverride; } @@ -1131,7 +1131,7 @@ public void updateViewProjection() { * matrix. This matrix is required for rendering an object. It is * precomputed so as to not compute it every time an object is rendered. */ - public Matrix4f getViewProjectionMatrix() { + public Matrix getViewProjectionMatrix() { return viewProjectionMatrix; } @@ -1356,7 +1356,7 @@ public Vector3f getWorldCoordinates(Vector2f screenPosition, store = new Vector3f(); } - Matrix4f inverseMat = new Matrix4f(viewProjectionMatrix); + Matrixable inverseMat = new Matrix(viewProjectionMatrix); inverseMat.invertLocal(); store.set( diff --git a/jme3-core/src/main/java/com/jme3/renderer/RenderManager.java b/jme3-core/src/main/java/com/jme3/renderer/RenderManager.java index 7aac5a6895..19c18831f8 100644 --- a/jme3-core/src/main/java/com/jme3/renderer/RenderManager.java +++ b/jme3-core/src/main/java/com/jme3/renderer/RenderManager.java @@ -35,7 +35,8 @@ import com.jme3.light.LightFilter; import com.jme3.light.LightList; import com.jme3.material.*; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.post.SceneProcessor; import com.jme3.profile.AppProfiler; import com.jme3.profile.AppStep; @@ -80,7 +81,7 @@ public class RenderManager { private String forcedTechnique = null; private RenderState forcedRenderState = null; private int viewX, viewY, viewWidth, viewHeight; - private Matrix4f orthoMatrix = new Matrix4f(); + private Matrix orthoMatrix = new Matrix(4); private LightList filteredLightList = new LightList(null); private String tmpTech; private boolean handleTranlucentBucket = true; @@ -471,7 +472,7 @@ public void setHandleTranslucentBucket(boolean handleTranslucentBucket) { * * @param mat The world matrix to set */ - public void setWorldMatrix(Matrix4f mat) { + public void setWorldMatrix(Matrix mat) { uniformBindingManager.setWorldMatrix(mat); } @@ -517,7 +518,7 @@ public void updateUniformBindings(List params) { */ public void renderGeometry(Geometry g) { if (g.isIgnoreTransform()) { - setWorldMatrix(Matrix4f.IDENTITY); + setWorldMatrix(new Matrix(4)); } else { setWorldMatrix(g.getWorldMatrix()); } @@ -903,7 +904,7 @@ private void setViewPort(Camera cam) { private void setViewProjection(Camera cam, boolean ortho) { if (ortho) { - uniformBindingManager.setCamera(cam, Matrix4f.IDENTITY, orthoMatrix, orthoMatrix); + uniformBindingManager.setCamera(cam, new Matrix(4), orthoMatrix, orthoMatrix); } else { uniformBindingManager.setCamera(cam, cam.getViewMatrix(), cam.getProjectionMatrix(), cam.getViewProjectionMatrix()); } diff --git a/jme3-core/src/main/java/com/jme3/scene/BatchNode.java b/jme3-core/src/main/java/com/jme3/scene/BatchNode.java index 26d944b88a..e031130b65 100644 --- a/jme3-core/src/main/java/com/jme3/scene/BatchNode.java +++ b/jme3-core/src/main/java/com/jme3/scene/BatchNode.java @@ -43,7 +43,7 @@ import com.jme3.collision.Collidable; import com.jme3.collision.CollisionResults; import com.jme3.material.Material; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrixable; import com.jme3.math.Vector3f; import com.jme3.scene.mesh.IndexBuffer; import com.jme3.util.SafeArrayList; @@ -120,7 +120,7 @@ public void onGeometryUnassociated(Geometry geom) { setNeedsFullRebatch(true); } - protected Matrix4f getTransformMatrix(Geometry g){ + protected Matrixable getTransformMatrix(Geometry g){ return g.cachedWorldMat; } @@ -139,7 +139,7 @@ protected void updateSubBatch(Geometry bg) { FloatBuffer oposBuf = (FloatBuffer) opvb.getData(); VertexBuffer onvb = origMesh.getBuffer(VertexBuffer.Type.Normal); FloatBuffer onormBuf = (FloatBuffer) onvb.getData(); - Matrix4f transformMat = getTransformMatrix(bg); + Matrixable transformMat = getTransformMatrix(bg); if (mesh.getBuffer(VertexBuffer.Type.Tangent) != null) { @@ -525,7 +525,7 @@ private void mergeGeometries(Mesh outMesh, List geometries) { } } - private void doTransforms(FloatBuffer bindBufPos, FloatBuffer bindBufNorm, FloatBuffer bufPos, FloatBuffer bufNorm, int start, int end, Matrix4f transform) { + private void doTransforms(FloatBuffer bindBufPos, FloatBuffer bindBufNorm, FloatBuffer bufPos, FloatBuffer bufNorm, int start, int end, Matrixable transform) { TempVars vars = TempVars.get(); Vector3f pos = vars.vect1; Vector3f norm = vars.vect2; @@ -571,7 +571,7 @@ private void doTransforms(FloatBuffer bindBufPos, FloatBuffer bindBufNorm, Float bufNorm.put(tmpFloatN, 0, length); } - private void doTransformsTangents(FloatBuffer bindBufPos, FloatBuffer bindBufNorm, FloatBuffer bindBufTangents,FloatBuffer bufPos, FloatBuffer bufNorm, FloatBuffer bufTangents, int start, int end, Matrix4f transform) { + private void doTransformsTangents(FloatBuffer bindBufPos, FloatBuffer bindBufNorm, FloatBuffer bindBufTangents,FloatBuffer bufPos, FloatBuffer bufNorm, FloatBuffer bufTangents, int start, int end, Matrixable transform) { TempVars vars = TempVars.get(); Vector3f pos = vars.vect1; Vector3f norm = vars.vect2; diff --git a/jme3-core/src/main/java/com/jme3/scene/CollisionData.java b/jme3-core/src/main/java/com/jme3/scene/CollisionData.java index 50309d5ea3..c6ebd7a767 100644 --- a/jme3-core/src/main/java/com/jme3/scene/CollisionData.java +++ b/jme3-core/src/main/java/com/jme3/scene/CollisionData.java @@ -35,7 +35,7 @@ import com.jme3.collision.Collidable; import com.jme3.collision.CollisionResults; import com.jme3.export.Savable; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrix; /** * CollisionData is an interface that can be used to @@ -45,7 +45,7 @@ */ public interface CollisionData extends Savable, Cloneable { public int collideWith(Collidable other, - Matrix4f worldMatrix, + Matrix worldMatrix, BoundingVolume worldBound, CollisionResults results); } diff --git a/jme3-core/src/main/java/com/jme3/scene/Geometry.java b/jme3-core/src/main/java/com/jme3/scene/Geometry.java index 4c394101ab..5eb944c0e0 100644 --- a/jme3-core/src/main/java/com/jme3/scene/Geometry.java +++ b/jme3-core/src/main/java/com/jme3/scene/Geometry.java @@ -40,7 +40,7 @@ import com.jme3.export.JmeImporter; import com.jme3.export.OutputCapsule; import com.jme3.material.Material; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrix; import com.jme3.renderer.Camera; import com.jme3.scene.VertexBuffer.Type; import com.jme3.util.TempVars; @@ -70,7 +70,7 @@ public class Geometry extends Spatial { * When true, the geometry's transform will not be applied. */ protected boolean ignoreTransform = false; - protected transient Matrix4f cachedWorldMat = new Matrix4f(); + protected transient Matrix cachedWorldMat = new Matrix(4); /** * Specifies which {@link GeometryGroupNode} this Geometry @@ -393,7 +393,7 @@ public void computeWorldMatrix() { cachedWorldMat.setTranslation(worldTransform.getTranslation()); TempVars vars = TempVars.get(); - Matrix4f scaleMat = vars.tempMat4; + Matrix scaleMat = vars.tempMat4; scaleMat.loadIdentity(); scaleMat.scale(worldTransform.getScale()); cachedWorldMat.multLocal(scaleMat); @@ -401,7 +401,7 @@ public void computeWorldMatrix() { } /** - * A {@link Matrix4f matrix} that transforms the {@link Geometry#getMesh() mesh} + * A {@link Matrix matrix} that transforms the {@link Geometry#getMesh() mesh} * from model space to world space. This matrix is computed based on the * {@link Geometry#getWorldTransform() world transform} of this geometry. * In order to receive updated values, you must call {@link Geometry#computeWorldMatrix() } @@ -409,7 +409,7 @@ public void computeWorldMatrix() { * * @return Matrix to transform from local space to world space */ - public Matrix4f getWorldMatrix() { + public Matrix getWorldMatrix() { return cachedWorldMat; } diff --git a/jme3-core/src/main/java/com/jme3/scene/Mesh.java b/jme3-core/src/main/java/com/jme3/scene/Mesh.java index a0f8e1fe6e..3ad780a111 100644 --- a/jme3-core/src/main/java/com/jme3/scene/Mesh.java +++ b/jme3-core/src/main/java/com/jme3/scene/Mesh.java @@ -38,7 +38,7 @@ import com.jme3.collision.bih.BIHTree; import com.jme3.export.*; import com.jme3.material.RenderState; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrix; import com.jme3.math.Triangle; import com.jme3.math.Vector2f; import com.jme3.math.Vector3f; @@ -919,7 +919,7 @@ public void setId(int id){ /** * Generates a collision tree for the mesh. * Called automatically by {@link #collideWith(com.jme3.collision.Collidable, - * com.jme3.math.Matrix4f, + * com.jme3.math.Matrix, * com.jme3.bounding.BoundingVolume, * com.jme3.collision.CollisionResults) }. */ @@ -944,7 +944,7 @@ public void clearCollisionData() { * graph elements such as {@link Spatial}s. */ public int collideWith(Collidable other, - Matrix4f worldMatrix, + Matrix worldMatrix, BoundingVolume worldBound, CollisionResults results){ diff --git a/jme3-core/src/main/java/com/jme3/scene/SimpleBatchNode.java b/jme3-core/src/main/java/com/jme3/scene/SimpleBatchNode.java index 2c5a1773f1..a9b4f37c13 100644 --- a/jme3-core/src/main/java/com/jme3/scene/SimpleBatchNode.java +++ b/jme3-core/src/main/java/com/jme3/scene/SimpleBatchNode.java @@ -31,7 +31,8 @@ */ package com.jme3.scene; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.math.Transform; import com.jme3.util.TempVars; @@ -72,17 +73,17 @@ protected void setTransformRefresh() { batch.geometry.setTransformRefresh(); } } - private Matrix4f cachedLocalMat = new Matrix4f(); + private Matrixable cachedLocalMat = new Matrix(4); @Override - protected Matrix4f getTransformMatrix(Geometry g){ + protected Matrixable getTransformMatrix(Geometry g){ // Compute the Local matrix for the geometry cachedLocalMat.loadIdentity(); cachedLocalMat.setRotationQuaternion(g.localTransform.getRotation()); cachedLocalMat.setTranslation(g.localTransform.getTranslation()); TempVars vars = TempVars.get(); - Matrix4f scaleMat = vars.tempMat4; + Matrix scaleMat = vars.tempMat4; scaleMat.loadIdentity(); scaleMat.scale(g.localTransform.getScale()); cachedLocalMat.multLocal(scaleMat); diff --git a/jme3-core/src/main/java/com/jme3/scene/Spatial.java b/jme3-core/src/main/java/com/jme3/scene/Spatial.java index 1fe68d7309..d0b329c6db 100644 --- a/jme3-core/src/main/java/com/jme3/scene/Spatial.java +++ b/jme3-core/src/main/java/com/jme3/scene/Spatial.java @@ -934,12 +934,12 @@ public Quaternion getLocalRotation() { /** * setLocalRotation sets the local rotation of this node - * by using a {@link Matrix3f}. + * by using a {@link Matrix}. * * @param rotation * the new local rotation. */ - public void setLocalRotation(Matrix3f rotation) { + public void setLocalRotation(Matrixable rotation) { localTransform.getRotation().fromRotationMatrix(rotation); setTransformRefresh(); } @@ -1597,9 +1597,9 @@ public String toString() { * * @see Spatial#getWorldTransform() */ - public Matrix4f getLocalToWorldMatrix(Matrix4f store) { + public Matrixable getLocalToWorldMatrix(Matrixable store) { if (store == null) { - store = new Matrix4f(); + store = new Matrix(4); } else { store.loadIdentity(); } diff --git a/jme3-core/src/main/java/com/jme3/scene/control/BillboardControl.java b/jme3-core/src/main/java/com/jme3/scene/control/BillboardControl.java index 7f54f901b2..7a34e1ca2b 100644 --- a/jme3-core/src/main/java/com/jme3/scene/control/BillboardControl.java +++ b/jme3-core/src/main/java/com/jme3/scene/control/BillboardControl.java @@ -36,7 +36,7 @@ import com.jme3.export.JmeImporter; import com.jme3.export.OutputCapsule; import com.jme3.math.FastMath; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrix; import com.jme3.math.Quaternion; import com.jme3.math.Vector3f; import com.jme3.renderer.Camera; @@ -48,7 +48,7 @@ public class BillboardControl extends AbstractControl { - private Matrix3f orient; + private Matrix orient; private Vector3f look; private Vector3f left; private Alignment alignment; @@ -80,7 +80,7 @@ public enum Alignment { public BillboardControl() { super(); - orient = new Matrix3f(); + orient = new Matrix(3); look = new Vector3f(); left = new Vector3f(); alignment = Alignment.Screen; @@ -298,7 +298,7 @@ public void write(JmeExporter e) throws IOException { public void read(JmeImporter e) throws IOException { super.read(e); InputCapsule capsule = e.getCapsule(this); - orient = (Matrix3f) capsule.readSavable("orient", null); + orient = (Matrix) capsule.readSavable("orient", null); look = (Vector3f) capsule.readSavable("look", null); left = (Vector3f) capsule.readSavable("left", null); alignment = capsule.readEnum("alignment", Alignment.class, Alignment.Screen); diff --git a/jme3-core/src/main/java/com/jme3/scene/instancing/InstancedGeometry.java b/jme3-core/src/main/java/com/jme3/scene/instancing/InstancedGeometry.java index 7f0bb601b5..f2963d50da 100644 --- a/jme3-core/src/main/java/com/jme3/scene/instancing/InstancedGeometry.java +++ b/jme3-core/src/main/java/com/jme3/scene/instancing/InstancedGeometry.java @@ -36,8 +36,7 @@ import com.jme3.export.JmeImporter; import com.jme3.export.OutputCapsule; import com.jme3.export.Savable; -import com.jme3.math.Matrix3f; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrixable; import com.jme3.math.Quaternion; import com.jme3.scene.Geometry; import com.jme3.scene.Spatial; @@ -134,8 +133,8 @@ public VertexBuffer getTransformUserInstanceData() { return transformInstanceData; } - private void updateInstance(Matrix4f worldMatrix, float[] store, - int offset, Matrix3f tempMat3, + private void updateInstance(Matrixable worldMatrix, float[] store, + int offset, Matrixable tempMat3, Quaternion tempQuat) { worldMatrix.toRotationMatrix(tempMat3); tempMat3.invertLocal(); @@ -147,21 +146,21 @@ private void updateInstance(Matrix4f worldMatrix, float[] store, // Column-major encoding. The "W" field in each of the encoded // vectors represents the quaternion. - store[offset + 0] = worldMatrix.m00; - store[offset + 1] = worldMatrix.m10; - store[offset + 2] = worldMatrix.m20; + store[offset + 0] = worldMatrix.getMatrix()[0][0]; + store[offset + 1] = worldMatrix.getMatrix()[1][0]; + store[offset + 2] = worldMatrix.getMatrix()[2][0]; store[offset + 3] = tempQuat.getX(); - store[offset + 4] = worldMatrix.m01; - store[offset + 5] = worldMatrix.m11; - store[offset + 6] = worldMatrix.m21; + store[offset + 4] = worldMatrix.getMatrix()[0][1]; + store[offset + 5] = worldMatrix.getMatrix()[1][1]; + store[offset + 6] = worldMatrix.getMatrix()[2][1]; store[offset + 7] = tempQuat.getY(); - store[offset + 8] = worldMatrix.m02; - store[offset + 9] = worldMatrix.m12; - store[offset + 10] = worldMatrix.m22; + store[offset + 8] = worldMatrix.getMatrix()[0][2]; + store[offset + 9] = worldMatrix.getMatrix()[1][2]; + store[offset + 10] = worldMatrix.getMatrix()[2][2]; store[offset + 11] = tempQuat.getZ(); - store[offset + 12] = worldMatrix.m03; - store[offset + 13] = worldMatrix.m13; - store[offset + 14] = worldMatrix.m23; + store[offset + 12] = worldMatrix.getMatrix()[0][3]; + store[offset + 13] = worldMatrix.getMatrix()[1][3]; + store[offset + 14] = worldMatrix.getMatrix()[2][3]; store[offset + 15] = tempQuat.getW(); } @@ -272,7 +271,7 @@ public void updateInstances() { } } - Matrix4f worldMatrix = geom.getWorldMatrix(); + Matrixable worldMatrix = geom.getWorldMatrix(); updateInstance(worldMatrix, temp, 0, vars.tempMat3, vars.quat1); fb.put(temp); } diff --git a/jme3-core/src/main/java/com/jme3/shader/Uniform.java b/jme3-core/src/main/java/com/jme3/shader/Uniform.java index 5d5fd2fe38..5399edce74 100644 --- a/jme3-core/src/main/java/com/jme3/shader/Uniform.java +++ b/jme3-core/src/main/java/com/jme3/shader/Uniform.java @@ -189,7 +189,7 @@ public void setValue(VarType type, Object value){ switch (type){ case Matrix3: - Matrix3f m3 = (Matrix3f) value; + Matrixable m3 = (Matrixable) value; if (multiData == null) { multiData = BufferUtils.createFloatBuffer(9); } @@ -197,7 +197,7 @@ public void setValue(VarType type, Object value){ multiData.clear(); break; case Matrix4: - Matrix4f m4 = (Matrix4f) value; + Matrixable m4 = (Matrixable) value; if (multiData == null) { multiData = BufferUtils.createFloatBuffer(16); } @@ -260,7 +260,7 @@ public void setValue(VarType type, Object value){ multiData.clear(); break; case Matrix3Array: - Matrix3f[] m3a = (Matrix3f[]) value; + Matrixable[] m3a = (Matrixable[]) value; if (multiData == null) { multiData = BufferUtils.createFloatBuffer(m3a.length * 9); } else { @@ -272,7 +272,7 @@ public void setValue(VarType type, Object value){ multiData.clear(); break; case Matrix4Array: - Matrix4f[] m4a = (Matrix4f[]) value; + Matrixable[] m4a = (Matrixable[]) value; if (multiData == null) { multiData = BufferUtils.createFloatBuffer(m4a.length * 16); } else { diff --git a/jme3-core/src/main/java/com/jme3/shader/UniformBindingManager.java b/jme3-core/src/main/java/com/jme3/shader/UniformBindingManager.java index af2df5a94a..06072c7857 100644 --- a/jme3-core/src/main/java/com/jme3/shader/UniformBindingManager.java +++ b/jme3-core/src/main/java/com/jme3/shader/UniformBindingManager.java @@ -58,22 +58,22 @@ public class UniformBindingManager { camLeft = new Vector3f(), camDir = new Vector3f(), camLoc = new Vector3f(); - private Matrix4f tempMatrix = new Matrix4f(); - private Matrix4f viewMatrix = new Matrix4f(); - private Matrix4f projMatrix = new Matrix4f(); - private Matrix4f viewProjMatrix = new Matrix4f(); - private Matrix4f worldMatrix = new Matrix4f(); - private Matrix4f worldViewMatrix = new Matrix4f(); - private Matrix4f worldViewProjMatrix = new Matrix4f(); - private Matrix3f normalMatrix = new Matrix3f(); - private Matrix4f worldMatrixInv = new Matrix4f(); - private Matrix3f worldMatrixInvTrsp = new Matrix3f(); - private Matrix4f viewMatrixInv = new Matrix4f(); - private Matrix4f projMatrixInv = new Matrix4f(); - private Matrix4f viewProjMatrixInv = new Matrix4f(); - private Matrix4f worldViewMatrixInv = new Matrix4f(); - private Matrix3f normalMatrixInv = new Matrix3f(); - private Matrix4f worldViewProjMatrixInv = new Matrix4f(); + private Matrixable tempMatrix = new Matrix(4); + private Matrix viewMatrix = new Matrix(4); + private Matrix projMatrix = new Matrix(4); + private Matrix viewProjMatrix = new Matrix(4); + private Matrix worldMatrix = new Matrix(4); + private Matrixable worldViewMatrix = new Matrix(4); + private Matrixable worldViewProjMatrix = new Matrix(4); + private Matrixable normalMatrix = new Matrix(3); + private Matrixable worldMatrixInv = new Matrix(4); + private Matrixable worldMatrixInvTrsp = new Matrix(3); + private Matrixable viewMatrixInv = new Matrix(4); + private Matrixable projMatrixInv = new Matrix(4); + private Matrixable viewProjMatrixInv = new Matrix(4); + private Matrixable worldViewMatrixInv = new Matrix(4); + private Matrixable normalMatrixInv = new Matrix(3); + private Matrixable worldViewProjMatrixInv = new Matrix(4); private Vector4f viewPort = new Vector4f(); private Vector2f resolution = new Vector2f(); private Vector2f resolutionInv = new Vector2f(); @@ -218,7 +218,7 @@ public void updateUniformBindings(List params) { * * @param mat The world matrix to set */ - public void setWorldMatrix(Matrix4f mat) { + public void setWorldMatrix(Matrix mat) { worldMatrix.set(mat); } @@ -232,7 +232,7 @@ public void setTimer(com.jme3.system.Timer timer) { this.timer = timer; } - public void setCamera(Camera cam, Matrix4f viewMatrix, Matrix4f projMatrix, Matrix4f viewProjMatrix) { + public void setCamera(Camera cam, Matrix viewMatrix, Matrix projMatrix, Matrix viewProjMatrix) { this.viewMatrix.set(viewMatrix); this.projMatrix.set(projMatrix); this.viewProjMatrix.set(viewProjMatrix); diff --git a/jme3-core/src/main/java/com/jme3/shadow/AbstractShadowFilter.java b/jme3-core/src/main/java/com/jme3/shadow/AbstractShadowFilter.java index 46dc8390e4..a50759af3a 100644 --- a/jme3-core/src/main/java/com/jme3/shadow/AbstractShadowFilter.java +++ b/jme3-core/src/main/java/com/jme3/shadow/AbstractShadowFilter.java @@ -37,7 +37,7 @@ import com.jme3.export.JmeImporter; import com.jme3.export.OutputCapsule; import com.jme3.material.Material; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrixable; import com.jme3.math.Vector4f; import com.jme3.post.Filter; import com.jme3.renderer.RenderManager; @@ -95,8 +95,8 @@ public Material getShadowMaterial() { protected void preFrame(float tpf) { shadowRenderer.preFrame(tpf); material.setMatrix4("ViewProjectionMatrixInverse", viewPort.getCamera().getViewProjectionMatrix().invert()); - Matrix4f m = viewPort.getCamera().getViewProjectionMatrix(); - material.setVector4("ViewProjectionMatrixRow2", tmpv.set(m.m20, m.m21, m.m22, m.m23)); + Matrixable m = viewPort.getCamera().getViewProjectionMatrix(); + material.setVector4("ViewProjectionMatrixRow2", tmpv.set(m.getMatrix()[2][0], m.getMatrix()[2][1], m.getMatrix()[2][2], m.getMatrix()[2][3])); } diff --git a/jme3-core/src/main/java/com/jme3/shadow/AbstractShadowRenderer.java b/jme3-core/src/main/java/com/jme3/shadow/AbstractShadowRenderer.java index bd70465cbc..dddf2c167e 100644 --- a/jme3-core/src/main/java/com/jme3/shadow/AbstractShadowRenderer.java +++ b/jme3-core/src/main/java/com/jme3/shadow/AbstractShadowRenderer.java @@ -43,7 +43,8 @@ import com.jme3.export.Savable; import com.jme3.material.Material; import com.jme3.math.ColorRGBA; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.math.Vector2f; import com.jme3.math.Vector3f; import com.jme3.post.SceneProcessor; @@ -85,7 +86,7 @@ public abstract class AbstractShadowRenderer implements SceneProcessor, Savable protected Texture2D dummyTex; protected Material preshadowMat; protected Material postshadowMat; - protected Matrix4f[] lightViewProjectionsMatrices; + protected Matrixable[] lightViewProjectionsMatrices; protected AssetManager assetManager; protected boolean debug = false; protected float edgesThickness = 1.0f; @@ -149,7 +150,7 @@ private void init(AssetManager assetManager, int nbShadowMaps, int shadowMapSize shadowFB = new FrameBuffer[nbShadowMaps]; shadowMaps = new Texture2D[nbShadowMaps]; dispPic = new Picture[nbShadowMaps]; - lightViewProjectionsMatrices = new Matrix4f[nbShadowMaps]; + lightViewProjectionsMatrices = new Matrixable[nbShadowMaps]; shadowMapStringCache = new String[nbShadowMaps]; lightViewStringCache = new String[nbShadowMaps]; @@ -160,7 +161,7 @@ private void init(AssetManager assetManager, int nbShadowMaps, int shadowMapSize postshadowMat.setFloat("ShadowMapSize", shadowMapSize); for (int i = 0; i < nbShadowMaps; i++) { - lightViewProjectionsMatrices[i] = new Matrix4f(); + lightViewProjectionsMatrices[i] = new Matrix(4); shadowFB[i] = new FrameBuffer(shadowMapSize, shadowMapSize, 1); shadowMaps[i] = new Texture2D(shadowMapSize, shadowMapSize, Format.Depth); diff --git a/jme3-core/src/main/java/com/jme3/shadow/PssmShadowFilter.java b/jme3-core/src/main/java/com/jme3/shadow/PssmShadowFilter.java index eda1c5ee64..61ae5f2849 100644 --- a/jme3-core/src/main/java/com/jme3/shadow/PssmShadowFilter.java +++ b/jme3-core/src/main/java/com/jme3/shadow/PssmShadowFilter.java @@ -37,7 +37,7 @@ import com.jme3.export.JmeImporter; import com.jme3.export.OutputCapsule; import com.jme3.material.Material; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrixable; import com.jme3.math.Vector3f; import com.jme3.math.Vector4f; import com.jme3.post.Filter; @@ -102,8 +102,8 @@ public Material getShadowMaterial() { protected void preFrame(float tpf) { pssmRenderer.preFrame(tpf); material.setMatrix4("ViewProjectionMatrixInverse", viewPort.getCamera().getViewProjectionMatrix().invert()); - Matrix4f m = viewPort.getCamera().getViewProjectionMatrix(); - material.setVector4("ViewProjectionMatrixRow2", tmpv.set(m.m20, m.m21, m.m22, m.m23)); + Matrixable m = viewPort.getCamera().getViewProjectionMatrix(); + material.setVector4("ViewProjectionMatrixRow2", tmpv.set(m.getMatrix()[2][0], m.getMatrix()[2][1], m.getMatrix()[2][2], m.getMatrix()[2][3])); } diff --git a/jme3-core/src/main/java/com/jme3/shadow/PssmShadowRenderer.java b/jme3-core/src/main/java/com/jme3/shadow/PssmShadowRenderer.java index e06b5c3375..4aa5ff817b 100644 --- a/jme3-core/src/main/java/com/jme3/shadow/PssmShadowRenderer.java +++ b/jme3-core/src/main/java/com/jme3/shadow/PssmShadowRenderer.java @@ -34,7 +34,8 @@ import com.jme3.asset.AssetManager; import com.jme3.material.Material; import com.jme3.math.ColorRGBA; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.math.Vector2f; import com.jme3.math.Vector3f; import com.jme3.post.SceneProcessor; @@ -146,7 +147,7 @@ public enum CompareMode { protected Material preshadowMat; protected Material postshadowMat; protected GeometryList splitOccluders = new GeometryList(new OpaqueComparator()); - protected Matrix4f[] lightViewProjectionsMatrices; + protected Matrixable[] lightViewProjectionsMatrices; protected ColorRGBA splits; protected float[] splitsArray; protected boolean noOccluders = false; @@ -214,7 +215,7 @@ protected PssmShadowRenderer(AssetManager manager, int size, int nbSplits, Mater shadowFB = new FrameBuffer[nbSplits]; shadowMaps = new Texture2D[nbSplits]; dispPic = new Picture[nbSplits]; - lightViewProjectionsMatrices = new Matrix4f[nbSplits]; + lightViewProjectionsMatrices = new Matrixable[nbSplits]; splits = new ColorRGBA(); splitsArray = new float[nbSplits + 1]; @@ -225,7 +226,7 @@ protected PssmShadowRenderer(AssetManager manager, int size, int nbSplits, Mater postshadowMat.setFloat("ShadowMapSize", size); for (int i = 0; i < nbSplits; i++) { - lightViewProjectionsMatrices[i] = new Matrix4f(); + lightViewProjectionsMatrices[i] = new Matrix(4); shadowFB[i] = new FrameBuffer(size, size, 1); shadowMaps[i] = new Texture2D(size, size, Format.Depth); diff --git a/jme3-core/src/main/java/com/jme3/shadow/PssmShadowUtil.java b/jme3-core/src/main/java/com/jme3/shadow/PssmShadowUtil.java index 888dc2fa81..c48811cafe 100644 --- a/jme3-core/src/main/java/com/jme3/shadow/PssmShadowUtil.java +++ b/jme3-core/src/main/java/com/jme3/shadow/PssmShadowUtil.java @@ -33,7 +33,7 @@ import com.jme3.bounding.BoundingBox; import com.jme3.math.FastMath; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrixable; import com.jme3.renderer.Camera; import com.jme3.renderer.queue.GeometryList; import static java.lang.Math.max; @@ -72,7 +72,7 @@ public static void updateFrustumSplits(float[] splits, float near, float far, fl * Compute the Zfar in the model vieuw to adjust the Zfar distance for the splits calculation */ public static float computeZFar(GeometryList occ, GeometryList recv, Camera cam) { - Matrix4f mat = cam.getViewMatrix(); + Matrixable mat = cam.getViewMatrix(); BoundingBox bbOcc = ShadowUtil.computeUnionBound(occ, mat); BoundingBox bbRecv = ShadowUtil.computeUnionBound(recv, mat); diff --git a/jme3-core/src/main/java/com/jme3/shadow/ShadowUtil.java b/jme3-core/src/main/java/com/jme3/shadow/ShadowUtil.java index d97a354f96..e55a49d6ab 100644 --- a/jme3-core/src/main/java/com/jme3/shadow/ShadowUtil.java +++ b/jme3-core/src/main/java/com/jme3/shadow/ShadowUtil.java @@ -34,7 +34,8 @@ import com.jme3.bounding.BoundingBox; import com.jme3.bounding.BoundingVolume; import com.jme3.math.FastMath; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.math.Transform; import com.jme3.math.Vector2f; import com.jme3.math.Vector3f; @@ -194,7 +195,7 @@ public static BoundingBox computeUnionBound(GeometryList list, Transform transfo * @param mat * @return */ - public static BoundingBox computeUnionBound(GeometryList list, Matrix4f mat) { + public static BoundingBox computeUnionBound(GeometryList list, Matrixable mat) { BoundingBox bbox = new BoundingBox(); TempVars tempv = TempVars.get(); for (int i = 0; i < list.size(); i++) { @@ -252,7 +253,7 @@ public static BoundingBox computeBoundForPoints(Vector3f[] pts, Transform transf * @param mat * @return */ - public static BoundingBox computeBoundForPoints(Vector3f[] pts, Matrix4f mat) { + public static BoundingBox computeBoundForPoints(Vector3f[] pts, Matrixable mat) { Vector3f min = new Vector3f(Vector3f.POSITIVE_INFINITY); Vector3f max = new Vector3f(Vector3f.NEGATIVE_INFINITY); TempVars vars = TempVars.get(); @@ -293,8 +294,8 @@ public static void updateShadowCamera(Camera shadowCam, Vector3f[] points) { shadowCam.setFrustumPerspective(45, 1, 1, 150); } - Matrix4f viewProjMatrix = shadowCam.getViewProjectionMatrix(); - Matrix4f projMatrix = shadowCam.getProjectionMatrix(); + Matrixable viewProjMatrix = shadowCam.getViewProjectionMatrix(); + Matrix projMatrix = shadowCam.getProjectionMatrix(); BoundingBox splitBB = computeBoundForPoints(points, viewProjMatrix); @@ -316,14 +317,15 @@ public static void updateShadowCamera(Camera shadowCam, Vector3f[] points) { scaleZ = 1.0f / (splitMax.z - splitMin.z); offsetZ = -splitMin.z * scaleZ; - Matrix4f cropMatrix = vars.tempMat4; - cropMatrix.set(scaleX, 0f, 0f, offsetX, + Matrixable cropMatrix = vars.tempMat4; + float[] data = {scaleX, 0f, 0f, offsetX, 0f, scaleY, 0f, offsetY, 0f, 0f, scaleZ, offsetZ, - 0f, 0f, 0f, 1f); + 0f, 0f, 0f, 1f}; + cropMatrix.set(data); - Matrix4f result = new Matrix4f(); + Matrixable result = new Matrix(4); result.set(cropMatrix); result.multLocal(projMatrix); @@ -341,7 +343,7 @@ public static void updateShadowCamera(Camera shadowCam, Vector3f[] points) { public static class OccludersExtractor { // global variables set in order not to have recursive process method with too many parameters - Matrix4f viewProjMatrix; + Matrixable viewProjMatrix; public Integer casterCount; BoundingBox splitBB, casterBB; GeometryList splitOccluders; @@ -350,7 +352,7 @@ public static class OccludersExtractor public OccludersExtractor() {} // initialize the global OccludersExtractor variables - public OccludersExtractor(Matrix4f vpm, int cc, BoundingBox sBB, BoundingBox cBB, GeometryList sOCC, TempVars v) { + public OccludersExtractor(Matrixable vpm, int cc, BoundingBox sBB, BoundingBox cBB, GeometryList sOCC, TempVars v) { viewProjMatrix = vpm; casterCount = cc; splitBB = sBB; @@ -469,7 +471,7 @@ public static void updateShadowCamera(ViewPort viewPort, } // create transform to rotate points to viewspace - Matrix4f viewProjMatrix = shadowCam.getViewProjectionMatrix(); + Matrixable viewProjMatrix = shadowCam.getViewProjectionMatrix(); BoundingBox splitBB = computeBoundForPoints(points, viewProjMatrix); @@ -524,7 +526,7 @@ public static void updateShadowCamera(ViewPort viewPort, // shadowCam.setFrustumPerspective(45, 1, 1, splitMax.z); // } - Matrix4f projMatrix = shadowCam.getProjectionMatrix(); + Matrix projMatrix = shadowCam.getProjectionMatrix(); Vector3f cropMin = vars.vect7; Vector3f cropMax = vars.vect8; @@ -576,14 +578,15 @@ public static void updateShadowCamera(ViewPort viewPort, - Matrix4f cropMatrix = vars.tempMat4; - cropMatrix.set(scaleX, 0f, 0f, offsetX, + Matrixable cropMatrix = vars.tempMat4; + float[] data = {scaleX, 0f, 0f, offsetX, 0f, scaleY, 0f, offsetY, 0f, 0f, scaleZ, offsetZ, - 0f, 0f, 0f, 1f); + 0f, 0f, 0f, 1f}; + cropMatrix.set(data); - Matrix4f result = new Matrix4f(); + Matrixable result = new Matrix(4); result.set(cropMatrix); result.multLocal(projMatrix); vars.release(); diff --git a/jme3-core/src/main/java/com/jme3/system/NullRenderer.java b/jme3-core/src/main/java/com/jme3/system/NullRenderer.java index f2e029af4e..ca7182c3d1 100644 --- a/jme3-core/src/main/java/com/jme3/system/NullRenderer.java +++ b/jme3-core/src/main/java/com/jme3/system/NullRenderer.java @@ -37,7 +37,7 @@ import com.jme3.light.LightList; import com.jme3.material.RenderState; import com.jme3.math.ColorRGBA; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrixable; import com.jme3.renderer.Caps; import com.jme3.renderer.Renderer; import com.jme3.renderer.Statistics; @@ -83,10 +83,10 @@ public void setDepthRange(float start, float end) { public void postFrame() { } - public void setWorldMatrix(Matrix4f worldMatrix) { + public void setWorldMatrix(Matrixable worldMatrix) { } - public void setViewProjectionMatrices(Matrix4f viewMatrix, Matrix4f projMatrix) { + public void setViewProjectionMatrices(Matrixable viewMatrix, Matrixable projMatrix) { } public void setViewPort(int x, int y, int width, int height) { diff --git a/jme3-core/src/main/java/com/jme3/util/TempVars.java b/jme3-core/src/main/java/com/jme3/util/TempVars.java index a7bd088b87..de741c65a3 100644 --- a/jme3-core/src/main/java/com/jme3/util/TempVars.java +++ b/jme3-core/src/main/java/com/jme3/util/TempVars.java @@ -192,9 +192,9 @@ public void release() { /** * General matrices. */ - public final Matrix3f tempMat3 = new Matrix3f(); - public final Matrix4f tempMat4 = new Matrix4f(); - public final Matrix4f tempMat42 = new Matrix4f(); + public final Matrix tempMat3 = new Matrix(3); + public final Matrix tempMat4 = new Matrix(4); + public final Matrix tempMat42 = new Matrix(4); /** * General quaternions. */ diff --git a/jme3-core/src/test/java/com/jme3/effect/ParticleEmitterTest.java b/jme3-core/src/test/java/com/jme3/effect/ParticleEmitterTest.java new file mode 100644 index 0000000000..1bd481238c --- /dev/null +++ b/jme3-core/src/test/java/com/jme3/effect/ParticleEmitterTest.java @@ -0,0 +1,70 @@ +package com.jme3.effect; + +import com.jme3.material.Material; +import com.jme3.math.Matrixable; +import com.jme3.renderer.Camera; +import com.jme3.renderer.RenderManager; +import com.jme3.renderer.ViewPort; +import org.junit.Before; +import org.junit.Test; + +import com.jme3.scene.Mesh; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.*; + +public class ParticleEmitterTest { + + private ParticleEmitter particleEmitter; + private ParticleMesh mockedParticlePointMesh; + + @Before + public void setUp() { + mockedParticlePointMesh = mock(ParticlePointMesh.class); + particleEmitter = new ParticleEmitter("test", mockedParticlePointMesh, 1); + } + + @Test(expected = IllegalArgumentException.class) + public void testSetMeshNull() { + particleEmitter.setMesh(null); + } + + @Test + public void testSetMesh() { + Mesh mockedMesh = mock(ParticleTriMesh.class); + particleEmitter.setMesh(mockedMesh); + assertEquals(mockedMesh, particleEmitter.getMesh()); + } + + @Test + public void testClone() { + ParticleEmitter clone = particleEmitter.clone(); + assertEquals(mockedParticlePointMesh, clone.getMesh()); + } + + @Test + public void testSetMaterial() { + Material mockedMaterial = mock(Material.class); + particleEmitter.setMaterial(mockedMaterial); + assertEquals(mockedMaterial, particleEmitter.getMaterial()); + } + + @Test + public void testRenderFromControl() { + RenderManager mockedRenderManager = mock(RenderManager.class); + ViewPort mockedViewPort = mock(ViewPort.class); + Camera mockedCamera = mock(Camera.class); + Material mockedMaterial = mock(Material.class); + + when(mockedViewPort.getCamera()).thenReturn(mockedCamera); + + particleEmitter.setMaterial(mockedMaterial); + + ParticleEmitter.ParticleEmitterControl particleEmitterControl = new ParticleEmitter.ParticleEmitterControl(particleEmitter); + particleEmitterControl.render(mockedRenderManager, mockedViewPort); + + verify(mockedParticlePointMesh).setQuadraticFloat(mockedCamera, mockedMaterial); + } + +} \ No newline at end of file diff --git a/jme3-core/src/test/java/com/jme3/effect/ParticleMeshTest.java b/jme3-core/src/test/java/com/jme3/effect/ParticleMeshTest.java new file mode 100644 index 0000000000..0beead6de9 --- /dev/null +++ b/jme3-core/src/test/java/com/jme3/effect/ParticleMeshTest.java @@ -0,0 +1,10 @@ +package com.jme3.effect; + +import org.junit.Test; + +public abstract class ParticleMeshTest { + + @Test + public abstract void testSetQuadraticFloat(); + +} diff --git a/jme3-core/src/test/java/com/jme3/effect/ParticlePointMeshTest.java b/jme3-core/src/test/java/com/jme3/effect/ParticlePointMeshTest.java new file mode 100644 index 0000000000..3e92cf6209 --- /dev/null +++ b/jme3-core/src/test/java/com/jme3/effect/ParticlePointMeshTest.java @@ -0,0 +1,31 @@ +package com.jme3.effect; + +import com.jme3.material.Material; +import com.jme3.math.Matrix; +import com.jme3.renderer.Camera; +import org.junit.Test; + +import static org.mockito.Matchers.anyFloat; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class ParticlePointMeshTest extends ParticleMeshTest { + + @Test + public void testSetQuadraticFloat() { + // Cannot mock Matrix because it is final. + Matrix matrix = new Matrix(4); + Camera mockedCamera = mock(Camera.class); + Material mockedMaterial = mock(Material.class); + + when(mockedCamera.getProjectionMatrix()).thenReturn(matrix); + + ParticlePointMesh particlePointMesh = new ParticlePointMesh(); + particlePointMesh.setQuadraticFloat(mockedCamera, mockedMaterial); + + verify(mockedMaterial).setFloat(eq("Quadratic"), anyFloat()); + } + +} diff --git a/jme3-core/src/test/java/com/jme3/math/MatrixTest.java b/jme3-core/src/test/java/com/jme3/math/MatrixTest.java new file mode 100644 index 0000000000..64ae3c2bb0 --- /dev/null +++ b/jme3-core/src/test/java/com/jme3/math/MatrixTest.java @@ -0,0 +1,986 @@ +package com.jme3.math; + +import static org.junit.Assert.*; + +import java.util.Vector; +import org.junit.Test; + +public class MatrixTest { + + @Test + public void testMatrixInt() { + float[][] expected = {{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}}; + Matrixable matrix4_test = new Matrix(4); + + assertArrayEquals(matrix4_test.getMatrix(), expected); + } + + @Test + public void testMatrixFloatArray() { + float[] expected = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + + Matrixable matrix4_test = new Matrix(expected); + + int count =0; + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 4; j++) + { + assertEquals(matrix4_test.getMatrix()[j][i], expected[count],0.0001); + count++; + } + } + } + + @Test + public void testMatrixMatrix() { + float[] data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + + Matrixable expected = new Matrix(data); + + Matrixable matrix_test = new Matrix(expected); + + assertArrayEquals(expected.getMatrix(), matrix_test.getMatrix()); + } + + @Test + public void testCopy() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + float[] data2 = { 8, 2, 8, 4, 5, 8, 7, 8, 9, 8, 11, 12, 8, 14, 15, 16 }; + + Matrixable matrix_test = new Matrix(data1); + Matrixable expected = new Matrix(data2); + + matrix_test.copy(expected); + + assertArrayEquals(expected.getMatrix(), matrix_test.getMatrix()); + } + + @Test + public void testAbsoluteLocal() { + float[] data1 = { 1, 2, -3, 4, 5, 6, 7, 8, 9, -10, 11, 12, -13, 14, 15, 16 }; + float[] data2 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + + Matrixable matrix_test = new Matrix(data1); + Matrixable expected = new Matrix(data2); + + matrix_test.absoluteLocal(); + + assertArrayEquals(expected.getMatrix(), matrix_test.getMatrix()); + } + + @Test + public void testNormalizeLocal() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9}; + float[] data2 = { (float) 0.12309149 , (float) 0.20739034 , (float) -0.03829199 , + (float) 0.49236596 , (float) 0.51847583, (float) 0.07658396 , + (float) 0.86164045 , (float) 0.82956135 , (float) -0.038291983 }; + + Matrixable matrix_test = new Matrix(data1); + Matrixable expected = new Matrix(data2); + + matrix_test.normalizeLocal(); + + assertArrayEquals(expected.getMatrix(), matrix_test.getMatrix()); + } + + @Test + public void testNormalize() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9}; + float[] data2 = { (float) 0.12309149 , (float) 0.20739034 , (float) -0.03829199 , + (float) 0.49236596 , (float) 0.51847583, (float) 0.07658396 , + (float) 0.86164045 , (float) 0.82956135 , (float) -0.038291983 }; + + Matrixable matrix_test = new Matrix(data1); + Matrixable expected = new Matrix(data2); + + Matrixable test = new Matrix(3); + + matrix_test.normalize(test); + + assertArrayEquals(expected.getMatrix(), test.getMatrix()); + } + + @Test + public void testGetFloatArray() { + float[] expected = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + float[] test1 = new float[16]; + + Matrixable matrix_test = new Matrix(expected); + + matrix_test.get(test1); + + for (int i = 0; i < 4; i++) { + assertEquals(test1[i], expected[i], 0.0001); + } + } + + @Test + public void testGetFloatArrayBoolean() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + float[] data2 = { 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15, 4, 8, 12, 16 }; + float[] test1 = new float[16]; + + Matrixable matrix_test = new Matrix(data1); + + matrix_test.get(test1, true); + + for (int i = 0; i < 16; i++) { + assertEquals(test1[i], data1[i], 0.0001); + } + + matrix_test.get(test1, false); + + for (int i = 0; i < 16; i++) { + assertEquals(test1[i], data2[i], 0.0001); + } + } + + @Test + public void testGetIntInt() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + + Matrixable matrix_test = new Matrix(data1); + float test1 = 3; + float test2 = matrix_test.get(0, 2); + + assertEquals(test1, test2, 0.0001); + + } + + @Test + public void testGetColumnInt() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + + Matrixable matrix_test = new Matrix(data1); + float[] array1 = { 1, 5, 9, 13 }; + float[] array2 = matrix_test.getColumn(0); + + for (int i = 0; i < 4; i++) { + assertEquals(array1[i], array2[i], 0.0001); + } + } + + @Test + public void testGetColumnIntFloatArray() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + + Matrixable matrix_test = new Matrix(data1); + float[] array1 = { 1, 5, 9, 13 }; + float[] array2 = new float[4]; + + matrix_test.getColumn(0, array2); + for (int i = 0; i < 4; i++) { + assertEquals(array1[i], array2[i], 0.0001); + } + } + + @Test + public void testGetColumnIntVector3f() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + + Matrixable matrix_test = new Matrix(data1); + Vector3f vector1 = new Vector3f(1, 5, 9); + Vector3f vector2 = new Vector3f(); + + matrix_test.getColumn(0, vector2); + + assertEquals(vector1, vector2); + } + + @Test + public void testGetRowInt() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + + Matrixable matrix_test = new Matrix(data1); + Vector3f vector1 = new Vector3f(1, 2, 3); + + Vector3f vector2 = matrix_test.getRow(0); + + assertEquals(vector1, vector2); + } + + @Test + public void testGetRowIntVector3f() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + + Matrixable matrix_test = new Matrix(data1); + Vector3f vector1 = new Vector3f(1, 2, 3); + + Vector3f vector2 = new Vector3f(); + matrix_test.getRow(0, vector2); + + assertEquals(vector1, vector2); + } + + @Test + public void testSetColumnIntFloatArray() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + float[] test = { 45, 45, 45, 45 }; + Matrixable matrix_test = new Matrix(data1); + + matrix_test.setColumn(0, test); + + for (int i = 0; i < 4; i++) { + assertEquals(test[i], matrix_test.getColumn(0)[i], 0.0001); + } + } + + @Test + public void testSetColumnIntVector3f() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + Vector3f test1 = new Vector3f(45, 45, 45); + Vector3f test2 = new Vector3f(); + Matrixable matrix_test = new Matrix(data1); + + matrix_test.setColumn(0, test1); + matrix_test.getColumn(0, test2); + + assertEquals(test1, test2); + } + + @Test + public void testSetRow() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + float[] data2 = { 999, 999, 999, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + + Matrixable matrix_test = new Matrix(data1); + Matrixable expected = new Matrix(data2); + + Vector3f vector = new Vector3f(999, 999, 999); + + matrix_test.setRow(0, vector); + + assertArrayEquals(expected.getMatrix(), matrix_test.getMatrix()); + } + + @Test + public void testSetIntIntFloat() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + float[] data2 = { 1, 2, 3, 4, 5, 6, 999, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + + int r = 1, c = 2; + + Matrixable matrix_test = new Matrix(data1); + Matrixable expected = new Matrix(data2); + + matrix_test.set(r, c, 999); + + assertArrayEquals(expected.getMatrix(), matrix_test.getMatrix()); + } + + @Test + public void testSetFloatArrayArray() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + float[][] data2 = { { 7, 7, 7, 7 }, { 7, 7, 7, 7 }, { 7, 7, 7, 7 }, { 7, 7, 7, 7 } }; + + Matrixable matrix_test = new Matrix(data1); + matrix_test.set(data2); + + assertArrayEquals(data2, matrix_test.getMatrix()); + } + + @Test + public void testSetMatrix() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + float[] data2 = { 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 }; + + Matrixable matrix_test = new Matrix(data1); + Matrixable expected = new Matrix(data2); + + matrix_test.set(expected); + + assertArrayEquals(expected.getMatrix(), matrix_test.getMatrix()); + } + + @Test + public void testSetFloatArray() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + float[] data2 = { 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 }; + float[][] expected = { { 7, 7, 7, 7 }, { 7, 7, 7, 7 }, { 7, 7, 7, 7 }, { 7, 7, 7, 7 } }; + + Matrixable matrix_test = new Matrix(data1); + + matrix_test.set(data2); + + assertArrayEquals(expected, matrix_test.getMatrix()); + } + + @Test + public void testSetFloatArrayBoolean() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + float[][] expected1 = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 }, { 13, 14, 15, 16 } }; + float[][] expected2 = { { 1, 5, 9, 13 }, { 2, 6, 10, 14 }, { 3, 7, 11, 15 }, { 4, 8, 12, 16 } }; + + Matrixable matrix_test = new Matrix(4); + matrix_test.set(data1, false); + + assertArrayEquals(expected1, matrix_test.getMatrix()); + matrix_test.set(data1, true); + + assertArrayEquals(expected2, matrix_test.getMatrix()); + } + + @Test + public void testSetQuaternion() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + Quaternion data2 = new Quaternion(1, 2, 3, 4); + float[][] expected = {{0.13333333f,-0.66666675f,0.73333335f ,13.0f},{0.9333334f,0.3333333f , 0.13333336f,14.0f },{ -0.33333334f, 0.66666675f , 0.6666666f,15.0f },{4.0f,8.0f,12.0f ,16.0f }}; + + Matrixable matrix_test = new Matrix(data1); + + matrix_test.set(data2); + assertArrayEquals(expected, matrix_test.getMatrix()); + } + + @Test + public void testTransposeLocal() { + float[] data1 = { 1, 1, 1, 1, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + float[] data2 = { 1, 5, 9, 13, 1, 6, 10, 14, 1, 7, 11, 15, 1, 8, 12, 16 }; + + Matrixable matrix_test = new Matrix(data1); + Matrixable expected = new Matrix(data2); + + matrix_test.transposeLocal(); + + assertArrayEquals(matrix_test.getMatrix(), expected.getMatrix()); + } + + @Test + public void testTransposeNew() { + float[] data1 = { 1, 1, 1, 1, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + float[] data2 = { 1, 5, 9, 13, 1, 6, 10, 14, 1, 7, 11, 15, 1, 8, 12, 16 }; + + Matrixable matrix_test = new Matrix(data1); + Matrixable expected = new Matrix(data2); + + Matrixable matrix_test1 = matrix_test.transposeNew(); + + assertArrayEquals(matrix_test1.getMatrix(), expected.getMatrix()); + } + + @Test + public void testLoadIdentity() { + float[] data4 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + Matrixable matrix_test = new Matrix(data4); + float[][] expected = { { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 1 } }; + + matrix_test.loadIdentity(); + assertArrayEquals(expected, matrix_test.getMatrix()); + } + + @Test + public void testMultLocalFloat() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + float[] data2 = { 14, 28, 42, 56, 70, 84, 98, 112, 126, 140, 154, 168, 182, 196, 210, 224 }; + + Matrixable matrix_test = new Matrix(data1); + Matrixable expected = new Matrix(data2); + + matrix_test.multLocal(14); + + assertArrayEquals(expected.getMatrix(), matrix_test.getMatrix()); + } + + @Test + public void testMultLocalVector3f() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + + Vector3f test1 = new Vector3f(2, 3, 4); + Vector3f expected = new Vector3f(24, 64, 104); + + Matrixable matrix_test = new Matrix(data1); + + matrix_test.multLocal(test1); + + assertEquals(test1, expected); + } + + @Test + public void testMultFloat() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + float[] data2 = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32 }; + + Matrixable matrix_test = new Matrix(data1); + Matrixable expected = new Matrix(data2); + + matrix_test.mult(2); + + assertArrayEquals(matrix_test.getMatrix(), expected.getMatrix()); + } + + @Test + public void testMultFloatMatrix() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + float[] data2 = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32 }; + + Matrixable matrix = new Matrix(data1); + Matrixable expected = new Matrix(data2); + Matrixable matrix_test = new Matrix(4); + + matrix.mult(2, matrix_test); + + assertArrayEquals(matrix_test.getMatrix(), expected.getMatrix()); + } + + @Test + public void testMultMatrix() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + float[] data2 = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }; + float[] data3 = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32 }; + + Matrixable matrix = new Matrix(data1); + Matrixable matrixMult = new Matrix(data2); + Matrixable expected = new Matrix(data3); + + Matrixable matrix_test = matrix.mult(matrixMult); + + assertArrayEquals(matrix_test.getMatrix(), expected.getMatrix()); + } + + @Test + public void testMultMatrixMatrix() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + float[] data2 = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }; + float[] data3 = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32 }; + + Matrixable matrix = new Matrix(data1); + Matrixable matrixMult = new Matrix(data2); + Matrixable expected = new Matrix(data3); + + Matrixable matrix_test = matrix.mult(matrixMult); + + assertArrayEquals(expected.getMatrix(), matrix_test.getMatrix()); + } + + @Test + public void testMultLocalMatrix() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + float[] data2 = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }; + float[] data3 = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32 }; + + Matrixable matrix_test = new Matrix(data1); + Matrixable matrix4_2 = new Matrix(data2); + Matrixable expected = new Matrix(data3); + + matrix_test.multLocal(matrix4_2); + + assertArrayEquals(matrix_test.getMatrix(), expected.getMatrix()); + } + + @Test + public void testMultVector3f() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + + Vector3f vector = new Vector3f(1, 2, 3); + Vector3f expected = new Vector3f(18, 46, 74); + + Matrixable matrix_test = new Matrix(data1); + + Vector3f test = matrix_test.mult(vector); + + assertEquals(expected, test); + } + + @Test + public void testMultVector3fVector3f() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + + Vector3f vector = new Vector3f(1, 2, 3); + Vector3f expected = new Vector3f(18, 46, 74); + + Matrixable matrix_test = new Matrix(data1); + + Vector3f test = new Vector3f(); + matrix_test.mult(vector, test); + + assertEquals(expected, test); + } + + @Test + public void testMultVector4f() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + + Vector4f vector = new Vector4f(1, 2, 3, 4); + Vector4f expected = new Vector4f(30, 70, 110, 150); + + Matrixable matrix_test = new Matrix(data1); + + Vector4f test = matrix_test.mult(vector); + + assertEquals(expected, test); + } + + @Test + public void testMultVector4fVector4f() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + + Vector4f vector = new Vector4f(1, 2, 3, 4); + Vector4f expected = new Vector4f(30, 70, 110, 150); + + Matrixable matrix_test = new Matrix(data1); + + Vector4f test = new Vector4f(); + matrix_test.mult(vector, test); + + assertEquals(expected, test); + } + + @Test + public void testMultAcrossVector4f() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + + Vector4f vector = new Vector4f(1, 2, 3, 4); + Vector4f expected = new Vector4f(90, 100, 110, 120); + + Matrixable matrix_test = new Matrix(data1); + + Vector4f test = matrix_test.multAcross(vector); + assertEquals(expected, test); + } + + @Test + public void testMultAcrossVector4fVector4f() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + + Vector4f vector = new Vector4f(1, 2, 3, 4); + Vector4f expected = new Vector4f(90, 100, 110, 120); + + Matrixable matrix_test = new Matrix(data1); + + Vector4f test = new Vector4f(); + matrix_test.multAcross(vector, test); + + assertEquals(expected, test); + } + + @Test + public void testMultNormal() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + + Vector3f vector = new Vector3f(1, 2, 3); + Vector3f expected = new Vector3f(14, 38, 62); + + Matrixable matrix_test = new Matrix(data1); + + Vector3f test = new Vector3f(); + + matrix_test.multNormal(vector, test); + + assertEquals(expected, test); + } + + @Test + public void testMultNormalAcross() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + + Vector3f vector = new Vector3f(1, 2, 3); + Vector3f expected = new Vector3f(38, 44, 50); + + Matrixable matrix_test = new Matrix(data1); + + Vector3f test = new Vector3f(); + + matrix_test.multNormalAcross(vector, test); + + assertEquals(expected, test); + } + + @Test + public void testMultProj() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + + Vector3f vector = new Vector3f(1, 2, 3); + Vector3f expected = new Vector3f(18, 46, 74); + + Matrixable matrix_test = new Matrix(data1); + + Vector3f test = new Vector3f(); + + matrix_test.multProj(vector, test); + + assertEquals(expected, test); + } + + @Test + public void testMultAcrossVector3fVector3f() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + + Vector3f vector = new Vector3f(1, 2, 3); + Vector3f expected = new Vector3f(51, 58, 65); + + Matrixable matrix_test = new Matrix(data1); + + Vector3f test = new Vector3f(); + + matrix_test.multAcross(vector, test); + + assertEquals(expected, test); + } + + @Test + public void testMultQuaternionQuaternion() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + + Quaternion vector = new Quaternion(1, 2, 3, 4); + Quaternion expected = new Quaternion(90, 100, 110, 120); + + Matrixable matrix_test = new Matrix(data1); + + Quaternion test = new Quaternion(); + + matrix_test.mult(vector, test); + + assertEquals(expected, test); + } + + @Test + public void testMultFloatArray() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + + float[] array = { 1, 2, 3, 4 }; + float[] expected = { 30, 70, 110, 150 }; + + Matrixable matrix_test = new Matrix(data1); + + float[] test = matrix_test.mult(array); + for (int r = 0; r < 4; r++) { + assertEquals(expected[r], test[r], 0.0001); + } + } + + @Test + public void testMultAcrossFloatArray() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + + float[] array = { 1, 2, 3, 4 }; + float[] expected = { 90, 100, 110, 120 }; + + Matrixable matrix_test = new Matrix(data1); + + float[] test = matrix_test.multAcross(array); + + for (int r = 0; r < 4; r++) { + assertEquals(expected[r], test[r], 0.0001); + } + } + + @Test + public void testInvert() { + float[] data1 = { 4, 0, 0, 0, 0, 0, 2, 0, 0, 1, 2, 0, 1, 0, 0, 1 }; + float[] data2 = { (float) 0.25, 0, 0, 0, 0, -1, 1, 0, 0, (float) 0.5, 0, 0, (float) -0.25, 0, 0, 1 }; + Matrixable matrix_test = new Matrix(data1); + Matrixable expected = new Matrix(data2); + + Matrixable test = matrix_test.invert(); + + assertArrayEquals(test.getMatrix(), expected.getMatrix()); + + } + + @Test + public void testInvertMatrix() { + float[] data1 = { 4, 0, 0, 0, 0, 0, 2, 0, 0, 1, 2, 0, 1, 0, 0, 1 }; + float[] data2 = { (float) 0.25, 0, 0, 0, 0, -1, 1, 0, 0, (float) 0.5, 0, 0, (float) -0.25, 0, 0, 1 }; + Matrixable matrix_test = new Matrix(data1); + Matrixable expected = new Matrix(data2); + + Matrixable test = new Matrix(4); + + matrix_test.invert(test); + + assertArrayEquals(test.getMatrix(), expected.getMatrix()); + } + + @Test + public void testInvertLocal() { + float[] data1 = { 4, 0, 0, 0, 0, 0, 2, 0, 0, 1, 2, 0, 1, 0, 0, 1 }; + float[] data2 = { (float) 0.25, 0, 0, 0, 0, -1, 1, 0, 0, (float) 0.5, 0, 0, (float) -0.25, 0, 0, 1 }; + Matrixable matrix_test = new Matrix(data1); + Matrixable expected = new Matrix(data2); + + matrix_test.invertLocal(); + + assertArrayEquals(matrix_test.getMatrix(), expected.getMatrix()); + } + + @Test + public void testAdjoint() { + float[] data1 = { 5, -2, 2, 7, 1, 0, 0, 3, -3, 1, 5, 0, 3, -1, -9, 4 }; + float[] data2 = { -12, 76, -60, -36, -56, 208, -82, -58, 4, 4, -2, -10, 4, 4, 20, 12 }; + Matrixable matrix_test = new Matrix(data1); + Matrixable expected = new Matrix(data2); + + Matrixable test = matrix_test.adjoint(); + + assertArrayEquals(test.getMatrix(), expected.getMatrix()); + } + + @Test + public void testAdjointMatrix() { + float[] data1 = { 5, -2, 2, 7, 1, 0, 0, 3, -3, 1, 5, 0, 3, -1, -9, 4 }; + float[] data2 = { -12, 76, -60, -36, -56, 208, -82, -58, 4, 4, -2, -10, 4, 4, 20, 12 }; + Matrixable matrix_test = new Matrix(data1); + Matrixable expected = new Matrix(data2); + + Matrixable test = new Matrix(4); + matrix_test.adjoint(test); + + assertArrayEquals(test.getMatrix(), expected.getMatrix()); + } + + @Test + public void testCofactor() { + float[] data1 = { 5, -2, 2, 7, 1, 0, 0, 3, -3, 1, 5, 0, 3, -1, -9, 4 }; + float[] data2 = { -12, 76, -60, -36, -56, 208, -82, -58, 4, 4, -2, -10, 4, 4, 20, 12 }; + Matrixable matrix_test = new Matrix(data1); + Matrixable expected = new Matrix(data2); + + Matrixable test = new Matrix(4); + matrix_test.cofactor(test); + + assertArrayEquals(test.getMatrix(), expected.getMatrix()); + } + + @Test + public void testRemoveRowCol() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + float[] data2 = { 1,3,4,9,11,12,13,15,16}; + Matrixable matrix_test = new Matrix(data1); + Matrixable expected = new Matrix(data2); + + Matrixable test = matrix_test.removeRowCol(1, 1); + + assertArrayEquals(test.getMatrix(), expected.getMatrix()); + } + + @Test + public void testDeterminant() { + float[] data1 = {2,5,3,5,4,6,6,3,11,3,2,-2,4,-7,9,3}; + Matrixable matrix_test = new Matrix(data1); + float expected =2960; + + float test = matrix_test.determinant(); + + assertEquals(test, expected,0.002); + } + + @Test + public void testZero() { + float[] data1 = {2,5,3,5,4,6,6,3,11,3,2,-2,4,-7,9,3}; + float[] data2 = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; + Matrixable matrix_test = new Matrix(data1); + Matrixable expected = new Matrix(data2); + + matrix_test.zero(); + + assertArrayEquals(matrix_test.getMatrix(), expected.getMatrix()); + } + + @Test + public void testAdd() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + float[] data2 = { 2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32}; + Matrixable matrix_test = new Matrix(data1); + Matrixable addMatrix = new Matrix(data1); + Matrixable expected = new Matrix(data2); + + Matrixable test = matrix_test.add(addMatrix); + + assertArrayEquals(test.getMatrix(), expected.getMatrix()); + } + + @Test + public void testAddLocal() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + float[] data2 = { 2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32}; + Matrixable matrix_test = new Matrix(data1); + Matrixable addMatrix = new Matrix(data1); + Matrixable expected = new Matrix(data2); + + matrix_test.addLocal(addMatrix); + + assertArrayEquals(matrix_test.getMatrix(), expected.getMatrix()); + } + + @Test + public void testToTranslationVector() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + Matrixable matrix_test = new Matrix(data1); + + Vector3f expected = new Vector3f(4,8,12); + Vector3f test = matrix_test.toTranslationVector(); + + assertEquals(test, expected); + } + + @Test + public void testToTranslationVectorVector3f() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + Matrixable matrix_test = new Matrix(data1); + + Vector3f expected = new Vector3f(4,8,12); + Vector3f test = new Vector3f(); + matrix_test.toTranslationVector(test); + + assertEquals(test, expected); + } + + @Test + public void testToRotationQuat() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + Matrixable matrix_test = new Matrix(data1); + + Quaternion expected = new Quaternion((float)0.029251702,(float) -0.09027569,(float) 0.018377202, (float)0.78618026); + Quaternion test = matrix_test.toRotationQuat(); + + assertEquals(test, expected); + } + + @Test + public void testToRotationQuatQuaternion() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + Matrixable matrix_test = new Matrix(data1); + + Quaternion expected = new Quaternion(0.029251702f, -0.09027569f, 0.018377202f, 0.78618026f); + Quaternion test = new Quaternion(); + matrix_test.toRotationQuat(test); + + System.out.println(test); + assertEquals(test, expected); + } + + @Test + public void testToRotationMatrix() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + float[] data2 = {1,2,3,5,6,7,9,10,11}; + Matrixable matrix_test = new Matrix(data1); + + Matrixable expected = new Matrix(data2); + Matrixable test = matrix_test.toRotationMatrix(); + + assertArrayEquals(test.getMatrix(), expected.getMatrix()); + } + + @Test + public void testToRotationMatrixMatrix() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + float[] data2 = {1,2,3,5,6,7,9,10,11}; + Matrixable matrix_test = new Matrix(data1); + + Matrixable expected = new Matrix(data2); + Matrixable test = new Matrix(3); + matrix_test.toRotationMatrix(test); + + assertArrayEquals(test.getMatrix(), expected.getMatrix()); + } + + @Test + public void testToScaleVector() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + Matrixable matrix_test = new Matrix(data1); + + Vector3f expected = new Vector3f((float)10.34408,(float)11.83216, (float)13.379088); + + Vector3f test = matrix_test.toScaleVector(); + + assertEquals(test, expected); + } + + @Test + public void testToScaleVectorVector3f() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + Matrixable matrix_test = new Matrix(data1); + + Vector3f expected = new Vector3f((float)10.34408,(float)11.83216, (float)13.379088); + + Vector3f test = new Vector3f(); + matrix_test.toScaleVector(test); + + assertEquals(test, expected); + } + + @Test + public void testSetScaleFloatFloatFloat() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + Matrixable matrix_test = new Matrix(data1); + + float[] data2 = { (float) 0.09667365, (float) 0.3380617, (float) 0.6726916, 4, (float) 0.48336828, (float) 1.0141851, (float) 1.5696137, 8, (float) 0.8700629, (float) 1.6903085, (float) 2.4665358, 12, 13, 14, 15, 16 }; + Matrixable expected = new Matrix(data2); + + matrix_test.setScale(1,2,3); + + assertArrayEquals(expected.getMatrix(), matrix_test.getMatrix()); + } + + @Test + public void testSetScaleVector3f() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + Matrixable matrix_test = new Matrix(data1); + + float[] data2 = { (float) 0.09667365, (float) 0.3380617, (float) 0.6726916, 4, (float) 0.48336828, (float) 1.0141851, (float) 1.5696137, 8, (float) 0.8700629, (float) 1.6903085, (float) 2.4665358, 12, 13, 14, 15, 16 }; + Matrixable expected = new Matrix(data2); + + Vector3f vector = new Vector3f(1,2,3); + + matrix_test.setScale(vector); + + assertArrayEquals(expected.getMatrix(), matrix_test.getMatrix()); + } + + @Test + public void testEqualsObject() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + Matrixable matrix_test = new Matrix(data1); + Matrixable equal = new Matrix(data1); + + float[] data3 = { 7, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + Matrixable notEqual = new Matrix(data3); + + assertEquals(matrix_test.equals(equal), true); + + assertEquals(matrix_test.equals(notEqual), false); + } + + @Test + public void testIsIdentity() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + Matrixable matrix_test1 = new Matrix(data1); + + float[] data2 = {1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1}; + Matrixable matrix_test2 = new Matrix(data2); + + assertEquals(matrix_test1.isIdentity(), false); + + assertEquals(matrix_test2.isIdentity(), true); + } + + @Test + public void testScale() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + Matrixable matrix_test = new Matrix(data1); + + float[] data2 = {1,4,9,4,5,12,21,8,9,20,33,12,13,28,45,16}; + Matrixable expected = new Matrix(data2); + + Vector3f vector = new Vector3f(1,2,3); + + matrix_test.scale(vector); + + assertArrayEquals(expected.getMatrix(), matrix_test.getMatrix()); + } + + @Test + public void testEqualIdentity() { + float[] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + Matrixable matrix_test1 = new Matrix(data1); + + float[] data2 = {1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1}; + Matrixable matrix_test2 = new Matrix(data2); + + assertEquals(Matrix.equalIdentity(matrix_test1), false); + + assertEquals(Matrix.equalIdentity(matrix_test2), true); + } + +} diff --git a/jme3-core/src/test/java/com/jme3/math/VectorTest.java b/jme3-core/src/test/java/com/jme3/math/VectorTest.java new file mode 100644 index 0000000000..5a36d90b52 --- /dev/null +++ b/jme3-core/src/test/java/com/jme3/math/VectorTest.java @@ -0,0 +1,146 @@ +package com.jme3.math; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class VectorTest { + + @Test + public void testAdd() { + float[] varray = {1.0f, 2.0f, 3.0f}; + float[] uarray = {1.0f, 2.0f, 3.0f}; + Vectorable v = new Vector(varray); + Vectorable u = new Vector(uarray); + + float[] expectedarray = {2.0f, 4.0f, 6.0f}; + Vectorable expected = new Vector(expectedarray); + + assertEquals(expected, v.add(u)); + } + + @Test + public void testAddLocal() { + float[] varray = {1.0f, 2.0f, 3.0f}; + float[] uarray = {1.0f, 2.0f, 3.0f}; + Vectorable v = new Vector(varray); + Vectorable u = new Vector(uarray); + + float[] expectedarray = {2.0f, 4.0f, 6.0f}; + Vectorable expected = new Vector(expectedarray); + + v.addLocal(u); + + assertEquals(expected, v); + } + + @Test + public void testDistance() { + float[] va = {1.0f, 2.0f}; + float[] ua = {2.0f, 3.0f}; + Vectorable v = new Vector(va); + Vectorable u = new Vector(ua); + + float expected = (float) Math.sqrt(2); + + assertEquals(v.distance(u), expected, 1e-5); + } + + @Test + public void testDivide() { + float[] va = {1.0f, 2.0f}; + Vectorable v = new Vector(va); + + float[] ea = {0.5f, 1.0f}; + Vectorable expected = new Vector(ea); + + assertEquals(expected, v.divide(2)); + } + + @Test + public void testDot() { + float[] a = {1.0f, 2.0f}; + Vectorable v = new Vector(a); + Vectorable u = new Vector(a); + + float expected = 5.0f; + + assertEquals(expected, v.dot(u), 1e-5); + } + + @Test + public void testGet() { + float[] va = {1.0f, 2.0f}; + Vectorable v = new Vector(va); + + assertEquals(1.0f, v.get(0), 1e-5); + assertEquals(2.0f, v.get(1), 1e-5); + } + + @Test + public void testLength() { + float[] va = {1.0f, 2.0f}; + Vectorable v = new Vector(va); + + float expected = (float) Math.sqrt(5.0); + + assertEquals(expected, v.length(), 1e-5); + } + + @Test + public void testMult() { + float[] va = {1.0f, 2.0f, 3.0f}; + Vectorable v = new Vector(va); + + float[] ea = {2.0f, 4.0f, 6.0f}; + Vectorable expected = new Vector(ea); + + assertEquals(expected, v.mult(2)); + } + + @Test + public void testNegate() { + float[] va = {1.0f, 2.0f, 3.0f}; + Vectorable v = new Vector(va); + + float[] ea = {-1.0f, -2.0f, -3.0f}; + Vectorable expected = new Vector(ea); + + assertEquals(expected, v.negate()); + } + + @Test + public void testNormalize() { + float[] va = {1.0f, 2.0f}; + Vectorable v = new Vector(va); + + float[] ea = {1.0f / (float) Math.sqrt(5), 2.0f / (float) Math.sqrt(5)}; + Vectorable expected = new Vector(ea); + + assertEquals(expected, v.normalize()); + } + + @Test + public void testSubstract() { + float[] va = {1.0f, 2.0f}; + float[] ua = {2.0f, 1.0f}; + Vectorable v = new Vector(va); + Vectorable u = new Vector(ua); + + float[] ea = {-1.0f, 1.0f}; + Vectorable expected = new Vector(ea); + + assertEquals(expected, v.substract(u)); + } + + @Test + public void testZero() { + float[] va = {1.0f, 2.0f}; + Vectorable v = new Vector(va); + + float[] ea = {0, 0}; + Vectorable expected = new Vector(ea); + + assertEquals(expected, v.zero()); + } +} diff --git a/jme3-core/src/tools/java/jme3tools/optimize/GeometryBatchFactory.java b/jme3-core/src/tools/java/jme3tools/optimize/GeometryBatchFactory.java index 9904b32836..55491773d4 100644 --- a/jme3-core/src/tools/java/jme3tools/optimize/GeometryBatchFactory.java +++ b/jme3-core/src/tools/java/jme3tools/optimize/GeometryBatchFactory.java @@ -1,7 +1,7 @@ package jme3tools.optimize; import com.jme3.material.Material; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrixable; import com.jme3.math.Transform; import com.jme3.math.Vector3f; import com.jme3.scene.*; @@ -23,7 +23,7 @@ public class GeometryBatchFactory { private static final Logger logger = Logger.getLogger(GeometryBatchFactory.class.getName()); - private static void doTransformVerts(FloatBuffer inBuf, int offset, FloatBuffer outBuf, Matrix4f transform) { + private static void doTransformVerts(FloatBuffer inBuf, int offset, FloatBuffer outBuf, Matrixable transform) { Vector3f pos = new Vector3f(); // offset is given in element units @@ -43,7 +43,7 @@ private static void doTransformVerts(FloatBuffer inBuf, int offset, FloatBuffer } } - private static void doTransformNorms(FloatBuffer inBuf, int offset, FloatBuffer outBuf, Matrix4f transform) { + private static void doTransformNorms(FloatBuffer inBuf, int offset, FloatBuffer outBuf, Matrixable transform) { Vector3f norm = new Vector3f(); // offset is given in element units @@ -63,7 +63,7 @@ private static void doTransformNorms(FloatBuffer inBuf, int offset, FloatBuffer } } - private static void doTransformTangents(FloatBuffer inBuf, int offset, int components, FloatBuffer outBuf, Matrix4f transform) { + private static void doTransformTangents(FloatBuffer inBuf, int offset, int components, FloatBuffer outBuf, Matrixable transform) { Vector3f tan = new Vector3f(); // offset is given in element units @@ -190,7 +190,7 @@ public static void mergeGeometries(Collection geometries, Mesh outMesh for (Geometry geom : geometries) { Mesh inMesh = geom.getMesh(); geom.computeWorldMatrix(); - Matrix4f worldMatrix = geom.getWorldMatrix(); + Matrixable worldMatrix = geom.getWorldMatrix(); int geomVertCount = inMesh.getVertexCount(); int geomTriCount = inMesh.getTriangleCount(); diff --git a/jme3-effects/src/main/java/com/jme3/water/WaterFilter.java b/jme3-effects/src/main/java/com/jme3/water/WaterFilter.java index e4a60d995b..2eace6b5a9 100644 --- a/jme3-effects/src/main/java/com/jme3/water/WaterFilter.java +++ b/jme3-effects/src/main/java/com/jme3/water/WaterFilter.java @@ -75,11 +75,12 @@ public class WaterFilter extends Filter { protected Ray ray = new Ray(); private Vector3f targetLocation = new Vector3f(); private ReflectionProcessor reflectionProcessor; - private Matrix4f biasMatrix = new Matrix4f(0.5f, 0.0f, 0.0f, 0.5f, + private float[] data = {0.5f, 0.0f, 0.0f, 0.5f, 0.0f, 0.5f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.5f, - 0.0f, 0.0f, 0.0f, 1.0f); - private Matrix4f textureProjMatrix = new Matrix4f(); + 0.0f, 0.0f, 0.0f, 1.0f}; + private Matrixable biasMatrix = new Matrix(data); + private Matrix textureProjMatrix = new Matrix(4); private boolean underWater; private RenderManager renderManager; private ViewPort viewPort; diff --git a/jme3-examples/src/main/java/jme3test/bullet/BombControl.java b/jme3-examples/src/main/java/jme3test/bullet/BombControl.java index c02e5a4412..3d4fcbf9ab 100644 --- a/jme3-examples/src/main/java/jme3test/bullet/BombControl.java +++ b/jme3-examples/src/main/java/jme3test/bullet/BombControl.java @@ -43,7 +43,7 @@ import com.jme3.bullet.objects.PhysicsGhostObject; import com.jme3.bullet.objects.PhysicsRigidBody; import com.jme3.effect.ParticleEmitter; -import com.jme3.effect.ParticleMesh.Type; +import com.jme3.effect.ParticleTriMesh; import com.jme3.effect.shapes.EmitterSphereShape; import com.jme3.export.JmeExporter; import com.jme3.export.JmeImporter; @@ -91,7 +91,7 @@ public void setPhysicsSpace(PhysicsSpace space) { private void prepareEffect(AssetManager assetManager) { int COUNT_FACTOR = 1; float COUNT_FACTOR_F = 1f; - effect = new ParticleEmitter("Flame", Type.Triangle, 32 * COUNT_FACTOR); + effect = new ParticleEmitter("Flame", new ParticleTriMesh(), 32 * COUNT_FACTOR); effect.setSelectRandomImage(true); effect.setStartColor(new ColorRGBA(1f, 0.4f, 0.05f, (float) (1f / COUNT_FACTOR_F))); effect.setEndColor(new ColorRGBA(.4f, .22f, .12f, 0f)); diff --git a/jme3-examples/src/main/java/jme3test/bullet/TestAttachDriver.java b/jme3-examples/src/main/java/jme3test/bullet/TestAttachDriver.java index 8f9447ea17..5ec292dbc5 100644 --- a/jme3-examples/src/main/java/jme3test/bullet/TestAttachDriver.java +++ b/jme3-examples/src/main/java/jme3test/bullet/TestAttachDriver.java @@ -282,7 +282,7 @@ public void onAction(String binding, boolean value, float tpf) { if (value) { System.out.println("Reset"); vehicle.setPhysicsLocation(new Vector3f(0, 0, 0)); - vehicle.setPhysicsRotation(new Matrix3f()); + vehicle.setPhysicsRotation(new Matrix(3)); vehicle.setLinearVelocity(Vector3f.ZERO); vehicle.setAngularVelocity(Vector3f.ZERO); vehicle.resetSuspension(); diff --git a/jme3-examples/src/main/java/jme3test/bullet/TestFancyCar.java b/jme3-examples/src/main/java/jme3test/bullet/TestFancyCar.java index ca64536def..51fadf8771 100644 --- a/jme3-examples/src/main/java/jme3test/bullet/TestFancyCar.java +++ b/jme3-examples/src/main/java/jme3test/bullet/TestFancyCar.java @@ -45,7 +45,7 @@ import com.jme3.input.controls.KeyTrigger; import com.jme3.light.DirectionalLight; import com.jme3.math.FastMath; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrix; import com.jme3.math.Vector3f; import com.jme3.renderer.queue.RenderQueue.ShadowMode; import com.jme3.scene.Geometry; @@ -251,7 +251,7 @@ else if (binding.equals("Ups")) { if (value) { System.out.println("Reset"); player.setPhysicsLocation(Vector3f.ZERO); - player.setPhysicsRotation(new Matrix3f()); + player.setPhysicsRotation(new Matrix(3)); player.setLinearVelocity(Vector3f.ZERO); player.setAngularVelocity(Vector3f.ZERO); player.resetSuspension(); diff --git a/jme3-examples/src/main/java/jme3test/bullet/TestHoveringTank.java b/jme3-examples/src/main/java/jme3test/bullet/TestHoveringTank.java index 5f058e68bb..6a77e8a983 100644 --- a/jme3-examples/src/main/java/jme3test/bullet/TestHoveringTank.java +++ b/jme3-examples/src/main/java/jme3test/bullet/TestHoveringTank.java @@ -207,7 +207,7 @@ public void onAction(String binding, boolean value, float tpf) { if (value) { System.out.println("Reset"); hoverControl.setPhysicsLocation(new Vector3f(-140, 14, -23)); - hoverControl.setPhysicsRotation(new Matrix3f()); + hoverControl.setPhysicsRotation(new Matrix(3)); hoverControl.clearForces(); } else { } diff --git a/jme3-examples/src/main/java/jme3test/bullet/TestPhysicsCar.java b/jme3-examples/src/main/java/jme3test/bullet/TestPhysicsCar.java index 4ba4e060be..546fa2cf9f 100644 --- a/jme3-examples/src/main/java/jme3test/bullet/TestPhysicsCar.java +++ b/jme3-examples/src/main/java/jme3test/bullet/TestPhysicsCar.java @@ -44,7 +44,7 @@ import com.jme3.material.Material; import com.jme3.math.ColorRGBA; import com.jme3.math.FastMath; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrix; import com.jme3.math.Vector3f; import com.jme3.scene.Geometry; import com.jme3.scene.Node; @@ -213,7 +213,7 @@ public void onAction(String binding, boolean value, float tpf) { if (value) { System.out.println("Reset"); vehicle.setPhysicsLocation(Vector3f.ZERO); - vehicle.setPhysicsRotation(new Matrix3f()); + vehicle.setPhysicsRotation(new Matrix(3)); vehicle.setLinearVelocity(Vector3f.ZERO); vehicle.setAngularVelocity(Vector3f.ZERO); vehicle.resetSuspension(); diff --git a/jme3-examples/src/main/java/jme3test/bullet/TestWalkingChar.java b/jme3-examples/src/main/java/jme3test/bullet/TestWalkingChar.java index a66a6ecc13..a6efa9686c 100644 --- a/jme3-examples/src/main/java/jme3test/bullet/TestWalkingChar.java +++ b/jme3-examples/src/main/java/jme3test/bullet/TestWalkingChar.java @@ -46,7 +46,7 @@ import com.jme3.bullet.control.RigidBodyControl; import com.jme3.bullet.util.CollisionShapeFactory; import com.jme3.effect.ParticleEmitter; -import com.jme3.effect.ParticleMesh.Type; +import com.jme3.effect.ParticleTriMesh; import com.jme3.effect.shapes.EmitterSphereShape; import com.jme3.input.ChaseCamera; import com.jme3.input.KeyInput; @@ -206,7 +206,7 @@ private void prepareBullet() { private void prepareEffect() { int COUNT_FACTOR = 1; float COUNT_FACTOR_F = 1f; - effect = new ParticleEmitter("Flame", Type.Triangle, 32 * COUNT_FACTOR); + effect = new ParticleEmitter("Flame", new ParticleTriMesh(), 32 * COUNT_FACTOR); effect.setSelectRandomImage(true); effect.setStartColor(new ColorRGBA(1f, 0.4f, 0.05f, (float) (1f / COUNT_FACTOR_F))); effect.setEndColor(new ColorRGBA(.4f, .22f, .12f, 0f)); diff --git a/jme3-examples/src/main/java/jme3test/effect/TestExplosionEffect.java b/jme3-examples/src/main/java/jme3test/effect/TestExplosionEffect.java index 5d2d781a6d..7d62f1a756 100644 --- a/jme3-examples/src/main/java/jme3test/effect/TestExplosionEffect.java +++ b/jme3-examples/src/main/java/jme3test/effect/TestExplosionEffect.java @@ -34,7 +34,9 @@ import com.jme3.app.SimpleApplication; import com.jme3.effect.ParticleEmitter; -import com.jme3.effect.ParticleMesh.Type; +import com.jme3.effect.ParticleMesh; +import com.jme3.effect.ParticlePointMesh; +import com.jme3.effect.ParticleTriMesh; import com.jme3.effect.shapes.EmitterSphereShape; import com.jme3.material.Material; import com.jme3.math.ColorRGBA; @@ -56,7 +58,7 @@ public class TestExplosionEffect extends SimpleApplication { private static final float COUNT_FACTOR_F = 1f; private static final boolean POINT_SPRITE = true; - private static final Type EMITTER_TYPE = POINT_SPRITE ? Type.Point : Type.Triangle; + private static final ParticleMesh EMITTER_TYPE = POINT_SPRITE ? new ParticlePointMesh() : new ParticleTriMesh(); public static void main(String[] args){ TestExplosionEffect app = new TestExplosionEffect(); @@ -132,7 +134,7 @@ private void createRoundSpark(){ } private void createSpark(){ - spark = new ParticleEmitter("Spark", Type.Triangle, 30 * COUNT_FACTOR); + spark = new ParticleEmitter("Spark", new ParticleTriMesh(), 30 * COUNT_FACTOR); spark.setStartColor(new ColorRGBA(1f, 0.8f, 0.36f, (float) (1.0f / COUNT_FACTOR_F))); spark.setEndColor(new ColorRGBA(1f, 0.8f, 0.36f, 0f)); spark.setStartSize(.5f); @@ -153,7 +155,7 @@ private void createSpark(){ } private void createSmokeTrail(){ - smoketrail = new ParticleEmitter("SmokeTrail", Type.Triangle, 22 * COUNT_FACTOR); + smoketrail = new ParticleEmitter("SmokeTrail", new ParticleTriMesh(), 22 * COUNT_FACTOR); smoketrail.setStartColor(new ColorRGBA(1f, 0.8f, 0.36f, (float) (1.0f / COUNT_FACTOR_F))); smoketrail.setEndColor(new ColorRGBA(1f, 0.8f, 0.36f, 0f)); smoketrail.setStartSize(.2f); @@ -176,7 +178,7 @@ private void createSmokeTrail(){ } private void createDebris(){ - debris = new ParticleEmitter("Debris", Type.Triangle, 15 * COUNT_FACTOR); + debris = new ParticleEmitter("Debris", new ParticleTriMesh(), 15 * COUNT_FACTOR); debris.setSelectRandomImage(true); debris.setRandomAngle(true); debris.setRotateSpeed(FastMath.TWO_PI * 4); @@ -201,7 +203,7 @@ private void createDebris(){ } private void createShockwave(){ - shockwave = new ParticleEmitter("Shockwave", Type.Triangle, 1 * COUNT_FACTOR); + shockwave = new ParticleEmitter("Shockwave", new ParticleTriMesh(), 1 * COUNT_FACTOR); // shockwave.setRandomAngle(true); shockwave.setFaceNormal(Vector3f.UNIT_Y); shockwave.setStartColor(new ColorRGBA(.48f, 0.17f, 0.01f, (float) (.8f / COUNT_FACTOR_F))); diff --git a/jme3-examples/src/main/java/jme3test/effect/TestMovingParticle.java b/jme3-examples/src/main/java/jme3test/effect/TestMovingParticle.java index d603e229a9..b206ebc8b8 100644 --- a/jme3-examples/src/main/java/jme3test/effect/TestMovingParticle.java +++ b/jme3-examples/src/main/java/jme3test/effect/TestMovingParticle.java @@ -33,7 +33,7 @@ import com.jme3.app.SimpleApplication; import com.jme3.effect.ParticleEmitter; -import com.jme3.effect.ParticleMesh.Type; +import com.jme3.effect.ParticleTriMesh; import com.jme3.input.KeyInput; import com.jme3.input.controls.ActionListener; import com.jme3.input.controls.KeyTrigger; @@ -58,7 +58,7 @@ public static void main(String[] args) { @Override public void simpleInitApp() { - emit = new ParticleEmitter("Emitter", Type.Triangle, 300); + emit = new ParticleEmitter("Emitter", new ParticleTriMesh(), 300); emit.setGravity(0, 0, 0); emit.setVelocityVariation(1); emit.setLowLife(1); diff --git a/jme3-examples/src/main/java/jme3test/effect/TestParticleExportingCloning.java b/jme3-examples/src/main/java/jme3test/effect/TestParticleExportingCloning.java index d245de23fc..7bd942a65b 100644 --- a/jme3-examples/src/main/java/jme3test/effect/TestParticleExportingCloning.java +++ b/jme3-examples/src/main/java/jme3test/effect/TestParticleExportingCloning.java @@ -34,7 +34,7 @@ import com.jme3.app.SimpleApplication; import com.jme3.effect.ParticleEmitter; -import com.jme3.effect.ParticleMesh.Type; +import com.jme3.effect.ParticleTriMesh; import com.jme3.effect.shapes.EmitterSphereShape; import com.jme3.export.binary.BinaryExporter; import com.jme3.export.binary.BinaryImporter; @@ -52,7 +52,7 @@ public static void main(String[] args){ @Override public void simpleInitApp() { - ParticleEmitter emit = new ParticleEmitter("Emitter", Type.Triangle, 200); + ParticleEmitter emit = new ParticleEmitter("Emitter", new ParticleTriMesh(), 200); emit.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f)); emit.setGravity(0, 0, 0); emit.setLowLife(5); diff --git a/jme3-examples/src/main/java/jme3test/effect/TestPointSprite.java b/jme3-examples/src/main/java/jme3test/effect/TestPointSprite.java index 1a3e89092b..62fa9a2bf3 100644 --- a/jme3-examples/src/main/java/jme3test/effect/TestPointSprite.java +++ b/jme3-examples/src/main/java/jme3test/effect/TestPointSprite.java @@ -34,7 +34,7 @@ import com.jme3.app.SimpleApplication; import com.jme3.effect.ParticleEmitter; -import com.jme3.effect.ParticleMesh.Type; +import com.jme3.effect.ParticlePointMesh; import com.jme3.effect.shapes.EmitterBoxShape; import com.jme3.input.KeyInput; import com.jme3.input.controls.ActionListener; @@ -52,7 +52,7 @@ public static void main(String[] args){ @Override public void simpleInitApp() { - final ParticleEmitter emit = new ParticleEmitter("Emitter", Type.Point, 10000); + final ParticleEmitter emit = new ParticleEmitter("Emitter", new ParticlePointMesh(), 10000); emit.setShape(new EmitterBoxShape(new Vector3f(-1.8f, -1.8f, -1.8f), new Vector3f(1.8f, 1.8f, 1.8f))); emit.setGravity(0, 0, 0); diff --git a/jme3-examples/src/main/java/jme3test/effect/TestSoftParticles.java b/jme3-examples/src/main/java/jme3test/effect/TestSoftParticles.java index 3d8f96d658..f48c55d6be 100644 --- a/jme3-examples/src/main/java/jme3test/effect/TestSoftParticles.java +++ b/jme3-examples/src/main/java/jme3test/effect/TestSoftParticles.java @@ -33,7 +33,7 @@ import com.jme3.app.SimpleApplication; import com.jme3.effect.ParticleEmitter; -import com.jme3.effect.ParticleMesh; +import com.jme3.effect.ParticleTriMesh; import com.jme3.effect.shapes.EmitterSphereShape; import com.jme3.input.KeyInput; import com.jme3.input.MouseInput; @@ -140,7 +140,7 @@ private void createParticles() { material.setFloat("Softness", 3f); // //Fire - ParticleEmitter fire = new ParticleEmitter("Fire", ParticleMesh.Type.Triangle, 30); + ParticleEmitter fire = new ParticleEmitter("Fire", new ParticleTriMesh(), 30); fire.setMaterial(material); fire.setShape(new EmitterSphereShape(Vector3f.ZERO, 0.1f)); fire.setImagesX(2); @@ -157,7 +157,7 @@ private void createParticles() { particleNode.attachChild(fire); - ParticleEmitter smoke = new ParticleEmitter("Smoke", ParticleMesh.Type.Triangle, 30); + ParticleEmitter smoke = new ParticleEmitter("Smoke", new ParticleTriMesh(), 30); smoke.setMaterial(material); smoke.setShape(new EmitterSphereShape(Vector3f.ZERO, 5)); smoke.setImagesX(1); diff --git a/jme3-examples/src/main/java/jme3test/helloworld/HelloEffects.java b/jme3-examples/src/main/java/jme3test/helloworld/HelloEffects.java index 1210c7040e..b5fad9a90a 100644 --- a/jme3-examples/src/main/java/jme3test/helloworld/HelloEffects.java +++ b/jme3-examples/src/main/java/jme3test/helloworld/HelloEffects.java @@ -35,6 +35,7 @@ import com.jme3.app.SimpleApplication; import com.jme3.effect.ParticleEmitter; import com.jme3.effect.ParticleMesh; +import com.jme3.effect.ParticleTriMesh; import com.jme3.material.Material; import com.jme3.math.ColorRGBA; import com.jme3.math.Vector3f; @@ -50,7 +51,7 @@ public static void main(String[] args) { @Override public void simpleInitApp() { ParticleEmitter fire = - new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, 30); + new ParticleEmitter("Emitter", new ParticleTriMesh(), 30); Material mat_red = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"); mat_red.setTexture("Texture", assetManager.loadTexture( @@ -70,7 +71,7 @@ public void simpleInitApp() { rootNode.attachChild(fire); ParticleEmitter debris = - new ParticleEmitter("Debris", ParticleMesh.Type.Triangle, 10); + new ParticleEmitter("Debris", new ParticleTriMesh(), 10); Material debris_mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"); debris_mat.setTexture("Texture", assetManager.loadTexture( diff --git a/jme3-examples/src/main/java/jme3test/light/TestTransparentShadow.java b/jme3-examples/src/main/java/jme3test/light/TestTransparentShadow.java index 23fe73c12e..abade91b64 100644 --- a/jme3-examples/src/main/java/jme3test/light/TestTransparentShadow.java +++ b/jme3-examples/src/main/java/jme3test/light/TestTransparentShadow.java @@ -34,6 +34,7 @@ import com.jme3.app.SimpleApplication; import com.jme3.effect.ParticleEmitter; import com.jme3.effect.ParticleMesh; +import com.jme3.effect.ParticleTriMesh; import com.jme3.input.KeyInput; import com.jme3.input.controls.ActionListener; import com.jme3.input.controls.KeyTrigger; @@ -94,7 +95,7 @@ public void simpleInitApp() { rootNode.attachChild(tree); // Uses Texture from jme3-test-data library! - ParticleEmitter fire = new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, 30); + ParticleEmitter fire = new ParticleEmitter("Emitter", new ParticleTriMesh(), 30); Material mat_red = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"); mat_red.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png")); fire.setShadowMode(ShadowMode.Cast); diff --git a/jme3-examples/src/main/java/jme3test/post/TestMultiRenderTarget.java b/jme3-examples/src/main/java/jme3test/post/TestMultiRenderTarget.java index 797d238dc5..141ea1d7b9 100644 --- a/jme3-examples/src/main/java/jme3test/post/TestMultiRenderTarget.java +++ b/jme3-examples/src/main/java/jme3test/post/TestMultiRenderTarget.java @@ -37,7 +37,7 @@ import com.jme3.material.Material; import com.jme3.math.ColorRGBA; import com.jme3.math.FastMath; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrixable; import com.jme3.math.Quaternion; import com.jme3.math.Vector3f; import com.jme3.post.SceneProcessor; @@ -215,7 +215,7 @@ public boolean isInitialized() { } public void preFrame(float tpf) { - Matrix4f inverseViewProj = cam.getViewProjectionMatrix().invert(); + Matrixable inverseViewProj = cam.getViewProjectionMatrix().invert(); mat.setMatrix4("ViewProjectionMatrixInverse", inverseViewProj); techOrig = renderManager.getForcedTechnique(); renderManager.setForcedTechnique("GBuf"); diff --git a/jme3-examples/src/main/java/jme3test/water/TestPostWater.java b/jme3-examples/src/main/java/jme3test/water/TestPostWater.java index a03aeb393b..4d94fc432c 100644 --- a/jme3-examples/src/main/java/jme3test/water/TestPostWater.java +++ b/jme3-examples/src/main/java/jme3test/water/TestPostWater.java @@ -5,6 +5,7 @@ import com.jme3.audio.LowPassFilter; import com.jme3.effect.ParticleEmitter; import com.jme3.effect.ParticleMesh; +import com.jme3.effect.ParticleTriMesh; import com.jme3.input.KeyInput; import com.jme3.input.controls.ActionListener; import com.jme3.input.controls.KeyTrigger; @@ -222,7 +223,7 @@ private void createFire() { /** * Uses Texture from jme3-test-data library! */ - ParticleEmitter fire = new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, 30); + ParticleEmitter fire = new ParticleEmitter("Emitter", new ParticleTriMesh(), 30); Material mat_red = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md"); mat_red.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png")); diff --git a/jme3-jbullet/src/main/java/com/jme3/bullet/collision/shapes/CompoundCollisionShape.java b/jme3-jbullet/src/main/java/com/jme3/bullet/collision/shapes/CompoundCollisionShape.java index 5cbc208d4d..723dfcd456 100644 --- a/jme3-jbullet/src/main/java/com/jme3/bullet/collision/shapes/CompoundCollisionShape.java +++ b/jme3-jbullet/src/main/java/com/jme3/bullet/collision/shapes/CompoundCollisionShape.java @@ -39,7 +39,8 @@ import com.jme3.export.JmeExporter; import com.jme3.export.JmeImporter; import com.jme3.export.OutputCapsule; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.math.Vector3f; import java.io.IOException; import java.util.ArrayList; @@ -67,9 +68,9 @@ public CompoundCollisionShape() { * @param location the local location of the child shape */ public void addChildShape(CollisionShape shape, Vector3f location) { - Transform transA = new Transform(Converter.convert(new Matrix3f())); + Transform transA = new Transform(Converter.convert(new Matrix(3))); Converter.convert(location, transA.origin); - children.add(new ChildCollisionShape(location.clone(), new Matrix3f(), shape)); + children.add(new ChildCollisionShape(location.clone(), new Matrix(3), shape)); ((CompoundShape) cShape).addChildShape(transA, shape.getCShape()); } @@ -78,7 +79,7 @@ public void addChildShape(CollisionShape shape, Vector3f location) { * @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) { + public void addChildShape(CollisionShape shape, Vector3f location, Matrixable rotation) { if(shape instanceof CompoundCollisionShape){ throw new IllegalStateException("CompoundCollisionShapes cannot have CompoundCollisionShapes as children!"); } @@ -89,7 +90,7 @@ public void addChildShape(CollisionShape shape, Vector3f location, Matrix3f rota ((CompoundShape) cShape).addChildShape(transA, shape.getCShape()); } - private void addChildShapeDirect(CollisionShape shape, Vector3f location, Matrix3f rotation) { + private void addChildShapeDirect(CollisionShape shape, Vector3f location, Matrixable rotation) { if(shape instanceof CompoundCollisionShape){ throw new IllegalStateException("CompoundCollisionShapes cannot have CompoundCollisionShapes as children!"); } diff --git a/jme3-jbullet/src/main/java/com/jme3/bullet/joints/ConeJoint.java b/jme3-jbullet/src/main/java/com/jme3/bullet/joints/ConeJoint.java index 45afa9d1af..c6765f387c 100644 --- a/jme3-jbullet/src/main/java/com/jme3/bullet/joints/ConeJoint.java +++ b/jme3-jbullet/src/main/java/com/jme3/bullet/joints/ConeJoint.java @@ -39,7 +39,7 @@ import com.jme3.export.JmeExporter; import com.jme3.export.JmeImporter; import com.jme3.export.OutputCapsule; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrix; import com.jme3.math.Vector3f; import java.io.IOException; @@ -52,7 +52,7 @@ */ public class ConeJoint extends PhysicsJoint { - protected Matrix3f rotA, rotB; + protected Matrix rotA, rotB; protected float swingSpan1 = 1e30f; protected float swingSpan2 = 1e30f; protected float twistSpan = 1e30f; @@ -67,8 +67,8 @@ public ConeJoint() { */ public ConeJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB) { super(nodeA, nodeB, pivotA, pivotB); - this.rotA = new Matrix3f(); - this.rotB = new Matrix3f(); + this.rotA = new Matrix(3); + this.rotB = new Matrix(3); createJoint(); } @@ -76,7 +76,7 @@ public ConeJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA * @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 ConeJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, Matrix3f rotA, Matrix3f rotB) { + public ConeJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, Matrix rotA, Matrix rotB) { super(nodeA, nodeB, pivotA, pivotB); this.rotA = rotA; this.rotB = rotB; @@ -99,8 +99,8 @@ public void setAngularOnly(boolean value) { public void write(JmeExporter ex) throws IOException { super.write(ex); OutputCapsule capsule = ex.getCapsule(this); - capsule.write(rotA, "rotA", new Matrix3f()); - capsule.write(rotB, "rotB", new Matrix3f()); + capsule.write(rotA, "rotA", new Matrix(3)); + capsule.write(rotB, "rotB", new Matrix(3)); capsule.write(angularOnly, "angularOnly", false); capsule.write(swingSpan1, "swingSpan1", 1e30f); @@ -112,8 +112,8 @@ public void write(JmeExporter ex) throws IOException { public void read(JmeImporter im) throws IOException { super.read(im); InputCapsule capsule = im.getCapsule(this); - this.rotA = (Matrix3f) capsule.readSavable("rotA", new Matrix3f()); - this.rotB = (Matrix3f) capsule.readSavable("rotB", new Matrix3f()); + this.rotA = (Matrix) capsule.readSavable("rotA", new Matrix(3)); + this.rotB = (Matrix) capsule.readSavable("rotB", new Matrix(3)); this.angularOnly = capsule.readBoolean("angularOnly", false); this.swingSpan1 = capsule.readFloat("swingSpan1", 1e30f); diff --git a/jme3-jbullet/src/main/java/com/jme3/bullet/joints/SixDofJoint.java b/jme3-jbullet/src/main/java/com/jme3/bullet/joints/SixDofJoint.java index afb45b4874..8ad3c94a33 100644 --- a/jme3-jbullet/src/main/java/com/jme3/bullet/joints/SixDofJoint.java +++ b/jme3-jbullet/src/main/java/com/jme3/bullet/joints/SixDofJoint.java @@ -41,7 +41,8 @@ import com.jme3.export.JmeExporter; import com.jme3.export.JmeImporter; import com.jme3.export.OutputCapsule; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.math.Vector3f; import java.io.IOException; import java.util.Iterator; @@ -75,7 +76,7 @@ public SixDofJoint() { * @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) { + public SixDofJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, Matrixable rotA, Matrixable rotB, boolean useLinearReferenceFrameA) { super(nodeA, nodeB, pivotA, pivotB); this.useLinearReferenceFrameA = useLinearReferenceFrameA; @@ -99,10 +100,10 @@ public SixDofJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivo super(nodeA, nodeB, pivotA, pivotB); this.useLinearReferenceFrameA = useLinearReferenceFrameA; - Transform transA = new Transform(Converter.convert(new Matrix3f())); + Transform transA = new Transform(Converter.convert(new Matrix(3))); Converter.convert(pivotA, transA.origin); - Transform transB = new Transform(Converter.convert(new Matrix3f())); + Transform transB = new Transform(Converter.convert(new Matrix(3))); Converter.convert(pivotB, transB.origin); constraint = new Generic6DofConstraint(nodeA.getObjectId(), nodeB.getObjectId(), transA, transB, useLinearReferenceFrameA); @@ -161,10 +162,10 @@ public void read(JmeImporter im) throws IOException { super.read(im); InputCapsule capsule = im.getCapsule(this); - Transform transA = new Transform(Converter.convert(new Matrix3f())); + Transform transA = new Transform(Converter.convert(new Matrix(3))); Converter.convert(pivotA, transA.origin); - Transform transB = new Transform(Converter.convert(new Matrix3f())); + Transform transB = new Transform(Converter.convert(new Matrix(3))); Converter.convert(pivotB, transB.origin); constraint = new Generic6DofConstraint(nodeA.getObjectId(), nodeB.getObjectId(), transA, transB, useLinearReferenceFrameA); gatherMotors(); diff --git a/jme3-jbullet/src/main/java/com/jme3/bullet/joints/SliderJoint.java b/jme3-jbullet/src/main/java/com/jme3/bullet/joints/SliderJoint.java index 5adf0b8b26..7bf7a941bf 100644 --- a/jme3-jbullet/src/main/java/com/jme3/bullet/joints/SliderJoint.java +++ b/jme3-jbullet/src/main/java/com/jme3/bullet/joints/SliderJoint.java @@ -39,7 +39,8 @@ import com.jme3.export.JmeExporter; import com.jme3.export.JmeImporter; import com.jme3.export.OutputCapsule; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.math.Vector3f; import java.io.IOException; @@ -49,7 +50,7 @@ * @author normenhansen */ public class SliderJoint extends PhysicsJoint { - protected Matrix3f rotA, rotB; + protected Matrixable rotA, rotB; protected boolean useLinearReferenceFrameA; public SliderJoint() { @@ -59,7 +60,7 @@ public SliderJoint() { * @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 SliderJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, Matrix3f rotA, Matrix3f rotB, boolean useLinearReferenceFrameA) { + public SliderJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, Matrixable rotA, Matrixable rotB, boolean useLinearReferenceFrameA) { super(nodeA, nodeB, pivotA, pivotB); this.rotA=rotA; this.rotB=rotB; @@ -73,8 +74,8 @@ public SliderJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivo */ public SliderJoint(PhysicsRigidBody nodeA, PhysicsRigidBody nodeB, Vector3f pivotA, Vector3f pivotB, boolean useLinearReferenceFrameA) { super(nodeA, nodeB, pivotA, pivotB); - this.rotA=new Matrix3f(); - this.rotB=new Matrix3f(); + this.rotA=new Matrix(3); + this.rotB=new Matrix(3); this.useLinearReferenceFrameA=useLinearReferenceFrameA; createJoint(); } diff --git a/jme3-jbullet/src/main/java/com/jme3/bullet/objects/PhysicsCharacter.java b/jme3-jbullet/src/main/java/com/jme3/bullet/objects/PhysicsCharacter.java index c057d99d24..a177bbc952 100644 --- a/jme3-jbullet/src/main/java/com/jme3/bullet/objects/PhysicsCharacter.java +++ b/jme3-jbullet/src/main/java/com/jme3/bullet/objects/PhysicsCharacter.java @@ -43,7 +43,7 @@ import com.jme3.export.JmeExporter; import com.jme3.export.JmeImporter; import com.jme3.export.OutputCapsule; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrix; import com.jme3.math.Quaternion; import com.jme3.math.Vector3f; import java.io.IOException; @@ -64,7 +64,7 @@ public class PhysicsCharacter extends PhysicsCollisionObject { protected boolean locationDirty = false; //TEMP VARIABLES protected final Quaternion tmp_inverseWorldRotation = new Quaternion(); - private Transform tempTrans = new Transform(Converter.convert(new Matrix3f())); + private Transform tempTrans = new Transform(Converter.convert(new Matrix(3))); private com.jme3.math.Transform physicsLocation = new com.jme3.math.Transform(); private javax.vecmath.Vector3f tempVec = new javax.vecmath.Vector3f(); diff --git a/jme3-jbullet/src/main/java/com/jme3/bullet/objects/PhysicsGhostObject.java b/jme3-jbullet/src/main/java/com/jme3/bullet/objects/PhysicsGhostObject.java index 19c08ddd2e..c12fd55a04 100644 --- a/jme3-jbullet/src/main/java/com/jme3/bullet/objects/PhysicsGhostObject.java +++ b/jme3-jbullet/src/main/java/com/jme3/bullet/objects/PhysicsGhostObject.java @@ -41,7 +41,8 @@ import com.jme3.export.JmeExporter; import com.jme3.export.JmeImporter; import com.jme3.export.OutputCapsule; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.math.Quaternion; import com.jme3.math.Vector3f; import com.jme3.scene.Spatial; @@ -63,7 +64,7 @@ public class PhysicsGhostObject extends PhysicsCollisionObject { protected boolean locationDirty = false; //TEMP VARIABLES protected final Quaternion tmp_inverseWorldRotation = new Quaternion(); - protected Transform tempTrans = new Transform(Converter.convert(new Matrix3f())); + protected Transform tempTrans = new Transform(Converter.convert(new Matrix(3))); private com.jme3.math.Transform physicsLocation = new com.jme3.math.Transform(); protected javax.vecmath.Quat4f tempRot = new javax.vecmath.Quat4f(); private List overlappingObjects = new LinkedList(); @@ -114,7 +115,7 @@ public void setPhysicsLocation(Vector3f location) { * Sets the physics object rotation * @param rotation the rotation of the actual physics object */ - public void setPhysicsRotation(Matrix3f rotation) { + public void setPhysicsRotation(Matrixable rotation) { gObject.getWorldTransform(tempTrans); Converter.convert(rotation, tempTrans.basis); gObject.setWorldTransform(tempTrans); @@ -164,9 +165,9 @@ public Quaternion getPhysicsRotation(Quaternion rot) { /** * @return the physicsLocation */ - public Matrix3f getPhysicsRotationMatrix(Matrix3f rot) { + public Matrix getPhysicsRotationMatrix(Matrix rot) { if (rot == null) { - rot = new Matrix3f(); + rot = new Matrix(3); } gObject.getWorldTransform(tempTrans); Converter.convert(tempTrans.getRotation(tempRot), physicsLocation.getRotation()); @@ -191,7 +192,7 @@ public Quaternion getPhysicsRotation() { return physicsLocation.getRotation(); } - public Matrix3f getPhysicsRotationMatrix() { + public Matrixable getPhysicsRotationMatrix() { gObject.getWorldTransform(tempTrans); Converter.convert(tempTrans.getRotation(tempRot), physicsLocation.getRotation()); return physicsLocation.getRotation().toRotationMatrix(); @@ -266,7 +267,7 @@ public void write(JmeExporter e) throws IOException { super.write(e); OutputCapsule capsule = e.getCapsule(this); capsule.write(getPhysicsLocation(new Vector3f()), "physicsLocation", new Vector3f()); - capsule.write(getPhysicsRotationMatrix(new Matrix3f()), "physicsRotation", new Matrix3f()); + capsule.write(getPhysicsRotationMatrix(new Matrix(3)), "physicsRotation", new Matrix(3)); capsule.write(getCcdMotionThreshold(), "ccdMotionThreshold", 0); capsule.write(getCcdSweptSphereRadius(), "ccdSweptSphereRadius", 0); } @@ -277,7 +278,7 @@ public void read(JmeImporter e) throws IOException { InputCapsule capsule = e.getCapsule(this); buildObject(); setPhysicsLocation((Vector3f) capsule.readSavable("physicsLocation", new Vector3f())); - setPhysicsRotation(((Matrix3f) capsule.readSavable("physicsRotation", new Matrix3f()))); + setPhysicsRotation(((Matrixable) capsule.readSavable("physicsRotation", new Matrix(3)))); setCcdMotionThreshold(capsule.readFloat("ccdMotionThreshold", 0)); setCcdSweptSphereRadius(capsule.readFloat("ccdSweptSphereRadius", 0)); } diff --git a/jme3-jbullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java b/jme3-jbullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java index 6798c63fd1..71ee2d35c3 100644 --- a/jme3-jbullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java +++ b/jme3-jbullet/src/main/java/com/jme3/bullet/objects/PhysicsRigidBody.java @@ -46,7 +46,8 @@ import com.jme3.export.JmeExporter; import com.jme3.export.JmeImporter; import com.jme3.export.OutputCapsule; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.math.Quaternion; import com.jme3.math.Vector3f; import java.io.IOException; @@ -155,7 +156,7 @@ public void setPhysicsLocation(Vector3f location) { * Sets the physics object rotation * @param rotation the rotation of the actual physics object */ - public void setPhysicsRotation(Matrix3f rotation) { + public void setPhysicsRotation(Matrixable rotation) { rBody.getCenterOfMassTransform(tempTrans); Converter.convert(rotation, tempTrans.basis); rBody.setCenterOfMassTransform(tempTrans); @@ -183,7 +184,7 @@ public Vector3f getPhysicsLocation() { /** * Gets the physics object rotation */ - public Matrix3f getPhysicsRotationMatrix() { + public Matrixable getPhysicsRotationMatrix() { return getPhysicsRotationMatrix(null); } @@ -203,9 +204,9 @@ public Vector3f getPhysicsLocation(Vector3f location) { * Gets the physics object rotation as a matrix, no conversions and no object instantiation * @param rotation the rotation of the actual physics object is stored in this Matrix3f */ - public Matrix3f getPhysicsRotationMatrix(Matrix3f rotation) { + public Matrix getPhysicsRotationMatrix(Matrix rotation) { if (rotation == null) { - rotation = new Matrix3f(); + rotation = new Matrix(3); } rBody.getCenterOfMassTransform(tempTrans); return Converter.convert(tempTrans.basis, rotation); @@ -247,9 +248,9 @@ public Vector3f getInterpolatedPhysicsLocation(Vector3f location) { * Gets the physics object rotation * @param rotation the rotation of the actual physics object is stored in this Matrix3f */ - public Matrix3f getInterpolatedPhysicsRotation(Matrix3f rotation) { + public Matrixable getInterpolatedPhysicsRotation(Matrix rotation) { if (rotation == null) { - rotation = new Matrix3f(); + rotation = new Matrix(3); } rBody.getInterpolationWorldTransform(tempTrans); return Converter.convert(tempTrans.basis, rotation); @@ -636,7 +637,7 @@ public void write(JmeExporter e) throws IOException { capsule.write(getCcdSweptSphereRadius(), "ccdSweptSphereRadius", 0); capsule.write(getPhysicsLocation(new Vector3f()), "physicsLocation", new Vector3f()); - capsule.write(getPhysicsRotationMatrix(new Matrix3f()), "physicsRotation", new Matrix3f()); + capsule.write(getPhysicsRotationMatrix(new Matrix(3)), "physicsRotation", new Matrix(3)); capsule.writeSavableArrayList(joints, "joints", null); } @@ -661,7 +662,7 @@ public void read(JmeImporter e) throws IOException { setCcdSweptSphereRadius(capsule.readFloat("ccdSweptSphereRadius", 0)); setPhysicsLocation((Vector3f) capsule.readSavable("physicsLocation", new Vector3f())); - setPhysicsRotation((Matrix3f) capsule.readSavable("physicsRotation", new Matrix3f())); + setPhysicsRotation((Matrixable) capsule.readSavable("physicsRotation", new Matrix(3))); joints = capsule.readSavableArrayList("joints", null); } diff --git a/jme3-jbullet/src/main/java/com/jme3/bullet/objects/VehicleWheel.java b/jme3-jbullet/src/main/java/com/jme3/bullet/objects/VehicleWheel.java index efcb79ec70..87ae768f9c 100644 --- a/jme3-jbullet/src/main/java/com/jme3/bullet/objects/VehicleWheel.java +++ b/jme3-jbullet/src/main/java/com/jme3/bullet/objects/VehicleWheel.java @@ -31,14 +31,20 @@ */ package com.jme3.bullet.objects; +import java.io.IOException; + import com.bulletphysics.dynamics.RigidBody; import com.jme3.bullet.collision.PhysicsCollisionObject; import com.jme3.bullet.util.Converter; -import com.jme3.export.*; +import com.jme3.export.InputCapsule; +import com.jme3.export.JmeExporter; +import com.jme3.export.JmeImporter; +import com.jme3.export.OutputCapsule; +import com.jme3.export.Savable; +import com.jme3.math.Matrix; import com.jme3.math.Quaternion; import com.jme3.math.Vector3f; import com.jme3.scene.Spatial; -import java.io.IOException; /** * Stores info about one wheel of a PhysicsVehicle @@ -63,7 +69,7 @@ public class VehicleWheel implements Savable { protected Vector3f wheelWorldLocation = new Vector3f(); protected Quaternion wheelWorldRotation = new Quaternion(); protected Spatial wheelSpatial; - protected com.jme3.math.Matrix3f tmp_Matrix = new com.jme3.math.Matrix3f(); + protected com.jme3.math.Matrix tmp_Matrix = new Matrix(3); protected final Quaternion tmp_inverseWorldRotation = new Quaternion(); private boolean applyLocal = false; diff --git a/jme3-jbullet/src/main/java/com/jme3/bullet/objects/infos/RigidBodyMotionState.java b/jme3-jbullet/src/main/java/com/jme3/bullet/objects/infos/RigidBodyMotionState.java index 6de4f040b9..0b7312efc8 100644 --- a/jme3-jbullet/src/main/java/com/jme3/bullet/objects/infos/RigidBodyMotionState.java +++ b/jme3-jbullet/src/main/java/com/jme3/bullet/objects/infos/RigidBodyMotionState.java @@ -35,7 +35,8 @@ import com.bulletphysics.linearmath.Transform; import com.jme3.bullet.objects.PhysicsVehicle; import com.jme3.bullet.util.Converter; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.math.Quaternion; import com.jme3.math.Vector3f; import com.jme3.scene.Spatial; @@ -48,9 +49,9 @@ public class RigidBodyMotionState extends MotionState { //stores the bullet transform - private Transform motionStateTrans = new Transform(Converter.convert(new Matrix3f())); + private Transform motionStateTrans = new Transform(Converter.convert(new Matrix(3))); private Vector3f worldLocation = new Vector3f(); - private Matrix3f worldRotation = new Matrix3f(); + private Matrix worldRotation = new Matrix(3); private Quaternion worldRotationQuat = new Quaternion(); private Vector3f localLocation = new Vector3f(); private Quaternion localRotationQuat = new Quaternion(); @@ -134,7 +135,7 @@ public Vector3f getWorldLocation() { /** * @return the worldRotation */ - public Matrix3f getWorldRotation() { + public Matrixable getWorldRotation() { return worldRotation; } diff --git a/jme3-jbullet/src/main/java/com/jme3/bullet/util/Converter.java b/jme3-jbullet/src/main/java/com/jme3/bullet/util/Converter.java index f9956d0804..2a2705af7d 100644 --- a/jme3-jbullet/src/main/java/com/jme3/bullet/util/Converter.java +++ b/jme3-jbullet/src/main/java/com/jme3/bullet/util/Converter.java @@ -34,6 +34,7 @@ import com.bulletphysics.collision.shapes.IndexedMesh; import com.bulletphysics.dom.HeightfieldTerrainShape; import com.jme3.math.FastMath; +import com.jme3.math.Matrixable; import com.jme3.scene.Mesh; import com.jme3.scene.VertexBuffer.Type; import com.jme3.scene.mesh.IndexBuffer; @@ -173,13 +174,13 @@ public static javax.vecmath.Matrix3f convert(com.jme3.math.Quaternion oldQuatern return newMatrix; } - public static com.jme3.math.Matrix3f convert(javax.vecmath.Matrix3f oldMatrix) { - com.jme3.math.Matrix3f newMatrix = new com.jme3.math.Matrix3f(); + public static Matrixable convert(javax.vecmath.Matrix3f oldMatrix) { + com.jme3.math.Matrix newMatrix = new com.jme3.math.Matrix(3); convert(oldMatrix, newMatrix); return newMatrix; } - public static com.jme3.math.Matrix3f convert(javax.vecmath.Matrix3f oldMatrix, com.jme3.math.Matrix3f newMatrix) { + public static com.jme3.math.Matrix convert(javax.vecmath.Matrix3f oldMatrix, com.jme3.math.Matrix newMatrix) { newMatrix.set(0, 0, oldMatrix.m00); newMatrix.set(0, 1, oldMatrix.m01); newMatrix.set(0, 2, oldMatrix.m02); @@ -192,13 +193,13 @@ public static com.jme3.math.Matrix3f convert(javax.vecmath.Matrix3f oldMatrix, c return newMatrix; } - public static javax.vecmath.Matrix3f convert(com.jme3.math.Matrix3f oldMatrix) { + public static javax.vecmath.Matrix3f convert(Matrixable oldMatrix) { javax.vecmath.Matrix3f newMatrix = new javax.vecmath.Matrix3f(); convert(oldMatrix, newMatrix); return newMatrix; } - public static javax.vecmath.Matrix3f convert(com.jme3.math.Matrix3f oldMatrix, javax.vecmath.Matrix3f newMatrix) { + public static javax.vecmath.Matrix3f convert(Matrixable oldMatrix, javax.vecmath.Matrix3f newMatrix) { newMatrix.m00 = oldMatrix.get(0, 0); newMatrix.m01 = oldMatrix.get(0, 1); newMatrix.m02 = oldMatrix.get(0, 2); diff --git a/jme3-jbullet/src/main/java/com/jme3/bullet/util/DebugShapeFactory.java b/jme3-jbullet/src/main/java/com/jme3/bullet/util/DebugShapeFactory.java index 077326d574..12c60e8603 100644 --- a/jme3-jbullet/src/main/java/com/jme3/bullet/util/DebugShapeFactory.java +++ b/jme3-jbullet/src/main/java/com/jme3/bullet/util/DebugShapeFactory.java @@ -39,7 +39,7 @@ import com.jme3.bullet.collision.shapes.CollisionShape; import com.jme3.bullet.collision.shapes.CompoundCollisionShape; import com.jme3.bullet.collision.shapes.infos.ChildCollisionShape; -import com.jme3.math.Matrix3f; +import com.jme3.math.Matrixable; import com.jme3.scene.Geometry; import com.jme3.scene.Mesh; import com.jme3.scene.Node; @@ -90,7 +90,7 @@ public static Spatial getDebugShape(CollisionShape collisionShape) { // apply rotation TempVars vars = TempVars.get(); - Matrix3f tempRot = vars.tempMat3; + Matrixable tempRot = vars.tempMat3; tempRot.set(geometry.getLocalRotation()); childCollisionShape.rotation.mult(tempRot, tempRot); diff --git a/jme3-niftygui/src/main/java/com/jme3/niftygui/JmeBatchRenderBackend.java b/jme3-niftygui/src/main/java/com/jme3/niftygui/JmeBatchRenderBackend.java index 9dd8310207..f2b9d80c3f 100644 --- a/jme3-niftygui/src/main/java/com/jme3/niftygui/JmeBatchRenderBackend.java +++ b/jme3-niftygui/src/main/java/com/jme3/niftygui/JmeBatchRenderBackend.java @@ -43,7 +43,7 @@ import com.jme3.asset.TextureKey; import com.jme3.material.Material; import com.jme3.material.RenderState; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrix; import com.jme3.renderer.RenderManager; import com.jme3.renderer.Renderer; import com.jme3.scene.Geometry; @@ -88,7 +88,7 @@ public class JmeBatchRenderBackend implements BatchRenderBackend { private Map textures = new HashMap(); private int textureAtlasId = 1; private Batch currentBatch; - private Matrix4f tempMat = new Matrix4f(); + private Matrix tempMat = new Matrix(4); private ByteBuffer initialData; // this is only used for debugging purpose and will make the removed textures filled with a color diff --git a/jme3-niftygui/src/main/java/com/jme3/niftygui/RenderDeviceJme.java b/jme3-niftygui/src/main/java/com/jme3/niftygui/RenderDeviceJme.java index ab0fc6659e..d0b3bb9e37 100644 --- a/jme3-niftygui/src/main/java/com/jme3/niftygui/RenderDeviceJme.java +++ b/jme3-niftygui/src/main/java/com/jme3/niftygui/RenderDeviceJme.java @@ -36,7 +36,7 @@ import com.jme3.material.Material; import com.jme3.material.RenderState; import com.jme3.math.ColorRGBA; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrix; import com.jme3.renderer.RenderManager; import com.jme3.renderer.Renderer; import com.jme3.scene.Geometry; @@ -71,7 +71,7 @@ public class RenderDeviceJme implements RenderDevice { private VertexBuffer quadDefaultTC = quad.getBuffer(Type.TexCoord); private VertexBuffer quadModTC = quadDefaultTC.clone(); private VertexBuffer quadColor; - private Matrix4f tempMat = new Matrix4f(); + private Matrix tempMat = new Matrix(4); private ColorRGBA tempColor = new ColorRGBA(); private RenderState renderState = new RenderState(); diff --git a/jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/FbxLoader.java b/jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/FbxLoader.java index fd157cb487..19cc5f979e 100644 --- a/jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/FbxLoader.java +++ b/jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/FbxLoader.java @@ -43,7 +43,7 @@ import com.jme3.asset.AssetLoader; import com.jme3.asset.AssetManager; import com.jme3.asset.ModelKey; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrix; import com.jme3.math.Transform; import com.jme3.scene.Node; import com.jme3.scene.Spatial; @@ -282,9 +282,9 @@ private void connectObjects(FbxElement element) { */ private void applyBindPoses() { for (FbxBindPose bindPose : bindPoses) { - Map bindPoseData = bindPose.getJmeObject(); + Map bindPoseData = bindPose.getJmeObject(); logger.log(Level.INFO, "Applying {0} bind poses", bindPoseData.size()); - for (Map.Entry entry : bindPoseData.entrySet()) { + for (Map.Entry entry : bindPoseData.entrySet()) { FbxObject obj = objectMap.get(entry.getKey()); if (obj instanceof FbxNode) { FbxNode node = (FbxNode) obj; diff --git a/jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/SceneLoader.java b/jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/SceneLoader.java index 491301c226..b63d815c82 100644 --- a/jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/SceneLoader.java +++ b/jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/SceneLoader.java @@ -60,7 +60,8 @@ import com.jme3.material.RenderState.BlendMode; import com.jme3.math.ColorRGBA; import com.jme3.math.FastMath; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.math.Quaternion; import com.jme3.math.Transform; import com.jme3.math.Vector3f; @@ -910,7 +911,7 @@ private Transform buildTransform(double[] transform) { float[] m = new float[transform.length]; for(int i = 0; i < transform.length; ++i) m[i] = (float) transform[i]; - Matrix4f matrix = new Matrix4f(m); + Matrixable matrix = new Matrix(m); Vector3f pos = matrix.toTranslationVector(); Quaternion rot = matrix.toRotationQuat(); Vector3f scale = matrix.toScaleVector(); diff --git a/jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/anim/FbxBindPose.java b/jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/anim/FbxBindPose.java index 78d37c74ea..856e72d6b8 100644 --- a/jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/anim/FbxBindPose.java +++ b/jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/anim/FbxBindPose.java @@ -32,16 +32,16 @@ package com.jme3.scene.plugins.fbx.anim; import com.jme3.asset.AssetManager; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrix; import com.jme3.scene.plugins.fbx.file.FbxElement; import com.jme3.scene.plugins.fbx.file.FbxId; import com.jme3.scene.plugins.fbx.obj.FbxObject; import java.util.HashMap; import java.util.Map; -public class FbxBindPose extends FbxObject> { +public class FbxBindPose extends FbxObject> { - private final Map bindPose = new HashMap(); + private final Map bindPose = new HashMap(); public FbxBindPose(AssetManager assetManager, String sceneFolderName) { super(assetManager, sceneFolderName); @@ -79,14 +79,14 @@ public void fromElement(FbxElement element) { } if (node != null && matData != null) { - Matrix4f matrix = new Matrix4f(matData); + Matrix matrix = new Matrix(matData); bindPose.put(node, matrix); } } } @Override - protected Map toJmeObject() { + protected Map toJmeObject() { return bindPose; } diff --git a/jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/node/FbxNode.java b/jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/node/FbxNode.java index c0ce06d4b9..27727b42cc 100644 --- a/jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/node/FbxNode.java +++ b/jme3-plugins/src/fbx/java/com/jme3/scene/plugins/fbx/node/FbxNode.java @@ -38,7 +38,8 @@ import com.jme3.material.Material; import com.jme3.math.ColorRGBA; import com.jme3.math.FastMath; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrix; +import com.jme3.math.Matrixable; import com.jme3.math.Quaternion; import com.jme3.math.Transform; import com.jme3.math.Vector3f; @@ -118,7 +119,7 @@ private static enum InheritMode { protected Transform jmeLocalBindPose; // used for debugging only - protected Matrix4f cachedWorldBindPose; + protected Matrixable cachedWorldBindPose; public FbxNode(AssetManager assetManager, String sceneFolderName) { super(assetManager, sceneFolderName); @@ -139,16 +140,16 @@ public Transform computeFbxLocalTransform() { // ScalingPivot, // ScalingOffset - Matrix4f scaleMat = new Matrix4f(); + Matrix scaleMat = new Matrix(4); scaleMat.setScale(jmeLocalNodeTransform.getScale()); - Matrix4f rotationMat = new Matrix4f(); + Matrix rotationMat = new Matrix(4); rotationMat.setRotationQuaternion(jmeLocalNodeTransform.getRotation()); - Matrix4f translationMat = new Matrix4f(); + Matrix translationMat = new Matrix(4); translationMat.setTranslation(jmeLocalNodeTransform.getTranslation()); - Matrix4f result = new Matrix4f(); + Matrixable result = new Matrix(4); result.multLocal(scaleMat).multLocal(rotationMat).multLocal(translationMat); Transform t = new Transform(); @@ -157,7 +158,7 @@ public Transform computeFbxLocalTransform() { return t; } - public void setWorldBindPose(Matrix4f worldBindPose) { + public void setWorldBindPose(Matrixable worldBindPose) { if (cachedWorldBindPose != null) { if (!cachedWorldBindPose.equals(worldBindPose)) { throw new UnsupportedOperationException("Bind poses don't match"); diff --git a/jme3-terrain/src/main/java/com/jme3/terrain/geomipmap/lodcalc/util/EntropyComputeUtil.java b/jme3-terrain/src/main/java/com/jme3/terrain/geomipmap/lodcalc/util/EntropyComputeUtil.java index 0f638830e3..b36b5e02ae 100644 --- a/jme3-terrain/src/main/java/com/jme3/terrain/geomipmap/lodcalc/util/EntropyComputeUtil.java +++ b/jme3-terrain/src/main/java/com/jme3/terrain/geomipmap/lodcalc/util/EntropyComputeUtil.java @@ -31,19 +31,20 @@ */ package com.jme3.terrain.geomipmap.lodcalc.util; +import java.nio.Buffer; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; +import java.nio.ShortBuffer; + import com.jme3.bounding.BoundingBox; import com.jme3.collision.CollisionResults; -import com.jme3.math.Matrix4f; +import com.jme3.math.Matrix; import com.jme3.math.Ray; import com.jme3.math.Vector3f; import com.jme3.scene.Mesh; import com.jme3.scene.VertexBuffer; import com.jme3.scene.VertexBuffer.Type; import com.jme3.util.BufferUtils; -import java.nio.Buffer; -import java.nio.FloatBuffer; -import java.nio.IntBuffer; -import java.nio.ShortBuffer; /** * Computes the entropy value δ (delta) for a given terrain block and @@ -93,7 +94,7 @@ else if (lodIndices instanceof ShortBuffer) { ray.setOrigin(pos); results.clear(); - terrainBlock.collideWith(ray, Matrix4f.IDENTITY, bbox, results); + terrainBlock.collideWith(ray, new Matrix(4), bbox, results); if (results.size() > 0){ Vector3f contactPoint = results.getClosestCollision().getContactPoint();