Terrain rendering hack
This commit is contained in:
parent
29935cf54e
commit
bf7b10850e
@ -1,5 +1,7 @@
|
|||||||
#include "3DRenderer.hpp"
|
#include "3DRenderer.hpp"
|
||||||
|
|
||||||
|
#include <SFML/Graphics/RectangleShape.hpp>
|
||||||
|
|
||||||
#include "../World/DbgCube.hpp"
|
#include "../World/DbgCube.hpp"
|
||||||
#include "../World/Tank.hpp"
|
#include "../World/Tank.hpp"
|
||||||
|
|
||||||
@ -99,12 +101,33 @@ void Graphic3DRenderer::Draw(sf::RenderTexture& context) {
|
|||||||
|
|
||||||
// Load main matrices
|
// Load main matrices
|
||||||
M3D_MATRIX viewMat = mMainCamera->GetView();
|
M3D_MATRIX viewMat = mMainCamera->GetView();
|
||||||
|
M3D_MATRIX invViewMat = M3D_MInverse(viewMat); // aka. camMat
|
||||||
M3D_MATRIX projMat = mMainCamera->GetProj();
|
M3D_MATRIX projMat = mMainCamera->GetProj();
|
||||||
M3D_MATRIX viewProjMat = viewMat * projMat;
|
M3D_MATRIX viewProjMat = viewMat * projMat;
|
||||||
|
|
||||||
// Create the frustrum "box"
|
// Create the frustrum "box"
|
||||||
M3D_BoundingFrustum camFrustrum(projMat, false);
|
M3D_BoundingFrustum camFrustrum(projMat, false);
|
||||||
camFrustrum.Transform(camFrustrum, M3D_MInverse(viewMat));
|
camFrustrum.Transform(camFrustrum, invViewMat);
|
||||||
|
|
||||||
|
const float sgRatio = std::tan(mMainCamera->GetLook3f().y);
|
||||||
|
// -= Draw the sky =-
|
||||||
|
// To avoid unfilled pixels on screen, the "sky-plane" will be rendered
|
||||||
|
// all over the screen.
|
||||||
|
// It's will be useless to use and compute a specific rectangle from the
|
||||||
|
// size of the screen!
|
||||||
|
// The sky have an infinite z-depth (any objects will be rendered over).
|
||||||
|
context.clear(sf::Color::Cyan);
|
||||||
|
|
||||||
|
// -= Draw the ground =-
|
||||||
|
// A simple rectangle shape is used to draw the ground over the sky-plane.
|
||||||
|
// The ground is draw after the sky, and before any other object.
|
||||||
|
// Depending of the camera pitch, the ratio sky/ground on screen vary.
|
||||||
|
// Like the sky, the ground have an infinite z-depth (any objects will
|
||||||
|
// be rendered over).
|
||||||
|
sf::RectangleShape gndRect(sf::Vector2f(1280, mRTSize.y * (0.5f - sgRatio)));
|
||||||
|
gndRect.setPosition(sf::Vector2f(0, mRTSize.y * (0.5f + sgRatio)));
|
||||||
|
gndRect.setFillColor(sf::Color::Green);
|
||||||
|
context.draw(gndRect, sRS);
|
||||||
|
|
||||||
// Process scene's objects
|
// Process scene's objects
|
||||||
for (auto& obj : mRenderList) {
|
for (auto& obj : mRenderList) {
|
||||||
@ -120,7 +143,7 @@ void Graphic3DRenderer::Draw(sf::RenderTexture& context) {
|
|||||||
{
|
{
|
||||||
size_t vCount = obj->GetObjectVerticesCount();
|
size_t vCount = obj->GetObjectVerticesCount();
|
||||||
auto& oMesh = obj->GetObjectMesh();
|
auto& oMesh = obj->GetObjectMesh();
|
||||||
auto* projVertices = new M3D_F4[vCount];
|
M3D_F4 projVertices[vCount] = {};
|
||||||
|
|
||||||
// Vertices homogeneous clip space transformation
|
// Vertices homogeneous clip space transformation
|
||||||
M3D_V3Transform(
|
M3D_V3Transform(
|
||||||
@ -131,7 +154,7 @@ void Graphic3DRenderer::Draw(sf::RenderTexture& context) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Draw the object indice triangles if visible or partially clipped
|
// Draw the object indice triangles if visible or partially clipped
|
||||||
auto* v_tri = new sf::Vertex[4];
|
sf::Vertex v_tri[4];
|
||||||
for (auto& objPt : oMesh.parts) {
|
for (auto& objPt : oMesh.parts) {
|
||||||
auto indicePtr = static_cast<const uint32_t*>(objPt.indices.data());
|
auto indicePtr = static_cast<const uint32_t*>(objPt.indices.data());
|
||||||
|
|
||||||
@ -188,9 +211,6 @@ void Graphic3DRenderer::Draw(sf::RenderTexture& context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] v_tri;
|
|
||||||
delete[] projVertices;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,8 @@ public:
|
|||||||
|
|
||||||
M3D_VECTOR GetPos() const { return M3D_V4LoadF3(&mPos); }
|
M3D_VECTOR GetPos() const { return M3D_V4LoadF3(&mPos); }
|
||||||
M3D_F3 GetPos3f() const { return mPos; }
|
M3D_F3 GetPos3f() const { return mPos; }
|
||||||
|
M3D_VECTOR GetLook() const { return M3D_V4LoadF3(&mLook); }
|
||||||
|
M3D_F3 GetLook3f() const { return mLook; }
|
||||||
M3D_MATRIX GetView() const { return M3D_V4LoadF4x4(&mViewMat); }
|
M3D_MATRIX GetView() const { return M3D_V4LoadF4x4(&mViewMat); }
|
||||||
const M3D_F4X4& GetView4x4f() const { return mViewMat; }
|
const M3D_F4X4& GetView4x4f() const { return mViewMat; }
|
||||||
M3D_MATRIX GetProj() const { return M3D_V4LoadF4x4(&mProjMat); }
|
M3D_MATRIX GetProj() const { return M3D_V4LoadF4x4(&mProjMat); }
|
||||||
|
@ -28,7 +28,7 @@ void DebugUI::DrawDebugData(std::shared_ptr<sf::RenderWindow> context) {
|
|||||||
outStrStream << std::fixed;
|
outStrStream << std::fixed;
|
||||||
|
|
||||||
outStrStream << std::setprecision(0) << "CPU: " << gDbgStats.cpu_usage << "% (cycle: " << std::setprecision(3) << gDbgStats.cpu_time << "/" << gDbgStats.cycle_time << "ms)" << std::endl;
|
outStrStream << std::setprecision(0) << "CPU: " << gDbgStats.cpu_usage << "% (cycle: " << std::setprecision(3) << gDbgStats.cpu_time << "/" << gDbgStats.cycle_time << "ms)" << std::endl;
|
||||||
outStrStream << std::setprecision(1) << "RAM: " << gDbgStats.ram_virt_usage << "MB(V) / " << gDbgStats.ram_phys_usage << "MB(P)" << std::endl;
|
outStrStream << std::setprecision(1) << "RAM: " << gDbgStats.ram_virt_usage << "MB(V)/" << gDbgStats.ram_phys_usage << "MB(P)" << std::endl;
|
||||||
outStrStream << std::setprecision(0) << "FPS: " << gDbgStats.fps;
|
outStrStream << std::setprecision(0) << "FPS: " << gDbgStats.fps;
|
||||||
|
|
||||||
gDbgText.setString(outStrStream.str());
|
gDbgText.setString(outStrStream.str());
|
||||||
|
@ -555,7 +555,7 @@ M3D_MATRIX M3D_MMultiply(M3D_MATRIX M1, M3D_MATRIX& M2) noexcept;
|
|||||||
M3D_MATRIX M3D_MTranspose(M3D_MATRIX M) noexcept;
|
M3D_MATRIX M3D_MTranspose(M3D_MATRIX M) noexcept;
|
||||||
M3D_MATRIX M3D_MInverse(M3D_MATRIX M) noexcept;
|
M3D_MATRIX M3D_MInverse(M3D_MATRIX M) noexcept;
|
||||||
|
|
||||||
M3D_VECTOR M3D_QRotationMatrix(M3D_MATRIX M) noexcept;
|
M3D_VECTOR M3D_QRotationFromMatrix(M3D_MATRIX M) noexcept;
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -178,7 +178,7 @@ INLINE_AVX_FIX void M3D_BoundingFrustum::Transform(M3D_BoundingFrustum& Out, M3D
|
|||||||
nM.rows[1] = M3D_V3Normalize(M.rows[1]);
|
nM.rows[1] = M3D_V3Normalize(M.rows[1]);
|
||||||
nM.rows[2] = M3D_V3Normalize(M.rows[2]);
|
nM.rows[2] = M3D_V3Normalize(M.rows[2]);
|
||||||
nM.rows[3] = M3D_MIdentityR3;
|
nM.rows[3] = M3D_MIdentityR3;
|
||||||
M3D_VECTOR Rotation = M3D_QRotationMatrix(nM);
|
M3D_VECTOR Rotation = M3D_QRotationFromMatrix(nM);
|
||||||
vOrientation = M3D_QMultiply(vOrientation, Rotation);
|
vOrientation = M3D_QMultiply(vOrientation, Rotation);
|
||||||
|
|
||||||
// Transform the center.
|
// Transform the center.
|
||||||
|
@ -591,7 +591,7 @@ INLINE_AVX_FIX M3D_MATRIX M3D_MInverse(M3D_MATRIX M) noexcept {
|
|||||||
|
|
||||||
/* -------------------------------------------------------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
INLINE_AVX_FIX M3D_VECTOR M3D_QRotationMatrix(M3D_MATRIX M) noexcept {
|
INLINE_AVX_FIX M3D_VECTOR M3D_QRotationFromMatrix(M3D_MATRIX M) noexcept {
|
||||||
#ifdef DISABLE_INTRINSICS
|
#ifdef DISABLE_INTRINSICS
|
||||||
M3D_V4F32 q;
|
M3D_V4F32 q;
|
||||||
float r22 = M.mat[2][2];
|
float r22 = M.mat[2][2];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user