VR-Vantage
Loading...
Searching...
No Matches
DtCamera.inl
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2023 MAK Technologies, Inc.
3** All rights reserved.
4******************************************************************************/
5
9#pragma once
10
11#include <vrvMath/DtVector4.h>
12#include <iostream>
13
14namespace makVrv
15{
16
17 template <class T>
22 , myfNearPlane(0.1f)
23 , myfFarPlane(10.0f)
24 , myfFieldOfViewY(DtMath::PI_BY_4)
25 , mybFixedUpVector(true)
26 , myfAspectRatio(1.0f)
27 {
28 //intentional nop
29 }
30
31 template <class T>
33 {
34 //intentional nop
35 }
36
37 template <class T>
38 void DtCamera<T>::setNearPlane(T fNearPlane)
39 {
40 myfNearPlane = fNearPlane;
42 }
43
44 template <class T>
46 {
47 return myfNearPlane;
48 }
49
50 template <class T>
51 void DtCamera<T>::setFarPlane(T fFarPlane)
52 {
53 myfFarPlane = fFarPlane;
55 }
56
57 template <class T>
59 {
60 return myfFarPlane;
61 }
62
63 template <class T>
69
70 template <class T>
72 {
73 return myfFieldOfViewY;
74 }
75
76 template <class T>
78 {
79 lookAt(vPosition, direction(), upVector());
80 }
81
82 template <class T>
84 {
85 return myVecPosition;
86 }
87
88 template <class T>
90 {
91 myVecDirection = vDirection;
92 myVecDirection.normalize();
93 }
94 template <class T>
96 {
97 return myVecDirection;
98 }
99
100 template <class T>
102 {
103 return myVecUpVector;
104 }
105
106 template <class T>
108 {
109 return myVecSideVector;
110 }
111
112 template <class T>
114 , const DtVector3<T>& vLook, const DtVector3<T>& _vUp)
115 {
116 DtVector3<T> vForward = vLook - vEye;
117 vForward.normalize();
118
119 DtVector3<T> vUp = _vUp;
120 vUp.normalize();
121
122 // Get the side vector
123 DtVector3<T> vSide = vForward.crossProduct(vUp);
124 vSide.normalize();
125
126 // Compute the up vector again
127 vUp = vSide.crossProduct(vForward);
128 vUp.normalize();
129
130 DtMatrix4<T> matToViewSpace(
131 vSide.x, vSide.y, vSide.z, 0
132 , vUp.x, vUp.y, vUp.z, 0
133 , -vForward.x, -vForward.y, -vForward.z, 0
134 , 0, 0, 0, 1
135 );
136
137 DtMatrix4<T> matTranslateToEye(
138 1, 0, 0, -vEye.x
139 , 0, 1, 0, -vEye.y
140 , 0, 0, 1, -vEye.z
141 , 0, 0, 0, 1
142 );
143
144 myViewMatrix = matToViewSpace * matTranslateToEye;
145
146 myVecPosition = vEye;
147 myVecDirection = vForward;
148 if (isFixedUpVector())
149 {
150 myVecUpVector = _vUp;
151 myVecUpVector.normalize();
152 }
153 else
154 {
155 myVecUpVector = vUp;
156 }
157 myVecSideVector = vSide;
158
161 }
162
163 template <class T>
165 {
166 return myViewMatrix;
167 }
168
169 template <class T>
170 void DtCamera<T>::SetPerspective(T fFOVy, T fAspectRatio, T fNearPlane, T fFarPlane)
171 {
172 ASSERT_PREDICATE_RETURN(fFarPlane > fNearPlane);
173
174 myfFieldOfViewY = fFOVy;
175
176 myfNearPlane = fNearPlane;
177 myfFarPlane = fFarPlane;
178
179 myfAspectRatio = fAspectRatio;
180
181 T f = 1.0f / DtMath::Tan(myfFieldOfViewY*0.5f);
182 T zNear_plus_zFar = myfNearPlane + myfFarPlane;
183 T zNear_minus_zFar = myfNearPlane - myfFarPlane;
184
186 myProjectionMatrix[1][0] = 0; myProjectionMatrix[1][1] = f; myProjectionMatrix[1][2] = 0; myProjectionMatrix[1][3] = 0;
187 myProjectionMatrix[2][0] = 0; myProjectionMatrix[2][1] = 0; myProjectionMatrix[2][2] = zNear_plus_zFar / zNear_minus_zFar; myProjectionMatrix[2][3] = 2 * myfNearPlane*myfFarPlane / zNear_minus_zFar;
188 myProjectionMatrix[3][0] = 0; myProjectionMatrix[3][1] = 0; myProjectionMatrix[3][2] = -1; myProjectionMatrix[3][3] = 0;
189
192 }
193
194 template <class T>
196 {
197 return myProjectionMatrix;
198 }
199
200 template <class T>
202 {
203 mybFixedUpVector = fixed;
204 }
205 template <class T>
207 {
208 return mybFixedUpVector;
209 }
210
211 template <class T>
213 {
214 return myfAspectRatio;
215 }
216
217 template <class T>
219 {
220 Frustum<T> frustum;
222 for (int i = 0; i < 6; ++i)
223 {
224 myFrustumPlanes[i] = frustum.plane(i);
225 }
226 }
227
228 template <class T>
233
234 template <class T>
239
240 template <class T>
242 {
243 // Null boxes always invisible
244 if (box.isNull())
245 {
246 return false;
247 }
248
249 // Infinite boxes always visible
250 if (box.isInfinite())
251 {
252 return true;
253 }
254 // Get center of the box
255 DtVector3<T> vCenter = box.center();
256 // Get the half-size of the box
257 DtVector3<T> vHalfSize = box.halfSize();
258
259 // For each plane, see if all points are on the negative side
260 // If so, object is not visible
261 for (int plane = 0; plane < 6; ++plane)
262 {
263 // Skip far plane if infinite view frustum
264 if (plane == FRUSTUM_PLANE_FAR && farPlane() == 0)
265 continue;
266
267 PlaneSide side = myFrustumPlanes[plane].getSide(vCenter, vHalfSize);
268 if (side == NEGATIVE_SIDE)
269 {
270 // ALL corners on negative side therefore out of view
271 return false;
272 }
273 }
274 return true;
275 }
276
277 template <class T>
279 {
280 // Null boxes always invisible
281 if (box.isNull())
282 {
283 return VISIBILITY_NONE;
284 }
285
286 // Infinite boxes always visible
287 if (box.isInfinite())
288 {
289 return VISIBILITY_FULL;
290 }
291
292 // Get center of the box
293 DtVector3<T> vCenter = box.center();
294 // Get the half-size of the box
295 DtVector3<T> vHalfSize = box.halfSize();
296
297 bool bAllInside = true;
298 // For each plane, see if all points are on the negative side
299 // If so, object is not visible
300 for (int plane = 0; plane < 6; ++plane)
301 {
302 // Skip far plane if infinite view frustum
303 if (plane == FRUSTUM_PLANE_FAR && farPlane() == 0)
304 continue;
305
306 PlaneSide side = myFrustumPlanes[plane].getSide(vCenter, vHalfSize);
307 if (side == NEGATIVE_SIDE)
308 {
309 // ALL corners on negative side therefore out of view
310 return VISIBILITY_NONE;
311 }
312 // We can't return now as the box could be later on the negative side of a plane.
313 if (side == BOTH_SIDE)
314 {
315 bAllInside = false;
316 }
317 }
318 if (bAllInside)
319 {
320 return VISIBILITY_FULL;
321 }
322 else
323 {
324 return VISIBILITY_PARTIAL;
325 }
326 }
327
328 template<class T>
330 , const DtMatrix4<T>& view_projection_matrix
331 , bool clip)
332 {
333 DtVector4<T> position = view_projection_matrix * DtVector4<T>(vPosition3, 1);
334 T w = (-position.w < position.w) ? position.w : -position.w;
335 if (clip)
336 {
337 position.x = DtMath::clamp<T>(position.x, -w, +w);
338 position.y = DtMath::clamp<T>(position.y, -w, +w);
339 position.z = DtMath::clamp<T>(position.z, -w, +w);
340 }
341
342 if (w < 0.000001)
343 {
344 w = 1.0;
345 }
346
347 position /= w;
348
349 if (clip)
350 {
351 position.x = DtMath::clamp<T>(position.x, -1, 1);
352 position.y = DtMath::clamp<T>(position.y, -1, 1);
353 }
354
355 position = position * T(0.5) + T(0.5);
356 //position.y = 1 - position.y;
357
358 return DtVector2<T>(position.x, position.y);
359 }
360
361 template<class T>
363 , const Vector2_uint32& viewPortSize) const
364 {
365 return ProjectionUtils<T>::screenAABB(worldBox, ViewProjectionMatrix(), viewPortSize);
366 }
367
368 template<class T>
370 , const DtMatrix4<T>& view_projection_matrix, const Vector2_uint32& viewPortSize
371 , bool clip)
372 {
373 DtVector2<T> vClipCoords = ProjectionUtils<T>::project(vPosition3, view_projection_matrix, clip);
374
375 vClipCoords.x *= viewPortSize.x;
376 vClipCoords.y *= viewPortSize.y;
377
378 return Vector2_uint32(uint32(vClipCoords.x), uint32(vClipCoords.y));
379 }
380
381 template<class T>
383 , const DtMatrix4<T>& view_projection_matrix, const Vector2_uint32& viewPortSize
384 , bool clip)
385 {
386 DtScreenRect rect;
387
388 if (worldBox.isInfinite())
389 {
391 rect.vMax = viewPortSize;
392 return rect;
393 }
394 if (worldBox.isNull())
395 {
398 return rect;
399 }
400
401 rect.vMin = viewPortSize;
403
404 // Array of 8 corners
405 DtVector3<float64> vectorAABBCorners[8];
406 worldBox.GetCorners(vectorAABBCorners);
407
408 for (size_t i = 0; i < 8; ++i)
409 {
410 Vector2_int vWindowCoords
411 = project(vectorAABBCorners[i], view_projection_matrix, viewPortSize, clip);
412
413 rect.vMin.x = std::min(rect.vMin.x, vWindowCoords.x);
414 rect.vMin.y = std::min(rect.vMin.y, vWindowCoords.y);
415
416 rect.vMax.x = std::max(rect.vMax.x, vWindowCoords.x);
417 rect.vMax.y = std::max(rect.vMax.y, vWindowCoords.y);
418 }
419 return rect;
420 }
421
422 template<class T>
424 {
425
426 }
427
428 template<class T>
430 {
431 //intentional nop
432 }
433
434 template <class T>
435 template <class RHS>
440
441 template <class T>
442 template <class RHS>
444 {
446 return *this;
447 }
448
449 template<class T>
451 {
452 myFrustumPlanes[plane].vNormal = vNormal;
453 myFrustumPlanes[plane].vNormal.normalize();
454 myFrustumPlanes[plane].d = d;
455 }
456
457 template<class T>
459 {
460 return myFrustumPlanes[planeIndex];
461 }
462
463 template<class T>
465 {
466 return DtVector4<T>(myFrustumPlanes[planeIndex].vNormal.x
467 , myFrustumPlanes[planeIndex].vNormal.y
468 , myFrustumPlanes[planeIndex].vNormal.z
469 , myFrustumPlanes[planeIndex].d);
470 }
471
472 template <class T>
474 {
475 // Null boxes always invisible
476 if (box.isNull()) return VISIBILITY_NONE;
477
478 // Infinite boxes always visible
479 if (box.isInfinite()) return VISIBILITY_FULL;
480
481 // Get center of the box
482 DtVector3<T> vCenter = box.center();
483 // Get the half-size of the box
484 DtVector3<T> vHalfSize = box.halfSize();
485
486 bool bAllInside = true;
487 // For each plane, see if all points are on the negative side
488 // If so, object is not visible
489 for (int plane = 0; plane < 6; ++plane)
490 {
491 if (ignoreNearFar && (plane == FRUSTUM_PLANE_NEAR || plane == FRUSTUM_PLANE_FAR))
492 {
493 continue;
494 }
495 // Skip far plane if infinite view frustum
496 // PPP
497 //if (plane == FRUSTUM_PLANE_FAR && GetFarPlane() == 0)
498 // continue;
499
500 PlaneSide side = myFrustumPlanes[plane].getSide(vCenter, vHalfSize);
501 if (side == NEGATIVE_SIDE)
502 {
503 // ALL corners on negative side therefore out of view
504 return VISIBILITY_NONE;
505 }
506 // We can't return now as the box could be later on the negative side of a plane.
507 if (side == BOTH_SIDE)
508 {
509 bAllInside = false;
510 }
511 }
512 if (bAllInside)
513 return VISIBILITY_FULL;
514 else
515 return VISIBILITY_PARTIAL;
516 }
517
518 template <class T>
520 {
521 // Null boxes always invisible
522 if (box.isNull())
523 {
524 return false;
525 }
526
527 // Infinite boxes always visible
528 if (box.isInfinite())
529 {
530 return true;
531 }
532
533 // Get center of the box
534 DtVector3<T> vCenter = box.center();
535 // Get the half-size of the box
536 DtVector3<T> vHalfSize = box.halfSize();
537
538 // For each plane, see if all points are on the negative side
539 // If so, object is not visible
540 for (int plane = 0; plane < 6; ++plane)
541 {
542 // PPP
543 // Skip far plane if infinite view frustum
544 //if (plane == FRUSTUM_PLANE_FAR && GetFarPlane() == 0)
545 // continue;
546
547 PlaneSide side = myFrustumPlanes[plane].getSide(vCenter, vHalfSize);
548 if (side == NEGATIVE_SIDE)
549 {
550 // ALL corners on negative side therefore out of view
551 return false;
552 }
553 }
554 return true;
555 }
556
557 template <class T>
558 bool Frustum<T>::isSphereVisible(const DtVector3<T>& center, T radius) const
559 {
560 const T x = center.x;
561 const T y = center.y;
562 const T z = center.z;
563
564 for (unsigned int i = 0; i < 6; ++i)
565 {
566 const DtPlane<T>& plane = myFrustumPlanes[i];
567 const DtVector3<T>& n = plane.vNormal;
568 const T dist = x * n.x + y * n.y + z * n.z + plane.d;
569 if (dist + radius < 0.0)
570 {
571 return false;
572 }
573 }
574
575 return true;
576 }
577
578 template <class T>
579 bool Frustum<T>::isSphereVisibleRadiusSquared(const DtVector3<T>& center, double radiusSquared) const
580 {
581 const T x = center.x;
582 const T y = center.y;
583 const T z = center.z;
584
585 for (unsigned int i = 0; i < 6; ++i)
586 {
587 const DtPlane<T>& plane = myFrustumPlanes[i];
588 const DtVector3<T>& n = plane.vNormal;
589 const T dist = x * n.x + y * n.y + z * n.z + plane.d;
590 if ((dist < 0.0) &&
591 ((dist * dist) > radiusSquared))
592 {
593 return false;
594 }
595 }
596
597 return true;
598 }
599
600 template<class T>
602 const DtVector3<T>& point1, const DtVector3<T>& point2) const
603 {
604 const DtVector3<T> a(point1 - point0);
605 const DtVector3<T> b(point2 - point0);
606
607 DtVector3<T>& n = plane.vNormal;
608 n = b.crossProduct(a);
609
610 T length = n.length();
611 if (length > 0.0)
612 {
613 n /= length;
614 }
615
616 plane.d = -(n.dotProduct(point0));
617 }
618
619 template<class T>
621 const DtMatrix4<T>& projMat)
622 {
623 // Note: would have liked to use Gribb & Hartman method for extracting
624 // frustum from projection matrix, but it does not work for reverse z.
625 // Maybe someone could figure out the math for it.
626
627 // This code works for normal and reverse z.
628
629 bool reverseZ = (projMat[2][2] > 0.0);
630
631 // Get near and far from the Projection matrix.
632 T frustNear;
633 T frustFar;
634
635 if (reverseZ)
636 {
637 frustNear = projMat[3][2] / (1.0 + projMat[2][2]);
638 frustFar = projMat[3][2] / projMat[2][2];
639 }
640 else
641 {
642 frustNear = projMat[3][2] / (projMat[2][2] - 1.0);
643 frustFar = projMat[3][2] / (1.0 + projMat[2][2]);
644 }
645
646 const T frustLeft = (projMat[2][0] - 1.0) / projMat[0][0];
647 const T frustRight = (1.0 + projMat[2][0]) / projMat[0][0];
648 const T frustTop = (1.0 + projMat[2][1]) / projMat[1][1];
649 const T frustBottom = (projMat[2][1] - 1.0) / projMat[1][1];
650
651 // Get the sides of the near plane.
652 const T nLeft = frustNear * frustLeft;
653 const T nRight = frustNear * frustRight;
654 const T nTop = frustNear * frustTop;
655 const T nBottom = frustNear * frustBottom;
656
657 // Get the sides of the far plane.
658 const T fLeft = frustFar * frustLeft;
659 const T fRight = frustFar * frustRight;
660 const T fTop = frustFar * frustTop;
661 const T fBottom = frustFar * frustBottom;
662
663 // Create the frustum points.
664 DtVector3<T> point[8];
665 point[0] = DtVector3<T>(nLeft, nBottom, -frustNear);
666 point[1] = DtVector3<T>(nRight, nBottom, -frustNear);
667 point[2] = DtVector3<T>(nRight, nTop, -frustNear);
668 point[3] = DtVector3<T>(nLeft, nTop, -frustNear);
669 point[4] = DtVector3<T>(fLeft, fBottom, -frustFar);
670 point[5] = DtVector3<T>(fRight, fBottom, -frustFar);
671 point[6] = DtVector3<T>(fRight, fTop, -frustFar);
672 point[7] = DtVector3<T>(fLeft, fTop, -frustFar);
673
674 // Transform the frustum points from model view space to world space.
675 const DtMatrix4<T> modelViewMatI = modelViewMat.getInverse();
676 DtVector4<T> point4;
677 for (int i = 0; i < 8; ++i)
678 {
679 DtVector3<T>& p = point[i];
680 point4.x = p.x;
681 point4.y = p.y;
682 point4.z = p.z;
683 point4.w = 1.0;
684 point4 = modelViewMatI.transposeMultiply(point4);
685 p.x = point4.x;
686 p.y = point4.y;
687 p.z = point4.z;
688 }
689
690 // Compute frustum planes from the world space frustum points.
691 computePlaneFromPoints(myFrustumPlanes[FRUSTUM_PLANE_LEFT], point[0], point[7], point[4]);
692 computePlaneFromPoints(myFrustumPlanes[FRUSTUM_PLANE_RIGHT], point[1], point[5], point[6]);
693 computePlaneFromPoints(myFrustumPlanes[FRUSTUM_PLANE_TOP], point[3], point[6], point[7]);
694 computePlaneFromPoints(myFrustumPlanes[FRUSTUM_PLANE_BOTTOM], point[0], point[4], point[5]);
695 computePlaneFromPoints(myFrustumPlanes[FRUSTUM_PLANE_NEAR], point[0], point[1], point[2]);
696 computePlaneFromPoints(myFrustumPlanes[FRUSTUM_PLANE_FAR], point[5], point[4], point[7]);
697 }
698
699 template<class T>
701 {
702 myFrustumPlanes[FRUSTUM_PLANE_LEFT].vNormal.x = mvp[3][0] + mvp[0][0];
703 myFrustumPlanes[FRUSTUM_PLANE_LEFT].vNormal.y = mvp[3][1] + mvp[0][1];
704 myFrustumPlanes[FRUSTUM_PLANE_LEFT].vNormal.z = mvp[3][2] + mvp[0][2];
705 myFrustumPlanes[FRUSTUM_PLANE_LEFT].d = mvp[3][3] + mvp[0][3];
706
707 myFrustumPlanes[FRUSTUM_PLANE_RIGHT].vNormal.x = mvp[3][0] - mvp[0][0];
708 myFrustumPlanes[FRUSTUM_PLANE_RIGHT].vNormal.y = mvp[3][1] - mvp[0][1];
709 myFrustumPlanes[FRUSTUM_PLANE_RIGHT].vNormal.z = mvp[3][2] - mvp[0][2];
710 myFrustumPlanes[FRUSTUM_PLANE_RIGHT].d = mvp[3][3] - mvp[0][3];
711
712 myFrustumPlanes[FRUSTUM_PLANE_TOP].vNormal.x = mvp[3][0] - mvp[1][0];
713 myFrustumPlanes[FRUSTUM_PLANE_TOP].vNormal.y = mvp[3][1] - mvp[1][1];
714 myFrustumPlanes[FRUSTUM_PLANE_TOP].vNormal.z = mvp[3][2] - mvp[1][2];
715 myFrustumPlanes[FRUSTUM_PLANE_TOP].d = mvp[3][3] - mvp[1][3];
716
717 myFrustumPlanes[FRUSTUM_PLANE_BOTTOM].vNormal.x = mvp[3][0] + mvp[1][0];
718 myFrustumPlanes[FRUSTUM_PLANE_BOTTOM].vNormal.y = mvp[3][1] + mvp[1][1];
719 myFrustumPlanes[FRUSTUM_PLANE_BOTTOM].vNormal.z = mvp[3][2] + mvp[1][2];
720 myFrustumPlanes[FRUSTUM_PLANE_BOTTOM].d = mvp[3][3] + mvp[1][3];
721
722 myFrustumPlanes[FRUSTUM_PLANE_NEAR].vNormal.x = mvp[3][0] + mvp[2][0];
723 myFrustumPlanes[FRUSTUM_PLANE_NEAR].vNormal.y = mvp[3][1] + mvp[2][1];
724 myFrustumPlanes[FRUSTUM_PLANE_NEAR].vNormal.z = mvp[3][2] + mvp[2][2];
725 myFrustumPlanes[FRUSTUM_PLANE_NEAR].d = mvp[3][3] + mvp[2][3];
726
727 myFrustumPlanes[FRUSTUM_PLANE_FAR].vNormal.x = mvp[3][0] - mvp[2][0];
728 myFrustumPlanes[FRUSTUM_PLANE_FAR].vNormal.y = mvp[3][1] - mvp[2][1];
729 myFrustumPlanes[FRUSTUM_PLANE_FAR].vNormal.z = mvp[3][2] - mvp[2][2];
730 myFrustumPlanes[FRUSTUM_PLANE_FAR].d = mvp[3][3] - mvp[2][3];
731
732 // Re-normalize any normals which were not unit length
733 for (int i = 0; i < 6; ++i)
734 {
735 T length = myFrustumPlanes[i].vNormal.length();
736 myFrustumPlanes[i].vNormal.normalize();
737 myFrustumPlanes[i].d /= length;
738 }
739 }
740
741 template<class T>
742 void Frustum<T>::frustumPlanes(std::array<DtVector4<T>, 6>& planes) const
743 {
744 for(int i=0; i<6; ++i)
745 {
746 const DtPlane<T>& sourcePlane = myFrustumPlanes[i];
747 const DtVector3<T>& sourceN = sourcePlane.vNormal;
748 DtVector4<T>& destPlane = planes[i];
749 destPlane.x = sourceN.x;
750 destPlane.y = sourceN.y;
751 destPlane.z = sourceN.z;
752 destPlane.w = sourcePlane.d;
753 }
754 }
755
756 template<class T>
757 bool Frustum<T>::operator==(const Frustum<T>& rhs) const
758 {
759 for (int i = 0; i < 6; ++i)
760 {
761 bool equal = myFrustumPlanes[i].vNormal == rhs.myFrustumPlanes[i].vNormal
762 && myFrustumPlanes[i].d == rhs.myFrustumPlanes[i].d;
763 if (!equal)
764 {
765 return false;
766 }
767 }
768 return true;
769 }
770
771 template<class T>
772 bool Frustum<T>::operator!=(const Frustum<T>& rhs) const
773 {
774 const Frustum<T>& lhs = *this;
775 return !(lhs == rhs);
776 }
777
778 template<class T>
779 inline std::ostream& operator <<
780 (std::ostream& o, const Frustum<T>& frustum)
781 {
782 o << "near: " << frustum.plane(FRUSTUM_PLANE_NEAR) << std::endl;
783 o << "far : " << frustum.plane(FRUSTUM_PLANE_FAR) << std::endl;
784 o << "left: " << frustum.plane(FRUSTUM_PLANE_LEFT) << std::endl;
785 o << "righ: " << frustum.plane(FRUSTUM_PLANE_RIGHT) << std::endl;
786 o << "top : " << frustum.plane(FRUSTUM_PLANE_TOP) << std::endl;
787 o << "bott: " << frustum.plane(FRUSTUM_PLANE_BOTTOM) << std::endl;
788
789 return o;
790 }
791
792} //namespace makVrv
#define ASSERT_PREDICATE_RETURN(p)
Definition DtAssert.h:37
4 dimensional vector
Template for 32/64 bit Axis Aligned bounding boxesnot virtual because its stored as is on the GPU.
Definition DtAxisAlignedBoundingBox.h:28
bool isNull(void) const
is null?
Definition DtAxisAlignedBoundingBox.inl:203
DtVector3< T > center(void) const
get the center
Definition DtAxisAlignedBoundingBox.inl:67
bool isInfinite(void) const
is infinite extents?
Definition DtAxisAlignedBoundingBox.inl:193
DtVector3< T > halfSize(void) const
half size
Definition DtAxisAlignedBoundingBox.inl:132
void GetCorners(DtVector3< T > corners[8]) const
get the 8 corners
Definition DtAxisAlignedBoundingBox.inl:209
DtVector3< T > myVecSideVector
Definition DtCamera.h:102
const DtMatrix4< T > & ViewProjectionMatrix(void) const
concatenated matrix : projection * view
Definition DtCamera.inl:235
T farPlane(void) const
Definition DtCamera.inl:58
T myfAspectRatio
Definition DtCamera.h:107
DtVector3< T > position(void) const
Definition DtCamera.inl:83
const DtMatrix4< T > & ProjectionMatrix(void) const
Get the projection matrix specified above.
Definition DtCamera.inl:195
T nearPlane(void) const
Definition DtCamera.inl:45
bool isFixedUpVector(void) const
Definition DtCamera.inl:206
T fieldOfView(void) const
Definition DtCamera.inl:71
DtMatrix4< T > myViewMatrix
Definition DtCamera.h:109
DtVector3< T > myVecUpVector
Definition DtCamera.h:101
DtVector3< T > myVecDirection
Definition DtCamera.h:100
T myfFarPlane
Definition DtCamera.h:105
void setFieldOfView(T fFOVy)
This is the complete field of view in the Y direction. Not half.
Definition DtCamera.inl:64
DtVector3< T > myVecPosition
Definition DtCamera.h:99
DtVector3< T > upVector(void) const
Definition DtCamera.inl:101
virtual ~DtCamera()
DTOR.
Definition DtCamera.inl:32
DtVector3< T > sideVector(void) const
Definition DtCamera.inl:107
void updateFrustumPlanes(void)
Definition DtCamera.inl:218
bool mybFixedUpVector
Definition DtCamera.h:113
DtCamera()
CTOR.
Definition DtCamera.inl:18
DtPlane< T > myFrustumPlanes[6]
Definition DtCamera.h:115
VisibilityFromCamera getVisibility(const DtAxisAlignedBoundingBox< T > &box) const
Returns visibility from this camera?
Definition DtCamera.inl:278
bool IsVisible(const DtAxisAlignedBoundingBox< T > &box) const
Is a box visible from this camera?
Definition DtCamera.inl:241
void SetPerspective(T fFOVy, T fAspectRatio, T fNearPlane, T fFarPlane)
gluPerspective style setting of the projection matrix
Definition DtCamera.inl:170
void lookAt(const DtVector3< T > &vEye, const DtVector3< T > &vLook, const DtVector3< T > &vUp)
gluLookAt style setting of the view matrix
Definition DtCamera.inl:113
T aspectRatio(void) const
Get the aspect ratio.
Definition DtCamera.inl:212
void setPosition(const DtVector3< T > &vPosition)
Definition DtCamera.inl:77
void setFixedUpVector(bool fixed)
Definition DtCamera.inl:201
DtVector3< T > direction(void) const
Definition DtCamera.inl:95
T myfNearPlane
Definition DtCamera.h:104
void updateViewProjectionMatrix(void)
Definition DtCamera.inl:229
DtMatrix4< T > myProjectionMatrix
Definition DtCamera.h:110
const DtMatrix4< T > & ViewMatrix(void) const
Get the view matrix specified above.
Definition DtCamera.inl:164
DtMatrix4< T > myViewProjectionMatrix
Definition DtCamera.h:111
void setNearPlane(T fNearPlane)
Definition DtCamera.inl:38
void setFarPlane(T fFarPlane)
Definition DtCamera.inl:51
void setDirection(const DtVector3< T > &vDirection)
Definition DtCamera.inl:89
T myfFieldOfViewY
Definition DtCamera.h:106
DtScreenRect screenAABB(const DtAxisAlignedBoundingBox< T > &worldBox, const Vector2_uint32 &viewPortSize) const
Get the screen space bounds of a world box.
Definition DtCamera.inl:362
Math utilities.
Definition DtMath.h:54
static T clamp(T val, T minval, T maxval)
Clamping routines.
Definition DtMath.h:173
static T Tan(T val)
Definition DtMath.h:63
4 dimensional matrix
Definition DtMatrix4.h:23
DtMatrix4< T > getInverse(void) const
Get the inverse of this matrix.
Definition DtMatrix4.h:375
const DtVector4< T > transposeMultiply(const DtVector4< T > &rhs) const
This is equal to: this->GetTranspose() * rhs (but potentialy faster).
Definition DtMatrix4.h:253
DtPlane class.
Definition DtPlane.h:25
T d
Definition DtPlane.h:35
DtVector3< T > vNormal
Definition DtPlane.h:34
2 dimensional vector
Definition DtVector2.h:26
T y
Definition DtVector2.h:105
static const DtVector2 theZeroVector
Definition DtVector2.h:108
T x
Definition DtVector2.h:105
2 dimensional vector
Definition DtVector3.h:27
T length(void) const
get the length of this vector
Definition DtVector3.h:180
DtVector3 crossProduct(const DtVector3 &rhs) const
get the cross product of this vector and rhs
Definition DtVector3.h:255
T y
Definition DtVector3.h:135
T z
Definition DtVector3.h:135
T x
Definition DtVector3.h:135
T dotProduct(const DtVector3 &rhs) const
get the dot product of this vector and rhs
Definition DtVector3.h:268
void normalize(void)
normalize this vector in place
Definition DtVector3.h:167
4 dimensional vector
Definition DtVector4.h:28
T x
Definition DtVector4.h:118
T w
Definition DtVector4.h:118
T z
Definition DtVector4.h:118
T y
Definition DtVector4.h:118
Template for 32/64 bit bit frustums.
Definition DtCamera.h:160
virtual VisibilityFromCamera visibility(const DtAxisAlignedBoundingBox< T > &box, bool ignoreNearFar=false) const
get visibility of bounding box within the frustum
Definition DtCamera.inl:473
virtual const DtPlane< T > & plane(FrustumPlane plane) const
get a frustum plane
Definition DtCamera.inl:458
Frustum & operator=(const Frustum< RHS > &rhs)
Assignment Operator.
virtual bool operator==(const Frustum< T > &rhs) const
equality
Definition DtCamera.inl:757
virtual DtVector4< T > planeAsVector(FrustumPlane plane) const
get the frustum plane as a vector
Definition DtCamera.inl:464
virtual bool isVisible(const DtAxisAlignedBoundingBox< T > &box) const
is bounding box visible within this frustum?
Definition DtCamera.inl:519
Frustum()
ctor
Definition DtCamera.inl:423
virtual void setPlane(FrustumPlane plane, T d, const DtVector3< T > &vNormal)
set a frustum plane
Definition DtCamera.inl:450
virtual void frustumPlanes(std::array< DtVector4< T >, 6 > &planes) const
get the frustum planes as DtVector4's
Definition DtCamera.inl:742
std::array< DtPlane< T >, 6 > myFrustumPlanes
Definition DtCamera.h:220
virtual bool isSphereVisibleRadiusSquared(const DtVector3< T > &center, double radiusSquared) const
is bounding sphere (with a radius squared) visible within this frustum?
Definition DtCamera.inl:579
void computePlaneFromPoints(DtPlane< T > &plane, const DtVector3< T > &point0, const DtVector3< T > &point1, const DtVector3< T > &point2) const
Helper to compute a plane from 3 points.
Definition DtCamera.inl:601
virtual ~Frustum()
dtor
Definition DtCamera.inl:429
virtual bool operator!=(const Frustum< T > &rhs) const
inequality
Definition DtCamera.inl:772
virtual void setFromModelViewProjectionMatrix(const DtMatrix4< T > &modelViewMat, const DtMatrix4< T > &projMat)
Definition DtCamera.inl:620
virtual bool isSphereVisible(const DtVector3< T > &center, T radius) const
is bounding sphere visible within this frustum?
Definition DtCamera.inl:558
static DtScreenRect screenAABB(const DtAxisAlignedBoundingBox< T > &worldBox, const DtMatrix4< T > &view_projection_matrix, const Vector2_uint32 &viewPortSize, bool clip=true)
Definition DtCamera.inl:382
static DtVector2< T > project(const DtVector3< T > &vPosition, const DtMatrix4< T > &view_projection_matrix, bool clip=true)
Definition DtCamera.inl:329
Contains DtCreateSensorFieldOfViewCommand and DtCreateSensorFieldOfViewCommandCreator class declarati...
Definition DtGridLinesSettingsRecord.h:16
PlaneSide
Definition DtPlane.h:14
@ NEGATIVE_SIDE
Definition DtPlane.h:17
@ BOTH_SIDE
Definition DtPlane.h:18
unsigned int uint32
Definition DtCommonTypes.h:28
DtVector2< uint32 > Vector2_uint32
Definition DtVector2.h:274
FrustumPlane
Definition DtCamera.h:26
@ FRUSTUM_PLANE_RIGHT
Definition DtCamera.h:30
@ FRUSTUM_PLANE_TOP
Definition DtCamera.h:31
@ FRUSTUM_PLANE_NEAR
Definition DtCamera.h:27
@ FRUSTUM_PLANE_LEFT
Definition DtCamera.h:29
@ FRUSTUM_PLANE_FAR
Definition DtCamera.h:28
@ FRUSTUM_PLANE_BOTTOM
Definition DtCamera.h:32
double length(const dvec3 &theVec)
Definition DtVecUtils.h:20
const DtVector2< T > DtVector2< T >::theZeroVector
Definition DtVector2.h:113
DtVector2< int32 > Vector2_int
Definition DtVector2.h:273
VisibilityFromCamera
Definition DtCamera.h:36
@ VISIBILITY_PARTIAL
Definition DtCamera.h:37
@ VISIBILITY_FULL
Definition DtCamera.h:37
@ VISIBILITY_NONE
Definition DtCamera.h:37
Screen Space Rectangle class.
Definition DtScreenRect.h:22
Vector2_int vMax
Definition DtScreenRect.h:25
Vector2_int vMin
Definition DtScreenRect.h:24