Terrain rendering hack
This commit is contained in:
parent
29935cf54e
commit
bf7b10850e
@ -1,5 +1,7 @@
|
||||
#include "3DRenderer.hpp"
|
||||
|
||||
#include <SFML/Graphics/RectangleShape.hpp>
|
||||
|
||||
#include "../World/DbgCube.hpp"
|
||||
#include "../World/Tank.hpp"
|
||||
|
||||
@ -99,12 +101,33 @@ void Graphic3DRenderer::Draw(sf::RenderTexture& context) {
|
||||
|
||||
// Load main matrices
|
||||
M3D_MATRIX viewMat = mMainCamera->GetView();
|
||||
M3D_MATRIX invViewMat = M3D_MInverse(viewMat); // aka. camMat
|
||||
M3D_MATRIX projMat = mMainCamera->GetProj();
|
||||
M3D_MATRIX viewProjMat = viewMat * projMat;
|
||||
|
||||
// Create the frustrum "box"
|
||||
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
|
||||
for (auto& obj : mRenderList) {
|
||||
@ -120,7 +143,7 @@ void Graphic3DRenderer::Draw(sf::RenderTexture& context) {
|
||||
{
|
||||
size_t vCount = obj->GetObjectVerticesCount();
|
||||
auto& oMesh = obj->GetObjectMesh();
|
||||
auto* projVertices = new M3D_F4[vCount];
|
||||
M3D_F4 projVertices[vCount] = {};
|
||||
|
||||
// Vertices homogeneous clip space transformation
|
||||
M3D_V3Transform(
|
||||
@ -131,7 +154,7 @@ void Graphic3DRenderer::Draw(sf::RenderTexture& context) {
|
||||
);
|
||||
|
||||
// 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) {
|
||||
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_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); }
|
||||
const M3D_F4X4& GetView4x4f() const { return mViewMat; }
|
||||
M3D_MATRIX GetProj() const { return M3D_V4LoadF4x4(&mProjMat); }
|
||||
|
@ -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_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[2] = M3D_V3Normalize(M.rows[2]);
|
||||
nM.rows[3] = M3D_MIdentityR3;
|
||||
M3D_VECTOR Rotation = M3D_QRotationMatrix(nM);
|
||||
M3D_VECTOR Rotation = M3D_QRotationFromMatrix(nM);
|
||||
vOrientation = M3D_QMultiply(vOrientation, Rotation);
|
||||
|
||||
// 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
|
||||
M3D_V4F32 q;
|
||||
float r22 = M.mat[2][2];
|
||||
|
Loading…
x
Reference in New Issue
Block a user