bloboland

diff src/camera.h @ 1:cfe68befb7cc

some progress
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 15 Dec 2012 23:43:03 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/camera.h	Sat Dec 15 23:43:03 2012 +0200
     1.3 @@ -0,0 +1,87 @@
     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 +	mutable struct {
    1.12 +		bool valid;
    1.13 +		Matrix4x4 mat;
    1.14 +	} mcache, mcache_inv;
    1.15 +
    1.16 +	virtual void calc_matrix(Matrix4x4 *mat) const = 0;
    1.17 +	virtual void calc_inv_matrix(Matrix4x4 *mat) const;
    1.18 +
    1.19 +	void inval_cache() { mcache.valid = mcache_inv.valid = false; }
    1.20 +	void set_glmat(const Matrix4x4 &m) const;
    1.21 +
    1.22 +public:
    1.23 +	Camera();
    1.24 +	virtual ~Camera();
    1.25 +
    1.26 +	const Matrix4x4 &matrix() const;
    1.27 +	const Matrix4x4 &inv_matrix() const;
    1.28 +
    1.29 +	void use() const;
    1.30 +	void use_inverse() const;
    1.31 +
    1.32 +	// these do nothing, override to provide input handling
    1.33 +	virtual void input_move(float x, float y, float z);
    1.34 +	virtual void input_rotate(float x, float y, float z);
    1.35 +	virtual void input_zoom(float factor);
    1.36 +};
    1.37 +
    1.38 +class OrbitCamera : public Camera {
    1.39 +protected:
    1.40 +	float theta, phi, rad;
    1.41 +	float min_phi, max_phi;
    1.42 +
    1.43 +	void calc_matrix(Matrix4x4 *mat) const;
    1.44 +	void calc_inv_matrix(Matrix4x4 *mat) const;
    1.45 +
    1.46 +public:
    1.47 +	OrbitCamera();
    1.48 +	virtual ~OrbitCamera();
    1.49 +
    1.50 +	void set_distance(float dist);
    1.51 +	void set_vertical_limits(float a, float b);
    1.52 +
    1.53 +	void input_rotate(float x, float y, float z);
    1.54 +	void input_zoom(float factor);
    1.55 +};
    1.56 +
    1.57 +class FpsCamera : public OrbitCamera {
    1.58 +protected:
    1.59 +	Vector3 pos;
    1.60 +
    1.61 +	void calc_matrix(Matrix4x4 *mat) const;
    1.62 +	void calc_inv_matrix(Matrix4x4 *mat) const;
    1.63 +
    1.64 +public:
    1.65 +	void input_move(float x, float y, float z);
    1.66 +
    1.67 +	const Vector3 &get_position() const;
    1.68 +};
    1.69 +
    1.70 +
    1.71 +class FlyCamera : public Camera {
    1.72 +private:
    1.73 +	Vector3 pos;
    1.74 +	Quaternion rot;
    1.75 +
    1.76 +	void calc_matrix(Matrix4x4 *mat) const;
    1.77 +	//void calc_inv_matrix(Matrix4x4 *mat) const;
    1.78 +
    1.79 +public:
    1.80 +	FlyCamera();
    1.81 +
    1.82 +	const Vector3 &get_position() const;
    1.83 +	const Quaternion &get_rotation() const;
    1.84 +
    1.85 +	void input_move(float x, float y, float z);
    1.86 +	void input_rotate(float x, float y, float z);
    1.87 +};
    1.88 +
    1.89 +
    1.90 +#endif	// CAMERA_H_