jaulib v1.4.1
Jau Support Library (C++, Java, ..)
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: INVERSE_MODELVIEW | INVERSE_PROJECTION | INVERSE_TRANSPOSED_MODELVIEW
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 {@link #INVERSE_MODELVIEW} has not been requested in ctor {@link #PMVMatrix4(int)}.
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 {@link #INVERSE_TRANSPOSED_MODELVIEW} has not been requested in ctor {@link #PMVMatrix4(int)}.
403 */
405 if( !is_set(m_requestBits, PMVData::inv_tps_mv) ) {
406 throw jau::IllegalArgumentError("Not requested in ctor", E_FILE_LINE);
407 }
408 return SyncMats4f(m_matP, 4, jau::bind_member(this, &PMVMatrix4::updateImpl0));
409 }
410
411 /**
412 * Returns a new SyncMatrices4f of either 4 matrices makeSyncPMvMviMvit(), 3 matrices makeSyncPMvMvi() or 2 matrices makeSyncPMv()
413 * depending on requestedBits().
414 *
415 * See <a href="#storageDetails"> matrix storage details</a>.
416 */
418 {
420 if( m == ( m & m_requestBits ) ) {
421 return makeSyncPMvMviMvit(); // P, Mv, Mvi and Mvit
422 }
423 }
424 {
425 constexpr PMVData m = PMVData::inv_mv;
426 if( m == ( m & m_requestBits ) ) {
427 return makeSyncPMvMvi(); // P, Mv, Mvi
428 }
429 }
430 return makeSyncPMv(); // P, Mv
431 }
432
433 //
434 // Basic Mat4, Vec3 and Vec4 operations similar to GLMatrixFunc
435 //
436
437 /**
438 * Returns multiplication result of {@link #getP() P} and {@link #getMv() Mv} matrix, i.e.
439 * <pre>
440 * result = P x Mv
441 * </pre>
442 * @param result 4x4 matrix storage for result
443 * @return given result matrix for chaining
444 */
445 constexpr Mat4& getMulPMv(Mat4& result) noexcept {
446 return result.mul(m_matP, m_matMv);
447 }
448
449 /**
450 * Returns multiplication result of {@link #getMv() Mv} and {@link #getP() P} matrix, i.e.
451 * <pre>
452 * result = Mv x P
453 * </pre>
454 * @param result 4x4 matrix storage for result
455 * @return given result matrix for chaining
456 */
457 constexpr Mat4& getMulMvP(Mat4& result) noexcept {
458 return result.mul(m_matMv, m_matP);
459 }
460
461 /**
462 * v_out = Mv x v_in
463 * @param v_in input vector, can be v_out for in-place transformation
464 * @param v_out output vector
465 * @returns v_out for chaining
466 */
467 constexpr Vec4& mulWithMv(const Vec4& v_in, Vec4& v_out) noexcept {
468 return m_matMv.mulVec4(v_in, v_out);
469 }
470
471 /**
472 * v_inout = Mv x v_inout
473 * @param v_inout input and output vector, i.e. in-place transformation
474 * @returns v_inout for chaining
475 */
476 constexpr Vec4& mulWithMv(Vec4& v_inout) noexcept {
477 return m_matMv.mulVec4(v_inout);
478 }
479
480 /**
481 * v_out = Mv x v_in
482 *
483 * Affine 3f-vector transformation by 4x4 matrix, see {@link Mat4#mulVec3(Vec3, Vec3)}.
484 *
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 constexpr Vec3& mulWithMv(const Vec3& v_in, Vec3& v_out) noexcept {
490 return m_matMv.mulVec3(v_in, v_out);
491 }
492
493 //
494 // GLMatrixFunc alike functionality
495 //
496
497 /**
498 * Load the {@link #getMv() modelview matrix} with the provided values.
499 */
500 constexpr PMVMatrix4& loadMv(float values[]) noexcept {
501 m_matMv.load(values);
503 return *this;
504 }
505 /**
506 * Load the {@link #getMv() modelview matrix} with the values of the given {@link Mat4}.
507 */
508 constexpr PMVMatrix4& loadMv(const Mat4& m) noexcept {
509 m_matMv.load(m);
511 return *this;
512 }
513 /**
514 * Load the {@link #getMv() modelview matrix} with the values of the given {@link Quaternion}'s rotation Quaternion::toMatrix() representation.
515 */
516 constexpr PMVMatrix4& loadMv(const Quat4f& quat) noexcept {
517 quat.toMatrix(m_matMv);
519 return *this;
520 }
521
522 /**
523 * Load the {@link #getP() projection matrix} with the provided values.
524 */
525 constexpr PMVMatrix4& loadP(float values[]) noexcept {
526 m_matP.load(values);
528 return *this;
529 }
530 /**
531 * Load the {@link #getP() projection matrix} with the values of the given {@link Mat4}.
532 */
533 constexpr PMVMatrix4& loadP(const Mat4& m) {
534 m_matP.load(m);
536 return *this;
537 }
538 /**
539 * Load the {@link #getP() projection matrix} with the values of the given {@link Quaternion}'s rotation Quaternion::toMatrix() representation.
540 */
541 constexpr PMVMatrix4& loadP(const Quat4f& quat) noexcept {
542 quat.toMatrix(m_matP);
544 return *this;
545 }
546
547 /**
548 * Load the {@link #getT() texture matrix} with the provided values.
549 */
550 constexpr PMVMatrix4& loadT(float values[]) noexcept {
551 m_matTex.load(values);
553 return *this;
554 }
555 /**
556 * Load the {@link #getT() texture matrix} with the values of the given {@link Mat4}.
557 */
558 constexpr PMVMatrix4& loadT(Mat4& m) noexcept {
559 m_matTex.load(m);
561 return *this;
562 }
563 /**
564 * Load the {@link #getT() texture matrix} with the values of the given {@link Quaternion}'s rotation Quaternion::toMatrix() representation.
565 */
566 constexpr PMVMatrix4& loadT(const Quat4f& quat) noexcept {
567 quat.toMatrix(m_matTex);
569 return *this;
570 }
571
572 /**
573 * Load the {@link #getMv() modelview matrix} with the values of the given {@link Mat4}.
574 */
575 constexpr PMVMatrix4& loadMvIdentity() noexcept {
576 m_matMv.loadIdentity();
578 return *this;
579 }
580
581 /**
582 * Load the {@link #getP() projection matrix} with the values of the given {@link Mat4}.
583 */
584 constexpr PMVMatrix4& loadPIdentity() noexcept {
585 m_matP.loadIdentity();
587 return *this;
588 }
589
590 /**
591 * Load the {@link #getT() texture matrix} with the values of the given {@link Mat4}.
592 */
593 constexpr PMVMatrix4& loadTIdentity() noexcept {
594 m_matTex.loadIdentity();
596 return *this;
597 }
598
599 /**
600 * Multiply the {@link #getMv() modelview matrix}: [c] = [c] x [m]
601 * @param m the right hand Mat4
602 * @return *this instance of chaining
603 */
604 constexpr PMVMatrix4& mulMv(const Mat4& m) noexcept {
605 m_matMv.mul( m );
607 return *this;
608 }
609
610 /**
611 * Multiply the {@link #getP() projection matrix}: [c] = [c] x [m]
612 * @param m the right hand Mat4
613 * @return *this instance of chaining
614 */
615 constexpr PMVMatrix4& mulP(const Mat4& m) noexcept {
616 m_matP.mul( m );
618 return *this;
619 }
620
621 /**
622 * Multiply the {@link #getT() texture matrix}: [c] = [c] x [m]
623 * @param m the right hand Mat4
624 * @return *this instance of chaining
625 */
626 constexpr PMVMatrix4& mulT(const Mat4& m) noexcept {
627 m_matTex.mul( m );
629 return *this;
630 }
631
632 /**
633 * Translate the {@link #getMv() modelview matrix}.
634 * @param x
635 * @param y
636 * @param z
637 * @return *this instance of chaining
638 */
639 constexpr PMVMatrix4& translateMv(float x, float y, float z) noexcept {
640 Mat4 mat4Tmp1;
641 return mulMv( mat4Tmp1.setToTranslation(x, y, z) );
642 }
643 /**
644 * Translate the {@link #getMv() modelview matrix}.
645 * @param t translation vec3
646 * @return *this instance of chaining
647 */
648 constexpr PMVMatrix4& translateMv(const Vec3& t) noexcept {
649 Mat4 mat4Tmp1;
650 return mulMv( mat4Tmp1.setToTranslation(t) );
651 }
652
653 /**
654 * Translate the {@link #getP() projection matrix}.
655 * @param x
656 * @param y
657 * @param z
658 * @return *this instance of chaining
659 */
660 constexpr PMVMatrix4& translateP(float x, float y, float z) noexcept {
661 Mat4 mat4Tmp1;
662 return mulP( mat4Tmp1.setToTranslation(x, y, z) );
663 }
664 /**
665 * Translate the {@link #getP() projection matrix}.
666 * @param t translation vec3
667 * @return *this instance of chaining
668 */
669 constexpr PMVMatrix4& translateP(const Vec3& t) noexcept {
670 Mat4 mat4Tmp1;
671 return mulP( mat4Tmp1.setToTranslation(t) );
672 }
673
674 /**
675 * Scale the {@link #getMv() modelview matrix}.
676 * @param x
677 * @param y
678 * @param z
679 * @return *this instance of chaining
680 */
681 constexpr PMVMatrix4& scaleMv(float x, float y, float z) noexcept {
682 Mat4 mat4Tmp1;
683 return mulMv( mat4Tmp1.setToScale(x, y, z) );
684 }
685 /**
686 * Scale the {@link #getMv() modelview matrix}.
687 * @param s scale vec4f
688 * @return *this instance of chaining
689 */
690 constexpr PMVMatrix4& scaleMv(const Vec3& s) noexcept {
691 Mat4 mat4Tmp1;
692 return mulMv( mat4Tmp1.setToScale(s) );
693 }
694
695 /**
696 * Scale the {@link #getP() projection matrix}.
697 * @param x
698 * @param y
699 * @param z
700 * @return *this instance of chaining
701 */
702 constexpr PMVMatrix4& scaleP(float x, float y, float z) noexcept {
703 Mat4 mat4Tmp1;
704 return mulP( mat4Tmp1.setToScale(x, y, z) );
705 }
706 /**
707 * Scale the {@link #getP() projection matrix}.
708 * @param s scale vec4f
709 * @return *this instance of chaining
710 */
711 constexpr PMVMatrix4& scaleP(const Vec3& s) noexcept {
712 Mat4 mat4Tmp1;
713 return mulP( mat4Tmp1.setToScale(s) );
714 }
715
716 /**
717 * Rotate the {@link #getMv() modelview matrix} by the given axis and angle in radians.
718 * <p>
719 * Consider using {@link #rotateMv(Quaternion)}
720 * </p>
721 * @param ang_rad angle in radians
722 * @param axis rotation axis
723 * @return *this instance of chaining
724 * @see #rotateMv(Quaternion)
725 */
726 constexpr_cxx26 PMVMatrix4& rotateMv(const float ang_rad, const float x, const float y, const float z) noexcept {
727 Mat4 mat4Tmp1;
728 return mulMv( mat4Tmp1.setToRotationAxis(ang_rad, x, y, z) );
729 }
730 /**
731 * Rotate the {@link #getMv() modelview matrix} by the given axis and angle in radians.
732 * <p>
733 * Consider using {@link #rotateMv(Quaternion)}
734 * </p>
735 * @param ang_rad angle in radians
736 * @param axis rotation axis
737 * @return *this instance of chaining
738 * @see #rotateMv(Quaternion)
739 */
740 constexpr_cxx26 PMVMatrix4& rotateMv(const float ang_rad, const Vec3& axis) noexcept {
741 Mat4 mat4Tmp1;
742 return mulMv( mat4Tmp1.setToRotationAxis(ang_rad, axis) );
743 }
744 /**
745 * Rotate the {@link #getMv() modelview matrix} with the given {@link Quaternion}'s rotation {@link Mat4#setToRotation(Quaternion) matrix representation}.
746 * @param quat the {@link Quaternion}
747 * @return *this instance of chaining
748 */
749 constexpr PMVMatrix4& rotateMv(const Quat4f& quat) noexcept {
750 Mat4 mat4Tmp1;
751 return mulMv( quat.toMatrix(mat4Tmp1) );
752 }
753
754 /**
755 * Rotate the {@link #getP() projection matrix} by the given axis and angle in radians.
756 * <p>
757 * Consider using {@link #rotateP(Quaternion)}
758 * </p>
759 * @param ang_rad angle in radians
760 * @param axis rotation axis
761 * @return *this instance of chaining
762 * @see #rotateP(Quaternion)
763 */
764 constexpr_cxx26 PMVMatrix4& rotateP(const float ang_rad, const float x, const float y, const float z) noexcept {
765 Mat4 mat4Tmp1;
766 return mulP( mat4Tmp1.setToRotationAxis(ang_rad, x, y, z) );
767 }
768 /**
769 * Rotate the {@link #getP() projection matrix} by the given axis and angle in radians.
770 * <p>
771 * Consider using {@link #rotateP(Quaternion)}
772 * </p>
773 * @param ang_rad angle in radians
774 * @param axis rotation axis
775 * @return *this instance of chaining
776 * @see #rotateP(Quaternion)
777 */
778 constexpr_cxx26 PMVMatrix4& rotateP(const float ang_rad, const Vec3& axis) noexcept {
779 Mat4 mat4Tmp1;
780 return mulP( mat4Tmp1.setToRotationAxis(ang_rad, axis) );
781 }
782 /**
783 * Rotate the {@link #getP() projection matrix} with the given {@link Quaternion}'s rotation {@link Mat4#setToRotation(Quaternion) matrix representation}.
784 * @param quat the {@link Quaternion}
785 * @return *this instance of chaining
786 */
787 constexpr PMVMatrix4& rotateP(const Quat4f& quat) noexcept {
788 Mat4 mat4Tmp1;
789 return mulP( quat.toMatrix(mat4Tmp1) );
790 }
791
792 /** Pop the {@link #getMv() modelview matrix} from its stack. */
794 m_stackMv.pop(m_matMv);
796 return *this;
797 }
798 /** Pop the {@link #getP() projection matrix} from its stack. */
800 m_stackP.pop(m_matP);
802 return *this;
803 }
804 /** Pop the {@link #getT() texture matrix} from its stack. */
806 m_stackTex.pop(m_matTex);
808 return *this;
809 }
810 /** Push the {@link #getMv() modelview matrix} to its stack, while preserving its values. */
812 m_stackMv.push(m_matMv);
813 return *this;
814 }
815 /** Push the {@link #getP() projection matrix} to its stack, while preserving its values. */
817 m_stackP.push(m_matP);
818 return *this;
819 }
820 /** Push the {@link #getT() texture matrix} to its stack, while preserving its values. */
822 m_stackTex.push(m_matTex);
823 return *this;
824 }
825
826 /**
827 * {@link #mulP(Mat4) Multiply} the {@link #getP() projection matrix} with the orthogonal matrix.
828 * @param left
829 * @param right
830 * @param bottom
831 * @param top
832 * @param zNear
833 * @param zFar
834 * @see Mat4#setToOrtho(float, float, float, float, float, float)
835 */
836 constexpr void orthoP(const float left, const float right, const float bottom, const float top, const float zNear, const float zFar) noexcept {
837 Mat4 mat4Tmp1;
838 mulP( mat4Tmp1.setToOrtho(left, right, bottom, top, zNear, zFar) );
839 }
840
841 /**
842 * {@link #mulP(Mat4) Multiply} the {@link #getP() projection matrix} with the frustum matrix.
843 *
844 * @throws IllegalArgumentException if {@code zNear <= 0} or {@code zFar <= zNear}
845 * or {@code left == right}, or {@code bottom == top}.
846 * @see Mat4#setToFrustum(float, float, float, float, float, float)
847 */
848 void frustumP(const float left, const float right, const float bottom, const float top, const float zNear, const float zFar) {
849 Mat4 mat4Tmp1;
850 mulP( mat4Tmp1.setToFrustum(left, right, bottom, top, zNear, zFar) );
851 }
852
853 //
854 // Extra functionality
855 //
856
857 /**
858 * {@link #mulP(Mat4) Multiply} the {@link #getP() projection matrix} with the perspective/frustum matrix.
859 *
860 * @param fovy_rad fov angle in radians
861 * @param aspect aspect ratio width / height
862 * @param zNear
863 * @param zFar
864 * @throws IllegalArgumentException if {@code zNear <= 0} or {@code zFar <= zNear}
865 * @see Mat4#setToPerspective(float, float, float, float)
866 */
867 PMVMatrix4& perspectiveP(const float fovy_rad, const float aspect, const float zNear, const float zFar) {
868 Mat4 mat4Tmp1;
869 mulP( mat4Tmp1.setToPerspective(fovy_rad, aspect, zNear, zFar) );
870 return *this;
871 }
872
873 /**
874 * {@link #mulP(Mat4) Multiply} the {@link #getP() projection matrix}
875 * with the eye, object and orientation, i.e. {@link Mat4#setToLookAt(Vec3, Vec3, Vec3, Mat4)}.
876 */
877 constexpr PMVMatrix4& lookAtP(const Vec3& eye, const Vec3& center, const Vec3& up) noexcept {
878 Mat4 mat4Tmp2;
879 Mat4 mat4Tmp1;
880 mulP( mat4Tmp1.setToLookAt(eye, center, up, mat4Tmp2) );
881 return *this;
882 }
883
884 /**
885 * Map object coordinates to window coordinates.
886 *
887 * Traditional <code>gluProject</code> implementation.
888 *
889 * @param objPos 3 component object coordinate
890 * @param viewport Rect4i viewport
891 * @param winPos 3 component window coordinate, the result
892 * @return true if successful, otherwise false (z is 1)
893 */
894 bool mapObjToWin(const Vec3& objPos, const Recti& viewport, Vec3& winPos) const noexcept {
895 return Mat4::mapObjToWin(objPos, m_matMv, m_matP, viewport, winPos);
896 }
897
898 /**
899 * Map world coordinates to window coordinates.
900 *
901 * - world = M x Obj
902 * - win = P x V x World = P x V' x Mv
903 * - V' x V x M = M, with Mv = V x M
904 *
905 * @param objPos 3 component object coordinate
906 * @param matV the view matrix
907 * @param viewport Rect4i viewport
908 * @param winPos 3 component window coordinate, the result
909 * @return true if successful, otherwise false (z is 1)
910 */
911 bool mapWorldToWin(const Vec3& objPos, const Mat4& matV, const Recti& viewport, Vec3& winPos) const noexcept {
912 return Mat4::mapWorldToWin(objPos, matV, m_matP, viewport, winPos);
913 }
914
915 /**
916 * Map view coordinates ( Mv x object ) to window coordinates.
917 *
918 * @param view view position, 3 component vector
919 * @param mP projection matrix
920 * @param viewport Rect4i viewport
921 * @param winPos 3 component window coordinate, the result
922 * @return true if successful, otherwise false (z is 1)
923 */
924 bool mapViewToWin(const Vec3& view, const Recti& viewport, Vec3& winPos) const noexcept {
925 return Mat4::mapViewToWin(view, m_matP, viewport, winPos);
926 }
927
928 /**
929 * Map window coordinates to object coordinates.
930 * <p>
931 * Traditional <code>gluUnProject</code> implementation.
932 * </p>
933 *
934 * @param winx
935 * @param winy
936 * @param winz
937 * @param viewport Rect4i viewport
938 * @param objPos 3 component object coordinate, the result
939 * @return true if successful, otherwise false (failed to invert matrix, or becomes infinity due to zero z)
940 */
941 bool mapWinToObj(const float winx, const float winy, const float winz,
942 const Recti& viewport, Vec3& objPos) noexcept {
943 if( Mat4::mapWinToAny(winx, winy, winz, getPMvi(), viewport, objPos) ) {
944 return true;
945 } else {
946 return false;
947 }
948 }
949
950 /**
951 * Map window coordinates to object coordinates.
952 *
953 * The INVERSE_PROJECTION must have been request in the constructor.
954 *
955 * - Pv' = P' x V', using getPi()
956 * - V' x V x M = M, with Mv = V x M
957 *
958 * @param winx
959 * @param winy
960 * @param winz
961 * @param matVi the inverse view matrix
962 * @param viewport Rect4i viewport
963 * @param objPos 3 component object coordinate, the result
964 * @return true if successful, otherwise false (failed to invert matrix, or becomes infinity due to zero z)
965 */
966 bool mapWinToWorld(const float winx, const float winy, const float winz,
967 const Mat4& matVi, const Recti& viewport, Vec3& objPos) noexcept {
968 Mat4 invPv;
969 invPv.mul(getPi(), matVi);
970 if( Mat4::mapWinToAny(winx, winy, winz, invPv, viewport, objPos) ) {
971 return true;
972 } else {
973 return false;
974 }
975 }
976
977 /**
978 * Map window coordinates to view coordinates.
979 *
980 * @param winx
981 * @param winy
982 * @param winz
983 * @param viewport Rect4i viewport
984 * @param objPos 3 component object coordinate, the result
985 * @return true if successful, otherwise false (failed to invert matrix, or becomes infinity due to zero z)
986 */
987 bool mapWinToView(const float winx, const float winy, const float winz,
988 const Recti& viewport, Vec3& objPos) noexcept {
989 if( Mat4::mapWinToAny(winx, winy, winz, getPi(), viewport, objPos) ) {
990 return true;
991 } else {
992 return false;
993 }
994 }
995
996 /**
997 * Map window coordinates to object coordinates.
998 * <p>
999 * Traditional <code>gluUnProject4</code> implementation.
1000 * </p>
1001 *
1002 * @param winx
1003 * @param winy
1004 * @param winz
1005 * @param clipw
1006 * @param viewport Rect4i viewport
1007 * @param near
1008 * @param far
1009 * @param objPos 4 component object coordinate, the result
1010 * @return true if successful, otherwise false (failed to invert matrix, or becomes infinity due to zero z)
1011 */
1012 bool mapWinToObj4(const float winx, const float winy, const float winz, const float clipw,
1013 const Recti& viewport, const float near, const float far, Vec4& objPos) const noexcept {
1014 if( Mat4::mapWinToObj4(winx, winy, winz, clipw, getPMvi(), viewport, near, far, objPos) ) {
1015 return true;
1016 } else {
1017 return false;
1018 }
1019 }
1020
1021 /**
1022 * Map two window coordinates w/ shared X/Y and distinctive Z
1023 * to a {@link Ray} in object space.
1024 *
1025 * The resulting {@link Ray} maybe used for <i>picking</i>
1026 * using a {@link AABBox#getRayIntersection(Vec3, Ray, float, bool) bounding box}
1027 * of a shape also in object space.
1028 *
1029 * Notes for picking <i>winz0</i> and <i>winz1</i>:
1030 * - see jau::math::util::getZBufferEpsilon()
1031 * - see jau::math::util::getZBufferValue()
1032 * - see jau::math::util::getOrthoWinZ()
1033 * @param winx
1034 * @param winy
1035 * @param winz0
1036 * @param winz1
1037 * @param viewport
1038 * @param ray storage for the resulting {@link Ray}
1039 * @return true if successful, otherwise false (failed to invert matrix, or becomes z is infinity)
1040 */
1041 bool mapWinToObjRay(const float winx, const float winy, const float winz0, const float winz1,
1042 const Recti& viewport, Ray3f& ray) noexcept {
1043 return Mat4::mapWinToAnyRay(winx, winy, winz0, winz1, getPMvi(), viewport, ray);
1044 }
1045
1046 /**
1047 * Map two window coordinates w/ shared X/Y and distinctive Z
1048 * to a {@link Ray} in world space.
1049 *
1050 * The resulting {@link Ray} maybe used for <i>picking</i>
1051 * using a {@link AABBox#getRayIntersection(Vec3, Ray, float, bool) bounding box}
1052 * of a shape also in world space.
1053 *
1054 * The INVERSE_PROJECTION must have been request in the constructor.
1055 *
1056 * - Pv' = P' x V', using getPi()
1057 * - V' x V x M = M, with Mv = V x M
1058 *
1059 * Notes for picking <i>winz0</i> and <i>winz1</i>:
1060 * - see jau::math::util::getZBufferEpsilon()
1061 * - see jau::math::util::getZBufferValue()
1062 * - see jau::math::util::getOrthoWinZ()
1063 * @param winx
1064 * @param winy
1065 * @param winz0
1066 * @param winz1
1067 * @param matVi the inverse view matrix
1068 * @param viewport
1069 * @param ray storage for the resulting {@link Ray}
1070 * @return true if successful, otherwise false (failed to invert matrix, or becomes z is infinity)
1071 *
1072 * @see INVERSE_PROJECTION
1073 * @see setView()
1074 */
1075 bool mapWinToWorldRay(const float winx, const float winy, const float winz0, const float winz1,
1076 const Mat4& matVi, const Recti& viewport, Ray3f& ray) noexcept {
1077 Mat4 invPv;
1078 invPv.mul(getPi(), matVi);
1079 return Mat4::mapWinToAnyRay(winx, winy, winz0, winz1, invPv, viewport, ray);
1080 }
1081
1082 /**
1083 * Map two window coordinates w/ shared X/Y and distinctive Z
1084 * to a {@link Ray} in view space.
1085 *
1086 * The resulting {@link Ray} maybe used for <i>picking</i>
1087 * using a {@link AABBox#getRayIntersection(Vec3, Ray, float, bool) bounding box}
1088 * of a shape also in view space.
1089 *
1090 * Notes for picking <i>winz0</i> and <i>winz1</i>:
1091 * - see jau::math::util::getZBufferEpsilon()
1092 * - see jau::math::util::getZBufferValue()
1093 * - see jau::math::util::getOrthoWinZ()
1094 * @param winx
1095 * @param winy
1096 * @param winz0
1097 * @param winz1
1098 * @param viewport
1099 * @param ray storage for the resulting {@link Ray}
1100 * @return true if successful, otherwise false (failed to invert matrix, or becomes z is infinity)
1101 */
1102 bool mapWinToViewRay(const float winx, const float winy, const float winz0, const float winz1,
1103 const Recti& viewport, Ray3f& ray) noexcept {
1104 return Mat4::mapWinToAnyRay(winx, winy, winz0, winz1, getPi(), viewport, ray);
1105 }
1106
1107 std::string& toString(std::string& sb, const std::string& f) const noexcept {
1108 int count = 3; // P, Mv, T
1109
1110 sb.append("PMVMatrix4[req").append(to_string(m_requestBits))
1111 .append(", mod1").append(to_string(m_dirtyBits))
1112 .append(", mod2").append(to_string(m_modifiedBits))
1113 .append(", Projection\n");
1114 m_matP.toString(sb, f);
1115 sb.append(", Modelview\n");
1116 m_matMv.toString(sb, f);
1117 sb.append(", Texture\n");
1118 m_matTex.toString(sb, f);
1119 {
1120 sb.append(", P * Mv\n");
1121 m_matPMv.toString(sb, f);
1122 ++count;
1123 }
1124 {
1125 sb.append(", P * Mv\n");
1126 m_matPMvi.toString(sb, f);
1127 ++count;
1128 }
1129 if( is_set(m_requestBits, PMVData::inv_mv) ) {
1130 sb.append(", Inverse Modelview\n");
1131 m_matMvi.toString(sb, f);
1132 ++count;
1133 }
1134 if( is_set(m_requestBits, PMVData::inv_tps_mv) ) {
1135 sb.append(", Inverse Transposed Modelview\n");
1136 m_matMvit.toString(sb, f);
1137 ++count;
1138 }
1139 int tmpCount = 1;
1140 if( true ) { // null != mat4Tmp2 ) {
1141 ++tmpCount;
1142 }
1143 sb.append(", matrices "+std::to_string(count)+" + "+std::to_string(tmpCount)+" temp = "+std::to_string(count+tmpCount)+"]");
1144 return sb;
1145 }
1146
1147 std::string toString() const noexcept {
1148 std::string sb;
1149 toString(sb, "%13.9f");
1150 return sb;
1151 }
1152
1153 /**
1154 * Returns the modified bits due to mutable operations..
1155 * <p>
1156 * A modified bit is set, if the corresponding matrix had been modified by a mutable operation
1157 * since last {@link #update()} or {@link #getModifiedBits(bool) getModifiedBits(true)} call.
1158 * </p>
1159 * @param clear if true, clears the modified bits, otherwise leaves them untouched.
1160 *
1161 * @see PMVState::MODIFIED_PROJECTION
1162 * @see PMVState::MODIFIED_MODELVIEW
1163 * @see PMVState::MODIFIED_TEXTURE
1164 * @see getDirtyBits()
1165 * @see isReqDirty()
1166 */
1167 constexpr PMVMod getModifiedBits(const bool clear) noexcept {
1168 const PMVMod r = m_modifiedBits;
1169 if(clear) {
1170 m_modifiedBits = PMVMod::none;
1171 }
1172 return r;
1173 }
1174
1175 /**
1176 * Returns the dirty bits due to mutable operations,
1177 * i.e.
1178 * - {@link #INVERSE_MODELVIEW} (if requested)
1179 * - {@link #INVERSE_PROJECTION} (if requested)
1180 * - {@link #INVERSE_TRANSPOSED_MODELVIEW} (if requested)
1181 * - {@link #FRUSTUM} (always, cleared via {@link #getFrustum()}
1182 * <p>
1183 * A dirty bit is set, if the corresponding matrix had been modified by a mutable operation
1184 * since last {@link #update()} call and requested in the constructor {@link #PMVMatrix4(int)}.
1185 * </p>
1186 * <p>
1187 * {@link #update()} clears the dirty state for the matrices and {@link #getFrustum()} for {@link #FRUSTUM}.
1188 * </p>
1189 *
1190 * @see #isReqDirty()
1191 * @see PMVMats::INVERSE_MODELVIEW
1192 * @see PMVMats::INVERSE_PROJECTION
1193 * @see PMVMats::INVERSE_TRANSPOSED_MODELVIEW
1194 * @see PMVMats::FRUSTUM
1195 * @see PMVMatrix4(PMVMats)
1196 * @see getMvi()
1197 * @see getMvit()
1198 * @see makeSyncPMvMvi()
1199 * @see makeSyncPMvMviMvit()
1200 * @see getFrustum()
1201 */
1202 constexpr PMVData getDirtyBits() noexcept {
1203 return m_dirtyBits;
1204 }
1205
1206 /**
1207 * Returns true if the one of the {@link #getReqBits() requested bits} are are set dirty due to mutable operations,
1208 * i.e. at least one of
1209 * - {@link #INVERSE_MODELVIEW}
1210 * - {@link #INVERSE_PROJECTION}
1211 * - {@link #INVERSE_TRANSPOSED_MODELVIEW}
1212 * <p>
1213 * A dirty bit is set, if the corresponding matrix had been modified by a mutable operation
1214 * since last {@link #update()} call and requested in the constructor {@link #PMVMatrix4(int)}.
1215 * </p>
1216 * <p>
1217 * {@link #update()} clears the dirty state for the matrices and {@link #getFrustum()} for {@link #FRUSTUM}.
1218 * </p>
1219 *
1220 * @see #INVERSE_MODELVIEW
1221 * @see #INVERSE_PROJECTION
1222 * @see #INVERSE_TRANSPOSED_MODELVIEW
1223 * @see #PMVMatrix4(int)
1224 * @see #getMvi()
1225 * @see #getMvit()
1226 * @see #makeSyncPMvMvi()
1227 * @see #makeSyncPMvMviMvit()
1228 */
1229 constexpr bool isReqDirty() noexcept {
1230 return has_any(m_dirtyBits, m_requestBits);
1231 }
1232
1233 /**
1234 * Sets the {@link #getMv() Modelview (Mv)} matrix dirty and modified,
1235 * i.e. adds INVERSE_MODELVIEW | INVERSE_TRANSPOSED_MODELVIEW | MANUAL_BITS to {@link #getDirtyBits() dirty bits}.
1236 * @see #isReqDirty()
1237 */
1238 constexpr void setModelviewDirty() noexcept {
1240 m_modifiedBits |= PMVMod::mv;
1241 }
1242
1243 /**
1244 * Sets the {@link #getP() Projection (P)} matrix dirty and modified,
1245 * i.e. adds INVERSE_PROJECTION | MANUAL_BITS to {@link #getDirtyBits() dirty bits}.
1246 */
1247 constexpr void setProjectionDirty() noexcept {
1248 m_dirtyBits |= PMVData::inv_proj | PMVData::manual ;
1249 m_modifiedBits |= PMVMod::proj;
1250 }
1251
1252 /**
1253 * Sets the {@link #getT() Texture (T)} matrix modified.
1254 */
1255 constexpr void setTextureDirty() noexcept {
1256 m_modifiedBits |= PMVMod::text;
1257 }
1258
1259 /**
1260 * Returns the request bit mask, which uses bit values equal to the dirty mask
1261 * and may contain
1262 * - PMVMats::INVERSE_MODELVIEW
1263 * - PMVMats::INVERSE_PROJECTION
1264 * - PMVMats::INVERSE_TRANSPOSED_MODELVIEW
1265 *
1266 * The request bit mask is set by in the constructor PMVMatrix4(PMVMats).
1267 *
1268 * @see PMVMats::INVERSE_MODELVIEW
1269 * @see PMVMats::INVERSE_PROJECTION
1270 * @see PMVMats::INVERSE_TRANSPOSED_MODELVIEW
1271 * @see PMVMatrix4(PMVMats)
1272 * @see getMvi()
1273 * @see getMvit()
1274 * @see makeSyncPMvMvi()
1275 * @see makeSyncPMvMviMvit()
1276 * @see getFrustum()
1277 */
1278 constexpr PMVData requestedBits() noexcept { return m_requestBits; }
1279
1280 /**
1281 * Returns the pre-multiplied projection x modelview, P x Mv.
1282 * <p>
1283 * This {@link Mat4} instance should be re-fetched via this method and not locally stored
1284 * to have it updated from a potential modification of underlying projection and/or modelview matrix.
1285 * {@link #update()} has no effect on this {@link Mat4}.
1286 * </p>
1287 * <p>
1288 * This pre-multipled P x Mv is considered dirty, if its corresponding
1289 * {@link #getP() P matrix} or {@link #getMv() Mv matrix} has been modified since its last update.
1290 * </p>
1291 * @see #update()
1292 */
1293 constexpr Mat4& getPMv() noexcept {
1294 if( is_set(m_dirtyBits, PMVData::pre_pmv) ) {
1295 m_matPMv.mul(m_matP, m_matMv);
1296 m_dirtyBits &= ~PMVData::pre_pmv;
1297 }
1298 return m_matPMv;
1299 }
1300
1301 /**
1302 * Returns the pre-multiplied inverse projection x modelview,
1303 * if {@link Mat4#invert(Mat4)} succeeded, otherwise `null`.
1304 * <p>
1305 * This {@link Mat4} instance should be re-fetched via this method and not locally stored
1306 * to have it updated from a potential modification of underlying projection and/or modelview matrix.
1307 * {@link #update()} has no effect on this {@link Mat4}.
1308 * </p>
1309 * <p>
1310 * This pre-multipled invert(P x Mv) is considered dirty, if its corresponding
1311 * {@link #getP() P matrix} or {@link #getMv() Mv matrix} has been modified since its last update.
1312 * </p>
1313 * @see #update()
1314 */
1315 constexpr Mat4& getPMvi() noexcept {
1316 if( is_set(m_dirtyBits, PMVData::pre_pmvi) ) {
1317 Mat4& mPMv = getPMv();
1318 m_matPMviOK = m_matPMvi.invert(mPMv);
1319 m_dirtyBits &= ~PMVData::pre_pmvi;
1320 }
1321 return m_matPMvi; // matPMviOK ? matPMvi : null; // FIXME
1322 }
1323
1324 /**
1325 * Returns the frustum, derived from projection x modelview.
1326 * <p>
1327 * This {@link Frustum} instance should be re-fetched via this method and not locally stored
1328 * to have it updated from a potential modification of underlying projection and/or modelview matrix.
1329 * {@link #update()} has no effect on this {@link Frustum}.
1330 * </p>
1331 * <p>
1332 * The {@link Frustum} is considered dirty, if its corresponding
1333 * {@link #getP() P matrix} or {@link #getMv() Mv matrix} has been modified since its last update.
1334 * </p>
1335 * @see #update()
1336 */
1338 if( is_set(m_dirtyBits, PMVData::frustum) ) {
1339 m_frustum.setFromMat(getPMv());
1340 m_dirtyBits &= ~PMVData::frustum;
1341 }
1342 return m_frustum;
1343 }
1344
1345 /**
1346 * Update the derived {@link #getMvi() inverse modelview (Mvi)},
1347 * {@link #getMvit() inverse transposed modelview (Mvit)} matrices
1348 * <b>if</b> they {@link #isReqDirty() are dirty} <b>and</b>
1349 * requested via the constructor {@link #PMVMatrix4(int)}.<br/>
1350 * Hence updates the following dirty bits.
1351 * - PMVMats::INVERSE_MODELVIEW
1352 * - PMVMats::INVERSE_PROJECTION
1353 * - PMVMats::INVERSE_TRANSPOSED_MODELVIEW
1354 *
1355 * The {@link Frustum} is updated only via {@link #getFrustum()} separately.
1356
1357 * The Mvi and Mvit matrices are considered dirty, if their corresponding
1358 * {@link #getMv() Mv matrix} has been modified since their last update.
1359
1360 * Method is automatically called by {@link SyncMat4} and {@link SyncMatrices4f}
1361 * instances {@link SyncAction} as retrieved by e.g. {@link #makeSyncMvit()}.
1362 * This ensures an automatic update cycle if used with {@link com.jogamp.opengl.GLUniformData}.
1363
1364 * Method may be called manually in case mutable operations has been called
1365 * and caller operates on already fetched references, i.e. not calling
1366 * {@link #getMvi()}, {@link #getMvit()} anymore.
1367
1368 * Method clears the modified bits like {@link #getModifiedBits(bool) getModifiedBits(true)},
1369 * which are set by any mutable operation. The modified bits have no impact
1370 * on this method, but the return value.
1371 *
1372 * @return true if any matrix has been modified since last update call or
1373 * if the derived matrices Mvi and Mvit were updated, otherwise false.
1374 * In other words, method returns true if any matrix used by the caller must be updated,
1375 * e.g. uniforms in a shader program.
1376 *
1377 * @see getModifiedBits(bool)
1378 * @see isReqDirty()
1379 * @see PMVMats::INVERSE_MODELVIEW
1380 * @see PMVMats::INVERSE_PROJECTION
1381 * @see PMVMats::INVERSE_TRANSPOSED_MODELVIEW
1382 * @see PMVMatrix4(PMVMats)
1383 * @see getMvi()
1384 * @see getMvit()
1385 * @see makeSyncPMvMvi()
1386 * @see makeSyncPMvMviMvit()
1387 */
1388 bool update() noexcept {
1389 return updateImpl(true);
1390 }
1391
1392 //
1393 // private
1394 //
1395
1396 private:
1397 void updateImpl0() noexcept { updateImpl(false); }
1398 bool updateImpl(bool clearModBits) noexcept {
1399 bool mod = has_any(m_modifiedBits);
1400 if( clearModBits ) {
1401 m_modifiedBits = PMVMod::none;
1402 mod = false;
1403 }
1404 if( has_any( m_requestBits & ( ( m_dirtyBits & ( PMVData::inv_proj ) ) ) ) ) { // only if requested & dirty
1405 if( !m_matPi.invert(m_matP) ) {
1406 DBG_ERR_PRINT("Invalid source P matrix, can't compute inverse: %s", m_matP.toString().c_str(), E_FILE_LINE);
1407 // still continue with other derived matrices
1408 } else {
1409 mod = true;
1410 }
1411 m_dirtyBits &= ~PMVData::inv_proj;
1412 }
1413 if( has_any( m_requestBits & ( ( m_dirtyBits & ( PMVData::inv_mv | PMVData::inv_tps_mv ) ) ) ) ) { // only if requested & dirty
1414 if( !m_matMvi.invert(m_matMv) ) {
1415 DBG_ERR_PRINT("Invalid source Mv matrix, can't compute inverse: %s", m_matMv.toString().c_str(), E_FILE_LINE);
1416 m_dirtyBits &= ~(PMVData::inv_mv | PMVData::inv_tps_mv);
1417 return mod; // no successful update as we abort due to inversion failure, skip INVERSE_TRANSPOSED_MODELVIEW as well
1418 }
1419 m_dirtyBits &= ~PMVData::inv_mv;
1420 mod = true;
1421 }
1422 if( has_any( m_requestBits & ( m_dirtyBits & PMVData::inv_tps_mv ) ) ) { // only if requested & dirty
1423 m_matMvit.transpose(m_matMvi);
1424 m_dirtyBits &= ~PMVData::inv_tps_mv;
1425 mod = true;
1426 }
1427 return mod;
1428 }
1429};
1430
1431template <jau::req::packed_floating_point Value_type>
1432inline std::ostream& operator<<(std::ostream& out, const PMVMatrix4<Value_type>& v) noexcept {
1433 return out << v.toString();
1434}
1435
1437
1438 /**@}*/
1439
1440 } // namespace jau::math::util
1441
1442 #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:690
constexpr void setModelviewDirty() noexcept
Sets the Modelview (Mv) matrix dirty and modified, i.e.
Definition pmvmat4.hpp:1238
constexpr PMVMatrix4 & scaleP(float x, float y, float z) noexcept
Scale the projection matrix.
Definition pmvmat4.hpp:702
SyncMats4f makeSyncPMvReq()
Returns a new SyncMatrices4f of either 4 matrices makeSyncPMvMviMvit(), 3 matrices makeSyncPMvMvi() o...
Definition pmvmat4.hpp:417
constexpr Mat4 & getMulMvP(Mat4 &result) noexcept
Returns multiplication result of Mv and P matrix, i.e.
Definition pmvmat4.hpp:457
constexpr PMVMod getModifiedBits(const bool clear) noexcept
Returns the modified bits due to mutable operations.
Definition pmvmat4.hpp:1167
constexpr PMVMatrix4 & loadMv(float values[]) noexcept
Load the modelview matrix with the provided values.
Definition pmvmat4.hpp:500
constexpr PMVMatrix4 & mulP(const Mat4 &m) noexcept
Multiply the projection matrix: [c] = [c] x [m].
Definition pmvmat4.hpp:615
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:1278
bool update() noexcept
Update the derived inverse modelview (Mvi), inverse transposed modelview (Mvit) matrices if they are ...
Definition pmvmat4.hpp:1388
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:1102
constexpr PMVMatrix4 & rotateP(const Quat4f &quat) noexcept
Rotate the projection matrix with the given Quaternion's rotation matrix representation.
Definition pmvmat4.hpp:787
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:848
constexpr PMVMatrix4 & mulMv(const Mat4 &m) noexcept
Multiply the modelview matrix: [c] = [c] x [m].
Definition pmvmat4.hpp:604
constexpr PMVMatrix4 & loadP(const Mat4 &m)
Load the projection matrix with the values of the given Mat4.
Definition pmvmat4.hpp:533
constexpr Vec4 & mulWithMv(const Vec4 &v_in, Vec4 &v_out) noexcept
v_out = Mv x v_in
Definition pmvmat4.hpp:467
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:508
constexpr PMVMatrix4 & scaleP(const Vec3 &s) noexcept
Scale the projection matrix.
Definition pmvmat4.hpp:711
constexpr PMVMatrix4 & translateMv(float x, float y, float z) noexcept
Translate the modelview matrix.
Definition pmvmat4.hpp:639
std::string toString() const noexcept
Definition pmvmat4.hpp:1147
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:726
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:966
Ray3F< value_type > Ray3
Definition pmvmat4.hpp:128
std::string & toString(std::string &sb, const std::string &f) const noexcept
Definition pmvmat4.hpp:1107
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:489
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:764
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:1075
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:1229
constexpr PMVMatrix4 & loadT(Mat4 &m) noexcept
Load the texture matrix with the values of the given Mat4.
Definition pmvmat4.hpp:558
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:1012
constexpr_cxx20 PMVMatrix4 & popMv() noexcept
Pop the modelview matrix from its stack.
Definition pmvmat4.hpp:793
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:541
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:476
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:648
constexpr PMVMatrix4 & mulT(const Mat4 &m) noexcept
Multiply the texture matrix: [c] = [c] x [m].
Definition pmvmat4.hpp:626
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:867
constexpr PMVMatrix4 & loadMvIdentity() noexcept
Load the modelview matrix with the values of the given Mat4.
Definition pmvmat4.hpp:575
constexpr Mat4 & getMulPMv(Mat4 &result) noexcept
Returns multiplication result of P and Mv matrix, i.e.
Definition pmvmat4.hpp:445
constexpr void setTextureDirty() noexcept
Sets the Texture (T) matrix modified.
Definition pmvmat4.hpp:1255
constexpr_cxx20 PMVMatrix4 & pushT() noexcept
Push the texture matrix to its stack, while preserving its values.
Definition pmvmat4.hpp:821
constexpr PMVMatrix4 & loadTIdentity() noexcept
Load the texture matrix with the values of the given Mat4.
Definition pmvmat4.hpp:593
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:566
constexpr PMVMatrix4 & rotateMv(const Quat4f &quat) noexcept
Rotate the modelview matrix with the given Quaternion's rotation matrix representation.
Definition pmvmat4.hpp:749
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:836
constexpr PMVMatrix4 & lookAtP(const Vec3 &eye, const Vec3 &center, const Vec3 &up) noexcept
Multiply the projection matrix with the eye, object and orientation, i.e.
Definition pmvmat4.hpp:877
bool mapViewToWin(const Vec3 &view, const Recti &viewport, Vec3 &winPos) const noexcept
Map view coordinates ( Mv x object ) to window coordinates.
Definition pmvmat4.hpp:924
constexpr PMVMatrix4 & loadP(float values[]) noexcept
Load the projection matrix with the provided values.
Definition pmvmat4.hpp:525
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:1041
bool mapWorldToWin(const Vec3 &objPos, const Mat4 &matV, const Recti &viewport, Vec3 &winPos) const noexcept
Map world coordinates to window coordinates.
Definition pmvmat4.hpp:911
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:805
constexpr PMVMatrix4 & translateP(float x, float y, float z) noexcept
Translate the projection matrix.
Definition pmvmat4.hpp:660
constexpr PMVMatrix4 & translateP(const Vec3 &t) noexcept
Translate the projection matrix.
Definition pmvmat4.hpp:669
constexpr Mat4 & getPMvi() noexcept
Returns the pre-multiplied inverse projection x modelview, if Mat4#invert(Mat4) succeeded,...
Definition pmvmat4.hpp:1315
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:681
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:987
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:516
constexpr_cxx20 PMVMatrix4 & pushP() noexcept
Push the projection matrix to its stack, while preserving its values.
Definition pmvmat4.hpp:816
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:740
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:1293
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:1247
constexpr PMVMatrix4 & loadPIdentity() noexcept
Load the projection matrix with the values of the given Mat4.
Definition pmvmat4.hpp:584
jau::math::geom::Frustum getFrustum() noexcept
Returns the frustum, derived from projection x modelview.
Definition pmvmat4.hpp:1337
SyncMatrices4< value_type > SyncMats4
Definition pmvmat4.hpp:130
constexpr_cxx20 PMVMatrix4 & popP() noexcept
Pop the projection matrix from its stack.
Definition pmvmat4.hpp:799
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:941
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:550
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:811
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:894
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:1202
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:778
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:1436
@ 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