Project restructure
This commit is contained in:
@@ -1,151 +0,0 @@
|
||||
#pragma once
|
||||
#ifndef _NB_CAMERA
|
||||
#define _NB_CAMERA
|
||||
|
||||
#include <GLLoad.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_inverse.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
namespace NB {
|
||||
|
||||
class Camera {
|
||||
public:
|
||||
typedef glm::vec3 Vec3;
|
||||
typedef glm::mat4 Mat4;
|
||||
|
||||
enum CameraTypeEnum : unsigned char {
|
||||
None,
|
||||
Orthographic,
|
||||
Perspective
|
||||
};
|
||||
|
||||
const CameraTypeEnum CameraType = CameraTypeEnum::None;
|
||||
|
||||
static Vec3 normCross(const Vec3&, const Vec3&);
|
||||
static Vec3 transformVec(const Mat4&, const Vec3&);
|
||||
|
||||
Camera(
|
||||
const Vec3& pos=Vec3(0.0f, 0.0f, -1.0f),
|
||||
const Vec3& tar=Vec3(0.0f, 0.0f, 0.0f),
|
||||
const Vec3& up =Vec3(0.0f, 1.0f, 0.0f)
|
||||
);
|
||||
|
||||
|
||||
Vec3 getPos() const;
|
||||
Vec3 getTarget() const;
|
||||
Vec3 getDirection() const;
|
||||
Vec3 getWorldUp() const;
|
||||
Vec3 getUp() const;
|
||||
Vec3 getRight() const;
|
||||
Mat4 getViewMatrix() const;
|
||||
Mat4 getProjectionMatrix() const;
|
||||
Mat4 getFlattenedMatrices() const;
|
||||
bool isUpLocked() const;
|
||||
|
||||
void setProjection(const Mat4&);
|
||||
void setPos(const Vec3&);
|
||||
void setTarget(const Vec3&);
|
||||
void setDirection(const Vec3&);
|
||||
void setWorldUp(const Vec3&);
|
||||
void lockToWorldUp(bool lock);
|
||||
void resetUp();
|
||||
void addPos(const Vec3&);
|
||||
void panPos(const Vec3&);
|
||||
void panPosRelative(const Vec3&);
|
||||
void addTarget(const Vec3&);
|
||||
void roll(float);
|
||||
void pitch(float);
|
||||
void yaw(float);
|
||||
|
||||
protected:
|
||||
Vec3 _pos;
|
||||
Vec3 _tar;
|
||||
Vec3 _dir;
|
||||
Vec3 _world_up;
|
||||
Vec3 _up;
|
||||
Vec3 _right;
|
||||
Mat4 _view;
|
||||
Mat4 _proj;
|
||||
bool _lock_world_up = true;
|
||||
|
||||
void _calcLook();
|
||||
|
||||
};
|
||||
|
||||
class OrthographicCamera : public Camera {
|
||||
public:
|
||||
const CameraTypeEnum CameraType = CameraTypeEnum::Orthographic;
|
||||
|
||||
OrthographicCamera(
|
||||
const Vec3& pos=Vec3(0.0f, 0.0f, -1.0f),
|
||||
const Vec3& tar=Vec3(0.0f, 0.0f, 0.0f),
|
||||
const Vec3& up =Vec3(0.0f, 1.0f, 0.0f),
|
||||
float left = -1.0f,
|
||||
float right = 1.0f,
|
||||
float bottom = -1.0f,
|
||||
float top = 1.0f,
|
||||
float near = 0.001f,
|
||||
float far = 1.0f
|
||||
);
|
||||
|
||||
float getLeftPlane() const;
|
||||
float getRightPlane() const;
|
||||
float getBottomPlane() const;
|
||||
float getTopPlane() const;
|
||||
float getNearPlane() const;
|
||||
float getFarPlane() const;
|
||||
|
||||
void setLeftPlane(float);
|
||||
void setRightPlane(float);
|
||||
void setBottomPlane(float);
|
||||
void setTopPlane(float);
|
||||
void setNearPlane(float);
|
||||
void setFarPlane(float);
|
||||
void setOrthographicProjection(float left=-1.0, float right=1.0, float bottom=-1.0, float top=1.0, float near=.001, float far=1.0);
|
||||
void setViewingVolume(float width, float height, float depth);
|
||||
|
||||
protected:
|
||||
float _leftPlane, _rightPlane, _topPlane, _bottomPlane, _nearPlane, _farPlane;
|
||||
|
||||
void _calcView();
|
||||
using Camera::setProjection;
|
||||
|
||||
};
|
||||
|
||||
class PerspectiveCamera : public Camera {
|
||||
public:
|
||||
const CameraTypeEnum CameraType = CameraTypeEnum::Perspective;
|
||||
|
||||
PerspectiveCamera(
|
||||
const Vec3& pos=Vec3(0.0f, 0.0f, -1.0f),
|
||||
const Vec3& tar=Vec3(0.0f, 0.0f, 0.0f),
|
||||
const Vec3& up =Vec3(0.0f, 1.0f, 0.0f),
|
||||
float fov = 45.0f,
|
||||
float aspectRatio = 1.0f,
|
||||
float near = 0.001f,
|
||||
float far = 1.0f
|
||||
);
|
||||
|
||||
float getFOV() const;
|
||||
float getAspectRatio() const;
|
||||
float getNearPlane() const;
|
||||
float getFarPlane() const;
|
||||
|
||||
void setFOV(float);
|
||||
void setAspectRatio(float);
|
||||
void setNearPlane(float);
|
||||
void setFarPlane(float);
|
||||
void setPerspectiveProjection(float fov=45, float aspectRatio=1.0f, float near=0.001f, float far=1.0f);
|
||||
|
||||
protected:
|
||||
float _fov, _ratio, _nearPlane, _farPlane;
|
||||
|
||||
void _calcView();
|
||||
using Camera::setProjection;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif // _NB_CAMERA
|
||||
Reference in New Issue
Block a user