More cleanups of custom classes in favor of .NET runtime types.
This commit is contained in:
@@ -15,11 +15,12 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.GameMath;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Framework.Constants;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Game.Collision
|
||||
{
|
||||
@@ -64,13 +65,13 @@ namespace Game.Collision
|
||||
iScale = modelOwner.GetScale();
|
||||
iInvScale = 1.0f / iScale;
|
||||
|
||||
Matrix3 iRotation = Matrix3.fromEulerAnglesZYX(modelOwner.GetOrientation(), 0, 0);
|
||||
iInvRot = iRotation.inverse();
|
||||
Matrix4x4 iRotation = Extensions.fromEulerAnglesZYX(modelOwner.GetOrientation(), 0, 0);
|
||||
Matrix4x4.Invert(iRotation, out iInvRot);
|
||||
// transform bounding box:
|
||||
mdl_box = new AxisAlignedBox(mdl_box.Lo * iScale, mdl_box.Hi * iScale);
|
||||
AxisAlignedBox rotated_bounds = new();
|
||||
for (int i = 0; i < 8; ++i)
|
||||
rotated_bounds.merge(iRotation * mdl_box.corner(i));
|
||||
rotated_bounds.merge(Vector3.Transform(mdl_box.corner(i), iRotation));
|
||||
|
||||
iBound = rotated_bounds + iPos;
|
||||
owner = modelOwner;
|
||||
@@ -100,8 +101,8 @@ namespace Game.Collision
|
||||
return false;
|
||||
|
||||
// child bounds are defined in object space:
|
||||
Vector3 p = iInvRot * (ray.Origin - iPos) * iInvScale;
|
||||
Ray modRay = new(p, iInvRot * ray.Direction);
|
||||
Vector3 p = Vector3.Transform((ray.Origin - iPos) * iInvScale, iInvRot);
|
||||
Ray modRay = new Ray(p, Vector3.Transform(ray.Direction, iInvRot));
|
||||
float distance = maxDist * iInvScale;
|
||||
bool hit = iModel.IntersectRay(modRay, ref distance, stopAtFirstHit, ignoreFlags);
|
||||
if (hit)
|
||||
@@ -124,13 +125,13 @@ namespace Game.Collision
|
||||
return;
|
||||
|
||||
// child bounds are defined in object space:
|
||||
Vector3 pModel = iInvRot * (point - iPos) * iInvScale;
|
||||
Vector3 zDirModel = iInvRot * new Vector3(0.0f, 0.0f, -1.0f);
|
||||
Vector3 pModel = Vector3.Transform((point - iPos) * iInvScale, iInvRot);
|
||||
Vector3 zDirModel = Vector3.Transform(new Vector3(0.0f, 0.0f, -1.0f), iInvRot);
|
||||
float zDist;
|
||||
if (iModel.IntersectPoint(pModel, zDirModel, out zDist, info))
|
||||
{
|
||||
Vector3 modelGround = pModel + zDist * zDirModel;
|
||||
float world_Z = ((modelGround * iInvRot) * iScale + iPos).Z;
|
||||
float world_Z = (Vector3.Transform(modelGround, iInvRot) * iScale + iPos).Z;
|
||||
if (info.ground_Z < world_Z)
|
||||
{
|
||||
info.ground_Z = world_Z;
|
||||
@@ -151,13 +152,13 @@ namespace Game.Collision
|
||||
return false;
|
||||
|
||||
// child bounds are defined in object space:
|
||||
Vector3 pModel = iInvRot * (point - iPos) * iInvScale;
|
||||
Vector3 zDirModel = iInvRot * new Vector3(0.0f, 0.0f, -1.0f);
|
||||
Vector3 pModel = Vector3.Transform((point - iPos) * iInvScale, iInvRot);
|
||||
Vector3 zDirModel = Vector3.Transform(new Vector3(0.0f, 0.0f, -1.0f), iInvRot);
|
||||
float zDist;
|
||||
if (iModel.GetLocationInfo(pModel, zDirModel, out zDist, info))
|
||||
{
|
||||
Vector3 modelGround = pModel + zDist * zDirModel;
|
||||
float world_Z = ((modelGround * iInvRot) * iScale + iPos).Z;
|
||||
float world_Z = (Vector3.Transform(modelGround, iInvRot) * iScale + iPos).Z;
|
||||
if (info.ground_Z < world_Z)
|
||||
{
|
||||
info.ground_Z = world_Z;
|
||||
@@ -171,7 +172,7 @@ namespace Game.Collision
|
||||
public bool GetLiquidLevel(Vector3 point, LocationInfo info, ref float liqHeight)
|
||||
{
|
||||
// child bounds are defined in object space:
|
||||
Vector3 pModel = iInvRot * (point - iPos) * iInvScale;
|
||||
Vector3 pModel = Vector3.Transform((point - iPos) * iInvScale, iInvRot);
|
||||
//Vector3 zDirModel = iInvRot * Vector3(0.f, 0.f, -1.f);
|
||||
float zDist;
|
||||
if (info.hitModel.GetLiquidLevel(pModel, out zDist))
|
||||
@@ -203,13 +204,13 @@ namespace Game.Collision
|
||||
|
||||
iPos = owner.GetPosition();
|
||||
|
||||
Matrix3 iRotation = Matrix3.fromEulerAnglesZYX(owner.GetOrientation(), 0, 0);
|
||||
iInvRot = iRotation.inverse();
|
||||
Matrix4x4 iRotation = Extensions.fromEulerAnglesZYX(owner.GetOrientation(), 0, 0);
|
||||
Matrix4x4.Invert(iRotation, out iInvRot);
|
||||
// transform bounding box:
|
||||
mdl_box = new AxisAlignedBox(mdl_box.Lo * iScale, mdl_box.Hi * iScale);
|
||||
AxisAlignedBox rotated_bounds = new();
|
||||
for (int i = 0; i < 8; ++i)
|
||||
rotated_bounds.merge(iRotation * mdl_box.corner(i));
|
||||
rotated_bounds.merge(Vector3.Transform(mdl_box.corner(i), iRotation));
|
||||
|
||||
iBound = rotated_bounds + iPos;
|
||||
|
||||
@@ -269,7 +270,7 @@ namespace Game.Collision
|
||||
|
||||
bool _collisionEnabled;
|
||||
AxisAlignedBox iBound;
|
||||
Matrix3 iInvRot;
|
||||
Matrix4x4 iInvRot;
|
||||
Vector3 iPos;
|
||||
float iInvScale;
|
||||
float iScale;
|
||||
|
||||
@@ -15,8 +15,9 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.GameMath;
|
||||
using Framework.Constants;
|
||||
using Framework.GameMath;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Game.Collision
|
||||
{
|
||||
|
||||
@@ -19,6 +19,7 @@ using Framework.Constants;
|
||||
using Framework.GameMath;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Game.Collision
|
||||
{
|
||||
@@ -85,7 +86,7 @@ namespace Game.Collision
|
||||
|
||||
public class ModelInstance : ModelMinimalData
|
||||
{
|
||||
Matrix3 iInvRot;
|
||||
Matrix4x4 iInvRot;
|
||||
float iInvScale;
|
||||
WorldModel iModel;
|
||||
|
||||
@@ -107,7 +108,8 @@ namespace Game.Collision
|
||||
|
||||
iModel = model;
|
||||
|
||||
iInvRot = Matrix3.fromEulerAnglesZYX(MathFunctions.PI * spawn.iRot.Y / 180.0f, MathFunctions.PI * spawn.iRot.X / 180.0f, MathFunctions.PI * spawn.iRot.Z / 180.0f).inverse();
|
||||
Matrix4x4.Invert(Extensions.fromEulerAnglesZYX(MathFunctions.PI * spawn.iRot.Y / 180.0f, MathFunctions.PI * spawn.iRot.X / 180.0f, MathFunctions.PI * spawn.iRot.Z / 180.0f), out iInvRot);
|
||||
|
||||
iInvScale = 1.0f / iScale;
|
||||
}
|
||||
|
||||
@@ -121,8 +123,8 @@ namespace Game.Collision
|
||||
return false;
|
||||
|
||||
// child bounds are defined in object space:
|
||||
Vector3 p = iInvRot * (pRay.Origin - iPos) * iInvScale;
|
||||
Ray modRay = new(p, iInvRot * pRay.Direction);
|
||||
Vector3 p = Vector3.Transform((pRay.Origin - iPos) * iInvScale, iInvRot);
|
||||
Ray modRay = new Ray(p, Vector3.Transform(pRay.Direction, iInvRot));
|
||||
float distance = pMaxDist * iInvScale;
|
||||
bool hit = iModel.IntersectRay(modRay, ref distance, pStopAtFirstHit, ignoreFlags);
|
||||
if (hit)
|
||||
@@ -144,8 +146,8 @@ namespace Game.Collision
|
||||
if (!iBound.contains(p))
|
||||
return;
|
||||
// child bounds are defined in object space:
|
||||
Vector3 pModel = iInvRot * (p - iPos) * iInvScale;
|
||||
Vector3 zDirModel = iInvRot * new Vector3(0.0f, 0.0f, -1.0f);
|
||||
Vector3 pModel = Vector3.Transform((p - iPos) * iInvScale, iInvRot);
|
||||
Vector3 zDirModel = Vector3.Transform(new Vector3(0.0f, 0.0f, -1.0f), iInvRot);
|
||||
float zDist;
|
||||
if (iModel.IntersectPoint(pModel, zDirModel, out zDist, info))
|
||||
{
|
||||
@@ -153,7 +155,7 @@ namespace Game.Collision
|
||||
// Transform back to world space. Note that:
|
||||
// Mat * vec == vec * Mat.transpose()
|
||||
// and for rotation matrices: Mat.inverse() == Mat.transpose()
|
||||
float world_Z = ((modelGround * iInvRot) * iScale + iPos).Z;
|
||||
float world_Z = ((Vector3.Transform(modelGround, iInvRot)) * iScale + iPos).Z;
|
||||
if (info.ground_Z < world_Z)
|
||||
{
|
||||
info.ground_Z = world_Z;
|
||||
@@ -165,7 +167,7 @@ namespace Game.Collision
|
||||
public bool GetLiquidLevel(Vector3 p, LocationInfo info, ref float liqHeight)
|
||||
{
|
||||
// child bounds are defined in object space:
|
||||
Vector3 pModel = iInvRot * (p - iPos) * iInvScale;
|
||||
Vector3 pModel = Vector3.Transform((p - iPos) * iInvScale, iInvRot);
|
||||
//Vector3 zDirModel = iInvRot * Vector3(0.f, 0.f, -1.f);
|
||||
float zDist;
|
||||
if (info.hitModel.GetLiquidLevel(pModel, out zDist))
|
||||
@@ -189,8 +191,8 @@ namespace Game.Collision
|
||||
if (!iBound.contains(p))
|
||||
return false;
|
||||
// child bounds are defined in object space:
|
||||
Vector3 pModel = iInvRot * (p - iPos) * iInvScale;
|
||||
Vector3 zDirModel = iInvRot * new Vector3(0.0f, 0.0f, -1.0f);
|
||||
Vector3 pModel = Vector3.Transform((p - iPos) * iInvScale, iInvRot);
|
||||
Vector3 zDirModel = Vector3.Transform(new Vector3(0.0f, 0.0f, -1.0f), iInvRot);
|
||||
float zDist;
|
||||
if (iModel.GetLocationInfo(pModel, zDirModel, out zDist, info))
|
||||
{
|
||||
@@ -198,7 +200,7 @@ namespace Game.Collision
|
||||
// Transform back to world space. Note that:
|
||||
// Mat * vec == vec * Mat.transpose()
|
||||
// and for rotation matrices: Mat.inverse() == Mat.transpose()
|
||||
float world_Z = ((modelGround * iInvRot) * iScale + iPos).Z;
|
||||
float world_Z = (Vector3.Transform(modelGround, iInvRot) * iScale + iPos).Z;
|
||||
if (info.ground_Z < world_Z) // hm...could it be handled automatically with zDist at intersection?
|
||||
{
|
||||
info.ground_Z = world_Z;
|
||||
|
||||
@@ -20,6 +20,7 @@ using Framework.GameMath;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Game.Collision
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user