JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestMatrix4fMatrixMulNOUI.java
Go to the documentation of this file.
1/**
2 * Copyright 2012 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 */
28
29package com.jogamp.opengl.test.junit.math;
30
31import org.junit.Assert;
32import org.junit.Test;
33import org.junit.FixMethodOrder;
34import org.junit.runners.MethodSorters;
35
36import com.jogamp.junit.util.JunitTracer;
37import com.jogamp.math.Matrix4f;
38
39@FixMethodOrder(MethodSorters.NAME_ASCENDING)
40public class TestMatrix4fMatrixMulNOUI extends JunitTracer {
41
42 final Matrix4f m1 = new Matrix4f(new float[]{
43 1, 3, 4, 0,
44 6, 7, 8, 5,
45 98, 7, 6, 9,
46 54, 3, 2, 5 });
47
48 final Matrix4f m2 = new Matrix4f(new float[]{
49 1, 6, 98, 54,
50 3, 7, 7, 3,
51 4, 8, 6, 2,
52 0, 5, 9, 5 });
53
54 final Matrix4f m2xm1 =
55 new Matrix4f(new float[]{
56 26, 59, 143, 71,
57 59, 174, 730, 386,
58 143, 730, 9770, 5370,
59 71, 386, 5370, 2954 });
60
61 final Matrix4f m1xm2 =
62 new Matrix4f(new float[]{
63 12557, 893, 748, 1182,
64 893, 116, 116, 113,
65 748, 116, 120, 104,
66 1182, 113, 104, 131 });
67
68 public static final void multMatrixf_RM(final Matrix4f a, final Matrix4f b, final Matrix4f d) {
69 for (int i = 0; i < 4; i++) {
70 final float ai0=a.get(i*4+0), ai1=a.get(i*4+1), ai2=a.get(i*4+2), ai3=a.get(i*4+3);
71 d.set(i*4+0, ai0 * b.get(0*4+0) + ai1 * b.get(1*4+0) + ai2 * b.get(2*4+0) + ai3 * b.get(3*4+0) );
72 d.set(i*4+1, ai0 * b.get(0*4+1) + ai1 * b.get(1*4+1) + ai2 * b.get(2*4+1) + ai3 * b.get(3*4+1) );
73 d.set(i*4+2, ai0 * b.get(0*4+2) + ai1 * b.get(1*4+2) + ai2 * b.get(2*4+2) + ai3 * b.get(3*4+2) );
74 d.set(i*4+3, ai0 * b.get(0*4+3) + ai1 * b.get(1*4+3) + ai2 * b.get(2*4+3) + ai3 * b.get(3*4+3) );
75 }
76 }
77
78 @Test
79 public void testCM_m1xm2(){
80 final Matrix4f r = new Matrix4f();
81 r.mul(m1, m2);
82 Assert.assertEquals(m1xm2, r);
83 }
84
85 @Test
86 public void testCM_m2xm1(){
87 final Matrix4f r = new Matrix4f();
88 r.mul(m2, m1);
89 Assert.assertEquals(m2xm1, r);
90 }
91
92 @Test
93 public void testRM_m1xm2(){
94 final Matrix4f r1 = new Matrix4f();
95 final Matrix4f r2 = new Matrix4f();
96 multMatrixf_RM(m1, m2, r1);
97 Assert.assertEquals(m2xm1, r1);
98
99 r2.mul(m1, m2).transpose();
100 Assert.assertEquals(m2xm1, r1);
101 }
102
103 @Test
104 public void testRM_m2xm1(){
105 final Matrix4f r1 = new Matrix4f();
106 final Matrix4f r2 = new Matrix4f();
107 multMatrixf_RM(m2, m1, r1);
108 Assert.assertEquals(m1xm2, r1);
109
110 r2.mul(m2, m1).transpose();
111 Assert.assertEquals(m1xm2, r1);
112 }
113
114 public static void main(final String args[]) {
115 org.junit.runner.JUnitCore.main(TestMatrix4fMatrixMulNOUI.class.getName());
116 }
117}
Basic 4x4 float matrix implementation using fields for intensive use-cases (host operations).
Definition: Matrix4f.java:89
final Matrix4f mul(final Matrix4f b)
Multiply matrix: [this] = [this] x [b].
Definition: Matrix4f.java:726
final Matrix4f transpose()
Transpose this matrix.
Definition: Matrix4f.java:464
float get(final int i)
Gets the ith component, 0 <= i < 16.
Definition: Matrix4f.java:279
void set(final int i, final float v)
Sets the ith component with float v 0 <= i < 16.
Definition: Matrix4f.java:136
static final void multMatrixf_RM(final Matrix4f a, final Matrix4f b, final Matrix4f d)