Gamp v0.0.7-54-gccdc599
Gamp: Graphics, Audio, Multimedia and Processing
Loading...
Searching...
No Matches
pmvmat4.hpp
Go to the documentation of this file.
1/*
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright Gothel Software e.K.
4 *
5 * SPDX-License-Identifier: MIT
6 *
7 * This Source Code Form is subject to the terms of the MIT License
8 * If a copy of the MIT was not distributed with this file,
9 * you can obtain one at https://opensource.org/license/mit/.
10 */
11
12#ifndef JAU_MATH_UTIL_PMVMAT4f_HPP_
13#define JAU_MATH_UTIL_PMVMAT4f_HPP_
14
15#include <cassert>
16#include <cmath>
17#include <cstdarg>
18#include <cstdint>
19#include <iostream>
20#include <string>
21
22#include <jau/basic_types.hpp>
23#include <jau/debug.hpp>
24#include <jau/enum_util.hpp>
25#include <jau/functional.hpp>
27#include <jau/math/mat4f.hpp>
31#include <jau/type_concepts.hpp>
32
33namespace jau::math::util {
34
35 /** \addtogroup Math
36 *
37 * @{
38 */
39
40 using namespace jau::enums;
41
42 /** PMVMatrix4 modified core matrices */
43 enum class PMVMod : uint32_t {
44 none = 0,
45 /** Bit value stating a modified {@link #getP() projection matrix (P)}, since last {@link #update()} call. */
46 proj = 1 << 0,
47 /** Bit value stating a modified {@link #getMv() modelview matrix (Mv)}, since last {@link #update()} call. */
48 mv = 1 << 1,
49 /** Bit value stating a modified {@link #getT() texture matrix (T)}, since last {@link #update()} call. */
50 text = 1 << 2,
51 /** Bit value stating all is modified */
52 all = proj | mv | text,
53 };
55
56 /** PMVMatrix4 derived matrices and values */
57 enum class PMVData : uint32_t {
58 none = 0,
59 /** Bit value for {@link #getMvi() inverse modelview matrix (Mvi)}, updated via {@link #update()}. */
60 inv_mv = 1 << 1,
61 /** Bit value for {@link #getMvit() inverse transposed modelview matrix (Mvit)}, updated via {@link #update()}. */
62 inv_tps_mv = 1 << 2,
63 /** Bit value for {@link #getPi() inverse projection matrix (Pi)}, updated via {@link #update()}. */
64 inv_proj = 1 << 3,
65 /** Bit value for {@link #getFrustum() frustum} and updated by {@link #getFrustum()}. */
66 frustum = 1 << 4,
67 /** Bit value for {@link #getPMv() pre-multiplied P x Mv}, updated by {@link #getPMv()}. */
68 pre_pmv = 1 << 5,
69 /** Bit value for {@link #getPMvi() pre-multiplied invert(P x Mv)}, updated by {@link #getPMvi()}. */
70 pre_pmvi = 1 << 6,
71 /** Manual bits not covered by {@link #update()} but {@link #getFrustum()}, {@link #FRUSTUM}, {@link #getPMv()}, {@link #PREMUL_PMV}, {@link #getPMvi()}, {@link #PREMUL_PMVI}, etc. */
73 };
76
77/**
78 * PMVMatrix4 implements the basic computer graphics Matrix4 pack using
79 * projection (P), modelview (Mv) and texture (T) Matrix4 operations.
80 *
81 * PMVMatrix4 provides the {@link #getMvi() inverse modelview matrix (Mvi)} and
82 * {@link #getMvit() inverse transposed modelview matrix (Mvit)}.
83 * {@link Frustum} is also provided by {@link #getFrustum()}.
84 *
85 * To keep these derived values synchronized after mutable Mv operations like {@link #rotateMv(Quaternion)}
86 * users have to call {@link #update()} before using Mvi and Mvit.
87 *
88 * All matrices are provided in column-major order,
89 * as specified in the OpenGL fixed function pipeline, i.e. compatibility profile.
90 * See Matrix4.
91 *
92 * Maintaining the inverse projection provides conversion to and from view space.
93 *
94 * Passing the view or inverse-view matrix to map-functions
95 * allows conversion to and from world space.
96 *
97 * - view = V x M x Obj = Mv x Obj
98 * - world = V' x Mv x Obj = V' x V x M x Obj = M x Obj
99 * - clip = P x V x M x Obj = P x Mv x Obj
100 * etc ..
101 *
102 * PMVMatrix4 can supplement {@link com.jogamp.opengl.GL2ES2 GL2ES2} applications w/ the
103 * lack of the described matrix functionality.
104 *
105 * <a name="storageDetails"><h5>Matrix storage details</h5></a>
106 * The native data layout of the matrices are preserved, linear and can be utilized by `GLUniformData`
107 * directly to be pushed to the GPU eventually via SyncMatrix4 and SyncMatrices4,
108 * both SyncBuffer specializations for Matrix4.
109 *
110 * SyncBuffer's provided `sync_action_t` ensures that derived matrices, e.g. getMvi(), are updated before use.
111 *
112 * SyncBuffer's `sync_action_t` is called by `GLUniformData::getBuffer()`
113 * i.e. before the data is pushed to the GPU.
114 */
115template <jau::req::packed_floating_point Value_type>
117 public:
120 typedef const value_type* const_pointer;
125
131
132 private:
133 Mat4 m_matP;
134 Mat4 m_matMv;
135 Mat4 m_matMvi;
136 Mat4 m_matMvit;
137
138 Mat4 m_matPi;
139 Mat4 m_matTex;
140
141 MatrixStack<value_type> m_stackMv, m_stackP, m_stackTex;
142
143 PMVData m_requestBits; // may contain the requested bits: PMVData::inv_mv | PMVData::inv_proj | PMVData::inv_tps_mv
144
145 PMVMod m_modifiedBits = PMVMod::all;
146 PMVData m_dirtyBits = PMVData::none; // contains the dirty bits, i.e. hinting for update operation
147 Mat4 m_matPMv;
148 Mat4 m_matPMvi;
149 bool m_matPMviOK;
150 geom::Frustum m_frustum;
151
152 constexpr static PMVData matToReq(PMVData req) noexcept {
153 PMVData mask = PMVData::none;
155 mask |= PMVData::inv_mv;
156 }
157 if( PMVData::none != ( req & PMVData::inv_tps_mv ) ) {
158 mask |= PMVData::inv_tps_mv;
159 }
160 if( PMVData::none != ( req & PMVData::inv_proj ) ) {
161 mask |= PMVData::inv_proj;
162 }
163 return mask;
164 }
165
166 public:
167
168
169 /**
170 * Creates an instance of PMVMatrix4.
171 *
172 * This constructor only sets up an instance w/o additional derived INVERSE_MODELVIEW, INVERSE_PROJECTION or INVERSE_TRANSPOSED_MODELVIEW matrices.
173 *
174 * @see #PMVMatrix4(int)
175 */
176 PMVMatrix4() noexcept
177 : PMVMatrix4(PMVData::none) { }
178
179 /**
180 * Creates an instance of PMVMatrix4.
181 *
182 * Additional derived matrices can be requested via `derivedMatrices`, i.e.
183 * - INVERSE_MODELVIEW
184 * - INVERSE_PROJECTION
185 * - INVERSE_TRANSPOSED_MODELVIEW
186 *
187 * Implementation uses native Matrix4 elements using column-order fields.
188 * Derived matrices are updated at retrieval, e.g. getMvi(), or via synchronized access, e.g. makeSyncMvi(), to the actual Mat4 instances.
189 *
190 * @param derivedMatrices additional matrices can be requested by passing bits {@link #INVERSE_MODELVIEW}, INVERSE_PROJECTION and {@link #INVERSE_TRANSPOSED_MODELVIEW}.
191 * @see #getReqBits()
192 * @see #isReqDirty()
193 * @see #getDirtyBits()
194 * @see #update()
195 */
196 PMVMatrix4(PMVData derivedMatrices) noexcept
197 : m_requestBits( matToReq(derivedMatrices) )
198 {
199 m_matPMviOK = false;
200 reset();
201 }
202
203 /** Returns the component's value_type signature */
204 const jau::type_info& compSignature() const noexcept { return jau::static_ctti<value_type>(); }
205
206 /** Return the number of Mat4 referenced by matrices() */
207 static size_t matrixCount(PMVData derivedMatrices) noexcept {
208 const PMVData requestBits = matToReq(derivedMatrices);
209 {
211 if( m == ( m & requestBits ) ) {
212 return 4; // P, Mv, Mvi and Mvit
213 }
214 }
215 {
216 constexpr PMVData m = PMVData::inv_mv;
217 if( m == ( m & requestBits ) ) {
218 return 3; // P, Mv, Mvi
219 }
220 }
221 return 2; // P, Mv
222 }
223 /** Return the number of Mat4 referenced by matrices() */
224 size_t matrixCount() const noexcept { return matrixCount(m_requestBits); }
225
226 /**
227 * Issues {@link Mat4#loadIdentity()} on all matrices and resets all internal states.
228 */
229 constexpr void reset() noexcept {
230 m_matP.loadIdentity();
231 m_matMv.loadIdentity();
232 m_matTex.loadIdentity();
233
234 m_modifiedBits = PMVMod::all;
235 m_dirtyBits = m_requestBits | PMVData::manual;
236 }
237
238 //
239 // Regular Mat4 access as well as their SyncedBuffer counterpart SyncedMatrix and SyncedMatrices
240 //
241
242 /**
243 * Returns the {@link GLMatrixFunc#GL_TEXTURE_MATRIX texture matrix} (T).
244 * <p>
245 * Consider using {@link #setTextureDirty()} if modifying the returned {@link Mat4}.
246 * </p>
247 * <p>
248 * See <a href="#storageDetails"> matrix storage details</a>.
249 * </p>
250 */
251 constexpr Mat4& getT() noexcept { return m_matTex; }
252 constexpr const Mat4& getT() const noexcept { return m_matTex; }
253
254 /**
255 * Returns the {@link GLMatrixFunc#GL_PROJECTION_MATRIX projection matrix} (P).
256 * <p>
257 * Consider using {@link #setProjectionDirty()} if modifying the returned {@link Mat4}.
258 * </p>
259 * <p>
260 * See <a href="#storageDetails"> matrix storage details</a>.
261 * </p>
262 */
263 constexpr Mat4& getP() noexcept { return m_matP; }
264 constexpr const Mat4& getP() const noexcept { return m_matP; }
265
266 /**
267 * Returns the {@link GLMatrixFunc#GL_MODELVIEW_MATRIX modelview matrix} (Mv).
268 * <p>
269 * Consider using {@link #setModelviewDirty()} if modifying the returned {@link Mat4}.
270 * </p>
271 * <p>
272 * See <a href="#storageDetails"> matrix storage details</a>.
273 * </p>
274 */
275 constexpr Mat4& getMv() noexcept { return m_matMv; }
276 constexpr const Mat4& getMv() const noexcept { return m_matMv; }
277
278 /**
279 * Returns the inverse {@link GLMatrixFunc#GL_MODELVIEW_MATRIX modelview matrix} (Pi) if requested.
280 * <p>
281 * See <a href="#storageDetails"> matrix storage details</a>.
282 * </p>
283 * @throws IllegalArgumentException if {@link #INVERSE_PROJECTION} has not been requested in ctor {@link #PMVMatrix4(int)}.
284 */
285 const Mat4& getPi() {
286 if( !is_set(m_requestBits, PMVData::inv_proj) ) {
287 throw jau::IllegalArgumentError("Not requested in ctor", E_FILE_LINE);
288 }
289 updateImpl(false);
290 return m_matPi;
291 }
292
293 /**
294 * Returns the inverse {@link GLMatrixFunc#GL_MODELVIEW_MATRIX modelview matrix} (Mvi) if requested.
295 * <p>
296 * See <a href="#storageDetails"> matrix storage details</a>.
297 * </p>
298 * @throws IllegalArgumentException if {@link #INVERSE_MODELVIEW} has not been requested in ctor {@link #PMVMatrix4(int)}.
299 */
300 const Mat4& getMvi() {
301 if( !is_set(m_requestBits, PMVData::inv_mv) ) {
302 throw jau::IllegalArgumentError("Not requested in ctor", E_FILE_LINE);
303 }
304 updateImpl(false);
305 return m_matMvi;
306 }
307
308 /**
309 * Returns the inverse transposed {@link GLMatrixFunc#GL_MODELVIEW_MATRIX modelview matrix} (Mvit) if requested.
310 * <p>
311 * See <a href="#storageDetails"> matrix storage details</a>.
312 * </p>
313 * @throws IllegalArgumentException if {@link #INVERSE_TRANSPOSED_MODELVIEW} has not been requested in ctor {@link #PMVMatrix4(int)}.
314 */
315 const Mat4& getMvit() {
316 if( !is_set(m_requestBits, PMVData::inv_tps_mv) ) {
317 throw jau::IllegalArgumentError("Not requested in ctor", E_FILE_LINE);
318 }
319 updateImpl(false);
320 return m_matMvit;
321 }
322
323 /**
324 * Returns a new SyncMatrix of {@link GLMatrixFunc#GL_PROJECTION_MATRIX projection matrix} (P).
325 * <p>
326 * See <a href="#storageDetails"> matrix storage details</a>.
327 * </p>
328 */
329 constexpr SyncMats4 makeSyncP() noexcept { return SyncMats4(m_matP, 1); }
330
331 /**
332 * Returns a new SyncMatrix of {@link GLMatrixFunc#GL_MODELVIEW_MATRIX modelview matrix} (Mv).
333 * <p>
334 * See <a href="#storageDetails"> matrix storage details</a>.
335 * </p>
336 */
337 constexpr SyncMats4 makeSyncMv() noexcept { return SyncMats4(m_matMv, 1); }
338
339 /**
340 * Returns a new SyncMatrices4f of 2 matrices within one FloatBuffer: {@link #getP() P} and {@link #getMv() Mv}.
341 * <p>
342 * See <a href="#storageDetails"> matrix storage details</a>.
343 * </p>
344 */
345 SyncMats4f makeSyncPMv() noexcept { return SyncMats4f(m_matP, 2); }
346
347 /**
348 * Returns a new SyncMatrix of {@link GLMatrixFunc#GL_TEXTURE_MATRIX texture matrix} (T).
349 * <p>
350 * See <a href="#storageDetails"> matrix storage details</a>.
351 * </p>
352 */
353 SyncMats4 makeSyncT() noexcept { return SyncMat4(m_matTex, 1); }
354
355 /**
356 * Returns a new SyncMatrix of inverse {@link GLMatrixFunc#GL_MODELVIEW_MATRIX modelview matrix} (Mvi) if requested.
357 * <p>
358 * See <a href="#storageDetails"> matrix storage details</a>.
359 * </p>
360 * @throws IllegalArgumentException if {@link #INVERSE_MODELVIEW} has not been requested in ctor {@link #PMVMatrix4(int)}.
361 */
363 if( !is_set(m_requestBits, PMVData::inv_mv) ) {
364 throw jau::IllegalArgumentError("Not requested in ctor", E_FILE_LINE);
365 }
366 return SyncMats4(m_matMvi, 1, jau::bind_member(this, &PMVMatrix4::updateImpl0));
367 }
368
369 /**
370 * Returns a new SyncMatrix of inverse transposed {@link GLMatrixFunc#GL_MODELVIEW_MATRIX modelview matrix} (Mvit) if requested.
371 * <p>
372 * See <a href="#storageDetails"> matrix storage details</a>.
373 * </p>
374 * @throws IllegalArgumentException if {@link #INVERSE_TRANSPOSED_MODELVIEW} has not been requested in ctor {@link #PMVMatrix4(int)}.
375 */
377 if( !is_set(m_requestBits, PMVData::inv_tps_mv) ) {
378 throw jau::IllegalArgumentError("Not requested in ctor", E_FILE_LINE);
379 }
380 return SyncMats4(m_matMvit, 1, jau::bind_member(this, &PMVMatrix4::updateImpl0));
381 }
382
383 /**
384 * Returns a new SyncMatrices4f of 3 matrices within one FloatBuffer: {@link #getP() P}, {@link #getMv() Mv} and {@link #getMvi() Mvi} if requested.
385 * <p>
386 * See <a href="#storageDetails"> matrix storage details</a>.
387 * </p>
388 * @throws IllegalArgumentException if PMVData::inv_mv has not been requested in ctor.
389 */
391 if( !is_set(m_requestBits, PMVData::inv_mv) ) {
392 throw jau::IllegalArgumentError("Not requested in ctor", E_FILE_LINE);
393 }
394 return SyncMats4f(m_matP, 3, jau::bind_member(this, &PMVMatrix4::updateImpl0));
395 }
396
397 /**
398 * Returns a new SyncMatrices4f of 4 matrices within one FloatBuffer: {@link #getP() P}, {@link #getMv() Mv}, {@link #getMvi() Mvi} and {@link #getMvit() Mvit} if requested.
399 * <p>
400 * See <a href="#storageDetails"> matrix storage details</a>.
401 * </p>
402 * @throws IllegalArgumentException if PMVData::inv_mv or PMVData::inv_tps_mv has not been requested in ctor.
403 */
405 if( !is_set(m_requestBits, PMVData::inv_mv) ||
406 !is_set(m_requestBits, PMVData::inv_tps_mv) )
407 {
408 throw jau::IllegalArgumentError("Not requested in ctor", E_FILE_LINE);
409 }
410 return SyncMats4f(m_matP, 4, jau::bind_member(this, &PMVMatrix4::updateImpl0));
411 }
412
413 /**
414 * Returns a new SyncMatrices4f of either 4 matrices makeSyncPMvMviMvit(), 3 matrices makeSyncPMvMvi() or 2 matrices makeSyncPMv()
415 * depending on requestedBits().
416 *
417 * See <a href="#storageDetails"> matrix storage details</a>.
418 */
420 {
422 if( m == ( m & m_requestBits ) ) {
423 return makeSyncPMvMviMvit(); // P, Mv, Mvi and Mvit
424 }
425 }
426 {
427 constexpr PMVData m = PMVData::inv_mv;
428 if( m == ( m & m_requestBits ) ) {
429 return makeSyncPMvMvi(); // P, Mv, Mvi
430 }
431 }
432 return makeSyncPMv(); // P, Mv
433 }
434
435 //
436 // Basic Mat4, Vec3 and Vec4 operations similar to GLMatrixFunc
437 //
438
439 /**
440 * Returns multiplication result of {@link #getP() P} and {@link #getMv() Mv} matrix, i.e.
441 * <pre>
442 * result = P x Mv
443 * </pre>
444 * @param result 4x4 matrix storage for result
445 * @return given result matrix for chaining
446 */
447 constexpr Mat4& getMulPMv(Mat4& result) noexcept {
448 return result.mul(m_matP, m_matMv);
449 }
450
451 /**
452 * Returns multiplication result of {@link #getMv() Mv} and {@link #getP() P} matrix, i.e.
453 * <pre>
454 * result = Mv x P
455 * </pre>
456 * @param result 4x4 matrix storage for result
457 * @return given result matrix for chaining
458 */
459 constexpr Mat4& getMulMvP(Mat4& result) noexcept {
460 return result.mul(m_matMv, m_matP);
461 }
462
463 /**
464 * v_out = Mv x v_in
465 * @param v_in input vector, can be v_out for in-place transformation
466 * @param v_out output vector
467 * @returns v_out for chaining
468 */
469 constexpr Vec4& mulWithMv(const Vec4& v_in, Vec4& v_out) noexcept {
470 return m_matMv.mulVec4(v_in, v_out);
471 }
472
473 /**
474 * v_inout = Mv x v_inout
475 * @param v_inout input and output vector, i.e. in-place transformation
476 * @returns v_inout for chaining
477 */
478 constexpr Vec4& mulWithMv(Vec4& v_inout) noexcept {
479 return m_matMv.mulVec4(v_inout);
480 }
481
482 /**
483 * v_out = Mv x v_in
484 *
485 * Affine 3f-vector transformation by 4x4 matrix, see {@link Mat4#mulVec3(Vec3, Vec3)}.
486 *
487 * @param v_in input vector, can be v_out for in-place transformation
488 * @param v_out output vector
489 * @returns v_out for chaining
490 */
491 constexpr Vec3& mulWithMv(const Vec3& v_in, Vec3& v_out) noexcept {
492 return m_matMv.mulVec3(v_in, v_out);
493 }
494
495 //
496 // GLMatrixFunc alike functionality
497 //
498
499 /**
500 * Load the {@link #getMv() modelview matrix} with the provided values.
501 */
502 constexpr PMVMatrix4& loadMv(float values[]) noexcept {
503 m_matMv.load(values);
505 return *this;
506 }
507 /**
508 * Load the {@link #getMv() modelview matrix} with the values of the given {@link Mat4}.
509 */
510 constexpr PMVMatrix4& loadMv(const Mat4& m) noexcept {
511 m_matMv.load(m);
513 return *this;
514 }
515 /**
516 * Load the {@link #getMv() modelview matrix} with the values of the given {@link Quaternion}'s rotation Quaternion::toMatrix() representation.
517 */
518 constexpr PMVMatrix4& loadMv(const Quat4f& quat) noexcept {
519 quat.toMatrix(m_matMv);
521 return *this;
522 }
523
524 /**
525 * Load the {@link #getP() projection matrix} with the provided values.
526 */
527 constexpr PMVMatrix4& loadP(float values[]) noexcept {
528 m_matP.load(values);
530 return *this;
531 }
532 /**
533 * Load the {@link #getP() projection matrix} with the values of the given {@link Mat4}.
534 */
535 constexpr PMVMatrix4& loadP(const Mat4& m) {
536 m_matP.load(m);
538 return *this;
539 }
540 /**
541 * Load the {@link #getP() projection matrix} with the values of the given {@link Quaternion}'s rotation Quaternion::toMatrix() representation.
542 */
543 constexpr PMVMatrix4& loadP(const Quat4f& quat) noexcept {
544 quat.toMatrix(m_matP);
546 return *this;
547 }
548
549 /**
550 * Load the {@link #getT() texture matrix} with the provided values.
551 */
552 constexpr PMVMatrix4& loadT(float values[]) noexcept {
553 m_matTex.load(values);
555 return *this;
556 }
557 /**
558 * Load the {@link #getT() texture matrix} with the values of the given {@link Mat4}.
559 */
560 constexpr PMVMatrix4& loadT(Mat4& m) noexcept {
561 m_matTex.load(m);
563 return *this;
564 }
565 /**
566 * Load the {@link #getT() texture matrix} with the values of the given {@link Quaternion}'s rotation Quaternion::toMatrix() representation.
567 */
568 constexpr PMVMatrix4& loadT(const Quat4f& quat) noexcept {
569 quat.toMatrix(m_matTex);
571 return *this;
572 }
573
574 /**
575 * Load the {@link #getMv() modelview matrix} with the values of the given {@link Mat4}.
576 */
577 constexpr PMVMatrix4& loadMvIdentity() noexcept {
578 m_matMv.loadIdentity();
580 return *this;
581 }
582
583 /**
584 * Load the {@link #getP() projection matrix} with the values of the given {@link Mat4}.
585 */
586 constexpr PMVMatrix4& loadPIdentity() noexcept {
587 m_matP.loadIdentity();
589 return *this;
590 }
591
592 /**
593 * Load the {@link #getT() texture matrix} with the values of the given {@link Mat4}.
594 */
595 constexpr PMVMatrix4& loadTIdentity() noexcept {
596 m_matTex.loadIdentity();
598 return *this;
599 }
600
601 /**
602 * Multiply the {@link #getMv() modelview matrix}: [c] = [c] x [m]
603 * @param m the right hand Mat4
604 * @return *this instance of chaining
605 */
606 constexpr PMVMatrix4& mulMv(const Mat4& m) noexcept {
607 m_matMv.mul( m );
609 return *this;
610 }
611
612 /**
613 * Multiply the {@link #getP() projection matrix}: [c] = [c] x [m]
614 * @param m the right hand Mat4
615 * @return *this instance of chaining
616 */
617 constexpr PMVMatrix4& mulP(const Mat4& m) noexcept {
618 m_matP.mul( m );
620 return *this;
621 }
622
623 /**
624 * Multiply the {@link #getT() texture matrix}: [c] = [c] x [m]
625 * @param m the right hand Mat4
626 * @return *this instance of chaining
627 */
628 constexpr PMVMatrix4& mulT(const Mat4& m) noexcept {
629 m_matTex.mul( m );
631 return *this;
632 }
633
634 /**
635 * Translate the {@link #getMv() modelview matrix}.
636 * @param x
637 * @param y
638 * @param z
639 * @return *this instance of chaining
640 */
641 constexpr PMVMatrix4& translateMv(float x, float y, float z) noexcept {
642 Mat4 mat4Tmp1;
643 return mulMv( mat4Tmp1.setToTranslation(x, y, z) );
644 }
645 /**
646 * Translate the {@link #getMv() modelview matrix}.
647 * @param t translation vec3
648 * @return *this instance of chaining
649 */
650 constexpr PMVMatrix4& translateMv(const Vec3& t) noexcept {
651 Mat4 mat4Tmp1;
652 return mulMv( mat4Tmp1.setToTranslation(t) );
653 }
654
655 /**
656 * Translate the {@link #getP() projection matrix}.
657 * @param x
658 * @param y
659 * @param z
660 * @return *this instance of chaining
661 */
662 constexpr PMVMatrix4& translateP(float x, float y, float z) noexcept {
663 Mat4 mat4Tmp1;
664 return mulP( mat4Tmp1.setToTranslation(x, y, z) );
665 }
666 /**
667 * Translate the {@link #getP() projection matrix}.
668 * @param t translation vec3
669 * @return *this instance of chaining
670 */
671 constexpr PMVMatrix4& translateP(const Vec3& t) noexcept {
672 Mat4 mat4Tmp1;
673 return mulP( mat4Tmp1.setToTranslation(t) );
674 }
675
676 /**
677 * Scale the {@link #getMv() modelview matrix}.
678 * @param x
679 * @param y
680 * @param z
681 * @return *this instance of chaining
682 */
683 constexpr PMVMatrix4& scaleMv(float x, float y, float z) noexcept {
684 Mat4 mat4Tmp1;
685 return mulMv( mat4Tmp1.setToScale(x, y, z) );
686 }
687 /**
688 * Scale the {@link #getMv() modelview matrix}.
689 * @param s scale vec4f
690 * @return *this instance of chaining
691 */
692 constexpr PMVMatrix4& scaleMv(const Vec3& s) noexcept {
693 Mat4 mat4Tmp1;
694 return mulMv( mat4Tmp1.setToScale(s) );
695 }
696
697 /**
698 * Scale the {@link #getP() projection matrix}.
699 * @param x
700 * @param y
701 * @param z
702 * @return *this instance of chaining
703 */
704 constexpr PMVMatrix4& scaleP(float x, float y, float z) noexcept {
705 Mat4 mat4Tmp1;
706 return mulP( mat4Tmp1.setToScale(x, y, z) );
707 }
708 /**
709 * Scale the {@link #getP() projection matrix}.
710 * @param s scale vec4f
711 * @return *this instance of chaining
712 */
713 constexpr PMVMatrix4& scaleP(const Vec3& s) noexcept {
714 Mat4 mat4Tmp1;
715 return mulP( mat4Tmp1.setToScale(s) );
716 }
717
718 /**
719 * Rotate the {@link #getMv() modelview matrix} by the given axis and angle in radians.
720 * <p>
721 * Consider using {@link #rotateMv(Quaternion)}
722 * </p>
723 * @param ang_rad angle in radians
724 * @param axis rotation axis
725 * @return *this instance of chaining
726 * @see #rotateMv(Quaternion)
727 */
728 constexpr_cxx26 PMVMatrix4& rotateMv(const float ang_rad, const float x, const float y, const float z) noexcept {
729 Mat4 mat4Tmp1;
730 return mulMv( mat4Tmp1.setToRotationAxis(ang_rad, x, y, z) );
731 }
732 /**
733 * Rotate the {@link #getMv() modelview matrix} by the given axis and angle in radians.
734 * <p>
735 * Consider using {@link #rotateMv(Quaternion)}
736 * </p>
737 * @param ang_rad angle in radians
738 * @param axis rotation axis
739 * @return *this instance of chaining
740 * @see #rotateMv(Quaternion)
741 */
742 constexpr_cxx26 PMVMatrix4& rotateMv(const float ang_rad, const Vec3& axis) noexcept {
743 Mat4 mat4Tmp1;
744 return mulMv( mat4Tmp1.setToRotationAxis(ang_rad, axis) );
745 }
746 /**
747 * Rotate the {@link #getMv() modelview matrix} with the given {@link Quaternion}'s rotation {@link Mat4#setToRotation(Quaternion) matrix representation}.
748 * @param quat the {@link Quaternion}
749 * @return *this instance of chaining
750 */
751 constexpr PMVMatrix4& rotateMv(const Quat4f& quat) noexcept {
752 Mat4 mat4Tmp1;
753 return mulMv( quat.toMatrix(mat4Tmp1) );
754 }
755
756 /**
757 * Rotate the {@link #getP() projection matrix} by the given axis and angle in radians.
758 * <p>
759 * Consider using {@link #rotateP(Quaternion)}
760 * </p>
761 * @param ang_rad angle in radians
762 * @param axis rotation axis
763 * @return *this instance of chaining
764 * @see #rotateP(Quaternion)
765 */
766 constexpr_cxx26 PMVMatrix4& rotateP(const float ang_rad, const float x, const float y, const float z) noexcept {
767 Mat4 mat4Tmp1;
768 return mulP( mat4Tmp1.setToRotationAxis(ang_rad, x, y, z) );
769 }
770 /**
771 * Rotate the {@link #getP() projection matrix} by the given axis and angle in radians.
772 * <p>
773 * Consider using {@link #rotateP(Quaternion)}
774 * </p>
775 * @param ang_rad angle in radians
776 * @param axis rotation axis
777 * @return *this instance of chaining
778 * @see #rotateP(Quaternion)
779 */
780 constexpr_cxx26 PMVMatrix4& rotateP(const float ang_rad, const Vec3& axis) noexcept {
781 Mat4 mat4Tmp1;
782 return mulP( mat4Tmp1.setToRotationAxis(ang_rad, axis) );
783 }
784 /**
785 * Rotate the {@link #getP() projection matrix} with the given {@link Quaternion}'s rotation {@link Mat4#setToRotation(Quaternion) matrix representation}.
786 * @param quat the {@link Quaternion}
787 * @return *this instance of chaining
788 */
789 constexpr PMVMatrix4& rotateP(const Quat4f& quat) noexcept {
790 Mat4 mat4Tmp1;
791 return mulP( quat.toMatrix(mat4Tmp1) );
792 }
793
794 /** Pop the {@link #getMv() modelview matrix} from its stack. */
796 m_stackMv.pop(m_matMv);
798 return *this;
799 }
800 /** Pop the {@link #getP() projection matrix} from its stack. */
802 m_stackP.pop(m_matP);
804 return *this;
805 }
806 /** Pop the {@link #getT() texture matrix} from its stack. */
808 m_stackTex.pop(m_matTex);
810 return *this;
811 }
812 /** Push the {@link #getMv() modelview matrix} to its stack, while preserving its values. */
814 m_stackMv.push(m_matMv);
815 return *this;
816 }
817 /** Push the {@link #getP() projection matrix} to its stack, while preserving its values. */
819 m_stackP.push(m_matP);
820 return *this;
821 }
822 /** Push the {@link #getT() texture matrix} to its stack, while preserving its values. */
824 m_stackTex.push(m_matTex);
825 return *this;
826 }
827
828 /**
829 * {@link #mulP(Mat4) Multiply} the {@link #getP() projection matrix} with the orthogonal matrix.
830 * @param left
831 * @param right
832 * @param bottom
833 * @param top
834 * @param zNear
835 * @param zFar
836 * @see Mat4#setToOrtho(float, float, float, float, float, float)
837 */
838 constexpr void orthoP(const float left, const float right, const float bottom, const float top, const float zNear, const float zFar) noexcept {
839 Mat4 mat4Tmp1;
840 mulP( mat4Tmp1.setToOrtho(left, right, bottom, top, zNear, zFar) );
841 }
842
843 /**
844 * {@link #mulP(Mat4) Multiply} the {@link #getP() projection matrix} with the frustum matrix.
845 *
846 * @throws IllegalArgumentException if {@code zNear <= 0} or {@code zFar <= zNear}
847 * or {@code left == right}, or {@code bottom == top}.
848 * @see Mat4#setToFrustum(float, float, float, float, float, float)
849 */
850 void frustumP(const float left, const float right, const float bottom, const float top, const float zNear, const float zFar) {
851 Mat4 mat4Tmp1;
852 mulP( mat4Tmp1.setToFrustum(left, right, bottom, top, zNear, zFar) );
853 }
854
855 //
856 // Extra functionality
857 //
858
859 /**
860 * Set the {@link #getP() projection matrix} to the perspective/frustum matrix.
861 *
862 * @param fovy_rad fov angle in radians
863 * @param aspect aspect ratio width / height
864 * @param zNear
865 * @param zFar
866 * @throws IllegalArgumentException if {@code zNear <= 0} or {@code zFar <= zNear}
867 * @see Mat4#setToPerspective(float, float, float, float)
868 */
869 PMVMatrix4& setToPerspective(const float fovy_rad, const float aspect, const float zNear, const float zFar) {
870 m_matP.setToPerspective(fovy_rad, aspect, zNear, zFar);
872 return *this;
873 }
874
875 /**
876 * {@link #mulP(Mat4) Multiply} the {@link #getP() projection matrix} with the perspective/frustum matrix.
877 *
878 * @param fovy_rad fov angle in radians
879 * @param aspect aspect ratio width / height
880 * @param zNear
881 * @param zFar
882 * @throws IllegalArgumentException if {@code zNear <= 0} or {@code zFar <= zNear}
883 * @see Mat4#setToPerspective(float, float, float, float)
884 */
885 PMVMatrix4& perspectiveP(const float fovy_rad, const float aspect, const float zNear, const float zFar) {
886 Mat4 mat4Tmp1;
887 mulP( mat4Tmp1.setToPerspective(fovy_rad, aspect, zNear, zFar) );
888 return *this;
889 }
890
891 /**
892 * Set the {@link #getMv() modelview matrix}
893 * to the eye, object and orientation (camera), i.e. {@link Mat4#setToLookAt(Vec3, Vec3, Vec3, Mat4)}.
894 */
895 constexpr PMVMatrix4& setToLookAtMv(const Vec3& eye, const Vec3& center, const Vec3& up) noexcept {
896 m_matMv.setToLookAt(eye, center, up);
898 return *this;
899 }
900
901 /**
902 * {@link #mulMv(Mat4) Multiply} the {@link #getMv() modelview matrix}
903 * with the eye, object and orientation (camera), i.e. {@link Mat4#setToLookAt(Vec3, Vec3, Vec3, Mat4)}.
904 */
905 constexpr PMVMatrix4& lookAtMv(const Vec3& eye, const Vec3& center, const Vec3& up) noexcept {
906 Mat4 mat4Tmp1;
907 mulMv( mat4Tmp1.setToLookAt(eye, center, up) );
908 return *this;
909 }
910
911 /**
912 * Map object coordinates to window coordinates.
913 *
914 * Traditional <code>gluProject</code> implementation.
915 *
916 * @param objPos 3 component object coordinate
917 * @param viewport Rect4i viewport
918 * @param winPos 3 component window coordinate, the result
919 * @return true if successful, otherwise false (z is 1)
920 */
921 bool mapObjToWin(const Vec3& objPos, const Recti& viewport, Vec3& winPos) const noexcept {
922 return Mat4::mapObjToWin(objPos, m_matMv, m_matP, viewport, winPos);
923 }
924
925 /**
926 * Map world coordinates to window coordinates.
927 *
928 * - world = M x Obj
929 * - win = P x V x World = P x V' x Mv
930 * - V' x V x M = M, with Mv = V x M
931 *
932 * @param objPos 3 component object coordinate
933 * @param matV the view matrix
934 * @param viewport Rect4i viewport
935 * @param winPos 3 component window coordinate, the result
936 * @return true if successful, otherwise false (z is 1)
937 */
938 bool mapWorldToWin(const Vec3& objPos, const Mat4& matV, const Recti& viewport, Vec3& winPos) const noexcept {
939 return Mat4::mapWorldToWin(objPos, matV, m_matP, viewport, winPos);
940 }
941
942 /**
943 * Map view coordinates ( Mv x object ) to window coordinates.
944 *
945 * @param view view position, 3 component vector
946 * @param mP projection matrix
947 * @param viewport Rect4i viewport
948 * @param winPos 3 component window coordinate, the result
949 * @return true if successful, otherwise false (z is 1)
950 */
951 bool mapViewToWin(const Vec3& view, const Recti& viewport, Vec3& winPos) const noexcept {
952 return Mat4::mapViewToWin(view, m_matP, viewport, winPos);
953 }
954
955 /**
956 * Map window coordinates to object coordinates.
957 * <p>
958 * Traditional <code>gluUnProject</code> implementation.
959 * </p>
960 *
961 * @param winx
962 * @param winy
963 * @param winz
964 * @param viewport Rect4i viewport
965 * @param objPos 3 component object coordinate, the result
966 * @return true if successful, otherwise false (failed to invert matrix, or becomes infinity due to zero z)
967 */
968 bool mapWinToObj(const float winx, const float winy, const float winz,
969 const Recti& viewport, Vec3& objPos) noexcept {
970 if( Mat4::mapWinToAny(winx, winy, winz, getPMvi(), viewport, objPos) ) {
971 return true;
972 } else {
973 return false;
974 }
975 }
976
977 /**
978 * Map window coordinates to object coordinates.
979 *
980 * The INVERSE_PROJECTION must have been request in the constructor.
981 *
982 * - Pv' = P' x V', using getPi()
983 * - V' x V x M = M, with Mv = V x M
984 *
985 * @param winx
986 * @param winy
987 * @param winz
988 * @param matVi the inverse view matrix
989 * @param viewport Rect4i viewport
990 * @param objPos 3 component object coordinate, the result
991 * @return true if successful, otherwise false (failed to invert matrix, or becomes infinity due to zero z)
992 */
993 bool mapWinToWorld(const float winx, const float winy, const float winz,
994 const Mat4& matVi, const Recti& viewport, Vec3& objPos) noexcept {
995 Mat4 invPv;
996 invPv.mul(getPi(), matVi);
997 if( Mat4::mapWinToAny(winx, winy, winz, invPv, viewport, objPos) ) {
998 return true;
999 } else {
1000 return false;
1001 }
1002 }
1003
1004 /**
1005 * Map window coordinates to view coordinates.
1006 *
1007 * @param winx
1008 * @param winy
1009 * @param winz
1010 * @param viewport Rect4i viewport
1011 * @param objPos 3 component object coordinate, the result
1012 * @return true if successful, otherwise false (failed to invert matrix, or becomes infinity due to zero z)
1013 */
1014 bool mapWinToView(const float winx, const float winy, const float winz,
1015 const Recti& viewport, Vec3& objPos) noexcept {
1016 if( Mat4::mapWinToAny(winx, winy, winz, getPi(), viewport, objPos) ) {
1017 return true;
1018 } else {
1019 return false;
1020 }
1021 }
1022
1023 /**
1024 * Map window coordinates to object coordinates.
1025 * <p>
1026 * Traditional <code>gluUnProject4</code> implementation.
1027 * </p>
1028 *
1029 * @param winx
1030 * @param winy
1031 * @param winz
1032 * @param clipw
1033 * @param viewport Rect4i viewport
1034 * @param near
1035 * @param far
1036 * @param objPos 4 component object coordinate, the result
1037 * @return true if successful, otherwise false (failed to invert matrix, or becomes infinity due to zero z)
1038 */
1039 bool mapWinToObj4(const float winx, const float winy, const float winz, const float clipw,
1040 const Recti& viewport, const float near, const float far, Vec4& objPos) const noexcept {
1041 if( Mat4::mapWinToObj4(winx, winy, winz, clipw, getPMvi(), viewport, near, far, objPos) ) {
1042 return true;
1043 } else {
1044 return false;
1045 }
1046 }
1047
1048 /**
1049 * Map two window coordinates w/ shared X/Y and distinctive Z
1050 * to a {@link Ray} in object space.
1051 *
1052 * The resulting {@link Ray} maybe used for <i>picking</i>
1053 * using a {@link AABBox#getRayIntersection(Vec3, Ray, float, bool) bounding box}
1054 * of a shape also in object space.
1055 *
1056 * Notes for picking <i>winz0</i> and <i>winz1</i>:
1057 * - see jau::math::util::getZBufferEpsilon()
1058 * - see jau::math::util::getZBufferValue()
1059 * - see jau::math::util::getOrthoWinZ()
1060 * @param winx
1061 * @param winy
1062 * @param winz0
1063 * @param winz1
1064 * @param viewport
1065 * @param ray storage for the resulting {@link Ray}
1066 * @return true if successful, otherwise false (failed to invert matrix, or becomes z is infinity)
1067 */
1068 bool mapWinToObjRay(const float winx, const float winy, const float winz0, const float winz1,
1069 const Recti& viewport, Ray3f& ray) noexcept {
1070 return Mat4::mapWinToAnyRay(winx, winy, winz0, winz1, getPMvi(), viewport, ray);
1071 }
1072
1073 /**
1074 * Map two window coordinates w/ shared X/Y and distinctive Z
1075 * to a {@link Ray} in world space.
1076 *
1077 * The resulting {@link Ray} maybe used for <i>picking</i>
1078 * using a {@link AABBox#getRayIntersection(Vec3, Ray, float, bool) bounding box}
1079 * of a shape also in world space.
1080 *
1081 * The INVERSE_PROJECTION must have been request in the constructor.
1082 *
1083 * - Pv' = P' x V', using getPi()
1084 * - V' x V x M = M, with Mv = V x M
1085 *
1086 * Notes for picking <i>winz0</i> and <i>winz1</i>:
1087 * - see jau::math::util::getZBufferEpsilon()
1088 * - see jau::math::util::getZBufferValue()
1089 * - see jau::math::util::getOrthoWinZ()
1090 * @param winx
1091 * @param winy
1092 * @param winz0
1093 * @param winz1
1094 * @param matVi the inverse view matrix
1095 * @param viewport
1096 * @param ray storage for the resulting {@link Ray}
1097 * @return true if successful, otherwise false (failed to invert matrix, or becomes z is infinity)
1098 *
1099 * @see INVERSE_PROJECTION
1100 * @see setView()
1101 */
1102 bool mapWinToWorldRay(const float winx, const float winy, const float winz0, const float winz1,
1103 const Mat4& matVi, const Recti& viewport, Ray3f& ray) noexcept {
1104 Mat4 invPv;
1105 invPv.mul(getPi(), matVi);
1106 return Mat4::mapWinToAnyRay(winx, winy, winz0, winz1, invPv, viewport, ray);
1107 }
1108
1109 /**
1110 * Map two window coordinates w/ shared X/Y and distinctive Z
1111 * to a {@link Ray} in view space.
1112 *
1113 * The resulting {@link Ray} maybe used for <i>picking</i>
1114 * using a {@link AABBox#getRayIntersection(Vec3, Ray, float, bool) bounding box}
1115 * of a shape also in view space.
1116 *
1117 * Notes for picking <i>winz0</i> and <i>winz1</i>:
1118 * - see jau::math::util::getZBufferEpsilon()
1119 * - see jau::math::util::getZBufferValue()
1120 * - see jau::math::util::getOrthoWinZ()
1121 * @param winx
1122 * @param winy
1123 * @param winz0
1124 * @param winz1
1125 * @param viewport
1126 * @param ray storage for the resulting {@link Ray}
1127 * @return true if successful, otherwise false (failed to invert matrix, or becomes z is infinity)
1128 */
1129 bool mapWinToViewRay(const float winx, const float winy, const float winz0, const float winz1,
1130 const Recti& viewport, Ray3f& ray) noexcept {
1131 return Mat4::mapWinToAnyRay(winx, winy, winz0, winz1, getPi(), viewport, ray);
1132 }
1133
1134 std::string& toString(std::string& sb, const std::string& f) const noexcept {
1135 int count = 3; // P, Mv, T
1136
1137 sb.append("PMVMatrix4[req").append(to_string(m_requestBits))
1138 .append(", mod1").append(to_string(m_dirtyBits))
1139 .append(", mod2").append(to_string(m_modifiedBits))
1140 .append(", Projection\n");
1141 m_matP.toString(sb, f);
1142 sb.append(", Modelview\n");
1143 m_matMv.toString(sb, f);
1144 sb.append(", Texture\n");
1145 m_matTex.toString(sb, f);
1146 {
1147 sb.append(", P * Mv\n");
1148 m_matPMv.toString(sb, f);
1149 ++count;
1150 }
1151 {
1152 sb.append(", P * Mv\n");
1153 m_matPMvi.toString(sb, f);
1154 ++count;
1155 }
1156 if( is_set(m_requestBits, PMVData::inv_mv) ) {
1157 sb.append(", Inverse Modelview\n");
1158 m_matMvi.toString(sb, f);
1159 ++count;
1160 }
1161 if( is_set(m_requestBits, PMVData::inv_tps_mv) ) {
1162 sb.append(", Inverse Transposed Modelview\n");
1163 m_matMvit.toString(sb, f);
1164 ++count;
1165 }
1166 int tmpCount = 1;
1167 if( true ) { // null != mat4Tmp2 ) {
1168 ++tmpCount;
1169 }
1170 sb.append(", matrices "+std::to_string(count)+" + "+std::to_string(tmpCount)+" temp = "+std::to_string(count+tmpCount)+"]");
1171 return sb;
1172 }
1173
1174 std::string toString() const noexcept {
1175 std::string sb;
1176 toString(sb, "%13.9f");
1177 return sb;
1178 }
1179
1180 /**
1181 * Returns the modified bits due to mutable operations..
1182 * <p>
1183 * A modified bit is set, if the corresponding matrix had been modified by a mutable operation
1184 * since last {@link #update()} or {@link #getModifiedBits(bool) getModifiedBits(true)} call.
1185 * </p>
1186 * @param clear if true, clears the modified bits, otherwise leaves them untouched.
1187 *
1188 * @see PMVState::MODIFIED_PROJECTION
1189 * @see PMVState::MODIFIED_MODELVIEW
1190 * @see PMVState::MODIFIED_TEXTURE
1191 * @see getDirtyBits()
1192 * @see isReqDirty()
1193 */
1194 constexpr PMVMod getModifiedBits(const bool clear) noexcept {
1195 const PMVMod r = m_modifiedBits;
1196 if(clear) {
1197 m_modifiedBits = PMVMod::none;
1198 }
1199 return r;
1200 }
1201
1202 /**
1203 * Returns the dirty bits due to mutable operations,
1204 * i.e.
1205 * - {@link #INVERSE_MODELVIEW} (if requested)
1206 * - {@link #INVERSE_PROJECTION} (if requested)
1207 * - {@link #INVERSE_TRANSPOSED_MODELVIEW} (if requested)
1208 * - {@link #FRUSTUM} (always, cleared via {@link #getFrustum()}
1209 * <p>
1210 * A dirty bit is set, if the corresponding matrix had been modified by a mutable operation
1211 * since last {@link #update()} call and requested in the constructor {@link #PMVMatrix4(int)}.
1212 * </p>
1213 * <p>
1214 * {@link #update()} clears the dirty state for the matrices and {@link #getFrustum()} for {@link #FRUSTUM}.
1215 * </p>
1216 *
1217 * @see #isReqDirty()
1218 * @see PMVMats::INVERSE_MODELVIEW
1219 * @see PMVMats::INVERSE_PROJECTION
1220 * @see PMVMats::INVERSE_TRANSPOSED_MODELVIEW
1221 * @see PMVMats::FRUSTUM
1222 * @see PMVMatrix4(PMVMats)
1223 * @see getMvi()
1224 * @see getMvit()
1225 * @see makeSyncPMvMvi()
1226 * @see makeSyncPMvMviMvit()
1227 * @see getFrustum()
1228 */
1229 constexpr PMVData getDirtyBits() noexcept {
1230 return m_dirtyBits;
1231 }
1232
1233 /**
1234 * Returns true if the one of the {@link #getReqBits() requested bits} are are set dirty due to mutable operations,
1235 * i.e. at least one of
1236 * - {@link #INVERSE_MODELVIEW}
1237 * - {@link #INVERSE_PROJECTION}
1238 * - {@link #INVERSE_TRANSPOSED_MODELVIEW}
1239 * <p>
1240 * A dirty bit is set, if the corresponding matrix had been modified by a mutable operation
1241 * since last {@link #update()} call and requested in the constructor {@link #PMVMatrix4(int)}.
1242 * </p>
1243 * <p>
1244 * {@link #update()} clears the dirty state for the matrices and {@link #getFrustum()} for {@link #FRUSTUM}.
1245 * </p>
1246 *
1247 * @see #INVERSE_MODELVIEW
1248 * @see #INVERSE_PROJECTION
1249 * @see #INVERSE_TRANSPOSED_MODELVIEW
1250 * @see #PMVMatrix4(int)
1251 * @see #getMvi()
1252 * @see #getMvit()
1253 * @see #makeSyncPMvMvi()
1254 * @see #makeSyncPMvMviMvit()
1255 */
1256 constexpr bool isReqDirty() noexcept {
1257 return has_any(m_dirtyBits, m_requestBits);
1258 }
1259
1260 /**
1261 * Sets the {@link #getMv() Modelview (Mv)} matrix dirty and modified,
1262 * i.e. adds INVERSE_MODELVIEW | INVERSE_TRANSPOSED_MODELVIEW | MANUAL_BITS to {@link #getDirtyBits() dirty bits}.
1263 * @see #isReqDirty()
1264 */
1265 constexpr void setModelviewDirty() noexcept {
1267 m_modifiedBits |= PMVMod::mv;
1268 }
1269
1270 /**
1271 * Sets the {@link #getP() Projection (P)} matrix dirty and modified,
1272 * i.e. adds INVERSE_PROJECTION | MANUAL_BITS to {@link #getDirtyBits() dirty bits}.
1273 */
1274 constexpr void setProjectionDirty() noexcept {
1275 m_dirtyBits |= PMVData::inv_proj | PMVData::manual ;
1276 m_modifiedBits |= PMVMod::proj;
1277 }
1278
1279 /**
1280 * Sets the {@link #getT() Texture (T)} matrix modified.
1281 */
1282 constexpr void setTextureDirty() noexcept {
1283 m_modifiedBits |= PMVMod::text;
1284 }
1285
1286 /**
1287 * Returns the request bit mask, which uses bit values equal to the dirty mask
1288 * and may contain
1289 * - PMVMats::INVERSE_MODELVIEW
1290 * - PMVMats::INVERSE_PROJECTION
1291 * - PMVMats::INVERSE_TRANSPOSED_MODELVIEW
1292 *
1293 * The request bit mask is set by in the constructor PMVMatrix4(PMVMats).
1294 *
1295 * @see PMVMats::INVERSE_MODELVIEW
1296 * @see PMVMats::INVERSE_PROJECTION
1297 * @see PMVMats::INVERSE_TRANSPOSED_MODELVIEW
1298 * @see PMVMatrix4(PMVMats)
1299 * @see getMvi()
1300 * @see getMvit()
1301 * @see makeSyncPMvMvi()
1302 * @see makeSyncPMvMviMvit()
1303 * @see getFrustum()
1304 */
1305 constexpr PMVData requestedBits() noexcept { return m_requestBits; }
1306
1307 /**
1308 * Returns the pre-multiplied projection x modelview, P x Mv.
1309 * <p>
1310 * This {@link Mat4} instance should be re-fetched via this method and not locally stored
1311 * to have it updated from a potential modification of underlying projection and/or modelview matrix.
1312 * {@link #update()} has no effect on this {@link Mat4}.
1313 * </p>
1314 * <p>
1315 * This pre-multipled P x Mv is considered dirty, if its corresponding
1316 * {@link #getP() P matrix} or {@link #getMv() Mv matrix} has been modified since its last update.
1317 * </p>
1318 * @see #update()
1319 */
1320 constexpr Mat4& getPMv() noexcept {
1321 if( is_set(m_dirtyBits, PMVData::pre_pmv) ) {
1322 m_matPMv.mul(m_matP, m_matMv);
1323 m_dirtyBits &= ~PMVData::pre_pmv;
1324 }
1325 return m_matPMv;
1326 }
1327
1328 /**
1329 * Returns the pre-multiplied inverse projection x modelview,
1330 * if {@link Mat4#invert(Mat4)} succeeded, otherwise `null`.
1331 * <p>
1332 * This {@link Mat4} instance should be re-fetched via this method and not locally stored
1333 * to have it updated from a potential modification of underlying projection and/or modelview matrix.
1334 * {@link #update()} has no effect on this {@link Mat4}.
1335 * </p>
1336 * <p>
1337 * This pre-multipled invert(P x Mv) is considered dirty, if its corresponding
1338 * {@link #getP() P matrix} or {@link #getMv() Mv matrix} has been modified since its last update.
1339 * </p>
1340 * @see #update()
1341 */
1342 constexpr Mat4& getPMvi() noexcept {
1343 if( is_set(m_dirtyBits, PMVData::pre_pmvi) ) {
1344 Mat4& mPMv = getPMv();
1345 m_matPMviOK = m_matPMvi.invert(mPMv);
1346 m_dirtyBits &= ~PMVData::pre_pmvi;
1347 }
1348 return m_matPMvi; // matPMviOK ? matPMvi : null; // FIXME
1349 }
1350
1351 /**
1352 * Returns the frustum, derived from projection x modelview.
1353 * <p>
1354 * This {@link Frustum} instance should be re-fetched via this method and not locally stored
1355 * to have it updated from a potential modification of underlying projection and/or modelview matrix.
1356 * {@link #update()} has no effect on this {@link Frustum}.
1357 * </p>
1358 * <p>
1359 * The {@link Frustum} is considered dirty, if its corresponding
1360 * {@link #getP() P matrix} or {@link #getMv() Mv matrix} has been modified since its last update.
1361 * </p>
1362 * @see #update()
1363 */
1365 if( is_set(m_dirtyBits, PMVData::frustum) ) {
1366 m_frustum.setFromMat(getPMv());
1367 m_dirtyBits &= ~PMVData::frustum;
1368 }
1369 return m_frustum;
1370 }
1371
1372 /**
1373 * Update the derived {@link #getMvi() inverse modelview (Mvi)},
1374 * {@link #getMvit() inverse transposed modelview (Mvit)} matrices
1375 * <b>if</b> they {@link #isReqDirty() are dirty} <b>and</b>
1376 * requested via the constructor {@link #PMVMatrix4(int)}.<br/>
1377 * Hence updates the following dirty bits.
1378 * - PMVMats::INVERSE_MODELVIEW
1379 * - PMVMats::INVERSE_PROJECTION
1380 * - PMVMats::INVERSE_TRANSPOSED_MODELVIEW
1381 *
1382 * The {@link Frustum} is updated only via {@link #getFrustum()} separately.
1383
1384 * The Mvi and Mvit matrices are considered dirty, if their corresponding
1385 * {@link #getMv() Mv matrix} has been modified since their last update.
1386
1387 * Method is automatically called by {@link SyncMat4} and {@link SyncMatrices4f}
1388 * instances {@link SyncAction} as retrieved by e.g. {@link #makeSyncMvit()}.
1389 * This ensures an automatic update cycle if used with {@link com.jogamp.opengl.GLUniformData}.
1390
1391 * Method may be called manually in case mutable operations has been called
1392 * and caller operates on already fetched references, i.e. not calling
1393 * {@link #getMvi()}, {@link #getMvit()} anymore.
1394
1395 * Method clears the modified bits like {@link #getModifiedBits(bool) getModifiedBits(true)},
1396 * which are set by any mutable operation. The modified bits have no impact
1397 * on this method, but the return value.
1398 *
1399 * @return true if any matrix has been modified since last update call or
1400 * if the derived matrices Mvi and Mvit were updated, otherwise false.
1401 * In other words, method returns true if any matrix used by the caller must be updated,
1402 * e.g. uniforms in a shader program.
1403 *
1404 * @see getModifiedBits(bool)
1405 * @see isReqDirty()
1406 * @see PMVMats::INVERSE_MODELVIEW
1407 * @see PMVMats::INVERSE_PROJECTION
1408 * @see PMVMats::INVERSE_TRANSPOSED_MODELVIEW
1409 * @see PMVMatrix4(PMVMats)
1410 * @see getMvi()
1411 * @see getMvit()
1412 * @see makeSyncPMvMvi()
1413 * @see makeSyncPMvMviMvit()
1414 */
1415 bool update() noexcept {
1416 return updateImpl(true);
1417 }
1418
1419 //
1420 // private
1421 //
1422
1423 private:
1424 void updateImpl0() noexcept { updateImpl(false); }
1425 bool updateImpl(bool clearModBits) noexcept {
1426 bool mod = has_any(m_modifiedBits);
1427 if( clearModBits ) {
1428 m_modifiedBits = PMVMod::none;
1429 mod = false;
1430 }
1431 if( has_any( m_requestBits & ( ( m_dirtyBits & ( PMVData::inv_proj ) ) ) ) ) { // only if requested & dirty
1432 if( !m_matPi.invert(m_matP) ) {
1433 DBG_ERR_PRINT("Invalid source P matrix, can't compute inverse: %s", m_matP.toString().c_str(), E_FILE_LINE);
1434 // still continue with other derived matrices
1435 } else {
1436 mod = true;
1437 }
1438 m_dirtyBits &= ~PMVData::inv_proj;
1439 }
1440 if( has_any( m_requestBits & ( ( m_dirtyBits & ( PMVData::inv_mv | PMVData::inv_tps_mv ) ) ) ) ) { // only if requested & dirty
1441 if( !m_matMvi.invert(m_matMv) ) {
1442 DBG_ERR_PRINT("Invalid source Mv matrix, can't compute inverse: %s", m_matMv.toString().c_str(), E_FILE_LINE);
1443 m_dirtyBits &= ~(PMVData::inv_mv | PMVData::inv_tps_mv);
1444 return mod; // no successful update as we abort due to inversion failure, skip INVERSE_TRANSPOSED_MODELVIEW as well
1445 }
1446 m_dirtyBits &= ~PMVData::inv_mv;
1447 mod = true;
1448 }
1449 if( has_any( m_requestBits & ( m_dirtyBits & PMVData::inv_tps_mv ) ) ) { // only if requested & dirty
1450 m_matMvit.transpose(m_matMvi);
1451 m_dirtyBits &= ~PMVData::inv_tps_mv;
1452 mod = true;
1453 }
1454 return mod;
1455 }
1456};
1457
1458template <jau::req::packed_floating_point Value_type>
1459inline std::ostream& operator<<(std::ostream& out, const PMVMatrix4<Value_type>& v) noexcept {
1460 return out << v.toString();
1461}
1462
1464
1465 /**@}*/
1466
1467 } // namespace jau::math::util
1468
1469 #endif // JAU_MATH_UTIL_PMVMAT4f_HPP_
#define E_FILE_LINE
Basic 4x4 value_type matrix implementation using fields for intensive use-cases (host operations).
Definition mat4f.hpp:100
static bool mapWinToAnyRay(const value_type winx, const value_type winy, const value_type winz0, const value_type winz1, const Matrix4 &invAny, const Recti &viewport, Ray3 &ray) noexcept
Definition mat4f.hpp:1914
static bool mapObjToWin(const Vec3 &obj, const Matrix4 &mPMv, const Recti &viewport, Vec3 &winPos) noexcept
Definition mat4f.hpp:1506
static bool mapWorldToWin(const Vec3 &world, const Matrix4 &mV, const Matrix4 &mP, const Recti &viewport, Vec3 &winPos) noexcept
Definition mat4f.hpp:1543
bool invert() noexcept
Invert this matrix.
Definition mat4f.hpp:510
Matrix4 & setToFrustum(const value_type left, const value_type right, const value_type bottom, const value_type top, const value_type zNear, const value_type zFar)
Set this matrix to frustum.
Definition mat4f.hpp:1225
constexpr_cxx26 Matrix4 & setToRotationAxis(const value_type ang_rad, value_type x, value_type y, value_type z) noexcept
Set this matrix to rotation from the given axis and angle in radians.
Definition mat4f.hpp:998
constexpr Matrix4 & mul(const Matrix4 &b) noexcept
Multiply matrix: [this] = [this] x [b].
Definition mat4f.hpp:713
static bool mapWinToObj4(const value_type winx, const value_type winy, const value_type winz, const value_type clipw, const Matrix4 &mMv, const Matrix4 &mP, const Recti &viewport, const value_type near, const value_type far, Vec4 &objPos) noexcept
Definition mat4f.hpp:1760
constexpr Matrix4 & setToTranslation(const value_type x, const value_type y, const value_type z) noexcept
Set this matrix to translation.
Definition mat4f.hpp:912
constexpr Matrix4 & setToScale(const value_type x, const value_type y, const value_type z) noexcept
Set this matrix to scale.
Definition mat4f.hpp:954
static bool mapWinToAny(const value_type winx, const value_type winy, const value_type winz, const Matrix4 &invAny, const Recti &viewport, Vec3 &objPos) noexcept
Definition mat4f.hpp:1659
static bool mapViewToWin(const Vec3 &view, const Matrix4 &mP, const Recti &viewport, Vec3 &winPos) noexcept
Definition mat4f.hpp:1559
Matrix4 & setToPerspective(const value_type fovy_rad, const value_type aspect, const value_type zNear, const value_type zFar)
Set this matrix to perspective frustum projection.
Definition mat4f.hpp:1274
std::string toString(const std::string &rowPrefix, const std::string_view f) const noexcept
Returns a formatted string representation of this matrix.
Definition mat4f.hpp:1932
constexpr Matrix4 & setToLookAt(const Vec3 &eye, const Vec3 &center, const Vec3 &up) noexcept
Set this matrix to the look-at matrix based on given parameters.
Definition mat4f.hpp:1321
constexpr Matrix4 & setToOrtho(const value_type left, const value_type right, const value_type bottom, const value_type top, const value_type zNear, const value_type zFar) noexcept
Set this matrix to orthogonal projection.
Definition mat4f.hpp:1177
Simple compound denoting a ray.
Definition vec3f.hpp:457
3D vector using three value_type components.
Definition vec3f.hpp:42
4D vector using four value_type components.
Definition vec4f.hpp:42
Providing frustum planes derived by different inputs (P*MV, ..) used to classify objects.
Definition frustum.hpp:78
A Matrix stack of compounds, each consisting of 16 * T
Definition sstack.hpp:99
PMVMatrix4 implements the basic computer graphics Matrix4 pack using projection (P),...
Definition pmvmat4.hpp:116
PMVMatrix4() noexcept
Creates an instance of PMVMatrix4.
Definition pmvmat4.hpp:176
constexpr PMVMatrix4 & scaleMv(const Vec3 &s) noexcept
Scale the modelview matrix.
Definition pmvmat4.hpp:692
constexpr void setModelviewDirty() noexcept
Sets the Modelview (Mv) matrix dirty and modified, i.e.
Definition pmvmat4.hpp:1265
constexpr PMVMatrix4 & scaleP(float x, float y, float z) noexcept
Scale the projection matrix.
Definition pmvmat4.hpp:704
SyncMats4f makeSyncPMvReq()
Returns a new SyncMatrices4f of either 4 matrices makeSyncPMvMviMvit(), 3 matrices makeSyncPMvMvi() o...
Definition pmvmat4.hpp:419
constexpr Mat4 & getMulMvP(Mat4 &result) noexcept
Returns multiplication result of Mv and P matrix, i.e.
Definition pmvmat4.hpp:459
constexpr PMVMod getModifiedBits(const bool clear) noexcept
Returns the modified bits due to mutable operations.
Definition pmvmat4.hpp:1194
constexpr PMVMatrix4 & loadMv(float values[]) noexcept
Load the modelview matrix with the provided values.
Definition pmvmat4.hpp:502
constexpr PMVMatrix4 & mulP(const Mat4 &m) noexcept
Multiply the projection matrix: [c] = [c] x [m].
Definition pmvmat4.hpp:617
Matrix4< value_type > Mat4
Definition pmvmat4.hpp:129
constexpr const Mat4 & getT() const noexcept
Definition pmvmat4.hpp:252
constexpr PMVData requestedBits() noexcept
Returns the request bit mask, which uses bit values equal to the dirty mask and may contain.
Definition pmvmat4.hpp:1305
bool update() noexcept
Update the derived inverse modelview (Mvi), inverse transposed modelview (Mvit) matrices if they are ...
Definition pmvmat4.hpp:1415
PMVMatrix4(PMVData derivedMatrices) noexcept
Creates an instance of PMVMatrix4.
Definition pmvmat4.hpp:196
bool mapWinToViewRay(const float winx, const float winy, const float winz0, const float winz1, const Recti &viewport, Ray3f &ray) noexcept
Map two window coordinates w/ shared X/Y and distinctive Z to a Ray in view space.
Definition pmvmat4.hpp:1129
constexpr PMVMatrix4 & rotateP(const Quat4f &quat) noexcept
Rotate the projection matrix with the given Quaternion's rotation matrix representation.
Definition pmvmat4.hpp:789
void frustumP(const float left, const float right, const float bottom, const float top, const float zNear, const float zFar)
Multiply the projection matrix with the frustum matrix.
Definition pmvmat4.hpp:850
constexpr PMVMatrix4 & mulMv(const Mat4 &m) noexcept
Multiply the modelview matrix: [c] = [c] x [m].
Definition pmvmat4.hpp:606
constexpr PMVMatrix4 & loadP(const Mat4 &m)
Load the projection matrix with the values of the given Mat4.
Definition pmvmat4.hpp:535
constexpr Vec4 & mulWithMv(const Vec4 &v_in, Vec4 &v_out) noexcept
v_out = Mv x v_in
Definition pmvmat4.hpp:469
static size_t matrixCount(PMVData derivedMatrices) noexcept
Return the number of Mat4 referenced by matrices()
Definition pmvmat4.hpp:207
constexpr const Mat4 & getP() const noexcept
Definition pmvmat4.hpp:264
constexpr Mat4 & getP() noexcept
Returns the projection matrix (P).
Definition pmvmat4.hpp:263
Vector4F< value_type > Vec4
Definition pmvmat4.hpp:127
constexpr SyncMats4 makeSyncMv() noexcept
Returns a new SyncMatrix of modelview matrix (Mv).
Definition pmvmat4.hpp:337
SyncMats4f makeSyncPMv() noexcept
Returns a new SyncMatrices4f of 2 matrices within one FloatBuffer: P and Mv.
Definition pmvmat4.hpp:345
SyncMats4f makeSyncPMvMviMvit()
Returns a new SyncMatrices4f of 4 matrices within one FloatBuffer: P, Mv, Mvi and Mvit if requested.
Definition pmvmat4.hpp:404
constexpr PMVMatrix4 & loadMv(const Mat4 &m) noexcept
Load the modelview matrix with the values of the given Mat4.
Definition pmvmat4.hpp:510
constexpr PMVMatrix4 & scaleP(const Vec3 &s) noexcept
Scale the projection matrix.
Definition pmvmat4.hpp:713
constexpr PMVMatrix4 & translateMv(float x, float y, float z) noexcept
Translate the modelview matrix.
Definition pmvmat4.hpp:641
std::string toString() const noexcept
Definition pmvmat4.hpp:1174
constexpr_cxx26 PMVMatrix4 & rotateMv(const float ang_rad, const float x, const float y, const float z) noexcept
Rotate the modelview matrix by the given axis and angle in radians.
Definition pmvmat4.hpp:728
bool mapWinToWorld(const float winx, const float winy, const float winz, const Mat4 &matVi, const Recti &viewport, Vec3 &objPos) noexcept
Map window coordinates to object coordinates.
Definition pmvmat4.hpp:993
Ray3F< value_type > Ray3
Definition pmvmat4.hpp:128
std::string & toString(std::string &sb, const std::string &f) const noexcept
Definition pmvmat4.hpp:1134
const value_type * const_pointer
Definition pmvmat4.hpp:120
constexpr Vec3 & mulWithMv(const Vec3 &v_in, Vec3 &v_out) noexcept
v_out = Mv x v_in
Definition pmvmat4.hpp:491
constexpr_cxx26 PMVMatrix4 & rotateP(const float ang_rad, const float x, const float y, const float z) noexcept
Rotate the projection matrix by the given axis and angle in radians.
Definition pmvmat4.hpp:766
bool mapWinToWorldRay(const float winx, const float winy, const float winz0, const float winz1, const Mat4 &matVi, const Recti &viewport, Ray3f &ray) noexcept
Map two window coordinates w/ shared X/Y and distinctive Z to a Ray in world space.
Definition pmvmat4.hpp:1102
const Mat4 & getPi()
Returns the inverse modelview matrix (Pi) if requested.
Definition pmvmat4.hpp:285
const Mat4 & getMvi()
Returns the inverse modelview matrix (Mvi) if requested.
Definition pmvmat4.hpp:300
constexpr bool isReqDirty() noexcept
Returns true if the one of the requested bits are are set dirty due to mutable operations,...
Definition pmvmat4.hpp:1256
constexpr PMVMatrix4 & loadT(Mat4 &m) noexcept
Load the texture matrix with the values of the given Mat4.
Definition pmvmat4.hpp:560
bool mapWinToObj4(const float winx, const float winy, const float winz, const float clipw, const Recti &viewport, const float near, const float far, Vec4 &objPos) const noexcept
Map window coordinates to object coordinates.
Definition pmvmat4.hpp:1039
constexpr PMVMatrix4 & lookAtMv(const Vec3 &eye, const Vec3 &center, const Vec3 &up) noexcept
Multiply the modelview matrix with the eye, object and orientation (camera), i.e.
Definition pmvmat4.hpp:905
constexpr_cxx20 PMVMatrix4 & popMv() noexcept
Pop the modelview matrix from its stack.
Definition pmvmat4.hpp:795
Vector3F< value_type > Vec3
Definition pmvmat4.hpp:126
const value_type * const_iterator
Definition pmvmat4.hpp:124
SyncMats4 makeSyncMvi()
Returns a new SyncMatrix of inverse modelview matrix (Mvi) if requested.
Definition pmvmat4.hpp:362
constexpr PMVMatrix4 & loadP(const Quat4f &quat) noexcept
Load the projection matrix with the values of the given Quaternion's rotation Quaternion::toMatrix() ...
Definition pmvmat4.hpp:543
constexpr Mat4 & getT() noexcept
Returns the texture matrix (T).
Definition pmvmat4.hpp:251
constexpr Vec4 & mulWithMv(Vec4 &v_inout) noexcept
v_inout = Mv x v_inout
Definition pmvmat4.hpp:478
const Mat4 & getMvit()
Returns the inverse transposed modelview matrix (Mvit) if requested.
Definition pmvmat4.hpp:315
constexpr PMVMatrix4 & translateMv(const Vec3 &t) noexcept
Translate the modelview matrix.
Definition pmvmat4.hpp:650
constexpr PMVMatrix4 & mulT(const Mat4 &m) noexcept
Multiply the texture matrix: [c] = [c] x [m].
Definition pmvmat4.hpp:628
PMVMatrix4 & perspectiveP(const float fovy_rad, const float aspect, const float zNear, const float zFar)
Multiply the projection matrix with the perspective/frustum matrix.
Definition pmvmat4.hpp:885
PMVMatrix4 & setToPerspective(const float fovy_rad, const float aspect, const float zNear, const float zFar)
Set the projection matrix to the perspective/frustum matrix.
Definition pmvmat4.hpp:869
constexpr PMVMatrix4 & loadMvIdentity() noexcept
Load the modelview matrix with the values of the given Mat4.
Definition pmvmat4.hpp:577
constexpr Mat4 & getMulPMv(Mat4 &result) noexcept
Returns multiplication result of P and Mv matrix, i.e.
Definition pmvmat4.hpp:447
constexpr void setTextureDirty() noexcept
Sets the Texture (T) matrix modified.
Definition pmvmat4.hpp:1282
constexpr_cxx20 PMVMatrix4 & pushT() noexcept
Push the texture matrix to its stack, while preserving its values.
Definition pmvmat4.hpp:823
constexpr PMVMatrix4 & loadTIdentity() noexcept
Load the texture matrix with the values of the given Mat4.
Definition pmvmat4.hpp:595
constexpr PMVMatrix4 & loadT(const Quat4f &quat) noexcept
Load the texture matrix with the values of the given Quaternion's rotation Quaternion::toMatrix() rep...
Definition pmvmat4.hpp:568
constexpr PMVMatrix4 & rotateMv(const Quat4f &quat) noexcept
Rotate the modelview matrix with the given Quaternion's rotation matrix representation.
Definition pmvmat4.hpp:751
constexpr void orthoP(const float left, const float right, const float bottom, const float top, const float zNear, const float zFar) noexcept
Multiply the projection matrix with the orthogonal matrix.
Definition pmvmat4.hpp:838
bool mapViewToWin(const Vec3 &view, const Recti &viewport, Vec3 &winPos) const noexcept
Map view coordinates ( Mv x object ) to window coordinates.
Definition pmvmat4.hpp:951
constexpr PMVMatrix4 & loadP(float values[]) noexcept
Load the projection matrix with the provided values.
Definition pmvmat4.hpp:527
constexpr const Mat4 & getMv() const noexcept
Definition pmvmat4.hpp:276
bool mapWinToObjRay(const float winx, const float winy, const float winz0, const float winz1, const Recti &viewport, Ray3f &ray) noexcept
Map two window coordinates w/ shared X/Y and distinctive Z to a Ray in object space.
Definition pmvmat4.hpp:1068
bool mapWorldToWin(const Vec3 &objPos, const Mat4 &matV, const Recti &viewport, Vec3 &winPos) const noexcept
Map world coordinates to window coordinates.
Definition pmvmat4.hpp:938
constexpr SyncMats4 makeSyncP() noexcept
Returns a new SyncMatrix of projection matrix (P).
Definition pmvmat4.hpp:329
constexpr_cxx20 PMVMatrix4 & popT() noexcept
Pop the texture matrix from its stack.
Definition pmvmat4.hpp:807
constexpr PMVMatrix4 & translateP(float x, float y, float z) noexcept
Translate the projection matrix.
Definition pmvmat4.hpp:662
constexpr PMVMatrix4 & translateP(const Vec3 &t) noexcept
Translate the projection matrix.
Definition pmvmat4.hpp:671
constexpr Mat4 & getPMvi() noexcept
Returns the pre-multiplied inverse projection x modelview, if Mat4#invert(Mat4) succeeded,...
Definition pmvmat4.hpp:1342
SyncMats4f makeSyncPMvMvi()
Returns a new SyncMatrices4f of 3 matrices within one FloatBuffer: P, Mv and Mvi if requested.
Definition pmvmat4.hpp:390
constexpr PMVMatrix4 & scaleMv(float x, float y, float z) noexcept
Scale the modelview matrix.
Definition pmvmat4.hpp:683
bool mapWinToView(const float winx, const float winy, const float winz, const Recti &viewport, Vec3 &objPos) noexcept
Map window coordinates to view coordinates.
Definition pmvmat4.hpp:1014
constexpr PMVMatrix4 & loadMv(const Quat4f &quat) noexcept
Load the modelview matrix with the values of the given Quaternion's rotation Quaternion::toMatrix() r...
Definition pmvmat4.hpp:518
constexpr_cxx20 PMVMatrix4 & pushP() noexcept
Push the projection matrix to its stack, while preserving its values.
Definition pmvmat4.hpp:818
constexpr_cxx26 PMVMatrix4 & rotateMv(const float ang_rad, const Vec3 &axis) noexcept
Rotate the modelview matrix by the given axis and angle in radians.
Definition pmvmat4.hpp:742
SyncMats4 makeSyncT() noexcept
Returns a new SyncMatrix of texture matrix (T).
Definition pmvmat4.hpp:353
constexpr Mat4 & getPMv() noexcept
Returns the pre-multiplied projection x modelview, P x Mv.
Definition pmvmat4.hpp:1320
const jau::type_info & compSignature() const noexcept
Returns the component's value_type signature.
Definition pmvmat4.hpp:204
constexpr void setProjectionDirty() noexcept
Sets the Projection (P) matrix dirty and modified, i.e.
Definition pmvmat4.hpp:1274
constexpr PMVMatrix4 & loadPIdentity() noexcept
Load the projection matrix with the values of the given Mat4.
Definition pmvmat4.hpp:586
jau::math::geom::Frustum getFrustum() noexcept
Returns the frustum, derived from projection x modelview.
Definition pmvmat4.hpp:1364
SyncMatrices4< value_type > SyncMats4
Definition pmvmat4.hpp:130
constexpr_cxx20 PMVMatrix4 & popP() noexcept
Pop the projection matrix from its stack.
Definition pmvmat4.hpp:801
bool mapWinToObj(const float winx, const float winy, const float winz, const Recti &viewport, Vec3 &objPos) noexcept
Map window coordinates to object coordinates.
Definition pmvmat4.hpp:968
constexpr void reset() noexcept
Issues Mat4#loadIdentity() on all matrices and resets all internal states.
Definition pmvmat4.hpp:229
const value_type & const_reference
Definition pmvmat4.hpp:122
constexpr PMVMatrix4 & loadT(float values[]) noexcept
Load the texture matrix with the provided values.
Definition pmvmat4.hpp:552
constexpr Mat4 & getMv() noexcept
Returns the modelview matrix (Mv).
Definition pmvmat4.hpp:275
constexpr_cxx20 PMVMatrix4 & pushMv() noexcept
Push the modelview matrix to its stack, while preserving its values.
Definition pmvmat4.hpp:813
size_t matrixCount() const noexcept
Return the number of Mat4 referenced by matrices()
Definition pmvmat4.hpp:224
bool mapObjToWin(const Vec3 &objPos, const Recti &viewport, Vec3 &winPos) const noexcept
Map object coordinates to window coordinates.
Definition pmvmat4.hpp:921
SyncMats4 makeSyncMvit()
Returns a new SyncMatrix of inverse transposed modelview matrix (Mvit) if requested.
Definition pmvmat4.hpp:376
constexpr PMVData getDirtyBits() noexcept
Returns the dirty bits due to mutable operations, i.e.
Definition pmvmat4.hpp:1229
constexpr_cxx26 PMVMatrix4 & rotateP(const float ang_rad, const Vec3 &axis) noexcept
Rotate the projection matrix by the given axis and angle in radians.
Definition pmvmat4.hpp:780
constexpr PMVMatrix4 & setToLookAtMv(const Vec3 &eye, const Vec3 &center, const Vec3 &up) noexcept
Set the modelview matrix to the eye, object and orientation (camera), i.e.
Definition pmvmat4.hpp:895
SyncBuffer interface with multiple underlying Matrix4.
Generic type information using either Runtime type information (RTTI) or Compile time type informatio...
#define DBG_ERR_PRINT(...)
Use for environment-variable environment::DEBUG conditional error messages, prefix '[elapsed_time] Wa...
Definition debug.hpp:78
constexpr bool has_any(const E mask, const E bits) noexcept
#define constexpr_cxx20
constexpr qualifier replacement for C++20 constexpr.
#define constexpr_cxx26
#define JAU_MAKE_BITFIELD_ENUM_STRING(type,...)
constexpr bool is_set(const E mask, const E bits) noexcept
std::ostream & operator<<(std::ostream &os, const T v)
const jau::type_info & static_ctti() noexcept
Returns a static global reference of make_ctti<T>(true) w/ identity instance.
jau::function< R(A...)> bind_member(C1 *base, R(C0::*mfunc)(A...)) noexcept
Bind given class instance and non-void member function to an anonymous function using func_member_tar...
SyncMatrices4< float > SyncMats4f
Ray3F< float > Ray3f
Definition vec3f.hpp:486
PMVMod
PMVMatrix4 modified core matrices.
Definition pmvmat4.hpp:43
PMVData
PMVMatrix4 derived matrices and values.
Definition pmvmat4.hpp:57
Quaternion< float > Quat4f
RectI< int > Recti
Definition recti.hpp:146
std::string to_string(const math_error_t v) noexcept
Returns std::string representation of math_error_t.
PMVMatrix4< float > PMVMat4f
Definition pmvmat4.hpp:1463
@ text
Bit value stating a modified texture matrix (T), since last update() call.
Definition pmvmat4.hpp:50
@ proj
Bit value stating a modified projection matrix (P), since last update() call.
Definition pmvmat4.hpp:46
@ mv
Bit value stating a modified modelview matrix (Mv), since last update() call.
Definition pmvmat4.hpp:48
@ all
Bit value stating all is modified.
Definition pmvmat4.hpp:52
@ pre_pmvi
Bit value for pre-multiplied invert(P x Mv), updated by getPMvi().
Definition pmvmat4.hpp:70
@ frustum
Bit value for frustum and updated by getFrustum().
Definition pmvmat4.hpp:66
@ inv_mv
Bit value for inverse modelview matrix (Mvi), updated via update().
Definition pmvmat4.hpp:60
@ manual
Manual bits not covered by update() but getFrustum(), FRUSTUM, getPMv(), PREMUL_PMV,...
Definition pmvmat4.hpp:72
@ inv_proj
Bit value for inverse projection matrix (Pi), updated via update().
Definition pmvmat4.hpp:64
@ inv_tps_mv
Bit value for inverse transposed modelview matrix (Mvit), updated via update().
Definition pmvmat4.hpp:62
@ pre_pmv
Bit value for pre-multiplied P x Mv, updated by getPMv().
Definition pmvmat4.hpp:68
Requirement (concept) Definitions.
static std::string f(uint32_t v)
uint8_t Value_type