fix frustum culling to use row major matrix

This commit is contained in:
Skarn
2021-11-26 23:13:43 +03:00
parent f418d25aa7
commit 57172101a6
4 changed files with 22 additions and 26 deletions

View File

@@ -3,23 +3,24 @@
#include <math/frustum.hpp>
#include <array>
#include <external/glm/glm.hpp>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_access.hpp>
namespace math
{
frustum::frustum (glm::mat4x4 const& matrix)
{
const glm::vec4 column_0 = matrix[0];
const glm::vec4 column_1 = matrix[1];
const glm::vec4 column_2 = matrix[2];
const glm::vec4 column_3 = matrix[3];
const glm::vec4 row_0 = glm::row(matrix, 0);
const glm::vec4 row_1 = glm::row(matrix, 1);
const glm::vec4 row_2 = glm::row(matrix, 2);
const glm::vec4 row_3 = glm::row(matrix, 3);
_planes[RIGHT] = column_3 - column_0;
_planes[LEFT] = column_3 + column_0;
_planes[TOP] = column_3 - column_1;
_planes[BOTTOM] = column_3 + column_1;
_planes[BACK] = column_3 - column_2;
_planes[FRONT] = column_3 + column_2;
_planes[RIGHT] = row_3 - row_0;
_planes[LEFT] = row_3 + row_0;
_planes[TOP] = row_3 - row_1;
_planes[BOTTOM] = row_3 + row_1;
_planes[BACK] = row_3 - row_2;
_planes[FRONT] = row_3 + row_2;
}
bool frustum::contains (const glm::vec3& point) const

View File

@@ -21,6 +21,7 @@
#include <map>
#include <QPixmap>
#include <QImage>
#include <limits>
MapChunk::MapChunk(MapTile *maintile, MPQFile *f, bool bigAlpha,
tile_mode mode, noggit::NoggitRenderContext context, bool init_empty, int chunk_idx)
@@ -28,12 +29,15 @@ MapChunk::MapChunk(MapTile *maintile, MPQFile *f, bool bigAlpha,
, mt(maintile)
, use_big_alphamap(bigAlpha)
, _context(context)
, vmin(std::numeric_limits<float>::max())
, vmax(std::numeric_limits<float>::lowest())
, _chunk_update_flags(ChunkUpdateFlags::VERTEX | ChunkUpdateFlags::ALPHAMAP
| ChunkUpdateFlags::SHADOW | ChunkUpdateFlags::MCCV
| ChunkUpdateFlags::NORMALS| ChunkUpdateFlags::HOLES
| ChunkUpdateFlags::AREA_ID| ChunkUpdateFlags::FLAGS)
{
if (init_empty)
{
@@ -76,10 +80,6 @@ MapChunk::MapChunk(MapTile *maintile, MPQFile *f, bool bigAlpha,
zbase = zbase*-1.0f + ZEROPOINT;
xbase = xbase*-1.0f + ZEROPOINT;
vmin.y = 0.0f;
vmin = glm::vec3(9999999.0f, 9999999.0f, 9999999.0f);
vmax = glm::vec3(-9999999.0f, -9999999.0f, -9999999.0f);
glm::vec3 *ttv = mVertices;
for (int j = 0; j < 17; ++j) {
@@ -145,9 +145,6 @@ MapChunk::MapChunk(MapTile *maintile, MPQFile *f, bool bigAlpha,
// correct the x and z values ^_^
zbase = zbase*-1.0f + ZEROPOINT;
xbase = xbase*-1.0f + ZEROPOINT;
vmin = glm::vec3(std::numeric_limits<float>::max(), std::numeric_limits<float>::max(), std::numeric_limits<float>::max());
vmax = glm::vec3(std::numeric_limits<float>::lowest(), std::numeric_limits<float>::lowest(), std::numeric_limits<float>::lowest());
}
texture_set = std::make_unique<TextureSet>(this, f, base, maintile, bigAlpha,

View File

@@ -17,8 +17,6 @@ ModelInstance::ModelInstance(std::string const& filename, noggit::NoggitRenderCo
: SceneObject(SceneObjectTypes::eMODEL, context, filename)
, model (filename, context)
{
pos = glm::vec3(0.f, 0.f, 0.f);
dir = math::degrees::vec3(0, 0, 0);
}
ModelInstance::ModelInstance(std::string const& filename, ENTRY_MDDF const*d, noggit::NoggitRenderContext context)

View File

@@ -6,12 +6,18 @@
#include <glm/gtx/euler_angles.hpp>
#include <noggit/Misc.h>
#include <math/trig.hpp>
#include <limits>
SceneObject::SceneObject(SceneObjectTypes type, noggit::NoggitRenderContext context, std::string filename)
: _type(type)
, _filename(filename)
, _context(context)
, pos(0.f, 0.f, 0.f)
, dir(0.f, 0.f, 0.f)
{
// min and max initialized to their opposites
extents[0] = glm::vec3(std::numeric_limits<float>::max());
extents[1] = glm::vec3(std::numeric_limits<float>::lowest());
}
bool SceneObject::isInsideRect(std::array<glm::vec3, 2> const* rect) const
@@ -29,14 +35,8 @@ bool SceneObject::isDuplicateOf(SceneObject const& other)
void SceneObject::updateTransformMatrix()
{
auto rotationVector = glm::vec3(0);
rotationVector.z = glm::radians(dir.y - math::degrees(90.0)._);
rotationVector.y = glm::radians(-dir.z);
rotationVector.x = glm::radians(dir.x);
auto matrix = glm::mat4x4(1);
matrix = glm::translate(matrix, pos);
glm::quat roationQuat = glm::quat(rotationVector);
matrix = matrix * glm::eulerAngleYZX(glm::radians(dir.y - math::degrees(90.0)._), glm::radians(-dir.x), glm::radians(dir.z));
matrix = glm::scale(matrix, glm::vec3(scale, scale, scale));