1
0
Fork 0
2018-soft-3d-renderer/Source/Camera.hpp

48 lines
834 B
C++

#pragma once
#include "Engine.hpp"
#include "Point.hpp"
#include <cmath>
constexpr float DegToRad(float degrees)
{
return degrees * (float)M_PI / 180.0f;
}
class Camera
{
public:
Camera()
{
position.x = 0.0f;
position.y = 0.0f;
position.z = 0.0f;
rotation.x = 0.0f;
rotation.y = 0.0f;
rotation.z = 0.0f;
zClipBias0 =
(CAMERA_FAR_CLIP + CAMERA_NEAR_CLIP)
/ (CAMERA_FAR_CLIP - CAMERA_NEAR_CLIP);
zClipBias1 =
(-2.0f * CAMERA_FAR_CLIP * CAMERA_NEAR_CLIP)
/ (CAMERA_FAR_CLIP - CAMERA_NEAR_CLIP);
xZoom = 1.0f / tanf(DegToRad(CAMERA_FOV / 2.0f));
yZoom = (xZoom * WINDOW_WIDTH) / WINDOW_HEIGHT;
xScale = (0.5f * WINDOW_WIDTH) - 0.5f;
yScale = (0.5f * WINDOW_HEIGHT) - 0.5f;
}
Point position;
Point rotation;
float zClipBias0, zClipBias1;
float xZoom, yZoom;
float xScale, yScale;
};