00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef VRS_VIEWINFO_H
00019 #define VRS_VIEWINFO_H
00020
00021 #include <vrs/sharedobj.h>
00022 #include <vrs/bounds.h>
00023 #include <vrs/vector.h>
00024
00025 namespace VRS {
00026
00027 class Engine;
00028
00029
00030
00031
00032
00033
00034
00035
00036
00038
00047 class VRS_CORE_API ViewInfo : public VRS::SharedObj {
00048 public:
00049 ViewInfo(SO<const Engine> engine);
00050
00051 ~ViewInfo();
00052
00053
00054 virtual int viewportWidth() const;
00055 virtual int viewportHeight() const;
00056
00057
00058 virtual const Vector &cameraPosition() const = 0;
00059 virtual const Vector &cameraUp() const = 0;
00060 virtual const Vector &cameraRight() const = 0;
00061 virtual const Vector &cameraDirection() const = 0;
00062 virtual double farPlaneDistance() const = 0;
00063 virtual double nearPlaneDistance() const = 0;
00064
00065
00066 virtual double distanceToCamera2(const Vector &point) const = 0;
00067 virtual double distanceToCamera2(const Bounds &bbox) const = 0;
00068
00069
00070 virtual double pixelSize2(const Vector ¢er, double radius) const = 0;
00071 virtual double pixelSize2(const Vector &segmentBegin, const Vector &segmentEnd) const = 0;
00072
00073
00074 enum CullingPos { Outside = -1, InAndOut = 0, Inside = 1 };
00075 VRS_SERIALIZABLE_CLASS_ENUM(CullingPos);
00076
00077 virtual CullingPos culling(const Vector& point, double radius) const = 0;
00079 virtual CullingPos culling(const Vector& point) const = 0;
00081
00082 virtual CullingPos culling(const Bounds& bbox) const = 0;
00084
00085 VRS_TYPEINFO(ViewInfo, SharedObj);
00086
00087 protected:
00088 ViewInfo();
00089
00090 int viewportWidth_;
00091 int viewportHeight_;
00092 };
00093
00094 class VRS_CORE_API ViewInfoFactory : public VRS::SharedObj {
00095 public:
00097
00098 virtual SO<ViewInfo> newViewInfo(SO<const Engine> engine) = 0;
00099
00100 VRS_TYPEINFO(ViewInfoFactory, SharedObj);
00101 };
00102
00105 class VRS_CORE_API ModelviewProjectionViewInfo :
00106 public ViewInfo
00107 {
00108 public:
00109 VRS_TYPEINFO(ModelviewProjectionViewInfo, ViewInfo);
00110
00111 ModelviewProjectionViewInfo(
00112 const Matrix& modelview,
00113 const Matrix& projection,
00114 unsigned int viewportPixelsX,
00115 unsigned int viewportPixelsY
00116 );
00117
00118 virtual double farPlaneDistance() const;
00119 virtual void setFarPlaneDistance(double farPlaneDistance) { farPlane_ = farPlaneDistance; };
00120
00121 virtual double nearPlaneDistance() const;
00122 virtual void setNearPlaneDistance(double nearPlaneDistance) { nearPlane_ = nearPlaneDistance; };
00123
00124 inline const Vector& focus(void) const { return focus_; };
00125 inline void setFocus(const Vector& focus) { focus_ = focus; };
00126
00127 virtual const Vector &cameraPosition() const;
00128 inline void setCameraPosition(const Vector& cameraPosition) { position_ = cameraPosition; };
00129
00130 virtual const Vector &cameraUp() const;
00131 inline void setCameraUp(const Vector& cameraUp) { upVector_ = cameraUp; };
00132
00133 virtual const Vector &cameraRight() const;
00134 inline void setCameraRight(const Vector& cameraRight) { rightVector_ = cameraRight; };
00135 virtual const Vector &cameraDirection() const;
00136
00137 virtual double distanceToCamera2(const Vector &point) const;
00138 virtual double distanceToCamera2(const Bounds &bbox) const;
00139
00140 virtual double pixelSize2(const Vector ¢er, double radius) const;
00141 virtual double pixelSize2(const Vector &segmentBegin, const Vector &segmentEnd) const;
00142
00143 virtual CullingPos culling(const Vector& point, double radius) const;
00144 virtual CullingPos culling(const Vector& point) const;
00145 virtual CullingPos culling(const Bounds& bbox) const;
00146
00147 inline const Vector& leftPlane(void) const { return leftPlane_; };
00148 inline void setLeftPlane(const Vector& leftPlane) { leftPlane_ = leftPlane; };
00149
00150 inline const Vector& rightPlane(void) const { return rightPlane_; };
00151 inline void setRightPlane(const Vector& rightPlane) { rightPlane_ = rightPlane; };
00152
00153 inline const Vector& topPlane(void) const { return topPlane_; };
00154 inline void setTopPlane(const Vector& topPlane) { topPlane_ = topPlane; };
00155
00156 inline const Vector& bottomPlane(void) const { return bottomPlane_; };
00157 inline void setBottomPlane(const Vector& bottomPlane) { bottomPlane_ = bottomPlane; };
00158
00159 inline const Vector& clipNormal(void) const { return clipNormal_; };
00160 inline void setClipNormal(const Vector& clipNormal) { clipNormal_ = clipNormal; };
00161
00162 inline const Vector& depthVector(void) const { return depthVector_; };
00163 inline void setDepthVector(const Vector& depthVector) { depthVector_ = depthVector; };
00164
00165 enum PrjType { Unknown, Parallel, Perspective };
00166 virtual PrjType projectionType() const;
00167
00168 protected:
00169 template<class T>
00170 inline CullingPos xculling(const T& obj) const;
00171
00172 private:
00173 void decompose(const Matrix& invMat);
00174
00175 Matrix mvp_;
00176
00177 Vector position_;
00178 Vector focus_;
00179 Vector upVector_;
00180 Vector rightVector_;
00181 Vector depthVector_;
00182 Vector leftPlane_;
00183 Vector rightPlane_;
00184 Vector topPlane_;
00185 Vector bottomPlane_;
00186 Vector clipNormal_;
00187
00188 double leftAngle_;
00189 double rightAngle_;
00190 double topAngle_;
00191 double bottomAngle_;
00192 double nearPlane_;
00193 double farPlane_;
00194
00195 Vector llf_;
00196 Vector urb_;
00197
00198 double pixelSizeVector_[4];
00199
00200 PrjType type_;
00201
00202 };
00203
00204 }
00205
00206 #endif // VRS_VIEWINFO_H