00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _SB_VIEWVOLUME_
00026 #define _SB_VIEWVOLUME_
00027
00028 #include <Inventor/SbBase.h>
00029 #include <Inventor/SbVec.h>
00030 #include <Inventor/SbBox.h>
00031 #include <Inventor/SbPlane.h>
00032 #include <Inventor/SbRotation.h>
00033 #include <Inventor/STL/vector>
00034
00035 class SbLine;
00036 class SbMatrix;
00037 class SbPlane;
00038 class SbRotation;
00039 class SbVec2f;
00040 class SbVec3f;
00041
00042 class DebugDataSbVolIntersect;
00043 class HomTransfData;
00044
00046
00047
00048
00049
00050
00051
00052
00054
00055
00081 class SbViewVolume {
00082 public:
00083
00087 SbViewVolume();
00091 ~SbViewVolume() {}
00092
00103 float getMatrices(SbMatrix &affine, SbMatrix &proj) const;
00104
00116 SbMatrix getMatrix() const;
00117
00123 SbMatrix getCameraSpaceMatrix() const;
00124
00128 void projectPointToLine(const SbVec2f &pt, SbLine &line) const;
00129
00134 void projectPointToLine(const SbVec2f &pt,
00135 SbVec3f &line0,
00136 SbVec3f &line1) const;
00137
00155 void projectToScreen(const SbVec3f &src, SbVec3f &dst) const;
00156
00168 void projectFromScreen(const SbVec3f &src, SbVec3f &dst) const;
00169
00174 SbPlane getPlane(float distFromEye) const;
00175
00180 SbVec3f getSightPoint(float distFromEye) const;
00181
00187 SbVec3f getPlanePoint(float distFromEye,
00188 const SbVec2f &normPoint) const;
00189
00196 SbRotation getAlignRotation(SbBool rightAngleOnly = FALSE) const;
00197
00203 float getWorldToScreenScale(const SbVec3f &worldCenter,
00204 float normRadius) const;
00205
00210 SbVec2f projectBox(const SbBox3f &box) const;
00211
00216 SbBox3f getProjectedBbox(const SbBox3f &box) const;
00217
00222 SbBox3f getProjectedBbox(const SbMatrix& affineProj, const SbBox3f &box) const;
00223
00229 SbViewVolume narrow(float left, float bottom,
00230 float right, float top) const;
00231
00236 SbViewVolume narrow(const SbBox3f &box) const;
00237
00242 void ortho(float left, float right,
00243 float bottom, float top,
00244 float nearPlane, float farPlane);
00245
00251 void perspective(float fovy, float aspect,
00252 float nearPlane, float farPlane);
00253
00259 void rotateCamera(const SbRotation &q);
00260
00266 void translateCamera(const SbVec3f &v);
00267
00272 SbVec3f zVector() const;
00273
00280 SbViewVolume zNarrow(float nearPlane, float farPlane) const;
00281
00285 void scale(float factor);
00286
00292 void scaleWidth(float ratio);
00293
00299 void scaleHeight(float ratio);
00300
00304 enum ProjectionType {
00308 ORTHOGRAPHIC,
00312 PERSPECTIVE
00313 };
00314
00318 inline ProjectionType getProjectionType() const { return type; }
00319
00323 inline const SbVec3f &getProjectionPoint() const { return projPoint; }
00324
00328 inline const SbVec3f &getProjectionDirection() const { return projDir; }
00329
00333 inline float getNearDist() const { return nearDist; }
00334
00338 inline float getWidth() const { return (lrfO-llfO).length(); }
00339
00343 inline float getHeight() const { return (ulfO-llfO).length(); }
00344
00348 inline float getDepth() const { return nearToFar; }
00349
00388 void setStereoAbsoluteAdjustments(SbBool absolute);
00389
00393 SbBool isStereoAbsoluteAdjustments() const;
00394
00400 void setStereoAdjustment(float adjustment);
00401
00405 float getStereoAdjustment() const;
00406
00421 void setBalanceAdjustment(float adjustment, SbBool nearFrac = false);
00422
00426 float getBalanceAdjustment() const;
00427
00432 SbBool isBalanceNearFraction() const;
00433
00437 enum StereoMode {
00441 MONOSCOPIC,
00445 LEFT_VIEW,
00449 RIGHT_VIEW
00450 } ;
00451
00455 inline void setStereoMode(StereoMode mode) { stereoMode = mode ; }
00456
00460 inline StereoMode getStereoMode() const { return stereoMode ; }
00461
00465 SbBool equals(const SbViewVolume &v, float tolerance);
00466
00467 private:
00468 ProjectionType type;
00469
00470
00471
00472 SbVec3f projPoint;
00473 SbVec3f projDir;
00474 float nearDist;
00475 float nearToFar;
00476 SbVec3f llf;
00477 SbVec3f lrf;
00478 SbVec3f ulf;
00479
00480
00481 SbVec3f llfO;
00482 SbVec3f lrfO;
00483 SbVec3f ulfO;
00484
00485
00486
00487 void frustum( float left, float right, float bottom,
00488 float top, float near_plane, float far_plane );
00489
00490 void frustumWorldCoords( const SbVec3f &projPt, const SbVec3f &projDire,
00491 float radius, float near_plane, float far_plane, bool forceNearPlane = false );
00492
00493
00494
00495
00496
00497 void transform( const SbMatrix &matrix);
00498
00499
00500 SbBool intersect( const SbVec3f &point) const;
00501
00502
00503 SbBool intersect( const SbVec3f &point, HomTransfData *pHomTData ) const;
00504
00505
00506
00507
00508 SbBool intersectOld( const SbVec3f &p0,
00509 const SbVec3f &p1,
00510 HomTransfData *pHomTData,
00511 SbVec3f &closestPoint,
00512 DebugDataSbVolIntersect *pdd = 0 ) const;
00513
00514
00515
00516
00517 SbBool intersect(const SbVec3f &p0,
00518 const SbVec3f &p1,
00519 HomTransfData *pHomTData,
00520 SbVec3f &closestPoint,
00521 DebugDataSbVolIntersect *pdd = 0 ) const;
00522
00523
00524
00525
00526 SbBool intersect( const SbVec3f &v0, const SbVec3f &v1, const SbVec3f &v2,
00527 HomTransfData *pHomTData,
00528 SbVec3f &intersection,
00529 SbVec3f &barycentric, SbBool &front,
00530 DebugDataSbVolIntersect *pdd = 0) const;
00531
00532
00533 inline SbBool intersect( const SbBox3f &box) const
00534 {
00535 SbXfBox3f xbox(box);
00536 return intersect(xbox);
00537 }
00538
00539
00540 SbBool intersect( const SbXfBox3f &box) const;
00541
00549 void clipFrustum(const SbXfBox3d& box, std::vector<SbVec3d>& points) const;
00550
00551
00552
00553 SbBool outsideTest( const SbPlane &p,
00554 const SbVec3f &min, const SbVec3f &max) const;
00555
00556 void setCameraOffset(float);
00557 float getCameraOffset(void) const;
00558 void unsetCameraOffset(void);
00559 int isCameraOffsetSet(void) const;
00560
00561 void setClipToFar(SbBool clipToFar);
00562 void setClipToNear(SbBool clipToNear);
00563
00564 inline const SbBox3f& getFrustumBbox() const;
00565
00567 SbBox3f getRestrictedBbox(float visibilityLength) const ;
00568
00569 SbVec3f getllf() const { return llf; }
00570
00571 SbBool checkRadialDistance( const SbVec3f & pt, float radius ) const;
00572
00573 SbMatrix getAllMatrices( SbMatrix &affine, SbMatrix &proj ) const;
00574
00575 private:
00576
00577
00578
00579
00580 SbBool intersect1( const SbVec3f &v0, const SbVec3f &v1, const SbVec3f &v2,
00581 HomTransfData *pHomTData,
00582 SbVec3f &intersection,
00583 SbVec3f &barycentric, SbBool &front,
00584 DebugDataSbVolIntersect *pdd = 0) const;
00585
00586 SbBool intersect2( const SbVec3f &v0, const SbVec3f &v1, const SbVec3f &v2,
00587 HomTransfData *pHomTData,
00588 SbVec3f &intersection,
00589 SbVec3f &barycentric, SbBool &front,
00590 DebugDataSbVolIntersect *pdd = 0) const;
00591
00592 SbBox3f m_frustumBbox;
00593
00594 SbBool stereoAbsoluteAdjustments;
00595 float stereoAdjustment, balanceAdjustment;
00596 StereoMode stereoMode;
00597 bool stereoNearFrac;
00598
00599 float mPStereoCameraOffset;
00600 int mPStereoOffsetSet;
00601
00602 SbBool m_bClipToNear, m_bClipToFar;
00603 };
00604
00605
00606 inline void
00607 SbViewVolume::setClipToFar(SbBool clipToFar)
00608 {
00609 m_bClipToFar = clipToFar;
00610 }
00611
00612 inline void
00613 SbViewVolume::setClipToNear(SbBool clipToNear)
00614 {
00615 m_bClipToNear = clipToNear;
00616 }
00617
00618 inline SbBool
00619 SbViewVolume::isStereoAbsoluteAdjustments() const
00620 {
00621 return stereoAbsoluteAdjustments;
00622 }
00623
00624 inline void
00625 SbViewVolume::setStereoAdjustment(float adjustment)
00626 {
00627 stereoAdjustment = adjustment;
00628 }
00629
00630 inline float
00631 SbViewVolume::getStereoAdjustment() const
00632 {
00633 return stereoAdjustment;
00634 }
00635
00636 inline void
00637 SbViewVolume::setBalanceAdjustment(float adjustment, SbBool nearFrac)
00638 {
00639 balanceAdjustment = adjustment;
00640 stereoNearFrac = (nearFrac!=FALSE);
00641 }
00642
00643 inline float
00644 SbViewVolume::getBalanceAdjustment() const
00645 {
00646 return balanceAdjustment;
00647 }
00648
00649 inline SbBool
00650 SbViewVolume::isBalanceNearFraction() const
00651 {
00652 return stereoNearFrac;
00653 }
00654
00655 inline void
00656 SbViewVolume::setStereoAbsoluteAdjustments(SbBool absolute)
00657 {
00658 stereoAbsoluteAdjustments = absolute;
00659 }
00660
00661 const SbBox3f&
00662 SbViewVolume::getFrustumBbox() const
00663 {
00664 return m_frustumBbox;
00665 }
00666
00667 #endif
00668
00669
00670