Revision c90aca24
Added by Leszek Koltunski almost 5 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 |
} |
src/main/java/org/distorted/library/effectqueue/EffectQueueMatrix.java | ||
---|---|---|
76 | 76 |
} |
77 | 77 |
|
78 | 78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
79 |
// return a float which describes how much larger an object must be so that it appears to be (dialog_about)
|
|
79 |
// return a float which describes how much larger an object must be so that it appears to be (about) |
|
80 | 80 |
// 'marginInPixels' pixels larger in each direction. Used in Postprocessing. |
81 | 81 |
|
82 | 82 |
float magnify(float[] projection, int width, int height, float mipmap, float halfX, float halfY, float halfZ, float marginInPixels) |
src/main/java/org/distorted/library/effectqueue/EffectQueuePostprocess.java | ||
---|---|---|
27 | 27 |
import org.distorted.library.effect.EffectType; |
28 | 28 |
import org.distorted.library.effect.PostprocessEffect; |
29 | 29 |
import org.distorted.library.effect.VertexEffect; |
30 |
import org.distorted.library.main.DistortedEffects; |
|
30 | 31 |
import org.distorted.library.main.DistortedLibrary; |
31 | 32 |
import org.distorted.library.main.DistortedFramebuffer; |
32 | 33 |
import org.distorted.library.main.DistortedNode; |
... | ... | |
164 | 165 |
if( input.setAsInput() ) |
165 | 166 |
{ |
166 | 167 |
MeshBase mesh = node.getMesh(); |
168 |
DistortedEffects effects = node.getEffects(); |
|
167 | 169 |
|
168 |
float halfW = input.getWidth() / 2.0f;
|
|
169 |
float halfH = input.getHeight()/ 2.0f;
|
|
170 |
float halfZ = halfW*mesh.getZFactor();
|
|
170 |
float halfW = effects.getStartchX() / 2.0f;
|
|
171 |
float halfH = effects.getStartchY() / 2.0f;
|
|
172 |
float halfZ = effects.getStartchZ() / 2.0f;
|
|
171 | 173 |
|
172 |
int width = buffer.getWidth(); |
|
173 |
int height = buffer.getHeight(); |
|
174 |
int width = buffer.getWidth();
|
|
175 |
int height = buffer.getHeight();
|
|
174 | 176 |
|
175 | 177 |
InternalRenderState.setUpStencilMark(mA!=0.0f); |
176 | 178 |
InternalRenderState.disableBlending(); |
... | ... | |
181 | 183 |
|
182 | 184 |
mesh.bindVertexAttribs(mPreProgram); |
183 | 185 |
|
184 |
EffectQueue[] queues = node.getEffects().getQueues();
|
|
186 |
EffectQueue[] queues = effects.getQueues();
|
|
185 | 187 |
EffectQueueMatrix matrix = (EffectQueueMatrix)queues[0]; |
186 | 188 |
EffectQueueVertex vertex = (EffectQueueVertex)queues[1]; |
187 | 189 |
|
src/main/java/org/distorted/library/main/DistortedEffects.java | ||
---|---|---|
36 | 36 |
private long mID; |
37 | 37 |
private EffectQueue[] mQueues; |
38 | 38 |
|
39 |
private int[] mStretchX, mStretchY, mStretchZ; |
|
40 |
|
|
39 | 41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
40 | 42 |
/** |
41 | 43 |
* @y.exclude |
... | ... | |
58 | 60 |
/** |
59 | 61 |
* Create empty effect queue. |
60 | 62 |
*/ |
61 |
public DistortedEffects() |
|
63 |
public DistortedEffects(int stretchX, int stretchY, int stretchZ) |
|
64 |
{ |
|
65 |
mStretchX = new int[1]; |
|
66 |
mStretchY = new int[1]; |
|
67 |
mStretchZ = new int[1]; |
|
68 |
|
|
69 |
mStretchX[0] = stretchX; |
|
70 |
mStretchY[0] = stretchY; |
|
71 |
mStretchZ[0] = stretchZ; |
|
72 |
|
|
73 |
mID = ++mNextID; |
|
74 |
mQueues = new EffectQueue[EffectType.LENGTH]; |
|
75 |
EffectQueue.allocateQueues(mQueues,null,0); |
|
76 |
} |
|
77 |
|
|
78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
79 |
/** |
|
80 |
* Temporary constructor. |
|
81 |
*/ |
|
82 |
public DistortedEffects(int dummy) |
|
62 | 83 |
{ |
84 |
mStretchX = new int[1]; |
|
85 |
mStretchY = new int[1]; |
|
86 |
mStretchZ = new int[1]; |
|
87 |
|
|
88 |
mStretchX[0] = 1; |
|
89 |
mStretchY[0] = 1; |
|
90 |
mStretchZ[0] = 1; |
|
91 |
|
|
63 | 92 |
mID = ++mNextID; |
64 | 93 |
mQueues = new EffectQueue[EffectType.LENGTH]; |
65 | 94 |
EffectQueue.allocateQueues(mQueues,null,0); |
... | ... | |
77 | 106 |
*/ |
78 | 107 |
public DistortedEffects(DistortedEffects dc, int flags) |
79 | 108 |
{ |
109 |
mStretchX = dc.mStretchX; |
|
110 |
mStretchY = dc.mStretchY; |
|
111 |
mStretchZ = dc.mStretchZ; |
|
112 |
|
|
80 | 113 |
mID = ++mNextID; |
81 | 114 |
mQueues = new EffectQueue[EffectType.LENGTH]; |
82 | 115 |
EffectQueue.allocateQueues(mQueues,dc.getQueues(),flags); |
83 | 116 |
} |
84 | 117 |
|
118 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
119 |
/** |
|
120 |
* Sets the stretch parameters. Coordinates of all vertices of any Mesh rendered with those Effects |
|
121 |
* will be first pre-multiplied by those. |
|
122 |
*/ |
|
123 |
public void setStretch(int sx, int sy, int sz) |
|
124 |
{ |
|
125 |
mStretchX[0] = sx; |
|
126 |
mStretchY[0] = sy; |
|
127 |
mStretchZ[0] = sz; |
|
128 |
} |
|
129 |
|
|
130 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
131 |
/** |
|
132 |
* X coordinates of all vertices of any Mesh rendered with those Effects will be first pre-multiplied |
|
133 |
* by this parameter. |
|
134 |
*/ |
|
135 |
public int getStartchX() |
|
136 |
{ |
|
137 |
return mStretchX[0]; |
|
138 |
} |
|
139 |
|
|
140 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
141 |
/** |
|
142 |
* Y coordinates of all vertices of any Mesh rendered with those Effects will be first pre-multiplied |
|
143 |
* by this parameter. |
|
144 |
*/ |
|
145 |
public int getStartchY() |
|
146 |
{ |
|
147 |
return mStretchY[0]; |
|
148 |
} |
|
149 |
|
|
150 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
151 |
/** |
|
152 |
* Z coordinates of all vertices of any Mesh rendered with those Effects will be first pre-multiplied |
|
153 |
* by this parameter. |
|
154 |
*/ |
|
155 |
public int getStartchZ() |
|
156 |
{ |
|
157 |
return mStretchZ[0]; |
|
158 |
} |
|
159 |
|
|
85 | 160 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
86 | 161 |
/** |
87 | 162 |
* Returns unique ID of this instance. |
src/main/java/org/distorted/library/main/DistortedLibrary.java | ||
---|---|---|
428 | 428 |
|
429 | 429 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
430 | 430 |
|
431 |
static void drawPrivOIT(EffectQueue[] queues, float halfW, float halfH, MeshBase mesh, InternalOutputSurface surface, long currTime)
|
|
431 |
static void drawPrivOIT(DistortedEffects effects, MeshBase mesh, InternalOutputSurface surface, long currTime)
|
|
432 | 432 |
{ |
433 |
float halfZ = halfW*mesh.getZFactor(); |
|
433 |
float halfX = effects.getStartchX() / 2.0f; |
|
434 |
float halfY = effects.getStartchY() / 2.0f; |
|
435 |
float halfZ = effects.getStartchZ() / 2.0f; |
|
434 | 436 |
|
435 |
EffectQueue.compute(queues, currTime, halfW, halfH, halfZ ); |
|
437 |
EffectQueue[] queues = effects.getQueues(); |
|
438 |
|
|
439 |
EffectQueue.compute(queues, currTime, halfX, halfY, halfZ ); |
|
436 | 440 |
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight ); |
437 | 441 |
|
438 | 442 |
DistortedLibrary.mMainOITProgram.useProgram(); |
... | ... | |
448 | 452 |
float mipmap = surface.mMipmap; |
449 | 453 |
float[] projection= surface.mProjectionMatrix; |
450 | 454 |
|
451 |
EffectQueue.send(queues, width, height, distance, mipmap, projection, inflate, halfW, halfH, halfZ, 1 );
|
|
455 |
EffectQueue.send(queues, width, height, distance, mipmap, projection, inflate, halfX, halfY, halfZ, 1 );
|
|
452 | 456 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, mesh.getNumVertices() ); |
453 | 457 |
|
454 | 458 |
if( mesh.getShowNormals() ) |
455 | 459 |
{ |
456 | 460 |
DistortedLibrary.mMainProgram.useProgram(); |
457 |
EffectQueue.send(queues, width, height, distance, mipmap, projection, inflate, halfW, halfH, halfZ, 0 );
|
|
461 |
EffectQueue.send(queues, width, height, distance, mipmap, projection, inflate, halfX, halfY, halfZ, 0 );
|
|
458 | 462 |
displayNormals(queues,mesh); |
459 | 463 |
} |
460 | 464 |
} |
461 | 465 |
|
462 | 466 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
463 | 467 |
|
464 |
static void drawPriv(EffectQueue[] queues, float halfW, float halfH, MeshBase mesh, InternalOutputSurface surface, long currTime)
|
|
468 |
static void drawPriv(DistortedEffects effects, MeshBase mesh, InternalOutputSurface surface, long currTime)
|
|
465 | 469 |
{ |
466 |
float halfZ = halfW*mesh.getZFactor(); |
|
470 |
float halfX = effects.getStartchX() / 2.0f; |
|
471 |
float halfY = effects.getStartchY() / 2.0f; |
|
472 |
float halfZ = effects.getStartchZ() / 2.0f; |
|
473 |
|
|
474 |
EffectQueue[] queues = effects.getQueues(); |
|
467 | 475 |
|
468 |
EffectQueue.compute(queues, currTime, halfW, halfH, halfZ );
|
|
476 |
EffectQueue.compute(queues, currTime, halfX, halfY, halfZ );
|
|
469 | 477 |
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight ); |
470 | 478 |
|
471 | 479 |
DistortedLibrary.mMainProgram.useProgram(); |
... | ... | |
479 | 487 |
float mipmap = surface.mMipmap; |
480 | 488 |
float[] projection= surface.mProjectionMatrix; |
481 | 489 |
|
482 |
EffectQueue.send(queues, width, height, distance, mipmap, projection, inflate, halfW, halfH, halfZ, 0 );
|
|
490 |
EffectQueue.send(queues, width, height, distance, mipmap, projection, inflate, halfX, halfY, halfZ, 0 );
|
|
483 | 491 |
GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, mesh.getNumVertices() ); |
484 | 492 |
|
485 | 493 |
if( mesh.getShowNormals() ) displayNormals(queues,mesh); |
src/main/java/org/distorted/library/main/DistortedNode.java | ||
---|---|---|
157 | 157 |
{ |
158 | 158 |
mState.apply(); |
159 | 159 |
GLES31.glDisable(GLES31.GL_BLEND); |
160 |
DistortedLibrary.drawPriv(mEffects.getQueues(), mSurface.getWidth()/2.0f, mSurface.getHeight()/2.0f, mMesh, surface, currTime);
|
|
160 |
DistortedLibrary.drawPriv(mEffects, mMesh, surface, currTime); |
|
161 | 161 |
GLES31.glEnable(GLES31.GL_BLEND); |
162 | 162 |
return 1; |
163 | 163 |
} |
... | ... | |
175 | 175 |
if( input.setAsInput() ) |
176 | 176 |
{ |
177 | 177 |
mState.apply(); |
178 |
DistortedLibrary.drawPrivOIT(mEffects.getQueues(), mSurface.getWidth()/2.0f, mSurface.getHeight()/2.0f, mMesh, surface, currTime);
|
|
178 |
DistortedLibrary.drawPrivOIT(mEffects, mMesh, surface, currTime); |
|
179 | 179 |
return 1; |
180 | 180 |
} |
181 | 181 |
|
... | ... | |
192 | 192 |
if( input.setAsInput() ) |
193 | 193 |
{ |
194 | 194 |
mState.apply(); |
195 |
DistortedLibrary.drawPriv(mEffects.getQueues(), mSurface.getWidth()/2.0f, mSurface.getHeight()/2.0f, mMesh, surface, currTime);
|
|
195 |
DistortedLibrary.drawPriv(mEffects, mMesh, surface, currTime); |
|
196 | 196 |
return 1; |
197 | 197 |
} |
198 | 198 |
|
... | ... | |
240 | 240 |
|
241 | 241 |
private DistortedFramebuffer allocateNewFBO() |
242 | 242 |
{ |
243 |
int width = mFboW <= 0 ? mSurface.getWidth() : mFboW;
|
|
244 |
int height = mFboH <= 0 ? mSurface.getHeight() : mFboH;
|
|
243 |
int width = mFboW <= 0 ? mEffects.getStartchX() : mFboW;
|
|
244 |
int height = mFboH <= 0 ? mEffects.getStartchY() : mFboH;
|
|
245 | 245 |
return new DistortedFramebuffer(1,mFboDepthStencil, InternalSurface.TYPE_TREE, width, height); |
246 | 246 |
} |
247 | 247 |
|
... | ... | |
273 | 273 |
mRenderWayOIT = false; |
274 | 274 |
|
275 | 275 |
mFboW = 0; // i.e. take this from |
276 |
mFboH = 0; // mSurface's dimensions
|
|
276 |
mFboH = 0; // mEffects's stretch{X,Y}
|
|
277 | 277 |
mFboDepthStencil = DistortedFramebuffer.DEPTH_NO_STENCIL; |
278 | 278 |
|
279 | 279 |
mData = InternalNodeData.returnData(generateIDList()); |
... | ... | |
307 | 307 |
} |
308 | 308 |
else |
309 | 309 |
{ |
310 |
int w = node.mSurface.getWidth(); |
|
311 |
int h = node.mSurface.getHeight(); |
|
312 |
|
|
313 | 310 |
if( node.mSurface instanceof DistortedTexture ) |
314 | 311 |
{ |
315 |
mSurface = new DistortedTexture(w,h, InternalSurface.TYPE_TREE);
|
|
312 |
mSurface = new DistortedTexture(InternalSurface.TYPE_TREE); |
|
316 | 313 |
} |
317 | 314 |
else if( node.mSurface instanceof DistortedFramebuffer ) |
318 | 315 |
{ |
316 |
int w = node.mSurface.getWidth(); |
|
317 |
int h = node.mSurface.getHeight(); |
|
319 | 318 |
int depthStencil = DistortedFramebuffer.NO_DEPTH_NO_STENCIL; |
320 | 319 |
|
321 | 320 |
if( ((DistortedFramebuffer) node.mSurface).hasDepth() ) |
src/main/java/org/distorted/library/main/DistortedScreen.java | ||
---|---|---|
133 | 133 |
|
134 | 134 |
if( mShowFPS && fpsTexture.setAsInput()) |
135 | 135 |
{ |
136 |
DistortedLibrary.drawPriv(fpsEffects.getQueues(), FPS_W / 2.0f, FPS_H / 2.0f, fpsMesh, this, time);
|
|
136 |
DistortedLibrary.drawPriv(fpsEffects, fpsMesh, this, time); |
|
137 | 137 |
} |
138 | 138 |
|
139 | 139 |
if( ++mCurRenderedFBO>= DistortedLibrary.FBO_QUEUE_SIZE ) |
... | ... | |
162 | 162 |
fpsString = ""; |
163 | 163 |
fpsBitmap = Bitmap.createBitmap(FPS_W, FPS_H, Bitmap.Config.ARGB_8888); |
164 | 164 |
fpsMesh = new MeshQuad(); |
165 |
fpsTexture = new DistortedTexture(FPS_W, FPS_H);
|
|
165 |
fpsTexture = new DistortedTexture(); |
|
166 | 166 |
fpsTexture.setTexture(fpsBitmap); |
167 | 167 |
fpsCanvas = new Canvas(fpsBitmap); |
168 |
fpsEffects = new DistortedEffects(); |
|
168 |
fpsEffects = new DistortedEffects(FPS_W,FPS_H,0);
|
|
169 | 169 |
fpsEffects.apply(mMoveEffect); |
170 | 170 |
|
171 | 171 |
mPaint = new Paint(); |
src/main/java/org/distorted/library/main/DistortedTexture.java | ||
---|---|---|
113 | 113 |
// inside a Tree of DistortedNodes (TREE) |
114 | 114 |
// SYSTEM surfaces do not get removed in onDestroy(). |
115 | 115 |
|
116 |
public DistortedTexture(int width, int height, int type)
|
|
116 |
public DistortedTexture(int type) |
|
117 | 117 |
{ |
118 |
super(width,height,NOT_CREATED_YET,1,1,type);
|
|
118 |
super(0,0,NOT_CREATED_YET,1,1,type);
|
|
119 | 119 |
mBmp= null; |
120 | 120 |
} |
121 | 121 |
|
... | ... | |
123 | 123 |
// PUBLIC API |
124 | 124 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
125 | 125 |
/** |
126 |
* Create empty texture of given dimensions.
|
|
126 |
* Create an empty texture.
|
|
127 | 127 |
*/ |
128 |
public DistortedTexture(int width, int height)
|
|
128 |
public DistortedTexture() |
|
129 | 129 |
{ |
130 |
this(width,height,TYPE_USER);
|
|
130 |
this(TYPE_USER); |
|
131 | 131 |
} |
132 | 132 |
|
133 | 133 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
157 | 157 |
*/ |
158 | 158 |
public void setTexture(Bitmap bmp) |
159 | 159 |
{ |
160 |
mBmp= bmp; |
|
160 |
mBmp = bmp; |
|
161 |
mWidth = bmp.getWidth(); |
|
162 |
mHeight= bmp.getHeight(); |
|
163 |
|
|
161 | 164 |
markForCreation(); |
162 | 165 |
} |
163 | 166 |
|
... | ... | |
173 | 176 |
paint.setColor(argb); |
174 | 177 |
paint.setStyle(Paint.Style.FILL); |
175 | 178 |
|
176 |
mBmp = Bitmap.createBitmap(1,1, Bitmap.Config.ARGB_8888); |
|
179 |
mWidth = 1; |
|
180 |
mHeight= 1; |
|
181 |
|
|
182 |
mBmp = Bitmap.createBitmap(mWidth,mHeight, Bitmap.Config.ARGB_8888); |
|
177 | 183 |
Canvas canvas = new Canvas(mBmp); |
178 |
canvas.drawRect(0,0,1,1,paint);
|
|
184 |
canvas.drawRect(0,0,mWidth,mHeight,paint);
|
|
179 | 185 |
|
180 | 186 |
markForCreation(); |
181 | 187 |
} |
src/main/java/org/distorted/library/main/InternalSurface.java | ||
---|---|---|
100 | 100 |
* |
101 | 101 |
* @return depth of the Object, in pixels. |
102 | 102 |
*/ |
103 |
|
|
104 |
/* |
|
103 | 105 |
public int getDepth(MeshBase mesh) |
104 | 106 |
{ |
105 | 107 |
return mesh==null ? 0 : (int)(mWidth*mesh.getZFactor() ); |
106 | 108 |
} |
107 |
|
|
109 |
*/ |
|
108 | 110 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
109 | 111 |
/** |
110 | 112 |
* Bind the underlying rectangle of pixels as a OpenGL Texture. |
src/main/java/org/distorted/library/mesh/MeshBase.java | ||
---|---|---|
20 | 20 |
package org.distorted.library.mesh; |
21 | 21 |
|
22 | 22 |
import android.opengl.GLES31; |
23 |
import android.opengl.Matrix; |
|
23 | 24 |
|
24 | 25 |
import org.distorted.library.effect.MatrixEffect; |
25 | 26 |
import org.distorted.library.main.DistortedLibrary; |
... | ... | |
29 | 30 |
import java.nio.ByteBuffer; |
30 | 31 |
import java.nio.ByteOrder; |
31 | 32 |
import java.nio.FloatBuffer; |
33 |
import java.util.ArrayList; |
|
32 | 34 |
|
33 | 35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
34 | 36 |
/** |
... | ... | |
63 | 65 |
|
64 | 66 |
private boolean mShowNormals; // when rendering this mesh, draw normal vectors? |
65 | 67 |
private InternalBuffer mVBO, mTFO; // main vertex buffer and transform feedback buffer |
66 |
private final float zFactor; // strange workaround for the fact that we need to somehow store the 'depth' |
|
67 |
// of the Mesh. Used in DistortedEffects. See DistortedTexture.getDepth(). |
|
68 | 68 |
private int mNumVertices; |
69 | 69 |
private float[] mVertAttribs; // packed: PosX,PosY,PosZ, NorX,NorY,NorZ, InfX,InfY,InfZ, TexS,TexT |
70 | 70 |
private float mInflate; |
71 | 71 |
|
72 |
private class Component |
|
73 |
{ |
|
74 |
private int mEndIndex; |
|
75 |
private float[] mTextureMap; |
|
76 |
|
|
77 |
Component() |
|
78 |
{ |
|
79 |
mTextureMap = new float[8]; |
|
80 |
|
|
81 |
mTextureMap[ 0] = 0.0f; // LLX |
|
82 |
mTextureMap[ 1] = 0.0f; // LLY |
|
83 |
mTextureMap[ 2] = 0.0f; // ULX |
|
84 |
mTextureMap[ 3] = 1.0f; // ULY |
|
85 |
mTextureMap[ 4] = 1.0f; // URX |
|
86 |
mTextureMap[ 5] = 1.0f; // URY |
|
87 |
mTextureMap[ 6] = 1.0f; // LRX |
|
88 |
mTextureMap[ 7] = 0.0f; // LRY |
|
89 |
} |
|
90 |
Component(Component original) |
|
91 |
{ |
|
92 |
mEndIndex = original.mEndIndex; |
|
93 |
mTextureMap = new float[8]; |
|
94 |
System.arraycopy(original.mTextureMap,0,mTextureMap,0,8); |
|
95 |
} |
|
96 |
|
|
97 |
} |
|
98 |
|
|
99 |
private ArrayList<Component> mComponent; |
|
100 |
|
|
72 | 101 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
73 | 102 |
|
74 |
MeshBase(float factor)
|
|
103 |
MeshBase() |
|
75 | 104 |
{ |
76 |
zFactor = factor; |
|
77 | 105 |
mShowNormals = false; |
106 |
mInflate = 0.0f; |
|
107 |
mComponent = new ArrayList<>(); |
|
108 |
mComponent.add(new Component()); |
|
109 |
|
|
110 |
mVBO = new InternalBuffer(GLES31.GL_ARRAY_BUFFER , GLES31.GL_STATIC_READ); |
|
111 |
mTFO = new InternalBuffer(GLES31.GL_TRANSFORM_FEEDBACK_BUFFER, GLES31.GL_STATIC_READ); |
|
112 |
} |
|
113 |
|
|
114 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
115 |
// copy constructor |
|
116 |
|
|
117 |
MeshBase(MeshBase original) |
|
118 |
{ |
|
119 |
mShowNormals = original.mShowNormals; |
|
120 |
mInflate = original.mInflate; |
|
121 |
|
|
122 |
int size = original.mComponent.size(); |
|
123 |
mComponent = new ArrayList<>(); |
|
124 |
for(int i=0; i<size; i++) |
|
125 |
{ |
|
126 |
Component comp = new Component(original.mComponent.get(i)); |
|
127 |
mComponent.add(comp); |
|
128 |
} |
|
78 | 129 |
|
79 | 130 |
mVBO = new InternalBuffer(GLES31.GL_ARRAY_BUFFER , GLES31.GL_STATIC_READ); |
80 | 131 |
mTFO = new InternalBuffer(GLES31.GL_TRANSFORM_FEEDBACK_BUFFER, GLES31.GL_STATIC_READ); |
132 |
|
|
133 |
System.arraycopy(original.mVertAttribs,0,mVertAttribs,0,original.mNumVertices*VERT_ATTRIBS); |
|
134 |
setAttribs(mVertAttribs); |
|
81 | 135 |
} |
82 | 136 |
|
83 | 137 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
88 | 142 |
mNumVertices = vertexAttribs.length/VERT_ATTRIBS; |
89 | 143 |
mVertAttribs = vertexAttribs; |
90 | 144 |
|
145 |
mComponent.get(0).mEndIndex = mNumVertices; |
|
146 |
|
|
91 | 147 |
FloatBuffer attribs = ByteBuffer.allocateDirect(mNumVertices*VERT_SIZE).order(ByteOrder.nativeOrder()).asFloatBuffer(); |
92 | 148 |
attribs.put(vertexAttribs).position(0); |
93 | 149 |
|
... | ... | |
117 | 173 |
return mNumVertices; |
118 | 174 |
} |
119 | 175 |
|
120 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
121 |
/** |
|
122 |
* Not part of public API, do not document (public only because has to be used from the main package) |
|
123 |
* |
|
124 |
* @y.exclude |
|
125 |
*/ |
|
126 |
public float getZFactor() |
|
127 |
{ |
|
128 |
return zFactor; |
|
129 |
} |
|
130 |
|
|
131 | 176 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
132 | 177 |
/** |
133 | 178 |
* Not part of public API, do not document (public only because has to be used from the main package) |
... | ... | |
219 | 264 |
|
220 | 265 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
221 | 266 |
/** |
222 |
* Multiply all coordinates, normal and inflate vectors by the matrix.
|
|
267 |
* Apply all Effects to the vertex mesh. Overwrite the mesh in place.
|
|
223 | 268 |
* <p> |
224 |
* This is a static, permanent modification of the vertices contained in this Mesh. If the Effect
|
|
225 |
* contains any Dynamics, they will be evaluated at 0.
|
|
269 |
* This is a static, permanent modification of the vertices contained in this Mesh. If the effects
|
|
270 |
* contain any Dynamics, they will be evaluated at 0. |
|
226 | 271 |
* |
227 | 272 |
* Please note that calling this once with the complete list of Effects will be much faster than |
228 | 273 |
* calling it repeatedly with one Effect at a time, as we have to reallocate the array of vertices |
... | ... | |
230 | 275 |
*/ |
231 | 276 |
public void apply(MatrixEffect[] effects) |
232 | 277 |
{ |
233 |
for(int v=0; v<mNumVertices; v++) |
|
278 |
float[][] matrix = new float[effects.length][16]; |
|
279 |
float[] tmp; |
|
280 |
float[] array = new float[4]; |
|
281 |
float x,y,z; |
|
282 |
int numEffects = 0; |
|
283 |
|
|
284 |
for(MatrixEffect eff: effects) |
|
234 | 285 |
{ |
235 |
for(MatrixEffect eff: effects)
|
|
286 |
if( eff!=null )
|
|
236 | 287 |
{ |
237 |
if( eff!=null ) eff.applyToVertex( mVertAttribs, v*VERT_ATTRIBS ); |
|
288 |
Matrix.setIdentityM(matrix[numEffects],0); |
|
289 |
eff.compute(array,0,0,0); |
|
290 |
eff.apply(matrix[numEffects], array, 0); |
|
291 |
numEffects++; |
|
238 | 292 |
} |
239 | 293 |
} |
240 | 294 |
|
241 |
setAttribs(mVertAttribs); |
|
295 |
for(int index=0; index<mNumVertices; index+=VERT_ATTRIBS ) |
|
296 |
{ |
|
297 |
for(int mat=0; mat<numEffects; mat++) |
|
298 |
{ |
|
299 |
tmp = matrix[mat]; |
|
300 |
|
|
301 |
x = mVertAttribs[index+POS_ATTRIB ]; |
|
302 |
y = mVertAttribs[index+POS_ATTRIB+1]; |
|
303 |
z = mVertAttribs[index+POS_ATTRIB+2]; |
|
304 |
|
|
305 |
mVertAttribs[index+POS_ATTRIB ] = tmp[0]*x + tmp[4]*y + tmp[ 8]*z + tmp[12]; |
|
306 |
mVertAttribs[index+POS_ATTRIB+1] = tmp[1]*x + tmp[5]*y + tmp[ 9]*z + tmp[13]; |
|
307 |
mVertAttribs[index+POS_ATTRIB+2] = tmp[2]*x + tmp[6]*y + tmp[10]*z + tmp[14]; |
|
308 |
|
|
309 |
x = mVertAttribs[index+NOR_ATTRIB ]; |
|
310 |
y = mVertAttribs[index+NOR_ATTRIB+1]; |
|
311 |
z = mVertAttribs[index+NOR_ATTRIB+2]; |
|
312 |
|
|
313 |
mVertAttribs[index+NOR_ATTRIB ] = tmp[0]*x + tmp[4]*y + tmp[ 8]*z; |
|
314 |
mVertAttribs[index+NOR_ATTRIB+1] = tmp[1]*x + tmp[5]*y + tmp[ 9]*z; |
|
315 |
mVertAttribs[index+NOR_ATTRIB+2] = tmp[2]*x + tmp[6]*y + tmp[10]*z; |
|
316 |
|
|
317 |
x = mVertAttribs[index+INF_ATTRIB ]; |
|
318 |
y = mVertAttribs[index+INF_ATTRIB+1]; |
|
319 |
z = mVertAttribs[index+INF_ATTRIB+2]; |
|
320 |
|
|
321 |
mVertAttribs[index+INF_ATTRIB ] = tmp[0]*x + tmp[4]*y + tmp[ 8]*z; |
|
322 |
mVertAttribs[index+INF_ATTRIB+1] = tmp[1]*x + tmp[5]*y + tmp[ 9]*z; |
|
323 |
mVertAttribs[index+INF_ATTRIB+2] = tmp[2]*x + tmp[6]*y + tmp[10]*z; |
|
324 |
} |
|
325 |
} |
|
326 |
|
|
327 |
FloatBuffer attribs = ByteBuffer.allocateDirect(mNumVertices*VERT_SIZE).order(ByteOrder.nativeOrder()).asFloatBuffer(); |
|
328 |
attribs.put(mVertAttribs).position(0); |
|
329 |
|
|
330 |
mVBO.setData(mNumVertices*VERT_SIZE, attribs); |
|
331 |
mTFO.setData(mNumVertices*TRAN_SIZE, null ); |
|
332 |
} |
|
333 |
|
|
334 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
335 |
/** |
|
336 |
* Join a list of Meshes into this one. |
|
337 |
* <p> |
|
338 |
* Please note that calling this once with the complete list of Meshes will be much faster than |
|
339 |
* calling it repeatedly with one Mesh at a time, as we have to reallocate the array of vertices |
|
340 |
* each time. |
|
341 |
*/ |
|
342 |
public void join(MeshBase[] meshes) |
|
343 |
{ |
|
344 |
|
|
242 | 345 |
} |
243 | 346 |
} |
244 | 347 |
|
src/main/java/org/distorted/library/mesh/MeshCubes.java | ||
---|---|---|
31 | 31 |
*/ |
32 | 32 |
public class MeshCubes extends MeshBase |
33 | 33 |
{ |
34 |
private static final float R = 0.0f;//0.2f;
|
|
34 |
private static final float R = 0.0f; |
|
35 | 35 |
|
36 | 36 |
private static final int FRONT = 0; |
37 | 37 |
private static final int BACK = 1; |
... | ... | |
165 | 165 |
int sideVert = 2*(mSlices-1) + mSlices*sideVertOneSlice; |
166 | 166 |
int firstWinding = (mSlices>0 && (frontVert+1)%2==1 ) ? 1:0; |
167 | 167 |
int dataL = mSlices==0 ? frontVert : (frontVert+1) +firstWinding+ (1+sideVert+1) + (1+frontVert); |
168 |
/* |
|
169 |
android.util.Log.e("CUBES","triangleShifts="+triangleShifts+" windingShifts="+windingShifts+" winding1="+firstWinding+" frontVert="+frontVert+" sideVert="+sideVert); |
|
170 |
android.util.Log.e("CUBES", "frontW="+frontWalls+" fSegments="+frontSegments+" sWalls="+mSideWalls+" sSegments="+mEdgeNum+" sideBends="+mSideBends+" dataLen="+dataL ); |
|
171 |
*/ |
|
168 |
|
|
172 | 169 |
return dataL<0 ? 0:dataL; |
173 | 170 |
} |
174 | 171 |
|
175 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
176 |
/* |
|
177 |
private static String debug(short[] val) |
|
178 |
{ |
|
179 |
String ret="";j |
|
180 |
|
|
181 |
for(int i=0; i<val.length; i++) ret+=(" "+val[i]); |
|
182 |
|
|
183 |
return ret; |
|
184 |
} |
|
185 |
*/ |
|
186 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
187 |
/* |
|
188 |
private static String debug(float[] val, int stop) |
|
189 |
{ |
|
190 |
String ret=""; |
|
191 |
float v; |
|
192 |
boolean neg; |
|
193 |
int mod; |
|
194 |
|
|
195 |
for(int i=0; i<val.length; i++) |
|
196 |
{ |
|
197 |
if( i%stop==0 ) ret+="\n"; |
|
198 |
|
|
199 |
mod = i%stop; |
|
200 |
|
|
201 |
if( mod==0 || mod==3 || mod==6 ) ret+=" ("; |
|
202 |
|
|
203 |
v = val[i]; |
|
204 |
if( v==-0.0f ) v=0.0f; |
|
205 |
|
|
206 |
|
|
207 |
neg = v<0; |
|
208 |
v = (v<0 ? -v:v); |
|
209 |
|
|
210 |
ret+=((neg? " -":" +")+v); |
|
211 |
|
|
212 |
if( mod==2 || mod==5 || mod==7 ) ret+=")"; |
|
213 |
} |
|
214 |
|
|
215 |
return ret; |
|
216 |
} |
|
217 |
*/ |
|
218 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
219 |
/* |
|
220 |
private static String debug(Edge e) |
|
221 |
{ |
|
222 |
String d = ""; |
|
223 |
|
|
224 |
switch(e.side) |
|
225 |
{ |
|
226 |
case NORTH: d+="NORTH "; break; |
|
227 |
case SOUTH: d+="SOUTH "; break; |
|
228 |
case WEST : d+="WEST "; break; |
|
229 |
case EAST : d+="EAST "; break; |
|
230 |
} |
|
231 |
|
|
232 |
d+=("("+e.row+","+e.col+")"); |
|
233 |
|
|
234 |
return d; |
|
235 |
} |
|
236 |
*/ |
|
237 | 172 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
238 | 173 |
|
239 | 174 |
private void prepareDataStructures(int cols, String desc, int slices) |
... | ... | |
347 | 282 |
|
348 | 283 |
do |
349 | 284 |
{ |
350 |
//android.util.Log.d("CUBES", "checking edge "+debug(e1)); |
|
351 |
|
|
352 | 285 |
mSideWalls++; |
353 | 286 |
|
354 | 287 |
if( e1.side==NORTH || e1.side==SOUTH ) |
... | ... | |
362 | 295 |
mEdges.remove(j); |
363 | 296 |
mEdgeNum--; |
364 | 297 |
j--; |
365 |
|
|
366 |
//android.util.Log.e("CUBES", "removing edge "+debug(e2)); |
|
367 | 298 |
} |
368 | 299 |
} |
369 | 300 |
} |
... | ... | |
456 | 387 |
if( lr>0 ) lr= 1; |
457 | 388 |
mNormalX[3] = lr*R; |
458 | 389 |
mNormalY[3] = td*R; |
459 |
/* |
|
460 |
android.util.Log.d("CUBES", "row="+row+" col="+col); |
|
461 |
android.util.Log.d("CUBES", mNormalX[0]+" "+mNormalY[0]); |
|
462 |
android.util.Log.d("CUBES", mNormalX[1]+" "+mNormalY[1]); |
|
463 |
android.util.Log.d("CUBES", mNormalX[2]+" "+mNormalY[2]); |
|
464 |
android.util.Log.d("CUBES", mNormalX[3]+" "+mNormalY[3]); |
|
465 |
*/ |
|
466 | 390 |
} |
467 | 391 |
|
468 | 392 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
475 | 399 |
boolean currentBlockIsNE; |
476 | 400 |
float vectZ = (front ? 0.5f : -0.5f); |
477 | 401 |
|
478 |
//android.util.Log.d("CUBES", "buildFrontBack"); |
|
479 |
|
|
480 | 402 |
for(int row=0; row<mRows; row++) |
481 | 403 |
{ |
482 | 404 |
last =0; |
... | ... | |
491 | 413 |
|
492 | 414 |
if( !seenLand && !front && ((currVert%2==1)^currentBlockIsNE) ) |
493 | 415 |
{ |
494 |
//android.util.Log.d("CUBES","repeating winding2 vertex"); |
|
495 |
|
|
496 | 416 |
repeatLast(attribs); |
497 | 417 |
} |
498 | 418 |
|
... | ... | |
538 | 458 |
|
539 | 459 |
private void buildSideGrid(float[] attribs) |
540 | 460 |
{ |
541 |
//android.util.Log.d("CUBES", "buildSide"); |
|
542 |
|
|
543 | 461 |
for(int i=0; i<mEdgeNum; i++) |
544 | 462 |
{ |
545 | 463 |
buildIthSide(mEdges.get(i), attribs); |
... | ... | |
599 | 517 |
{ |
600 | 518 |
int col = curr.col; |
601 | 519 |
int row = curr.row; |
602 |
|
|
603 |
//android.util.Log.e("CUBES", "row="+row+" col="+col+" mRows="+mRows+" mCols="+mCols); |
|
604 |
|
|
520 |
|
|
605 | 521 |
switch(curr.side) |
606 | 522 |
{ |
607 | 523 |
case NORTH: if( col==mCols-1 ) |
... | ... | |
695 | 611 |
|
696 | 612 |
mInflateY[row][col] = (byte)diff; |
697 | 613 |
} |
698 |
|
|
699 |
//android.util.Log.e("mesh","col="+col+" row="+row+" inflateX="+mInflateX[col][row]+" InflateY="+mInflateY[col][row]); |
|
700 | 614 |
} |
701 | 615 |
|
702 | 616 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
736 | 650 |
|
737 | 651 |
private void addSideVertex(Edge curr, boolean back, int slice, int side, float[] attribs) |
738 | 652 |
{ |
739 |
//android.util.Log.e("CUBES", "adding Side vertex!"); |
|
740 | 653 |
float x, y, z; |
741 | 654 |
int row, col; |
742 | 655 |
|
... | ... | |
839 | 752 |
|
840 | 753 |
private void repeatLast(float[] attribs) |
841 | 754 |
{ |
842 |
//android.util.Log.e("CUBES", "repeating last vertex!"); |
|
843 |
|
|
844 | 755 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB ] = attribs[VERT_ATTRIBS*(currVert-1) + POS_ATTRIB ]; |
845 | 756 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = attribs[VERT_ATTRIBS*(currVert-1) + POS_ATTRIB+1]; |
846 | 757 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = attribs[VERT_ATTRIBS*(currVert-1) + POS_ATTRIB+2]; |
... | ... | |
916 | 827 |
*/ |
917 | 828 |
public MeshCubes(int cols, String desc, int slices) |
918 | 829 |
{ |
919 |
super( (float)slices/cols); |
|
920 |
|
|
921 | 830 |
Static4D map = new Static4D(0.0f,0.0f,1.0f,1.0f); |
922 | 831 |
fillTexMappings(map,map,map,map,map,map); |
923 | 832 |
prepareDataStructures(cols,desc,slices); |
... | ... | |
963 | 872 |
*/ |
964 | 873 |
public MeshCubes(int cols, String desc, int slices, Static4D front, Static4D back, Static4D left, Static4D right, Static4D top, Static4D bottom) |
965 | 874 |
{ |
966 |
super( (float)slices/cols); |
|
967 | 875 |
fillTexMappings(front,back,left,right,top,bottom); |
968 | 876 |
prepareDataStructures(cols,desc,slices); |
969 | 877 |
build(); |
... | ... | |
979 | 887 |
*/ |
980 | 888 |
public MeshCubes(int cols, int rows, int slices) |
981 | 889 |
{ |
982 |
super( (float)slices/cols); |
|
983 |
|
|
984 | 890 |
Static4D map = new Static4D(0.0f,0.0f,1.0f,1.0f); |
985 | 891 |
fillTexMappings(map,map,map,map,map,map); |
986 | 892 |
prepareDataStructures(cols,rows,slices); |
... | ... | |
1010 | 916 |
*/ |
1011 | 917 |
public MeshCubes(int cols, int rows, int slices, Static4D front, Static4D back, Static4D left, Static4D right, Static4D top, Static4D bottom) |
1012 | 918 |
{ |
1013 |
super( (float)slices/cols); |
|
1014 | 919 |
fillTexMappings(front,back,left,right,top,bottom); |
1015 | 920 |
prepareDataStructures(cols,rows,slices); |
1016 | 921 |
build(); |
src/main/java/org/distorted/library/mesh/MeshQuad.java | ||
---|---|---|
56 | 56 |
*/ |
57 | 57 |
public MeshQuad() |
58 | 58 |
{ |
59 |
super(0.0f); |
|
60 |
|
|
61 | 59 |
float[] attribs= new float[VERT_ATTRIBS*4]; |
62 | 60 |
|
63 | 61 |
addVertex(0.0f,0.0f, attribs,0); |
src/main/java/org/distorted/library/mesh/MeshRectangles.java | ||
---|---|---|
50 | 50 |
(mCols>=2 && mRows>=2 ? 2*mRows-2 : 1); |
51 | 51 |
} |
52 | 52 |
|
53 |
//android.util.Log.e("MeshRectangles","vertices="+numVertices+" rows="+mRows+" cols="+mCols); |
|
54 |
|
|
55 | 53 |
remainingVert = numVertices; |
56 | 54 |
} |
57 | 55 |
|
... | ... | |
83 | 81 |
|
84 | 82 |
private int repeatLast(int vertex, float[] attribs) |
85 | 83 |
{ |
86 |
//android.util.Log.e("MeshRectangles", "repeating last vertex!"); |
|
87 |
|
|
88 | 84 |
if( vertex>0 ) |
89 | 85 |
{ |
90 | 86 |
remainingVert--; |
... | ... | |
122 | 118 |
final float X = 1.0f/mCols; |
123 | 119 |
final float Y = 1.0f/mRows; |
124 | 120 |
|
125 |
//android.util.Log.d("MeshRectangles", "buildGrid"); |
|
126 |
|
|
127 | 121 |
y = 0.0f; |
128 | 122 |
|
129 | 123 |
for(int row=0; row<mRows; row++) |
... | ... | |
151 | 145 |
|
152 | 146 |
y+=Y; |
153 | 147 |
} |
154 |
|
|
155 |
//android.util.Log.d("MeshRectangles", "buildGrid done"); |
|
156 | 148 |
} |
157 | 149 |
|
158 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
159 |
/* |
|
160 |
private static String debug(float[] val, int stop) |
|
161 |
{ |
|
162 |
String ret=""; |
|
163 |
|
|
164 |
for(int i=0; i<val.length; i++) |
|
165 |
{ |
|
166 |
if( i%stop==0 ) ret+="\n"; |
|
167 |
ret+=(" "+val[i]); |
|
168 |
} |
|
169 |
|
|
170 |
return ret; |
|
171 |
} |
|
172 |
*/ |
|
173 |
|
|
174 | 150 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
175 | 151 |
// PUBLIC API |
176 | 152 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
182 | 158 |
*/ |
183 | 159 |
public MeshRectangles(int cols, int rows) |
184 | 160 |
{ |
185 |
super(0.0f); |
|
186 | 161 |
computeNumberOfVertices(cols,rows); |
187 | 162 |
|
188 | 163 |
float[] attribs= new float[VERT_ATTRIBS*numVertices]; |
189 | 164 |
|
190 | 165 |
buildGrid(attribs); |
191 | 166 |
|
192 |
//android.util.Log.e("MeshRectangles", "dataLen="+numVertices); |
|
193 |
//android.util.Log.d("MeshRectangles", "attribs: "+debug(attribs,VERT_ATTRIBS) ); |
|
194 |
|
|
195 | 167 |
if( remainingVert!=0 ) |
196 | 168 |
android.util.Log.d("MeshRectangles", "remainingVert " +remainingVert ); |
197 | 169 |
|
src/main/java/org/distorted/library/mesh/MeshSphere.java | ||
---|---|---|
38 | 38 |
// Single row is (longitude of V1, longitude of V2, (common) latitude of V1 and V2, latitude of V3) |
39 | 39 |
// longitude of V3 is simply midpoint of V1 and V2 so we don't have to specify it here. |
40 | 40 |
|
41 |
private static final double FACES[][] = {
|
|
41 |
private static final double[][] FACES = {
|
|
42 | 42 |
|
43 | 43 |
{ 0.00*P, 0.25*P, 0.0, 0.5*P }, |
44 | 44 |
{ 0.25*P, 0.50*P, 0.0, 0.5*P }, |
... | ... | |
79 | 79 |
|
80 | 80 |
private void repeatVertex(float[] attribs) |
81 | 81 |
{ |
82 |
//android.util.Log.e("sphere", "repeat last!"); |
|
83 |
|
|
84 | 82 |
if( currentVert>0 ) |
85 | 83 |
{ |
86 | 84 |
attribs[VERT_ATTRIBS*currentVert + POS_ATTRIB ] = attribs[VERT_ATTRIBS*(currentVert-1) + POS_ATTRIB ]; |
... | ... | |
172 | 170 |
double longitude = midLongitude(lonV1, lonV2, quotZ ); |
173 | 171 |
double latitude = midLatitude(latV12, latV3, quotY ); |
174 | 172 |
|
175 |
//android.util.Log.e("sphere", "newVertex: long:"+lonPoint+" lat:"+latPoint+" column="+column+" row="+row); |
|
176 |
|
|
177 | 173 |
double sinLON = Math.sin(longitude); |
178 | 174 |
double cosLON = Math.cos(longitude); |
179 | 175 |
double sinLAT = Math.sin(latitude); |
... | ... | |
186 | 182 |
double texX = 0.5 + longitude/(2*P); |
187 | 183 |
if( texX>=1.0 ) texX-=1.0; |
188 | 184 |
|
189 |
//android.util.Log.e("tex", "longitude = "+((int)(180.0*longitude/P))+" texX="+texX ); |
|
190 |
|
|
191 | 185 |
double texY = 0.5 + latitude/P; |
192 | 186 |
|
193 | 187 |
attribs[VERT_ATTRIBS*currentVert + POS_ATTRIB ] = x; // |
... | ... | |
197 | 191 |
attribs[VERT_ATTRIBS*currentVert + NOR_ATTRIB ] = 2*x;// the vertex coords, normal vector, and |
198 | 192 |
attribs[VERT_ATTRIBS*currentVert + NOR_ATTRIB+1] = 2*y;// inflate vector have identical (x,y,z). |
199 | 193 |
attribs[VERT_ATTRIBS*currentVert + NOR_ATTRIB+2] = 2*z;// |
200 |
// TODO: think dialog_about some more efficient
|
|
194 |
// TODO: think about some more efficient |
|
201 | 195 |
attribs[VERT_ATTRIBS*currentVert + INF_ATTRIB ] = x; // representation. |
202 | 196 |
attribs[VERT_ATTRIBS*currentVert + INF_ATTRIB+1] = y; // |
203 | 197 |
attribs[VERT_ATTRIBS*currentVert + INF_ATTRIB+2] = z; // |
... | ... | |
259 | 253 |
*/ |
260 | 254 |
public MeshSphere(int level) |
261 | 255 |
{ |
262 |
super(1.0f); |
|
263 |
|
|
264 | 256 |
computeNumberOfVertices(level); |
265 | 257 |
float[] attribs= new float[VERT_ATTRIBS*numVertices]; |
266 | 258 |
|
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)