Changeset 14249
- Timestamp:
- 01/15/13 11:25:39 (12 years ago)
- Location:
- issm/trunk-jpl/src/android/ISSM/src/com/example/issm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/android/ISSM/src/com/example/issm/ISSM.java
r14210 r14249 252 252 mGLView = new MyGLSurfaceView(this, buff, size, colorMap); 253 253 frame.addView(mGLView); 254 frame.addView(colorBar);254 //frame.addView(colorBar); 255 255 } 256 256 //------------------------------------------------------------------------------------ -
issm/trunk-jpl/src/android/ISSM/src/com/example/issm/MyGLRenderer.java
r14210 r14249 30 30 { 31 31 public volatile float mAngle; 32 32 public volatile float mAngleX; /* NEW STUFF*/ 33 public volatile float mAngleY; 34 35 36 private FloatBuffer[] triangleVert; 37 38 private float[][] mScaleMatrix; // scaling /* NEW STUFF*/ 39 private float[][] mRotXMatrix; // rotation x 40 private float[][] mRotYMatrix; // rotation x 41 33 42 /** 34 43 * Store the model matrix. This matrix is used to move models from object space (where each model can be thought … … 52 61 private int mMatrixHandle; 53 62 54 private FloatBuffer[] triangleVert;55 56 63 private float[][] triangleData2DArr; 57 64 … … 78 85 private final int mColorDataSize = 4; 79 86 87 // scaling /* NEW STUFF*/ 88 float scaleX = 1.0f; 89 float scaleY = 1.0f; 90 float scaleZ = 1.0f; 91 92 public float eyeX; 93 public float eyeY; 94 public float eyeZ; 95 80 96 public MyGLRenderer(float[][] vertices) 81 97 { 82 98 triangleData2DArr = new float[vertices.length][21]; 99 83 100 triangleVert = new FloatBuffer[vertices.length]; 101 mScaleMatrix = new float[triangleVert.length][16]; // scaling /* NEW STUFF*/ 102 mRotXMatrix = new float[triangleVert.length][16]; // rotation x 103 mRotYMatrix = new float[triangleVert.length][16]; // rotation x 84 104 85 105 for (int i = 0; i < vertices.length; i++) … … 88 108 triangleData2DArr[i][j] = vertices[i][j]; 89 109 } 90 110 91 111 // initialize vertex byte buffer for shape coordinates 92 112 for (int i = 0; i < vertices.length; i++) … … 98 118 } 99 119 120 public void changeScale(float scale) /* NEW STUFF*/ 121 { 122 if (scaleX * scale > 3.0f) return; 123 scaleX *= scale; scaleY *= scale; scaleZ *= scale; 124 125 //scaleX += scale;scaleY += scale;scaleZ += scale; 126 //scaleX = scale;scaleY = scale;scaleZ = scale; 127 //scaleX /= 100;scaleY /= 100;scaleZ /= 100; 128 } 129 130 public void defaultScale() 131 { 132 scaleX = 1f; 133 scaleY = 1f; 134 scaleZ = 1f; 135 } 136 100 137 public void onSurfaceCreated(GL10 unused, EGLConfig config) 101 138 { 102 139 // Set the background frame color 103 GLES20.glClearColor(0.0f, 0. 8f, 1.0f, 1.0f);140 GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 104 141 105 142 // Position the eye behind the origin. 106 final floateyeX = 0.0f;107 final floateyeY = 0.0f;108 final floateyeZ = 1.5f;143 eyeX = 0.0f; 144 eyeY = 0.0f; 145 eyeZ = 1.5f; 109 146 110 147 // We are looking toward the distance … … 123 160 mViewMatrix = new float[triangleVert.length][16]; 124 161 162 125 163 for (int i = 0; i < triangleVert.length; i++) 126 164 Matrix.setLookAtM(mViewMatrix[i], 0, eyeX, eyeY, eyeZ, lookX, lookY, lookZ, upX, upY, upZ); 165 //Matrix.setLookAtM(mVMatrix[i], 0, 0, 0, -5.0f, 0.0f, 0f, 0f, 0f, 1.0f, 0.0f); 127 166 128 167 final String vertexShader = … … 134 173 + "{ \n" 135 174 + " v_Color = a_Color; \n" // Pass the color through to the fragment shader. 175 136 176 // It will be interpolated across the triangle. 137 177 + " gl_Position = u_MVPMatrix \n" // gl_Position is a special variable used to store the final position. … … 197 237 GLES20.glBindAttribLocation(mProgram, 0, "a_Position"); 198 238 GLES20.glBindAttribLocation(mProgram, 1, "a_Color"); 199 239 200 240 // Link the two shaders together into a program. 201 241 GLES20.glLinkProgram(mProgram); … … 214 254 for (int i = 0; i < triangleVert.length; i++) 215 255 { 216 mMatrixHandle = GLES20.glGetUniformLocation(mProgram, "u_MVPMatrix"); 256 mMatrixHandle = GLES20.glGetUniformLocation(mProgram, "u_MVPMatrix"); 217 257 mPositionHandle = GLES20.glGetAttribLocation(mProgram, "a_Position"); 218 258 mColorHandle = GLES20.glGetAttribLocation(mProgram, "a_Color"); … … 222 262 GLES20.glUseProgram(mProgram); 223 263 } 224 225 264 public void onSurfaceChanged(GL10 unused, int width, int height) 226 265 { … … 236 275 for (int i = 0; i < triangleVert.length; i++) 237 276 Matrix.frustumM(mProjectionMatrix[i], 0, -ratio*0.7f, ratio*1.0f, 0.0f, 1.0f, 1.0f, 14f); 238 //Matrix.frustumM(m, offset, left, right, bottom, top, near, far)239 277 } 240 278 … … 247 285 // Draw the triangle facing straight on. 248 286 for (int i = 0; i < triangleVert.length; i++) 249 Matrix.setIdentityM(mModelMatrix[i], 0); 287 { 288 //Matrix.setIdentityM(mModelMatrix[i], 0); /* NEW STUFF*/ 289 Matrix.setIdentityM(mScaleMatrix[i], 0); 290 Matrix.scaleM(mScaleMatrix[i], 0, scaleX, scaleY, scaleZ); 291 292 // Rotation along x 293 Matrix.setRotateM(mRotXMatrix[i], 0, this.mAngleY, -1.0f, 0.0f, 0.0f); 294 Matrix.setRotateM(mRotYMatrix[i], 0, this.mAngleX, 0.0f, 1.0f, 0.0f); /* NEW STUFF*/ 295 296 Matrix.setLookAtM(mViewMatrix[i], 0, eyeX, eyeY, eyeZ, 0.0f, 0.0f, -5.0f, 0.0f, 1.0f, 0.0f); 297 298 } 250 299 251 300 mMVPMatrix = new float[triangleVert.length][16]; … … 273 322 GLES20.glEnableVertexAttribArray(mColorHandle); 274 323 275 //Matrix.setRotateM(mModelMatrix[i], 0, mAngle, 0, 0, -1.0f); 324 Matrix.setRotateM(mRotXMatrix[i], 0, this.mAngleY, -1.0f, 0.0f, 0.0f); /* NEW STUFF*/ 325 Matrix.setRotateM(mRotYMatrix[i], 0, this.mAngleX, 0.0f, 1.0f, 0.0f); 326 327 float tempMatrix[][] = new float[triangleVert.length][16]; /* NEW STUFF*/ 328 Matrix.multiplyMM(tempMatrix[i], 0, mRotYMatrix[i], 0, mRotXMatrix[i], 0); 329 Matrix.multiplyMM(mModelMatrix[i], 0, mScaleMatrix[i], 0, tempMatrix[i], 0); 276 330 277 331 // This multiplies the view matrix by the model matrix, and stores the result in the MVP matrix … … 283 337 Matrix.multiplyMM(mMVPMatrix[i], 0, mProjectionMatrix[i], 0, mMVPMatrix[i], 0); 284 338 285 GLES20.glUniformMatrix4fv(mMatrixHandle, 1, false, mMVPMatrix[i], 0); 286 339 GLES20.glUniformMatrix4fv(mMatrixHandle, 1, false, mMVPMatrix[i], 0); 340 287 341 // Draw the triangle 288 342 GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 3); -
issm/trunk-jpl/src/android/ISSM/src/com/example/issm/MyGLSurfaceView.java
r14246 r14249 6 6 import android.content.Context; 7 7 import android.opengl.GLSurfaceView; 8 import android.util.FloatMath; 8 9 import android.view.MotionEvent; 9 10 … … 17 18 final int firstVelocity = 9; 18 19 ColorMap colorMap; 20 21 // pinch to zoom 22 float oldDist = 100.0f; 23 float newDist; 24 25 int mode = 0; 19 26 public MyGLSurfaceView(Context context, DoubleBuffer db, int size, ColorMap colorMap) 20 27 { … … 152 159 153 160 private float mPreviousY; 161 // touch events 162 private final int NONE = 0; 163 private final int DRAG = 0; 164 private final int ZOOM = 0; 154 165 @Override 155 public boolean onTouchEvent(MotionEvent e) { 156 // MotionEvent reports input details from the touch screen 157 // and other input controls. In this case, you are only 158 // interested in events where the touch position changed. 159 160 float x = e.getX(); 161 float y = e.getY(); 162 163 switch (e.getAction()) { 164 case MotionEvent.ACTION_MOVE: 165 166 float dx = x - mPreviousX; 167 float dy = y - mPreviousY; 168 169 // reverse direction of rotation above the mid-line 170 if (y > getHeight() / 2) { 171 dx = dx * -1 ; 172 } 173 174 // reverse direction of rotation to left of the mid-line 175 if (x < getWidth() / 2) { 176 dy = dy * -1 ; 177 } 178 179 mRend.mAngle += (dx + dy) * TOUCH_SCALE_FACTOR; // = 180.0f / 320 180 requestRender(); 181 } 182 183 mPreviousX = x; 184 mPreviousY = y; 185 return true; 186 } 166 public boolean onTouchEvent(MotionEvent e) /* NEW STUFF*/ 167 { 168 float x = e.getX(); 169 float y = e.getY(); 170 switch (e.getAction()) { 171 case MotionEvent.ACTION_DOWN: // one touch: drag 172 mode = DRAG; 173 //mRend.eyeX = e.getX(); 174 //mRend.eyeY = e.getY; 175 break; 176 177 case MotionEvent.ACTION_POINTER_DOWN: // two touches: zoom 178 oldDist = spacing(e); 179 if (oldDist > 10.0f) 180 mode = ZOOM; // zoom 181 break; 182 183 case MotionEvent.ACTION_UP: // no mode 184 mode = NONE; 185 oldDist = 100.0f; 186 break; 187 188 case MotionEvent.ACTION_POINTER_UP: // no mode 189 mode = NONE; 190 oldDist = 100.0f; 191 break; 192 193 case MotionEvent.ACTION_MOVE: // rotation 194 if (e.getPointerCount() > 1 && mode == ZOOM) 195 { 196 newDist = spacing(e); 197 if (newDist > 10.0f) { 198 float scale = newDist/oldDist; // scale 199 200 // scale in the renderer 201 mRend.changeScale(scale); 202 oldDist = newDist; 203 } 204 } 205 else if (mode == DRAG) 206 { 207 float dx = x - mPreviousX; 208 float dy = y - mPreviousY; 209 210 mRend.mAngleX += dx * TOUCH_SCALE_FACTOR; 211 mRend.mAngleY += dy * TOUCH_SCALE_FACTOR; 212 213 requestRender(); 214 } 215 break; 216 } 217 mPreviousX = x; 218 mPreviousY = y; 219 return true; 220 } 221 222 private float spacing(MotionEvent event) /* NEW STUFF*/ 223 { 224 float x = event.getX(0) - event.getX(1); 225 float y = event.getY(0) - event.getY(1); 226 return FloatMath.sqrt(x * x + y * y); 227 } 187 228 } 229
Note:
See TracChangeset
for help on using the changeset viewer.