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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #ifndef _SO_CAMERA_
00051 #define _SO_CAMERA_
00052
00053 #include <Inventor/SbBox.h>
00054 #include <Inventor/SbViewportRegion.h>
00055 #include <Inventor/nodes/SoNode.h>
00056 #include <Inventor/fields/SoSFFloat.h>
00057 #include <Inventor/fields/SoSFRotation.h>
00058 #include <Inventor/fields/SoSFVec3f.h>
00059 #include <Inventor/fields/SoSFEnum.h>
00060
00061 #ifdef _WIN32
00062 #pragma warning(push)
00063 #pragma warning(disable:4251)
00064 #endif
00065
00066 class SbViewportRegion;
00067 class SoState;
00068
00069
00070
00071
00072 class SoCamera ;
00073 typedef void SoCameraCB( SoCamera *camera, SoGLRenderAction* action );
00074
00076
00077
00078
00079
00080
00082
00186 class SoCamera : public SoNode {
00187
00188 SO_NODE_ABSTRACT_HEADER(SoCamera);
00189
00190 public:
00192 enum ViewportMapping {
00198 CROP_VIEWPORT_FILL_FRAME = 0,
00202 CROP_VIEWPORT_LINE_FRAME = 1,
00207 CROP_VIEWPORT_NO_FRAME = 2,
00208
00214 ADJUST_CAMERA = 3,
00218 LEAVE_ALONE = 4
00219 };
00220
00221
00222
00223
00224
00225
00226
00232 SoSFEnum viewportMapping;
00237 SoSFVec3f position;
00243 SoSFRotation orientation;
00249 SoSFFloat aspectRatio;
00254 SoSFFloat nearDistance;
00259 SoSFFloat farDistance;
00266 SoSFFloat focalDistance;
00267
00273 void pointAt(const SbVec3f &targetPoint);
00274
00280 virtual void scaleHeight(float scaleFactor) = 0;
00281
00343 virtual SbViewVolume getViewVolume(float useAspectRatio = 0.0) const = 0;
00344
00345
00370 void viewAll(SoNode *sceneRoot,
00371 const SbViewportRegion &vpRegion,
00372 float slack = 1.0);
00381 void viewAll(SoPath *path,
00382 const SbViewportRegion &vpRegion,
00383 float slack = 1.0);
00384
00392 void viewAll(const SbBox3f& bbox,
00393 const SbViewportRegion &vpRegion);
00394
00399 SbViewportRegion getViewportBounds(const SbViewportRegion ®ion) const;
00400
00401 #if 1 SoDEPRECATED
00409 virtual void setStereoAdjustment(float adjustment);
00410 SoDEPRECATED
00415 float getStereoAdjustment() const
00416 { return _stereoAdjustment ; }
00417 SoDEPRECATED
00459 virtual void setStereoAbsoluteAdjustments( SbBool absolute );
00460 SoDEPRECATED
00465 SbBool getStereoAbsoluteAdjustment() const
00466 { return _stereoAbsoluteAdjustments ; }
00467 SoDEPRECATED
00483 virtual void setBalanceAdjustment(float adjustment, SbBool nearFrac = false);
00484 SoDEPRECATED
00489 float getBalanceAdjustment() const
00490 { return _balanceAdjustment; }
00491 SoDEPRECATED
00497 SbBool isBalanceAdjustmentNearFrac() const
00498 { return _balanceNearFrac; }
00499 SoDEPRECATED
00504 virtual void allowStereo(SbBool);
00505
00506 #endif
00509 enum StereoMode {
00510
00513 MONOSCOPIC,
00517 LEFT_VIEW,
00521 RIGHT_VIEW
00522 };
00523
00530 void setStereoMode(StereoMode mode);
00531
00535 StereoMode getStereoMode() const;
00536
00537 private:
00538 virtual void doAction(SoAction *action);
00539 virtual void callback(SoCallbackAction *action);
00540 virtual void GLRender(SoGLRenderAction *action);
00541 virtual void getBoundingBox(SoGetBoundingBoxAction *action);
00542 virtual void handleEvent(SoHandleEventAction *action);
00543 virtual void rayPick(SoRayPickAction *action);
00544 virtual void getPrimitiveCount(SoGetPrimitiveCountAction *action);
00545
00546 private:
00547 static void initClass();
00548 static void exitClass();
00549
00550
00551 static void setPostCallback( SoCameraCB *f ) ;
00552
00557 virtual SbViewVolume getViewVolume(float aspectRatio,
00558 float nearDist,
00559 float farDist,
00560 SbVec3f position,
00561 SbRotation rotation) const = 0;
00562
00563 virtual SbViewVolume getViewVolume(SoGLRenderAction *action);
00564
00565 static SbVec3f fromObjectSpace(const SbVec3f &vector, const SbMatrix &matrix, const SbViewportRegion &vpr);
00566 static SbVec3f toObjectSpace(const SbVec3f &pixel, const SbMatrix &matrix, const SbViewportRegion &vpr);
00567
00569 SbViewVolume getViewVolume(SoState *state);
00570
00572 inline void setLightCamera(bool flag);
00573
00575 inline bool isLightCamera() const;
00576
00580 const SbViewportRegion &getLastViewportRegion() const
00581 { return m_lastVpRegion; }
00582
00583 private:
00584 SoCamera();
00585 virtual ~SoCamera();
00586
00587
00588
00589
00590
00591 virtual void viewBoundingBox(const SbBox3f &box,
00592 float aspect, float slack) = 0;
00593
00594
00595
00596
00597 virtual void jitter(int numPasses, int curPass,
00598 const SbViewportRegion &vpReg,
00599 SbVec3f &jitterAmount) const;
00600
00601 virtual float getEyeOffset( SoState* state = NULL );
00602 virtual void updateStereoAdjustments( SoState* state = NULL );
00603
00604 private:
00605
00606 void computeView(const SbViewportRegion &vpReg,
00607 SbViewVolume &viewVol,
00608 SbBool &changeRegion,
00609 SoState *state);
00610
00611
00612 void computeView_Wall(const SbViewportRegion &vpReg,
00613 SbViewVolume &viewVol,
00614 SbBool &changeRegion,
00615 SoState *state);
00616
00617
00618 void setElements(SoAction *action,
00619 SbViewVolume &viewVol,
00620 SbBool setRegion,
00621 const SbViewportRegion &vpReg,
00622 SbBool doJitter,
00623 const SbVec3f &jitterAmount);
00624
00625
00626 void drawFrame(SoGLRenderAction *action,
00627 const SbViewportRegion &vpReg,
00628 const SbViewportRegion &croppedReg);
00629
00630
00631 void tuneBbox(SbBox3f& bbox);
00632
00633
00634 void getJitterSample(int numPasses, int curPass, SbVec2f &samplePoint) const;
00635
00637 static void generateJitterGrid(std::vector<SbVec2f>& samples, unsigned int gridDim);
00638
00642 typedef std::map<int, std::vector<SbVec2f> > GridDimJitterOffsetMap;
00643 mutable GridDimJitterOffsetMap m_cachedJitterOffset;
00644
00645 SbBool m_stereoAbsoluteAdjustments;
00646 float m_stereoAdjustment, m_balanceAdjustment;
00647 SbBool m_balanceNearFrac;
00648 StereoMode m_stereoMode ;
00649
00650 SbBool _stereoAbsoluteAdjustments;
00651 float _stereoAdjustment, _balanceAdjustment;
00652 SbBool _balanceNearFrac;
00653 StereoMode _stereoMode ;
00654 SbBool _modeInRender;
00655
00656
00657 SbBool stereoIsAllowed;
00658
00660 bool m_lightCamera;
00661
00662 static SoCameraCB* s_cameraPostCB ;
00663
00665 SbViewportRegion m_lastVpRegion;
00666 };
00667
00668
00669 void
00670 SoCamera::setLightCamera(bool flag)
00671 {
00672 m_lightCamera = flag;
00673 }
00674
00675
00676 bool
00677 SoCamera::isLightCamera() const
00678 {
00679 return m_lightCamera;
00680 }
00681
00683
00684
00685
00686
00687 #define SO_ASPECT_SQUARE 1.00
00688 #define SO_ASPECT_VIDEO 1.333333333
00689 #define SO_ASPECT_35mm_ACADEMY 1.371
00690 #define SO_ASPECT_16mm 1.369
00691 #define SO_ASPECT_35mm_FULL 1.33333
00692 #define SO_ASPECT_70mm 2.287
00693 #define SO_ASPECT_CINEMASCOPE 2.35
00694 #define SO_ASPECT_HDTV 1.777777777
00695 #define SO_ASPECT_PANAVISION 2.361
00696 #define SO_ASPECT_35mm 1.5
00697 #define SO_ASPECT_VISTAVISION 2.301
00698
00699
00700 #ifdef _WIN32
00701 #pragma warning(pop)
00702 #endif
00703
00704 #endif
00705
00706