/** Postmultiplies this matrix with a scale matrix. Postmultiplication is also used by OpenGL ES' 1.x * glTranslate/glRotate/glScale. * @param scale The vector to scale the matrix by. * @return This matrix for the purpose of chaining. */ public Matrix3 scale (Vector2 scale) { float[] tmp = this.tmp; tmp[M00] = scale.x; tmp[M10] = 0; tmp[M20] = 0; tmp[M01] = 0; tmp[M11] = scale.y; tmp[M21] = 0; tmp[M02] = 0; tmp[M12] = 0; tmp[M22] = 1; mul(val, tmp); return this; }
Matrix3 mat1 = new Matrix3(); Matrix3 mat2 = new Matrix3(); Affine2 afn1 = new Affine2(); Affine2 afn2 = new Affine2(); checkEqual(mat1, mat2.idt()); checkEqual(mat1, afn1); checkEqual(mat1, afn1.idt()); mat1.setToTranslation(trn); checkEqual(mat1, new float[] {1, 0, 0, 0, 1, 0, trn.x, trn.y, 1}); afn1.setToTranslation(trn); mat1.setToScaling(scl); checkEqual(mat1, new float[] {scl.x, 0, 0, 0, scl.y, 0, 0, 0, 1}); afn1.setToScaling(scl); mat1.setToRotation(rot); checkEqual(mat1, new float[] {cos, sin, 0, -sin, cos, 0, 0, 0, 1}); afn1.setToRotation(rot); checkEqual(mat1, afn1); mat1.setToRotationRad(MathUtils.degreesToRadians * rot); checkEqual(mat1, afn1); afn1.setToRotationRad(MathUtils.degreesToRadians * rot); checkEqual(mat1.set(afn1), new float[] {1, shear.y, 0, shear.x, 1, 0, 0, 0, 1}); mat1.idt().scale(scl).rotate(rot).translate(trn).mul(mat2.set(afn2.setToShearing(shear))); afn1.idt().scale(scl).rotate(rot).translate(trn).shear(shear);
void updateBody() { if (body == null || staticLight) return; final Vector2 vec = body.getPosition(); tmpVec.set(0, 0).sub(bodyPosition); bodyPosition.set(vec); zeroPosition.setToTranslation(tmpVec); restorePosition.setToTranslation(bodyPosition); rotateAroundZero.setToRotationRad(bodyAngle).inv().rotateRad(body.getAngle()); bodyAngle = body.getAngle(); for (int i = 0; i < rayNum; i++) { tmpVec.set(startX[i], startY[i]).mul(zeroPosition).mul(rotateAroundZero) .mul(restorePosition); startX[i] = tmpVec.x; startY[i] = tmpVec.y; tmpVec.set(endX[i], endY[i]).mul(zeroPosition).mul(rotateAroundZero) .mul(restorePosition); endX[i] = tmpVec.x; endY[i] = tmpVec.y; } }
/** Constructs a matrix from the given float array. The array must have at least 9 elements; the first 9 will be copied. * @param values The float array to copy. Remember that this matrix is in <a * href="http://en.wikipedia.org/wiki/Row-major_order#Column-major_order">column major</a> order. (The float array is * not modified.) */ public Matrix3 (float[] values) { this.set(values); }
public Matrix3 setToRotation (Vector3 axis, float degrees) { return setToRotation(axis, MathUtils.cosDeg(degrees), MathUtils.sinDeg(degrees)); }
/** Postmultiplies this matrix with a (counter-clockwise) rotation matrix. Postmultiplication is also used by OpenGL ES' 1.x * glTranslate/glRotate/glScale. * @param degrees The angle in degrees * @return This matrix for the purpose of chaining. */ public Matrix3 rotate (float degrees) { return rotateRad(MathUtils.degreesToRadians * degrees); }
public Matrix3 () { idt(); }
/** Sets this matrix to a rotation matrix that will rotate any vector in counter-clockwise direction around the z-axis. * @param degrees the angle in degrees. * @return This matrix for the purpose of chaining operations. */ public Matrix3 setToRotation (float degrees) { return setToRotationRad(MathUtils.degreesToRadians * degrees); }
/** * Applies attached body initial transform to all lights rays */ void applyAttachment() { if (body == null || staticLight) return; restorePosition.setToTranslation(bodyPosition); rotateAroundZero.setToRotationRad(bodyAngle + bodyAngleOffset); for (int i = 0; i < rayNum; i++) { tmpVec.set(startX[i], startY[i]).mul(rotateAroundZero).mul(restorePosition); startX[i] = tmpVec.x; startY[i] = tmpVec.y; tmpVec.set(endX[i], endY[i]).mul(rotateAroundZero).mul(restorePosition); endX[i] = tmpVec.x; endY[i] = tmpVec.y; } }
/** Inverts this matrix given that the determinant is != 0. * @return This matrix for the purpose of chaining operations. * @throws GdxRuntimeException if the matrix is singular (not invertible) */ public Matrix3 inv () { float det = det(); if (det == 0) throw new GdxRuntimeException("Can't invert a singular matrix"); float inv_det = 1.0f / det; float[] tmp = this.tmp, val = this.val; tmp[M00] = val[M11] * val[M22] - val[M21] * val[M12]; tmp[M10] = val[M20] * val[M12] - val[M10] * val[M22]; tmp[M20] = val[M10] * val[M21] - val[M20] * val[M11]; tmp[M01] = val[M21] * val[M02] - val[M01] * val[M22]; tmp[M11] = val[M00] * val[M22] - val[M20] * val[M02]; tmp[M21] = val[M20] * val[M01] - val[M00] * val[M21]; tmp[M02] = val[M01] * val[M12] - val[M11] * val[M02]; tmp[M12] = val[M10] * val[M02] - val[M00] * val[M12]; tmp[M22] = val[M00] * val[M11] - val[M10] * val[M01]; val[M00] = inv_det * tmp[M00]; val[M10] = inv_det * tmp[M10]; val[M20] = inv_det * tmp[M20]; val[M01] = inv_det * tmp[M01]; val[M11] = inv_det * tmp[M11]; val[M21] = inv_det * tmp[M21]; val[M02] = inv_det * tmp[M02]; val[M12] = inv_det * tmp[M12]; val[M22] = inv_det * tmp[M22]; return this; }
public Matrix3Attribute(long type) { super(type); this.value = new Matrix3(); }
void updateBody() { if (body == null || staticLight) return; final Vector2 vec = body.getPosition(); tmpVec.set(0, 0).sub(bodyPosition); bodyPosition.set(vec); zeroPosition.setToTranslation(tmpVec); restorePosition.setToTranslation(bodyPosition); rotateAroundZero.setToRotationRad(bodyAngle).inv().rotateRad(body.getAngle()); bodyAngle = body.getAngle(); for (int i = 0; i < rayNum; i++) { tmpVec.set(startX[i], startY[i]).mul(zeroPosition).mul(rotateAroundZero) .mul(restorePosition); startX[i] = tmpVec.x; startY[i] = tmpVec.y; tmpVec.set(endX[i], endY[i]).mul(zeroPosition).mul(rotateAroundZero) .mul(restorePosition); endX[i] = tmpVec.x; endY[i] = tmpVec.y; } }
/** Constructs a matrix from the given float array. The array must have at least 9 elements; the first 9 will be copied. * @param values The float array to copy. Remember that this matrix is in <a * href="http://en.wikipedia.org/wiki/Row-major_order#Column-major_order">column major</a> order. (The float array is * not modified.) */ public Matrix3 (float[] values) { this.set(values); }