summaryrefslogtreecommitdiffstats
path: root/opengl/java/android/opengl/Matrix.java
diff options
context:
space:
mode:
authorJack Palevich <jackpal@google.com>2011-04-21 14:52:37 -0700
committerJack Palevich <jackpal@google.com>2011-04-21 14:52:37 -0700
commitd793299e875a97dc73e04e3beb2a2865563dccdb (patch)
treee8cdc375a5debec366cb3a6138226c1ab5ed4fe3 /opengl/java/android/opengl/Matrix.java
parentbf96c356c02c430153c281fb81dc1a00f7ad0b43 (diff)
downloadframeworks_base-d793299e875a97dc73e04e3beb2a2865563dccdb.zip
frameworks_base-d793299e875a97dc73e04e3beb2a2865563dccdb.tar.gz
frameworks_base-d793299e875a97dc73e04e3beb2a2865563dccdb.tar.bz2
Add utility method Matrix.perspectiveM
Change-Id: Ic9d5e5d967bbc08acc524c5092ce61a1cdbfd360
Diffstat (limited to 'opengl/java/android/opengl/Matrix.java')
-rw-r--r--opengl/java/android/opengl/Matrix.java39
1 files changed, 37 insertions, 2 deletions
diff --git a/opengl/java/android/opengl/Matrix.java b/opengl/java/android/opengl/Matrix.java
index b9fd4ab..a412a43 100644
--- a/opengl/java/android/opengl/Matrix.java
+++ b/opengl/java/android/opengl/Matrix.java
@@ -16,8 +16,6 @@
package android.opengl;
-import javax.microedition.khronos.opengles.GL10;
-
/**
* Matrix math utilities. These methods operate on OpenGL ES format
* matrices and vectors stored in float arrays.
@@ -332,6 +330,43 @@ public class Matrix {
}
/**
+ * Define a projection matrix in terms of a field of view angle, an
+ * aspect ratio, and z clip planes
+ * @param m the float array that holds the perspective matrix
+ * @param offset the offset into float array m where the perspective
+ * matrix data is written
+ * @param fovy field of view in y direction, in degrees
+ * @param aspect width to height aspect ratio of the viewport
+ * @param zNear
+ * @param zFar
+ */
+ public static void perspectiveM(float[] m, int offset,
+ float fovy, float aspect, float zNear, float zFar) {
+ float f = 1.0f / (float) Math.tan(fovy * (Math.PI / 360.0));
+ float rangeReciprocal = 1.0f / (zNear - zFar);
+
+ m[offset + 0] = f / aspect;
+ m[offset + 1] = 0.0f;
+ m[offset + 2] = 0.0f;
+ m[offset + 3] = 0.0f;
+
+ m[offset + 4] = 0.0f;
+ m[offset + 5] = f;
+ m[offset + 6] = 0.0f;
+ m[offset + 7] = 0.0f;
+
+ m[offset + 8] = 0.0f;
+ m[offset + 9] = 0.0f;
+ m[offset + 10] = (zFar + zNear) * rangeReciprocal;
+ m[offset + 11] = -1.0f;
+
+ m[offset + 12] = 0.0f;
+ m[offset + 13] = 0.0f;
+ m[offset + 14] = 2.0f * zFar * rangeReciprocal;
+ m[offset + 15] = 0.0f;
+ }
+
+ /**
* Computes the length of a vector
*
* @param x x coordinate of a vector