This commit is contained in:
h4570
2022-07-30 14:48:59 +02:00
parent 52a19f11a5
commit b7b32fb35a
25 changed files with 792 additions and 21 deletions
+2
View File
@@ -30,6 +30,8 @@ class Math {
static inline float sin(float x) { return cos(x - HALF_PI); }
static inline float tan(float x) { return sin(x) / cos(x); }
static float invSqrt(float x);
static bool equalf(const float& a, const float& b,
const float& epsilon = 0.00001F);
private:
Math();
@@ -35,9 +35,16 @@ class RendererCore3D {
void setFov(const float& t_fov);
/**
* Called by beginFrame();
* Sets 3D support to off
*/
void update();
/**
* Called by beginFrame();
* Updates camera info, to get proper frustum culling.
* Sets 3D support to on
*/
void update(const CameraInfo3D& cameraInfo);
@@ -48,13 +55,13 @@ class RendererCore3D {
* Get view (camera) matrix
* Updated at every beginFrame()
*/
const M4x4& getView() { return view; }
const M4x4& getView();
/**
* Get projection * view matrix
* Updated at every beginFrame()
*/
const M4x4& getViewProj() { return viewProj; }
const M4x4& getViewProj();
/**
* @brief
@@ -80,6 +87,7 @@ class RendererCore3D {
private:
M4x4 view, projection, viewProj;
float fov;
bool is3DSupportEnabled;
RendererSettings* settings;
+4 -1
View File
@@ -47,7 +47,10 @@ class RendererCore {
/** World background color */
void setClearScreenColor(const Color& color);
/** Clear screen and update view frustum for frustum culling. */
/** Clear screen and update view frustum for frustum culling. NO 3D support */
void beginFrame();
/** Clear screen and update view frustum for frustum culling. 3D support */
void beginFrame(const CameraInfo3D& cameraInfo);
/** VSync and swap frame double buffer. */
+4 -1
View File
@@ -37,7 +37,10 @@ class Renderer {
void setFrameLimit(const bool& onoff) { core.setFrameLimit(onoff); }
/** Update view frustum for frustum culling. */
/** Update view frustum for frustum culling. 3D support - off */
void beginFrame();
/** Update view frustum for frustum culling. 3D support - on */
void beginFrame(const CameraInfo3D& cameraInfo);
/** VSync and swap frame double buffer. */
+4
View File
@@ -136,6 +136,10 @@ float Math::asin(float x) {
return r;
}
bool Math::equalf(const float& a, const float& b, const float& epsilon) {
return fabs(a - b) < epsilon;
}
float Math::mod(float x, float y) {
/*
* Portable fmod(x,y) implementation for systems
@@ -12,13 +12,19 @@
namespace Tyra {
RendererCore3D::RendererCore3D() { fov = 60.0F; }
RendererCore3D::RendererCore3D() {
fov = 60.0F;
is3DSupportEnabled = false;
}
RendererCore3D::~RendererCore3D() {}
void RendererCore3D::update() { is3DSupportEnabled = false; }
void RendererCore3D::update(const CameraInfo3D& cameraInfo) {
frustumPlanes.update(cameraInfo, fov);
M4x4::lookAt(&view, *cameraInfo.position, *cameraInfo.looksAt);
viewProj = projection * view;
is3DSupportEnabled = true;
}
void RendererCore3D::init(RendererSettings* t_settings, Path1* t_path1) {
@@ -29,7 +35,20 @@ void RendererCore3D::init(RendererSettings* t_settings, Path1* t_path1) {
TYRA_LOG("RendererCore3D initialized!");
}
// TODO, usunac albo private core? przesunac set/get fov?
const M4x4& RendererCore3D::getView() {
TYRA_ASSERT(is3DSupportEnabled,
"You can't compute 3D without camera information. Please correct "
"your beginFrame()");
return view;
}
const M4x4& RendererCore3D::getViewProj() {
TYRA_ASSERT(is3DSupportEnabled,
"You can't compute 3D without camera information. Please correct "
"your beginFrame()");
return viewProj;
}
void RendererCore3D::setFov(const float& t_fov) {
fov = t_fov;
setProjection();
@@ -27,6 +27,12 @@ void RendererCore::init() {
void RendererCore::setClearScreenColor(const Color& color) { bgColor = color; }
void RendererCore::beginFrame() {
renderer3D.update();
Threading::switchThread();
path3.clearScreen(&gs.zBuffer, bgColor);
}
void RendererCore::beginFrame(const CameraInfo3D& cameraInfo) {
renderer3D.update(cameraInfo);
Threading::switchThread();
+2
View File
@@ -20,6 +20,8 @@ void Renderer::init() {
renderer2D.init(&core);
}
void Renderer::beginFrame() { core.beginFrame(); }
void Renderer::beginFrame(const CameraInfo3D& cameraInfo) {
core.beginFrame(cameraInfo);
}