Source: raytracer/transformatable.h


Annotated List
Files
Globals
Hierarchy
Index
/* *************************************************************************
                            transformatable.h  -  description
                             -------------------
    begin                : Wed Oct 16 2002    
    copyright            : (C) 2002 by Micha Riser
    email                : mriser@gmx.net
 ************************************************************************* */

/* *************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ************************************************************************* */

#ifndef TRANSFORMATABLE_H
#define TRANSFORMATABLE_H

#include "vector.h"
#include "ray.h"

/**Supperclass for everything that is in space an can be translated and
  *transformed.
  *@author Micha Riser
  */

class Transformatable {

public: // Constructor and destructor

    /**Create untransformated Transformatable.
      */
    Transformatable():translation(0),transformation(0),inverse(0) {}

    Transformatable(Vector3 loc):translation(loc),transformation(0),inverse(0) {}

    /**Copy constructor.
      */
    Transformatable(const Transformatable &t):translation(t.translation) {
        if (t.transformation) {
            transformation = new Matrix(*t.transformation);
            inverse = new Matrix(*t.inverse);
        } else {transformation = 0; inverse = 0;}
    }

    // destructor
    virtual ~Transformatable() {
        if (transformation) {
            delete(transformation);
            delete(inverse);
        }
    }

private: // Disallow assignment constructor
    Transformatable& operator=(const Transformatable&);

public: // Public methods

    /**
      *@returns translation vector
      */
    Vector3 getTranslation() const {return translation;}

    /**
      *@returns pointer to transformation matrix
      */
    const Matrix* getTransformationMatrix() const {return transformation;}

    /**
      *@returns pointer to inverse transformation matrix
      */
    const Matrix* getInverseMatrix() const {return inverse;}

    /**Translate by vector.
      */
    virtual void translate(const Vector3 &v) {translation.add(v);}

    /**Scale by x,y,z factor from vector.
      */
    virtual void scale(Vector3 v);

    /**Rotate around x,y,z axe.
      *@param v vector holding the rotation angles in degrees
      */
    virtual void rotate(const Vector3 &v);

    /**Transform by orthogonal matrix.
      */
    virtual void applyOrthogonalMatrix(const Matrix &m);

    /**Transform the same way as given Transformatable.
      */
    virtual void transform(const Transformatable& t);

    /**Transform inverse as given Transformatble.
      */
    virtual void transformInverse(const Transformatable& t);

    /**Transform point into local space.
      */
    void transformPointIn(Vector3 &p) const;

    /**Transform normal vector into local space.
      */
    void transformNormalIn(Vector3 &p) const;

    /**Transform normal vector from local space to outer space.
      */
    void transformNormalOut(Vector3 &p) const;

    /**Transform ray into local space.
      */
    void transformRayIn(Ray &r) const;

protected: // Protected attributes

    /**Translation vector. Always present.
      */
    Vector3 translation;

    /**Transformation matrix. May be 0.
      */
    Matrix* transformation;

    /**Inverse matrix of transformation. Is 0 if no transformation.
      */
    Matrix* inverse;

};


#endif

Generated by: micha@laptop on Thu Oct 24 20:25:24 2002, using kdoc 2.0a53.