|
|
@@ -40,90 +40,166 @@ public:
|
|
|
FP_COUNT
|
|
|
};
|
|
|
|
|
|
- /// @name Constructors
|
|
|
- /// @{
|
|
|
- Frustum()
|
|
|
- : CollisionShape(CST_FRUSTUM), type(FT_ORTHOGRAPHIC)
|
|
|
+ Frustum(FrustumType type_)
|
|
|
+ : CollisionShape(CST_FRUSTUM), type(type_)
|
|
|
{}
|
|
|
|
|
|
- Frustum(const Frustum& b)
|
|
|
- : CollisionShape(CST_FRUSTUM)
|
|
|
+ /// Copy
|
|
|
+ Frustum& operator=(const Frustum& b);
|
|
|
+
|
|
|
+ /// Implements CollisionShape::transform
|
|
|
+ void transform(const Transform& trf);
|
|
|
+
|
|
|
+ /// Implements CollisionShape::accept
|
|
|
+ void accept(MutableVisitor& v)
|
|
|
{
|
|
|
- *this = b;
|
|
|
+ v.visit(*this);
|
|
|
}
|
|
|
+ /// Implements CollisionShape::accept
|
|
|
+ void accept(ConstVisitor& v) const
|
|
|
+ {
|
|
|
+ v.visit(*this);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Check if a collision shape is inside the frustum
|
|
|
+ bool insideFrustum(const CollisionShape& b) const;
|
|
|
+
|
|
|
+protected:
|
|
|
+ boost::array<Plane, FP_COUNT> planes;
|
|
|
+ float zNear, zFar;
|
|
|
|
|
|
- Frustum(float fovX, float fovY, float zNear,
|
|
|
- float zFar, const Transform& trf)
|
|
|
- : CollisionShape(CST_FRUSTUM)
|
|
|
+ /// Called when a viewing variable changes. It recalculates the planes and
|
|
|
+ /// the other variables
|
|
|
+ virtual void recalculate() = 0;
|
|
|
+
|
|
|
+private:
|
|
|
+ FrustumType type;
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+/// XXX
|
|
|
+class PerspectiveFrustum: public Frustum
|
|
|
+{
|
|
|
+public:
|
|
|
+ PerspectiveFrustum()
|
|
|
+ : Frustum(FT_PERSPECTIVE)
|
|
|
+ {}
|
|
|
+
|
|
|
+ /// @name Accessors
|
|
|
+ /// @{
|
|
|
+ float getFovX() const
|
|
|
+ {
|
|
|
+ return fovX;
|
|
|
+ }
|
|
|
+ void setFovX(float ang)
|
|
|
+ {
|
|
|
+ fovX = ang;
|
|
|
+ recalculate();
|
|
|
+ }
|
|
|
+
|
|
|
+ float getFovY() const
|
|
|
+ {
|
|
|
+ return fovY;
|
|
|
+ }
|
|
|
+ void setFovY(float ang)
|
|
|
{
|
|
|
- setPerspective(fovX, fovY, zNear, zFar, trf);
|
|
|
+ fovY = ang;
|
|
|
+ recalculate();
|
|
|
}
|
|
|
|
|
|
- Frustum(float left, float right, float near,
|
|
|
- float far, float top, float buttom, const Transform& trf)
|
|
|
- : CollisionShape(CST_FRUSTUM)
|
|
|
+ void setAll(float fovX_, float fovY_, float zNear_, float zFar_)
|
|
|
{
|
|
|
- setOrthographic(left, right, near, far, top, buttom, trf);
|
|
|
+ fovX = fovX_;
|
|
|
+ fovY = fovY_,
|
|
|
+ zNear = zNear_;
|
|
|
+ zFar = zFar_;
|
|
|
+ recalculate();
|
|
|
}
|
|
|
/// @}
|
|
|
|
|
|
/// Copy
|
|
|
- Frustum& operator=(const Frustum& b);
|
|
|
+ PerspectiveFrustum& operator=(const PerspectiveFrustum& b);
|
|
|
|
|
|
/// Implements CollisionShape::testPlane
|
|
|
float testPlane(const Plane& p) const;
|
|
|
|
|
|
- /// Implements CollisionShape::transform
|
|
|
- void transform(const Transform& trf)
|
|
|
- {
|
|
|
- *this = getTransformed(trf);
|
|
|
- }
|
|
|
+ /// Re-implements Frustum::transform
|
|
|
+ void transform(const Transform& trf);
|
|
|
|
|
|
- Frustum getTransformed(const Transform& trf) const;
|
|
|
+private:
|
|
|
+ Vec3 eye; ///< The eye point
|
|
|
+ boost::array<Vec3, 4> dirs; ///< Directions
|
|
|
+ float fovX;
|
|
|
+ float fovY;
|
|
|
|
|
|
- /// Implements CollisionShape::accept
|
|
|
- void accept(MutableVisitor& v)
|
|
|
+ /// Implements CollisionShape::recalculate
|
|
|
+ void recalculate();
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+/// XXX
|
|
|
+class OrthographicFrustum: public Frustum
|
|
|
+{
|
|
|
+public:
|
|
|
+
|
|
|
+ /// @name Accessors
|
|
|
+ /// @{
|
|
|
+ float getLeft() const
|
|
|
{
|
|
|
- v.visit(*this);
|
|
|
+ return left;
|
|
|
}
|
|
|
- /// Implements CollisionShape::accept
|
|
|
- void accept(ConstVisitor& v) const
|
|
|
+ void setLeft(float f)
|
|
|
{
|
|
|
- v.visit(*this);
|
|
|
+ left = f;
|
|
|
+ recalculate();
|
|
|
}
|
|
|
|
|
|
- /// Set all for perspective camera
|
|
|
- void setPerspective(float fovX, float fovY, float zNear,
|
|
|
- float zFar, const Transform& trf);
|
|
|
-
|
|
|
- /// Set all for orthographic camera
|
|
|
- void setOrthographic(float left, float right, float near,
|
|
|
- float far, float top, float buttom, const Transform& trf)
|
|
|
+ float getRight() const
|
|
|
{
|
|
|
- type = FT_ORTHOGRAPHIC;
|
|
|
- /// XXX
|
|
|
+ return right;
|
|
|
+ }
|
|
|
+ void setRight(float f)
|
|
|
+ {
|
|
|
+ right = f;
|
|
|
+ recalculate();
|
|
|
}
|
|
|
|
|
|
- /// Check if a collision shape is inside the frustum
|
|
|
- bool insideFrustum(const CollisionShape& b) const;
|
|
|
-
|
|
|
-private:
|
|
|
- FrustumType type;
|
|
|
+ float getTop() const
|
|
|
+ {
|
|
|
+ return top;
|
|
|
+ }
|
|
|
+ void setTop(float f)
|
|
|
+ {
|
|
|
+ top = f;
|
|
|
+ recalculate();
|
|
|
+ }
|
|
|
|
|
|
- boost::array<Plane, FP_COUNT> planes;
|
|
|
+ float getBottom() const
|
|
|
+ {
|
|
|
+ return bottom;
|
|
|
+ }
|
|
|
+ void setBottom(float f)
|
|
|
+ {
|
|
|
+ bottom = f;
|
|
|
+ recalculate();
|
|
|
+ }
|
|
|
|
|
|
- /// @name Including shape for perspective cameras
|
|
|
- /// @{
|
|
|
- Vec3 eye; ///< The eye point
|
|
|
- boost::array<Vec3, 4> dirs; ///< Directions
|
|
|
- float fovX, fovY, zNear, zFar;
|
|
|
+ void setAll(float left_, float right_, float zNear_,
|
|
|
+ float zFar_, float top_, float bottom_)
|
|
|
+ {
|
|
|
+ left = left_;
|
|
|
+ right = right_;
|
|
|
+ zNear = zNear_;
|
|
|
+ zFar = zFar_;
|
|
|
+ top = top_;
|
|
|
+ bottom = bottom_;
|
|
|
+ recalculate();
|
|
|
+ }
|
|
|
/// @}
|
|
|
|
|
|
- /// @name Including shape for orthographic cameras
|
|
|
- /// @{
|
|
|
+private:
|
|
|
Obb obb;
|
|
|
- float left, right, near, far, top, bottom;
|
|
|
- /// @}
|
|
|
+ float left, right, top, bottom;
|
|
|
};
|
|
|
/// @}
|
|
|
|