⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transform3.h

📁 一个用MATLAB语言编写的摄像机标定工具箱,内容丰富
💻 H
字号:
//
// transform3.h
//
// $Id: transform3.h,v 1.1.1.1 2001/02/28 00:28:40 cstolte Exp $
//

#ifndef SGL_TRANSFORM3_H
#define SGL_TRANSFORM3_H

#include <sgl/defs.h>
#include <sgl/vecmath3.h>
#include <sgl/hmg.h>

class Transform3;
class Projection3;

//
// Matrix3
//

class Matrix3 {
  public:
    Matrix3() { }
    Matrix3(double a00, double a01, double a02,
	    double a10, double a11, double a12,
	    double a20, double a21, double a22);

    friend std::ostream &operator<<(std::ostream &, const Matrix3 &);

    Matrix3 operator*(const Matrix3 &) const;
    Matrix3 &operator*=(const Matrix3 &);
    Matrix3 operator+(const Matrix3 &) const;
    Matrix3 &operator+=(const Matrix3 &);
    Matrix3 operator-(const Matrix3 &) const;
    Matrix3 &operator-=(const Matrix3 &);

    Matrix3 &identity();
    Matrix3 &zero();
    Matrix3 &rotatex(double theta);
    Matrix3 &rotatey(double theta);
    Matrix3 &rotatez(double theta);
    Matrix3 &rotate(double theta, const Vector3 &axis);
    Matrix3 &scale(double sx, double sy, double sz);
    Matrix3 &transpose();
    Matrix3 &invert();
    Matrix3 inverse() const { Matrix3 ret(*this); return ret.invert(); }

    double determinant() const;
    double determinant(const Matrix3 &adj) const;
    Matrix3 adjoint() const;

    Point3 apply(const Point3 &) const;
    Vector3 apply(const Vector3 &) const;
    Normal3 apply(const Normal3 &, const Matrix3 * = 0) const;

    bool operator==(const Matrix3 &) const;
    bool operator!=(const Matrix3 &) const;

    void glLoadMatrix() const;
    void glMultMatrix() const;

    static const Matrix3 unit;

//CO  protected:
    friend class Transform3;
    friend class Projection3;
    double cofactor(int, int) const;
    double T[3][3];
};

extern Matrix3 identityM3();
extern Matrix3 rotatex(double);
extern Matrix3 rotatey(double);
extern Matrix3 rotatez(double);
extern Matrix3 rotate(double, const Vector3 &);
extern Matrix3 scale(double, double, double);

//
// Transform3
//

class Transform3 : public Matrix3 {
  public:
    Transform3() { }
    Transform3(const Matrix3 &);
    Transform3(const Matrix3 &, const Vector3 &);

    friend std::ostream &operator<<(std::ostream &, const Transform3 &);

    Transform3 operator*(const Transform3 &) const;
    Transform3 &operator*=(const Transform3 &);
    friend Transform3 operator*(const Matrix3 &, const Transform3 &);
    Transform3 operator*(const Matrix3 &) const;
    Transform3 &operator*=(const Matrix3 &);

    Transform3 &identity();
    Transform3 &translate(double tx, double ty, double tz);
    Transform3 &rotatex(double angle);
    Transform3 &rotatey(double angle);
    Transform3 &rotatez(double angle);
    Transform3 &rotate(double theta, const Vector3 &axis);
    Transform3 &scale(double sx, double sy, double sz);
    Transform3 &invert();
    Transform3 inverse() const { Transform3 ret(*this); return ret.invert(); }
    Transform3 &camera(const Point3 &at, const Point3 &from,
		       const Point3 &up);
    Transform3 &perspective(double fov, double aspect,
			    double znear, double zfar);

    Point3 apply(const Point3 &) const;
    Vector3 apply(const Vector3 &) const;
    Normal3 apply(const Normal3 &, const Transform3 * = 0) const;
    Ray3 apply(const Ray3 &) const;

    bool operator==(const Transform3 &) const;
    bool operator!=(const Transform3 &) const;

    void glLoadMatrix() const;
    void glMultMatrix() const;

    static const Transform3 unit;

//CO  private:
    friend class Projection3;
    Vector3 translation;
};

extern Transform3 translate(double, double, double);

//
// TransInv3
//

class TransInv3 {
  public:
    TransInv3() { }
    TransInv3(const Transform3 &);
    TransInv3(const Transform3 &, const Transform3 &);

    Point3 apply(const Point3 &) const;
    Vector3 apply(const Vector3 &) const;
    Normal3 apply(const Normal3 &) const;
    Ray3 apply(const Ray3 &) const;

    Point3 applyInv(const Point3 &) const;
    Vector3 applyInv(const Vector3 &) const;
    Normal3 applyInv(const Normal3 &) const;
    Ray3 applyInv(const Ray3 &) const;
    
    Transform3 trans, itrans;
};

//
// Projection3
//

class Projection3 {
public:
    Projection3() { }
    Projection3(double, double, double, double,
		double, double, double, double,
		double, double, double, double,
		double, double, double, double);
    Projection3(const Matrix3 &);
    Projection3(const Transform3 &);

    friend std::ostream &operator<<(std::ostream &, const Projection3 &);

    Projection3 operator*(const Projection3 &) const;
    Projection3 &operator*=(const Projection3 &);
    Projection3 operator+(const  Projection3&) const;
    Projection3 &operator+=(const  Projection3&);
    Projection3 operator-(const  Projection3&) const;
    Projection3 &operator-=(const Projection3 &);

    Projection3 &identity();
    Projection3 &zero();
    Projection3 &perspective(double fov, double aspect, 
			     double znear, double zfar);
    Projection3 &frustum(double l, double r, double t,
			 double b, double n, double f);
    Projection3 &orthox();
    Projection3 &orthoy();
    Projection3 &orthoz();
    Projection3 &scale(double, double, double);
    Projection3 &translate(double, double, double);
    Projection3 &rotatex(double);
    Projection3 &rotatey(double);
    Projection3 &rotatez(double);
    Projection3 &rotate(double, const Vector3 &);
    Projection3 &invert();
    Projection3 inverse() const 
      { Projection3 ret(*this); return ret.invert(); }
    Projection3 &transpose();

    Point3 project(const Point3 &) const;
    Vector3 project(const Vector3 &) const;
    Normal3 project(const Normal3 &, const Projection3 * = 0) const;
    Homogeneous3 project(const Homogeneous3 &) const;

    bool operator==(const Projection3 &) const;
    bool operator!=(const Projection3 &) const;

    void glLoadMatrix() const;
    void glMultMatrix() const;

//CO  private:
    double determinant() const;
    static double det3x3(double, double, double, double, double, double,
			 double, double, double);
    Projection3 &adjoint();

    double T[4][4];
};

extern Projection3 identityP3();
extern Projection3 perspective(double, double, double, double);
extern Projection3 frustum(double, double, double, double, double, double);
extern Projection3 orthox();
extern Projection3 orthoy();
extern Projection3 orthoz();

#endif // SGL_TRANSFORM_H

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -