1 // Created on: 2015-06-18
2 // Created by: Anton POLETAEV
3 // Copyright (c) 2015 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _Graphic3d_TransformPers_HeaderFile
17 #define _Graphic3d_TransformPers_HeaderFile
19 #include <Aspect_TypeOfTriedronPosition.hxx>
20 #include <Bnd_Box.hxx>
21 #include <BVH_Box.hxx>
22 #include <Graphic3d_Camera.hxx>
23 #include <Graphic3d_TransformUtils.hxx>
24 #include <Graphic3d_TransModeFlags.hxx>
25 #include <Graphic3d_Vec.hxx>
26 #include <NCollection_Mat4.hxx>
28 DEFINE_STANDARD_HANDLE(Graphic3d_TransformPers, Standard_Transient)
30 //! Transformation Persistence definition.
32 //! Transformation Persistence defines a mutable Local Coordinate system which depends on camera position,
33 //! so that visual appearance of the object becomes partially immutable while camera moves.
34 //! Object visually preserves particular property such as size, placement, rotation or their combination.
36 //! Graphic3d_TMF_ZoomPers, Graphic3d_TMF_RotatePers and Graphic3d_TMF_ZoomRotatePers define Local Coordinate system
37 //! having origin in specified anchor point defined in World Coordinate system,
38 //! while Graphic3d_TMF_TriedronPers and Graphic3d_TMF_2d define origin as 2D offset from screen corner in pixels.
40 //! Graphic3d_TMF_2d, Graphic3d_TMF_TriedronPers and Graphic3d_TMF_ZoomPers defines Local Coordinate system where length units are pixels.
41 //! Beware that Graphic3d_RenderingParams::ResolutionRatio() will be ignored!
42 //! For other Persistence flags, normal (world) length units will apply.
44 //! WARNING: Graphic3d_TMF_None is not permitted for defining instance of this class - NULL handle should be used for this purpose!
45 class Graphic3d_TransformPers : public Standard_Transient
47 DEFINE_STANDARD_RTTIEXT(Graphic3d_TransformPers, Standard_Transient)
50 //! Return true if specified mode is zoom/rotate transformation persistence.
51 static Standard_Boolean IsZoomOrRotate (Graphic3d_TransModeFlags theMode)
53 return (theMode & (Graphic3d_TMF_ZoomPers | Graphic3d_TMF_RotatePers)) != 0;
56 //! Return true if specified mode is 2d/trihedron transformation persistence.
57 static Standard_Boolean IsTrihedronOr2d (Graphic3d_TransModeFlags theMode)
59 return (theMode & (Graphic3d_TMF_TriedronPers | Graphic3d_TMF_2d)) != 0;
64 //! Set transformation persistence.
65 Graphic3d_TransformPers (const Graphic3d_TransModeFlags theMode)
68 if (IsZoomOrRotate (theMode))
70 SetPersistence (theMode, gp_Pnt(0.0, 0.0, 0.0));
72 else if (IsTrihedronOr2d (theMode))
74 SetPersistence (theMode, Aspect_TOTP_LEFT_LOWER, Graphic3d_Vec2i (0, 0));
76 else if (theMode == Graphic3d_TMF_CameraPers)
82 throw Standard_ProgramError("Graphic3d_TransformPers::SetPersistence(), wrong persistence mode.");
86 //! Set Zoom/Rotate transformation persistence with an anchor 3D point.
87 //! Anchor point defines the origin of Local Coordinate system within World Coordinate system.
88 //! Throws an exception if persistence mode is not Graphic3d_TMF_ZoomPers, Graphic3d_TMF_ZoomRotatePers or Graphic3d_TMF_RotatePers.
89 Graphic3d_TransformPers (const Graphic3d_TransModeFlags theMode,
91 : myMode (Graphic3d_TMF_None)
93 SetPersistence (theMode, thePnt);
96 //! Set 2d/trihedron transformation persistence with a corner and 2D offset.
97 //! 2D offset defines the origin of Local Coordinate system as projection of 2D point on screen plane into World Coordinate system.
98 //! Throws an exception if persistence mode is not Graphic3d_TMF_TriedronPers or Graphic3d_TMF_2d.
99 //! The offset is a positive displacement from the view corner in pixels.
100 Graphic3d_TransformPers (const Graphic3d_TransModeFlags theMode,
101 const Aspect_TypeOfTriedronPosition theCorner,
102 const Graphic3d_Vec2i& theOffset = Graphic3d_Vec2i (0, 0))
103 : myMode (Graphic3d_TMF_None)
105 SetPersistence (theMode, theCorner, theOffset);
108 //! Return true for Graphic3d_TMF_ZoomPers, Graphic3d_TMF_ZoomRotatePers or Graphic3d_TMF_RotatePers modes.
109 Standard_Boolean IsZoomOrRotate() const { return IsZoomOrRotate (myMode); }
111 //! Return true for Graphic3d_TMF_TriedronPers and Graphic3d_TMF_2d modes.
112 Standard_Boolean IsTrihedronOr2d() const { return IsTrihedronOr2d (myMode); }
114 //! Transformation persistence mode flags.
115 Graphic3d_TransModeFlags Mode() const { return myMode; }
117 //! Transformation persistence mode flags.
118 Graphic3d_TransModeFlags Flags() const { return myMode; }
120 //! Set Zoom/Rotate transformation persistence with an anchor 3D point.
121 //! Throws an exception if persistence mode is not Graphic3d_TMF_ZoomPers, Graphic3d_TMF_ZoomRotatePers or Graphic3d_TMF_RotatePers.
122 void SetPersistence (const Graphic3d_TransModeFlags theMode,
123 const gp_Pnt& thePnt)
125 if (!IsZoomOrRotate (theMode))
127 throw Standard_ProgramError("Graphic3d_TransformPers::SetPersistence(), wrong persistence mode.");
131 myParams.Params3d.PntX = thePnt.X();
132 myParams.Params3d.PntY = thePnt.Y();
133 myParams.Params3d.PntZ = thePnt.Z();
136 //! Set 2d/trihedron transformation persistence with a corner and 2D offset.
137 //! Throws an exception if persistence mode is not Graphic3d_TMF_TriedronPers or Graphic3d_TMF_2d.
138 void SetPersistence (const Graphic3d_TransModeFlags theMode,
139 const Aspect_TypeOfTriedronPosition theCorner,
140 const Graphic3d_Vec2i& theOffset)
142 if (!IsTrihedronOr2d (theMode))
144 throw Standard_ProgramError("Graphic3d_TransformPers::SetPersistence(), wrong persistence mode.");
148 myParams.Params2d.Corner = theCorner;
149 myParams.Params2d.OffsetX = theOffset.x();
150 myParams.Params2d.OffsetY = theOffset.y();
155 //! Return the anchor point for zoom/rotate transformation persistence.
156 gp_Pnt AnchorPoint() const
158 if (!IsZoomOrRotate())
160 throw Standard_ProgramError("Graphic3d_TransformPers::AnchorPoint(), wrong persistence mode.");
163 return gp_Pnt (myParams.Params3d.PntX, myParams.Params3d.PntY, myParams.Params3d.PntZ);
166 //! Set the anchor point for zoom/rotate transformation persistence.
167 void SetAnchorPoint (const gp_Pnt& thePnt)
169 if (!IsZoomOrRotate())
171 throw Standard_ProgramError("Graphic3d_TransformPers::SetAnchorPoint(), wrong persistence mode.");
174 myParams.Params3d.PntX = thePnt.X();
175 myParams.Params3d.PntY = thePnt.Y();
176 myParams.Params3d.PntZ = thePnt.Z();
179 //! Return the corner for 2d/trihedron transformation persistence.
180 Aspect_TypeOfTriedronPosition Corner2d() const
182 if (!IsTrihedronOr2d())
184 throw Standard_ProgramError("Graphic3d_TransformPers::Corner2d(), wrong persistence mode.");
187 return myParams.Params2d.Corner;
190 //! Set the corner for 2d/trihedron transformation persistence.
191 void SetCorner2d (const Aspect_TypeOfTriedronPosition thePos)
193 if (!IsTrihedronOr2d())
195 throw Standard_ProgramError("Graphic3d_TransformPers::SetCorner2d(), wrong persistence mode.");
198 myParams.Params2d.Corner = thePos;
201 //! Return the offset from the corner for 2d/trihedron transformation persistence.
202 Graphic3d_Vec2i Offset2d() const
204 if (!IsTrihedronOr2d())
206 throw Standard_ProgramError("Graphic3d_TransformPers::Offset2d(), wrong persistence mode.");
209 return Graphic3d_Vec2i (myParams.Params2d.OffsetX, myParams.Params2d.OffsetY);
212 //! Set the offset from the corner for 2d/trihedron transformation persistence.
213 void SetOffset2d (const Graphic3d_Vec2i& theOffset)
215 if (!IsTrihedronOr2d())
217 throw Standard_ProgramError("Graphic3d_TransformPers::SetOffset2d(), wrong persistence mode.");
220 myParams.Params2d.OffsetX = theOffset.x();
221 myParams.Params2d.OffsetY = theOffset.y();
226 //! Find scale value based on the camera position and view dimensions
227 //! @param theCamera [in] camera definition
228 //! @param theViewportWidth [in] the width of viewport.
229 //! @param theViewportHeight [in] the height of viewport.
230 virtual Standard_Real persistentScale (const Handle(Graphic3d_Camera)& theCamera,
231 const Standard_Integer /*theViewportWidth*/,
232 const Standard_Integer theViewportHeight) const
234 // use total size when tiling is active
235 const Standard_Integer aVPSizeY = theCamera->Tile().IsValid() ? theCamera->Tile().TotalSize.y() : theViewportHeight;
237 gp_Vec aVecToEye (theCamera->Direction());
238 gp_Vec aVecToObj (theCamera->Eye(), gp_Pnt (myParams.Params3d.PntX, myParams.Params3d.PntY, myParams.Params3d.PntZ));
239 const Standard_Real aFocus = aVecToObj.Dot (aVecToEye);
240 const gp_XYZ aViewDim = theCamera->ViewDimensions (aFocus);
241 return Abs(aViewDim.Y()) / Standard_Real(aVPSizeY);
244 //! Apply transformation to bounding box of presentation.
245 //! @param theCamera [in] camera definition
246 //! @param theProjection [in] the projection transformation matrix.
247 //! @param theWorldView [in] the world view transformation matrix.
248 //! @param theViewportWidth [in] the width of viewport (for 2d persistence).
249 //! @param theViewportHeight [in] the height of viewport (for 2d persistence).
250 //! @param theBoundingBox [in/out] the bounding box to transform.
252 void Apply (const Handle(Graphic3d_Camera)& theCamera,
253 const NCollection_Mat4<T>& theProjection,
254 const NCollection_Mat4<T>& theWorldView,
255 const Standard_Integer theViewportWidth,
256 const Standard_Integer theViewportHeight,
257 Bnd_Box& theBoundingBox) const;
259 //! Apply transformation to bounding box of presentation
260 //! @param theCamera [in] camera definition
261 //! @param theProjection [in] the projection transformation matrix.
262 //! @param theWorldView [in] the world view transformation matrix.
263 //! @param theViewportWidth [in] the width of viewport (for 2d persistence).
264 //! @param theViewportHeight [in] the height of viewport (for 2d persistence).
265 //! @param theBoundingBox [in/out] the bounding box to transform.
267 void Apply (const Handle(Graphic3d_Camera)& theCamera,
268 const NCollection_Mat4<T>& theProjection,
269 const NCollection_Mat4<T>& theWorldView,
270 const Standard_Integer theViewportWidth,
271 const Standard_Integer theViewportHeight,
272 BVH_Box<T, 3>& theBoundingBox) const;
274 //! Compute transformation.
275 //! Computed matrix can be applied to model world transformation
276 //! of an object to implement effect of transformation persistence.
277 //! @param theCamera [in] camera definition
278 //! @param theProjection [in] the projection transformation matrix.
279 //! @param theWorldView [in] the world view transformation matrix.
280 //! @param theViewportWidth [in] the width of viewport (for 2d persistence).
281 //! @param theViewportHeight [in] the height of viewport (for 2d persistence).
282 //! @return transformation matrix to be applied to model world transformation of an object.
284 NCollection_Mat4<T> Compute (const Handle(Graphic3d_Camera)& theCamera,
285 const NCollection_Mat4<T>& theProjection,
286 const NCollection_Mat4<T>& theWorldView,
287 const Standard_Integer theViewportWidth,
288 const Standard_Integer theViewportHeight) const;
290 //! Apply transformation persistence on specified matrices.
291 //! @param theCamera camera definition
292 //! @param theProjection projection matrix to modify
293 //! @param theWorldView world-view matrix to modify
294 //! @param theViewportWidth viewport width
295 //! @param theViewportHeight viewport height
297 void Apply (const Handle(Graphic3d_Camera)& theCamera,
298 const NCollection_Mat4<T>& theProjection,
299 NCollection_Mat4<T>& theWorldView,
300 const Standard_Integer theViewportWidth,
301 const Standard_Integer theViewportHeight) const;
303 //! Dumps the content of me into the stream
304 Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
308 //! 3D anchor point for zoom/rotate transformation persistence.
315 //! Dumps the content of me into the stream
316 Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
319 //! 2d/trihedron transformation persistence parameters.
322 Standard_Integer OffsetX;
323 Standard_Integer OffsetY;
324 Aspect_TypeOfTriedronPosition Corner;
326 //! Dumps the content of me into the stream
327 Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
332 Graphic3d_TransModeFlags myMode; //!< Transformation persistence mode flags
335 PersParams3d Params3d;
336 PersParams2d Params2d;
341 // =======================================================================
343 // purpose : Apply transformation to world view and projection matrices.
344 // =======================================================================
346 void Graphic3d_TransformPers::Apply (const Handle(Graphic3d_Camera)& theCamera,
347 const NCollection_Mat4<T>& theProjection,
348 NCollection_Mat4<T>& theWorldView,
349 const Standard_Integer theViewportWidth,
350 const Standard_Integer theViewportHeight) const
352 (void )theViewportWidth;
353 (void )theProjection;
354 if (myMode == Graphic3d_TMF_None
355 || theViewportHeight == 0)
360 // use total size when tiling is active
361 const Standard_Integer aVPSizeY = theCamera->Tile().IsValid() ? theCamera->Tile().TotalSize.y() : theViewportHeight;
363 // a small enough jitter compensation offset
364 // to avoid image dragging within single pixel in corner cases
365 const Standard_Real aJitterComp = 0.001;
366 if (myMode == Graphic3d_TMF_TriedronPers)
368 // reset Z focus for trihedron persistence
369 const Standard_Real aFocus = theCamera->IsOrthographic()
370 ? theCamera->Distance()
371 : (theCamera->ZFocusType() == Graphic3d_Camera::FocusType_Relative
372 ? Standard_Real(theCamera->ZFocus() * theCamera->Distance())
373 : Standard_Real(theCamera->ZFocus()));
375 // scale factor to pixels
376 const gp_XYZ aViewDim = theCamera->ViewDimensions (aFocus);
377 const Standard_Real aScale = Abs(aViewDim.Y()) / Standard_Real(aVPSizeY);
378 const gp_Dir aForward = theCamera->Direction();
379 gp_XYZ aCenter = theCamera->Center().XYZ() + aForward.XYZ() * (aFocus - theCamera->Distance());
380 if ((myParams.Params2d.Corner & (Aspect_TOTP_LEFT | Aspect_TOTP_RIGHT)) != 0)
382 const Standard_Real anOffsetX = (Standard_Real(myParams.Params2d.OffsetX) + aJitterComp) * aScale;
383 const gp_Dir aSide = aForward.Crossed (theCamera->Up());
384 const gp_XYZ aDeltaX = aSide.XYZ() * (Abs(aViewDim.X()) * theCamera->NDC2dOffsetX() - anOffsetX);
385 if ((myParams.Params2d.Corner & Aspect_TOTP_RIGHT) != 0)
394 if ((myParams.Params2d.Corner & (Aspect_TOTP_TOP | Aspect_TOTP_BOTTOM)) != 0)
396 const Standard_Real anOffsetY = (Standard_Real(myParams.Params2d.OffsetY) + aJitterComp) * aScale;
397 const gp_XYZ aDeltaY = theCamera->Up().XYZ() * (Abs(aViewDim.Y()) * theCamera->NDC2dOffsetY() - anOffsetY);
398 if ((myParams.Params2d.Corner & Aspect_TOTP_TOP) != 0)
408 NCollection_Mat4<Standard_Real> aWorldView = theCamera->OrientationMatrix();
409 Graphic3d_TransformUtils::Translate (aWorldView, aCenter.X(), aCenter.Y(), aCenter.Z());
410 Graphic3d_TransformUtils::Scale (aWorldView, aScale, aScale, aScale);
411 theWorldView.ConvertFrom (aWorldView);
414 else if (myMode == Graphic3d_TMF_2d)
416 const Standard_Real aFocus = theCamera->IsOrthographic()
417 ? theCamera->Distance()
418 : (theCamera->ZFocusType() == Graphic3d_Camera::FocusType_Relative
419 ? Standard_Real(theCamera->ZFocus() * theCamera->Distance())
420 : Standard_Real(theCamera->ZFocus()));
422 // scale factor to pixels
423 const gp_XYZ aViewDim = theCamera->ViewDimensions (aFocus);
424 const Standard_Real aScale = Abs(aViewDim.Y()) / Standard_Real(aVPSizeY);
425 gp_XYZ aCenter (0.0, 0.0, -aFocus);
426 if ((myParams.Params2d.Corner & (Aspect_TOTP_LEFT | Aspect_TOTP_RIGHT)) != 0)
428 aCenter.SetX (-aViewDim.X() * theCamera->NDC2dOffsetX() + (Standard_Real(myParams.Params2d.OffsetX) + aJitterComp) * aScale);
429 if ((myParams.Params2d.Corner & Aspect_TOTP_RIGHT) != 0)
431 aCenter.SetX (-aCenter.X());
434 if ((myParams.Params2d.Corner & (Aspect_TOTP_TOP | Aspect_TOTP_BOTTOM)) != 0)
436 aCenter.SetY (-aViewDim.Y() * theCamera->NDC2dOffsetY() + (Standard_Real(myParams.Params2d.OffsetY) + aJitterComp) * aScale);
437 if ((myParams.Params2d.Corner & Aspect_TOTP_TOP) != 0)
439 aCenter.SetY (-aCenter.Y());
443 theWorldView.InitIdentity();
444 Graphic3d_TransformUtils::Translate (theWorldView, T(aCenter.X()), T(aCenter.Y()), T(aCenter.Z()));
445 Graphic3d_TransformUtils::Scale (theWorldView, T(aScale), T(aScale), T(aScale));
448 else if ((myMode & Graphic3d_TMF_CameraPers) != 0)
450 theWorldView.InitIdentity();
454 // Compute reference point for transformation in untransformed projection space.
455 NCollection_Mat4<Standard_Real> aWorldView = theCamera->OrientationMatrix();
456 Graphic3d_TransformUtils::Translate (aWorldView, myParams.Params3d.PntX, myParams.Params3d.PntY, myParams.Params3d.PntZ);
457 if ((myMode & Graphic3d_TMF_RotatePers) != 0)
459 // lock rotation by nullifying rotation component
460 aWorldView.SetValue (0, 0, 1.0);
461 aWorldView.SetValue (1, 0, 0.0);
462 aWorldView.SetValue (2, 0, 0.0);
464 aWorldView.SetValue (0, 1, 0.0);
465 aWorldView.SetValue (1, 1, 1.0);
466 aWorldView.SetValue (2, 1, 0.0);
468 aWorldView.SetValue (0, 2, 0.0);
469 aWorldView.SetValue (1, 2, 0.0);
470 aWorldView.SetValue (2, 2, 1.0);
473 if ((myMode & Graphic3d_TMF_ZoomPers) != 0)
476 Standard_Real aScale = persistentScale (theCamera, theViewportWidth, theViewportHeight);
477 Graphic3d_TransformUtils::Scale (aWorldView, aScale, aScale, aScale);
479 theWorldView.ConvertFrom (aWorldView);
484 // =======================================================================
486 // purpose : Apply transformation to bounding box of presentation.
487 // =======================================================================
489 void Graphic3d_TransformPers::Apply (const Handle(Graphic3d_Camera)& theCamera,
490 const NCollection_Mat4<T>& theProjection,
491 const NCollection_Mat4<T>& theWorldView,
492 const Standard_Integer theViewportWidth,
493 const Standard_Integer theViewportHeight,
494 Bnd_Box& theBoundingBox) const
496 if (theBoundingBox.IsVoid())
501 T aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
503 theBoundingBox.Get (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
505 typename BVH_Box<T, 3>::BVH_VecNt aMin (aXmin, aYmin, aZmin);
506 typename BVH_Box<T, 3>::BVH_VecNt aMax (aXmax, aYmax, aZmax);
507 BVH_Box<T, 3> aBBox (aMin, aMax);
509 Apply (theCamera, theProjection, theWorldView, theViewportWidth, theViewportHeight, aBBox);
511 theBoundingBox = Bnd_Box();
512 theBoundingBox.Update (aBBox.CornerMin().x(), aBBox.CornerMin().y(), aBBox.CornerMin().z(),
513 aBBox.CornerMax().x(), aBBox.CornerMax().y(), aBBox.CornerMax().z());
516 // =======================================================================
518 // purpose : Apply transformation to bounding box of presentation.
519 // =======================================================================
521 void Graphic3d_TransformPers::Apply (const Handle(Graphic3d_Camera)& theCamera,
522 const NCollection_Mat4<T>& theProjection,
523 const NCollection_Mat4<T>& theWorldView,
524 const Standard_Integer theViewportWidth,
525 const Standard_Integer theViewportHeight,
526 BVH_Box<T, 3>& theBoundingBox) const
528 NCollection_Mat4<T> aTPers = Compute (theCamera, theProjection, theWorldView, theViewportWidth, theViewportHeight);
529 if (aTPers.IsIdentity()
530 || !theBoundingBox.IsValid())
535 const typename BVH_Box<T, 3>::BVH_VecNt& aMin = theBoundingBox.CornerMin();
536 const typename BVH_Box<T, 3>::BVH_VecNt& aMax = theBoundingBox.CornerMax();
538 typename BVH_Box<T, 4>::BVH_VecNt anArrayOfCorners[8];
539 anArrayOfCorners[0] = typename BVH_Box<T, 4>::BVH_VecNt (aMin.x(), aMin.y(), aMin.z(), static_cast<T> (1.0));
540 anArrayOfCorners[1] = typename BVH_Box<T, 4>::BVH_VecNt (aMin.x(), aMin.y(), aMax.z(), static_cast<T> (1.0));
541 anArrayOfCorners[2] = typename BVH_Box<T, 4>::BVH_VecNt (aMin.x(), aMax.y(), aMin.z(), static_cast<T> (1.0));
542 anArrayOfCorners[3] = typename BVH_Box<T, 4>::BVH_VecNt (aMin.x(), aMax.y(), aMax.z(), static_cast<T> (1.0));
543 anArrayOfCorners[4] = typename BVH_Box<T, 4>::BVH_VecNt (aMax.x(), aMin.y(), aMin.z(), static_cast<T> (1.0));
544 anArrayOfCorners[5] = typename BVH_Box<T, 4>::BVH_VecNt (aMax.x(), aMin.y(), aMax.z(), static_cast<T> (1.0));
545 anArrayOfCorners[6] = typename BVH_Box<T, 4>::BVH_VecNt (aMax.x(), aMax.y(), aMin.z(), static_cast<T> (1.0));
546 anArrayOfCorners[7] = typename BVH_Box<T, 4>::BVH_VecNt (aMax.x(), aMax.y(), aMax.z(), static_cast<T> (1.0));
548 theBoundingBox.Clear();
549 for (Standard_Integer anIt = 0; anIt < 8; ++anIt)
551 typename BVH_Box<T, 4>::BVH_VecNt& aCorner = anArrayOfCorners[anIt];
552 aCorner = aTPers * aCorner;
553 aCorner = aCorner / aCorner.w();
554 theBoundingBox.Add (typename BVH_Box<T, 3>::BVH_VecNt (aCorner.x(), aCorner.y(), aCorner.z()));
558 // =======================================================================
559 // function : Compute
560 // purpose : Compute transformation.
561 // =======================================================================
563 NCollection_Mat4<T> Graphic3d_TransformPers::Compute (const Handle(Graphic3d_Camera)& theCamera,
564 const NCollection_Mat4<T>& theProjection,
565 const NCollection_Mat4<T>& theWorldView,
566 const Standard_Integer theViewportWidth,
567 const Standard_Integer theViewportHeight) const
569 if (myMode == Graphic3d_TMF_None)
571 return NCollection_Mat4<T>();
574 NCollection_Mat4<T> aWorldView (theWorldView);
575 NCollection_Mat4<T> anUnviewMat;
576 if (!theWorldView.Inverted (anUnviewMat))
578 return NCollection_Mat4<T>();
581 // compute only world-view matrix difference to avoid floating point instability
582 // caused by projection matrix modifications outside of this algorithm (e.g. by Z-fit)
583 Apply (theCamera, theProjection, aWorldView, theViewportWidth, theViewportHeight);
584 return anUnviewMat * aWorldView;
587 #endif // _Graphic3d_TransformPers_HeaderFile