erebus

diff liberebus/src/camera.h @ 0:4abdce1361b9

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 27 Apr 2014 16:02:47 +0300
parents
children 9621beb22694
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/liberebus/src/camera.h	Sun Apr 27 16:02:47 2014 +0300
     1.3 @@ -0,0 +1,61 @@
     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 +	Vector3 pos;
    1.12 +	float vfov;	// vertical field of view in radians
    1.13 +
    1.14 +	mutable Matrix4x4 cached_matrix;
    1.15 +	mutable bool cached_matrix_valid;
    1.16 +
    1.17 +	mutable Vector3 *rdir_cache;
    1.18 +	mutable int rdir_cache_width, rdir_cache_height;
    1.19 +
    1.20 +	virtual void calc_matrix(Matrix4x4 *mat) const = 0;
    1.21 +
    1.22 +	Vector2 calc_sample_pos(int x, int y, int xsz, int ysz, int sample) const;
    1.23 +
    1.24 +public:
    1.25 +	Camera();
    1.26 +	Camera(const Vector3 &pos);
    1.27 +	virtual ~Camera();
    1.28 +
    1.29 +	virtual void set_fov(float vfov);
    1.30 +	virtual float get_fov() const;
    1.31 +
    1.32 +	virtual void set_position(const Vector3 &pos);
    1.33 +	virtual const Vector3 &get_position() const;
    1.34 +	virtual const Matrix4x4 &get_matrix() const;
    1.35 +
    1.36 +	virtual Ray get_primary_ray(int x, int y, int xsz, int ysz, int sample = 0) const;
    1.37 +};
    1.38 +
    1.39 +class TargetCamera : public Camera {
    1.40 +protected:
    1.41 +	Vector3 target;
    1.42 +
    1.43 +	void calc_matrix(Matrix4x4 *mat) const;
    1.44 +
    1.45 +public:
    1.46 +	TargetCamera();
    1.47 +	TargetCamera(const Vector3 &pos, const Vector3 &targ);
    1.48 +
    1.49 +	virtual void set_target(const Vector3 &targ);
    1.50 +	virtual const Vector3 &get_target() const;
    1.51 +};
    1.52 +
    1.53 +class FlyCamera : public Camera {
    1.54 +protected:
    1.55 +	Quaternion rot;
    1.56 +
    1.57 +	void calc_matrix(Matrix4x4 *mat) const;
    1.58 +
    1.59 +public:
    1.60 +	void input_move(float x, float y, float z);
    1.61 +	void input_rotate(float x, float y, float z);
    1.62 +};
    1.63 +
    1.64 +#endif	// CAMERA_H_