Revision 03aa6c3b
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/library/main/EffectQueueMatrix.java | ||
---|---|---|
35 | 35 |
|
36 | 36 |
private static float[] mMVPMatrix = new float[16]; |
37 | 37 |
private static float[] mViewMatrix= new float[16]; |
38 |
private static float[] mTmpMatrix = new float[16]; |
|
39 |
private static float[] mTmpResult = new float[4]; |
|
40 |
private static float[] mTmpPoint = new float[4]; |
|
41 |
private static float mMinx; |
|
42 |
private static float mMaxx; |
|
43 |
private static float mMiny; |
|
44 |
private static float mMaxy; |
|
38 | 45 |
|
39 | 46 |
private static int mObjDH; // This is a handle to half a Object dimensions |
40 | 47 |
private static int mMVPMatrixH; // the transformation matrix |
... | ... | |
49 | 56 |
|
50 | 57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
51 | 58 |
|
59 |
private void magnifyDir() |
|
60 |
{ |
|
61 |
Matrix.multiplyMV(mTmpResult,0,mTmpMatrix,0,mTmpPoint,0); |
|
62 |
float nx = mTmpResult[0]/mTmpResult[3]; |
|
63 |
float ny = mTmpResult[1]/mTmpResult[3]; |
|
64 |
|
|
65 |
if( nx<mMinx ) mMinx = nx; |
|
66 |
if( nx>mMaxx ) mMaxx = nx; |
|
67 |
if( ny<mMiny ) mMiny = ny; |
|
68 |
if( ny>mMaxy ) mMaxy = ny; |
|
69 |
} |
|
70 |
|
|
71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
72 |
// modify the ModelView matrix so that the object drawn appears to be (about) 'marginInPixels' pixels |
|
73 |
// larger in each direction when rendered. Used in BLUR. |
|
74 |
|
|
52 | 75 |
private void magnify(DistortedOutputSurface projection, float halfX, float halfY, float halfZ, float marginInPixels) |
53 | 76 |
{ |
54 |
float scale, nx, ny; |
|
55 |
float[] result= new float[4]; |
|
56 |
float[] point = new float[4]; |
|
57 |
float[] matrix= new float[16]; |
|
58 |
float minx = Integer.MAX_VALUE; |
|
59 |
float maxx = Integer.MIN_VALUE; |
|
60 |
float miny = Integer.MAX_VALUE; |
|
61 |
float maxy = Integer.MIN_VALUE; |
|
62 |
|
|
63 |
point[3] = 1.0f; |
|
64 |
|
|
65 |
Matrix.multiplyMM(matrix, 0, projection.mProjectionMatrix, 0, mViewMatrix, 0); |
|
66 |
|
|
67 |
point[0] = +halfX; point[1] = +halfY; point[2] = +halfZ; |
|
68 |
Matrix.multiplyMV(result,0,matrix,0,point,0); |
|
69 |
nx = result[0]/result[3]; |
|
70 |
ny = result[1]/result[3]; |
|
71 |
if( nx<minx ) minx = nx; |
|
72 |
if( nx>maxx ) maxx = nx; |
|
73 |
if( ny<miny ) miny = ny; |
|
74 |
if( ny>maxy ) maxy = ny; |
|
75 |
|
|
76 |
point[0] = +halfX; point[1] = +halfY; point[2] = -halfZ; |
|
77 |
Matrix.multiplyMV(result,0,matrix,0,point,0); |
|
78 |
nx = result[0]/result[3]; |
|
79 |
ny = result[1]/result[3]; |
|
80 |
if( nx<minx ) minx = nx; |
|
81 |
if( nx>maxx ) maxx = nx; |
|
82 |
if( ny<miny ) miny = ny; |
|
83 |
if( ny>maxy ) maxy = ny; |
|
84 |
|
|
85 |
point[0] = +halfX; point[1] = -halfY; point[2] = +halfZ; |
|
86 |
Matrix.multiplyMV(result,0,matrix,0,point,0); |
|
87 |
nx = result[0]/result[3]; |
|
88 |
ny = result[1]/result[3]; |
|
89 |
if( nx<minx ) minx = nx; |
|
90 |
if( nx>maxx ) maxx = nx; |
|
91 |
if( ny<miny ) miny = ny; |
|
92 |
if( ny>maxy ) maxy = ny; |
|
93 |
|
|
94 |
point[0] = +halfX; point[1] = -halfY; point[2] = -halfZ; |
|
95 |
Matrix.multiplyMV(result,0,matrix,0,point,0); |
|
96 |
nx = result[0]/result[3]; |
|
97 |
ny = result[1]/result[3]; |
|
98 |
if( nx<minx ) minx = nx; |
|
99 |
if( nx>maxx ) maxx = nx; |
|
100 |
if( ny<miny ) miny = ny; |
|
101 |
if( ny>maxy ) maxy = ny; |
|
102 |
|
|
103 |
point[0] = -halfX; point[1] = +halfY; point[2] = +halfZ; |
|
104 |
Matrix.multiplyMV(result,0,matrix,0,point,0); |
|
105 |
nx = result[0]/result[3]; |
|
106 |
ny = result[1]/result[3]; |
|
107 |
if( nx<minx ) minx = nx; |
|
108 |
if( nx>maxx ) maxx = nx; |
|
109 |
if( ny<miny ) miny = ny; |
|
110 |
if( ny>maxy ) maxy = ny; |
|
111 |
|
|
112 |
point[0] = -halfX; point[1] = +halfY; point[2] = -halfZ; |
|
113 |
Matrix.multiplyMV(result,0,matrix,0,point,0); |
|
114 |
nx = result[0]/result[3]; |
|
115 |
ny = result[1]/result[3]; |
|
116 |
if( nx<minx ) minx = nx; |
|
117 |
if( nx>maxx ) maxx = nx; |
|
118 |
if( ny<miny ) miny = ny; |
|
119 |
if( ny>maxy ) maxy = ny; |
|
120 |
|
|
121 |
point[0] = -halfX; point[1] = -halfY; point[2] = +halfZ; |
|
122 |
Matrix.multiplyMV(result,0,matrix,0,point,0); |
|
123 |
nx = result[0]/result[3]; |
|
124 |
ny = result[1]/result[3]; |
|
125 |
if( nx<minx ) minx = nx; |
|
126 |
if( nx>maxx ) maxx = nx; |
|
127 |
if( ny<miny ) miny = ny; |
|
128 |
if( ny>maxy ) maxy = ny; |
|
129 |
|
|
130 |
point[0] = -halfX; point[1] = -halfY; point[2] = -halfZ; |
|
131 |
Matrix.multiplyMV(result,0,matrix,0,point,0); |
|
132 |
nx = result[0]/result[3]; |
|
133 |
ny = result[1]/result[3]; |
|
134 |
if( nx<minx ) minx = nx; |
|
135 |
if( nx>maxx ) maxx = nx; |
|
136 |
if( ny<miny ) miny = ny; |
|
137 |
if( ny>maxy ) maxy = ny; |
|
138 |
|
|
139 |
float xlen = projection.mWidth *(maxx-minx)/2; |
|
140 |
float ylen = projection.mHeight*(maxy-miny)/2; |
|
141 |
|
|
142 |
scale = 1.0f + marginInPixels/( xlen>ylen ? ylen:xlen ); |
|
77 |
mMinx = Integer.MAX_VALUE; |
|
78 |
mMaxx = Integer.MIN_VALUE; |
|
79 |
mMiny = Integer.MAX_VALUE; |
|
80 |
mMaxy = Integer.MIN_VALUE; |
|
81 |
|
|
82 |
mTmpPoint[3] = 1.0f; |
|
83 |
|
|
84 |
Matrix.multiplyMM(mTmpMatrix, 0, projection.mProjectionMatrix, 0, mViewMatrix, 0); |
|
85 |
|
|
86 |
mTmpPoint[0] = +halfX; mTmpPoint[1] = +halfY; mTmpPoint[2] = +halfZ; magnifyDir(); |
|
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 |
|
|
95 |
float xlen = projection.mWidth *(mMaxx-mMinx)/2; |
|
96 |
float ylen = projection.mHeight*(mMaxy-mMiny)/2; |
|
97 |
float scale = 1.0f + marginInPixels/( xlen>ylen ? ylen:xlen ); |
|
143 | 98 |
|
144 | 99 |
//android.util.Log.d("scale", ""+marginInPixels+" scale= "+scale+" xlen="+xlen+" ylen="+ylen); |
145 | 100 |
|
Also available in: Unified diff
Simplification in EffectQueueMatrix.