Browse Source

SceneGraph: method chaining also for Camera.

Mention it also in documentation to hint users to use it.
vectorfields
Vladimír Vondruš 14 years ago
parent
commit
7d3435f483
  1. 12
      src/SceneGraph/Camera.cpp
  2. 16
      src/SceneGraph/Camera.h
  3. 7
      src/SceneGraph/Object.h

12
src/SceneGraph/Camera.cpp

@ -47,9 +47,10 @@ template Matrix4 aspectRatioFix<Matrix4>(AspectRatioPolicy, const Vector2&, cons
template<class MatrixType, class VectorType, class ObjectType, class SceneType, class CameraType> Camera<MatrixType, VectorType, ObjectType, SceneType, CameraType>::Camera(ObjectType* parent): ObjectType(parent), _aspectRatioPolicy(AspectRatioPolicy::NotPreserved) {}
template<class MatrixType, class VectorType, class ObjectType, class SceneType, class CameraType> void Camera<MatrixType, VectorType, ObjectType, SceneType, CameraType>::setAspectRatioPolicy(AspectRatioPolicy policy) {
template<class MatrixType, class VectorType, class ObjectType, class SceneType, class CameraType> CameraType* Camera<MatrixType, VectorType, ObjectType, SceneType, CameraType>::setAspectRatioPolicy(AspectRatioPolicy policy) {
_aspectRatioPolicy = policy;
fixAspectRatio();
return static_cast<CameraType*>(this);
}
template<class MatrixType, class VectorType, class ObjectType, class SceneType, class CameraType> void Camera<MatrixType, VectorType, ObjectType, SceneType, CameraType>::setViewport(const Math::Vector2<GLsizei>& size) {
@ -82,14 +83,15 @@ template<class MatrixType, class VectorType, class ObjectType, class SceneType,
}
}
void Camera2D::setProjection(const Vector2& size) {
Camera2D* Camera2D::setProjection(const Vector2& size) {
/* Scale the volume down so it fits in (-1, 1) in all directions */
rawProjectionMatrix = Matrix3::scaling(2.0f/size);
fixAspectRatio();
return this;
}
void Camera3D::setOrthographic(const Vector2& size, GLfloat near, GLfloat far) {
Camera3D* Camera3D::setOrthographic(const Vector2& size, GLfloat near, GLfloat far) {
_near = near;
_far = far;
@ -104,9 +106,10 @@ void Camera3D::setOrthographic(const Vector2& size, GLfloat near, GLfloat far) {
);
fixAspectRatio();
return this;
}
void Camera3D::setPerspective(GLfloat fov, GLfloat near, GLfloat far) {
Camera3D* Camera3D::setPerspective(GLfloat fov, GLfloat near, GLfloat far) {
_near = near;
_far = far;
@ -121,6 +124,7 @@ void Camera3D::setPerspective(GLfloat fov, GLfloat near, GLfloat far) {
);
fixAspectRatio();
return this;
}
/* Explicitly instantiate the templates */

16
src/SceneGraph/Camera.h

@ -72,8 +72,11 @@ template<class MatrixType, class VectorType, class ObjectType, class SceneType,
/** @brief Aspect ratio policy */
inline AspectRatioPolicy aspectRatioPolicy() const { return _aspectRatioPolicy; }
/** @brief Set aspect ratio policy */
void setAspectRatioPolicy(AspectRatioPolicy policy);
/**
* @brief Set aspect ratio policy
* @return Pointer to self (for method chaining)
*/
CameraType* setAspectRatioPolicy(AspectRatioPolicy policy);
/**
* @brief Camera matrix
@ -191,11 +194,12 @@ class SCENEGRAPH_EXPORT Camera2D: public Camera<Matrix3, Vector2, Object2D, Scen
/**
* @brief Set projection
* @param size Size of the view
* @return Pointer to self (for method chaining)
*
* The area of given size will be scaled down to range @f$ [-1; 1] @f$
* on all directions.
*/
void setProjection(const Vector2& size);
Camera2D* setProjection(const Vector2& size);
};
/** @brief %Camera for three-dimensional scenes */
@ -215,21 +219,23 @@ class SCENEGRAPH_EXPORT Camera3D: public Camera<Matrix4, Vector3, Object3D, Scen
* @param size Size of the view
* @param near Near clipping plane
* @param far Far clipping plane
* @return Pointer to self (for method chaining)
*
* The volume of given size will be scaled down to range @f$ [-1; 1] @f$
* on all directions.
*/
void setOrthographic(const Vector2& size, GLfloat near, GLfloat far);
Camera3D* setOrthographic(const Vector2& size, GLfloat near, GLfloat far);
/**
* @brief Set perspective projection
* @param fov Field of view angle
* @param near Near clipping plane
* @param far Far clipping plane
* @return Pointer to self (for method chaining)
*
* @todo Aspect ratio
*/
void setPerspective(GLfloat fov, GLfloat near, GLfloat far);
Camera3D* setPerspective(GLfloat fov, GLfloat near, GLfloat far);
/** @brief Near clipping plane */
inline GLfloat near() const { return _near; }

7
src/SceneGraph/Object.h

@ -286,6 +286,7 @@ class SCENEGRAPH_EXPORT Object2D: public Object<Matrix3, Vector2, Object2D, Scen
/**
* @brief Translate object
* @return Pointer to self (for method chaining)
*
* Same as calling multiplyTransformation() with Matrix3::translation().
*/
@ -296,6 +297,7 @@ class SCENEGRAPH_EXPORT Object2D: public Object<Matrix3, Vector2, Object2D, Scen
/**
* @brief Scale object
* @return Pointer to self (for method chaining)
*
* Same as calling multiplyTransformation() with Matrix3::scaling().
*/
@ -306,6 +308,7 @@ class SCENEGRAPH_EXPORT Object2D: public Object<Matrix3, Vector2, Object2D, Scen
/**
* @brief Rotate object
* @return Pointer to self (for method chaining)
*
* Same as calling multiplyTransformation() with Matrix3::rotation().
*/
@ -318,6 +321,7 @@ class SCENEGRAPH_EXPORT Object2D: public Object<Matrix3, Vector2, Object2D, Scen
* @brief Move object in stacking order
* @param under Sibling object under which to move or `nullptr`,
* if you want to move it above all.
* @return Pointer to self (for method chaining)
*/
inline Object2D* move(Object2D* under) {
parent()->Corrade::Containers::LinkedList<Object2D>::move(this, under);
@ -333,6 +337,7 @@ class SCENEGRAPH_EXPORT Object3D: public Object<Matrix4, Vector3, Object3D, Scen
/**
* @brief Translate object
* @return Pointer to self (for method chaining)
*
* Same as calling multiplyTransformation() with Matrix4::translation().
*/
@ -343,6 +348,7 @@ class SCENEGRAPH_EXPORT Object3D: public Object<Matrix4, Vector3, Object3D, Scen
/**
* @brief Scale object
* @return Pointer to self (for method chaining)
*
* Same as calling multiplyTransformation() with Matrix4::scaling().
*/
@ -353,6 +359,7 @@ class SCENEGRAPH_EXPORT Object3D: public Object<Matrix4, Vector3, Object3D, Scen
/**
* @brief Rotate object
* @return Pointer to self (for method chaining)
*
* Same as calling multiplyTransformation() with Matrix4::rotation().
*/

Loading…
Cancel
Save