JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestMatrix4fProject02NOUI.java
Go to the documentation of this file.
1/**
2 * Copyright 2014-2023 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28package com.jogamp.opengl.test.junit.math;
29
30import java.util.Arrays;
31
32import com.jogamp.junit.util.JunitTracer;
33import com.jogamp.math.FloatUtil;
34import com.jogamp.math.Matrix4f;
35import com.jogamp.math.Recti;
36import com.jogamp.math.Vec2f;
37import com.jogamp.math.Vec3f;
38
39import org.junit.Assert;
40import org.junit.Test;
41import org.junit.FixMethodOrder;
42import org.junit.runners.MethodSorters;
43
44@FixMethodOrder(MethodSorters.NAME_ASCENDING)
45public class TestMatrix4fProject02NOUI extends JunitTracer {
46
47 static final float epsilon = 0.00001f;
48
49 @Test
50 public void test01() {
51 final Vec3f winHas = new Vec3f();
52 final Vec2f winExp = new Vec2f( 297, 360 );
53
54 final Recti viewport = new Recti(0, 0, 1280, 720);
55
56 final Matrix4f mat4Mv = new Matrix4f(new float[] {
57 0.40000000596046450000f, 0.00000000000000000000f, 0.00000000000000000000f, 0.00000000000000000000f,
58 0.00000000000000000000f, 0.40000000596046450000f, 0.00000000000000000000f, 0.00000000000000000000f,
59 0.00000000000000000000f, 0.00000000000000000000f, 1.00000000000000000000f, 0.00000000000000000000f,
60 -0.09278385341167450000f, -0.00471283448860049250f, -0.20000000298023224000f, 1.00000000000000000000f });
61
62 final Matrix4f mat4P = new Matrix4f(new float[] {
63 1.35799503326416020000f, 0.00000000000000000000f, 0.00000000000000000000f, 0.00000000000000000000f,
64 0.00000000000000000000f, 2.41421341896057130000f, 0.00000000000000000000f, 0.00000000000000000000f,
65 0.00000000000000000000f, 0.00000000000000000000f, -1.00002861022949220000f, -1.00000000000000000000f,
66 0.00000000000000000000f, 0.00000000000000000000f, -0.20000286400318146000f, 0.00000000000000000000f });
67
68 final Vec3f objPos = new Vec3f(0.02945519052445888500f, 0.01178207620978355400f, -0.00499999988824129100f);
69
70 System.err.println("pMv");
71 System.err.println(mat4Mv.toString(null, "", "%25.20ff"));
72 System.err.println("pP");
73 System.err.println(mat4P.toString(null, "", "%25.20ff"));
74
75 Matrix4f.mapObjToWin(objPos, mat4Mv, mat4P, viewport, winHas);
76 System.err.println("B.0.0 - Project 1,0 -->" + winHas);
77
78 Assert.assertEquals("A/B 0.0 Project 1,0 failure.x", winExp.x(), Math.round(winHas.x()), epsilon);
79 Assert.assertEquals("A/B 0.0 Project 1,0 failure.y", winExp.y(), Math.round(winHas.y()), epsilon);
80 }
81
82 @Test
83 public void test02() {
84 final Vec3f winHas = new Vec3f();
85 final Vec2f winExp = new Vec2f( 136, 360 );
86
87 final Recti viewport = new Recti(0, 0, 1280, 720);
88
89 // m30 (row 3, column 0) differs from test01
90 final Matrix4f mat4Mv = new Matrix4f(new float[] {
91 0.40000000596046450000f, 0.00000000000000000000f, 0.00000000000000000000f, 0.00000000000000000000f,
92 0.00000000000000000000f, 0.40000000596046450000f, 0.00000000000000000000f, 0.00000000000000000000f,
93 0.00000000000000000000f, 0.00000000000000000000f, 1.00000000000000000000f, 0.00000000000000000000f,
94 -0.13065303862094880000f, -0.00471283448860049250f, -0.20000000298023224000f, 1.00000000000000000000f });
95
96 final Matrix4f mat4P = new Matrix4f(new float[] {
97 1.35799503326416020000f, 0.00000000000000000000f, 0.00000000000000000000f, 0.00000000000000000000f,
98 0.00000000000000000000f, 2.41421341896057130000f, 0.00000000000000000000f, 0.00000000000000000000f,
99 0.00000000000000000000f, 0.00000000000000000000f, -1.00002861022949220000f, -1.00000000000000000000f,
100 0.00000000000000000000f, 0.00000000000000000000f, -0.20000286400318146000f, 0.00000000000000000000f });
101
102 final Vec3f objPos = new Vec3f(0.02945519052445888500f, 0.01178207620978355400f, -0.00499999988824129100f);
103
104 System.err.println("pMv");
105 System.err.println(mat4Mv.toString(null, "", "%25.20ff"));
106 System.err.println("pP");
107 System.err.println(mat4P.toString(null, "", "%25.20ff"));
108
109 Matrix4f.mapObjToWin(objPos, mat4Mv, mat4P, viewport, winHas);
110 System.err.println("B.0.0 - Project 1,0 -->" + winHas);
111
112 Assert.assertEquals("A/B 0.0 Project 1,0 failure.x", winExp.x(), Math.round(winHas.x()), epsilon);
113 Assert.assertEquals("A/B 0.0 Project 1,0 failure.y", winExp.y(), Math.round(winHas.y()), epsilon);
114 }
115
116 public static void main(final String args[]) {
117 org.junit.runner.JUnitCore.main(TestMatrix4fProject02NOUI.class.getName());
118 }
119}
Basic 4x4 float matrix implementation using fields for intensive use-cases (host operations).
Definition: Matrix4f.java:89
static boolean mapObjToWin(final Vec3f obj, final Matrix4f mMv, final Matrix4f mP, final Recti viewport, final Vec3f winPos)
Map object coordinates to window coordinates.
Definition: Matrix4f.java:1696
StringBuilder toString(final StringBuilder sb, final String rowPrefix, final String f)
Definition: Matrix4f.java:2085
Rectangle with x, y, width and height integer components.
Definition: Recti.java:34
2D Vector based upon two float components.
Definition: Vec2f.java:37
3D Vector based upon three float components.
Definition: Vec3f.java:37