📄 transformmatrix.java
字号:
*
* @param trans
*/
public void setTranslation(Vector3f trans){
if (trans==null){
throw new JmeException("Vector3f translation must be non-null");
}
translation.set(trans);
}
/**
* Sets the Transform's Translational component
* @param x New X translation
* @param y New Y translation
* @param z New Z translation
*/
public void setTranslation(float x,float y,float z){
translation.set(x,y,z);
}
/**
* Sets the rotational component of this transform to the matrix represented
* by an Euler rotation about x, y, then z.
* @param x The X rotation, in radians
* @param y The Y rotation, in radians
* @param z The Z rotation, in radians
*/
public void setEulerRot(float x,float y,float z){
double A = Math.cos(x);
double B = Math.sin(x);
double C = Math.cos(y);
double D = Math.sin(y);
double E = Math.cos(z);
double F = Math.sin(z);
double AD = A * D;
double BD = B * D;
rot.m00 = (float) (C * E);
rot.m01 = (float) (BD * E + -(A * F));
rot.m02 = (float) (AD * E + B * F);
rot.m10 = (float) (C * F);
rot.m11 = (float) (BD * F + A * E);
rot.m12 = (float) (AD * F + -(B * E));
rot.m20 = (float) -D;
rot.m21 = (float) (B * C);
rot.m22 = (float) (A * C);
}
/**
* <code>setRotationQuaternion</code> builds a rotation from a
* <code>Quaternion</code>.
* @param quat The quaternion to build the rotation from.
* @throws JmeException if quat is null.
*/
public void setRotationQuaternion(Quaternion quat) {
if (null == quat) {
throw new JmeException("Quat may not be null.");
}
rot.set(quat);
}
/**
* <code>invertRotInPlace</code> inverts the rotational component of this Matrix
* in place
*/
private void invertRotInPlace() {
float temp;
temp=rot.m01;
rot.m01=rot.m10;
rot.m10=temp;
temp=rot.m02;
rot.m02=rot.m20;
rot.m20=temp;
temp=rot.m21;
rot.m21=rot.m12;
rot.m12=temp;
}
/**
* Stores the rotational part of this matrix into the passed matrix.
* Will create a new Matrix3f if given matrix is null. Returns the
* given matrix after it has been loaded with rotation values, to allow
* chaining
*
* @param rotStore The matrix to store rotation values
* @return The given matrix with updated values
*/
public Matrix3f getRotation(Matrix3f rotStore){
if (rotStore==null) rotStore=new Matrix3f();
rotStore.copy(rot);
return rotStore;
}
/**
* Stores the translational part of this matrix into the passed matrix.
* Will create a new Vector3f if given vector is null. Returns the
* given vector after it has been loaded with translation values, to allow
* chaining
*
* @param tranStore The vector to store translation values
* @return The given Vector with updated values
*/
public Vector3f getTranslation(Vector3f tranStore){
if (tranStore==null) tranStore=new Vector3f();
tranStore.set(translation);
return tranStore;
}
/**
* Stores the rotational part of this matrix into the passed Quaternion.
* Will create a new Quaternion if given quaternion is null. Returns the
* given Quaternion after it has been loaded with rotation values, to allow
* chaining
*
* @param rotStore The Quat to store translation values
* @return The given Vector with updated values
*/
public Quaternion getRotation(Quaternion rotStore){
if (rotStore==null) rotStore=new Quaternion();
rotStore.fromRotationMatrix(rot);
return rotStore;
}
/**
* <code>toString</code> returns the string representation of this object.
* It is simply a toString() call of the rotational matrix and the translational vector
* @return the string representation of this object.
*/
public String toString() {
return "com.jme.math.TransformMatrix\n[\n"+
rot.toString() + ":" +
translation.toString() + ":" +
scale.toString();
}
/**
* <code>inverse</code> turns this matrix into it's own inverse
*/
public void inverse() {
invertRotInPlace();
rot.multLocal(translation);
translation.multLocal(-1);
scale.set(1/scale.x,1/scale.y,1/scale.z);
}
/**
* <code>setEulerRot</code> is equivalent to
* setEulerRot(eulerVec.x,eulverVec.y,eulverVec.z){
* @param eulerVec A Vector3f representing the new rotation in Euler angles
*/
public void setEulerRot(Vector3f eulerVec) {
this.setEulerRot(eulerVec.x,eulerVec.y,eulerVec.z);
}
/**
* <code>set</code> changes this matrix's rotational and translational components
* to that represented by the given parameters
* @param rotation The new rotaiton
* @param translation The new translation
*/
public void set(Quaternion rotation, Vector3f translation) {
this.set(rotation);
this.setTranslation(translation);
}
/**
* Sets this TransformMatrix's scale to the given scale (x,y,z)
* @param scale The new scale
*/
public void setScale(Vector3f scale) {
this.scale.set(scale);
}
/**
* Sets this TransformMatrix's scale to the given x,y,z
* @param x The x scale
* @param y The y scale
* @param z The z scale
*/
public void setScale(float x, float y, float z) {
scale.set(x,y,z);
}
/**
* Returns this TransformMatrix's scale factor
* @param storeS The place to store the current scale factor
* @return The given scale factor
*/
public Vector3f getScale(Vector3f storeS) {
if (storeS==null) storeS=new Vector3f();
return storeS.set(this.scale);
}
/**
* Applies this TransformMatrix to the given spatial, by updating the spatial's local translation, rotation, scale.
* @param spatial The spatial to update
*/
public void applyToSpatial(Spatial spatial) {
spatial.setLocalTranslation(translation);
spatial.setLocalRotation(rot);
spatial.setLocalScale(scale);
}
/**
* Combines this TransformMatrix with a parent TransformMatrix.
* @param parent The parent matrix.
* @return This matrix, after it has been updated by it's parent.
*/
public TransformMatrix combineWithParent(TransformMatrix parent){
this.scale.multLocal(parent.scale);
this.rot.multLocal(parent.rot);
parent.rot.multLocal(this.translation).multLocal(parent.scale).addLocal(parent.translation);
return this;
}
public void write(JMEExporter e) throws IOException {
OutputCapsule capsule = e.getCapsule(this);
capsule.write(rot, "rot", new Matrix3f());
capsule.write(translation, "translation", Vector3f.ZERO);
capsule.write(scale, "scale", Vector3f.UNIT_XYZ);
}
public void read(JMEImporter e) throws IOException {
InputCapsule capsule = e.getCapsule(this);
rot = (Matrix3f)capsule.readSavable("rot", new Matrix3f());
translation = (Vector3f)capsule.readSavable("translation", Vector3f.ZERO.clone());
scale = (Vector3f)capsule.readSavable("scale", Vector3f.UNIT_XYZ.clone());
}
public Class<? extends TransformMatrix> getClassTag() {
return this.getClass();
}
@Override
public TransformMatrix clone() {
try {
TransformMatrix tm = (TransformMatrix) super.clone();
tm.rot = rot.clone();
tm.scale = scale.clone();
tm.translation = translation.clone();
return tm;
} catch (CloneNotSupportedException e) {
throw new AssertionError();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -