nuclear@0: #ifndef CAMERA_H_ nuclear@0: #define CAMERA_H_ nuclear@0: nuclear@5: #include "vmath/vmath.h" nuclear@5: nuclear@0: class Camera { nuclear@5: protected: nuclear@5: mutable struct { nuclear@5: bool valid; nuclear@5: Matrix4x4 mat; nuclear@5: } mcache, mcache_inv; nuclear@5: nuclear@5: virtual void calc_matrix(Matrix4x4 *mat) const = 0; nuclear@5: virtual void calc_inv_matrix(Matrix4x4 *mat) const; nuclear@5: nuclear@5: void inval_cache() { mcache.valid = mcache_inv.valid = false; } nuclear@5: void set_glmat(const Matrix4x4 &m) const; nuclear@5: nuclear@0: public: nuclear@5: Camera(); nuclear@5: virtual ~Camera(); nuclear@5: nuclear@5: const Matrix4x4 &matrix() const; nuclear@5: const Matrix4x4 &inv_matrix() const; nuclear@5: nuclear@5: void use() const; nuclear@5: void use_inverse() const; nuclear@5: nuclear@5: // these do nothing, override to provide input handling nuclear@5: virtual void input_move(float x, float y, float z); nuclear@5: virtual void input_rotate(float x, float y, float z); nuclear@5: virtual void input_zoom(float factor); nuclear@0: }; nuclear@0: nuclear@5: class OrbitCamera : public Camera { nuclear@5: private: nuclear@5: float theta, phi, rad; nuclear@5: nuclear@5: void calc_matrix(Matrix4x4 *mat) const; nuclear@5: void calc_inv_matrix(Matrix4x4 *mat) const; nuclear@5: nuclear@5: public: nuclear@5: OrbitCamera(); nuclear@5: virtual ~OrbitCamera(); nuclear@5: nuclear@5: void input_rotate(float x, float y, float z); nuclear@5: void input_zoom(float factor); nuclear@5: }; nuclear@5: nuclear@5: class FlyCamera : public Camera { nuclear@5: private: nuclear@5: Vector3 pos; nuclear@5: Quaternion rot; nuclear@5: nuclear@5: void calc_matrix(Matrix4x4 *mat) const; nuclear@5: //void calc_inv_matrix(Matrix4x4 *mat) const; nuclear@5: nuclear@5: public: nuclear@5: FlyCamera(); nuclear@5: nuclear@5: const Vector3 &get_position() const; nuclear@5: const Quaternion &get_rotation() const; nuclear@5: nuclear@5: void input_move(float x, float y, float z); nuclear@5: void input_rotate(float x, float y, float z); nuclear@5: }; nuclear@5: nuclear@5: nuclear@0: #endif // CAMERA_H_