conworlds

view src/camera.h @ 5:8b7da5ab814e

vr wrapper in progress
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 20 Aug 2014 16:34:43 +0300
parents
children
line source
1 #ifndef CAMERA_H_
2 #define CAMERA_H_
4 #include "vmath/vmath.h"
6 class Camera {
7 protected:
8 Vector3 pos;
9 float vfov; // vertical field of view in radians
11 mutable Matrix4x4 cached_matrix;
12 mutable bool cached_matrix_valid;
14 mutable Vector3 *rdir_cache;
15 mutable int rdir_cache_width, rdir_cache_height;
17 virtual void calc_matrix(Matrix4x4 *mat) const = 0;
19 Vector2 calc_sample_pos(int x, int y, int xsz, int ysz, int sample) const;
21 public:
22 Camera();
23 Camera(const Vector3 &pos);
24 virtual ~Camera();
26 virtual void set_fov(float vfov);
27 virtual float get_fov() const;
29 virtual void set_position(const Vector3 &pos);
30 virtual const Vector3 &get_position() const;
31 virtual const Matrix4x4 &get_matrix() const;
33 virtual Ray get_primary_ray(int x, int y, int xsz, int ysz, int sample = 0) const;
34 };
36 class TargetCamera : public Camera {
37 protected:
38 Vector3 target;
40 void calc_matrix(Matrix4x4 *mat) const;
42 public:
43 TargetCamera();
44 TargetCamera(const Vector3 &pos, const Vector3 &targ);
46 virtual void set_target(const Vector3 &targ);
47 virtual const Vector3 &get_target() const;
48 };
50 class FlyCamera : public Camera {
51 protected:
52 Quaternion rot;
54 void calc_matrix(Matrix4x4 *mat) const;
56 public:
57 void input_move(float x, float y, float z);
58 void input_rotate(float x, float y, float z);
59 };
61 #endif // CAMERA_H_