Revision 62c869ad
Added by Leszek Koltunski over 3 years ago
src/main/java/org/distorted/library/effectqueue/EffectQueueMatrix.java | ||
---|---|---|
24 | 24 |
|
25 | 25 |
import org.distorted.library.effect.EffectType; |
26 | 26 |
import org.distorted.library.effect.MatrixEffect; |
27 |
import org.distorted.library.mesh.MeshBase; |
|
28 | 27 |
import org.distorted.library.message.EffectMessageSender; |
29 | 28 |
|
30 | 29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
35 | 34 |
private static final int INDEX = EffectType.MATRIX.ordinal(); |
36 | 35 |
|
37 | 36 |
private static float[] mMVPMatrix = new float[16]; |
38 |
private static float[] mModelViewMatrix = new float[16]; |
|
37 |
private static float[] mModelViewMatrixP= new float[16]; |
|
38 |
private static float[] mModelViewMatrixV= new float[16]; |
|
39 | 39 |
|
40 | 40 |
private static int[] mMVPMatrixH = new int[MAIN_VARIANTS]; |
41 |
private static int[] mMVMatrixH = new int[MAIN_VARIANTS]; |
|
41 |
private static int[] mMVMatrixPH = new int[MAIN_VARIANTS]; |
|
42 |
private static int[] mMVMatrixVH = new int[MAIN_VARIANTS]; |
|
42 | 43 |
|
43 | 44 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
44 | 45 |
|
... | ... | |
59 | 60 |
static void uniforms(int mProgramH, int variant) |
60 | 61 |
{ |
61 | 62 |
mMVPMatrixH[variant]= GLES30.glGetUniformLocation(mProgramH, "u_MVPMatrix"); |
62 |
mMVMatrixH[variant] = GLES30.glGetUniformLocation(mProgramH, "u_MVMatrix"); |
|
63 |
mMVMatrixPH[variant]= GLES30.glGetUniformLocation(mProgramH, "u_MVMatrixP"); |
|
64 |
mMVMatrixVH[variant]= GLES30.glGetUniformLocation(mProgramH, "u_MVMatrixV"); |
|
63 | 65 |
} |
64 | 66 |
|
65 | 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
83 | 85 |
|
84 | 86 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
85 | 87 |
|
86 |
float[] getMVP()
|
|
88 |
void send(float distance, float mipmap, float[] projection, int variant)
|
|
87 | 89 |
{ |
88 |
return mMVPMatrix; |
|
89 |
} |
|
90 |
|
|
91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
90 |
Matrix.setIdentityM(mModelViewMatrixP, 0); |
|
91 |
Matrix.translateM(mModelViewMatrixP, 0, 0,0, -distance); |
|
92 | 92 |
|
93 |
void send(float distance, float mipmap, float[] projection, MeshBase mesh, int variant) |
|
94 |
{ |
|
95 |
Matrix.setIdentityM(mModelViewMatrix, 0); |
|
93 |
if( mipmap!=1 ) |
|
94 |
{ |
|
95 |
Matrix.scaleM(mModelViewMatrixP, 0, mipmap, mipmap, mipmap); |
|
96 |
} |
|
96 | 97 |
|
97 |
// The 'View' part of the MV matrix |
|
98 |
Matrix.translateM(mModelViewMatrix, 0, 0,0, -distance); |
|
99 |
if( mipmap!=1 ) Matrix.scaleM(mModelViewMatrix, 0, mipmap, mipmap, mipmap); |
|
98 |
mModelViewMatrixV[ 0] = mModelViewMatrixP[ 0]; |
|
99 |
mModelViewMatrixV[ 1] = mModelViewMatrixP[ 1]; |
|
100 |
mModelViewMatrixV[ 2] = mModelViewMatrixP[ 2]; |
|
101 |
mModelViewMatrixV[ 3] = mModelViewMatrixP[ 3]; |
|
102 |
mModelViewMatrixV[ 4] = mModelViewMatrixP[ 4]; |
|
103 |
mModelViewMatrixV[ 5] = mModelViewMatrixP[ 5]; |
|
104 |
mModelViewMatrixV[ 6] = mModelViewMatrixP[ 6]; |
|
105 |
mModelViewMatrixV[ 7] = mModelViewMatrixP[ 7]; |
|
106 |
mModelViewMatrixV[ 8] = mModelViewMatrixP[ 8]; |
|
107 |
mModelViewMatrixV[ 9] = mModelViewMatrixP[ 9]; |
|
108 |
mModelViewMatrixV[10] = mModelViewMatrixP[10]; |
|
109 |
mModelViewMatrixV[11] = mModelViewMatrixP[11]; |
|
110 |
mModelViewMatrixV[12] = mModelViewMatrixP[12]; |
|
111 |
mModelViewMatrixV[13] = mModelViewMatrixP[13]; |
|
112 |
mModelViewMatrixV[14] = mModelViewMatrixP[14]; |
|
113 |
mModelViewMatrixV[15] = mModelViewMatrixP[15]; |
|
100 | 114 |
|
101 | 115 |
// the 'Model' part of the MV matrix |
102 |
for(int i=mNumEffects-1; i>=0; i--) ((MatrixEffect)mEffects[i]).apply(mModelViewMatrix,mUniforms,i); |
|
116 |
for(int i=mNumEffects-1; i>=0; i--) |
|
117 |
{ |
|
118 |
((MatrixEffect)mEffects[i]).apply(mModelViewMatrixP,mModelViewMatrixV,mUniforms,i); |
|
119 |
} |
|
103 | 120 |
|
104 | 121 |
// combined Model-View-Projection matrix |
105 |
Matrix.multiplyMM(mMVPMatrix, 0, projection, 0, mModelViewMatrix, 0); |
|
122 |
Matrix.multiplyMM(mMVPMatrix, 0, projection, 0, mModelViewMatrixP, 0);
|
|
106 | 123 |
|
107 |
GLES30.glUniformMatrix4fv(mMVMatrixH[variant] , 1, false, mModelViewMatrix, 0); |
|
108 |
GLES30.glUniformMatrix4fv(mMVPMatrixH[variant], 1, false, mMVPMatrix , 0); |
|
124 |
GLES30.glUniformMatrix4fv(mMVMatrixVH[variant], 1, false, mModelViewMatrixV, 0); |
|
125 |
GLES30.glUniformMatrix4fv(mMVMatrixPH[variant], 1, false, mModelViewMatrixP, 0); |
|
126 |
GLES30.glUniformMatrix4fv(mMVPMatrixH[variant], 1, false, mMVPMatrix , 0); |
|
109 | 127 |
} |
110 | 128 |
} |
Also available in: Unified diff
Fix normals in case of MatrixEffectScale / Shear.
Fix displaying the normal vector.