Revision 227b03bd
Added by Leszek Koltunski over 8 years ago
| src/main/java/org/distorted/library/effect/MatrixEffect.java | ||
|---|---|---|
| 26 | 26 |
{
|
| 27 | 27 |
public static final int NUM_UNIFORMS = 7; // 4 per-effect interpolated values + 3 dimensional center. |
| 28 | 28 |
|
| 29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 30 |
|
|
| 31 |
public abstract void apply(float[] matrix, float[] uniforms, int index); |
|
| 32 |
|
|
| 29 | 33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 30 | 34 |
|
| 31 | 35 |
MatrixEffect(EffectName name) |
| src/main/java/org/distorted/library/effect/MatrixEffectMove.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.library.effect; |
| 21 | 21 |
|
| 22 |
import android.opengl.Matrix; |
|
| 23 |
|
|
| 22 | 24 |
import org.distorted.library.type.Data3D; |
| 23 | 25 |
|
| 24 | 26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 45 | 47 |
{
|
| 46 | 48 |
return mVector.get(uniforms,index,currentDuration,step); |
| 47 | 49 |
} |
| 50 |
|
|
| 51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 52 |
|
|
| 53 |
public void apply(float[] matrix, float[] uniforms, int index) |
|
| 54 |
{
|
|
| 55 |
float sx = uniforms[NUM_UNIFORMS*index ]; |
|
| 56 |
float sy = uniforms[NUM_UNIFORMS*index+1]; |
|
| 57 |
float sz = uniforms[NUM_UNIFORMS*index+2]; |
|
| 58 |
|
|
| 59 |
Matrix.translateM(matrix, 0, sx,-sy, sz); |
|
| 60 |
} |
|
| 48 | 61 |
} |
| src/main/java/org/distorted/library/effect/MatrixEffectQuaternion.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.library.effect; |
| 21 | 21 |
|
| 22 |
import android.opengl.Matrix; |
|
| 23 |
|
|
| 22 | 24 |
import org.distorted.library.type.Data3D; |
| 23 | 25 |
import org.distorted.library.type.Data4D; |
| 24 | 26 |
|
| ... | ... | |
| 29 | 31 |
private Data4D mQuaternion; |
| 30 | 32 |
private Data3D mCenter; |
| 31 | 33 |
|
| 34 |
private static float[] mTmpMatrix1 = new float[16]; |
|
| 35 |
private static float[] mTmpMatrix2 = new float[16]; |
|
| 36 |
|
|
| 32 | 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 33 | 38 |
/** |
| 34 | 39 |
* Rotates the Object by quaternion. |
| ... | ... | |
| 50 | 55 |
mCenter.get(uniforms,index+4,currentDuration,step); |
| 51 | 56 |
return mQuaternion.get(uniforms,index,currentDuration,step); |
| 52 | 57 |
} |
| 58 |
|
|
| 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 60 |
|
|
| 61 |
public void apply(float[] matrix, float[] uniforms, int index) |
|
| 62 |
{
|
|
| 63 |
float qX = uniforms[NUM_UNIFORMS*index ]; |
|
| 64 |
float qY = uniforms[NUM_UNIFORMS*index+1]; |
|
| 65 |
float qZ = uniforms[NUM_UNIFORMS*index+2]; |
|
| 66 |
float qW = uniforms[NUM_UNIFORMS*index+3]; |
|
| 67 |
|
|
| 68 |
float x = uniforms[NUM_UNIFORMS*index+4]; |
|
| 69 |
float y = uniforms[NUM_UNIFORMS*index+5]; |
|
| 70 |
float z = uniforms[NUM_UNIFORMS*index+6]; |
|
| 71 |
|
|
| 72 |
Matrix.translateM(matrix, 0, x,-y, z); |
|
| 73 |
multiplyByQuat( matrix, qX, qY, qZ, qW); |
|
| 74 |
Matrix.translateM(matrix, 0,-x, y,-z); |
|
| 75 |
} |
|
| 76 |
|
|
| 77 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 78 |
|
|
| 79 |
private static void multiplyByQuat(float[] matrix, float X, float Y, float Z, float W) |
|
| 80 |
{
|
|
| 81 |
float xx= X * X; |
|
| 82 |
float xy= X * Y; |
|
| 83 |
float xz= X * Z; |
|
| 84 |
float xw= X * W; |
|
| 85 |
float yy= Y * Y; |
|
| 86 |
float yz= Y * Z; |
|
| 87 |
float yw= Y * W; |
|
| 88 |
float zz= Z * Z; |
|
| 89 |
float zw= Z * W; |
|
| 90 |
|
|
| 91 |
mTmpMatrix1[0] = 1 - 2 * ( yy + zz ); |
|
| 92 |
mTmpMatrix1[1] = 2 * ( xy - zw ); |
|
| 93 |
mTmpMatrix1[2] = 2 * ( xz + yw ); |
|
| 94 |
mTmpMatrix1[4] = 2 * ( xy + zw ); |
|
| 95 |
mTmpMatrix1[5] = 1 - 2 * ( xx + zz ); |
|
| 96 |
mTmpMatrix1[6] = 2 * ( yz - xw ); |
|
| 97 |
mTmpMatrix1[8] = 2 * ( xz - yw ); |
|
| 98 |
mTmpMatrix1[9] = 2 * ( yz + xw ); |
|
| 99 |
mTmpMatrix1[10] = 1 - 2 * ( xx + yy ); |
|
| 100 |
mTmpMatrix1[3] = mTmpMatrix1[7] = mTmpMatrix1[11] = mTmpMatrix1[12] = mTmpMatrix1[13] = mTmpMatrix1[14] = 0; |
|
| 101 |
mTmpMatrix1[15] = 1; |
|
| 102 |
|
|
| 103 |
Matrix.multiplyMM(mTmpMatrix2, 0, matrix, 0, mTmpMatrix1, 0); |
|
| 104 |
|
|
| 105 |
matrix[ 0] = mTmpMatrix2[ 0]; |
|
| 106 |
matrix[ 1] = mTmpMatrix2[ 1]; |
|
| 107 |
matrix[ 2] = mTmpMatrix2[ 2]; |
|
| 108 |
matrix[ 3] = mTmpMatrix2[ 3]; |
|
| 109 |
matrix[ 4] = mTmpMatrix2[ 4]; |
|
| 110 |
matrix[ 5] = mTmpMatrix2[ 5]; |
|
| 111 |
matrix[ 6] = mTmpMatrix2[ 6]; |
|
| 112 |
matrix[ 7] = mTmpMatrix2[ 7]; |
|
| 113 |
matrix[ 8] = mTmpMatrix2[ 8]; |
|
| 114 |
matrix[ 9] = mTmpMatrix2[ 9]; |
|
| 115 |
matrix[10] = mTmpMatrix2[10]; |
|
| 116 |
matrix[11] = mTmpMatrix2[11]; |
|
| 117 |
matrix[12] = mTmpMatrix2[12]; |
|
| 118 |
matrix[13] = mTmpMatrix2[13]; |
|
| 119 |
matrix[14] = mTmpMatrix2[14]; |
|
| 120 |
matrix[15] = mTmpMatrix2[15]; |
|
| 121 |
} |
|
| 53 | 122 |
} |
| src/main/java/org/distorted/library/effect/MatrixEffectRotate.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.library.effect; |
| 21 | 21 |
|
| 22 |
import android.opengl.Matrix; |
|
| 23 |
|
|
| 22 | 24 |
import org.distorted.library.type.Data1D; |
| 23 | 25 |
import org.distorted.library.type.Data3D; |
| 24 | 26 |
|
| ... | ... | |
| 54 | 56 |
mAxis.get(uniforms,index+1,currentDuration,step); |
| 55 | 57 |
return mAngle.get(uniforms,index,currentDuration,step); |
| 56 | 58 |
} |
| 59 |
|
|
| 60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 61 |
|
|
| 62 |
public void apply(float[] matrix, float[] uniforms, int index) |
|
| 63 |
{
|
|
| 64 |
float alpha = uniforms[NUM_UNIFORMS*index ]; |
|
| 65 |
float axisX = uniforms[NUM_UNIFORMS*index+1]; |
|
| 66 |
float axisY = uniforms[NUM_UNIFORMS*index+2]; |
|
| 67 |
float axisZ = uniforms[NUM_UNIFORMS*index+3]; |
|
| 68 |
|
|
| 69 |
float x = uniforms[NUM_UNIFORMS*index+4]; |
|
| 70 |
float y = uniforms[NUM_UNIFORMS*index+5]; |
|
| 71 |
float z = uniforms[NUM_UNIFORMS*index+6]; |
|
| 72 |
|
|
| 73 |
Matrix.translateM(matrix, 0, x,-y, z); |
|
| 74 |
Matrix.rotateM( matrix, 0, alpha, axisX, axisY, axisZ); |
|
| 75 |
Matrix.translateM(matrix, 0,-x, y,-z); |
|
| 76 |
} |
|
| 57 | 77 |
} |
| src/main/java/org/distorted/library/effect/MatrixEffectScale.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.library.effect; |
| 21 | 21 |
|
| 22 |
import android.opengl.Matrix; |
|
| 23 |
|
|
| 22 | 24 |
import org.distorted.library.type.Data3D; |
| 23 | 25 |
import org.distorted.library.type.Static3D; |
| 24 | 26 |
|
| ... | ... | |
| 58 | 60 |
{
|
| 59 | 61 |
return mScale.get(uniforms,index,currentDuration,step); |
| 60 | 62 |
} |
| 63 |
|
|
| 64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 65 |
|
|
| 66 |
public void apply(float[] matrix, float[] uniforms, int index) |
|
| 67 |
{
|
|
| 68 |
float sx = uniforms[NUM_UNIFORMS*index ]; |
|
| 69 |
float sy = uniforms[NUM_UNIFORMS*index+1]; |
|
| 70 |
float sz = uniforms[NUM_UNIFORMS*index+2]; |
|
| 71 |
|
|
| 72 |
Matrix.scaleM(matrix, 0, sx, sy, sz); |
|
| 73 |
} |
|
| 61 | 74 |
} |
| src/main/java/org/distorted/library/effect/MatrixEffectShear.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.library.effect; |
| 21 | 21 |
|
| 22 |
import android.opengl.Matrix; |
|
| 23 |
|
|
| 22 | 24 |
import org.distorted.library.type.Data3D; |
| 23 | 25 |
|
| 24 | 26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 51 | 53 |
mCenter.get(uniforms,index+4,currentDuration,step); |
| 52 | 54 |
return mShear.get(uniforms,index,currentDuration,step); |
| 53 | 55 |
} |
| 56 |
|
|
| 57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 58 |
|
|
| 59 |
public void apply(float[] matrix, float[] uniforms, int index) |
|
| 60 |
{
|
|
| 61 |
float sx = uniforms[NUM_UNIFORMS*index ]; |
|
| 62 |
float sy = uniforms[NUM_UNIFORMS*index+1]; |
|
| 63 |
float sz = uniforms[NUM_UNIFORMS*index+2]; |
|
| 64 |
|
|
| 65 |
float x = uniforms[NUM_UNIFORMS*index+4]; |
|
| 66 |
float y = uniforms[NUM_UNIFORMS*index+5]; |
|
| 67 |
float z = uniforms[NUM_UNIFORMS*index+6]; |
|
| 68 |
|
|
| 69 |
Matrix.translateM(matrix, 0, x,-y, z); |
|
| 70 |
|
|
| 71 |
matrix[4] += sx*matrix[0]; // Multiply viewMatrix by 1 x 0 0 , i.e. X-shear. |
|
| 72 |
matrix[5] += sx*matrix[1]; // 0 1 0 0 |
|
| 73 |
matrix[6] += sx*matrix[2]; // 0 0 1 0 |
|
| 74 |
matrix[7] += sx*matrix[3]; // 0 0 0 1 |
|
| 75 |
|
|
| 76 |
matrix[0] += sy*matrix[4]; // Multiply viewMatrix by 1 0 0 0 , i.e. Y-shear. |
|
| 77 |
matrix[1] += sy*matrix[5]; // y 1 0 0 |
|
| 78 |
matrix[2] += sy*matrix[6]; // 0 0 1 0 |
|
| 79 |
matrix[3] += sy*matrix[7]; // 0 0 0 1 |
|
| 80 |
|
|
| 81 |
matrix[4] += sz*matrix[8]; // Multiply viewMatrix by 1 0 0 0 , i.e. Z-shear. |
|
| 82 |
matrix[5] += sz*matrix[9]; // 0 1 0 0 |
|
| 83 |
matrix[6] += sz*matrix[10];// 0 z 1 0 |
|
| 84 |
matrix[7] += sz*matrix[11];// 0 0 0 1 |
|
| 85 |
|
|
| 86 |
Matrix.translateM(matrix, 0,-x, y, -z); |
|
| 87 |
} |
|
| 54 | 88 |
} |
| src/main/java/org/distorted/library/main/EffectQueueMatrix.java | ||
|---|---|---|
| 34 | 34 |
private static final int INDEX = EffectType.MATRIX.ordinal(); |
| 35 | 35 |
|
| 36 | 36 |
private static float[] mMVPMatrix = new float[16]; |
| 37 |
private static float[] mTmpMatrix = new float[16]; |
|
| 38 | 37 |
private static float[] mViewMatrix= new float[16]; |
| 39 | 38 |
|
| 40 | 39 |
private static int mObjDH; // This is a handle to half a Object dimensions |
| ... | ... | |
| 48 | 47 |
super(id,NUM_UNIFORMS,INDEX ); |
| 49 | 48 |
} |
| 50 | 49 |
|
| 51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 52 |
|
|
| 53 |
private static void multiplyByQuat(float[] matrix, float X, float Y, float Z, float W) |
|
| 54 |
{
|
|
| 55 |
float xx= X * X; |
|
| 56 |
float xy= X * Y; |
|
| 57 |
float xz= X * Z; |
|
| 58 |
float xw= X * W; |
|
| 59 |
float yy= Y * Y; |
|
| 60 |
float yz= Y * Z; |
|
| 61 |
float yw= Y * W; |
|
| 62 |
float zz= Z * Z; |
|
| 63 |
float zw= Z * W; |
|
| 64 |
|
|
| 65 |
mTmpMatrix[0] = 1 - 2 * ( yy + zz ); |
|
| 66 |
mTmpMatrix[1] = 2 * ( xy - zw ); |
|
| 67 |
mTmpMatrix[2] = 2 * ( xz + yw ); |
|
| 68 |
mTmpMatrix[4] = 2 * ( xy + zw ); |
|
| 69 |
mTmpMatrix[5] = 1 - 2 * ( xx + zz ); |
|
| 70 |
mTmpMatrix[6] = 2 * ( yz - xw ); |
|
| 71 |
mTmpMatrix[8] = 2 * ( xz - yw ); |
|
| 72 |
mTmpMatrix[9] = 2 * ( yz + xw ); |
|
| 73 |
mTmpMatrix[10] = 1 - 2 * ( xx + yy ); |
|
| 74 |
mTmpMatrix[3] = mTmpMatrix[7] = mTmpMatrix[11] = mTmpMatrix[12] = mTmpMatrix[13] = mTmpMatrix[14] = 0; |
|
| 75 |
mTmpMatrix[15] = 1; |
|
| 76 |
|
|
| 77 |
Matrix.multiplyMM(mMVPMatrix, 0, matrix, 0, mTmpMatrix, 0); |
|
| 78 |
|
|
| 79 |
matrix[ 0] = mMVPMatrix[ 0]; |
|
| 80 |
matrix[ 1] = mMVPMatrix[ 1]; |
|
| 81 |
matrix[ 2] = mMVPMatrix[ 2]; |
|
| 82 |
matrix[ 3] = mMVPMatrix[ 3]; |
|
| 83 |
matrix[ 4] = mMVPMatrix[ 4]; |
|
| 84 |
matrix[ 5] = mMVPMatrix[ 5]; |
|
| 85 |
matrix[ 6] = mMVPMatrix[ 6]; |
|
| 86 |
matrix[ 7] = mMVPMatrix[ 7]; |
|
| 87 |
matrix[ 8] = mMVPMatrix[ 8]; |
|
| 88 |
matrix[ 9] = mMVPMatrix[ 9]; |
|
| 89 |
matrix[10] = mMVPMatrix[10]; |
|
| 90 |
matrix[11] = mMVPMatrix[11]; |
|
| 91 |
matrix[12] = mMVPMatrix[12]; |
|
| 92 |
matrix[13] = mMVPMatrix[13]; |
|
| 93 |
matrix[14] = mMVPMatrix[14]; |
|
| 94 |
matrix[15] = mMVPMatrix[15]; |
|
| 95 |
} |
|
| 96 |
|
|
| 97 | 50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 98 | 51 |
|
| 99 | 52 |
private void magnify(DistortedOutputSurface projection, float halfX, float halfY, float halfZ, float marginInPixels) |
| ... | ... | |
| 200 | 153 |
{
|
| 201 | 154 |
Matrix.setIdentityM(mViewMatrix, 0); |
| 202 | 155 |
Matrix.translateM(mViewMatrix, 0, -projection.mWidth/2, projection.mHeight/2, -projection.mDistance); |
| 203 |
|
|
| 204 |
float x,y,z, sx,sy,sz; |
|
| 205 | 156 |
float mipmap = projection.mMipmap; |
| 206 |
|
|
| 207 | 157 |
if( mipmap!=1 ) Matrix.scaleM(mViewMatrix, 0, mipmap, mipmap, mipmap); |
| 208 | 158 |
|
| 209 |
for(int i=0; i<mNumEffects; i++) |
|
| 210 |
{
|
|
| 211 |
switch( mEffects[i].getName() ) |
|
| 212 |
{
|
|
| 213 |
case ROTATE : x = mUniforms[NUM_UNIFORMS*i+4]; |
|
| 214 |
y = mUniforms[NUM_UNIFORMS*i+5]; |
|
| 215 |
z = mUniforms[NUM_UNIFORMS*i+6]; |
|
| 216 |
|
|
| 217 |
Matrix.translateM(mViewMatrix, 0, x,-y, z); |
|
| 218 |
Matrix.rotateM( mViewMatrix, 0, mUniforms[NUM_UNIFORMS*i], mUniforms[NUM_UNIFORMS*i+1], mUniforms[NUM_UNIFORMS*i+2], mUniforms[NUM_UNIFORMS*i+3]); |
|
| 219 |
Matrix.translateM(mViewMatrix, 0,-x, y,-z); |
|
| 220 |
break; |
|
| 221 |
case QUATERNION : x = mUniforms[NUM_UNIFORMS*i+4]; |
|
| 222 |
y = mUniforms[NUM_UNIFORMS*i+5]; |
|
| 223 |
z = mUniforms[NUM_UNIFORMS*i+6]; |
|
| 224 |
|
|
| 225 |
Matrix.translateM(mViewMatrix, 0, x,-y, z); |
|
| 226 |
multiplyByQuat(mViewMatrix, mUniforms[NUM_UNIFORMS*i], mUniforms[NUM_UNIFORMS*i+1], mUniforms[NUM_UNIFORMS*i+2], mUniforms[NUM_UNIFORMS*i+3]); |
|
| 227 |
Matrix.translateM(mViewMatrix, 0,-x, y,-z); |
|
| 228 |
break; |
|
| 229 |
case MOVE : sx = mUniforms[NUM_UNIFORMS*i ]; |
|
| 230 |
sy = mUniforms[NUM_UNIFORMS*i+1]; |
|
| 231 |
sz = mUniforms[NUM_UNIFORMS*i+2]; |
|
| 232 |
|
|
| 233 |
Matrix.translateM(mViewMatrix, 0, sx,-sy, sz); |
|
| 234 |
break; |
|
| 235 |
case SCALE : sx = mUniforms[NUM_UNIFORMS*i ]; |
|
| 236 |
sy = mUniforms[NUM_UNIFORMS*i+1]; |
|
| 237 |
sz = mUniforms[NUM_UNIFORMS*i+2]; |
|
| 238 |
|
|
| 239 |
Matrix.scaleM(mViewMatrix, 0, sx, sy, sz); |
|
| 240 |
break; |
|
| 241 |
case SHEAR : sx = mUniforms[NUM_UNIFORMS*i ]; |
|
| 242 |
sy = mUniforms[NUM_UNIFORMS*i+1]; |
|
| 243 |
sz = mUniforms[NUM_UNIFORMS*i+2]; |
|
| 244 |
|
|
| 245 |
x = mUniforms[NUM_UNIFORMS*i+4]; |
|
| 246 |
y = mUniforms[NUM_UNIFORMS*i+5]; |
|
| 247 |
z = mUniforms[NUM_UNIFORMS*i+6]; |
|
| 248 |
|
|
| 249 |
Matrix.translateM(mViewMatrix, 0, x,-y, z); |
|
| 250 |
|
|
| 251 |
mViewMatrix[4] += sx*mViewMatrix[0]; // Multiply viewMatrix by 1 x 0 0 , i.e. X-shear. |
|
| 252 |
mViewMatrix[5] += sx*mViewMatrix[1]; // 0 1 0 0 |
|
| 253 |
mViewMatrix[6] += sx*mViewMatrix[2]; // 0 0 1 0 |
|
| 254 |
mViewMatrix[7] += sx*mViewMatrix[3]; // 0 0 0 1 |
|
| 255 |
|
|
| 256 |
mViewMatrix[0] += sy*mViewMatrix[4]; // Multiply viewMatrix by 1 0 0 0 , i.e. Y-shear. |
|
| 257 |
mViewMatrix[1] += sy*mViewMatrix[5]; // y 1 0 0 |
|
| 258 |
mViewMatrix[2] += sy*mViewMatrix[6]; // 0 0 1 0 |
|
| 259 |
mViewMatrix[3] += sy*mViewMatrix[7]; // 0 0 0 1 |
|
| 260 |
|
|
| 261 |
mViewMatrix[4] += sz*mViewMatrix[8]; // Multiply viewMatrix by 1 0 0 0 , i.e. Z-shear. |
|
| 262 |
mViewMatrix[5] += sz*mViewMatrix[9]; // 0 1 0 0 |
|
| 263 |
mViewMatrix[6] += sz*mViewMatrix[10];// 0 z 1 0 |
|
| 264 |
mViewMatrix[7] += sz*mViewMatrix[11];// 0 0 0 1 |
|
| 265 |
|
|
| 266 |
Matrix.translateM(mViewMatrix, 0,-x, y, -z); |
|
| 267 |
break; |
|
| 268 |
} |
|
| 269 |
} |
|
| 159 |
for(int i=0; i<mNumEffects; i++) ((MatrixEffect)mEffects[i]).apply(mViewMatrix,mUniforms,i); |
|
| 270 | 160 |
|
| 271 | 161 |
Matrix.translateM(mViewMatrix, 0, halfX,-halfY,-halfZ); |
| 272 |
|
|
| 273 | 162 |
if( marginInPixels!=0 ) magnify(projection,halfX,halfY,halfZ, marginInPixels); |
| 274 |
|
|
| 275 | 163 |
Matrix.multiplyMM(mMVPMatrix, 0, projection.mProjectionMatrix, 0, mViewMatrix, 0); |
| 276 | 164 |
} |
| 277 | 165 |
|
Also available in: Unified diff
Move all knowledge about a MatrixEffect from the EffectQueueMatrix to the classes.