Revision e54bfada
Added by Leszek Koltunski over 5 years ago
| src/main/java/org/distorted/library/effect/VertexEffectQuaternion.java | ||
|---|---|---|
| 78 | 78 |
|
| 79 | 79 |
+ "n.x = qw*nx + qz*ny - qy*nz - qx*nw; \n" |
| 80 | 80 |
+ "n.y = qw*ny - qz*nx - qy*nw + qx*nz; \n" |
| 81 |
+ "n.z = qw*nz - qz*nw + qy*nx - qx*ny; \n"; |
|
| 81 |
+ "n.z = qw*nz - qz*nw + qy*nx - qx*ny; \n" |
|
| 82 |
|
|
| 83 |
+ "#ifdef PREAPPLY \n" |
|
| 84 |
|
|
| 85 |
+ "float ix = - inf.z*qy + inf.y*qz + inf.x*qw; \n" |
|
| 86 |
+ "float iy = + inf.z*qx + inf.y*qw - inf.x*qz; \n" |
|
| 87 |
+ "float iz = + inf.z*qw - inf.y*qx + inf.x*qy; \n" |
|
| 88 |
+ "float iw = - inf.z*qz - inf.y*qy - inf.x*qx; \n" |
|
| 89 |
|
|
| 90 |
+ "inf.x = qw*ix + qz*iy - qy*iz - qx*iw; \n" |
|
| 91 |
+ "inf.y = qw*iy - qz*ix - qy*iw + qx*iz; \n" |
|
| 92 |
+ "inf.z = qw*iz - qz*iw + qy*ix - qx*iy; \n" |
|
| 93 |
|
|
| 94 |
+ "#endif \n"; |
|
| 82 | 95 |
} |
| 83 | 96 |
|
| 84 | 97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/library/effect/VertexEffectRotate.java | ||
|---|---|---|
| 95 | 95 |
|
| 96 | 96 |
+ "n.x = qw*nx + qz*ny - qy*nz - qx*nw; \n" |
| 97 | 97 |
+ "n.y = qw*ny - qz*nx - qy*nw + qx*nz; \n" |
| 98 |
+ "n.z = qw*nz - qz*nw + qy*nx - qx*ny; \n"; |
|
| 98 |
+ "n.z = qw*nz - qz*nw + qy*nx - qx*ny; \n" |
|
| 99 |
|
|
| 100 |
+ "#ifdef PREAPPLY \n" |
|
| 101 |
|
|
| 102 |
+ "float ix = - inf.z*qy + inf.y*qz + inf.x*qw; \n" |
|
| 103 |
+ "float iy = + inf.z*qx + inf.y*qw - inf.x*qz; \n" |
|
| 104 |
+ "float iz = + inf.z*qw - inf.y*qx + inf.x*qy; \n" |
|
| 105 |
+ "float iw = - inf.z*qz - inf.y*qy - inf.x*qx; \n" |
|
| 106 |
|
|
| 107 |
+ "inf.x = qw*ix + qz*iy - qy*iz - qx*iw; \n" |
|
| 108 |
+ "inf.y = qw*iy - qz*ix - qy*iw + qx*iz; \n" |
|
| 109 |
+ "inf.z = qw*iz - qz*iw + qy*ix - qx*iy; \n" |
|
| 110 |
|
|
| 111 |
+ "#endif \n"; |
|
| 99 | 112 |
} |
| 100 | 113 |
|
| 101 | 114 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/library/effect/VertexEffectShear.java | ||
|---|---|---|
| 73 | 73 |
|
| 74 | 74 |
+ "n.x = new_nx; \n" |
| 75 | 75 |
+ "n.y = new_ny; \n" |
| 76 |
+ "n.z = new_nz; \n"; |
|
| 76 |
+ "n.z = new_nz; \n" |
|
| 77 |
|
|
| 78 |
+ "#ifdef PREAPPLY \n" |
|
| 79 |
|
|
| 80 |
+ "float new_ix = (1.0+sx*sy)*inf.x + sx*inf.y; \n" |
|
| 81 |
+ "float new_iy = sy*inf.x + inf.y; \n" |
|
| 82 |
+ "float new_iz = sz*inf.y + inf.z; \n" |
|
| 83 |
|
|
| 84 |
+ "inf.x = new_ix; \n" |
|
| 85 |
+ "inf.y = new_iy; \n" |
|
| 86 |
+ "inf.z = new_iz; \n" |
|
| 87 |
|
|
| 88 |
+ "#endif \n"; |
|
| 77 | 89 |
} |
| 78 | 90 |
|
| 79 | 91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/library/main/DistortedLibrary.java | ||
|---|---|---|
| 307 | 307 |
|
| 308 | 308 |
fullVertHeader += "#define PREAPPLY\n"; |
| 309 | 309 |
|
| 310 |
String[] feedback = { "v_Position", "v_endPosition" };
|
|
| 310 |
String[] feedback = { "v_Position", "v_endPosition", "v_Inflate" };
|
|
| 311 | 311 |
|
| 312 | 312 |
try |
| 313 | 313 |
{
|
| src/main/java/org/distorted/library/mesh/MeshBase.java | ||
|---|---|---|
| 52 | 52 |
static final int POS_ATTRIB = 0; |
| 53 | 53 |
static final int NOR_ATTRIB = POS_DATA_SIZE; |
| 54 | 54 |
static final int INF_ATTRIB = POS_DATA_SIZE + NOR_DATA_SIZE; |
| 55 |
static final int TEX_ATTRIB = POS_DATA_SIZE + NOR_DATA_SIZE + INF_DATA_SIZE; |
|
| 56 |
static final int VERT_ATTRIBS = POS_DATA_SIZE + NOR_DATA_SIZE + INF_DATA_SIZE + TEX_DATA_SIZE; // number of attributes of a 'normal' vertex |
|
| 57 |
static final int TRAN_ATTRIBS = POS_DATA_SIZE + POS_DATA_SIZE; // number of attributes of a transform feedback vertex |
|
| 55 |
static final int TEX_ATTRIB = 0; |
|
| 56 |
static final int VERT1_ATTRIBS= POS_DATA_SIZE + NOR_DATA_SIZE + INF_DATA_SIZE; // number of attributes of a vertex (the part changed by preapply) |
|
| 57 |
static final int VERT2_ATTRIBS= TEX_DATA_SIZE; // number of attributes of a vertex (the 'preapply invariant' part) |
|
| 58 |
static final int TRAN_ATTRIBS = POS_DATA_SIZE + NOR_DATA_SIZE + INF_DATA_SIZE; // number of attributes of a transform feedback vertex |
|
| 58 | 59 |
|
| 59 | 60 |
private static final int BYTES_PER_FLOAT = 4; |
| 60 | 61 |
|
| ... | ... | |
| 63 | 64 |
private static final int OFFSET_INF = INF_ATTRIB*BYTES_PER_FLOAT; |
| 64 | 65 |
private static final int OFFSET_TEX = TEX_ATTRIB*BYTES_PER_FLOAT; |
| 65 | 66 |
private static final int TRAN_SIZE = TRAN_ATTRIBS*BYTES_PER_FLOAT; |
| 66 |
private static final int VERT_SIZE = VERT_ATTRIBS*BYTES_PER_FLOAT; |
|
| 67 |
private static final int VERT1_SIZE = VERT1_ATTRIBS*BYTES_PER_FLOAT; |
|
| 68 |
private static final int VERT2_SIZE = VERT2_ATTRIBS*BYTES_PER_FLOAT; |
|
| 67 | 69 |
|
| 68 |
private boolean mShowNormals; // when rendering this mesh, draw normal vectors? |
|
| 69 |
private InternalBuffer mVBO, mTFO; // main vertex buffer and transform feedback buffer |
|
| 70 |
private boolean mShowNormals; // when rendering this mesh, draw normal vectors?
|
|
| 71 |
private InternalBuffer mVBO1, mVBO2, mTFO; // main vertex buffer and transform feedback buffer
|
|
| 70 | 72 |
private int mNumVertices; |
| 71 |
private float[] mVertAttribs; // packed: PosX,PosY,PosZ, NorX,NorY,NorZ, InfX,InfY,InfZ, TexS,TexT |
|
| 73 |
private float[] mVertAttribs1; // packed: PosX,PosY,PosZ, NorX,NorY,NorZ, InfX,InfY,InfZ |
|
| 74 |
private float[] mVertAttribs2; // packed: TexS,TexT |
|
| 72 | 75 |
private float mInflate; |
| 73 | 76 |
private boolean mNeedsAdjustment; |
| 74 | 77 |
|
| ... | ... | |
| 113 | 116 |
mNeedsAdjustment = false; |
| 114 | 117 |
mComponent = new ArrayList<>(); |
| 115 | 118 |
|
| 116 |
mVBO = new InternalBuffer(GLES30.GL_ARRAY_BUFFER , GLES30.GL_STATIC_READ); |
|
| 119 |
mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER , GLES30.GL_STATIC_READ); |
|
| 120 |
mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER , GLES30.GL_STATIC_READ); |
|
| 117 | 121 |
mTFO = new InternalBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, GLES30.GL_STATIC_READ); |
| 118 | 122 |
} |
| 119 | 123 |
|
| ... | ... | |
| 134 | 138 |
mComponent.add(comp); |
| 135 | 139 |
} |
| 136 | 140 |
|
| 137 |
mVBO = new InternalBuffer(GLES30.GL_ARRAY_BUFFER , GLES30.GL_STATIC_READ); |
|
| 141 |
mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER , GLES30.GL_STATIC_READ); |
|
| 142 |
mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER , GLES30.GL_STATIC_READ); |
|
| 138 | 143 |
mTFO = new InternalBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, GLES30.GL_STATIC_READ); |
| 139 | 144 |
|
| 140 | 145 |
mNumVertices = original.mNumVertices; |
| 141 |
mVertAttribs = new float[mNumVertices*VERT_ATTRIBS];
|
|
| 142 |
System.arraycopy(original.mVertAttribs,0,mVertAttribs,0,mNumVertices*VERT_ATTRIBS);
|
|
| 146 |
mVertAttribs1= new float[mNumVertices*VERT1_ATTRIBS];
|
|
| 147 |
mVertAttribs2= new float[mNumVertices*VERT2_ATTRIBS];
|
|
| 143 | 148 |
|
| 144 |
mVBO.invalidate(); |
|
| 149 |
System.arraycopy(original.mVertAttribs1,0,mVertAttribs1,0,mNumVertices*VERT1_ATTRIBS); |
|
| 150 |
System.arraycopy(original.mVertAttribs2,0,mVertAttribs2,0,mNumVertices*VERT2_ATTRIBS); |
|
| 151 |
|
|
| 152 |
mVBO1.invalidate(); |
|
| 153 |
mVBO2.invalidate(); |
|
| 145 | 154 |
mTFO.invalidate(); |
| 146 | 155 |
} |
| 147 | 156 |
|
| ... | ... | |
| 155 | 164 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 156 | 165 |
// when a derived class is done computing its mesh, it has to call this method. |
| 157 | 166 |
|
| 158 |
void setAttribs(float[] vertexAttribs)
|
|
| 167 |
void setAttribs(float[] vert1Attribs, float[] vert2Attribs)
|
|
| 159 | 168 |
{
|
| 160 |
mNumVertices = vertexAttribs.length/VERT_ATTRIBS; |
|
| 161 |
mVertAttribs = vertexAttribs; |
|
| 169 |
mNumVertices = vert1Attribs.length/VERT1_ATTRIBS; |
|
| 170 |
mVertAttribs1= vert1Attribs; |
|
| 171 |
mVertAttribs2= vert2Attribs; |
|
| 162 | 172 |
|
| 163 | 173 |
mComponent.add(new Component(mNumVertices)); |
| 164 | 174 |
|
| 165 |
mVBO.invalidate(); |
|
| 166 |
mTFO.invalidate();
|
|
| 175 |
mVBO1.invalidate();
|
|
| 176 |
mVBO2.invalidate();
|
|
| 167 | 177 |
} |
| 168 | 178 |
|
| 169 | 179 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 211 | 221 |
} |
| 212 | 222 |
|
| 213 | 223 |
// allocate new attrib array |
| 214 |
float[] newAttribs = new float[VERT_ATTRIBS*mNumVertices]; |
|
| 224 |
float[] newAttribs1 = new float[VERT1_ATTRIBS*mNumVertices]; |
|
| 225 |
float[] newAttribs2 = new float[VERT2_ATTRIBS*mNumVertices]; |
|
| 215 | 226 |
numVertices = origVertices; |
| 216 | 227 |
|
| 217 | 228 |
if( origVertices>0 ) |
| 218 | 229 |
{
|
| 219 |
System.arraycopy(mVertAttribs, 0, newAttribs, 0, VERT_ATTRIBS*numVertices); |
|
| 220 |
System.arraycopy(mVertAttribs, VERT_ATTRIBS*(origVertices-1), newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS ); |
|
| 230 |
System.arraycopy(mVertAttribs1, 0, newAttribs1, 0, VERT1_ATTRIBS*numVertices); |
|
| 231 |
System.arraycopy(mVertAttribs2, 0, newAttribs2, 0, VERT2_ATTRIBS*numVertices); |
|
| 232 |
System.arraycopy(mVertAttribs1, VERT1_ATTRIBS*(origVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS ); |
|
| 233 |
System.arraycopy(mVertAttribs2, VERT2_ATTRIBS*(origVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS ); |
|
| 221 | 234 |
origVertices++; |
| 222 | 235 |
|
| 223 | 236 |
if( numVertices%2==1 ) |
| 224 | 237 |
{
|
| 225 |
System.arraycopy(mVertAttribs, VERT_ATTRIBS*(origVertices-1), newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS); |
|
| 238 |
System.arraycopy(mVertAttribs1, VERT1_ATTRIBS*(origVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS); |
|
| 239 |
System.arraycopy(mVertAttribs2, VERT2_ATTRIBS*(origVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS); |
|
| 226 | 240 |
origVertices++; |
| 227 | 241 |
} |
| 228 | 242 |
} |
| ... | ... | |
| 234 | 248 |
|
| 235 | 249 |
if( origVertices>0 ) |
| 236 | 250 |
{
|
| 237 |
System.arraycopy(mesh.mVertAttribs, 0, newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS ); |
|
| 251 |
System.arraycopy(mesh.mVertAttribs1, 0, newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS ); |
|
| 252 |
System.arraycopy(mesh.mVertAttribs2, 0, newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS ); |
|
| 238 | 253 |
origVertices++; |
| 239 | 254 |
} |
| 240 |
System.arraycopy(mesh.mVertAttribs, 0, newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS*numVertices); |
|
| 255 |
System.arraycopy(mesh.mVertAttribs1, 0, newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS*numVertices); |
|
| 256 |
System.arraycopy(mesh.mVertAttribs2, 0, newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS*numVertices); |
|
| 241 | 257 |
origVertices+=numVertices; |
| 242 | 258 |
|
| 243 | 259 |
if( i<numMeshes-1 ) |
| 244 | 260 |
{
|
| 245 |
System.arraycopy(mesh.mVertAttribs, VERT_ATTRIBS*(numVertices-1), newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS); |
|
| 261 |
System.arraycopy(mesh.mVertAttribs1, VERT1_ATTRIBS*(numVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS); |
|
| 262 |
System.arraycopy(mesh.mVertAttribs2, VERT2_ATTRIBS*(numVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS); |
|
| 246 | 263 |
origVertices++; |
| 247 | 264 |
|
| 248 | 265 |
if( numVertices%2==1 ) |
| 249 | 266 |
{
|
| 250 |
System.arraycopy(mesh.mVertAttribs, VERT_ATTRIBS*(numVertices-1), newAttribs, VERT_ATTRIBS*origVertices, VERT_ATTRIBS); |
|
| 267 |
System.arraycopy(mesh.mVertAttribs1, VERT1_ATTRIBS*(numVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS); |
|
| 268 |
System.arraycopy(mesh.mVertAttribs2, VERT2_ATTRIBS*(numVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS); |
|
| 251 | 269 |
origVertices++; |
| 252 | 270 |
} |
| 253 | 271 |
} |
| ... | ... | |
| 258 | 276 |
android.util.Log.e("mesh", "join: origVertices: "+origVertices+" numVertices: "+mNumVertices);
|
| 259 | 277 |
} |
| 260 | 278 |
|
| 261 |
mVertAttribs = newAttribs; |
|
| 279 |
mVertAttribs1 = newAttribs1; |
|
| 280 |
mVertAttribs2 = newAttribs2; |
|
| 262 | 281 |
|
| 263 |
mVBO.invalidate(); |
|
| 282 |
mVBO1.invalidate(); |
|
| 283 |
mVBO2.invalidate(); |
|
| 264 | 284 |
} |
| 265 | 285 |
|
| 266 | 286 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 271 | 291 |
*/ |
| 272 | 292 |
public void copyTransformToVertex() |
| 273 | 293 |
{
|
| 274 |
float posX, posY, posZ, norX, norY, norZ; |
|
| 275 |
FloatBuffer feedback=null; |
|
| 276 |
|
|
| 277 |
ByteBuffer buffer = (ByteBuffer)GLES30.glMapBufferRange( GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, TRAN_SIZE*mNumVertices, |
|
| 278 |
GLES30.GL_MAP_READ_BIT); |
|
| 294 |
ByteBuffer buffer = (ByteBuffer)GLES30.glMapBufferRange( GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, |
|
| 295 |
TRAN_SIZE*mNumVertices, GLES30.GL_MAP_READ_BIT); |
|
| 279 | 296 |
if( buffer!=null ) |
| 280 | 297 |
{
|
| 281 |
feedback = buffer.order(ByteOrder.nativeOrder()).asFloatBuffer(); |
|
| 298 |
FloatBuffer feedback = buffer.order(ByteOrder.nativeOrder()).asFloatBuffer(); |
|
| 299 |
feedback.get(mVertAttribs1,0,VERT1_ATTRIBS*mNumVertices); |
|
| 300 |
mVBO1.update(mVertAttribs1); |
|
| 282 | 301 |
} |
| 283 | 302 |
else |
| 284 | 303 |
{
|
| ... | ... | |
| 286 | 305 |
Log.e("mesh", "failed to map tf buffer, error="+error);
|
| 287 | 306 |
} |
| 288 | 307 |
|
| 289 |
if( feedback!=null ) |
|
| 290 |
{
|
|
| 291 |
for(int vertex=0; vertex<mNumVertices; vertex++) |
|
| 292 |
{
|
|
| 293 |
mVertAttribs[vertex*VERT_ATTRIBS + POS_ATTRIB ] = feedback.get(6*vertex ); |
|
| 294 |
mVertAttribs[vertex*VERT_ATTRIBS + POS_ATTRIB + 1 ] = feedback.get(6*vertex+1); |
|
| 295 |
mVertAttribs[vertex*VERT_ATTRIBS + POS_ATTRIB + 2 ] = feedback.get(6*vertex+2); |
|
| 296 |
mVertAttribs[vertex*VERT_ATTRIBS + NOR_ATTRIB ] = feedback.get(6*vertex+3); |
|
| 297 |
mVertAttribs[vertex*VERT_ATTRIBS + NOR_ATTRIB + 1 ] = feedback.get(6*vertex+4); |
|
| 298 |
mVertAttribs[vertex*VERT_ATTRIBS + NOR_ATTRIB + 2 ] = feedback.get(6*vertex+5); |
|
| 299 |
} |
|
| 300 |
|
|
| 301 |
mVBO.update(mVertAttribs); |
|
| 302 |
} |
|
| 303 |
|
|
| 304 | 308 |
GLES30.glUnmapBuffer(GLES30.GL_TRANSFORM_FEEDBACK); |
| 305 | 309 |
|
| 306 | 310 |
int numComp = mComponent.size(); |
| ... | ... | |
| 379 | 383 |
DistortedLibrary.adjustVertices(this); |
| 380 | 384 |
} |
| 381 | 385 |
|
| 382 |
int index = mVBO.createImmediately(mNumVertices*VERT_SIZE, mVertAttribs); |
|
| 386 |
int index1 = mVBO1.createImmediately(mNumVertices*VERT1_SIZE, mVertAttribs1); |
|
| 387 |
int index2 = mVBO2.createImmediately(mNumVertices*VERT2_SIZE, mVertAttribs2); |
|
| 383 | 388 |
|
| 384 |
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index ); |
|
| 385 |
GLES30.glVertexAttribPointer(program.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, VERT_SIZE, OFFSET_POS); |
|
| 386 |
GLES30.glVertexAttribPointer(program.mAttribute[1], NOR_DATA_SIZE, GLES30.GL_FLOAT, false, VERT_SIZE, OFFSET_NOR); |
|
| 387 |
GLES30.glVertexAttribPointer(program.mAttribute[2], INF_DATA_SIZE, GLES30.GL_FLOAT, false, VERT_SIZE, OFFSET_INF); |
|
| 388 |
GLES30.glVertexAttribPointer(program.mAttribute[3], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, VERT_SIZE, OFFSET_TEX); |
|
| 389 |
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index1 ); |
|
| 390 |
GLES30.glVertexAttribPointer(program.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, VERT1_SIZE, OFFSET_POS); |
|
| 391 |
GLES30.glVertexAttribPointer(program.mAttribute[1], NOR_DATA_SIZE, GLES30.GL_FLOAT, false, VERT1_SIZE, OFFSET_NOR); |
|
| 392 |
GLES30.glVertexAttribPointer(program.mAttribute[2], INF_DATA_SIZE, GLES30.GL_FLOAT, false, VERT1_SIZE, OFFSET_INF); |
|
| 393 |
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index2 ); |
|
| 394 |
GLES30.glVertexAttribPointer(program.mAttribute[3], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, VERT2_SIZE, OFFSET_TEX); |
|
| 389 | 395 |
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0); |
| 390 | 396 |
} |
| 391 | 397 |
|
| ... | ... | |
| 458 | 464 |
*/ |
| 459 | 465 |
public void markForDeletion() |
| 460 | 466 |
{
|
| 461 |
mVertAttribs = null; |
|
| 467 |
mVertAttribs1 = null; |
|
| 468 |
mVertAttribs2 = null; |
|
| 462 | 469 |
|
| 463 |
mVBO.markForDeletion(); |
|
| 470 |
mVBO1.markForDeletion(); |
|
| 471 |
mVBO2.markForDeletion(); |
|
| 464 | 472 |
mTFO.markForDeletion(); |
| 465 | 473 |
} |
| 466 | 474 |
|
| ... | ... | |
| 538 | 546 |
movX = newMap.get0() - ratW*oldMap.get0(); |
| 539 | 547 |
movY = newMap.get1() - ratH*oldMap.get1(); |
| 540 | 548 |
|
| 541 |
for( int index=vertex*VERT_ATTRIBS+TEX_ATTRIB ; vertex<=comp.mEndIndex; vertex++, index+=VERT_ATTRIBS)
|
|
| 549 |
for( int index=vertex*VERT2_ATTRIBS+TEX_ATTRIB ; vertex<=comp.mEndIndex; vertex++, index+=VERT2_ATTRIBS)
|
|
| 542 | 550 |
{
|
| 543 |
mVertAttribs[index ] = ratW*mVertAttribs[index ] + movX;
|
|
| 544 |
mVertAttribs[index+1] = ratH*mVertAttribs[index+1] + movY;
|
|
| 551 |
mVertAttribs2[index ] = ratW*mVertAttribs2[index ] + movX;
|
|
| 552 |
mVertAttribs2[index+1] = ratH*mVertAttribs2[index+1] + movY;
|
|
| 545 | 553 |
} |
| 546 | 554 |
comp.setMap(newMap); |
| 547 | 555 |
} |
| ... | ... | |
| 550 | 558 |
vertex= comp.mEndIndex+1; |
| 551 | 559 |
} |
| 552 | 560 |
|
| 553 |
mVBO.invalidate(); |
|
| 561 |
mVBO2.invalidate();
|
|
| 554 | 562 |
} |
| 555 | 563 |
|
| 556 | 564 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/library/mesh/MeshCubes.java | ||
|---|---|---|
| 391 | 391 |
|
| 392 | 392 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 393 | 393 |
|
| 394 |
private void buildFrontBackGrid(boolean front, float[] attribs) |
|
| 394 |
private void buildFrontBackGrid(boolean front, float[] attribs1, float[] attribs2)
|
|
| 395 | 395 |
{
|
| 396 | 396 |
int last, current; |
| 397 | 397 |
boolean seenLand=false; |
| ... | ... | |
| 413 | 413 |
|
| 414 | 414 |
if( !seenLand && !front && ((currVert%2==1)^currentBlockIsNE) ) |
| 415 | 415 |
{
|
| 416 |
repeatLast(attribs); |
|
| 416 |
repeatLast(attribs1,attribs2);
|
|
| 417 | 417 |
} |
| 418 | 418 |
|
| 419 | 419 |
createNormals(front,row,col); |
| ... | ... | |
| 422 | 422 |
{
|
| 423 | 423 |
if( (last!=current) || !lastBlockIsNE ) |
| 424 | 424 |
{
|
| 425 |
if( seenLand && (last != current) ) repeatLast(attribs); |
|
| 426 |
addFrontVertex( 0, vectZ, col, row, attribs); |
|
| 427 |
if( seenLand && (last != current) ) repeatLast(attribs); |
|
| 428 |
if( !lastBlockIsNE || (!front && !seenLand) ) repeatLast(attribs); |
|
| 429 |
addFrontVertex( 1, vectZ, col, row+1, attribs); |
|
| 425 |
if( seenLand && (last != current) ) repeatLast(attribs1,attribs2);
|
|
| 426 |
addFrontVertex( 0, vectZ, col, row, attribs1,attribs2);
|
|
| 427 |
if( seenLand && (last != current) ) repeatLast(attribs1,attribs2);
|
|
| 428 |
if( !lastBlockIsNE || (!front && !seenLand) ) repeatLast(attribs1,attribs2);
|
|
| 429 |
addFrontVertex( 1, vectZ, col, row+1, attribs1,attribs2);
|
|
| 430 | 430 |
} |
| 431 |
addFrontVertex( 2, vectZ, col+1, row , attribs); |
|
| 432 |
addFrontVertex( 3, vectZ, col+1, row+1, attribs); |
|
| 431 |
addFrontVertex( 2, vectZ, col+1, row , attribs1,attribs2);
|
|
| 432 |
addFrontVertex( 3, vectZ, col+1, row+1, attribs1,attribs2);
|
|
| 433 | 433 |
} |
| 434 | 434 |
else |
| 435 | 435 |
{
|
| 436 | 436 |
if( (last!=current) || lastBlockIsNE ) |
| 437 | 437 |
{
|
| 438 |
if( seenLand && (last != current) ) repeatLast(attribs); |
|
| 439 |
addFrontVertex( 1, vectZ, col, row+1, attribs); |
|
| 440 |
if( seenLand && (last != current) ) repeatLast(attribs); |
|
| 441 |
if( lastBlockIsNE || (!front && !seenLand) ) repeatLast(attribs); |
|
| 442 |
addFrontVertex( 0, vectZ, col, row, attribs); |
|
| 438 |
if( seenLand && (last != current) ) repeatLast(attribs1,attribs2);
|
|
| 439 |
addFrontVertex( 1, vectZ, col, row+1, attribs1,attribs2);
|
|
| 440 |
if( seenLand && (last != current) ) repeatLast(attribs1,attribs2);
|
|
| 441 |
if( lastBlockIsNE || (!front && !seenLand) ) repeatLast(attribs1,attribs2);
|
|
| 442 |
addFrontVertex( 0, vectZ, col, row, attribs1,attribs2);
|
|
| 443 | 443 |
} |
| 444 |
addFrontVertex( 3, vectZ, col+1, row+1, attribs); |
|
| 445 |
addFrontVertex( 2, vectZ, col+1, row , attribs); |
|
| 444 |
addFrontVertex( 3, vectZ, col+1, row+1, attribs1,attribs2);
|
|
| 445 |
addFrontVertex( 2, vectZ, col+1, row , attribs1,attribs2);
|
|
| 446 | 446 |
} |
| 447 | 447 |
|
| 448 | 448 |
seenLand = true; |
| ... | ... | |
| 456 | 456 |
|
| 457 | 457 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 458 | 458 |
|
| 459 |
private void buildSideGrid(float[] attribs) |
|
| 459 |
private void buildSideGrid(float[] attribs1,float[] attribs2)
|
|
| 460 | 460 |
{
|
| 461 | 461 |
for(int i=0; i<mEdgeNum; i++) |
| 462 | 462 |
{
|
| 463 |
buildIthSide(mEdges.get(i), attribs); |
|
| 463 |
buildIthSide(mEdges.get(i), attribs1, attribs2);
|
|
| 464 | 464 |
} |
| 465 | 465 |
} |
| 466 | 466 |
|
| 467 | 467 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 468 | 468 |
|
| 469 |
private void buildIthSide(Edge curr, float[] attribs) |
|
| 469 |
private void buildIthSide(Edge curr, float[] attribs1, float[] attribs2)
|
|
| 470 | 470 |
{
|
| 471 | 471 |
Edge prev, next; |
| 472 | 472 |
int col, row, side; |
| ... | ... | |
| 488 | 488 |
side= curr.side; |
| 489 | 489 |
next = getNextEdge(curr); |
| 490 | 490 |
|
| 491 |
addSideVertex(curr,true,slice+1,prev.side,attribs); |
|
| 491 |
addSideVertex(curr,true,slice+1,prev.side,attribs1,attribs2);
|
|
| 492 | 492 |
|
| 493 | 493 |
do |
| 494 | 494 |
{
|
| 495 | 495 |
if( prev.side!=curr.side ) |
| 496 | 496 |
{
|
| 497 |
addSideVertex(curr,true,slice+1,prev.side,attribs); |
|
| 498 |
addSideVertex(curr,true,slice ,prev.side,attribs); |
|
| 497 |
addSideVertex(curr,true,slice+1,prev.side,attribs1,attribs2);
|
|
| 498 |
addSideVertex(curr,true,slice ,prev.side,attribs1,attribs2);
|
|
| 499 | 499 |
} |
| 500 | 500 |
|
| 501 |
addSideVertex(curr,false,slice+1,next.side,attribs); |
|
| 502 |
addSideVertex(curr,false,slice ,next.side,attribs); |
|
| 501 |
addSideVertex(curr,false,slice+1,next.side,attribs1,attribs2);
|
|
| 502 |
addSideVertex(curr,false,slice ,next.side,attribs1,attribs2);
|
|
| 503 | 503 |
|
| 504 | 504 |
prev = curr; |
| 505 | 505 |
curr = next; |
| ... | ... | |
| 507 | 507 |
} |
| 508 | 508 |
while( curr.col!=col || curr.row!=row || curr.side!=side ); |
| 509 | 509 |
|
| 510 |
repeatLast(attribs); |
|
| 510 |
repeatLast(attribs1,attribs2);
|
|
| 511 | 511 |
} |
| 512 | 512 |
} |
| 513 | 513 |
|
| ... | ... | |
| 615 | 615 |
|
| 616 | 616 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 617 | 617 |
|
| 618 |
private void addFrontVertex(int index, float vectZ, int col, int row, float[] attribs) |
|
| 618 |
private void addFrontVertex(int index, float vectZ, int col, int row, float[] attribs1, float[] attribs2)
|
|
| 619 | 619 |
{
|
| 620 | 620 |
float x = (float)col/mCols; |
| 621 | 621 |
float y = (float)row/mRows; |
| 622 | 622 |
|
| 623 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB ] = x-0.5f;
|
|
| 624 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = 0.5f-y;
|
|
| 625 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = vectZ;
|
|
| 623 |
attribs1[VERT1_ATTRIBS*currVert + POS_ATTRIB ] = x-0.5f;
|
|
| 624 |
attribs1[VERT1_ATTRIBS*currVert + POS_ATTRIB+1] = 0.5f-y;
|
|
| 625 |
attribs1[VERT1_ATTRIBS*currVert + POS_ATTRIB+2] = vectZ;
|
|
| 626 | 626 |
|
| 627 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB ] = mNormalX[index];
|
|
| 628 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = mNormalY[index];
|
|
| 629 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = mNormalZ[index];
|
|
| 627 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB ] = mNormalX[index];
|
|
| 628 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB+1] = mNormalY[index];
|
|
| 629 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB+2] = mNormalZ[index];
|
|
| 630 | 630 |
|
| 631 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB ] = mInflateX[row][col]/2.0f;
|
|
| 632 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f;
|
|
| 633 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = vectZ;
|
|
| 631 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB ] = mInflateX[row][col]/2.0f;
|
|
| 632 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f;
|
|
| 633 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB+2] = vectZ;
|
|
| 634 | 634 |
|
| 635 | 635 |
if( vectZ>0 ) |
| 636 | 636 |
{
|
| 637 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[FRONT] + x * mTexMappingW[FRONT];
|
|
| 638 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[FRONT] + (1.0f-y) * mTexMappingH[FRONT];
|
|
| 637 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[FRONT] + x * mTexMappingW[FRONT];
|
|
| 638 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[FRONT] + (1.0f-y) * mTexMappingH[FRONT];
|
|
| 639 | 639 |
} |
| 640 | 640 |
else |
| 641 | 641 |
{
|
| 642 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[BACK] + x * mTexMappingW[BACK];
|
|
| 643 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[BACK] + (1.0f-y) * mTexMappingH[BACK];
|
|
| 642 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[BACK] + x * mTexMappingW[BACK];
|
|
| 643 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[BACK] + (1.0f-y) * mTexMappingH[BACK];
|
|
| 644 | 644 |
} |
| 645 | 645 |
|
| 646 | 646 |
currVert++; |
| ... | ... | |
| 648 | 648 |
|
| 649 | 649 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 650 | 650 |
|
| 651 |
private void addSideVertex(Edge curr, boolean back, int slice, int side, float[] attribs) |
|
| 651 |
private void addSideVertex(Edge curr, boolean back, int slice, int side, float[] attribs1, float[] attribs2)
|
|
| 652 | 652 |
{
|
| 653 | 653 |
float x, y, z; |
| 654 | 654 |
int row, col; |
| ... | ... | |
| 661 | 661 |
y = 0.5f - (float)row/mRows; |
| 662 | 662 |
z = 0.5f - (float)slice/mSlices; |
| 663 | 663 |
|
| 664 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB ] = x - 0.5f;
|
|
| 665 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = y;
|
|
| 666 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = z;
|
|
| 664 |
attribs1[VERT1_ATTRIBS*currVert + POS_ATTRIB ] = x - 0.5f;
|
|
| 665 |
attribs1[VERT1_ATTRIBS*currVert + POS_ATTRIB+1] = y;
|
|
| 666 |
attribs1[VERT1_ATTRIBS*currVert + POS_ATTRIB+2] = z;
|
|
| 667 | 667 |
|
| 668 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB ] = side==NORTH ? 0.0f : (side==WEST?-R:R);
|
|
| 669 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = 1.0f;
|
|
| 670 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
|
|
| 668 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB ] = side==NORTH ? 0.0f : (side==WEST?-R:R);
|
|
| 669 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB+1] = 1.0f;
|
|
| 670 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
|
|
| 671 | 671 |
|
| 672 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB ] = mInflateX[row][col]/2.0f;
|
|
| 673 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f;
|
|
| 674 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = z;
|
|
| 672 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB ] = mInflateX[row][col]/2.0f;
|
|
| 673 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f;
|
|
| 674 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB+2] = z;
|
|
| 675 | 675 |
|
| 676 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[TOP] + x * mTexMappingW[TOP];
|
|
| 677 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[TOP] + (0.5f-z) * mTexMappingH[TOP];
|
|
| 676 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[TOP] + x * mTexMappingW[TOP];
|
|
| 677 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[TOP] + (0.5f-z) * mTexMappingH[TOP];
|
|
| 678 | 678 |
|
| 679 | 679 |
break; |
| 680 | 680 |
case SOUTH: row = curr.row+1; |
| ... | ... | |
| 683 | 683 |
y = 0.5f - (float)row/mRows; |
| 684 | 684 |
z = 0.5f - (float)slice/mSlices; |
| 685 | 685 |
|
| 686 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB ] = x - 0.5f;
|
|
| 687 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = y;
|
|
| 688 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = z;
|
|
| 686 |
attribs1[VERT1_ATTRIBS*currVert + POS_ATTRIB ] = x - 0.5f;
|
|
| 687 |
attribs1[VERT1_ATTRIBS*currVert + POS_ATTRIB+1] = y;
|
|
| 688 |
attribs1[VERT1_ATTRIBS*currVert + POS_ATTRIB+2] = z;
|
|
| 689 | 689 |
|
| 690 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB ] = side==SOUTH ? 0.0f: (side==EAST?-R:R);
|
|
| 691 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] =-1.0f;
|
|
| 692 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
|
|
| 690 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB ] = side==SOUTH ? 0.0f: (side==EAST?-R:R);
|
|
| 691 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB+1] =-1.0f;
|
|
| 692 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
|
|
| 693 | 693 |
|
| 694 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB ] = mInflateX[row][col]/2.0f;
|
|
| 695 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f;
|
|
| 696 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = z;
|
|
| 694 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB ] = mInflateX[row][col]/2.0f;
|
|
| 695 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f;
|
|
| 696 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB+2] = z;
|
|
| 697 | 697 |
|
| 698 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[BOTTOM] + x * mTexMappingW[BOTTOM];
|
|
| 699 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[BOTTOM] + (0.5f-z) * mTexMappingH[BOTTOM];
|
|
| 698 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[BOTTOM] + x * mTexMappingW[BOTTOM];
|
|
| 699 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[BOTTOM] + (0.5f-z) * mTexMappingH[BOTTOM];
|
|
| 700 | 700 |
|
| 701 | 701 |
break; |
| 702 | 702 |
case WEST : row = (back ? (curr.row+1):(curr.row)); |
| ... | ... | |
| 705 | 705 |
y = (float)row/mRows; |
| 706 | 706 |
z = 0.5f - (float)slice/mSlices; |
| 707 | 707 |
|
| 708 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB ] = x;
|
|
| 709 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = 0.5f - y;
|
|
| 710 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = z;
|
|
| 708 |
attribs1[VERT1_ATTRIBS*currVert + POS_ATTRIB ] = x;
|
|
| 709 |
attribs1[VERT1_ATTRIBS*currVert + POS_ATTRIB+1] = 0.5f - y;
|
|
| 710 |
attribs1[VERT1_ATTRIBS*currVert + POS_ATTRIB+2] = z;
|
|
| 711 | 711 |
|
| 712 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB ] =-1.0f;
|
|
| 713 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = side==WEST ? 0.0f : (side==NORTH?-R:R);
|
|
| 714 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
|
|
| 712 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB ] =-1.0f;
|
|
| 713 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB+1] = side==WEST ? 0.0f : (side==NORTH?-R:R);
|
|
| 714 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
|
|
| 715 | 715 |
|
| 716 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB ] = mInflateX[row][col]/2.0f;
|
|
| 717 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f;
|
|
| 718 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = z;
|
|
| 716 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB ] = mInflateX[row][col]/2.0f;
|
|
| 717 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f;
|
|
| 718 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB+2] = z;
|
|
| 719 | 719 |
|
| 720 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[LEFT] + (0.5f-z) * mTexMappingW[LEFT];
|
|
| 721 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[LEFT] + (1.0f-y) * mTexMappingH[LEFT];
|
|
| 720 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[LEFT] + (0.5f-z) * mTexMappingW[LEFT];
|
|
| 721 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[LEFT] + (1.0f-y) * mTexMappingH[LEFT];
|
|
| 722 | 722 |
|
| 723 | 723 |
break; |
| 724 | 724 |
case EAST : row = (back ? (curr.row):(curr.row+1)); |
| ... | ... | |
| 727 | 727 |
y = (float)row/mRows; |
| 728 | 728 |
z = 0.5f - (float)slice/mSlices; |
| 729 | 729 |
|
| 730 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB ] = x;
|
|
| 731 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = 0.5f - y;
|
|
| 732 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = z;
|
|
| 730 |
attribs1[VERT1_ATTRIBS*currVert + POS_ATTRIB ] = x;
|
|
| 731 |
attribs1[VERT1_ATTRIBS*currVert + POS_ATTRIB+1] = 0.5f - y;
|
|
| 732 |
attribs1[VERT1_ATTRIBS*currVert + POS_ATTRIB+2] = z;
|
|
| 733 | 733 |
|
| 734 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB ] = 1.0f;
|
|
| 735 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = side==EAST ? 0.0f : (side==SOUTH?-R:R);
|
|
| 736 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
|
|
| 734 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB ] = 1.0f;
|
|
| 735 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB+1] = side==EAST ? 0.0f : (side==SOUTH?-R:R);
|
|
| 736 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
|
|
| 737 | 737 |
|
| 738 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB ] = mInflateX[row][col]/2.0f;
|
|
| 739 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f;
|
|
| 740 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = z;
|
|
| 738 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB ] = mInflateX[row][col]/2.0f;
|
|
| 739 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f;
|
|
| 740 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB+2] = z;
|
|
| 741 | 741 |
|
| 742 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[RIGHT] + (0.5f-z) * mTexMappingW[RIGHT];
|
|
| 743 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[RIGHT] + (1.0f-y) * mTexMappingH[RIGHT];
|
|
| 742 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[RIGHT] + (0.5f-z) * mTexMappingW[RIGHT];
|
|
| 743 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[RIGHT] + (1.0f-y) * mTexMappingH[RIGHT];
|
|
| 744 | 744 |
|
| 745 | 745 |
break; |
| 746 | 746 |
} |
| ... | ... | |
| 750 | 750 |
|
| 751 | 751 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 752 | 752 |
|
| 753 |
private void repeatLast(float[] attribs) |
|
| 753 |
private void repeatLast(float[] attribs1, float[] attribs2)
|
|
| 754 | 754 |
{
|
| 755 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB ] = attribs[VERT_ATTRIBS*(currVert-1) + POS_ATTRIB ];
|
|
| 756 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = attribs[VERT_ATTRIBS*(currVert-1) + POS_ATTRIB+1];
|
|
| 757 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = attribs[VERT_ATTRIBS*(currVert-1) + POS_ATTRIB+2];
|
|
| 755 |
attribs1[VERT1_ATTRIBS*currVert + POS_ATTRIB ] = attribs1[VERT1_ATTRIBS*(currVert-1) + POS_ATTRIB ];
|
|
| 756 |
attribs1[VERT1_ATTRIBS*currVert + POS_ATTRIB+1] = attribs1[VERT1_ATTRIBS*(currVert-1) + POS_ATTRIB+1];
|
|
| 757 |
attribs1[VERT1_ATTRIBS*currVert + POS_ATTRIB+2] = attribs1[VERT1_ATTRIBS*(currVert-1) + POS_ATTRIB+2];
|
|
| 758 | 758 |
|
| 759 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB ] = attribs[VERT_ATTRIBS*(currVert-1) + NOR_ATTRIB ];
|
|
| 760 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = attribs[VERT_ATTRIBS*(currVert-1) + NOR_ATTRIB+1];
|
|
| 761 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = attribs[VERT_ATTRIBS*(currVert-1) + NOR_ATTRIB+2];
|
|
| 759 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB ] = attribs1[VERT1_ATTRIBS*(currVert-1) + NOR_ATTRIB ];
|
|
| 760 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB+1] = attribs1[VERT1_ATTRIBS*(currVert-1) + NOR_ATTRIB+1];
|
|
| 761 |
attribs1[VERT1_ATTRIBS*currVert + NOR_ATTRIB+2] = attribs1[VERT1_ATTRIBS*(currVert-1) + NOR_ATTRIB+2];
|
|
| 762 | 762 |
|
| 763 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB ] = attribs[VERT_ATTRIBS*(currVert-1) + INF_ATTRIB ];
|
|
| 764 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = attribs[VERT_ATTRIBS*(currVert-1) + INF_ATTRIB+1];
|
|
| 765 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = attribs[VERT_ATTRIBS*(currVert-1) + INF_ATTRIB+2];
|
|
| 763 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB ] = attribs1[VERT1_ATTRIBS*(currVert-1) + INF_ATTRIB ];
|
|
| 764 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB+1] = attribs1[VERT1_ATTRIBS*(currVert-1) + INF_ATTRIB+1];
|
|
| 765 |
attribs1[VERT1_ATTRIBS*currVert + INF_ATTRIB+2] = attribs1[VERT1_ATTRIBS*(currVert-1) + INF_ATTRIB+2];
|
|
| 766 | 766 |
|
| 767 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB ] = attribs[VERT_ATTRIBS*(currVert-1) + TEX_ATTRIB ];
|
|
| 768 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = attribs[VERT_ATTRIBS*(currVert-1) + TEX_ATTRIB+1];
|
|
| 767 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB ] = attribs2[VERT2_ATTRIBS*(currVert-1) + TEX_ATTRIB ];
|
|
| 768 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB+1] = attribs2[VERT2_ATTRIBS*(currVert-1) + TEX_ATTRIB+1];
|
|
| 769 | 769 |
|
| 770 | 770 |
currVert++; |
| 771 | 771 |
} |
| ... | ... | |
| 774 | 774 |
|
| 775 | 775 |
private void build() |
| 776 | 776 |
{
|
| 777 |
float[] attribs= new float[VERT_ATTRIBS*numVertices]; |
|
| 777 |
float[] attribs1= new float[VERT1_ATTRIBS*numVertices]; |
|
| 778 |
float[] attribs2= new float[VERT2_ATTRIBS*numVertices]; |
|
| 778 | 779 |
|
| 779 |
buildFrontBackGrid(true,attribs); |
|
| 780 |
buildFrontBackGrid(true,attribs1,attribs2);
|
|
| 780 | 781 |
|
| 781 | 782 |
if( mSlices>0 ) |
| 782 | 783 |
{
|
| 783 |
repeatLast(attribs); |
|
| 784 |
if( currVert%2==1 ) repeatLast(attribs); |
|
| 785 |
buildSideGrid(attribs); |
|
| 786 |
buildFrontBackGrid(false,attribs); |
|
| 784 |
repeatLast(attribs1,attribs2);
|
|
| 785 |
if( currVert%2==1 ) repeatLast(attribs1,attribs2);
|
|
| 786 |
buildSideGrid(attribs1,attribs2);
|
|
| 787 |
buildFrontBackGrid(false,attribs1,attribs2);
|
|
| 787 | 788 |
} |
| 788 | 789 |
|
| 789 | 790 |
mEdges.clear(); |
| ... | ... | |
| 795 | 796 |
if( currVert!=numVertices ) |
| 796 | 797 |
android.util.Log.e("MeshCubes", "currVert " +currVert+" numVertices="+numVertices );
|
| 797 | 798 |
|
| 798 |
setAttribs(attribs); |
|
| 799 |
setAttribs(attribs1,attribs2);
|
|
| 799 | 800 |
} |
| 800 | 801 |
|
| 801 | 802 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/library/mesh/MeshJoined.java | ||
|---|---|---|
| 25 | 25 |
{
|
| 26 | 26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 27 | 27 |
/** |
| 28 |
* Join a list of (probably already changed by Matrix Effects) Meshes into one.
|
|
| 28 |
* Join a list of (probably already changed by Vertex Effects) Meshes into one.
|
|
| 29 | 29 |
* <p> |
| 30 | 30 |
* You need to try and keep the origin (0,0,0) in the center of gravity of the whole thing. |
| 31 | 31 |
*/ |
| ... | ... | |
| 39 | 39 |
/** |
| 40 | 40 |
* deep copy. |
| 41 | 41 |
*/ |
| 42 |
public MeshJoined(MeshJoined mesh) |
|
| 42 |
public MeshJoined(MeshJoined mesh)
|
|
| 43 | 43 |
{
|
| 44 | 44 |
super(mesh); |
| 45 | 45 |
} |
| ... | ... | |
| 48 | 48 |
/** |
| 49 | 49 |
* deep copy. |
| 50 | 50 |
*/ |
| 51 |
public MeshJoined deepCopy() |
|
| 51 |
public MeshJoined deepCopy()
|
|
| 52 | 52 |
{
|
| 53 | 53 |
return new MeshJoined(this); |
| 54 | 54 |
} |
| ... | ... | |
| 57 | 57 |
/** |
| 58 | 58 |
* Return how many basic Meshes is this Mesh joined from. |
| 59 | 59 |
*/ |
| 60 |
public int getNumComponents()
|
|
| 60 |
public int getNumComponents() |
|
| 61 | 61 |
{
|
| 62 | 62 |
return numComponents(); |
| 63 | 63 |
} |
| src/main/java/org/distorted/library/mesh/MeshQuad.java | ||
|---|---|---|
| 30 | 30 |
{
|
| 31 | 31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 32 | 32 |
|
| 33 |
private void addVertex( float x, float y, float[] attribs, int index) |
|
| 33 |
private void addVertex( float x, float y, float[] attribs1, float[] attribs2, int index)
|
|
| 34 | 34 |
{
|
| 35 |
attribs[VERT_ATTRIBS*index + POS_ATTRIB ] = x-0.5f;
|
|
| 36 |
attribs[VERT_ATTRIBS*index + POS_ATTRIB+1] = 0.5f-y;
|
|
| 37 |
attribs[VERT_ATTRIBS*index + POS_ATTRIB+2] = 0.0f;
|
|
| 35 |
attribs1[VERT1_ATTRIBS*index + POS_ATTRIB ] = x-0.5f;
|
|
| 36 |
attribs1[VERT1_ATTRIBS*index + POS_ATTRIB+1] = 0.5f-y;
|
|
| 37 |
attribs1[VERT1_ATTRIBS*index + POS_ATTRIB+2] = 0.0f;
|
|
| 38 | 38 |
|
| 39 |
attribs[VERT_ATTRIBS*index + NOR_ATTRIB ] = 0.0f;
|
|
| 40 |
attribs[VERT_ATTRIBS*index + NOR_ATTRIB+1] = 0.0f;
|
|
| 41 |
attribs[VERT_ATTRIBS*index + NOR_ATTRIB+2] = 1.0f;
|
|
| 39 |
attribs1[VERT1_ATTRIBS*index + NOR_ATTRIB ] = 0.0f;
|
|
| 40 |
attribs1[VERT1_ATTRIBS*index + NOR_ATTRIB+1] = 0.0f;
|
|
| 41 |
attribs1[VERT1_ATTRIBS*index + NOR_ATTRIB+2] = 1.0f;
|
|
| 42 | 42 |
|
| 43 |
attribs[VERT_ATTRIBS*index + INF_ATTRIB ] = (x-0.5f);
|
|
| 44 |
attribs[VERT_ATTRIBS*index + INF_ATTRIB+1] = (0.5f-y);
|
|
| 45 |
attribs[VERT_ATTRIBS*index + INF_ATTRIB+2] = 0.01f ; // Inflated surface needs to be slightly in front
|
|
| 43 |
attribs1[VERT1_ATTRIBS*index + INF_ATTRIB ] = (x-0.5f);
|
|
| 44 |
attribs1[VERT1_ATTRIBS*index + INF_ATTRIB+1] = (0.5f-y);
|
|
| 45 |
attribs1[VERT1_ATTRIBS*index + INF_ATTRIB+2] = 0.01f ; // Inflated surface needs to be slightly in front
|
|
| 46 | 46 |
|
| 47 |
attribs[VERT_ATTRIBS*index + TEX_ATTRIB ] = x;
|
|
| 48 |
attribs[VERT_ATTRIBS*index + TEX_ATTRIB+1] = 1.0f-y;
|
|
| 47 |
attribs2[VERT2_ATTRIBS*index + TEX_ATTRIB ] = x;
|
|
| 48 |
attribs2[VERT2_ATTRIBS*index + TEX_ATTRIB+1] = 1.0f-y;
|
|
| 49 | 49 |
} |
| 50 | 50 |
|
| 51 | 51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 57 | 57 |
public MeshQuad() |
| 58 | 58 |
{
|
| 59 | 59 |
super(); |
| 60 |
float[] attribs= new float[VERT_ATTRIBS*4]; |
|
| 61 | 60 |
|
| 62 |
addVertex(0.0f,0.0f, attribs,0); |
|
| 63 |
addVertex(0.0f,1.0f, attribs,1); |
|
| 64 |
addVertex(1.0f,0.0f, attribs,2); |
|
| 65 |
addVertex(1.0f,1.0f, attribs,3); |
|
| 61 |
float[] attribs1= new float[VERT1_ATTRIBS*4]; |
|
| 62 |
float[] attribs2= new float[VERT2_ATTRIBS*4]; |
|
| 66 | 63 |
|
| 67 |
setAttribs(attribs); |
|
| 64 |
addVertex(0.0f,0.0f, attribs1, attribs2, 0); |
|
| 65 |
addVertex(0.0f,1.0f, attribs1, attribs2, 1); |
|
| 66 |
addVertex(1.0f,0.0f, attribs1, attribs2, 2); |
|
| 67 |
addVertex(1.0f,1.0f, attribs1, attribs2, 3); |
|
| 68 |
|
|
| 69 |
setAttribs(attribs1,attribs2); |
|
| 68 | 70 |
} |
| 69 | 71 |
|
| 70 | 72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/library/mesh/MeshRectangles.java | ||
|---|---|---|
| 55 | 55 |
|
| 56 | 56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 57 | 57 |
|
| 58 |
private int addVertex(int vertex, float x, float y, float[] attribs) |
|
| 58 |
private int addVertex(int vertex, float x, float y, float[] attribs1, float[] attribs2)
|
|
| 59 | 59 |
{
|
| 60 | 60 |
remainingVert--; |
| 61 | 61 |
|
| 62 |
attribs[VERT_ATTRIBS*vertex + POS_ATTRIB ] = x-0.5f;
|
|
| 63 |
attribs[VERT_ATTRIBS*vertex + POS_ATTRIB+1] = 0.5f-y;
|
|
| 64 |
attribs[VERT_ATTRIBS*vertex + POS_ATTRIB+2] = 0.0f;
|
|
| 62 |
attribs1[VERT1_ATTRIBS*vertex + POS_ATTRIB ] = x-0.5f;
|
|
| 63 |
attribs1[VERT1_ATTRIBS*vertex + POS_ATTRIB+1] = 0.5f-y;
|
|
| 64 |
attribs1[VERT1_ATTRIBS*vertex + POS_ATTRIB+2] = 0.0f;
|
|
| 65 | 65 |
|
| 66 |
attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB ] = 0.0f;
|
|
| 67 |
attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB+1] = 0.0f;
|
|
| 68 |
attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB+2] = 1.0f;
|
|
| 66 |
attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB ] = 0.0f;
|
|
| 67 |
attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB+1] = 0.0f;
|
|
| 68 |
attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB+2] = 1.0f;
|
|
| 69 | 69 |
|
| 70 |
attribs[VERT_ATTRIBS*vertex + INF_ATTRIB ] = (x-0.5f);
|
|
| 71 |
attribs[VERT_ATTRIBS*vertex + INF_ATTRIB+1] = (0.5f-y);
|
|
| 72 |
attribs[VERT_ATTRIBS*vertex + INF_ATTRIB+2] = 0.01f ; // Inflated surface needs to be slightly in front
|
|
| 70 |
attribs1[VERT1_ATTRIBS*vertex + INF_ATTRIB ] = (x-0.5f);
|
|
| 71 |
attribs1[VERT1_ATTRIBS*vertex + INF_ATTRIB+1] = (0.5f-y);
|
|
| 72 |
attribs1[VERT1_ATTRIBS*vertex + INF_ATTRIB+2] = 0.01f ; // Inflated surface needs to be slightly in front
|
|
| 73 | 73 |
|
| 74 |
attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB ] = x;
|
|
| 75 |
attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB+1] = 1.0f-y;
|
|
| 74 |
attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB ] = x;
|
|
| 75 |
attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB+1] = 1.0f-y;
|
|
| 76 | 76 |
|
| 77 | 77 |
return vertex+1; |
| 78 | 78 |
} |
| 79 | 79 |
|
| 80 | 80 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 81 | 81 |
|
| 82 |
private int repeatLast(int vertex, float[] attribs) |
|
| 82 |
private int repeatLast(int vertex, float[] attribs1, float[] attribs2)
|
|
| 83 | 83 |
{
|
| 84 | 84 |
if( vertex>0 ) |
| 85 | 85 |
{
|
| 86 | 86 |
remainingVert--; |
| 87 | 87 |
|
| 88 |
attribs[VERT_ATTRIBS*vertex + POS_ATTRIB ] = attribs[VERT_ATTRIBS*(vertex-1) + POS_ATTRIB ];
|
|
| 89 |
attribs[VERT_ATTRIBS*vertex + POS_ATTRIB+1] = attribs[VERT_ATTRIBS*(vertex-1) + POS_ATTRIB+1];
|
|
| 90 |
attribs[VERT_ATTRIBS*vertex + POS_ATTRIB+2] = attribs[VERT_ATTRIBS*(vertex-1) + POS_ATTRIB+2];
|
|
| 88 |
attribs1[VERT1_ATTRIBS*vertex + POS_ATTRIB ] = attribs1[VERT1_ATTRIBS*(vertex-1) + POS_ATTRIB ];
|
|
| 89 |
attribs1[VERT1_ATTRIBS*vertex + POS_ATTRIB+1] = attribs1[VERT1_ATTRIBS*(vertex-1) + POS_ATTRIB+1];
|
|
| 90 |
attribs1[VERT1_ATTRIBS*vertex + POS_ATTRIB+2] = attribs1[VERT1_ATTRIBS*(vertex-1) + POS_ATTRIB+2];
|
|
| 91 | 91 |
|
| 92 |
attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB ] = attribs[VERT_ATTRIBS*(vertex-1) + NOR_ATTRIB ];
|
|
| 93 |
attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB+1] = attribs[VERT_ATTRIBS*(vertex-1) + NOR_ATTRIB+1];
|
|
| 94 |
attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB+2] = attribs[VERT_ATTRIBS*(vertex-1) + NOR_ATTRIB+2];
|
|
| 92 |
attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB ] = attribs1[VERT1_ATTRIBS*(vertex-1) + NOR_ATTRIB ];
|
|
| 93 |
attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB+1] = attribs1[VERT1_ATTRIBS*(vertex-1) + NOR_ATTRIB+1];
|
|
| 94 |
attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB+2] = attribs1[VERT1_ATTRIBS*(vertex-1) + NOR_ATTRIB+2];
|
|
| 95 | 95 |
|
| 96 |
attribs[VERT_ATTRIBS*vertex + INF_ATTRIB ] = attribs[VERT_ATTRIBS*(vertex-1) + INF_ATTRIB ];
|
|
| 97 |
attribs[VERT_ATTRIBS*vertex + INF_ATTRIB+1] = attribs[VERT_ATTRIBS*(vertex-1) + INF_ATTRIB+1];
|
|
| 98 |
attribs[VERT_ATTRIBS*vertex + INF_ATTRIB+2] = attribs[VERT_ATTRIBS*(vertex-1) + INF_ATTRIB+2];
|
|
| 96 |
attribs1[VERT1_ATTRIBS*vertex + INF_ATTRIB ] = attribs1[VERT1_ATTRIBS*(vertex-1) + INF_ATTRIB ];
|
|
| 97 |
attribs1[VERT1_ATTRIBS*vertex + INF_ATTRIB+1] = attribs1[VERT1_ATTRIBS*(vertex-1) + INF_ATTRIB+1];
|
|
| 98 |
attribs1[VERT1_ATTRIBS*vertex + INF_ATTRIB+2] = attribs1[VERT1_ATTRIBS*(vertex-1) + INF_ATTRIB+2];
|
|
| 99 | 99 |
|
| 100 |
attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB ] = attribs[VERT_ATTRIBS*(vertex-1) + TEX_ATTRIB ];
|
|
| 101 |
attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB+1] = attribs[VERT_ATTRIBS*(vertex-1) + TEX_ATTRIB+1];
|
|
| 100 |
attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB ] = attribs2[VERT2_ATTRIBS*(vertex-1) + TEX_ATTRIB ];
|
|
| 101 |
attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB+1] = attribs2[VERT2_ATTRIBS*(vertex-1) + TEX_ATTRIB+1];
|
|
| 102 | 102 |
|
| 103 | 103 |
vertex++; |
| 104 | 104 |
} |
| ... | ... | |
| 108 | 108 |
|
| 109 | 109 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 110 | 110 |
|
| 111 |
private void buildGrid(float[] attribs) |
|
| 111 |
private void buildGrid(float[] attribs1, float[] attribs2)
|
|
| 112 | 112 |
{
|
| 113 | 113 |
boolean lastBlockIsNE = false; |
| 114 | 114 |
boolean currentBlockIsNE; |
| ... | ... | |
| 130 | 130 |
|
| 131 | 131 |
if( col==0 || (lastBlockIsNE^currentBlockIsNE) ) |
| 132 | 132 |
{
|
| 133 |
if( row!=0 && col==0 ) vertex = repeatLast(vertex,attribs); |
|
| 134 |
vertex= addVertex( vertex, x, y+(currentBlockIsNE?0:Y), attribs); |
|
| 135 |
if( row!=0 && col==0 ) vertex = repeatLast(vertex,attribs); |
|
| 136 |
if( lastBlockIsNE^currentBlockIsNE) vertex = repeatLast(vertex,attribs); |
|
| 137 |
vertex= addVertex( vertex, x, y+(currentBlockIsNE?Y:0), attribs); |
|
| 133 |
if( row!=0 && col==0 ) vertex = repeatLast(vertex,attribs1,attribs2);
|
|
| 134 |
vertex= addVertex( vertex, x, y+(currentBlockIsNE?0:Y), attribs1,attribs2);
|
|
| 135 |
if( row!=0 && col==0 ) vertex = repeatLast(vertex,attribs1,attribs2);
|
|
| 136 |
if( lastBlockIsNE^currentBlockIsNE) vertex = repeatLast(vertex,attribs1,attribs2);
|
|
| 137 |
vertex= addVertex( vertex, x, y+(currentBlockIsNE?Y:0), attribs1,attribs2);
|
|
| 138 | 138 |
} |
| 139 |
vertex= addVertex( vertex, x+X, y+(currentBlockIsNE?0:Y), attribs); |
|
| 140 |
vertex= addVertex( vertex, x+X, y+(currentBlockIsNE?Y:0), attribs); |
|
| 139 |
vertex= addVertex( vertex, x+X, y+(currentBlockIsNE?0:Y), attribs1,attribs2);
|
|
| 140 |
vertex= addVertex( vertex, x+X, y+(currentBlockIsNE?Y:0), attribs1,attribs2);
|
|
| 141 | 141 |
|
| 142 | 142 |
lastBlockIsNE = currentBlockIsNE; |
| 143 | 143 |
x+=X; |
| ... | ... | |
| 156 | 156 |
* @param cols Number of columns in the grid. |
| 157 | 157 |
* @param rows Number of rows in the grid. |
| 158 | 158 |
*/ |
| 159 |
public MeshRectangles(int cols, int rows) |
|
| 159 |
public MeshRectangles(int cols, int rows)
|
|
| 160 | 160 |
{
|
| 161 | 161 |
super(); |
| 162 | 162 |
computeNumberOfVertices(cols,rows); |
| 163 | 163 |
|
| 164 |
float[] attribs= new float[VERT_ATTRIBS*numVertices]; |
|
| 164 |
float[] attribs1= new float[VERT1_ATTRIBS*numVertices]; |
|
| 165 |
float[] attribs2= new float[VERT2_ATTRIBS*numVertices]; |
|
| 165 | 166 |
|
| 166 |
buildGrid(attribs); |
|
| 167 |
buildGrid(attribs1,attribs2);
|
|
| 167 | 168 |
|
| 168 | 169 |
if( remainingVert!=0 ) |
| 169 | 170 |
android.util.Log.d("MeshRectangles", "remainingVert " +remainingVert );
|
| 170 | 171 |
|
| 171 |
setAttribs(attribs); |
|
| 172 |
setAttribs(attribs1,attribs2);
|
|
| 172 | 173 |
} |
| 173 | 174 |
|
| 174 | 175 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 175 | 176 |
/** |
| 176 | 177 |
* deep copy. |
| 177 | 178 |
*/ |
| 178 |
public MeshRectangles(MeshRectangles mesh) |
|
| 179 |
{
|
|
| 180 |
super(mesh); |
|
| 181 |
} |
|
| 179 |
public MeshRectangles(MeshRectangles mesh)
|
|
| 180 |
{
|
|
| 181 |
super(mesh);
|
|
| 182 |
}
|
|
| 182 | 183 |
|
| 183 | 184 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 184 | 185 |
/** |
| 185 | 186 |
* deep copy. |
| 186 | 187 |
*/ |
| 187 |
public MeshRectangles deepCopy() |
|
| 188 |
{
|
|
| 189 |
return new MeshRectangles(this); |
|
| 190 |
} |
|
| 188 |
public MeshRectangles deepCopy()
|
|
| 189 |
{
|
|
| 190 |
return new MeshRectangles(this);
|
|
| 191 |
}
|
|
| 191 | 192 |
} |
| src/main/java/org/distorted/library/mesh/MeshSphere.java | ||
|---|---|---|
| 77 | 77 |
|
| 78 | 78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 79 | 79 |
|
| 80 |
private void repeatVertex(float[] attribs) |
|
| 80 |
private void repeatVertex(float[] attribs1, float[] attribs2)
|
|
| 81 | 81 |
{
|
| 82 | 82 |
if( currentVert>0 ) |
| 83 | 83 |
{
|
| 84 |
attribs[VERT_ATTRIBS*currentVert + POS_ATTRIB ] = attribs[VERT_ATTRIBS*(currentVert-1) + POS_ATTRIB ];
|
|
| 85 |
attribs[VERT_ATTRIBS*currentVert + POS_ATTRIB+1] = attribs[VERT_ATTRIBS*(currentVert-1) + POS_ATTRIB+1];
|
|
| 86 |
attribs[VERT_ATTRIBS*currentVert + POS_ATTRIB+2] = attribs[VERT_ATTRIBS*(currentVert-1) + POS_ATTRIB+2];
|
|
| 84 |
attribs1[VERT1_ATTRIBS*currentVert + POS_ATTRIB ] = attribs1[VERT1_ATTRIBS*(currentVert-1) + POS_ATTRIB ];
|
|
| 85 |
attribs1[VERT1_ATTRIBS*currentVert + POS_ATTRIB+1] = attribs1[VERT1_ATTRIBS*(currentVert-1) + POS_ATTRIB+1];
|
|
| 86 |
attribs1[VERT1_ATTRIBS*currentVert + POS_ATTRIB+2] = attribs1[VERT1_ATTRIBS*(currentVert-1) + POS_ATTRIB+2];
|
|
| 87 | 87 |
|
| 88 |
attribs[VERT_ATTRIBS*currentVert + NOR_ATTRIB ] = attribs[VERT_ATTRIBS*(currentVert-1) + NOR_ATTRIB ];
|
|
| 89 |
attribs[VERT_ATTRIBS*currentVert + NOR_ATTRIB+1] = attribs[VERT_ATTRIBS*(currentVert-1) + NOR_ATTRIB+1];
|
|
| 90 |
attribs[VERT_ATTRIBS*currentVert + NOR_ATTRIB+2] = attribs[VERT_ATTRIBS*(currentVert-1) + NOR_ATTRIB+2];
|
|
| 88 |
attribs1[VERT1_ATTRIBS*currentVert + NOR_ATTRIB ] = attribs1[VERT1_ATTRIBS*(currentVert-1) + NOR_ATTRIB ];
|
|
| 89 |
attribs1[VERT1_ATTRIBS*currentVert + NOR_ATTRIB+1] = attribs1[VERT1_ATTRIBS*(currentVert-1) + NOR_ATTRIB+1];
|
|
| 90 |
attribs1[VERT1_ATTRIBS*currentVert + NOR_ATTRIB+2] = attribs1[VERT1_ATTRIBS*(currentVert-1) + NOR_ATTRIB+2];
|
|
| 91 | 91 |
|
| 92 |
attribs[VERT_ATTRIBS*currentVert + INF_ATTRIB ] = attribs[VERT_ATTRIBS*(currentVert-1) + INF_ATTRIB ];
|
|
| 93 |
attribs[VERT_ATTRIBS*currentVert + INF_ATTRIB+1] = attribs[VERT_ATTRIBS*(currentVert-1) + INF_ATTRIB+1];
|
|
| 94 |
attribs[VERT_ATTRIBS*currentVert + INF_ATTRIB+2] = attribs[VERT_ATTRIBS*(currentVert-1) + INF_ATTRIB+2];
|
|
| 92 |
attribs1[VERT1_ATTRIBS*currentVert + INF_ATTRIB ] = attribs1[VERT1_ATTRIBS*(currentVert-1) + INF_ATTRIB ];
|
|
| 93 |
attribs1[VERT1_ATTRIBS*currentVert + INF_ATTRIB+1] = attribs1[VERT1_ATTRIBS*(currentVert-1) + INF_ATTRIB+1];
|
|
| 94 |
attribs1[VERT1_ATTRIBS*currentVert + INF_ATTRIB+2] = attribs1[VERT1_ATTRIBS*(currentVert-1) + INF_ATTRIB+2];
|
|
| 95 | 95 |
|
| 96 |
attribs[VERT_ATTRIBS*currentVert + TEX_ATTRIB ] = attribs[VERT_ATTRIBS*(currentVert-1) + TEX_ATTRIB ];
|
|
| 97 |
attribs[VERT_ATTRIBS*currentVert + TEX_ATTRIB+1] = attribs[VERT_ATTRIBS*(currentVert-1) + TEX_ATTRIB+1];
|
|
| 96 |
attribs2[VERT2_ATTRIBS*currentVert + TEX_ATTRIB ] = attribs2[VERT2_ATTRIBS*(currentVert-1) + TEX_ATTRIB ];
|
|
| 97 |
attribs2[VERT2_ATTRIBS*currentVert + TEX_ATTRIB+1] = attribs2[VERT2_ATTRIBS*(currentVert-1) + TEX_ATTRIB+1];
|
|
| 98 | 98 |
|
| 99 | 99 |
currentVert++; |
| 100 | 100 |
} |
| ... | ... | |
| 151 | 151 |
// ( 0, level-1, level) -> (lonV3,latV3 ) |
| 152 | 152 |
// (level-1, 0, level) -> (lonV2,latV12) |
| 153 | 153 |
|
| 154 |
private void addVertex(float[] attribs, int column, int row, int level, |
|
| 154 |
private void addVertex(float[] attribs1, float[] attribs2, int column, int row, int level,
|
|
| 155 | 155 |
double lonV1, double lonV2, double latV12, double latV3) |
| 156 | 156 |
{
|
| 157 | 157 |
double quotX = (double)column/level; |
| ... | ... | |
| 184 | 184 |
|
| 185 | 185 |
double texY = 0.5 + latitude/P; |
| 186 | 186 |
|
| 187 |
attribs[VERT_ATTRIBS*currentVert + POS_ATTRIB ] = x; //
|
|
| 188 |
attribs[VERT_ATTRIBS*currentVert + POS_ATTRIB+1] = y; //
|
|
| 189 |
attribs[VERT_ATTRIBS*currentVert + POS_ATTRIB+2] = z; //
|
|
| 190 |
// In case of this Mesh so it happens that |
|
| 191 |
attribs[VERT_ATTRIBS*currentVert + NOR_ATTRIB ] = 2*x;// the vertex coords, normal vector, and
|
|
| 192 |
attribs[VERT_ATTRIBS*currentVert + NOR_ATTRIB+1] = 2*y;// inflate vector have identical (x,y,z).
|
|
| 193 |
attribs[VERT_ATTRIBS*currentVert + NOR_ATTRIB+2] = 2*z;//
|
|
| 194 |
// TODO: think about some more efficient |
|
| 195 |
attribs[VERT_ATTRIBS*currentVert + INF_ATTRIB ] = x; // representation.
|
|
| 196 |
attribs[VERT_ATTRIBS*currentVert + INF_ATTRIB+1] = y; //
|
|
| 197 |
attribs[VERT_ATTRIBS*currentVert + INF_ATTRIB+2] = z; //
|
|
| 198 |
|
|
| 199 |
attribs[VERT_ATTRIBS*currentVert + TEX_ATTRIB ] = (float)texX;
|
|
| 200 |
attribs[VERT_ATTRIBS*currentVert + TEX_ATTRIB+1] = (float)texY;
|
|
| 187 |
attribs1[VERT1_ATTRIBS*currentVert + POS_ATTRIB ] = x; //
|
|
| 188 |
attribs1[VERT1_ATTRIBS*currentVert + POS_ATTRIB+1] = y; //
|
|
| 189 |
attribs1[VERT1_ATTRIBS*currentVert + POS_ATTRIB+2] = z; //
|
|
| 190 |
// In case of this Mesh so it happens that
|
|
| 191 |
attribs1[VERT1_ATTRIBS*currentVert + NOR_ATTRIB ] = 2*x;// the vertex coords, normal vector, and
|
|
| 192 |
attribs1[VERT1_ATTRIBS*currentVert + NOR_ATTRIB+1] = 2*y;// inflate vector have identical (x,y,z).
|
|
| 193 |
attribs1[VERT1_ATTRIBS*currentVert + NOR_ATTRIB+2] = 2*z;//
|
|
| 194 |
// TODO: think about some more efficient
|
|
| 195 |
attribs1[VERT1_ATTRIBS*currentVert + INF_ATTRIB ] = x; // representation.
|
|
| 196 |
attribs1[VERT1_ATTRIBS*currentVert + INF_ATTRIB+1] = y; //
|
|
| 197 |
attribs1[VERT1_ATTRIBS*currentVert + INF_ATTRIB+2] = z; //
|
|
| 198 |
|
|
| 199 |
attribs2[VERT2_ATTRIBS*currentVert + TEX_ATTRIB ] = (float)texX;
|
|
| 200 |
attribs2[VERT2_ATTRIBS*currentVert + TEX_ATTRIB+1] = (float)texY;
|
|
| 201 | 201 |
|
| 202 | 202 |
currentVert++; |
| 203 | 203 |
|
| ... | ... | |
| 209 | 209 |
|
| 210 | 210 |
if( currentVert>=3 && texX==0.0 ) |
| 211 | 211 |
{
|
| 212 |
double tex1 = attribs[VERT_ATTRIBS*(currentVert-2) + TEX_ATTRIB];
|
|
| 213 |
double tex2 = attribs[VERT_ATTRIBS*(currentVert-3) + TEX_ATTRIB];
|
|
| 212 |
double tex1 = attribs2[VERT2_ATTRIBS*(currentVert-2) + TEX_ATTRIB];
|
|
| 213 |
double tex2 = attribs2[VERT2_ATTRIBS*(currentVert-3) + TEX_ATTRIB];
|
|
| 214 | 214 |
|
| 215 | 215 |
// if the triangle is not degenerate and last vertex was on the western hemisphere |
| 216 | 216 |
if( tex1!=tex2 && tex1>0.5 ) |
| 217 | 217 |
{
|
| 218 |
attribs[VERT_ATTRIBS*(currentVert-1) + TEX_ATTRIB] = 1.0f;
|
|
| 218 |
attribs2[VERT2_ATTRIBS*(currentVert-1) + TEX_ATTRIB] = 1.0f;
|
|
| 219 | 219 |
} |
| 220 | 220 |
} |
| 221 | 221 |
} |
| 222 | 222 |
|
| 223 | 223 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 224 | 224 |
|
| 225 |
private void buildFace(float[] attribs, int level, int face, double lonV1, double lonV2, double latV12, double latV3) |
|
| 225 |
private void buildFace(float[] attribs1, float[] attribs2, int level, int face, double lonV1, double lonV2, double latV12, double latV3)
|
|
| 226 | 226 |
{
|
| 227 | 227 |
for(int row=0; row<level; row++) |
| 228 | 228 |
{
|
| 229 | 229 |
for (int column=0; column<level-row; column++) |
| 230 | 230 |
{
|
| 231 |
addVertex(attribs, column, row , level, lonV1, lonV2, latV12, latV3); |
|
| 232 |
if (column==0 && !(face==0 && row==0 ) ) repeatVertex(attribs); |
|
| 233 |
addVertex(attribs, column, row+1, level, lonV1, lonV2, latV12, latV3); |
|
| 231 |
addVertex(attribs1, attribs2, column, row , level, lonV1, lonV2, latV12, latV3);
|
|
| 232 |
if (column==0 && !(face==0 && row==0 ) ) repeatVertex(attribs1, attribs2);
|
|
| 233 |
addVertex(attribs1, attribs2, column, row+1, level, lonV1, lonV2, latV12, latV3);
|
|
| 234 | 234 |
} |
| 235 | 235 |
|
| 236 |
addVertex(attribs, level-row, row , level, lonV1, lonV2, latV12, latV3); |
|
| 237 |
if( row!=level-1 || face!=NUMFACES-1 ) repeatVertex(attribs); |
|
| 236 |
addVertex(attribs1, attribs2, level-row, row , level, lonV1, lonV2, latV12, latV3);
|
|
| 237 |
if( row!=level-1 || face!=NUMFACES-1 ) repeatVertex(attribs1, attribs2);
|
|
| 238 | 238 |
} |
| 239 | 239 |
} |
| 240 | 240 |
|
| ... | ... | |
| 254 | 254 |
public MeshSphere(int level) |
| 255 | 255 |
{
|
| 256 | 256 |
super(); |
| 257 |
|
|
| 257 | 258 |
computeNumberOfVertices(level); |
| 258 |
float[] attribs= new float[VERT_ATTRIBS*numVertices]; |
|
| 259 |
float[] attribs1= new float[VERT1_ATTRIBS*numVertices]; |
|
| 260 |
float[] attribs2= new float[VERT2_ATTRIBS*numVertices]; |
|
| 259 | 261 |
|
| 260 | 262 |
for(int face=0; face<NUMFACES; face++ ) |
| 261 | 263 |
{
|
| 262 |
buildFace(attribs, level, face, FACES[face][0], FACES[face][1], FACES[face][2], FACES[face][3]); |
|
| 264 |
buildFace(attribs1, attribs2, level, face, FACES[face][0], FACES[face][1], FACES[face][2], FACES[face][3]);
|
|
| 263 | 265 |
} |
| 264 | 266 |
|
| 265 | 267 |
if( currentVert!=numVertices ) |
| 266 | 268 |
android.util.Log.d("MeshSphere", "currentVert= " +currentVert+" numVertices="+numVertices );
|
| 267 | 269 |
|
| 268 |
setAttribs(attribs); |
|
| 270 |
setAttribs(attribs1, attribs2);
|
|
| 269 | 271 |
} |
| 270 | 272 |
|
| 271 | 273 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/library/mesh/MeshTriangles.java | ||
|---|---|---|
| 30 | 30 |
|
| 31 | 31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 32 | 32 |
|
| 33 |
private int addVertex(int vertex, float x, float y, float[] attribs) |
|
| 33 |
private int addVertex(int vertex, float x, float y, float[] attribs1, float[] attribs2)
|
|
| 34 | 34 |
{
|
| 35 | 35 |
remainingVert--; |
| 36 | 36 |
|
| 37 |
attribs[VERT_ATTRIBS*vertex + POS_ATTRIB ] = x-0.5f;
|
|
| 38 |
attribs[VERT_ATTRIBS*vertex + POS_ATTRIB+1] = y-0.5f;
|
|
| 39 |
attribs[VERT_ATTRIBS*vertex + POS_ATTRIB+2] = 0.0f;
|
|
| 37 |
attribs1[VERT1_ATTRIBS*vertex + POS_ATTRIB ] = x-0.5f;
|
|
| 38 |
attribs1[VERT1_ATTRIBS*vertex + POS_ATTRIB+1] = y-0.5f;
|
|
| 39 |
attribs1[VERT1_ATTRIBS*vertex + POS_ATTRIB+2] = 0.0f;
|
|
| 40 | 40 |
|
| 41 |
attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB ] = 0.0f;
|
|
| 42 |
attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB+1] = 0.0f;
|
|
| 43 |
attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB+2] = 1.0f;
|
|
| 41 |
attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB ] = 0.0f;
|
|
| 42 |
attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB+1] = 0.0f;
|
|
| 43 |
attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB+2] = 1.0f;
|
|
| 44 | 44 |
|
| 45 |
attribs[VERT_ATTRIBS*vertex + INF_ATTRIB ] = (x-0.5f);
|
|
| 46 |
attribs[VERT_ATTRIBS*vertex + INF_ATTRIB+1] = (y-0.5f);
|
|
| 47 |
attribs[VERT_ATTRIBS*vertex + INF_ATTRIB+2] = 0.01f ; // Inflated surface needs to be slightly in front
|
|
| 45 |
attribs1[VERT1_ATTRIBS*vertex + INF_ATTRIB ] = (x-0.5f);
|
|
| 46 |
attribs1[VERT1_ATTRIBS*vertex + INF_ATTRIB+1] = (y-0.5f);
|
|
| 47 |
attribs1[VERT1_ATTRIBS*vertex + INF_ATTRIB+2] = 0.01f ; // Inflated surface needs to be slightly in front
|
|
| 48 | 48 |
|
| 49 |
attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB ] = x;
|
|
| 50 |
attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB+1] = y;
|
|
| 49 |
attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB ] = x;
|
|
| 50 |
attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB+1] = y;
|
|
| 51 | 51 |
|
| 52 | 52 |
return vertex+1; |
| 53 | 53 |
} |
| ... | ... | |
| 62 | 62 |
|
| 63 | 63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 64 | 64 |
|
| 65 |
private int buildRow(int vertex,float sx, float sy, int length, float dx, float dy, float[] attribs) |
|
| 65 |
private int buildRow(int vertex,float sx, float sy, int length, float dx, float dy, float[] attribs1, float[] attribs2)
|
|
| 66 | 66 |
{
|
| 67 | 67 |
for(int i=0; i<length; i++) |
| 68 | 68 |
{
|
| 69 |
vertex = addVertex(vertex, sx , sy , attribs); |
|
| 70 |
vertex = addVertex(vertex, sx+dx, sy+dy, attribs); |
|
| 69 |
vertex = addVertex(vertex, sx , sy , attribs1, attribs2);
|
|
| 70 |
vertex = addVertex(vertex, sx+dx, sy+dy, attribs1, attribs2);
|
|
| 71 | 71 |
sx += 2*dx; |
| 72 | 72 |
} |
| 73 | 73 |
|
| 74 |
vertex = addVertex(vertex, sx, sy, attribs); |
|
| 74 |
vertex = addVertex(vertex, sx, sy, attribs1, attribs2);
|
|
| 75 | 75 |
|
| 76 | 76 |
return vertex; |
| 77 | 77 |
} |
| 78 | 78 |
|
| 79 | 79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 80 | 80 |
|
| 81 |
private void buildGrid(float[] attribs, int level) |
|
| 81 |
private void buildGrid(float[] attribs1, float[] attribs2, int level)
|
|
| 82 | 82 |
{
|
| 83 | 83 |
float sx = 0.0f; |
| 84 | 84 |
float sy = 0.0f; |
| ... | ... | |
| 88 | 88 |
|
| 89 | 89 |
for(int row=level; row>=1; row--) |
| 90 | 90 |
{
|
| 91 |
vertex = buildRow(vertex,sx,sy,row,dx,dy,attribs); |
|
| 91 |
vertex = buildRow(vertex,sx,sy,row,dx,dy,attribs1,attribs2);
|
|
| 92 | 92 |
|
| 93 | 93 |
sx += 2*dx*(row-0.5f); |
| 94 | 94 |
sy += dy; |
| ... | ... | |
| 111 | 111 |
|
| 112 | 112 |
computeNumberOfVertices(level); |
| 113 | 113 |
|
| 114 |
float[] attribs= new float[VERT_ATTRIBS*numVertices]; |
|
| 115 |
buildGrid(attribs,level); |
|
| 114 |
float[] attribs1= new float[VERT1_ATTRIBS*numVertices]; |
|
| 115 |
float[] attribs2= new float[VERT2_ATTRIBS*numVertices]; |
|
| 116 |
|
|
| 117 |
buildGrid(attribs1, attribs2, level); |
|
| 116 | 118 |
|
| 117 | 119 |
if( remainingVert!=0 ) |
| 118 | 120 |
android.util.Log.d("MeshTriangles", "remainingVert " +remainingVert );
|
| 119 | 121 |
|
| 120 |
setAttribs(attribs); |
|
| 122 |
setAttribs(attribs1, attribs2);
|
|
| 121 | 123 |
} |
| 122 | 124 |
|
| 123 | 125 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/res/raw/main_vertex_shader.glsl | ||
|---|---|---|
| 28 | 28 |
|
| 29 | 29 |
out vec3 v_Position; // |
| 30 | 30 |
out vec3 v_endPosition; // for Transform Feedback only |
| 31 |
|
|
| 32 |
#ifdef PREAPPLY |
|
| 33 |
out vec3 v_Inflate; // Transform Feedback for preapply effects |
|
| 34 |
#endif |
|
| 35 |
|
|
| 31 | 36 |
out vec3 v_Normal; // |
| 32 | 37 |
out vec2 v_TexCoordinate; // |
| 33 | 38 |
|
| ... | ... | |
| 95 | 100 |
vec3 v = a_Position + u_Inflate*a_Inflate; |
| 96 | 101 |
vec3 n = a_Normal; |
| 97 | 102 |
|
| 103 |
#ifdef PREAPPLY |
|
| 104 |
vec3 inf = a_Inflate; |
|
| 105 |
#endif |
|
| 106 |
|
|
| 98 | 107 |
#if NUM_VERTEX>0 |
| 99 | 108 |
int effect=0; |
| 100 | 109 |
|
| ... | ... | |
| 110 | 119 |
|
| 111 | 120 |
#ifdef PREAPPLY |
| 112 | 121 |
v_endPosition = n; |
| 122 |
v_Inflate = inf; |
|
| 113 | 123 |
#else |
| 114 | 124 |
v_endPosition = v + 0.5*n; |
| 115 | 125 |
#endif |
Also available in: Unified diff
Have VERTEX_QUATERNION, VERTEX_ROTATE and VERTEX_SHEAR modify inflate vectors.
Split Vertex attribute array into two (the one modified by preapply effects and the one not)