Browse Source

Function for getting absolute object transformation (relative to the

camera).

Usable for computation of light positions.
vectorfields
Vladimír Vondruš 16 years ago
parent
commit
5af44143e2
  1. 23
      src/Object.cpp
  2. 13
      src/Object.h

23
src/Object.cpp

@ -43,6 +43,29 @@ void Object::setParent(Object* parent) {
_parent = parent;
}
Matrix4 Object::transformation(bool absolute) {
if(!absolute) return _transformation;
Matrix4 t = _transformation;
Object* p = parent();
while(p != 0) {
t = p->transformation()*t;
/* We got to the scene, multiply with camera matrix */
if(p->parent() == p) {
Camera* camera = static_cast<Scene*>(p)->camera();
if(camera && camera != this) t = camera->cameraMatrix()*t;
break;
}
p = p->parent();
}
return t;
}
Object::~Object() {
/* Remove the object from parent's children */
setParent(0);

13
src/Object.h

@ -72,8 +72,17 @@ class Object {
/** @brief Set parent object */
virtual void setParent(Object* parent);
/** @brief Transformation matrix */
inline Matrix4 transformation() const { return _transformation; }
/**
* @brief Transformation matrix
*
* If the object is part of an scene and @c absolute is set to true,
* returns absolute transformation matrix (thus relative to actual
* camera), if the object is not part of an scene, returns
* transformation matrix composed of all matrices of parent objects.
* If @c absolute is set to false, returns transformation matrix
* relative to parent.
*/
virtual Matrix4 transformation(bool absolute = false);
/** @brief Set transformation matrix */
inline void setTransformation(const Matrix4& transformation) { _transformation = transformation; }

Loading…
Cancel
Save