goat3dgfx

diff src/camera.h @ 11:d061fe1a31ec

compile vr source files or not
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 24 Nov 2013 14:00:14 +0200
parents
children 7d6b667821cf
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/camera.h	Sun Nov 24 14:00:14 2013 +0200
     1.3 @@ -0,0 +1,98 @@
     1.4 +#ifndef CAMERA_H_
     1.5 +#define CAMERA_H_
     1.6 +
     1.7 +#include <vmath/vmath.h>
     1.8 +
     1.9 +class Camera {
    1.10 +protected:
    1.11 +	float roll;
    1.12 +
    1.13 +	mutable struct {
    1.14 +		bool valid;
    1.15 +		Matrix4x4 mat;
    1.16 +	} mcache, mcache_inv;
    1.17 +
    1.18 +	virtual void calc_matrix(Matrix4x4 *mat) const = 0;
    1.19 +	virtual void calc_inv_matrix(Matrix4x4 *mat) const;
    1.20 +
    1.21 +	void inval_cache() { mcache.valid = mcache_inv.valid = false; }
    1.22 +	void set_glmat(const Matrix4x4 &m) const;
    1.23 +
    1.24 +public:
    1.25 +	Camera();
    1.26 +	virtual ~Camera();
    1.27 +
    1.28 +	const Matrix4x4 &matrix() const;
    1.29 +	const Matrix4x4 &inv_matrix() const;
    1.30 +
    1.31 +	void use() const;
    1.32 +	void use_inverse() const;
    1.33 +
    1.34 +	// these do nothing, override to provide input handling
    1.35 +	virtual void input_move(float x, float y, float z);
    1.36 +	virtual void input_rotate(float x, float y, float z);
    1.37 +	virtual void input_zoom(float factor);
    1.38 +};
    1.39 +
    1.40 +class OrbitCamera : public Camera {
    1.41 +protected:
    1.42 +	float theta, phi, rad;
    1.43 +
    1.44 +	void calc_matrix(Matrix4x4 *mat) const;
    1.45 +	void calc_inv_matrix(Matrix4x4 *mat) const;
    1.46 +
    1.47 +public:
    1.48 +	OrbitCamera();
    1.49 +	virtual ~OrbitCamera();
    1.50 +
    1.51 +	void input_rotate(float x, float y, float z);
    1.52 +	void input_zoom(float factor);
    1.53 +};
    1.54 +
    1.55 +class FpsCamera : public OrbitCamera {
    1.56 +protected:
    1.57 +	Vector3 pos;
    1.58 +
    1.59 +	void calc_matrix(Matrix4x4 *mat) const;
    1.60 +	void calc_inv_matrix(Matrix4x4 *mat) const;
    1.61 +
    1.62 +public:
    1.63 +	void input_move(float x, float y, float z);
    1.64 +
    1.65 +	const Vector3 &get_position() const;
    1.66 +};
    1.67 +
    1.68 +class FlyCamera : public Camera {
    1.69 +private:
    1.70 +	Vector3 pos;
    1.71 +	Quaternion rot;
    1.72 +
    1.73 +	void calc_matrix(Matrix4x4 *mat) const;
    1.74 +	//void calc_inv_matrix(Matrix4x4 *mat) const;
    1.75 +
    1.76 +public:
    1.77 +	FlyCamera();
    1.78 +
    1.79 +	const Vector3 &get_position() const;
    1.80 +	const Quaternion &get_rotation() const;
    1.81 +
    1.82 +	void input_move(float x, float y, float z);
    1.83 +	void input_rotate(float x, float y, float z);
    1.84 +};
    1.85 +
    1.86 +
    1.87 +class VRFpsCamera : public FpsCamera {
    1.88 +private:
    1.89 +	float neck_eye_dist;
    1.90 +	float prev_angles[3];
    1.91 +
    1.92 +	void calc_matrix(Matrix4x4 *mat) const;
    1.93 +	void calc_inv_matrix(Matrix4x4 *mat) const;
    1.94 +
    1.95 +public:
    1.96 +	VRFpsCamera();
    1.97 +
    1.98 +	void track_vr();
    1.99 +};
   1.100 +
   1.101 +#endif	// CAMERA_H_