Revision 7a5e538a
Added by Leszek Koltunski over 5 years ago
src/main/java/org/distorted/library/main/EffectQueueMatrix.java | ||
---|---|---|
36 | 36 |
|
37 | 37 |
private static float[] mMVPMatrix = new float[16]; |
38 | 38 |
private static float[] mViewMatrix= new float[16]; |
39 |
private static float[] mTmpMatrix = new float[16]; |
|
40 |
private static float[] mTmpResult = new float[4]; |
|
41 |
private static float[] mTmpPoint = new float[4]; |
|
42 |
private static float mMinx; |
|
43 |
private static float mMaxx; |
|
44 |
private static float mMiny; |
|
45 |
private static float mMaxy; |
|
46 | 39 |
|
47 | 40 |
private static int[] mObjDH = new int[Distorted.MAIN_VARIANTS]; |
48 | 41 |
private static int[] mMVPMatrixH = new int[Distorted.MAIN_VARIANTS]; |
... | ... | |
55 | 48 |
super(id,NUM_UNIFORMS,INDEX ); |
56 | 49 |
} |
57 | 50 |
|
58 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
59 |
|
|
60 |
private void magnifyDir() |
|
61 |
{ |
|
62 |
Matrix.multiplyMV(mTmpResult,0,mTmpMatrix,0,mTmpPoint,0); |
|
63 |
float nx = mTmpResult[0]/mTmpResult[3]; |
|
64 |
float ny = mTmpResult[1]/mTmpResult[3]; |
|
65 |
|
|
66 |
if( nx<mMinx ) mMinx = nx; |
|
67 |
if( nx>mMaxx ) mMaxx = nx; |
|
68 |
if( ny<mMiny ) mMiny = ny; |
|
69 |
if( ny>mMaxy ) mMaxy = ny; |
|
70 |
} |
|
71 |
|
|
72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
73 |
// modify the ModelView matrix so that the object drawn appears to be (about) 'marginInPixels' pixels |
|
74 |
// larger in each direction when rendered. Used in Postprocessing. |
|
75 |
|
|
76 |
private void magnify(DistortedOutputSurface projection, float halfX, float halfY, float halfZ, float marginInPixels) |
|
77 |
{ |
|
78 |
mMinx = Integer.MAX_VALUE; |
|
79 |
mMaxx = Integer.MIN_VALUE; |
|
80 |
mMiny = Integer.MAX_VALUE; |
|
81 |
mMaxy = Integer.MIN_VALUE; |
|
82 |
|
|
83 |
mTmpPoint[3] = 1.0f; |
|
84 |
|
|
85 |
Matrix.multiplyMM(mTmpMatrix, 0, projection.mProjectionMatrix, 0, mViewMatrix, 0); |
|
86 |
|
|
87 |
mTmpPoint[0] = +halfX; mTmpPoint[1] = +halfY; mTmpPoint[2] = +halfZ; magnifyDir(); |
|
88 |
mTmpPoint[0] = +halfX; mTmpPoint[1] = +halfY; mTmpPoint[2] = -halfZ; magnifyDir(); |
|
89 |
mTmpPoint[0] = +halfX; mTmpPoint[1] = -halfY; mTmpPoint[2] = +halfZ; magnifyDir(); |
|
90 |
mTmpPoint[0] = +halfX; mTmpPoint[1] = -halfY; mTmpPoint[2] = -halfZ; magnifyDir(); |
|
91 |
mTmpPoint[0] = -halfX; mTmpPoint[1] = +halfY; mTmpPoint[2] = +halfZ; magnifyDir(); |
|
92 |
mTmpPoint[0] = -halfX; mTmpPoint[1] = +halfY; mTmpPoint[2] = -halfZ; magnifyDir(); |
|
93 |
mTmpPoint[0] = -halfX; mTmpPoint[1] = -halfY; mTmpPoint[2] = +halfZ; magnifyDir(); |
|
94 |
mTmpPoint[0] = -halfX; mTmpPoint[1] = -halfY; mTmpPoint[2] = -halfZ; magnifyDir(); |
|
95 |
|
|
96 |
float xlen = projection.mWidth *(mMaxx-mMinx)/2; |
|
97 |
float ylen = projection.mHeight*(mMaxy-mMiny)/2; |
|
98 |
float scale = 1.0f + 2*marginInPixels/( xlen>ylen ? ylen:xlen ); |
|
99 |
|
|
100 |
Matrix.scaleM(mViewMatrix, 0, scale, scale, scale); |
|
101 |
} |
|
102 |
|
|
103 | 51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
104 | 52 |
|
105 | 53 |
static void getUniforms(int mProgramH, int variant) |
... | ... | |
146 | 94 |
|
147 | 95 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
148 | 96 |
|
149 |
void send(DistortedOutputSurface projection, float halfX, float halfY, float halfZ, float marginInPixels, int variant)
|
|
97 |
void send(DistortedOutputSurface projection, float halfX, float halfY, float halfZ, int variant) |
|
150 | 98 |
{ |
151 | 99 |
Matrix.setIdentityM(mViewMatrix, 0); |
152 | 100 |
Matrix.translateM(mViewMatrix, 0, -projection.mWidth/2, projection.mHeight/2, -projection.mDistance); |
... | ... | |
156 | 104 |
for(int i=0; i<mNumEffects; i++) ((MatrixEffect)mEffects[i]).apply(mViewMatrix,mUniforms,i); |
157 | 105 |
|
158 | 106 |
Matrix.translateM(mViewMatrix, 0, halfX,-halfY,-halfZ); |
159 |
if( marginInPixels!=0 ) magnify(projection,halfX,halfY,halfZ, marginInPixels); |
|
160 | 107 |
Matrix.multiplyMM(mMVPMatrix, 0, projection.mProjectionMatrix, 0, mViewMatrix, 0); |
161 | 108 |
|
162 | 109 |
GLES31.glUniform3f( mObjDH[variant] , halfX, halfY, halfZ); |
Also available in: Unified diff
Progress with Inflate (building block of postprocessing effects: the proper way of marking a halo around a Mesh)
'Inflate' app testing the machanism. MeshFlat appears to be working, now we only need to fill up the per-vertex Inflate vector in the MeshCubes.