Revision c0255951
Added by Leszek Koltunski over 2 years ago
| src/main/java/org/distorted/library/effect/MatrixEffectRotate.java | ||
|---|---|---|
| 32 | 32 |
{
|
| 33 | 33 |
private final Data1D mAngle; |
| 34 | 34 |
private final Data3D mAxis, mCenter; |
| 35 |
private float[] mTmp1 = new float[16]; |
|
| 36 |
private float[] mTmp2 = new float[16]; |
|
| 35 | 37 |
|
| 36 | 38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 37 | 39 |
/** |
| ... | ... | |
| 63 | 65 |
float y = uniforms[NUM_FLOAT_UNIFORMS*index+CENTER_OFFSET+1]; |
| 64 | 66 |
float z = uniforms[NUM_FLOAT_UNIFORMS*index+CENTER_OFFSET+2]; |
| 65 | 67 |
|
| 68 |
double inRadians = Math.PI*angle/180; |
|
| 69 |
float sin = (float)Math.sin(inRadians); |
|
| 70 |
float cos = (float)Math.cos(inRadians); |
|
| 71 |
|
|
| 66 | 72 |
MatrixHelper.translate(matrixP, x, y, z); |
| 67 |
MatrixHelper.rotate(matrixP, angle, axisX, axisY, axisZ);
|
|
| 73 |
MatrixHelper.rotateSinCos(matrixP, mTmp1, mTmp2, sin,cos, axisX, axisY, axisZ);
|
|
| 68 | 74 |
MatrixHelper.translate(matrixP,-x,-y,-z); |
| 69 | 75 |
|
| 70 | 76 |
MatrixHelper.translate(matrixV, x, y, z); |
| 71 |
MatrixHelper.rotate(matrixV, angle, axisX, axisY, axisZ);
|
|
| 77 |
MatrixHelper.rotateSinCos(matrixV, mTmp1, mTmp2, sin,cos, axisX, axisY, axisZ);
|
|
| 72 | 78 |
MatrixHelper.translate(matrixV,-x,-y,-z); |
| 73 | 79 |
} |
| 74 | 80 |
|
| src/main/java/org/distorted/library/helpers/MatrixHelper.java | ||
|---|---|---|
| 123 | 123 |
} |
| 124 | 124 |
|
| 125 | 125 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 126 |
// this is android.opengl.Matrix.rotateM(), but with pre-computed sin and cos of the angle |
|
| 127 |
// and also we have to pre-allocate and pass here two temp arrays. |
|
| 126 | 128 |
|
| 127 |
public static void rotate(float[] output, float angle, float axisX, float axisY, float axisZ)
|
|
| 129 |
public static void rotateSinCos(float[] output, float[] tmp1, float[] tmp2, float sin, float cos, float x, float y, float z)
|
|
| 128 | 130 |
{
|
| 129 |
android.opengl.Matrix.rotateM(output,0,angle,axisX,axisY,axisZ); |
|
| 131 |
tmp1[0] = (1-cos)*x*x + cos; |
|
| 132 |
tmp1[1] = (1-cos)*x*y + sin*z; |
|
| 133 |
tmp1[2] = (1-cos)*x*z - sin*y; |
|
| 134 |
tmp1[3] = 0; |
|
| 135 |
tmp1[4] = (1-cos)*x*y - sin*z; |
|
| 136 |
tmp1[5] = (1-cos)*y*y + cos; |
|
| 137 |
tmp1[6] = (1-cos)*y*z + sin*x; |
|
| 138 |
tmp1[7] = 0; |
|
| 139 |
tmp1[8] = (1-cos)*x*z + sin*y; |
|
| 140 |
tmp1[9] = (1-cos)*y*z - sin*x; |
|
| 141 |
tmp1[10] = (1-cos)*z*z + cos; |
|
| 142 |
tmp1[11] = 0; |
|
| 143 |
tmp1[12] = 0; |
|
| 144 |
tmp1[13] = 0; |
|
| 145 |
tmp1[14] = 0; |
|
| 146 |
tmp1[15] = 1; |
|
| 147 |
|
|
| 148 |
tmp2[0] = output[ 0]; |
|
| 149 |
tmp2[1] = output[ 1]; |
|
| 150 |
tmp2[2] = output[ 2]; |
|
| 151 |
tmp2[3] = output[ 3]; |
|
| 152 |
tmp2[4] = output[ 4]; |
|
| 153 |
tmp2[5] = output[ 5]; |
|
| 154 |
tmp2[6] = output[ 6]; |
|
| 155 |
tmp2[7] = output[ 7]; |
|
| 156 |
tmp2[8] = output[ 8]; |
|
| 157 |
tmp2[9] = output[ 9]; |
|
| 158 |
tmp2[10] = output[10]; |
|
| 159 |
tmp2[11] = output[11]; |
|
| 160 |
tmp2[12] = output[12]; |
|
| 161 |
tmp2[13] = output[13]; |
|
| 162 |
tmp2[14] = output[14]; |
|
| 163 |
tmp2[15] = output[15]; |
|
| 164 |
|
|
| 165 |
multiply(output,tmp2,tmp1); |
|
| 130 | 166 |
} |
| 131 | 167 |
|
| 132 | 168 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Completely kick out the android.opengl.Matrix dependency from the library.