28package com.jogamp.opengl.test.junit.math;
30import java.util.Arrays;
32import com.jogamp.common.nio.Buffers;
33import com.jogamp.junit.util.JunitTracer;
34import com.jogamp.math.FloatUtil;
35import com.jogamp.math.Matrix4f;
36import com.jogamp.math.Recti;
37import com.jogamp.math.Vec3f;
38import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
39import com.jogamp.opengl.glu.GLU;
41import jogamp.opengl.gl2.ProjectDouble;
43import com.jogamp.opengl.util.PMVMatrix;
45import org.junit.Assert;
47import org.junit.FixMethodOrder;
48import org.junit.runners.MethodSorters;
50@FixMethodOrder(MethodSorters.NAME_ASCENDING)
53 static final float epsilon = 0.00001f;
56 static final Recti viewport =
new Recti(0,0,10,10);
57 static final int[] viewport_i4 =
new int[] { 0, 0, 10, 10 };
78 System.err.println(mat4PMv.
toString(
null,
"mat4PMv",
"%10.5f"));
81 System.err.println(
"A.0.0 - Project 1,0 -->" + winA00);
83 System.err.println(
"B.0.0 - Project 1,0 -->" + winB00);
86 System.err.println(
"A.0.1 - Project 0,0 -->" + winA01);
88 System.err.println(
"B.0.1 - Project 0,0 -->" + winB01);
92 System.err.println(
"MATRIX - Ortho 0,0,10,10 - Locate the origin in the bottom left and scale");
93 System.err.println(m);
95 System.err.println(mat4PMv.
toString(
null,
"mat4PMv",
"%10.5f"));
98 System.err.println(
"A.1.0 - Project 1,0 -->" +winA10);
100 System.err.println(
"B.1.0 - Project 1,0 -->" +winB10);
103 System.err.println(
"A.1.1 - Project 0,0 -->" +winA11);
105 System.err.println(
"B.1.1 - Project 0,0 -->" +winB11);
107 Assert.assertEquals(
"A/B 0.0 Project 1,0 failure", winB00, winA00);
108 Assert.assertEquals(
"A/B 0.1 Project 0,0 failure", winB01, winA01);
109 Assert.assertEquals(
"A/B 1.0 Project 1,0 failure", winB10, winA10);
110 Assert.assertEquals(
"A/B 1.1 Project 0,0 failure", winB11, winA11);
132 final float[] mat4Mv_f16 =
new float[16];
133 final float[] mat4P_f16 =
new float[16];
141 Assert.assertEquals(
new Matrix4f(mat4Mv_f16), mat4Mv);
142 Assert.assertEquals(
new Matrix4f(mat4P_f16), mat4P);
143 Assert.assertEquals(mat4Mv, m.
getMv());
144 Assert.assertEquals(mat4P, m.
getP());
147 System.err.println(
"A.0.0 - Project 1,0 -->" + winA00);
149 System.err.println(
"B.0.0 - Project 1,0 -->" + winB00);
152 System.err.println(
"A.0.1 - Project 0,0 -->" + winA01);
154 System.err.println(
"B.0.1 - Project 0,0 -->" + winB01);
158 System.err.println(
"MATRIX - Ortho 0,0,10,10 - Locate the origin in the bottom left and scale");
159 System.err.println(m);
166 Assert.assertEquals(
new Matrix4f(mat4Mv_f16), mat4Mv);
167 Assert.assertEquals(
new Matrix4f(mat4P_f16), mat4P);
168 Assert.assertEquals(mat4Mv, m.
getMv());
169 Assert.assertEquals(mat4P, m.
getP());
172 System.err.println(
"A.1.0 - Project 1,0 -->" +winA10);
174 System.err.println(
"B.1.0 - Project 1,0 -->" +winB10);
177 System.err.println(
"A.1.1 - Project 0,0 -->" +winA11);
179 System.err.println(
"B.1.1 - Project 0,0 -->" +winB11);
181 Assert.assertEquals(
"A/B 0.0 Project 1,0 failure", winB00, winA00);
182 Assert.assertEquals(
"A/B 0.1 Project 0,0 failure", winB01, winA01);
183 Assert.assertEquals(
"A/B 1.0 Project 1,0 failure", winB10, winA10);
184 Assert.assertEquals(
"A/B 1.1 Project 0,0 failure", winB11, winA11);
192 final float[] winA00 =
new float[4];
193 final float[] winA01 =
new float[4];
194 final float[] winA10 =
new float[4];
195 final float[] winA11 =
new float[4];
204 final float[] mat4Mv_f16 =
new float[16];
205 final float[] mat4P_f16 =
new float[16];
206 final GLU glu =
new GLU();
215 glu.
gluProject(1f, 0f, 0f, mat4Mv_f16, 0, mat4P_f16, 0, viewport_i4, 0, winA00, 0);
216 System.err.println(
"A.0.0 - Project 1,0 -->" + winA00);
218 System.err.println(
"B.0.0 - Project 1,0 -->" + winB00);
220 glu.
gluProject(0f, 0f, 0f, mat4Mv_f16, 0, mat4P_f16, 0, viewport_i4, 0, winA01, 0);
221 System.err.println(
"A.0.1 - Project 0,0 -->" + winA01);
223 System.err.println(
"B.0.1 - Project 0,0 -->" + winB01);
227 System.err.println(
"MATRIX - Ortho 0,0,10,10 - Locate the origin in the bottom left and scale");
228 System.err.println(m);
236 glu.
gluProject(1f, 0f, 0f, mat4Mv_f16, 0, mat4P_f16, 0, viewport_i4, 0, winA10, 0);
237 System.err.println(
"A.1.0 - Project 1,0 -->" +winA10);
239 System.err.println(
"B.1.0 - Project 1,0 -->" +winB10);
241 glu.
gluProject(0f, 0f, 0f, mat4Mv_f16, 0, mat4P_f16, 0, viewport_i4, 0, winA11, 0);
242 System.err.println(
"A.1.1 - Project 0,0 -->" +winA11);
244 System.err.println(
"B.1.1 - Project 0,0 -->" +winB11);
246 Assert.assertEquals(
"A/B 0.0 Project 1,0 failure", winB00,
new Vec3f(winA00));
247 Assert.assertEquals(
"A/B 0.1 Project 0,0 failure", winB01,
new Vec3f(winA01));
248 Assert.assertEquals(
"A/B 1.0 Project 1,0 failure", winB10,
new Vec3f(winA10));
249 Assert.assertEquals(
"A/B 1.1 Project 0,0 failure", winB11,
new Vec3f(winA11));
257 final double[] winA00 =
new double[3];
258 final double[] winA01 =
new double[3];
259 final double[] winA10 =
new double[3];
260 final double[] winA11 =
new double[3];
269 final float[] mat4Mv_f16 =
new float[16];
270 final float[] mat4P_f16 =
new float[16];
271 final ProjectDouble glu =
new ProjectDouble();
279 double[] mat4Mv_d16 = Buffers.getDoubleArray(mat4Mv_f16, 0,
null, 0, -1);
280 double[] mat4P_d16 = Buffers.getDoubleArray(mat4P_f16, 0,
null, 0, -1);
282 glu.gluProject(1f, 0f, 0f, mat4Mv_d16, 0, mat4P_d16, 0, viewport_i4, 0, winA00, 0);
283 System.err.println(
"A.0.0 - Project 1,0 -->" + Arrays.toString(winA00));
285 System.err.println(
"B.0.0 - Project 1,0 -->" + winB00);
287 glu.gluProject(0f, 0f, 0f, mat4Mv_d16, 0, mat4P_d16, 0, viewport_i4, 0, winA01, 0);
288 System.err.println(
"A.0.1 - Project 0,0 -->" + Arrays.toString(winA01));
290 System.err.println(
"B.0.1 - Project 0,0 -->" + winB01);
294 System.err.println(
"MATRIX - Ortho 0,0,10,10 - Locate the origin in the bottom left and scale");
295 System.err.println(m);
302 mat4Mv_d16 = Buffers.getDoubleArray(mat4Mv_f16, 0,
null, 0, -1);
303 mat4P_d16 = Buffers.getDoubleArray(mat4P_f16, 0,
null, 0, -1);
305 glu.gluProject(1f, 0f, 0f, mat4Mv_d16, 0, mat4P_d16, 0, viewport_i4, 0, winA10, 0);
306 System.err.println(
"A.1.0 - Project 1,0 -->" +Arrays.toString(winA10));
308 System.err.println(
"B.1.0 - Project 1,0 -->" +winB10);
310 glu.gluProject(0f, 0f, 0f, mat4Mv_d16, 0, mat4P_d16, 0, viewport_i4, 0, winA11, 0);
311 System.err.println(
"A.1.1 - Project 0,0 -->" +Arrays.toString(winA11));
313 System.err.println(
"B.1.1 - Project 0,0 -->" +winB11);
315 final float[] tmp =
new float[3];
316 double[] d_winBxx = Buffers.getDoubleArray(winB00.
get(tmp), 0,
null, 0, -1);
317 Assert.assertArrayEquals(
"A/B 0.0 Project 1,0 failure", d_winBxx, winA00, epsilon);
318 d_winBxx = Buffers.getDoubleArray(winB01.
get(tmp), 0,
null, 0, -1);
319 Assert.assertArrayEquals(
"A/B 0.1 Project 0,0 failure", d_winBxx, winA01, epsilon);
320 d_winBxx = Buffers.getDoubleArray(winB10.
get(tmp), 0,
null, 0, -1);
321 Assert.assertArrayEquals(
"A/B 1.0 Project 1,0 failure", d_winBxx, winA10, epsilon);
322 d_winBxx = Buffers.getDoubleArray(winB11.
get(tmp), 0,
null, 0, -1);
323 Assert.assertArrayEquals(
"A/B 1.1 Project 0,0 failure", d_winBxx, winA11, epsilon);
326 public static void main(
final String args[]) {
Basic Float math utility functions.
static StringBuilder matrixToString(StringBuilder sb, final String rowPrefix, final String f, final FloatBuffer a, final int aOffset, final int rows, final int columns, final boolean rowMajorOrder)
Basic 4x4 float matrix implementation using fields for intensive use-cases (host operations).
static boolean mapObjToWin(final Vec3f obj, final Matrix4f mMv, final Matrix4f mP, final Recti viewport, final Vec3f winPos)
Map object coordinates to window coordinates.
Matrix4f load(final Matrix4f src)
Load the values of the given matrix src to this matrix.
StringBuilder toString(final StringBuilder sb, final String rowPrefix, final String f)
Rectangle with x, y, width and height integer components.
3D Vector based upon three float components.
float[] get(final float[] xyz)
xyz = this, returns xyz.
final Matrix4f getMulPMv(final Matrix4f result)
Returns multiplication result of P and Mv matrix, i.e.
final Matrix4f getMv()
Returns the modelview matrix (Mv).
final Matrix4f getP()
Returns the projection matrix (P).
final boolean mapObjToWin(final Vec3f objPos, final Recti viewport, final Vec3f winPos)
Map object coordinates to window coordinates.
Provides access to the OpenGL Utility Library (GLU).
boolean gluProject(float objX, float objY, float objZ, float[] model, int model_offset, float[] proj, int proj_offset, int[] view, int view_offset, float[] winPos, int winPos_offset)
Interface to C language function: GLint gluProject(GLdouble objX, GLdouble objY,...
void test01PMVMatrixToMatrix4f2()
PMVMatrix vs Matrix4f.mapObjToWin(), both w/ separate P + Mv.
static void main(final String args[])
void test01PMVMatrixToMatrix4f()
PMVMatrix w/ separate P + Mv vs Matrix4f.mapObjToWin() w/ single PMv.
void test04GLUDoubleToMatrix4f2()
GLU ProjectDouble vs Matrix4f.mapObjToWin(), both w/ separate P + Mv.
void test03GLUToMatrix4f2()
GLU ProjectFloat vs Matrix4f.mapObjToWin(), both w/ separate P + Mv.
PMVMatrix implements a subset of the fixed function pipeline GLMatrixFunc using PMVMatrix4f.
final void glMatrixMode(final int matrixName)
Sets the current matrix mode.
final Matrix4f getMat(final int matrixName)
final void glGetFloatv(final int matrixGetName, final FloatBuffer params)
final void glOrthof(final float left, final float right, final float bottom, final float top, final float zNear, final float zFar)
Multiply the current matrix with the orthogonal matrix.
Subset of OpenGL fixed function pipeline's matrix operations.
static final int GL_PROJECTION
Matrix mode projection.
static final int GL_MODELVIEW_MATRIX
Matrix access name for modelview.
static final int GL_PROJECTION_MATRIX
Matrix access name for projection.