Refactor OrientedBoundingBox to use Transform for transformation instead of Matrix (for large worlds)

This commit is contained in:
Wojtek Figat
2022-06-16 10:51:59 +02:00
parent 995e5bc6ff
commit 9ba117cde3
16 changed files with 168 additions and 780 deletions

View File

@@ -1,6 +1,7 @@
// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
#include "BoxBrush.h"
#include "Engine/Core/Math/Matrix.h"
#include "Engine/Content/Content.h"
#include "Engine/Serialization/Serialization.h"
#include "Engine/Level/Scene/Scene.h"

View File

@@ -190,7 +190,7 @@ private:
FORCE_INLINE void UpdateBounds()
{
OrientedBoundingBox::CreateCentered(_center, _size, _bounds);
_bounds.Transform(_transform.GetWorld());
_bounds.Transform(_transform);
_bounds.GetBoundingBox(_box);
BoundingSphere::FromBox(_box, _sphere);
}

View File

@@ -1,6 +1,7 @@
// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
#include "BoxVolume.h"
#include "Engine/Core/Math/Matrix.h"
#include "Engine/Serialization/Serialization.h"
BoxVolume::BoxVolume(const SpawnParams& params)
@@ -54,11 +55,13 @@ namespace
else
Quaternion::LookRotation(dir, Vector3::Cross(Vector3::Cross(dir, Vector3::Up), dir), orientation);
const Vector3 up = orientation * Vector3::Up;
Matrix::CreateWorld(min + vec * 0.5f, dir, up, box.Transformation);
Matrix inv;
Matrix::Invert(box.Transformation, inv);
Matrix world;
Matrix::CreateWorld(min + vec * 0.5f, dir, up, world);
world.Decompose(box.Transformation);
Matrix invWorld;
Matrix::Invert(world, invWorld);
Vector3 vecLocal;
Vector3::TransformNormal(vec * 0.5f, inv, vecLocal);
Vector3::TransformNormal(vec * 0.5f, invWorld, vecLocal);
box.Extents.X = margin;
box.Extents.Y = margin;
box.Extents.Z = vecLocal.Z;

View File

@@ -15,7 +15,7 @@ Decal::Decal(const SpawnParams& params)
{
_world = Matrix::Scaling(_size);
_bounds.Extents = Vector3::Half;
_bounds.Transformation = _world;
_world.Decompose(_bounds.Transformation);
_bounds.GetBoundingBox(_box);
BoundingSphere::FromBox(_box, _sphere);
}
@@ -30,8 +30,8 @@ void Decal::SetSize(const Vector3& value)
Transform t = _transform;
t.Scale *= _size;
t.GetWorld(_world);
_bounds.Extents = Vector3::Half;
_bounds.Transformation = _world;
_bounds.Transformation = t;
_bounds.GetBoundingBox(_box);
BoundingSphere::FromBox(_box, _sphere);
}
@@ -152,7 +152,7 @@ void Decal::OnTransformChanged()
t.GetWorld(_world);
_bounds.Extents = Vector3::Half;
_bounds.Transformation = _world;
_bounds.Transformation = t;
_bounds.GetBoundingBox(_box);
BoundingSphere::FromBox(_box, _sphere);

View File

@@ -3,6 +3,7 @@
#pragma once
#include "../Actor.h"
#include "Engine/Core/Math/Matrix.h"
#include "Engine/Core/Math/OrientedBoundingBox.h"
#include "Engine/Content/Assets/MaterialBase.h"
#include "Engine/Content/AssetReference.h"