Revision fa8bc998
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 |
|
|
22 | 24 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
23 | 25 |
/** |
24 | 26 |
* Abstract class that represents an Effect that works by modifying the ModelView matrix. |
... | ... | |
30 | 32 |
*/ |
31 | 33 |
public static final int NUM_UNIFORMS = 7; |
32 | 34 |
|
35 |
private float[] mMatrix,mTmpArray; |
|
36 |
|
|
33 | 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
34 | 38 |
/** |
35 | 39 |
* Only for use by the library itself. |
... | ... | |
38 | 42 |
*/ |
39 | 43 |
public abstract void apply(float[] matrix, float[] uniforms, int index); |
40 | 44 |
|
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 |
|
|
41 | 143 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
42 | 144 |
// empty function for completeness |
43 | 145 |
|
... | ... | |
51 | 153 |
MatrixEffect(EffectName name) |
52 | 154 |
{ |
53 | 155 |
super(name); |
156 |
|
|
157 |
mMatrix = new float[16]; |
|
158 |
mTmpArray= new float[4]; |
|
54 | 159 |
} |
55 | 160 |
} |
Also available in: Unified diff
New API MeshBase.apply(MatrixEffect[])