JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
PMVMatrix4f.java
Go to the documentation of this file.
1/**
2 * Copyright 2009-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.math.util;
29
30import java.nio.Buffer;
31import java.nio.FloatBuffer;
32
33import com.jogamp.common.nio.Buffers;
34import com.jogamp.math.FloatUtil;
35import com.jogamp.math.Matrix4f;
36import com.jogamp.math.Quaternion;
37import com.jogamp.math.Ray;
38import com.jogamp.math.Recti;
39import com.jogamp.math.Vec3f;
40import com.jogamp.math.Vec4f;
41import com.jogamp.math.geom.AABBox;
42import com.jogamp.math.geom.Frustum;
43
44/**
45 * PMVMatrix4f implements the basic computer graphics {@link Matrix4f} pack using
46 * projection (P), modelview (Mv) and texture (T) {@link Matrix4f} operations.
47 * <p>
48 * Unlike {@link com.jogamp.opengl.util.PMVMatrix PMVMatrix}, this class doesn't implement
49 * {@link com.jogamp.opengl.fixedfunc.GLMatrixFunc GLMatrixFunc} and is OpenGL agnostic.
50 * </p>
51 * <p>
52 * This is the second implementation of `PMVMatrix4f` using
53 * direct {@link Matrix4f}, {@link Vec4f} and {@link Vec3f} math operations instead of `float[]`
54 * via {@link com.jogamp.math.FloatUtil FloatUtil}.
55 * </p>
56 * <p>
57 * PMVMatrix4f provides the {@link #getMvi() inverse modelview matrix (Mvi)} and
58 * {@link #getMvit() inverse transposed modelview matrix (Mvit)}.
59 * {@link Frustum} is also provided by {@link #getFrustum()}.
60 *
61 * To keep these derived values synchronized after mutable Mv operations like {@link #rotateMv(Quaternion)}
62 * users have to call {@link #update()} before using Mvi and Mvit.
63 * </p>
64 * <p>
65 * All matrices are provided in column-major order,
66 * as specified in the OpenGL fixed function pipeline, i.e. compatibility profile.
67 * See {@link Matrix4f}.
68 * </p>
69 * <p>
70 * PMVMatrix4f can supplement {@link com.jogamp.opengl.GL2ES2 GL2ES2} applications w/ the
71 * lack of the described matrix functionality.
72 * </p>
73 * <a name="storageDetails"><h5>Matrix storage details</h5></a>
74 * <p>
75 * The {@link SyncBuffer} abstraction is provided, e.g. {@link #getSyncPMvMvi()},
76 * to synchronize the respective {@link Matrix4f matrices} with the `float[]` backing store.
77 * The latter is represents the data to {@link com.jogamp.opengl.GLUniformData} via its {@link FloatBuffer}s, see {@link SyncBuffer#getBuffer()},
78 * and is pushed to the GPU eventually.
79 * </p>
80 * <p>
81 * {@link SyncBuffer}'s {@link SyncAction} is called by {@link com.jogamp.opengl.GLUniformData#getBuffer()},
82 * i.e. before the data is pushed to the GPU.
83 * </p>
84 * <p>
85 * The provided {@link SyncAction} ensures that the {@link Matrix4f matrices data}
86 * gets copied into the `float[]` backing store.
87 * </p>
88 * <p>
89 * PMVMatrix4f provides two specializations of {@link SyncBuffer}, {@link SyncMatrix4f} for single {@link Matrix4f} mappings
90 * and {@link SyncMatrices4f} for multiple {@link Matrix4f} mappings.
91 * </p>
92 * <p>
93 * They can be feed directly to instantiate a {@link com.jogamp.opengl.GLUniformData} object via e.g. {@link com.jogamp.opengl.GLUniformData#GLUniformData(String, int, int, SyncBuffer)}.
94 * </p>
95 * <p>
96 * All {@link Matrix4f matrix} {@link SyncBuffer}'s backing store are backed up by a common primitive float-array for performance considerations
97 * and are a {@link Buffers#slice2Float(float[], int, int) sliced} representation of it.
98 * </p>
99 * <p>
100 * <b>{@link Matrix4f} {@link SyncBuffer}'s Backing-Store Notes:</b>
101 * <ul>
102 * <li>The {@link Matrix4f matrix} {@link SyncBuffer}'s backing store is a {@link Buffers#slice2Float(float[], int, int) sliced part } of a host matrix and it's start position has been {@link FloatBuffer#mark() marked}.</li>
103 * <li>Use {@link FloatBuffer#reset() reset()} to rewind it to it's start position after relative operations, like {@link FloatBuffer#get() get()}.</li>
104 * <li>If using absolute operations like {@link FloatBuffer#get(int) get(int)}, use it's {@link FloatBuffer#reset() reset} {@link FloatBuffer#position() position} as it's offset.</li>
105 * </ul>
106 * </p>
107 */
108public class PMVMatrix4f {
109
110 /** Bit value stating a modified {@link #getP() projection matrix (P)}, since last {@link #update()} call. */
111 public static final int MODIFIED_PROJECTION = 1 << 0;
112 /** Bit value stating a modified {@link #getMv() modelview matrix (Mv)}, since last {@link #update()} call. */
113 public static final int MODIFIED_MODELVIEW = 1 << 1;
114 /** Bit value stating a modified {@link #getT() texture matrix (T)}, since last {@link #update()} call. */
115 public static final int MODIFIED_TEXTURE = 1 << 2;
116 /** Bit value stating all is modified */
118 /** Bit value for {@link #getMvi() inverse modelview matrix (Mvi)}, updated via {@link #update()}. */
119 public static final int INVERSE_MODELVIEW = 1 << 1;
120 /** Bit value for {@link #getMvit() inverse transposed modelview matrix (Mvit)}, updated via {@link #update()}. */
121 public static final int INVERSE_TRANSPOSED_MODELVIEW = 1 << 2;
122 /** Bit value for {@link #getFrustum() frustum} and updated by {@link #getFrustum()}. */
123 public static final int FRUSTUM = 1 << 3;
124 /** Bit value for {@link #getPMv() pre-multiplied P * Mv}, updated by {@link #getPMv()}. */
125 public static final int PREMUL_PMV = 1 << 4;
126 /** Bit value for {@link #getPMvi() pre-multiplied invert(P * Mv)}, updated by {@link #getPMvi()}. */
127 public static final int PREMUL_PMVI = 1 << 5;
128 /** Manual bits not covered by {@link #update()} but {@link #getFrustum()}, {@link #FRUSTUM}, {@link #getPMv()}, {@link #PREMUL_PMV}, {@link #getPMvi()}, {@link #PREMUL_PMVI}, etc. */
129 public static final int MANUAL_BITS = FRUSTUM | PREMUL_PMV | PREMUL_PMVI;
130
131 /**
132 * Creates an instance of PMVMatrix4f.
133 * <p>
134 * This constructor only sets up an instance w/o additional {@link #INVERSE_MODELVIEW} or {@link #INVERSE_TRANSPOSED_MODELVIEW}.
135 * </p>
136 * <p>
137 * Implementation uses non-direct non-NIO Buffers with guaranteed backing array,
138 * which are synchronized to the actual Matrix4f instances.
139 * This allows faster access in Java computation.
140 * </p>
141 * @see #PMVMatrix4f(int)
142 */
143 public PMVMatrix4f() {
144 this(0);
145 }
146
147 /**
148 * Creates an instance of PMVMatrix4f.
149 * <p>
150 * Additional derived matrices can be requested via `derivedMatrices`, i.e.
151 * - {@link #INVERSE_MODELVIEW}
152 * - {@link #INVERSE_TRANSPOSED_MODELVIEW}
153 * </p>
154 * <p>
155 * Implementation uses non-direct non-NIO Buffers with guaranteed backing array,
156 * which are synchronized to the actual Matrix4f instances.
157 * This allows faster access in Java computation.
158 * </p>
159 * @param derivedMatrices additional matrices can be requested by passing bits {@link #INVERSE_MODELVIEW} and {@link #INVERSE_TRANSPOSED_MODELVIEW}.
160 * @see #getReqBits()
161 * @see #isReqDirty()
162 * @see #getDirtyBits()
163 * @see #update()
164 */
165 public PMVMatrix4f(final int derivedMatrices) {
166 // I Identity
167 // T Texture
168 // P Projection
169 // Mv ModelView
170 // Mvi Modelview-Inverse
171 // Mvit Modelview-Inverse-Transpose
172 {
173 int mask = 0;
174 if( 0 != ( derivedMatrices & ( INVERSE_MODELVIEW | INVERSE_TRANSPOSED_MODELVIEW ) ) ) {
175 mask |= INVERSE_MODELVIEW;
176 }
177 if( 0 != ( derivedMatrices & INVERSE_TRANSPOSED_MODELVIEW ) ) {
179 }
180 requestBits = mask;
181 }
182
183 // actual underlying Matrix4f count
184 int mcount = 3;
185
186 // actual underlying Matrix4f data
187 matP = new Matrix4f();
188 matMv = new Matrix4f();
189 matTex = new Matrix4f();
190
191 if( 0 != ( requestBits & INVERSE_MODELVIEW ) ) {
192 matMvi = new Matrix4f();
193 mMvi_offset = 2*16;
194 ++mcount;
195 } else {
196 matMvi = null;
197 mMvi_offset = -1;
198 }
199 if( 0 != ( requestBits & INVERSE_TRANSPOSED_MODELVIEW ) ) {
200 matMvit = new Matrix4f();
201 mMvit_offset = 3*16;
202 ++mcount;
203 } else {
204 matMvit = null;
205 mMvit_offset = -1;
206 }
207 mTex_offset = (mcount-1)*16; // last one
208
209 // float back buffer for GPU, Matrix4f -> matrixStore via SyncedBuffer
210 matrixStore = new float[mcount*16];
211
212 // FloatBuffer for single Matrix4f back-buffer
213 final FloatBuffer bufP = Buffers.slice2Float(matrixStore, mP_offset, 1*16); // P
214 syncP = new SyncBuffer0(matP, bufP); // mP_offset
215
216 final FloatBuffer bufMv = Buffers.slice2Float(matrixStore, mMv_offset, 1*16); // Mv
217 syncMv = new SyncBuffer1(matMv, bufMv, mMv_offset);
218
219 final FloatBuffer bufP_Mv = Buffers.slice2Float(matrixStore, mP_offset, 2*16); // P + Mv
220 syncP_Mv = new SyncBufferN(new Matrix4f[] { matP, matMv }, bufP_Mv, mP_offset);
221
222 final FloatBuffer bufTex = Buffers.slice2Float(matrixStore, mTex_offset, 1*16); // T
223 syncT = new SyncBuffer1(matTex, bufTex, mTex_offset);
224
225 if( null != matMvi ) {
226 final FloatBuffer bufMvi = Buffers.slice2Float(matrixStore, mMvi_offset, 1*16); // Mvi
227 final FloatBuffer bufP_Mv_Mvi = Buffers.slice2Float(matrixStore, mP_offset, 3*16); // P + Mv + Mvi
228 syncMvi = new SyncBuffer1U(matMvi, bufMvi, mMvi_offset);
229 syncP_Mv_Mvi = new SyncBufferNU(new Matrix4f[] { matP, matMv, matMvi }, bufP_Mv_Mvi, mP_offset);
230 } else {
231 syncMvi = null;
232 syncP_Mv_Mvi = null;
233 }
234 if( null != matMvit ) {
235 final FloatBuffer bufMvit = Buffers.slice2Float(matrixStore, mMvit_offset, 1*16); // Mvit
236 final FloatBuffer bufP_Mv_Mvi_Mvit = Buffers.slice2Float(matrixStore, mP_offset, 4*16); // P + Mv + Mvi + Mvit
237 syncMvit = new SyncBuffer1U(matMvit, bufMvit, mMvit_offset);
238 syncP_Mv_Mvi_Mvit = new SyncBufferNU(new Matrix4f[] { matP, matMv, matMvi, matMvit }, bufP_Mv_Mvi_Mvit, mP_offset);
239 } else {
240 syncMvit = null;
241 syncP_Mv_Mvi_Mvit = null;
242 }
243
244 mat4Tmp1 = new Matrix4f();
245
246 mat4Tmp2 = null; // on demand
247 matPMv = null; // on demand
248 matPMvi = null; // on demand
249 matPMviOK = false;
250 frustum = null; // on demand
251
252 reset();
253 }
254
255 /**
256 * Issues {@link Matrix4f#loadIdentity()} on all matrices and resets all internal states.
257 */
258 public void reset() {
262
263 modifiedBits = MODIFIED_ALL;
264 dirtyBits = requestBits | MANUAL_BITS;
265 }
266
267 //
268 // Temporary storage access for efficiency
269 //
270
271
272 /**
273 * Return the second temporary Matrix4f exposed to be reused for efficiency.
274 * <p>
275 * Temporary storage is only used by this class within single method calls,
276 * hence has no side-effects.
277 * </p>
278 */
279 protected final Matrix4f getTmp2Mat() {
280 if( null == mat4Tmp2 ) {
281 mat4Tmp2 = new Matrix4f();
282 }
283 return mat4Tmp2;
284 }
285
286 //
287 // Regular Matrix4f access as well as their SyncedBuffer counterpart SyncedMatrix and SyncedMatrices
288 //
289
290 /**
291 * Returns the {@link GLMatrixFunc#GL_TEXTURE_MATRIX texture matrix} (T).
292 * <p>
293 * Consider using {@link #setTextureDirty()} if modifying the returned {@link Matrix4f}.
294 * </p>
295 * <p>
296 * See <a href="#storageDetails"> matrix storage details</a>.
297 * </p>
298 */
299 public final Matrix4f getT() {
300 return matTex;
301 }
302
303 /**
304 * Returns the {@link SyncMatrix} of {@link GLMatrixFunc#GL_TEXTURE_MATRIX texture matrix} (T).
305 * <p>
306 * See <a href="#storageDetails"> matrix storage details</a>.
307 * </p>
308 */
309 public final SyncMatrix4f getSyncT() {
310 return syncT;
311 }
312
313 /**
314 * Returns the {@link GLMatrixFunc#GL_PROJECTION_MATRIX projection matrix} (P).
315 * <p>
316 * Consider using {@link #setProjectionDirty()} if modifying the returned {@link Matrix4f}.
317 * </p>
318 * <p>
319 * See <a href="#storageDetails"> matrix storage details</a>.
320 * </p>
321 */
322 public final Matrix4f getP() {
323 return matP;
324 }
325
326 /**
327 * Returns the {@link SyncMatrix} of {@link GLMatrixFunc#GL_PROJECTION_MATRIX projection matrix} (P).
328 * <p>
329 * See <a href="#storageDetails"> matrix storage details</a>.
330 * </p>
331 */
332 public final SyncMatrix4f getSyncP() {
333 return syncP;
334 }
335
336 /**
337 * Returns the {@link GLMatrixFunc#GL_MODELVIEW_MATRIX modelview matrix} (Mv).
338 * <p>
339 * Consider using {@link #setModelviewDirty()} if modifying the returned {@link Matrix4f}.
340 * </p>
341 * <p>
342 * See <a href="#storageDetails"> matrix storage details</a>.
343 * </p>
344 */
345 public final Matrix4f getMv() {
346 return matMv;
347 }
348
349 /**
350 * Returns the {@link SyncMatrix} of {@link GLMatrixFunc#GL_MODELVIEW_MATRIX modelview matrix} (Mv).
351 * <p>
352 * See <a href="#storageDetails"> matrix storage details</a>.
353 * </p>
354 */
355 public final SyncMatrix4f getSyncMv() {
356 return syncMv;
357 }
358
359 /**
360 * Returns {@link SyncMatrices4f} of 2 matrices within one FloatBuffer: {@link #getP() P} and {@link #getMv() Mv}.
361 * <p>
362 * See <a href="#storageDetails"> matrix storage details</a>.
363 * </p>
364 */
365 public final SyncMatrices4f getSyncPMv() {
366 return syncP_Mv;
367 }
368
369 /**
370 * Returns the inverse {@link GLMatrixFunc#GL_MODELVIEW_MATRIX modelview matrix} (Mvi) if requested.
371 * <p>
372 * See <a href="#storageDetails"> matrix storage details</a>.
373 * </p>
374 * @throws IllegalArgumentException if {@link #INVERSE_MODELVIEW} has not been requested in ctor {@link #PMVMatrix4f(int)}.
375 */
376 public final Matrix4f getMvi() {
377 if( 0 == ( INVERSE_MODELVIEW & requestBits ) ) {
378 throw new IllegalArgumentException("Not requested in ctor");
379 }
380 updateImpl(false);
381 return matMvi;
382 }
383
384 /**
385 * Returns the {@link SyncMatrix} of inverse {@link GLMatrixFunc#GL_MODELVIEW_MATRIX modelview matrix} (Mvi) if requested.
386 * <p>
387 * See <a href="#storageDetails"> matrix storage details</a>.
388 * </p>
389 * @throws IllegalArgumentException if {@link #INVERSE_MODELVIEW} has not been requested in ctor {@link #PMVMatrix4f(int)}.
390 */
391 public final SyncMatrix4f getSyncMvi() {
392 if( 0 == ( INVERSE_MODELVIEW & requestBits ) ) {
393 throw new IllegalArgumentException("Not requested in ctor");
394 }
395 return syncMvi;
396 }
397
398 /**
399 * Returns the inverse transposed {@link GLMatrixFunc#GL_MODELVIEW_MATRIX modelview matrix} (Mvit) if requested.
400 * <p>
401 * See <a href="#storageDetails"> matrix storage details</a>.
402 * </p>
403 * @throws IllegalArgumentException if {@link #INVERSE_TRANSPOSED_MODELVIEW} has not been requested in ctor {@link #PMVMatrix4f(int)}.
404 */
405 public final Matrix4f getMvit() {
406 if( 0 == ( INVERSE_TRANSPOSED_MODELVIEW & requestBits ) ) {
407 throw new IllegalArgumentException("Not requested in ctor");
408 }
409 updateImpl(false);
410 return matMvit;
411 }
412
413 /**
414 * Returns the {@link SyncMatrix} of inverse transposed {@link GLMatrixFunc#GL_MODELVIEW_MATRIX modelview matrix} (Mvit) if requested.
415 * <p>
416 * See <a href="#storageDetails"> matrix storage details</a>.
417 * </p>
418 * @throws IllegalArgumentException if {@link #INVERSE_TRANSPOSED_MODELVIEW} has not been requested in ctor {@link #PMVMatrix4f(int)}.
419 */
420 public final SyncMatrix4f getSyncMvit() {
421 if( 0 == ( INVERSE_TRANSPOSED_MODELVIEW & requestBits ) ) {
422 throw new IllegalArgumentException("Not requested in ctor");
423 }
424 return syncMvit;
425 }
426
427 /**
428 * Returns {@link SyncMatrices4f} of 3 matrices within one FloatBuffer: {@link #getP() P}, {@link #getMv() Mv} and {@link #getMvi() Mvi} if requested.
429 * <p>
430 * See <a href="#storageDetails"> matrix storage details</a>.
431 * </p>
432 * @throws IllegalArgumentException if {@link #INVERSE_MODELVIEW} has not been requested in ctor {@link #PMVMatrix4f(int)}.
433 */
435 if( 0 == ( INVERSE_MODELVIEW & requestBits ) ) {
436 throw new IllegalArgumentException("Not requested in ctor");
437 }
438 return syncP_Mv_Mvi;
439 }
440
441 /**
442 * Returns {@link SyncMatrices4f} of 4 matrices within one FloatBuffer: {@link #getP() P}, {@link #getMv() Mv}, {@link #getMvi() Mvi} and {@link #getMvit() Mvit} if requested.
443 * <p>
444 * See <a href="#storageDetails"> matrix storage details</a>.
445 * </p>
446 * @throws IllegalArgumentException if {@link #INVERSE_TRANSPOSED_MODELVIEW} has not been requested in ctor {@link #PMVMatrix4f(int)}.
447 */
449 if( 0 == ( INVERSE_TRANSPOSED_MODELVIEW & requestBits ) ) {
450 throw new IllegalArgumentException("Not requested in ctor");
451 }
452 return syncP_Mv_Mvi_Mvit;
453 }
454
455 //
456 // Basic Matrix4f, Vec3f and Vec4f operations similar to GLMatrixFunc
457 //
458
459 /**
460 * Returns multiplication result of {@link #getP() P} and {@link #getMv() Mv} matrix, i.e.
461 * <pre>
462 * result = P x Mv
463 * </pre>
464 * @param result 4x4 matrix storage for result
465 * @return given result matrix for chaining
466 */
467 public final Matrix4f getMulPMv(final Matrix4f result) {
468 return result.mul(matP, matMv);
469 }
470
471 /**
472 * Returns multiplication result of {@link #getMv() Mv} and {@link #getP() P} matrix, i.e.
473 * <pre>
474 * result = Mv x P
475 * </pre>
476 * @param result 4x4 matrix storage for result
477 * @return given result matrix for chaining
478 */
479 public final Matrix4f getMulMvP(final Matrix4f result) {
480 return result.mul(matMv, matP);
481 }
482
483 /**
484 * v_out = Mv * v_in
485 * @param v_in input vector, can be v_out for in-place transformation
486 * @param v_out output vector
487 * @returns v_out for chaining
488 */
489 public final Vec4f mulWithMv(final Vec4f v_in, final Vec4f v_out) {
490 return matMv.mulVec4f(v_in, v_out);
491 }
492
493 /**
494 * v_inout = Mv * v_inout
495 * @param v_inout input and output vector, i.e. in-place transformation
496 * @returns v_inout for chaining
497 */
498 public final Vec4f mulWithMv(final Vec4f v_inout) {
499 return matMv.mulVec4f(v_inout);
500 }
501
502 /**
503 * v_out = Mv * v_in
504 *
505 * Affine 3f-vector transformation by 4x4 matrix, see {@link Matrix4f#mulVec3f(Vec3f, Vec3f)}.
506 *
507 * @param v_in input vector, can be v_out for in-place transformation
508 * @param v_out output vector
509 * @returns v_out for chaining
510 */
511 public final Vec3f mulWithMv(final Vec3f v_in, final Vec3f v_out) {
512 return matMv.mulVec3f(v_in, v_out);
513 }
514
515 //
516 // GLMatrixFunc alike functionality
517 //
518
519 /**
520 * Load the {@link #getMv() modelview matrix} with the provided values.
521 */
522 public final PMVMatrix4f loadMv(final float[] values, final int offset) {
523 matMv.load(values, offset);
525 return this;
526 }
527 /**
528 * Load the {@link #getMv() modelview matrix} with the provided values.
529 */
530 public final PMVMatrix4f loadMv(final java.nio.FloatBuffer m) {
531 final int spos = m.position();
532 matMv.load(m);
534 m.position(spos);
535 return this;
536 }
537 /**
538 * Load the {@link #getMv() modelview matrix} with the values of the given {@link Matrix4f}.
539 */
540 public final PMVMatrix4f loadMv(final Matrix4f m) {
541 matMv.load(m);
543 return this;
544 }
545 /**
546 * Load the {@link #getMv() modelview matrix} with the values of the given {@link Quaternion}'s rotation {@link Matrix4f#setToRotation(Quaternion) matrix representation}.
547 */
548 public final PMVMatrix4f loadMv(final Quaternion quat) {
549 matMv.setToRotation(quat);
551 return this;
552 }
553
554 /**
555 * Load the {@link #getP() projection matrix} with the provided values.
556 */
557 public final PMVMatrix4f loadP(final float[] values, final int offset) {
558 matP.load(values, offset);
560 return this;
561 }
562 /**
563 * Load the {@link #getP() projection matrix} with the provided values.
564 */
565 public final PMVMatrix4f loadP(final java.nio.FloatBuffer m) {
566 final int spos = m.position();
567 matP.load(m);
569 m.position(spos);
570 return this;
571 }
572 /**
573 * Load the {@link #getP() projection matrix} with the values of the given {@link Matrix4f}.
574 */
575 public final PMVMatrix4f loadP(final Matrix4f m) {
576 matP.load(m);
578 return this;
579 }
580 /**
581 * Load the {@link #getP() projection matrix} with the values of the given {@link Quaternion}'s rotation {@link Matrix4f#setToRotation(Quaternion) matrix representation}.
582 */
583 public final PMVMatrix4f loadP(final Quaternion quat) {
584 matP.setToRotation(quat);
586 return this;
587 }
588
589 /**
590 * Load the {@link #getT() texture matrix} with the provided values.
591 */
592 public final PMVMatrix4f loadT(final float[] values, final int offset) {
593 matTex.load(values, offset);
595 return this;
596 }
597 /**
598 * Load the {@link #getT() texture matrix} with the provided values.
599 */
600 public final PMVMatrix4f loadT(final java.nio.FloatBuffer m) {
601 final int spos = m.position();
602 matTex.load(m);
604 m.position(spos);
605 return this;
606 }
607 /**
608 * Load the {@link #getT() texture matrix} with the values of the given {@link Matrix4f}.
609 */
610 public final PMVMatrix4f loadT(final Matrix4f m) {
611 matTex.load(m);
613 return this;
614 }
615 /**
616 * Load the {@link #getT() texture matrix} with the values of the given {@link Quaternion}'s rotation {@link Matrix4f#setToRotation(Quaternion) matrix representation}.
617 */
618 public final PMVMatrix4f loadT(final Quaternion quat) {
619 matTex.setToRotation(quat);
621 return this;
622 }
623
624 /**
625 * Load the {@link #getMv() modelview matrix} with the values of the given {@link Matrix4f}.
626 */
630 return this;
631 }
632
633 /**
634 * Load the {@link #getP() projection matrix} with the values of the given {@link Matrix4f}.
635 */
636 public final PMVMatrix4f loadPIdentity() {
639 return this;
640 }
641
642 /**
643 * Load the {@link #getT() texture matrix} with the values of the given {@link Matrix4f}.
644 */
645 public final PMVMatrix4f loadTIdentity() {
648 return this;
649 }
650
651 /**
652 * Multiply the {@link #getMv() modelview matrix}: [c] = [c] x [m]
653 * @param m the right hand Matrix4f
654 * @return this instance of chaining
655 */
656 public final PMVMatrix4f mulMv(final Matrix4f m) {
657 matMv.mul( m );
659 return this;
660 }
661
662 /**
663 * Multiply the {@link #getP() projection matrix}: [c] = [c] x [m]
664 * @param m the right hand Matrix4f
665 * @return this instance of chaining
666 */
667 public final PMVMatrix4f mulP(final Matrix4f m) {
668 matP.mul( m );
670 return this;
671 }
672
673 /**
674 * Multiply the {@link #getT() texture matrix}: [c] = [c] x [m]
675 * @param m the right hand Matrix4f
676 * @return this instance of chaining
677 */
678 public final PMVMatrix4f mulT(final Matrix4f m) {
679 matTex.mul( m );
681 return this;
682 }
683
684 /**
685 * Translate the {@link #getMv() modelview matrix}.
686 * @param x
687 * @param y
688 * @param z
689 * @return this instance of chaining
690 */
691 public final PMVMatrix4f translateMv(final float x, final float y, final float z) {
692 return mulMv( mat4Tmp1.setToTranslation(x, y, z) );
693 }
694 /**
695 * Translate the {@link #getMv() modelview matrix}.
696 * @param t translation vec3
697 * @return this instance of chaining
698 */
699 public final PMVMatrix4f translateMv(final Vec3f t) {
700 return mulMv( mat4Tmp1.setToTranslation(t) );
701 }
702
703 /**
704 * Translate the {@link #getP() projection matrix}.
705 * @param x
706 * @param y
707 * @param z
708 * @return this instance of chaining
709 */
710 public final PMVMatrix4f translateP(final float x, final float y, final float z) {
711 return mulP( mat4Tmp1.setToTranslation(x, y, z) );
712 }
713 /**
714 * Translate the {@link #getP() projection matrix}.
715 * @param t translation vec3
716 * @return this instance of chaining
717 */
718 public final PMVMatrix4f translateP(final Vec3f t) {
719 return mulP( mat4Tmp1.setToTranslation(t) );
720 }
721
722 /**
723 * Scale the {@link #getMv() modelview matrix}.
724 * @param x
725 * @param y
726 * @param z
727 * @return this instance of chaining
728 */
729 public final PMVMatrix4f scaleMv(final float x, final float y, final float z) {
730 return mulMv( mat4Tmp1.setToScale(x, y, z) );
731 }
732 /**
733 * Scale the {@link #getMv() modelview matrix}.
734 * @param s scale vec4f
735 * @return this instance of chaining
736 */
737 public final PMVMatrix4f scaleMv(final Vec3f s) {
738 return mulMv( mat4Tmp1.setToScale(s) );
739 }
740
741 /**
742 * Scale the {@link #getP() projection matrix}.
743 * @param x
744 * @param y
745 * @param z
746 * @return this instance of chaining
747 */
748 public final PMVMatrix4f scaleP(final float x, final float y, final float z) {
749 return mulP( mat4Tmp1.setToScale(x, y, z) );
750 }
751 /**
752 * Scale the {@link #getP() projection matrix}.
753 * @param s scale vec4f
754 * @return this instance of chaining
755 */
756 public final PMVMatrix4f scaleP(final Vec3f s) {
757 return mulP( mat4Tmp1.setToScale(s) );
758 }
759
760 /**
761 * Rotate the {@link #getMv() modelview matrix} by the given axis and angle in radians.
762 * <p>
763 * Consider using {@link #rotateMv(Quaternion)}
764 * </p>
765 * @param ang_rad angle in radians
766 * @param axis rotation axis
767 * @return this instance of chaining
768 * @see #rotateMv(Quaternion)
769 */
770 public final PMVMatrix4f rotateMv(final float ang_rad, final float x, final float y, final float z) {
771 return mulMv( mat4Tmp1.setToRotationAxis(ang_rad, x, y, z) );
772 }
773 /**
774 * Rotate the {@link #getMv() modelview matrix} by the given axis and angle in radians.
775 * <p>
776 * Consider using {@link #rotateMv(Quaternion)}
777 * </p>
778 * @param ang_rad angle in radians
779 * @param axis rotation axis
780 * @return this instance of chaining
781 * @see #rotateMv(Quaternion)
782 */
783 public final PMVMatrix4f rotateMv(final float ang_rad, final Vec3f axis) {
784 return mulMv( mat4Tmp1.setToRotationAxis(ang_rad, axis) );
785 }
786 /**
787 * Rotate the {@link #getMv() modelview matrix} with the given {@link Quaternion}'s rotation {@link Matrix4f#setToRotation(Quaternion) matrix representation}.
788 * @param quat the {@link Quaternion}
789 * @return this instance of chaining
790 */
791 public final PMVMatrix4f rotateMv(final Quaternion quat) {
792 return mulMv( mat4Tmp1.setToRotation(quat) );
793 }
794
795 /**
796 * Rotate the {@link #getP() projection matrix} by the given axis and angle in radians.
797 * <p>
798 * Consider using {@link #rotateP(Quaternion)}
799 * </p>
800 * @param ang_rad angle in radians
801 * @param axis rotation axis
802 * @return this instance of chaining
803 * @see #rotateP(Quaternion)
804 */
805 public final PMVMatrix4f rotateP(final float ang_rad, final float x, final float y, final float z) {
806 return mulP( mat4Tmp1.setToRotationAxis(ang_rad, x, y, z) );
807 }
808 /**
809 * Rotate the {@link #getP() projection matrix} by the given axis and angle in radians.
810 * <p>
811 * Consider using {@link #rotateP(Quaternion)}
812 * </p>
813 * @param ang_rad angle in radians
814 * @param axis rotation axis
815 * @return this instance of chaining
816 * @see #rotateP(Quaternion)
817 */
818 public final PMVMatrix4f rotateP(final float ang_rad, final Vec3f axis) {
819 return mulP( mat4Tmp1.setToRotationAxis(ang_rad, axis) );
820 }
821 /**
822 * Rotate the {@link #getP() projection matrix} with the given {@link Quaternion}'s rotation {@link Matrix4f#setToRotation(Quaternion) matrix representation}.
823 * @param quat the {@link Quaternion}
824 * @return this instance of chaining
825 */
826 public final PMVMatrix4f rotateP(final Quaternion quat) {
827 return mulP( mat4Tmp1.setToRotation(quat) );
828 }
829
830 /** Pop the {@link #getMv() modelview matrix} from its stack. */
831 public final PMVMatrix4f popMv() {
832 matMv.pop();
834 return this;
835 }
836 /** Pop the {@link #getP() projection matrix} from its stack. */
837 public final PMVMatrix4f popP() {
838 matP.pop();
840 return this;
841 }
842 /** Pop the {@link #getT() texture matrix} from its stack. */
843 public final PMVMatrix4f popT() {
844 matTex.pop();
846 return this;
847 }
848 /** Push the {@link #getMv() modelview matrix} to its stack, while preserving its values. */
849 public final PMVMatrix4f pushMv() {
850 matMv.push();
851 return this;
852 }
853 /** Push the {@link #getP() projection matrix} to its stack, while preserving its values. */
854 public final PMVMatrix4f pushP() {
855 matP.push();
856 return this;
857 }
858 /** Push the {@link #getT() texture matrix} to its stack, while preserving its values. */
859 public final PMVMatrix4f pushT() {
860 matTex.push();
861 return this;
862 }
863
864 /**
865 * {@link #mulP(Matrix4f) Multiply} the {@link #getP() projection matrix} with the orthogonal matrix.
866 * @param left
867 * @param right
868 * @param bottom
869 * @param top
870 * @param zNear
871 * @param zFar
872 * @see Matrix4f#setToOrtho(float, float, float, float, float, float)
873 */
874 public final void orthoP(final float left, final float right, final float bottom, final float top, final float zNear, final float zFar) {
875 mulP( mat4Tmp1.setToOrtho(left, right, bottom, top, zNear, zFar) );
876 }
877
878 /**
879 * {@link #mulP(Matrix4f) Multiply} the {@link #getP() projection matrix} with the frustum matrix.
880 *
881 * @throws IllegalArgumentException if {@code zNear <= 0} or {@code zFar <= zNear}
882 * or {@code left == right}, or {@code bottom == top}.
883 * @see Matrix4f#setToFrustum(float, float, float, float, float, float)
884 */
885 public final void frustumP(final float left, final float right, final float bottom, final float top, final float zNear, final float zFar) throws IllegalArgumentException {
886 mulP( mat4Tmp1.setToFrustum(left, right, bottom, top, zNear, zFar) );
887 }
888
889 //
890 // Extra functionality
891 //
892
893 /**
894 * {@link #mulP(Matrix4f) Multiply} the {@link #getP() projection matrix} with the perspective/frustum matrix.
895 *
896 * @param fovy_rad fov angle in radians
897 * @param aspect aspect ratio width / height
898 * @param zNear
899 * @param zFar
900 * @throws IllegalArgumentException if {@code zNear <= 0} or {@code zFar <= zNear}
901 * @see Matrix4f#setToPerspective(float, float, float, float)
902 */
903 public final PMVMatrix4f perspectiveP(final float fovy_rad, final float aspect, final float zNear, final float zFar) throws IllegalArgumentException {
904 mulP( mat4Tmp1.setToPerspective(fovy_rad, aspect, zNear, zFar) );
905 return this;
906 }
907
908 /**
909 * {@link #mulP(Matrix4f) Multiply} the {@link #getP() projection matrix}
910 * with the eye, object and orientation, i.e. {@link Matrix4f#setToLookAt(Vec3f, Vec3f, Vec3f, Matrix4f)}.
911 */
912 public final PMVMatrix4f lookAtP(final Vec3f eye, final Vec3f center, final Vec3f up) {
913 mulP( mat4Tmp1.setToLookAt(eye, center, up, getTmp2Mat()) );
914 return this;
915 }
916
917 /**
918 * Map object coordinates to window coordinates.
919 * <p>
920 * Traditional <code>gluProject</code> implementation.
921 * </p>
922 *
923 * @param objPos 3 component object coordinate
924 * @param viewport Rect4i viewport
925 * @param winPos 3 component window coordinate, the result
926 * @return true if successful, otherwise false (z is 1)
927 */
928 public final boolean mapObjToWin(final Vec3f objPos, final Recti viewport, final Vec3f winPos) {
929 return Matrix4f.mapObjToWin(objPos, matMv, matP, viewport, winPos);
930 }
931
932 /**
933 * Map window coordinates to object coordinates.
934 * <p>
935 * Traditional <code>gluUnProject</code> implementation.
936 * </p>
937 *
938 * @param winx
939 * @param winy
940 * @param winz
941 * @param viewport Rect4i viewport
942 * @param objPos 3 component object coordinate, the result
943 * @return true if successful, otherwise false (failed to invert matrix, or becomes infinity due to zero z)
944 */
945 public final boolean mapWinToObj(final float winx, final float winy, final float winz,
946 final Recti viewport, final Vec3f objPos) {
947 if( Matrix4f.mapWinToObj(winx, winy, winz, getPMvi(), viewport, objPos) ) {
948 return true;
949 } else {
950 return false;
951 }
952 }
953
954 /**
955 * Map window coordinates to object coordinates.
956 * <p>
957 * Traditional <code>gluUnProject4</code> implementation.
958 * </p>
959 *
960 * @param winx
961 * @param winy
962 * @param winz
963 * @param clipw
964 * @param viewport Rect4i viewport
965 * @param near
966 * @param far
967 * @param objPos 4 component object coordinate, the result
968 * @return true if successful, otherwise false (failed to invert matrix, or becomes infinity due to zero z)
969 */
970 public boolean mapWinToObj4(final float winx, final float winy, final float winz, final float clipw,
971 final Recti viewport, final float near, final float far, final Vec4f objPos) {
972 if( Matrix4f.mapWinToObj4(winx, winy, winz, clipw, getPMvi(), viewport, near, far, objPos) ) {
973 return true;
974 } else {
975 return false;
976 }
977 }
978
979 /**
980 * Map two window coordinates w/ shared X/Y and distinctive Z
981 * to a {@link Ray}. The resulting {@link Ray} maybe used for <i>picking</i>
982 * using a {@link AABBox#getRayIntersection(Vec3f, Ray, float, boolean) bounding box}.
983 * <p>
984 * Notes for picking <i>winz0</i> and <i>winz1</i>:
985 * <ul>
986 * <li>see {@link FloatUtil#getZBufferEpsilon(int, float, float)}</li>
987 * <li>see {@link FloatUtil#getZBufferValue(int, float, float, float)}</li>
988 * <li>see {@link FloatUtil#getOrthoWinZ(float, float, float)}</li>
989 * </ul>
990 * </p>
991 * @param winx
992 * @param winy
993 * @param winz0
994 * @param winz1
995 * @param viewport
996 * @param ray storage for the resulting {@link Ray}
997 * @return true if successful, otherwise false (failed to invert matrix, or becomes z is infinity)
998 */
999 public final boolean mapWinToRay(final float winx, final float winy, final float winz0, final float winz1,
1000 final Recti viewport, final Ray ray) {
1001 return Matrix4f.mapWinToRay(winx, winy, winz0, winz1, getPMvi(), viewport, ray);
1002 }
1003
1004 public StringBuilder toString(StringBuilder sb, final String f) {
1005 if(null == sb) {
1006 sb = new StringBuilder();
1007 }
1008 final boolean pmvDirty = 0 != (PREMUL_PMV & dirtyBits);
1009 final boolean pmvUsed = null != matPMv;
1010
1011 final boolean pmviDirty = 0 != (PREMUL_PMVI & dirtyBits);
1012 final boolean pmviUsed = null != matPMvi;
1013
1014 final boolean frustumDirty = 0 != (FRUSTUM & dirtyBits);
1015 final boolean frustumUsed = null != frustum;
1016
1017 final boolean mviDirty = 0 != (INVERSE_MODELVIEW & dirtyBits);
1018 final boolean mviReq = 0 != (INVERSE_MODELVIEW & requestBits);
1019
1020 final boolean mvitDirty = 0 != (INVERSE_TRANSPOSED_MODELVIEW & dirtyBits);
1021 final boolean mvitReq = 0 != (INVERSE_TRANSPOSED_MODELVIEW & requestBits);
1022
1023 final boolean modP = 0 != ( MODIFIED_PROJECTION & modifiedBits );
1024 final boolean modMv = 0 != ( MODIFIED_MODELVIEW & modifiedBits );
1025 final boolean modT = 0 != ( MODIFIED_TEXTURE & modifiedBits );
1026 int count = 3; // P, Mv, T
1027
1028 sb.append("PMVMatrix4f[modified[P ").append(modP).append(", Mv ").append(modMv).append(", T ").append(modT);
1029 sb.append("], dirty/used[PMv ").append(pmvDirty).append("/").append(pmvUsed).append(", Pmvi ").append(pmviDirty).append("/").append(pmviUsed).append(", Frustum ").append(frustumDirty).append("/").append(frustumUsed);
1030 sb.append("], dirty/req[Mvi ").append(mviDirty).append("/").append(mviReq).append(", Mvit ").append(mvitDirty).append("/").append(mvitReq).append("]").append(System.lineSeparator());
1031 sb.append(", Projection").append(System.lineSeparator());
1032 matP.toString(sb, null, f);
1033 sb.append(", Modelview").append(System.lineSeparator());
1034 matMv.toString(sb, null, f);
1035 sb.append(", Texture").append(System.lineSeparator());
1036 matTex.toString(sb, null, f);
1037 if( null != matPMv ) {
1038 sb.append(", P * Mv").append(System.lineSeparator());
1039 matPMv.toString(sb, null, f);
1040 ++count;
1041 }
1042 if( null != matPMvi ) {
1043 sb.append(", P * Mv").append(System.lineSeparator());
1044 matPMvi.toString(sb, null, f);
1045 ++count;
1046 }
1047 if( mviReq ) {
1048 sb.append(", Inverse Modelview").append(System.lineSeparator());
1049 matMvi.toString(sb, null, f);
1050 ++count;
1051 }
1052 if( mvitReq ) {
1053 sb.append(", Inverse Transposed Modelview").append(System.lineSeparator());
1054 matMvit.toString(sb, null, f);
1055 ++count;
1056 }
1057 int tmpCount = 1;
1058 if( null != mat4Tmp2 ) {
1059 ++tmpCount;
1060 }
1061 sb.append(", matrices "+count+" + "+tmpCount+" temp = "+(count+tmpCount)+"]");
1062 return sb;
1063 }
1064
1065 @Override
1066 public String toString() {
1067 return toString(null, "%10.5f").toString();
1068 }
1069
1070 /**
1071 * Returns the modified bits due to mutable operations..
1072 * <p>
1073 * A modified bit is set, if the corresponding matrix had been modified by a mutable operation
1074 * since last {@link #update()} or {@link #getModifiedBits(boolean) getModifiedBits(true)} call.
1075 * </p>
1076 * @param clear if true, clears the modified bits, otherwise leaves them untouched.
1077 *
1078 * @see #MODIFIED_PROJECTION
1079 * @see #MODIFIED_MODELVIEW
1080 * @see #MODIFIED_TEXTURE
1081 * @see #getDirtyBits()
1082 * @see #isReqDirty()
1083 */
1084 public final int getModifiedBits(final boolean clear) {
1085 final int r = modifiedBits;
1086 if(clear) {
1087 modifiedBits = 0;
1088 }
1089 return r;
1090 }
1091
1092 /**
1093 * Returns the dirty bits due to mutable operations,
1094 * i.e.
1095 * - {@link #INVERSE_MODELVIEW} (if requested)
1096 * - {@link #INVERSE_TRANSPOSED_MODELVIEW} (if requested)
1097 * - {@link #FRUSTUM} (always, cleared via {@link #getFrustum()}
1098 * <p>
1099 * A dirty bit is set, if the corresponding matrix had been modified by a mutable operation
1100 * since last {@link #update()} call and requested in the constructor {@link #PMVMatrix4f(int)}.
1101 * </p>
1102 * <p>
1103 * {@link #update()} clears the dirty state for the matrices and {@link #getFrustum()} for {@link #FRUSTUM}.
1104 * </p>
1105 *
1106 * @see #isReqDirty()
1107 * @see #INVERSE_MODELVIEW
1108 * @see #INVERSE_TRANSPOSED_MODELVIEW
1109 * @see #FRUSTUM
1110 * @see #PMVMatrix4f(int)
1111 * @see #getMvi()
1112 * @see #getMvit()
1113 * @see #getSyncPMvMvi()
1114 * @see #getSyncPMvMviMvit()
1115 * @see #getFrustum()
1116 */
1117 public final int getDirtyBits() {
1118 return dirtyBits;
1119 }
1120
1121 /**
1122 * Returns true if the one of the {@link #getReqBits() requested bits} are are set dirty due to mutable operations,
1123 * i.e. at least one of
1124 * - {@link #INVERSE_MODELVIEW}
1125 * - {@link #INVERSE_TRANSPOSED_MODELVIEW}
1126 * <p>
1127 * A dirty bit is set, if the corresponding matrix had been modified by a mutable operation
1128 * since last {@link #update()} call and requested in the constructor {@link #PMVMatrix4f(int)}.
1129 * </p>
1130 * <p>
1131 * {@link #update()} clears the dirty state for the matrices and {@link #getFrustum()} for {@link #FRUSTUM}.
1132 * </p>
1133 *
1134 * @see #INVERSE_MODELVIEW
1135 * @see #INVERSE_TRANSPOSED_MODELVIEW
1136 * @see #PMVMatrix4f(int)
1137 * @see #getMvi()
1138 * @see #getMvit()
1139 * @see #getSyncPMvMvi()
1140 * @see #getSyncPMvMviMvit()
1141 */
1142 public final boolean isReqDirty() {
1143 return 0 != ( requestBits & dirtyBits );
1144 }
1145
1146 /**
1147 * Sets the {@link #getMv() Modelview (Mv)} matrix dirty and modified,
1148 * i.e. adds {@link #getReqBits() requested bits} and {@link #MANUAL_BITS} to {@link #getDirtyBits() dirty bits}.
1149 * @see #isReqDirty()
1150 */
1151 public final void setModelviewDirty() {
1152 dirtyBits |= requestBits | MANUAL_BITS ;
1153 modifiedBits |= MODIFIED_MODELVIEW;
1154 }
1155
1156 /**
1157 * Sets the {@link #getP() Projection (P)} matrix dirty and modified,
1158 * i.e. adds {@link #MANUAL_BITS} to {@link #getDirtyBits() dirty bits}.
1159 */
1160 public final void setProjectionDirty() {
1161 dirtyBits |= MANUAL_BITS ;
1162 modifiedBits |= MODIFIED_PROJECTION;
1163 }
1164
1165 /**
1166 * Sets the {@link #getT() Texture (T)} matrix modified.
1167 */
1168 public final void setTextureDirty() {
1169 modifiedBits |= MODIFIED_TEXTURE;
1170 }
1171
1172 /**
1173 * Returns the request bit mask, which uses bit values equal to the dirty mask
1174 * and may contain
1175 * - {@link #INVERSE_MODELVIEW}
1176 * - {@link #INVERSE_TRANSPOSED_MODELVIEW}
1177 * <p>
1178 * The request bit mask is set by in the constructor {@link #PMVMatrix4f(int)}.
1179 * </p>
1180 *
1181 * @see #INVERSE_MODELVIEW
1182 * @see #INVERSE_TRANSPOSED_MODELVIEW
1183 * @see #PMVMatrix4f(int)
1184 * @see #getMvi()
1185 * @see #getMvit()
1186 * @see #getSyncPMvMvi()
1187 * @see #getSyncPMvMviMvit()
1188 * @see #getFrustum()
1189 */
1190 public final int getReqBits() {
1191 return requestBits;
1192 }
1193
1194 /**
1195 * Returns the pre-multiplied projection x modelview, P x Mv.
1196 * <p>
1197 * This {@link Matrix4f} instance should be re-fetched via this method and not locally stored
1198 * to have it updated from a potential modification of underlying projection and/or modelview matrix.
1199 * {@link #update()} has no effect on this {@link Matrix4f}.
1200 * </p>
1201 * <p>
1202 * This pre-multipled P x Mv is considered dirty, if its corresponding
1203 * {@link #getP() P matrix} or {@link #getMv() Mv matrix} has been modified since its last update.
1204 * </p>
1205 * @see #update()
1206 */
1207 public final Matrix4f getPMv() {
1208 if( 0 != ( dirtyBits & PREMUL_PMV ) ) {
1209 if( null == matPMv ) {
1210 matPMv = new Matrix4f();
1211 }
1212 matPMv.mul(matP, matMv);
1213 dirtyBits &= ~PREMUL_PMV;
1214 }
1215 return matPMv;
1216 }
1217
1218 /**
1219 * Returns the pre-multiplied inverse projection x modelview,
1220 * if {@link Matrix4f#invert(Matrix4f)} succeeded, otherwise `null`.
1221 * <p>
1222 * This {@link Matrix4f} instance should be re-fetched via this method and not locally stored
1223 * to have it updated from a potential modification of underlying projection and/or modelview matrix.
1224 * {@link #update()} has no effect on this {@link Matrix4f}.
1225 * </p>
1226 * <p>
1227 * This pre-multipled invert(P x Mv) is considered dirty, if its corresponding
1228 * {@link #getP() P matrix} or {@link #getMv() Mv matrix} has been modified since its last update.
1229 * </p>
1230 * @see #update()
1231 */
1232 public final Matrix4f getPMvi() {
1233 if( 0 != ( dirtyBits & PREMUL_PMVI ) ) {
1234 if( null == matPMvi ) {
1235 matPMvi = new Matrix4f();
1236 }
1237 final Matrix4f mPMv = getPMv();
1238 matPMviOK = matPMvi.invert(mPMv);
1239 dirtyBits &= ~PREMUL_PMVI;
1240 }
1241 return matPMviOK ? matPMvi : null;
1242 }
1243
1244 /**
1245 * Returns the frustum, derived from projection x modelview.
1246 * <p>
1247 * This {@link Frustum} instance should be re-fetched via this method and not locally stored
1248 * to have it updated from a potential modification of underlying projection and/or modelview matrix.
1249 * {@link #update()} has no effect on this {@link Frustum}.
1250 * </p>
1251 * <p>
1252 * The {@link Frustum} is considered dirty, if its corresponding
1253 * {@link #getP() P matrix} or {@link #getMv() Mv matrix} has been modified since its last update.
1254 * </p>
1255 * @see #update()
1256 */
1257 public final Frustum getFrustum() {
1258 if( 0 != ( dirtyBits & FRUSTUM ) ) {
1259 if( null == frustum ) {
1260 frustum = new Frustum();
1261 }
1262 frustum.setFromMat(getPMv());
1263 dirtyBits &= ~FRUSTUM;
1264 }
1265 return frustum;
1266 }
1267
1268 /**
1269 * Update the derived {@link #getMvi() inverse modelview (Mvi)},
1270 * {@link #getMvit() inverse transposed modelview (Mvit)} matrices
1271 * <b>if</b> they {@link #isReqDirty() are dirty} <b>and</b>
1272 * requested via the constructor {@link #PMVMatrix4f(int)}.<br/>
1273 * Hence updates the following dirty bits.
1274 * - {@link #INVERSE_MODELVIEW}
1275 * - {@link #INVERSE_TRANSPOSED_MODELVIEW}
1276 * <p>
1277 * The {@link Frustum} is updated only via {@link #getFrustum()} separately.
1278 * </p>
1279 * <p>
1280 * The Mvi and Mvit matrices are considered dirty, if their corresponding
1281 * {@link #getMv() Mv matrix} has been modified since their last update.
1282 * </p>
1283 * <p>
1284 * Method is automatically called by {@link SyncMatrix4f} and {@link SyncMatrices4f}
1285 * instances {@link SyncAction} as retrieved by e.g. {@link #getSyncMvit()}.
1286 * This ensures an automatic update cycle if used with {@link com.jogamp.opengl.GLUniformData}.
1287 * </p>
1288 * <p>
1289 * Method may be called manually in case mutable operations has been called
1290 * and caller operates on already fetched references, i.e. not calling
1291 * {@link #getMvi()}, {@link #getMvit()} anymore.
1292 * </p>
1293 * <p>
1294 * Method clears the modified bits like {@link #getModifiedBits(boolean) getModifiedBits(true)},
1295 * which are set by any mutable operation. The modified bits have no impact
1296 * on this method, but the return value.
1297 * </p>
1298 *
1299 * @return true if any matrix has been modified since last update call or
1300 * if the derived matrices Mvi and Mvit were updated, otherwise false.
1301 * In other words, method returns true if any matrix used by the caller must be updated,
1302 * e.g. uniforms in a shader program.
1303 *
1304 * @see #getModifiedBits(boolean)
1305 * @see #isReqDirty()
1306 * @see #INVERSE_MODELVIEW
1307 * @see #INVERSE_TRANSPOSED_MODELVIEW
1308 * @see #PMVMatrix4f(int)
1309 * @see #getMvi()
1310 * @see #getMvit()
1311 * @see #getSyncPMvMvi()
1312 * @see #getSyncPMvMviMvit()
1313 */
1314 public final boolean update() {
1315 return updateImpl(true);
1316 }
1317
1318 //
1319 // private
1320 //
1321
1322 private final boolean updateImpl(final boolean clearModBits) {
1323 boolean mod = 0 != modifiedBits;
1324 if( clearModBits ) {
1325 modifiedBits = 0;
1326 }
1327 if( 0 != ( requestBits & ( ( dirtyBits & ( INVERSE_MODELVIEW | INVERSE_TRANSPOSED_MODELVIEW ) ) ) ) ) { // only if dirt requested & dirty
1328 if( !matMvi.invert(matMv) ) {
1329 throw new RuntimeException("Invalid source Mv matrix, can't compute inverse");
1330 }
1331 dirtyBits &= ~INVERSE_MODELVIEW;
1332 mod = true;
1333 }
1334 if( 0 != ( requestBits & ( dirtyBits & INVERSE_TRANSPOSED_MODELVIEW ) ) ) { // only if requested & dirty
1335 matMvit.transpose(matMvi);
1336 dirtyBits &= ~INVERSE_TRANSPOSED_MODELVIEW;
1337 mod = true;
1338 }
1339 return mod;
1340 }
1341
1342 protected final Matrix4f matP;
1343 protected final Matrix4f matMv;
1344 protected final Matrix4f matTex;
1345
1346 private final Matrix4f matMvi;
1347 private final Matrix4f matMvit;
1348
1349 private static final int mP_offset = 0*16;
1350 private static final int mMv_offset = 1*16;
1351 private final int mMvi_offset;
1352 private final int mMvit_offset;
1353 private final int mTex_offset;
1354
1355 private final float[] matrixStore;
1356
1357 private final SyncMatrix4f syncP, syncMv, syncT;
1358 private final SyncMatrix4f syncMvi, syncMvit;
1359 private final SyncMatrices4f syncP_Mv, syncP_Mv_Mvi, syncP_Mv_Mvi_Mvit;
1360
1361 protected final Matrix4f mat4Tmp1;
1362 private Matrix4f mat4Tmp2;
1363
1364 private int modifiedBits = MODIFIED_ALL;
1365 private int dirtyBits = 0; // contains the dirty bits, i.e. hinting for update operation
1366 private final int requestBits; // may contain the requested bits: INVERSE_MODELVIEW | INVERSE_TRANSPOSED_MODELVIEW
1367 private Matrix4f matPMv;
1368 private Matrix4f matPMvi;
1369 private boolean matPMviOK;
1370 private Frustum frustum;
1371
1372 private abstract class PMVSyncBuffer implements SyncMatrix4f {
1373 protected final Matrix4f mat;
1374 private final FloatBuffer fbuf;
1375
1376 public PMVSyncBuffer(final Matrix4f m, final FloatBuffer fbuf) {
1377 this.mat = m;
1378 this.fbuf = fbuf;
1379 }
1380
1381 @Override
1382 public final Buffer getBuffer() { return fbuf; }
1383
1384 @Override
1385 public final SyncBuffer sync() { getAction().sync(); return this; }
1386
1387 @Override
1388 public final Buffer getSyncBuffer() { getAction().sync(); return fbuf; }
1389
1390 @Override
1391 public final Matrix4f getMatrix() { return mat; }
1392
1393 @Override
1394 public final FloatBuffer getSyncFloats() { getAction().sync(); return fbuf; }
1395 }
1396 private final class SyncBuffer0 extends PMVSyncBuffer {
1397 private final SyncAction action = new SyncAction() {
1398 @Override
1399 public void sync() { mat.get(matrixStore); }
1400 };
1401
1402 public SyncBuffer0(final Matrix4f m, final FloatBuffer fbuf) { super(m, fbuf); }
1403
1404 @Override
1405 public SyncAction getAction() { return action; }
1406
1407 }
1408 private final class SyncBuffer1 extends PMVSyncBuffer {
1409 private final int offset;
1410 private final SyncAction action = new SyncAction() {
1411 @Override
1412 public void sync() { mat.get(matrixStore, offset); }
1413 };
1414
1415 public SyncBuffer1(final Matrix4f m, final FloatBuffer fbuf, final int offset) {
1416 super(m, fbuf);
1417 this.offset = offset;
1418 }
1419
1420 @Override
1421 public SyncAction getAction() { return action; }
1422 }
1423 private final class SyncBuffer1U extends PMVSyncBuffer {
1424 private final int offset;
1425 private final SyncAction action = new SyncAction() {
1426 @Override
1427 public void sync() {
1428 updateImpl(true);
1429 mat.get(matrixStore, offset);
1430 }
1431 };
1432
1433 public SyncBuffer1U(final Matrix4f m, final FloatBuffer fbuf, final int offset) {
1434 super(m, fbuf);
1435 this.offset = offset;
1436 }
1437
1438 @Override
1439 public SyncAction getAction() { return action; }
1440 }
1441
1442 private abstract class PMVSyncBufferN implements SyncMatrices4f {
1443 protected final Matrix4f[] mats;
1444 private final FloatBuffer fbuf;
1445
1446 public PMVSyncBufferN(final Matrix4f[] ms, final FloatBuffer fbuf) {
1447 this.mats = ms;
1448 this.fbuf = fbuf;
1449 }
1450
1451 @Override
1452 public final Buffer getBuffer() { return fbuf; }
1453
1454 @Override
1455 public final SyncBuffer sync() { getAction().sync(); return this; }
1456
1457 @Override
1458 public final Buffer getSyncBuffer() { getAction().sync(); return fbuf; }
1459
1460 @Override
1461 public Matrix4f[] getMatrices() { return mats; }
1462
1463 @Override
1464 public final FloatBuffer getSyncFloats() { getAction().sync(); return fbuf; }
1465 }
1466 private final class SyncBufferN extends PMVSyncBufferN {
1467 private final int offset;
1468 private final SyncAction action = new SyncAction() {
1469 @Override
1470 public void sync() {
1471 int ioff = offset;
1472 for(int i=0; i<mats.length; ++i, ioff+=16) {
1473 mats[i].get(matrixStore, ioff);
1474 }
1475 }
1476 };
1477
1478 public SyncBufferN(final Matrix4f[] ms, final FloatBuffer fbuf, final int offset) {
1479 super(ms, fbuf);
1480 this.offset = offset;
1481 }
1482
1483 @Override
1484 public SyncAction getAction() { return action; }
1485 }
1486 private final class SyncBufferNU extends PMVSyncBufferN {
1487 private final int offset;
1488 private final SyncAction action = new SyncAction() {
1489 @Override
1490 public void sync() {
1491 updateImpl(true);
1492 int ioff = offset;
1493 for(int i=0; i<mats.length; ++i, ioff+=16) {
1494 mats[i].get(matrixStore, ioff);
1495 }
1496 }
1497 };
1498
1499 public SyncBufferNU(final Matrix4f[] ms, final FloatBuffer fbuf, final int offset) {
1500 super(ms, fbuf);
1501 this.offset = offset;
1502 }
1503
1504 @Override
1505 public SyncAction getAction() { return action; }
1506 }
1507}
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
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
Matrix4f load(final Matrix4f src)
Load the values of the given matrix src to this matrix.
Definition: Matrix4f.java:186
final Matrix4f loadIdentity()
Set this matrix to identity.
Definition: Matrix4f.java:172
static boolean mapWinToObj4(final float winx, final float winy, final float winz, final float clipw, final Matrix4f mMv, final Matrix4f mP, final Recti viewport, final float near, final float far, final Vec4f objPos, final Matrix4f mat4Tmp)
Map window coordinates to object coordinates.
Definition: Matrix4f.java:1926
final Vec3f mulVec3f(final Vec3f v_in, final Vec3f v_out)
Affine 3f-vector transformation by 4x4 matrix.
Definition: Matrix4f.java:841
final Matrix4f transpose()
Transpose this matrix.
Definition: Matrix4f.java:464
Matrix4f setToPerspective(final float fovy_rad, final float aspect, final float zNear, final float zFar)
Set this matrix to perspective frustum projection.
Definition: Matrix4f.java:1303
boolean invert()
Invert this matrix.
Definition: Matrix4f.java:530
final Matrix4f setToRotation(final Quaternion q)
Set this matrix to rotation using the given Quaternion.
Definition: Matrix4f.java:1124
final void pop()
Pop the current matrix from it's stack, replacing this matrix values.
Definition: Matrix4f.java:1610
StringBuilder toString(final StringBuilder sb, final String rowPrefix, final String f)
Definition: Matrix4f.java:2085
final Matrix4f setToRotationAxis(final float ang_rad, float x, float y, float z)
Set this matrix to rotation from the given axis and angle in radians.
Definition: Matrix4f.java:973
Matrix4f setToOrtho(final float left, final float right, final float bottom, final float top, final float zNear, final float zFar)
Set this matrix to orthogonal projection.
Definition: Matrix4f.java:1206
Matrix4f setToLookAt(final Vec3f eye, final Vec3f center, final Vec3f up, final Matrix4f tmp)
Set this matrix to the look-at matrix based on given parameters.
Definition: Matrix4f.java:1432
static boolean mapWinToRay(final float winx, final float winy, final float winz0, final float winz1, final Matrix4f mMv, final Matrix4f mP, final Recti viewport, final Ray ray, final Matrix4f mat4Tmp1)
Map two window coordinates w/ shared X/Y and distinctive Z to a Ray.
Definition: Matrix4f.java:2023
final void push()
Push the matrix to it's stack, while preserving this matrix values.
Definition: Matrix4f.java:1602
final Vec4f mulVec4f(final Vec4f v_in, final Vec4f v_out)
Definition: Matrix4f.java:806
final Matrix4f setToScale(final float x, final float y, final float z)
Set this matrix to scale.
Definition: Matrix4f.java:929
Matrix4f setToFrustum(final float left, final float right, final float bottom, final float top, final float zNear, final float zFar)
Set this matrix to frustum.
Definition: Matrix4f.java:1254
static boolean mapWinToObj(final float winx, final float winy, final float winz, final Matrix4f mMv, final Matrix4f mP, final Recti viewport, final Vec3f objPos, final Matrix4f mat4Tmp)
Map window coordinates to object coordinates.
Definition: Matrix4f.java:1778
final Matrix4f setToTranslation(final float x, final float y, final float z)
Set this matrix to translation.
Definition: Matrix4f.java:887
Quaternion implementation supporting Gimbal-Lock free rotations.
Definition: Quaternion.java:45
Simple compound denoting a ray.
Definition: Ray.java:49
Rectangle with x, y, width and height integer components.
Definition: Recti.java:34
3D Vector based upon three float components.
Definition: Vec3f.java:37
4D Vector based upon four float components.
Definition: Vec4f.java:37
Providing frustum planes derived by different inputs (P*MV, ..) used to classify objects.
Definition: Frustum.java:81
Frustum setFromMat(final Matrix4f pmv)
Calculate the frustum planes in world coordinates using the passed column major order matrix,...
Definition: Frustum.java:378
PMVMatrix4f implements the basic computer graphics Matrix4f pack using projection (P),...
final PMVMatrix4f mulMv(final Matrix4f m)
Multiply the modelview matrix: [c] = [c] x [m].
final PMVMatrix4f translateMv(final float x, final float y, final float z)
Translate the modelview matrix.
final Matrix4f getMulPMv(final Matrix4f result)
Returns multiplication result of P and Mv matrix, i.e.
final PMVMatrix4f loadP(final Matrix4f m)
Load the projection matrix with the values of the given Matrix4f.
final int getReqBits()
Returns the request bit mask, which uses bit values equal to the dirty mask and may contain.
final PMVMatrix4f scaleMv(final float x, final float y, final float z)
Scale the modelview matrix.
final PMVMatrix4f scaleMv(final Vec3f s)
Scale the modelview matrix.
static final int MANUAL_BITS
Manual bits not covered by update() but getFrustum(), FRUSTUM, getPMv(), PREMUL_PMV,...
final SyncMatrix4f getSyncMvi()
Returns the SyncMatrix of inverse modelview matrix (Mvi) if requested.
final Vec4f mulWithMv(final Vec4f v_in, final Vec4f v_out)
v_out = Mv * v_in
final Matrix4f getMvi()
Returns the inverse modelview matrix (Mvi) if requested.
final SyncMatrix4f getSyncMvit()
Returns the SyncMatrix of inverse transposed modelview matrix (Mvit) if requested.
final PMVMatrix4f rotateMv(final float ang_rad, final float x, final float y, final float z)
Rotate the modelview matrix by the given axis and angle in radians.
final PMVMatrix4f loadTIdentity()
Load the texture matrix with the values of the given Matrix4f.
final PMVMatrix4f loadMv(final float[] values, final int offset)
Load the modelview matrix with the provided values.
final SyncMatrix4f getSyncT()
Returns the SyncMatrix of texture matrix (T).
final PMVMatrix4f loadMv(final Quaternion quat)
Load the modelview matrix with the values of the given Quaternion's rotation matrix representation.
final PMVMatrix4f loadMvIdentity()
Load the modelview matrix with the values of the given Matrix4f.
final SyncMatrix4f getSyncMv()
Returns the SyncMatrix of modelview matrix (Mv).
static final int MODIFIED_PROJECTION
Bit value stating a modified projection matrix (P), since last update() call.
final PMVMatrix4f pushP()
Push the projection matrix to its stack, while preserving its values.
final PMVMatrix4f translateP(final Vec3f t)
Translate the projection matrix.
PMVMatrix4f(final int derivedMatrices)
Creates an instance of PMVMatrix4f.
final PMVMatrix4f rotateP(final float ang_rad, final Vec3f axis)
Rotate the projection matrix by the given axis and angle in radians.
final PMVMatrix4f loadMv(final java.nio.FloatBuffer m)
Load the modelview matrix with the provided values.
static final int FRUSTUM
Bit value for frustum and updated by getFrustum().
final PMVMatrix4f loadP(final float[] values, final int offset)
Load the projection matrix with the provided values.
final Vec3f mulWithMv(final Vec3f v_in, final Vec3f v_out)
v_out = Mv * v_in
final boolean mapWinToRay(final float winx, final float winy, final float winz0, final float winz1, final Recti viewport, final Ray ray)
Map two window coordinates w/ shared X/Y and distinctive Z to a Ray.
final PMVMatrix4f mulT(final Matrix4f m)
Multiply the texture matrix: [c] = [c] x [m].
final PMVMatrix4f mulP(final Matrix4f m)
Multiply the projection matrix: [c] = [c] x [m].
void reset()
Issues Matrix4f#loadIdentity() on all matrices and resets all internal states.
final int getDirtyBits()
Returns the dirty bits due to mutable operations, i.e.
final PMVMatrix4f loadT(final Quaternion quat)
Load the texture matrix with the values of the given Quaternion's rotation matrix representation.
final int getModifiedBits(final boolean clear)
Returns the modified bits due to mutable operations.
final SyncMatrix4f getSyncP()
Returns the SyncMatrix of projection matrix (P).
final Matrix4f getT()
Returns the texture matrix (T).
final PMVMatrix4f loadT(final java.nio.FloatBuffer m)
Load the texture matrix with the provided values.
final Matrix4f getMulMvP(final Matrix4f result)
Returns multiplication result of Mv and P matrix, i.e.
final PMVMatrix4f popP()
Pop the projection matrix from its stack.
final PMVMatrix4f loadP(final java.nio.FloatBuffer m)
Load the projection matrix with the provided values.
final PMVMatrix4f rotateMv(final Quaternion quat)
Rotate the modelview matrix with the given Quaternion's rotation matrix representation.
final Matrix4f getMv()
Returns the modelview matrix (Mv).
final SyncMatrices4f getSyncPMvMvi()
Returns SyncMatrices4f of 3 matrices within one FloatBuffer: P, Mv and Mvi if requested.
StringBuilder toString(StringBuilder sb, final String f)
final PMVMatrix4f loadP(final Quaternion quat)
Load the projection matrix with the values of the given Quaternion's rotation matrix representation.
static final int MODIFIED_ALL
Bit value stating all is modified.
static final int MODIFIED_MODELVIEW
Bit value stating a modified modelview matrix (Mv), since last update() call.
final PMVMatrix4f translateP(final float x, final float y, final float z)
Translate the projection matrix.
final PMVMatrix4f lookAtP(final Vec3f eye, final Vec3f center, final Vec3f up)
Multiply the projection matrix with the eye, object and orientation, i.e.
final PMVMatrix4f perspectiveP(final float fovy_rad, final float aspect, final float zNear, final float zFar)
Multiply the projection matrix with the perspective/frustum matrix.
final PMVMatrix4f rotateMv(final float ang_rad, final Vec3f axis)
Rotate the modelview matrix by the given axis and angle in radians.
static final int INVERSE_TRANSPOSED_MODELVIEW
Bit value for inverse transposed modelview matrix (Mvit), updated via update().
final Matrix4f getPMv()
Returns the pre-multiplied projection x modelview, P x Mv.
final PMVMatrix4f loadT(final Matrix4f m)
Load the texture matrix with the values of the given Matrix4f.
final PMVMatrix4f rotateP(final Quaternion quat)
Rotate the projection matrix with the given Quaternion's rotation matrix representation.
final Vec4f mulWithMv(final Vec4f v_inout)
v_inout = Mv * v_inout
final void orthoP(final float left, final float right, final float bottom, final float top, final float zNear, final float zFar)
Multiply the projection matrix with the orthogonal matrix.
final PMVMatrix4f popT()
Pop the texture matrix from its stack.
boolean mapWinToObj4(final float winx, final float winy, final float winz, final float clipw, final Recti viewport, final float near, final float far, final Vec4f objPos)
Map window coordinates to object coordinates.
final PMVMatrix4f scaleP(final float x, final float y, final float z)
Scale the projection matrix.
static final int INVERSE_MODELVIEW
Bit value for inverse modelview matrix (Mvi), updated via update().
PMVMatrix4f()
Creates an instance of PMVMatrix4f.
final boolean update()
Update the derived inverse modelview (Mvi), inverse transposed modelview (Mvit) matrices if they are ...
final SyncMatrices4f getSyncPMv()
Returns SyncMatrices4f of 2 matrices within one FloatBuffer: P and Mv.
final PMVMatrix4f scaleP(final Vec3f s)
Scale the projection matrix.
final PMVMatrix4f loadPIdentity()
Load the projection matrix with the values of the given Matrix4f.
final Frustum getFrustum()
Returns the frustum, derived from projection x modelview.
final Matrix4f getP()
Returns the projection matrix (P).
final Matrix4f getTmp2Mat()
Return the second temporary Matrix4f exposed to be reused for efficiency.
static final int MODIFIED_TEXTURE
Bit value stating a modified texture matrix (T), since last update() call.
final boolean mapObjToWin(final Vec3f objPos, final Recti viewport, final Vec3f winPos)
Map object coordinates to window coordinates.
final PMVMatrix4f popMv()
Pop the modelview matrix from its stack.
final PMVMatrix4f loadT(final float[] values, final int offset)
Load the texture matrix with the provided values.
final boolean mapWinToObj(final float winx, final float winy, final float winz, final Recti viewport, final Vec3f objPos)
Map window coordinates to object coordinates.
static final int PREMUL_PMVI
Bit value for pre-multiplied invert(P * Mv), updated by getPMvi().
final Matrix4f getPMvi()
Returns the pre-multiplied inverse projection x modelview, if Matrix4f#invert(Matrix4f) succeeded,...
final void setModelviewDirty()
Sets the Modelview (Mv) matrix dirty and modified, i.e.
final PMVMatrix4f loadMv(final Matrix4f m)
Load the modelview matrix with the values of the given Matrix4f.
final void setProjectionDirty()
Sets the Projection (P) matrix dirty and modified, i.e.
final boolean isReqDirty()
Returns true if the one of the requested bits are are set dirty due to mutable operations,...
final PMVMatrix4f pushMv()
Push the modelview matrix to its stack, while preserving its values.
final PMVMatrix4f rotateP(final float ang_rad, final float x, final float y, final float z)
Rotate the projection matrix by the given axis and angle in radians.
final PMVMatrix4f pushT()
Push the texture matrix to its stack, while preserving its values.
final PMVMatrix4f translateMv(final Vec3f t)
Translate the modelview matrix.
static final int PREMUL_PMV
Bit value for pre-multiplied P * Mv, updated by getPMv().
final Matrix4f getMvit()
Returns the inverse transposed modelview matrix (Mvit) if requested.
final void frustumP(final float left, final float right, final float bottom, final float top, final float zNear, final float zFar)
Multiply the projection matrix with the frustum matrix.
final SyncMatrices4f getSyncPMvMviMvit()
Returns SyncMatrices4f of 4 matrices within one FloatBuffer: P, Mv, Mvi and Mvit if requested.
final void setTextureDirty()
Sets the Texture (T) matrix modified.
Specific data synchronization action implemented by the data provider to update the buffer with the u...
Definition: SyncAction.java:38
void sync()
Synchronizes the buffer with the underlying data before usage.
Convenient tuple of a SyncAction and Buffer.
Definition: SyncBuffer.java:40
SyncAction getAction()
Return the SyncAction.
SyncBuffer with a multiple underlying Matrix4f, used in SyncMatrices4f16 and PMVMatrix4f
SyncBuffer interface with a single underlying Matrix4f, used in SyncMatrix4f16 and PMVMatrix4f.