Revision c90aca24
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/library/effect/MatrixEffect.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.library.effect; |
21 | 21 |
|
22 |
import android.opengl.Matrix; |
|
23 |
|
|
24 | 22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
25 | 23 |
/** |
26 | 24 |
* Abstract class that represents an Effect that works by modifying the ModelView matrix. |
... | ... | |
32 | 30 |
*/ |
33 | 31 |
public static final int NUM_UNIFORMS = 7; |
34 | 32 |
|
35 |
private float[] mMatrix,mTmpArray; |
|
36 |
|
|
37 | 33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
38 | 34 |
/** |
39 | 35 |
* Only for use by the library itself. |
... | ... | |
42 | 38 |
*/ |
43 | 39 |
public abstract void apply(float[] matrix, float[] uniforms, int index); |
44 | 40 |
|
45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
46 |
/** |
|
47 |
* Only for use by the library itself. |
|
48 |
* <p> |
|
49 |
* The three values buffer[index], buffer[index+1], buffer[index+2] are assumed to contain the |
|
50 |
* x,y,z coordinates of a point. We apply this Matrix effect to this point and overwrite those |
|
51 |
* three values. |
|
52 |
* |
|
53 |
* This is on purpose a static evaluation - if this Effect contains any Dynamics, they will be |
|
54 |
* evaluated at 0. |
|
55 |
* |
|
56 |
* @y.exclude |
|
57 |
*/ |
|
58 |
public void applyToPoint(float[] buffer, int index) |
|
59 |
{ |
|
60 |
Matrix.setIdentityM(mMatrix,0); |
|
61 |
compute(mTmpArray,0,0,0); |
|
62 |
apply(mMatrix, mTmpArray, 0); |
|
63 |
|
|
64 |
float x = buffer[index ]; |
|
65 |
float y = buffer[index+1]; |
|
66 |
float z = buffer[index+2]; |
|
67 |
|
|
68 |
buffer[index ] = mMatrix[0]*x + mMatrix[4]*y + mMatrix[ 8]*z + mMatrix[12]; |
|
69 |
buffer[index+1] = mMatrix[1]*x + mMatrix[5]*y + mMatrix[ 9]*z + mMatrix[13]; |
|
70 |
buffer[index+2] = mMatrix[2]*x + mMatrix[6]*y + mMatrix[10]*z + mMatrix[14]; |
|
71 |
} |
|
72 |
|
|
73 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
74 |
/** |
|
75 |
* Only for use by the library itself. |
|
76 |
* <p> |
|
77 |
* The three values buffer[index], buffer[index+1], buffer[index+2] are assumed to contain the |
|
78 |
* x,y,z coordinates of a vector. We apply this Matrix effect to this vector and overwrite those |
|
79 |
* three values. |
|
80 |
* |
|
81 |
* This is on purpose a static evaluation - if this Effect contains any Dynamics, they will be |
|
82 |
* evaluated at 0. |
|
83 |
* |
|
84 |
* @y.exclude |
|
85 |
*/ |
|
86 |
public void applyToVector(float[] buffer, int index) |
|
87 |
{ |
|
88 |
Matrix.setIdentityM(mMatrix,0); |
|
89 |
compute(mTmpArray,0,0,0); |
|
90 |
apply(mMatrix, mTmpArray, 0); |
|
91 |
|
|
92 |
float x = buffer[index ]; |
|
93 |
float y = buffer[index+1]; |
|
94 |
float z = buffer[index+2]; |
|
95 |
|
|
96 |
buffer[index ] = mMatrix[0]*x + mMatrix[4]*y + mMatrix[ 8]*z; |
|
97 |
buffer[index+1] = mMatrix[1]*x + mMatrix[5]*y + mMatrix[ 9]*z; |
|
98 |
buffer[index+2] = mMatrix[2]*x + mMatrix[6]*y + mMatrix[10]*z; |
|
99 |
} |
|
100 |
|
|
101 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
102 |
/** |
|
103 |
* Only for use by the library itself. |
|
104 |
* <p> |
|
105 |
* The 9 floats starting at buffer[index] are assumed to contain info about a vertex arranged in |
|
106 |
* MeshBase way, i.e. coord point (x,y,z) ; normal vector (x,y,z) ; inflate vector (x,y,z) |
|
107 |
* |
|
108 |
* @y.exclude |
|
109 |
*/ |
|
110 |
public void applyToVertex(float[] buffer, int index) |
|
111 |
{ |
|
112 |
float x,y,z; |
|
113 |
|
|
114 |
Matrix.setIdentityM(mMatrix,0); |
|
115 |
compute(mTmpArray,0,0,0); |
|
116 |
apply(mMatrix, mTmpArray, 0); |
|
117 |
|
|
118 |
x = buffer[index ]; |
|
119 |
y = buffer[index+1]; |
|
120 |
z = buffer[index+2]; |
|
121 |
|
|
122 |
buffer[index ] = mMatrix[0]*x + mMatrix[4]*y + mMatrix[ 8]*z + mMatrix[12]; |
|
123 |
buffer[index+1] = mMatrix[1]*x + mMatrix[5]*y + mMatrix[ 9]*z + mMatrix[13]; |
|
124 |
buffer[index+2] = mMatrix[2]*x + mMatrix[6]*y + mMatrix[10]*z + mMatrix[14]; |
|
125 |
|
|
126 |
x = buffer[index+3]; |
|
127 |
y = buffer[index+4]; |
|
128 |
z = buffer[index+5]; |
|
129 |
|
|
130 |
buffer[index+3] = mMatrix[0]*x + mMatrix[4]*y + mMatrix[ 8]*z; |
|
131 |
buffer[index+4] = mMatrix[1]*x + mMatrix[5]*y + mMatrix[ 9]*z; |
|
132 |
buffer[index+5] = mMatrix[2]*x + mMatrix[6]*y + mMatrix[10]*z; |
|
133 |
|
|
134 |
x = buffer[index+6]; |
|
135 |
y = buffer[index+7]; |
|
136 |
z = buffer[index+8]; |
|
137 |
|
|
138 |
buffer[index+6] = mMatrix[0]*x + mMatrix[4]*y + mMatrix[ 8]*z; |
|
139 |
buffer[index+7] = mMatrix[1]*x + mMatrix[5]*y + mMatrix[ 9]*z; |
|
140 |
buffer[index+8] = mMatrix[2]*x + mMatrix[6]*y + mMatrix[10]*z; |
|
141 |
} |
|
142 |
|
|
143 | 41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
144 | 42 |
// empty function for completeness |
145 | 43 |
|
... | ... | |
153 | 51 |
MatrixEffect(EffectName name) |
154 | 52 |
{ |
155 | 53 |
super(name); |
156 |
|
|
157 |
mMatrix = new float[16]; |
|
158 |
mTmpArray= new float[4]; |
|
159 | 54 |
} |
160 | 55 |
} |
Also available in: Unified diff
Move the 'pre-multiply mesh before applying any effects' thing from [(Xsize of texture, Ysize of texture) x Mesh's zFactor] to Effects.setStretch(sx,sy,sz)