Made Math::Matrix an alias to glm::mat4, partial refactors
parent
e5d8e2b428
commit
208f142cd2
|
@ -38,11 +38,6 @@
|
|||
class CImage;
|
||||
struct ImageData;
|
||||
|
||||
namespace Math
|
||||
{
|
||||
struct Matrix;
|
||||
} // namespace Math
|
||||
|
||||
|
||||
// Graphics module namespace
|
||||
namespace Gfx
|
||||
|
@ -454,7 +449,7 @@ public:
|
|||
virtual void Restore() = 0;
|
||||
|
||||
//! Sets the transform matrix of given type
|
||||
virtual void SetTransform(TransformType type, const Math::Matrix &matrix) = 0;
|
||||
virtual void SetTransform(TransformType type, const glm::mat4 &matrix) = 0;
|
||||
|
||||
//! Sets the current material
|
||||
virtual void SetMaterial(const Material &material) = 0;
|
||||
|
@ -521,10 +516,6 @@ public:
|
|||
virtual void DrawVertexBuffer(CVertexBuffer*) = 0;
|
||||
virtual void DestroyVertexBuffer(CVertexBuffer*) = 0;
|
||||
|
||||
//! Tests whether a sphere is (partially) within the frustum volume
|
||||
//! Returns a mask of frustum planes for which the test is positive
|
||||
virtual int ComputeSphereVisibility(const glm::vec3& center, float radius) = 0;
|
||||
|
||||
//! Changes rendering viewport
|
||||
virtual void SetViewport(int x, int y, int width, int height) = 0;
|
||||
|
||||
|
|
|
@ -127,8 +127,7 @@ void CCloud::Draw()
|
|||
|
||||
m_engine->SetState(ENG_RSTATE_TTEXTURE_BLACK | ENG_RSTATE_FOG | ENG_RSTATE_WRAP);
|
||||
|
||||
Math::Matrix matrix;
|
||||
matrix.LoadIdentity();
|
||||
Math::Matrix matrix = glm::mat4(1.0f);
|
||||
device->SetTransform(TRANSFORM_WORLD, matrix);
|
||||
|
||||
float size = m_brickSize/2.0f;
|
||||
|
|
|
@ -235,7 +235,7 @@ CEngine::CEngine(CApplication *app, CSystemUtils* systemUtils)
|
|||
Math::Matrix temp1, temp2;
|
||||
Math::LoadScaleMatrix(temp1, glm::vec3(0.5f, 0.5f, 0.5f));
|
||||
Math::LoadTranslationMatrix(temp2, glm::vec3(1.0f, 1.0f, 1.0f));
|
||||
m_shadowBias = Math::MultiplyMatrices(temp1, temp2);
|
||||
m_shadowBias = temp1 * temp2;
|
||||
|
||||
m_lastState = -1;
|
||||
m_statisticTriangle = 0;
|
||||
|
@ -350,8 +350,8 @@ bool CEngine::Create()
|
|||
|
||||
SetFocus(m_focus);
|
||||
|
||||
m_matWorldInterface.LoadIdentity();
|
||||
m_matViewInterface.LoadIdentity();
|
||||
m_matWorldInterface = glm::mat4(1.0f);
|
||||
m_matViewInterface = glm::mat4(1.0f);
|
||||
|
||||
auto renderer = m_device->GetUIRenderer();
|
||||
renderer->SetProjection(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
|
@ -900,7 +900,7 @@ int CEngine::CreateObject()
|
|||
m_objects[objRank].used = true;
|
||||
|
||||
Math::Matrix mat;
|
||||
mat.LoadIdentity();
|
||||
mat = glm::mat4(1.0f);
|
||||
SetObjectTransform(objRank, mat);
|
||||
|
||||
m_objects[objRank].drawWorld = true;
|
||||
|
@ -1644,9 +1644,9 @@ void CEngine::ComputeDistance()
|
|||
continue;
|
||||
|
||||
glm::vec3 v{};
|
||||
v.x = m_eyePt.x - m_objects[i].transform.Get(1, 4);
|
||||
v.y = m_eyePt.y - m_objects[i].transform.Get(2, 4);
|
||||
v.z = m_eyePt.z - m_objects[i].transform.Get(3, 4);
|
||||
v.x = m_eyePt.x - m_objects[i].transform[3][0];
|
||||
v.y = m_eyePt.y - m_objects[i].transform[3][1];
|
||||
v.z = m_eyePt.z - m_objects[i].transform[3][2];
|
||||
m_objects[i].distance = glm::length(v);
|
||||
}
|
||||
}
|
||||
|
@ -1910,13 +1910,16 @@ bool CEngine::DetectTriangle(const glm::vec2& mouse, Vertex3D* triangle, int obj
|
|||
if (! Math::IsInsideTriangle(a, b, c, mouse))
|
||||
return false;
|
||||
|
||||
auto matViewInverse = glm::inverse(m_matView);
|
||||
auto matProjInverse = glm::inverse(m_matProj);
|
||||
|
||||
glm::vec3 a2 = Math::Transform(m_objects[objRank].transform, triangle[0].position);
|
||||
glm::vec3 b2 = Math::Transform(m_objects[objRank].transform, triangle[1].position);
|
||||
glm::vec3 c2 = Math::Transform(m_objects[objRank].transform, triangle[2].position);
|
||||
glm::vec3 e = Math::Transform(m_matView.Inverse(), glm::vec3(0.0f, 0.0f, -1.0f));
|
||||
glm::vec3 f = Math::Transform(m_matView.Inverse(), glm::vec3(
|
||||
(mouse.x*2.0f-1.0f)*m_matProj.Inverse().Get(1,1),
|
||||
(mouse.y*2.0f-1.0f)*m_matProj.Inverse().Get(2,2),
|
||||
glm::vec3 e = Math::Transform(matViewInverse, glm::vec3(0.0f, 0.0f, -1.0f));
|
||||
glm::vec3 f = Math::Transform(matViewInverse, glm::vec3(
|
||||
(mouse.x*2.0f-1.0f) * matProjInverse[0][0],
|
||||
(mouse.y*2.0f-1.0f) * matProjInverse[1][1],
|
||||
0.0f));
|
||||
Math::Intersect(a2, b2, c2, e, f, pos);
|
||||
|
||||
|
@ -1952,52 +1955,52 @@ int CEngine::ComputeSphereVisibility(const Math::Matrix& m, const glm::vec3& cen
|
|||
float originPlane[6];
|
||||
|
||||
// Left plane
|
||||
vec[0].x = m.Get(4, 1) + m.Get(1, 1);
|
||||
vec[0].y = m.Get(4, 2) + m.Get(1, 2);
|
||||
vec[0].z = m.Get(4, 3) + m.Get(1, 3);
|
||||
vec[0].x = m[0][3] + m[0][0];
|
||||
vec[0].y = m[1][3] + m[1][0];
|
||||
vec[0].z = m[2][3] + m[2][0];
|
||||
float l1 = glm::length(vec[0]);
|
||||
vec[0] = glm::normalize(vec[0]);
|
||||
originPlane[0] = (m.Get(4, 4) + m.Get(1, 4)) / l1;
|
||||
originPlane[0] = (m[3][3] + m[3][0]) / l1;
|
||||
|
||||
// Right plane
|
||||
vec[1].x = m.Get(4, 1) - m.Get(1, 1);
|
||||
vec[1].y = m.Get(4, 2) - m.Get(1, 2);
|
||||
vec[1].z = m.Get(4, 3) - m.Get(1, 3);
|
||||
vec[1].x = m[0][3] - m[0][0];
|
||||
vec[1].y = m[1][3] - m[1][0];
|
||||
vec[1].z = m[2][3] - m[2][0];
|
||||
float l2 = glm::length(vec[1]);
|
||||
vec[1] = glm::normalize(vec[1]);
|
||||
originPlane[1] = (m.Get(4, 4) - m.Get(1, 4)) / l2;
|
||||
originPlane[1] = (m[3][3] - m[3][0]) / l2;
|
||||
|
||||
// Bottom plane
|
||||
vec[2].x = m.Get(4, 1) + m.Get(2, 1);
|
||||
vec[2].y = m.Get(4, 2) + m.Get(2, 2);
|
||||
vec[2].z = m.Get(4, 3) + m.Get(2, 3);
|
||||
vec[2].x = m[0][3] + m[1][0];
|
||||
vec[2].y = m[1][3] + m[1][1];
|
||||
vec[2].z = m[3][2] + m[1][2];
|
||||
float l3 = glm::length(vec[2]);
|
||||
vec[2] = glm::normalize(vec[2]);
|
||||
originPlane[2] = (m.Get(4, 4) + m.Get(2, 4)) / l3;
|
||||
originPlane[2] = (m[3][3] + m[3][1]) / l3;
|
||||
|
||||
// Top plane
|
||||
vec[3].x = m.Get(4, 1) - m.Get(2, 1);
|
||||
vec[3].y = m.Get(4, 2) - m.Get(2, 2);
|
||||
vec[3].z = m.Get(4, 3) - m.Get(2, 3);
|
||||
vec[3].x = m[0][3] - m[0][1];
|
||||
vec[3].y = m[1][3] - m[1][1];
|
||||
vec[3].z = m[2][3] - m[2][1];
|
||||
float l4 = glm::length(vec[3]);
|
||||
vec[3] = glm::normalize(vec[3]);
|
||||
originPlane[3] = (m.Get(4, 4) - m.Get(2, 4)) / l4;
|
||||
originPlane[3] = (m[3][3] - m[3][1]) / l4;
|
||||
|
||||
// Front plane
|
||||
vec[4].x = m.Get(4, 1) + m.Get(3, 1);
|
||||
vec[4].y = m.Get(4, 2) + m.Get(3, 2);
|
||||
vec[4].z = m.Get(4, 3) + m.Get(3, 3);
|
||||
vec[4].x = m[0][3] + m[0][2];
|
||||
vec[4].y = m[1][3] + m[1][2];
|
||||
vec[4].z = m[2][3] + m[2][2];
|
||||
float l5 = glm::length(vec[4]);
|
||||
vec[4] = glm::normalize(vec[4]);
|
||||
originPlane[4] = (m.Get(4, 4) + m.Get(3, 4)) / l5;
|
||||
originPlane[4] = (m[3][3] + m[3][2]) / l5;
|
||||
|
||||
// Back plane
|
||||
vec[5].x = m.Get(4, 1) - m.Get(3, 1);
|
||||
vec[5].y = m.Get(4, 2) - m.Get(3, 2);
|
||||
vec[5].z = m.Get(4, 3) - m.Get(3, 3);
|
||||
vec[5].x = m[0][3] - m[0][2];
|
||||
vec[5].y = m[1][3] - m[1][2];
|
||||
vec[5].z = m[2][3] - m[2][2];
|
||||
float l6 = glm::length(vec[5]);
|
||||
vec[5] = glm::normalize(vec[5]);
|
||||
originPlane[5] = (m.Get(4, 4) - m.Get(3, 4)) / l6;
|
||||
originPlane[5] = (m[3][3] - m[3][2]) / l6;
|
||||
|
||||
int result = 0;
|
||||
|
||||
|
@ -2037,8 +2040,8 @@ bool CEngine::TransformPoint(glm::vec3& p2D, int objRank, glm::vec3 p3D)
|
|||
if (p3D.z < 2.0f)
|
||||
return false; // behind?
|
||||
|
||||
p2D.x = (p3D.x/p3D.z)*m_matProj.Get(1,1);
|
||||
p2D.y = (p3D.y/p3D.z)*m_matProj.Get(2,2);
|
||||
p2D.x = (p3D.x/p3D.z)*m_matProj[0][0];
|
||||
p2D.y = (p3D.y/p3D.z)*m_matProj[1][1];
|
||||
p2D.z = p3D.z;
|
||||
|
||||
p2D.x = (p2D.x+1.0f)/2.0f; // [-1..1] -> [0..1]
|
||||
|
@ -3423,10 +3426,10 @@ void CEngine::Draw3DScene()
|
|||
|
||||
terrainRenderer->SetFog(fogStart, fogEnd, { fogColor.r, fogColor.g, fogColor.b });
|
||||
|
||||
Math::Matrix scale;
|
||||
scale.Set(3, 3, -1.0f);
|
||||
auto projectionViewMatrix = Math::MultiplyMatrices(m_matProj, scale);
|
||||
projectionViewMatrix = Math::MultiplyMatrices(projectionViewMatrix, m_matView);
|
||||
glm::mat4 scale = glm::mat4(1.0f);
|
||||
scale[2][2] = -1.0f;
|
||||
auto projectionViewMatrix = m_matProj * scale;
|
||||
projectionViewMatrix = projectionViewMatrix * m_matView;
|
||||
|
||||
for (int objRank = 0; objRank < static_cast<int>(m_objects.size()); objRank++)
|
||||
{
|
||||
|
@ -3439,7 +3442,7 @@ void CEngine::Draw3DScene()
|
|||
if (! m_objects[objRank].drawWorld)
|
||||
continue;
|
||||
|
||||
auto combinedMatrix = Math::MultiplyMatrices(projectionViewMatrix, m_objects[objRank].transform);
|
||||
auto combinedMatrix = projectionViewMatrix * m_objects[objRank].transform;
|
||||
|
||||
if (! IsVisible(combinedMatrix, objRank))
|
||||
continue;
|
||||
|
@ -3515,7 +3518,7 @@ void CEngine::Draw3DScene()
|
|||
if (! m_objects[objRank].drawWorld)
|
||||
continue;
|
||||
|
||||
auto combinedMatrix = Math::MultiplyMatrices(projectionViewMatrix, m_objects[objRank].transform);
|
||||
auto combinedMatrix = projectionViewMatrix * m_objects[objRank].transform;
|
||||
|
||||
if (! IsVisible(combinedMatrix, objRank))
|
||||
continue;
|
||||
|
@ -3600,7 +3603,7 @@ void CEngine::Draw3DScene()
|
|||
if (! m_objects[objRank].drawWorld)
|
||||
continue;
|
||||
|
||||
auto combinedMatrix = Math::MultiplyMatrices(projectionViewMatrix, m_objects[objRank].transform);
|
||||
auto combinedMatrix = projectionViewMatrix * m_objects[objRank].transform;
|
||||
|
||||
if (! IsVisible(combinedMatrix, objRank))
|
||||
continue;
|
||||
|
@ -3667,8 +3670,7 @@ void CEngine::Draw3DScene()
|
|||
|
||||
if (m_debugGoto)
|
||||
{
|
||||
Math::Matrix worldMatrix;
|
||||
worldMatrix.LoadIdentity();
|
||||
Math::Matrix worldMatrix = glm::mat4(1.0f);
|
||||
m_device->SetTransform(TRANSFORM_WORLD, worldMatrix);
|
||||
|
||||
SetState(ENG_RSTATE_OPAQUE_COLOR);
|
||||
|
@ -4079,7 +4081,7 @@ void CEngine::RenderShadowMap()
|
|||
pos.z = round(pos.z);
|
||||
pos *= worldUnitsPerTexel;
|
||||
// ...and convert back to world space.
|
||||
pos = Math::MatrixVectorMultiply(lightRotation.Inverse(), pos);
|
||||
pos = Math::MatrixVectorMultiply(glm::inverse(lightRotation), pos);
|
||||
}
|
||||
|
||||
glm::vec3 lookAt = pos - lightDir;
|
||||
|
@ -4089,14 +4091,14 @@ void CEngine::RenderShadowMap()
|
|||
|
||||
Math::Matrix scaleMat;
|
||||
Math::LoadScaleMatrix(scaleMat, glm::vec3(1.0f, 1.0f, -1.0f));
|
||||
m_shadowViewMat = Math::MultiplyMatrices(scaleMat, m_shadowViewMat);
|
||||
m_shadowViewMat = scaleMat * m_shadowViewMat;
|
||||
|
||||
Math::Matrix temporary = Math::MultiplyMatrices(m_shadowProjMat, m_shadowViewMat);
|
||||
m_shadowTextureMat = Math::MultiplyMatrices(m_shadowBias, temporary);
|
||||
Math::Matrix temporary = m_shadowProjMat * m_shadowViewMat;
|
||||
m_shadowTextureMat = m_shadowBias * temporary;
|
||||
|
||||
m_shadowViewMat = Math::MultiplyMatrices(scaleMat, m_shadowViewMat);
|
||||
m_shadowViewMat = scaleMat * m_shadowViewMat;
|
||||
|
||||
auto projectionViewMatrix = Math::MultiplyMatrices(m_shadowProjMat, m_shadowViewMat);
|
||||
auto projectionViewMatrix = m_shadowProjMat * m_shadowViewMat;
|
||||
|
||||
m_shadowParams[region].transform = m_shadowTextureMat;
|
||||
|
||||
|
@ -4113,7 +4115,7 @@ void CEngine::RenderShadowMap()
|
|||
|
||||
if (terrain && !m_terrainShadows) continue;
|
||||
|
||||
auto combinedMatrix = Math::MultiplyMatrices(projectionViewMatrix, m_objects[objRank].transform);
|
||||
auto combinedMatrix = projectionViewMatrix * m_objects[objRank].transform;
|
||||
|
||||
if (!IsVisible(combinedMatrix, objRank))
|
||||
continue;
|
||||
|
@ -4327,7 +4329,7 @@ void CEngine::DrawInterface()
|
|||
|
||||
m_device->SetTransform(TRANSFORM_VIEW, m_matView);
|
||||
|
||||
auto projectionViewMatrix = Math::MultiplyMatrices(m_matProj, m_matView);
|
||||
auto projectionViewMatrix = m_matProj * m_matView;
|
||||
|
||||
for (int objRank = 0; objRank < static_cast<int>(m_objects.size()); objRank++)
|
||||
{
|
||||
|
@ -4341,7 +4343,7 @@ void CEngine::DrawInterface()
|
|||
continue;
|
||||
|
||||
m_device->SetTransform(TRANSFORM_WORLD, m_objects[objRank].transform);
|
||||
auto combinedMatrix = Math::MultiplyMatrices(projectionViewMatrix, m_objects[objRank].transform);
|
||||
auto combinedMatrix = projectionViewMatrix * m_objects[objRank].transform;
|
||||
|
||||
if (! IsVisible(combinedMatrix, objRank))
|
||||
continue;
|
||||
|
@ -4717,8 +4719,7 @@ void CEngine::DrawShadowSpots()
|
|||
m_device->SetRenderState(RENDER_STATE_DEPTH_WRITE, false);
|
||||
m_device->SetRenderState(RENDER_STATE_LIGHTING, false);
|
||||
|
||||
Math::Matrix matrix;
|
||||
matrix.LoadIdentity();
|
||||
Math::Matrix matrix = glm::mat4(1.0f);
|
||||
m_device->SetTransform(TRANSFORM_WORLD, matrix);
|
||||
|
||||
|
||||
|
@ -5714,11 +5715,9 @@ void CEngine::DisablePauseBlur()
|
|||
|
||||
void CEngine::SetWindowCoordinates()
|
||||
{
|
||||
Math::Matrix matWorldWindow;
|
||||
matWorldWindow.LoadIdentity();
|
||||
Math::Matrix matWorldWindow = glm::mat4(1.0f);
|
||||
|
||||
Math::Matrix matViewWindow;
|
||||
matViewWindow.LoadIdentity();
|
||||
Math::Matrix matViewWindow = glm::mat4(1.0f);
|
||||
|
||||
Math::Matrix matProjWindow;
|
||||
Math::LoadOrthoProjectionMatrix(matProjWindow, 0.0f, m_size.x, m_size.y, 0.0f, -1.0f, 1.0f);
|
||||
|
|
|
@ -222,8 +222,7 @@ void CLightning::Draw()
|
|||
|
||||
CDevice* device = m_engine->GetDevice();
|
||||
|
||||
Math::Matrix mat;
|
||||
mat.LoadIdentity();
|
||||
glm::mat4 mat = glm::mat4(1.0f);
|
||||
device->SetTransform(TRANSFORM_WORLD, mat);
|
||||
|
||||
m_engine->SetTexture("textures/effect00.png");
|
||||
|
|
|
@ -2504,8 +2504,7 @@ void CParticle::TrackDraw(int i, ParticleType type)
|
|||
if (h < 0) h = MAXTRACKLEN-1;
|
||||
}
|
||||
|
||||
Math::Matrix mat;
|
||||
mat.LoadIdentity();
|
||||
glm::mat4 mat = glm::mat4(1.0f);
|
||||
m_device->SetTransform(TRANSFORM_WORLD, mat);
|
||||
|
||||
glm::vec2 texInf{ 0, 0 }, texSup{ 0, 0 };
|
||||
|
@ -2681,11 +2680,11 @@ void CParticle::DrawParticleTriangle(int i)
|
|||
angle.y = Math::RotateAngle(pos.z-eye.z, pos.x-eye.x);
|
||||
angle.z = m_particle[i].angle;
|
||||
|
||||
Math::Matrix mat;
|
||||
glm::mat4 mat;
|
||||
Math::LoadRotationXZYMatrix(mat, angle);
|
||||
mat.Set(1, 4, pos.x);
|
||||
mat.Set(2, 4, pos.y);
|
||||
mat.Set(3, 4, pos.z);
|
||||
mat[3][0] = pos.x;
|
||||
mat[3][1] = pos.y;
|
||||
mat[3][2] = pos.z;
|
||||
m_device->SetTransform(TRANSFORM_WORLD, mat);
|
||||
|
||||
m_device->DrawPrimitive(PrimitiveType::TRIANGLES, m_triangle[i].triangle, 3);
|
||||
|
@ -2751,11 +2750,11 @@ void CParticle::DrawParticleNorm(int i)
|
|||
angle.y = Math::RotateAngle(pos.z-eye.z, pos.x-eye.x);
|
||||
angle.z = m_particle[i].angle;
|
||||
|
||||
Math::Matrix mat;
|
||||
glm::mat4 mat;
|
||||
Math::LoadRotationXZYMatrix(mat, angle);
|
||||
mat.Set(1, 4, pos.x);
|
||||
mat.Set(2, 4, pos.y);
|
||||
mat.Set(3, 4, pos.z);
|
||||
mat[3][0] = pos.x;
|
||||
mat[3][1] = pos.y;
|
||||
mat[3][2] = pos.z;
|
||||
m_device->SetTransform(TRANSFORM_WORLD, mat);
|
||||
|
||||
glm::vec3 n(0.0f, 0.0f, -1.0f);
|
||||
|
@ -2813,11 +2812,11 @@ void CParticle::DrawParticleFlat(int i)
|
|||
if (pos.y > eye.y) // seen from below?
|
||||
angle.x = -Math::PI/2.0f;
|
||||
|
||||
Math::Matrix mat;
|
||||
glm::mat4 mat;
|
||||
Math::LoadRotationXZYMatrix(mat, angle);
|
||||
mat.Set(1, 4, pos.x);
|
||||
mat.Set(2, 4, pos.y);
|
||||
mat.Set(3, 4, pos.z);
|
||||
mat[3][0] = pos.x;
|
||||
mat[3][1] = pos.y;
|
||||
mat[3][2] = pos.z;
|
||||
m_device->SetTransform(TRANSFORM_WORLD, mat);
|
||||
|
||||
glm::vec3 n(0.0f, 0.0f, -1.0f);
|
||||
|
@ -2902,11 +2901,11 @@ void CParticle::DrawParticleFog(int i)
|
|||
if (pos.y > eye.y) // seen from below?
|
||||
angle.x = -Math::PI/2.0f;
|
||||
|
||||
Math::Matrix mat;
|
||||
glm::mat4 mat;
|
||||
Math::LoadRotationXZYMatrix(mat, angle);
|
||||
mat.Set(1, 4, pos.x);
|
||||
mat.Set(2, 4, pos.y);
|
||||
mat.Set(3, 4, pos.z);
|
||||
mat[3][0] = pos.x;
|
||||
mat[3][1] = pos.y;
|
||||
mat[3][2] = pos.z;
|
||||
m_device->SetTransform(TRANSFORM_WORLD, mat);
|
||||
|
||||
glm::vec3 n(0.0f, 0.0f, -1.0f);
|
||||
|
@ -2963,11 +2962,11 @@ void CParticle::DrawParticleRay(int i)
|
|||
angle.z = -Math::RotateAngle(Math::DistanceProjected(pos, goal), pos.y-goal.y);
|
||||
if (left) angle.x = -angle.x;
|
||||
|
||||
Math::Matrix mat;
|
||||
glm::mat4 mat;
|
||||
Math::LoadRotationZXYMatrix(mat, angle);
|
||||
mat.Set(1, 4, pos.x);
|
||||
mat.Set(2, 4, pos.y);
|
||||
mat.Set(3, 4, pos.z);
|
||||
mat[3][0] = pos.x;
|
||||
mat[3][1] = pos.y;
|
||||
mat[3][2] = pos.z;
|
||||
m_device->SetTransform(TRANSFORM_WORLD, mat);
|
||||
|
||||
glm::vec3 n(0.0f, 0.0f, left ? 1.0f : -1.0f);
|
||||
|
@ -3106,14 +3105,13 @@ void CParticle::DrawParticleSphere(int i)
|
|||
m_engine->SetState(ENG_RSTATE_TTEXTURE_BLACK | ENG_RSTATE_2FACE | ENG_RSTATE_WRAP,
|
||||
IntensityToColor(m_particle[i].intensity));
|
||||
|
||||
Math::Matrix mat;
|
||||
mat.LoadIdentity();
|
||||
mat.Set(1, 1, zoom);
|
||||
mat.Set(2, 2, zoom);
|
||||
mat.Set(3, 3, zoom);
|
||||
mat.Set(1, 4, m_particle[i].pos.x);
|
||||
mat.Set(2, 4, m_particle[i].pos.y);
|
||||
mat.Set(3, 4, m_particle[i].pos.z);
|
||||
glm::mat4 mat = glm::mat4(1.0f);
|
||||
mat[0][0] = zoom;
|
||||
mat[1][1] = zoom;
|
||||
mat[2][2] = zoom;
|
||||
mat[3][0] = m_particle[i].pos.x;
|
||||
mat[3][1] = m_particle[i].pos.y;
|
||||
mat[3][2] = m_particle[i].pos.z;
|
||||
|
||||
if (m_particle[i].angle != 0.0f)
|
||||
{
|
||||
|
@ -3121,9 +3119,9 @@ void CParticle::DrawParticleSphere(int i)
|
|||
angle.x = m_particle[i].angle*0.4f;
|
||||
angle.y = m_particle[i].angle*1.0f;
|
||||
angle.z = m_particle[i].angle*0.7f;
|
||||
Math::Matrix rot;
|
||||
glm::mat4 rot;
|
||||
Math::LoadRotationZXYMatrix(rot, angle);
|
||||
mat = Math::MultiplyMatrices(mat, rot);
|
||||
mat = mat * rot;
|
||||
}
|
||||
|
||||
m_device->SetTransform(TRANSFORM_WORLD, mat);
|
||||
|
@ -3215,14 +3213,14 @@ void CParticle::DrawParticleCylinder(int i)
|
|||
m_engine->SetState(ENG_RSTATE_TTEXTURE_BLACK | ENG_RSTATE_2FACE | ENG_RSTATE_WRAP,
|
||||
IntensityToColor(m_particle[i].intensity));
|
||||
|
||||
Math::Matrix mat;
|
||||
mat.LoadIdentity();
|
||||
mat.Set(1, 1, zoom);
|
||||
mat.Set(2, 2, zoom);
|
||||
mat.Set(3, 3, zoom);
|
||||
mat.Set(1, 4, m_particle[i].pos.x);
|
||||
mat.Set(2, 4, m_particle[i].pos.y);
|
||||
mat.Set(3, 4, m_particle[i].pos.z);
|
||||
glm::mat4 mat = glm::mat4(1.0f);
|
||||
mat[0][0] = zoom;
|
||||
mat[1][1] = zoom;
|
||||
mat[2][2] = zoom;
|
||||
mat[3][0] = m_particle[i].pos.x;
|
||||
mat[3][1] = m_particle[i].pos.y;
|
||||
mat[3][2] = m_particle[i].pos.z;
|
||||
|
||||
m_device->SetTransform(TRANSFORM_WORLD, mat);
|
||||
|
||||
glm::vec2 ts, ti;
|
||||
|
@ -3399,8 +3397,7 @@ void CParticle::DrawParticle(int sheet)
|
|||
if (m_wheelTraceTotal > 0 && sheet == SH_WORLD)
|
||||
{
|
||||
m_engine->SetState(ENG_RSTATE_OPAQUE_COLOR);
|
||||
Math::Matrix matrix;
|
||||
matrix.LoadIdentity();
|
||||
glm::mat4 matrix = glm::mat4(1.0f);
|
||||
m_device->SetTransform(TRANSFORM_WORLD, matrix);
|
||||
|
||||
for (int i = 0; i < m_wheelTraceTotal; i++)
|
||||
|
|
|
@ -734,10 +734,9 @@ bool CTerrain::CreateMosaic(int ox, int oy, int step, int objRank,
|
|||
}
|
||||
}
|
||||
|
||||
Math::Matrix transform;
|
||||
transform.LoadIdentity();
|
||||
transform.Set(1, 4, o.coord.x);
|
||||
transform.Set(3, 4, o.coord.z);
|
||||
glm::mat4 transform = glm::mat4(1.0f);
|
||||
transform[3][0] = o.coord.x;
|
||||
transform[3][2] = o.coord.z;
|
||||
m_engine->SetObjectTransform(objRank, transform);
|
||||
|
||||
return true;
|
||||
|
|
|
@ -276,8 +276,7 @@ void CWater::DrawBack()
|
|||
m_engine->SetFocus(m_engine->GetFocus());
|
||||
m_engine->UpdateMatProj(); // twice the depth of view
|
||||
|
||||
Math::Matrix matrix;
|
||||
matrix.LoadIdentity();
|
||||
glm::mat4 matrix = glm::mat4(1.0f);
|
||||
device->SetTransform(TRANSFORM_WORLD, matrix);
|
||||
|
||||
glm::vec3 p = { 0, 0, 0 };
|
||||
|
@ -329,8 +328,7 @@ void CWater::DrawSurf()
|
|||
|
||||
CDevice* device = m_engine->GetDevice();
|
||||
|
||||
Math::Matrix matrix;
|
||||
matrix.LoadIdentity();
|
||||
glm::mat4 matrix = glm::mat4(1.0f);
|
||||
device->SetTransform(TRANSFORM_WORLD, matrix);
|
||||
|
||||
Material material;
|
||||
|
@ -379,8 +377,9 @@ void CWater::DrawSurf()
|
|||
if (glm::distance(p, eye) > deep + radius)
|
||||
continue;
|
||||
|
||||
if (device->ComputeSphereVisibility(p, radius) != Gfx::FRUSTUM_PLANE_ALL)
|
||||
continue;
|
||||
/// TODO: use m_engine->ComputeSphereVisibility() instead
|
||||
//if (device->ComputeSphereVisibility(p, radius) != Gfx::FRUSTUM_PLANE_ALL)
|
||||
// continue;
|
||||
|
||||
int vertexIndex = 0;
|
||||
|
||||
|
|
|
@ -118,8 +118,7 @@ void CGL33Device::DebugLights()
|
|||
glDisable(GL_BLEND);
|
||||
|
||||
Math::Matrix saveWorldMat = m_worldMat;
|
||||
Math::Matrix identity;
|
||||
identity.LoadIdentity();
|
||||
glm::mat4 identity = glm::mat4(1.0f);
|
||||
SetTransform(TRANSFORM_WORLD, identity);
|
||||
|
||||
for (int i = 0; i < static_cast<int>( m_lights.size() ); ++i)
|
||||
|
@ -399,14 +398,13 @@ bool CGL33Device::Create()
|
|||
}
|
||||
|
||||
// Set default uniform values
|
||||
Math::Matrix matrix;
|
||||
matrix.LoadIdentity();
|
||||
glm::mat4 matrix = glm::mat4(1.0f);
|
||||
|
||||
glUniformMatrix4fv(uni.projectionMatrix, 1, GL_FALSE, matrix.Array());
|
||||
glUniformMatrix4fv(uni.viewMatrix, 1, GL_FALSE, matrix.Array());
|
||||
glUniformMatrix4fv(uni.modelMatrix, 1, GL_FALSE, matrix.Array());
|
||||
glUniformMatrix4fv(uni.normalMatrix, 1, GL_FALSE, matrix.Array());
|
||||
glUniformMatrix4fv(uni.shadowMatrix, 1, GL_FALSE, matrix.Array());
|
||||
glUniformMatrix4fv(uni.projectionMatrix, 1, GL_FALSE, glm::value_ptr(matrix));
|
||||
glUniformMatrix4fv(uni.viewMatrix, 1, GL_FALSE, glm::value_ptr(matrix));
|
||||
glUniformMatrix4fv(uni.modelMatrix, 1, GL_FALSE, glm::value_ptr(matrix));
|
||||
glUniformMatrix4fv(uni.normalMatrix, 1, GL_FALSE, glm::value_ptr(matrix));
|
||||
glUniformMatrix4fv(uni.shadowMatrix, 1, GL_FALSE, glm::value_ptr(matrix));
|
||||
glUniform3f(uni.cameraPosition, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
glUniform1i(uni.primaryTexture, 0);
|
||||
|
@ -528,9 +526,9 @@ void CGL33Device::BeginScene()
|
|||
{
|
||||
Clear();
|
||||
|
||||
glUniformMatrix4fv(m_uniforms.projectionMatrix, 1, GL_FALSE, m_projectionMat.Array());
|
||||
glUniformMatrix4fv(m_uniforms.viewMatrix, 1, GL_FALSE, m_viewMat.Array());
|
||||
glUniformMatrix4fv(m_uniforms.modelMatrix, 1, GL_FALSE, m_worldMat.Array());
|
||||
glUniformMatrix4fv(m_uniforms.projectionMatrix, 1, GL_FALSE, glm::value_ptr(m_projectionMat));
|
||||
glUniformMatrix4fv(m_uniforms.viewMatrix, 1, GL_FALSE, glm::value_ptr(m_viewMat));
|
||||
glUniformMatrix4fv(m_uniforms.modelMatrix, 1, GL_FALSE, glm::value_ptr(m_worldMat));
|
||||
}
|
||||
|
||||
void CGL33Device::EndScene()
|
||||
|
@ -584,35 +582,31 @@ void CGL33Device::SetTransform(TransformType type, const Math::Matrix &matrix)
|
|||
if (type == TRANSFORM_WORLD)
|
||||
{
|
||||
m_worldMat = matrix;
|
||||
glUniformMatrix4fv(m_uniforms.modelMatrix, 1, GL_FALSE, m_worldMat.Array());
|
||||
glUniformMatrix4fv(m_uniforms.modelMatrix, 1, GL_FALSE, glm::value_ptr(m_worldMat));
|
||||
|
||||
m_modelviewMat = Math::MultiplyMatrices(m_viewMat, m_worldMat);
|
||||
m_modelviewMat = m_viewMat * m_worldMat;
|
||||
m_combinedMatrixOutdated = true;
|
||||
|
||||
// normal transform
|
||||
Math::Matrix normalMat = matrix;
|
||||
Math::Matrix normalMat = glm::inverse(normalMat);
|
||||
|
||||
if (fabs(normalMat.Det()) > 1e-6)
|
||||
normalMat = normalMat.Inverse();
|
||||
|
||||
glUniformMatrix4fv(m_uniforms.normalMatrix, 1, GL_TRUE, normalMat.Array());
|
||||
glUniformMatrix4fv(m_uniforms.normalMatrix, 1, GL_TRUE, glm::value_ptr(normalMat));
|
||||
}
|
||||
else if (type == TRANSFORM_VIEW)
|
||||
{
|
||||
Math::Matrix scale;
|
||||
glm::vec3 cameraPosition;
|
||||
scale.Set(3, 3, -1.0f);
|
||||
m_viewMat = Math::MultiplyMatrices(scale, matrix);
|
||||
Math::Matrix scale = glm::mat4(1.0f);
|
||||
scale[2][2] = -1.0f;
|
||||
m_viewMat = scale * matrix;
|
||||
|
||||
m_modelviewMat = Math::MultiplyMatrices(m_viewMat, m_worldMat);
|
||||
m_modelviewMat = m_viewMat * m_worldMat;
|
||||
m_combinedMatrixOutdated = true;
|
||||
|
||||
glUniformMatrix4fv(m_uniforms.viewMatrix, 1, GL_FALSE, m_viewMat.Array());
|
||||
glUniformMatrix4fv(m_uniforms.viewMatrix, 1, GL_FALSE, glm::value_ptr(m_viewMat));
|
||||
|
||||
if (m_uniforms.cameraPosition >= 0)
|
||||
{
|
||||
cameraPosition = { 0, 0, 0 };
|
||||
cameraPosition = MatrixVectorMultiply(m_viewMat.Inverse(), cameraPosition);
|
||||
glm::vec3 cameraPosition = { 0, 0, 0 };
|
||||
cameraPosition = glm::vec3(glm::inverse(m_viewMat) * glm::vec4(cameraPosition, 1.0f));
|
||||
glUniform3fv(m_uniforms.cameraPosition, 1, glm::value_ptr(cameraPosition));
|
||||
}
|
||||
}
|
||||
|
@ -621,12 +615,12 @@ void CGL33Device::SetTransform(TransformType type, const Math::Matrix &matrix)
|
|||
m_projectionMat = matrix;
|
||||
m_combinedMatrixOutdated = true;
|
||||
|
||||
glUniformMatrix4fv(m_uniforms.projectionMatrix, 1, GL_FALSE, m_projectionMat.Array());
|
||||
glUniformMatrix4fv(m_uniforms.projectionMatrix, 1, GL_FALSE, glm::value_ptr(m_projectionMat));
|
||||
}
|
||||
else if (type == TRANSFORM_SHADOW)
|
||||
{
|
||||
Math::Matrix temp = matrix;
|
||||
glUniformMatrix4fv(m_uniforms.shadowMatrix, 1, GL_FALSE, temp.Array());
|
||||
glUniformMatrix4fv(m_uniforms.shadowMatrix, 1, GL_FALSE, glm::value_ptr(temp));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1327,87 +1321,6 @@ void CGL33Device::DestroyVertexBuffer(CVertexBuffer* buffer)
|
|||
delete buffer;
|
||||
}
|
||||
|
||||
/* Based on libwine's implementation */
|
||||
|
||||
int CGL33Device::ComputeSphereVisibility(const glm::vec3 ¢er, float radius)
|
||||
{
|
||||
if (m_combinedMatrixOutdated)
|
||||
{
|
||||
m_combinedMatrix = Math::MultiplyMatrices(m_projectionMat, m_modelviewMat);
|
||||
m_combinedMatrixOutdated = false;
|
||||
}
|
||||
|
||||
Math::Matrix &m = m_combinedMatrix;
|
||||
|
||||
glm::vec3 vec[6];
|
||||
float originPlane[6];
|
||||
|
||||
// Left plane
|
||||
vec[0].x = m.Get(4, 1) + m.Get(1, 1);
|
||||
vec[0].y = m.Get(4, 2) + m.Get(1, 2);
|
||||
vec[0].z = m.Get(4, 3) + m.Get(1, 3);
|
||||
float l1 = glm::length(vec[0]);
|
||||
vec[0] = glm::normalize(vec[0]);
|
||||
originPlane[0] = (m.Get(4, 4) + m.Get(1, 4)) / l1;
|
||||
|
||||
// Right plane
|
||||
vec[1].x = m.Get(4, 1) - m.Get(1, 1);
|
||||
vec[1].y = m.Get(4, 2) - m.Get(1, 2);
|
||||
vec[1].z = m.Get(4, 3) - m.Get(1, 3);
|
||||
float l2 = glm::length(vec[1]);
|
||||
vec[1] = glm::normalize(vec[1]);
|
||||
originPlane[1] = (m.Get(4, 4) - m.Get(1, 4)) / l2;
|
||||
|
||||
// Bottom plane
|
||||
vec[2].x = m.Get(4, 1) + m.Get(2, 1);
|
||||
vec[2].y = m.Get(4, 2) + m.Get(2, 2);
|
||||
vec[2].z = m.Get(4, 3) + m.Get(2, 3);
|
||||
float l3 = glm::length(vec[2]);
|
||||
vec[2] = glm::normalize(vec[2]);
|
||||
originPlane[2] = (m.Get(4, 4) + m.Get(2, 4)) / l3;
|
||||
|
||||
// Top plane
|
||||
vec[3].x = m.Get(4, 1) - m.Get(2, 1);
|
||||
vec[3].y = m.Get(4, 2) - m.Get(2, 2);
|
||||
vec[3].z = m.Get(4, 3) - m.Get(2, 3);
|
||||
float l4 = glm::length(vec[3]);
|
||||
vec[3] = glm::normalize(vec[3]);
|
||||
originPlane[3] = (m.Get(4, 4) - m.Get(2, 4)) / l4;
|
||||
|
||||
// Front plane
|
||||
vec[4].x = m.Get(4, 1) + m.Get(3, 1);
|
||||
vec[4].y = m.Get(4, 2) + m.Get(3, 2);
|
||||
vec[4].z = m.Get(4, 3) + m.Get(3, 3);
|
||||
float l5 = glm::length(vec[4]);
|
||||
vec[4] = glm::normalize(vec[4]);
|
||||
originPlane[4] = (m.Get(4, 4) + m.Get(3, 4)) / l5;
|
||||
|
||||
// Back plane
|
||||
vec[5].x = m.Get(4, 1) - m.Get(3, 1);
|
||||
vec[5].y = m.Get(4, 2) - m.Get(3, 2);
|
||||
vec[5].z = m.Get(4, 3) - m.Get(3, 3);
|
||||
float l6 = glm::length(vec[5]);
|
||||
vec[5] = glm::normalize(vec[5]);
|
||||
originPlane[5] = (m.Get(4, 4) - m.Get(3, 4)) / l6;
|
||||
|
||||
int result = 0;
|
||||
|
||||
if (InPlane(vec[0], originPlane[0], center, radius))
|
||||
result |= FRUSTUM_PLANE_LEFT;
|
||||
if (InPlane(vec[1], originPlane[1], center, radius))
|
||||
result |= FRUSTUM_PLANE_RIGHT;
|
||||
if (InPlane(vec[2], originPlane[2], center, radius))
|
||||
result |= FRUSTUM_PLANE_BOTTOM;
|
||||
if (InPlane(vec[3], originPlane[3], center, radius))
|
||||
result |= FRUSTUM_PLANE_TOP;
|
||||
if (InPlane(vec[4], originPlane[4], center, radius))
|
||||
result |= FRUSTUM_PLANE_FRONT;
|
||||
if (InPlane(vec[5], originPlane[5], center, radius))
|
||||
result |= FRUSTUM_PLANE_BACK;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void CGL33Device::SetViewport(int x, int y, int width, int height)
|
||||
{
|
||||
glViewport(x, y, width, height);
|
||||
|
|
|
@ -169,8 +169,6 @@ public:
|
|||
void DrawVertexBuffer(CVertexBuffer*) override;
|
||||
void DestroyVertexBuffer(CVertexBuffer*) override;
|
||||
|
||||
int ComputeSphereVisibility(const glm::vec3 ¢er, float radius) override;
|
||||
|
||||
void SetViewport(int x, int y, int width, int height) override;
|
||||
|
||||
void SetRenderState(RenderState state, bool enabled) override;
|
||||
|
|
|
@ -72,7 +72,6 @@ void CMainMovie::Flush()
|
|||
|
||||
bool CMainMovie::Start(MainMovieType type, float time)
|
||||
{
|
||||
Math::Matrix* mat;
|
||||
glm::vec3 pos{ 0, 0, 0 };
|
||||
CObject* pObj;
|
||||
|
||||
|
@ -97,11 +96,11 @@ bool CMainMovie::Start(MainMovieType type, float time)
|
|||
m_camera->SetSmooth(Gfx::CAM_SMOOTH_HARD);
|
||||
m_camera->SetScriptCamera(m_initialEye, m_initialLookat);
|
||||
|
||||
mat = pObj->GetWorldMatrix(0);
|
||||
m_finalLookat[0] = Math::Transform(*mat, glm::vec3( 1.6f, 1.0f, 1.2f));
|
||||
m_finalEye[0] = Math::Transform(*mat, glm::vec3(-1.5f, 5.0f, 3.0f));
|
||||
m_finalLookat[1] = Math::Transform(*mat, glm::vec3( 1.6f, 1.0f, 1.2f));
|
||||
m_finalEye[1] = Math::Transform(*mat, glm::vec3( 0.8f, 3.0f, 0.8f));
|
||||
glm::mat4 mat = pObj->GetWorldMatrix(0);
|
||||
m_finalLookat[0] = Math::Transform(mat, glm::vec3( 1.6f, 1.0f, 1.2f));
|
||||
m_finalEye[0] = Math::Transform(mat, glm::vec3(-1.5f, 5.0f, 3.0f));
|
||||
m_finalLookat[1] = Math::Transform(mat, glm::vec3( 1.6f, 1.0f, 1.2f));
|
||||
m_finalEye[1] = Math::Transform(mat, glm::vec3( 0.8f, 3.0f, 0.8f));
|
||||
}
|
||||
|
||||
if ( m_type == MM_SATCOMclose )
|
||||
|
|
|
@ -6050,16 +6050,15 @@ float CRobotMain::GetGlobalCellCapacity()
|
|||
|
||||
void CRobotMain::StartDetectEffect(COldObject* object, CObject* target)
|
||||
{
|
||||
Math::Matrix* mat;
|
||||
glm::vec3 pos, goal;
|
||||
glm::vec2 dim;
|
||||
glm::vec3 goal;
|
||||
glm::vec2 dim;
|
||||
|
||||
mat = object->GetWorldMatrix(0);
|
||||
pos = Math::Transform(*mat, glm::vec3(2.0f, 3.0f, 0.0f));
|
||||
glm::mat4 mat = object->GetWorldMatrix(0);
|
||||
glm::vec3 pos = Math::Transform(mat, glm::vec3(2.0f, 3.0f, 0.0f));
|
||||
|
||||
if ( target == nullptr )
|
||||
{
|
||||
goal = Math::Transform(*mat, glm::vec3(50.0f, 3.0f, 0.0f));
|
||||
goal = Math::Transform(mat, glm::vec3(50.0f, 3.0f, 0.0f));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -306,22 +306,22 @@ inline void LoadViewMatrix(Math::Matrix &mat, const glm::vec3 &from,
|
|||
|
||||
// Start building the matrix. The first three rows contains the basis
|
||||
// vectors used to rotate the view to point at the lookat point
|
||||
mat.LoadIdentity();
|
||||
mat = glm::mat4(1.0f);
|
||||
|
||||
/* (1,1) */ mat.m[0 ] = right.x;
|
||||
/* (2,1) */ mat.m[1 ] = up.x;
|
||||
/* (3,1) */ mat.m[2 ] = view.x;
|
||||
/* (1,2) */ mat.m[4 ] = right.y;
|
||||
/* (2,2) */ mat.m[5 ] = up.y;
|
||||
/* (3,2) */ mat.m[6 ] = view.y;
|
||||
/* (1,3) */ mat.m[8 ] = right.z;
|
||||
/* (2,3) */ mat.m[9 ] = up.z;
|
||||
/* (3,3) */ mat.m[10] = view.z;
|
||||
mat[0][0] = right.x;
|
||||
mat[0][1] = up.x;
|
||||
mat[0][2] = view.x;
|
||||
mat[1][0] = right.y;
|
||||
mat[1][1] = up.y;
|
||||
mat[1][2] = view.y;
|
||||
mat[2][0] = right.z;
|
||||
mat[2][1] = up.z;
|
||||
mat[2][2] = view.z;
|
||||
|
||||
// Do the translation values (rotations are still about the eyepoint)
|
||||
/* (1,4) */ mat.m[12] = -glm::dot(from, right);
|
||||
/* (2,4) */ mat.m[13] = -glm::dot(from, up);
|
||||
/* (3,4) */ mat.m[14] = -glm::dot(from, view);
|
||||
mat[3][0] = -glm::dot(from, right);
|
||||
mat[3][1] = -glm::dot(from, up);
|
||||
mat[3][2] = -glm::dot(from, view);
|
||||
}
|
||||
|
||||
//! Loads a perspective projection matrix
|
||||
|
@ -340,13 +340,13 @@ inline void LoadProjectionMatrix(Math::Matrix &mat, float fov = Math::PI / 2.0f,
|
|||
|
||||
float f = cosf(fov / 2.0f) / sinf(fov / 2.0f);
|
||||
|
||||
mat.LoadZero();
|
||||
mat = glm::mat4(0.0f);
|
||||
|
||||
/* (1,1) */ mat.m[0 ] = f / aspect;
|
||||
/* (2,2) */ mat.m[5 ] = f;
|
||||
/* (3,3) */ mat.m[10] = (nearPlane + farPlane) / (nearPlane - farPlane);
|
||||
/* (4,3) */ mat.m[11] = -1.0f;
|
||||
/* (3,4) */ mat.m[14] = (2.0f * farPlane * nearPlane) / (nearPlane - farPlane);
|
||||
mat[0][0] = f / aspect;
|
||||
mat[1][1] = f;
|
||||
mat[2][2] = (nearPlane + farPlane) / (nearPlane - farPlane);
|
||||
mat[2][3] = -1.0f;
|
||||
mat[3][2] = (2.0f * farPlane * nearPlane) / (nearPlane - farPlane);
|
||||
}
|
||||
|
||||
//! Loads an othogonal projection matrix
|
||||
|
@ -359,15 +359,15 @@ inline void LoadProjectionMatrix(Math::Matrix &mat, float fov = Math::PI / 2.0f,
|
|||
inline void LoadOrthoProjectionMatrix(Math::Matrix &mat, float left, float right, float bottom, float top,
|
||||
float zNear = -1.0f, float zFar = 1.0f)
|
||||
{
|
||||
mat.LoadIdentity();
|
||||
mat = glm::mat4(1.0f);
|
||||
|
||||
/* (1,1) */ mat.m[0 ] = 2.0f / (right - left);
|
||||
/* (2,2) */ mat.m[5 ] = 2.0f / (top - bottom);
|
||||
/* (3,3) */ mat.m[10] = -2.0f / (zFar - zNear);
|
||||
mat[0][0] = 2.0f / (right - left);
|
||||
mat[1][1] = 2.0f / (top - bottom);
|
||||
mat[2][2] = -2.0f / (zFar - zNear);
|
||||
|
||||
/* (1,4) */ mat.m[12] = - (right + left) / (right - left);
|
||||
/* (2,4) */ mat.m[13] = - (top + bottom) / (top - bottom);
|
||||
/* (3,4) */ mat.m[14] = - (zFar + zNear) / (zFar - zNear);
|
||||
mat[3][0] = - (right + left) / (right - left);
|
||||
mat[3][1] = - (top + bottom) / (top - bottom);
|
||||
mat[3][2] = - (zFar + zNear) / (zFar - zNear);
|
||||
}
|
||||
|
||||
//! Loads a translation matrix from given vector
|
||||
|
@ -377,10 +377,7 @@ inline void LoadOrthoProjectionMatrix(Math::Matrix &mat, float left, float right
|
|||
*/
|
||||
inline void LoadTranslationMatrix(Math::Matrix &mat, const glm::vec3 &trans)
|
||||
{
|
||||
mat.LoadIdentity();
|
||||
/* (1,4) */ mat.m[12] = trans.x;
|
||||
/* (2,4) */ mat.m[13] = trans.y;
|
||||
/* (3,4) */ mat.m[14] = trans.z;
|
||||
mat = glm::translate(glm::mat4(1.0f), trans);
|
||||
}
|
||||
|
||||
//! Loads a scaling matrix fom given vector
|
||||
|
@ -390,10 +387,7 @@ inline void LoadTranslationMatrix(Math::Matrix &mat, const glm::vec3 &trans)
|
|||
*/
|
||||
inline void LoadScaleMatrix(Math::Matrix &mat, const glm::vec3 &scale)
|
||||
{
|
||||
mat.LoadIdentity();
|
||||
/* (1,1) */ mat.m[0 ] = scale.x;
|
||||
/* (2,2) */ mat.m[5 ] = scale.y;
|
||||
/* (3,3) */ mat.m[10] = scale.z;
|
||||
mat = glm::scale(glm::mat4(1.0f), scale);
|
||||
}
|
||||
|
||||
//! Loads a rotation matrix along the X axis
|
||||
|
@ -403,11 +397,12 @@ inline void LoadScaleMatrix(Math::Matrix &mat, const glm::vec3 &scale)
|
|||
*/
|
||||
inline void LoadRotationXMatrix(Math::Matrix &mat, float angle)
|
||||
{
|
||||
mat.LoadIdentity();
|
||||
/* (2,2) */ mat.m[5 ] = cosf(angle);
|
||||
/* (3,2) */ mat.m[6 ] = sinf(angle);
|
||||
/* (2,3) */ mat.m[9 ] = -sinf(angle);
|
||||
/* (3,3) */ mat.m[10] = cosf(angle);
|
||||
mat = glm::mat4(1.0f);
|
||||
|
||||
mat[1][1] = cosf(angle);
|
||||
mat[1][2] = sinf(angle);
|
||||
mat[2][1] = -sinf(angle);
|
||||
mat[2][2] = cosf(angle);
|
||||
}
|
||||
|
||||
//! Loads a rotation matrix along the Y axis
|
||||
|
@ -417,11 +412,12 @@ inline void LoadRotationXMatrix(Math::Matrix &mat, float angle)
|
|||
*/
|
||||
inline void LoadRotationYMatrix(Math::Matrix &mat, float angle)
|
||||
{
|
||||
mat.LoadIdentity();
|
||||
/* (1,1) */ mat.m[0 ] = cosf(angle);
|
||||
/* (3,1) */ mat.m[2 ] = -sinf(angle);
|
||||
/* (1,3) */ mat.m[8 ] = sinf(angle);
|
||||
/* (3,3) */ mat.m[10] = cosf(angle);
|
||||
mat = glm::mat4(1.0f);
|
||||
|
||||
mat[0][0] = cosf(angle);
|
||||
mat[0][2] = -sinf(angle);
|
||||
mat[2][0] = sinf(angle);
|
||||
mat[2][2] = cosf(angle);
|
||||
}
|
||||
|
||||
//! Loads a rotation matrix along the Z axis
|
||||
|
@ -431,11 +427,12 @@ inline void LoadRotationYMatrix(Math::Matrix &mat, float angle)
|
|||
*/
|
||||
inline void LoadRotationZMatrix(Math::Matrix &mat, float angle)
|
||||
{
|
||||
mat.LoadIdentity();
|
||||
/* (1,1) */ mat.m[0 ] = cosf(angle);
|
||||
/* (2,1) */ mat.m[1 ] = sinf(angle);
|
||||
/* (1,2) */ mat.m[4 ] = -sinf(angle);
|
||||
/* (2,2) */ mat.m[5 ] = cosf(angle);
|
||||
mat = glm::mat4(1.0f);
|
||||
|
||||
mat[0][0] = cosf(angle);
|
||||
mat[0][1] = sinf(angle);
|
||||
mat[1][0] = -sinf(angle);
|
||||
mat[1][1] = cosf(angle);
|
||||
}
|
||||
|
||||
//! Loads a rotation matrix along the given axis
|
||||
|
@ -450,19 +447,19 @@ inline void LoadRotationMatrix(Math::Matrix &mat, const glm::vec3 &dir, float an
|
|||
float sin = sinf(angle);
|
||||
glm::vec3 v = glm::normalize(dir);
|
||||
|
||||
mat.LoadIdentity();
|
||||
mat = glm::mat4(1.0f);
|
||||
|
||||
/* (1,1) */ mat.m[0 ] = (v.x * v.x) * (1.0f - cos) + cos;
|
||||
/* (2,1) */ mat.m[1 ] = (v.x * v.y) * (1.0f - cos) - (v.z * sin);
|
||||
/* (3,1) */ mat.m[2 ] = (v.x * v.z) * (1.0f - cos) + (v.y * sin);
|
||||
mat[0][0] = (v.x * v.x) * (1.0f - cos) + cos;
|
||||
mat[0][1] = (v.x * v.y) * (1.0f - cos) - (v.z * sin);
|
||||
mat[0][2] = (v.x * v.z) * (1.0f - cos) + (v.y * sin);
|
||||
|
||||
/* (1,2) */ mat.m[4 ] = (v.y * v.x) * (1.0f - cos) + (v.z * sin);
|
||||
/* (2,2) */ mat.m[5 ] = (v.y * v.y) * (1.0f - cos) + cos ;
|
||||
/* (3,2) */ mat.m[6 ] = (v.y * v.z) * (1.0f - cos) - (v.x * sin);
|
||||
mat[1][0] = (v.y * v.x) * (1.0f - cos) + (v.z * sin);
|
||||
mat[1][1] = (v.y * v.y) * (1.0f - cos) + cos ;
|
||||
mat[1][2] = (v.y * v.z) * (1.0f - cos) - (v.x * sin);
|
||||
|
||||
/* (1,3) */ mat.m[8 ] = (v.z * v.x) * (1.0f - cos) - (v.y * sin);
|
||||
/* (2,3) */ mat.m[9 ] = (v.z * v.y) * (1.0f - cos) + (v.x * sin);
|
||||
/* (3,3) */ mat.m[10] = (v.z * v.z) * (1.0f - cos) + cos;
|
||||
mat[2][0] = (v.z * v.x) * (1.0f - cos) - (v.y * sin);
|
||||
mat[2][1] = (v.z * v.y) * (1.0f - cos) + (v.x * sin);
|
||||
mat[2][2] = (v.z * v.z) * (1.0f - cos) + cos;
|
||||
}
|
||||
|
||||
//! Calculates the matrix to make three rotations in the order X, Z and Y
|
||||
|
@ -472,10 +469,10 @@ inline void LoadRotationXZYMatrix(Math::Matrix &mat, const glm::vec3 &angles)
|
|||
LoadRotationXMatrix(temp, angles.x);
|
||||
|
||||
LoadRotationZMatrix(mat, angles.z);
|
||||
mat = Math::MultiplyMatrices(temp, mat);
|
||||
mat = temp * mat;
|
||||
|
||||
LoadRotationYMatrix(temp, angles.y);
|
||||
mat = Math::MultiplyMatrices(temp, mat);
|
||||
mat = temp * mat;
|
||||
}
|
||||
|
||||
//! Calculates the matrix to make three rotations in the order Z, X and Y
|
||||
|
@ -485,10 +482,10 @@ inline void LoadRotationZXYMatrix(Math::Matrix &mat, const glm::vec3 &angles)
|
|||
LoadRotationZMatrix(temp, angles.z);
|
||||
|
||||
LoadRotationXMatrix(mat, angles.x);
|
||||
mat = Math::MultiplyMatrices(temp, mat);
|
||||
mat = temp * mat;
|
||||
|
||||
LoadRotationYMatrix(temp, angles.y);
|
||||
mat = Math::MultiplyMatrices(temp, mat);
|
||||
mat = temp * mat;
|
||||
}
|
||||
|
||||
//! Returns the distance between projections on XZ plane of two vectors
|
||||
|
@ -611,7 +608,7 @@ inline glm::vec3 LookatPoint(const glm::vec3 &eye, float angleH, float angleV, f
|
|||
/** Is equal to multiplying the matrix by the vector (of course without perspective divide). */
|
||||
inline glm::vec3 Transform(const Math::Matrix &m, const glm::vec3 &p)
|
||||
{
|
||||
return MatrixVectorMultiply(m, p);
|
||||
return glm::vec3(m * glm::vec4(p, 1.0f));
|
||||
}
|
||||
|
||||
//! Calculates the projection of the point \a p on a straight line \a a to \a b
|
||||
|
@ -634,7 +631,7 @@ inline glm::vec3 RotateView(glm::vec3 center, float angleH, float angleV, float
|
|||
LoadRotationZMatrix(mat1, -angleV);
|
||||
LoadRotationYMatrix(mat2, -angleH);
|
||||
|
||||
Math::Matrix mat = MultiplyMatrices(mat2, mat1);
|
||||
Math::Matrix mat = mat2 * mat1;
|
||||
|
||||
glm::vec3 eye{};
|
||||
eye.x = 0.0f+dist;
|
||||
|
|
|
@ -39,424 +39,8 @@
|
|||
namespace Math
|
||||
{
|
||||
|
||||
/**
|
||||
* \struct Matrix math/matrix.h
|
||||
* \brief 4x4 matrix
|
||||
*
|
||||
* Represents an universal 4x4 matrix that can be used in OpenGL and DirectX engines.
|
||||
* Contains the required methods for operating on matrices (inverting, multiplying, etc.).
|
||||
*
|
||||
* The internal representation is a 16-value table in column-major order, thus:
|
||||
using Matrix = glm::mat4;
|
||||
|
||||
\verbatim
|
||||
m[0 ] m[4 ] m[8 ] m[12]
|
||||
m[1 ] m[5 ] m[9 ] m[13]
|
||||
m[2 ] m[6 ] m[10] m[14]
|
||||
m[3 ] m[7 ] m[11] m[15]
|
||||
\endverbatim
|
||||
|
||||
* This representation is native to OpenGL; DirectX requires transposing the matrix.
|
||||
*
|
||||
* The order of multiplication of matrix and vector is also OpenGL-native
|
||||
* (see the function MatrixVectorMultiply).
|
||||
*
|
||||
* All methods are made inline to maximize optimization.
|
||||
*
|
||||
*/
|
||||
struct Matrix
|
||||
{
|
||||
//! Matrix values in column-major order
|
||||
float m[16];
|
||||
|
||||
//! Creates the indentity matrix
|
||||
Matrix()
|
||||
: m()
|
||||
{
|
||||
LoadIdentity();
|
||||
}
|
||||
|
||||
//! Creates the matrix from 1D array
|
||||
/** \a m matrix values in column-major order */
|
||||
explicit Matrix(const float (&_m)[16])
|
||||
: m()
|
||||
{
|
||||
for (int i = 0; i < 16; ++i)
|
||||
m[i] = _m[i];
|
||||
}
|
||||
|
||||
//! Creates the matrix from 2D array
|
||||
/**
|
||||
* The array's first index is row, second is column.
|
||||
* \param _m array with values
|
||||
*/
|
||||
explicit Matrix(const float (&_m)[4][4])
|
||||
: m()
|
||||
{
|
||||
for (int c = 0; c < 4; ++c)
|
||||
{
|
||||
for (int r = 0; r < 4; ++r)
|
||||
{
|
||||
m[4*c+r] = _m[r][c];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Matrix(const glm::mat4& matrix)
|
||||
{
|
||||
for (int c = 0; c < 4; ++c)
|
||||
{
|
||||
for (int r = 0; r < 4; ++r)
|
||||
{
|
||||
m[4 * c + r] = matrix[c][r];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
operator glm::mat4() const
|
||||
{
|
||||
glm::mat4 matrix;
|
||||
|
||||
for (int c = 0; c < 4; ++c)
|
||||
{
|
||||
for (int r = 0; r < 4; ++r)
|
||||
{
|
||||
matrix[c][r] = m[4 * c + r];
|
||||
}
|
||||
}
|
||||
|
||||
return matrix;
|
||||
}
|
||||
|
||||
//! Sets value in given row and col
|
||||
/**
|
||||
* \param row row (1 to 4)
|
||||
* \param col column (1 to 4)
|
||||
* \param value value
|
||||
*/
|
||||
void Set(int row, int col, float value)
|
||||
{
|
||||
m[(col-1)*4+(row-1)] = value;
|
||||
}
|
||||
|
||||
//! Returns the value in given row and col
|
||||
/**
|
||||
* \param row row (1 to 4)
|
||||
* \param col column (1 to 4)
|
||||
* \returns value
|
||||
*/
|
||||
float Get(int row, int col) const
|
||||
{
|
||||
return m[(col-1)*4+(row-1)];
|
||||
}
|
||||
|
||||
//! Loads the zero matrix
|
||||
void LoadZero()
|
||||
{
|
||||
for (int i = 0; i < 16; ++i)
|
||||
m[i] = 0.0f;
|
||||
}
|
||||
|
||||
//! Loads the identity matrix
|
||||
void LoadIdentity()
|
||||
{
|
||||
LoadZero();
|
||||
/* (1,1) */ m[0 ] = 1.0f;
|
||||
/* (2,2) */ m[5 ] = 1.0f;
|
||||
/* (3,3) */ m[10] = 1.0f;
|
||||
/* (4,4) */ m[15] = 1.0f;
|
||||
}
|
||||
|
||||
//! Returns the struct cast to \c float* array; use with care!
|
||||
float* Array()
|
||||
{
|
||||
return reinterpret_cast<float*>(this);
|
||||
}
|
||||
|
||||
//! Transposes the matrix
|
||||
void Transpose()
|
||||
{
|
||||
/* (2,1) <-> (1,2) */ Swap(m[1 ], m[4 ]);
|
||||
/* (3,1) <-> (1,3) */ Swap(m[2 ], m[8 ]);
|
||||
/* (4,1) <-> (1,4) */ Swap(m[3 ], m[12]);
|
||||
/* (3,2) <-> (2,3) */ Swap(m[6 ], m[9 ]);
|
||||
/* (4,2) <-> (2,4) */ Swap(m[7 ], m[13]);
|
||||
/* (4,3) <-> (3,4) */ Swap(m[11], m[14]);
|
||||
}
|
||||
|
||||
//! Calculates the determinant of the matrix
|
||||
/** \returns the determinant */
|
||||
float Det() const
|
||||
{
|
||||
float result = 0.0f;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
result += m[i] * Cofactor(i, 0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//! Calculates the cofactor of the matrix
|
||||
/**
|
||||
* \param r row (0 to 3)
|
||||
* \param c column (0 to 3)
|
||||
* \returns the cofactor
|
||||
*/
|
||||
float Cofactor(int r, int c) const
|
||||
{
|
||||
assert(r >= 0 && r <= 3);
|
||||
assert(c >= 0 && c <= 3);
|
||||
|
||||
float result = 0.0f;
|
||||
|
||||
/* That looks horrible, I know. But it's fast :) */
|
||||
|
||||
switch (4*r + c)
|
||||
{
|
||||
// r=0, c=0
|
||||
/* 05 09 13
|
||||
06 10 14
|
||||
07 11 15 */
|
||||
case 0:
|
||||
result = + m[5 ] * (m[10] * m[15] - m[14] * m[11])
|
||||
- m[9 ] * (m[6 ] * m[15] - m[14] * m[7 ])
|
||||
+ m[13] * (m[6 ] * m[11] - m[10] * m[7 ]);
|
||||
break;
|
||||
|
||||
// r=0, c=1
|
||||
/* 01 09 13
|
||||
02 10 14
|
||||
03 11 15 */
|
||||
case 1:
|
||||
result = - m[1 ] * (m[10] * m[15] - m[14] * m[11])
|
||||
+ m[9 ] * (m[2 ] * m[15] - m[14] * m[3 ])
|
||||
- m[13] * (m[2 ] * m[11] - m[10] * m[3 ]);
|
||||
break;
|
||||
|
||||
// r=0, c=2
|
||||
/* 01 05 13
|
||||
02 06 14
|
||||
03 07 15 */
|
||||
case 2:
|
||||
result = + m[1 ] * (m[6 ] * m[15] - m[14] * m[7 ])
|
||||
- m[5 ] * (m[2 ] * m[15] - m[14] * m[3 ])
|
||||
+ m[13] * (m[2 ] * m[7 ] - m[6 ] * m[3 ]);
|
||||
break;
|
||||
|
||||
// r=0, c=3
|
||||
/* 01 05 09
|
||||
02 06 10
|
||||
03 07 11 */
|
||||
case 3:
|
||||
result = - m[1 ] * (m[6 ] * m[11] - m[10] * m[7 ])
|
||||
+ m[5 ] * (m[2 ] * m[11] - m[10] * m[3 ])
|
||||
- m[9 ] * (m[2 ] * m[7 ] - m[6 ] * m[3 ]);
|
||||
break;
|
||||
|
||||
// r=1, c=0
|
||||
/* 04 08 12
|
||||
06 10 14
|
||||
07 11 15 */
|
||||
case 4:
|
||||
result = - m[4 ] * (m[10] * m[15] - m[14] * m[11])
|
||||
+ m[8 ] * (m[6 ] * m[15] - m[14] * m[7 ])
|
||||
- m[12] * (m[6 ] * m[11] - m[10] * m[7 ]);
|
||||
break;
|
||||
|
||||
// r=1, c=1
|
||||
/* 00 08 12
|
||||
02 10 14
|
||||
03 11 15 */
|
||||
case 5:
|
||||
result = + m[0 ] * (m[10] * m[15] - m[14] * m[11])
|
||||
- m[8 ] * (m[2 ] * m[15] - m[14] * m[3 ])
|
||||
+ m[12] * (m[2 ] * m[11] - m[10] * m[3 ]);
|
||||
break;
|
||||
|
||||
// r=1, c=2
|
||||
/* 00 04 12
|
||||
02 06 14
|
||||
03 07 15 */
|
||||
case 6:
|
||||
result = - m[0 ] * (m[6 ] * m[15] - m[14] * m[7 ])
|
||||
+ m[4 ] * (m[2 ] * m[15] - m[14] * m[3 ])
|
||||
- m[12] * (m[2 ] * m[7 ] - m[6 ] * m[3 ]);
|
||||
break;
|
||||
|
||||
// r=1, c=3
|
||||
/* 00 04 08
|
||||
02 06 10
|
||||
03 07 11 */
|
||||
case 7:
|
||||
result = + m[0 ] * (m[6 ] * m[11] - m[10] * m[7 ])
|
||||
- m[4 ] * (m[2 ] * m[11] - m[10] * m[3 ])
|
||||
+ m[8 ] * (m[2 ] * m[7 ] - m[6 ] * m[3 ]);
|
||||
break;
|
||||
|
||||
// r=2, c=0
|
||||
/* 04 08 12
|
||||
05 09 13
|
||||
07 11 15 */
|
||||
case 8:
|
||||
result = + m[4 ] * (m[9 ] * m[15] - m[13] * m[11])
|
||||
- m[8 ] * (m[5 ] * m[15] - m[13] * m[7 ])
|
||||
+ m[12] * (m[5 ] * m[11] - m[9 ] * m[7 ]);
|
||||
break;
|
||||
|
||||
// r=2, c=1
|
||||
/* 00 08 12
|
||||
01 09 13
|
||||
03 11 15 */
|
||||
case 9:
|
||||
result = - m[0 ] * (m[9 ] * m[15] - m[13] * m[11])
|
||||
+ m[8 ] * (m[1 ] * m[15] - m[13] * m[3 ])
|
||||
- m[12] * (m[1 ] * m[11] - m[9 ] * m[3 ]);
|
||||
break;
|
||||
|
||||
// r=2, c=2
|
||||
/* 00 04 12
|
||||
01 05 13
|
||||
03 07 15 */
|
||||
case 10:
|
||||
result = + m[0 ] * (m[5 ] * m[15] - m[13] * m[7 ])
|
||||
- m[4 ] * (m[1 ] * m[15] - m[13] * m[3 ])
|
||||
+ m[12] * (m[1 ] * m[7 ] - m[5 ] * m[3 ]);
|
||||
break;
|
||||
|
||||
// r=2, c=3
|
||||
/* 00 04 08
|
||||
01 05 09
|
||||
03 07 11 */
|
||||
case 11:
|
||||
result = - m[0 ] * (m[5 ] * m[11] - m[9 ] * m[7 ])
|
||||
+ m[4 ] * (m[1 ] * m[11] - m[9 ] * m[3 ])
|
||||
- m[8 ] * (m[1 ] * m[7 ] - m[5 ] * m[3 ]);
|
||||
break;
|
||||
|
||||
// r=3, c=0
|
||||
/* 04 08 12
|
||||
05 09 13
|
||||
06 10 14 */
|
||||
case 12:
|
||||
result = - m[4 ] * (m[9 ] * m[14] - m[13] * m[10])
|
||||
+ m[8 ] * (m[5 ] * m[14] - m[13] * m[6 ])
|
||||
- m[12] * (m[5 ] * m[10] - m[9 ] * m[6 ]);
|
||||
break;
|
||||
|
||||
// r=3, c=1
|
||||
/* 00 08 12
|
||||
01 09 13
|
||||
02 10 14 */
|
||||
case 13:
|
||||
result = + m[0 ] * (m[9 ] * m[14] - m[13] * m[10])
|
||||
- m[8 ] * (m[1 ] * m[14] - m[13] * m[2 ])
|
||||
+ m[12] * (m[1 ] * m[10] - m[9 ] * m[2 ]);
|
||||
break;
|
||||
|
||||
// r=3, c=2
|
||||
/* 00 04 12
|
||||
01 05 13
|
||||
02 06 14 */
|
||||
case 14:
|
||||
result = - m[0 ] * (m[5 ] * m[14] - m[13] * m[6 ])
|
||||
+ m[4 ] * (m[1 ] * m[14] - m[13] * m[2 ])
|
||||
- m[12] * (m[1 ] * m[6 ] - m[5 ] * m[2 ]);
|
||||
break;
|
||||
|
||||
// r=3, c=3
|
||||
/* 00 04 08
|
||||
01 05 09
|
||||
02 06 10 */
|
||||
case 15:
|
||||
result = + m[0 ] * (m[5 ] * m[10] - m[9 ] * m[6 ])
|
||||
- m[4 ] * (m[1 ] * m[10] - m[9 ] * m[2 ])
|
||||
+ m[8 ] * (m[1 ] * m[6 ] - m[5 ] * m[2 ]);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//! Calculates the inverse matrix
|
||||
/**
|
||||
* The determinant of the matrix must not be zero.
|
||||
* \returns the inverted matrix
|
||||
*/
|
||||
Matrix Inverse() const
|
||||
{
|
||||
float d = Det();
|
||||
assert(! IsZero(d));
|
||||
|
||||
float result[16] = { 0.0f };
|
||||
|
||||
for (int r = 0; r < 4; ++r)
|
||||
{
|
||||
for (int c = 0; c < 4; ++c)
|
||||
{
|
||||
// Already transposed!
|
||||
result[4*r+c] = (1.0f / d) * Cofactor(r, c);
|
||||
}
|
||||
}
|
||||
|
||||
return Matrix(result);
|
||||
}
|
||||
|
||||
//! Calculates the multiplication of this matrix * given matrix
|
||||
/**
|
||||
* \param right right-hand matrix
|
||||
* \returns multiplication result
|
||||
*/
|
||||
Matrix Multiply(const Matrix &right) const
|
||||
{
|
||||
float result[16] = { 0.0f };
|
||||
|
||||
for (int c = 0; c < 4; ++c)
|
||||
{
|
||||
for (int r = 0; r < 4; ++r)
|
||||
{
|
||||
result[4*c+r] = 0.0f;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
result[4*c+r] += m[4*i+r] * right.m[4*c+i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Matrix(result);
|
||||
}
|
||||
}; // struct Matrix
|
||||
|
||||
//! Checks if two matrices are equal within given \a tolerance
|
||||
inline bool MatricesEqual(const Matrix &m1, const Matrix &m2,
|
||||
float tolerance = TOLERANCE)
|
||||
{
|
||||
for (int i = 0; i < 16; ++i)
|
||||
{
|
||||
if (! IsEqual(m1.m[i], m2.m[i], tolerance))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//! Convenience function for getting transposed matrix
|
||||
inline Math::Matrix Transpose(const Math::Matrix &m)
|
||||
{
|
||||
Math::Matrix result = m;
|
||||
result.Transpose();
|
||||
return result;
|
||||
}
|
||||
|
||||
//! Convenience function for multiplying a matrix
|
||||
/** \a left left-hand matrix
|
||||
\a right right-hand matrix
|
||||
\returns multiplied matrices */
|
||||
inline Math::Matrix MultiplyMatrices(const Math::Matrix &left, const Math::Matrix &right)
|
||||
{
|
||||
return left.Multiply(right);
|
||||
}
|
||||
|
||||
//! Calculates the result of multiplying m * v
|
||||
/**
|
||||
|
@ -473,23 +57,15 @@ inline Math::Matrix MultiplyMatrices(const Math::Matrix &left, const Math::Matri
|
|||
x,y,z coords by the fourth coord (w). */
|
||||
inline glm::vec3 MatrixVectorMultiply(const Math::Matrix &m, const glm::vec3 &v, bool wDivide = false)
|
||||
{
|
||||
float x = v.x * m.m[0 ] + v.y * m.m[4 ] + v.z * m.m[8 ] + m.m[12];
|
||||
float y = v.x * m.m[1 ] + v.y * m.m[5 ] + v.z * m.m[9 ] + m.m[13];
|
||||
float z = v.x * m.m[2 ] + v.y * m.m[6 ] + v.z * m.m[10] + m.m[14];
|
||||
glm::vec4 result = m * glm::vec4(v, 1.0);
|
||||
|
||||
if (!wDivide)
|
||||
return glm::vec3(x, y, z);
|
||||
return result;
|
||||
|
||||
float w = v.x * m.m[3 ] + v.y * m.m[7 ] + v.z * m.m[11] + m.m[15];
|
||||
if (IsZero(result.w))
|
||||
return glm::vec3(result);
|
||||
|
||||
if (IsZero(w))
|
||||
return glm::vec3(x, y, z);
|
||||
|
||||
x /= w;
|
||||
y /= w;
|
||||
z /= w;
|
||||
|
||||
return glm::vec3(x, y, z);
|
||||
return glm::vec3(result) / result.w;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ void CAutoBase::Start(int param)
|
|||
|
||||
bool CAutoBase::EventProcess(const Event &event)
|
||||
{
|
||||
Math::Matrix* mat;
|
||||
glm::mat4 mat;
|
||||
CObject* pObj;
|
||||
glm::vec3 pos, speed, vibCir, iPos;
|
||||
glm::vec2 dim, p;
|
||||
|
@ -275,28 +275,28 @@ begin:
|
|||
dim.x = 10.0f;
|
||||
dim.y = dim.x;
|
||||
pos = glm::vec3(42.0f, -2.0f, 17.0f);
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
m_partiChannel[0] = m_particle->CreateParticle(pos, speed, dim, Gfx::PARTILENS1, BASE_TRANSIT_TIME+1.0f, 0.0f, 0.0f);
|
||||
pos = glm::vec3(17.0f, -2.0f, 42.0f);
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
m_partiChannel[1] = m_particle->CreateParticle(pos, speed, dim, Gfx::PARTILENS1, BASE_TRANSIT_TIME+1.0f, 0.0f, 0.0f);
|
||||
pos = glm::vec3(42.0f, -2.0f, -17.0f);
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
m_partiChannel[2] = m_particle->CreateParticle(pos, speed, dim, Gfx::PARTILENS1, BASE_TRANSIT_TIME+1.0f, 0.0f, 0.0f);
|
||||
pos = glm::vec3(17.0f, -2.0f, -42.0f);
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
m_partiChannel[3] = m_particle->CreateParticle(pos, speed, dim, Gfx::PARTILENS1, BASE_TRANSIT_TIME+1.0f, 0.0f, 0.0f);
|
||||
pos = glm::vec3(-42.0f, -2.0f, 17.0f);
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
m_partiChannel[4] = m_particle->CreateParticle(pos, speed, dim, Gfx::PARTILENS1, BASE_TRANSIT_TIME+1.0f, 0.0f, 0.0f);
|
||||
pos = glm::vec3(-17.0f, -2.0f, 42.0f);
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
m_partiChannel[5] = m_particle->CreateParticle(pos, speed, dim, Gfx::PARTILENS1, BASE_TRANSIT_TIME+1.0f, 0.0f, 0.0f);
|
||||
pos = glm::vec3(-42.0f, -2.0f, -17.0f);
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
m_partiChannel[6] = m_particle->CreateParticle(pos, speed, dim, Gfx::PARTILENS1, BASE_TRANSIT_TIME+1.0f, 0.0f, 0.0f);
|
||||
pos = glm::vec3(-17.0f, -2.0f, -42.0f);
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
m_partiChannel[7] = m_particle->CreateParticle(pos, speed, dim, Gfx::PARTILENS1, BASE_TRANSIT_TIME+1.0f, 0.0f, 0.0f);
|
||||
|
||||
if ( m_soundChannel == -1 )
|
||||
|
@ -957,8 +957,8 @@ begin:
|
|||
speed.z = (Math::Rand()-0.5f)*4.0f;
|
||||
speed.y = vSpeed*0.8f-(8.0f+Math::Rand()*6.0f);
|
||||
speed += pos;
|
||||
pos = Transform(*mat, pos);
|
||||
speed = Transform(*mat, speed);
|
||||
pos = Math::Transform(mat, pos);
|
||||
speed = Math::Transform(mat, speed);
|
||||
speed -= pos;
|
||||
|
||||
dim.x = 4.0f+Math::Rand()*4.0f;
|
||||
|
@ -973,7 +973,7 @@ begin:
|
|||
dim.y = dim.x;
|
||||
pos = glm::vec3(0.0f, 7.0f, 0.0f);
|
||||
pos.x += (Math::Rand()-0.5f)*2.0f; pos.z += (Math::Rand()-0.5f)*2.0f;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGAS, 1.0f, 0.0f, 0.0f);
|
||||
|
||||
speed = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
|
@ -981,60 +981,60 @@ begin:
|
|||
dim.y = dim.x;
|
||||
pos = glm::vec3(42.0f, 0.0f, 17.0f);
|
||||
pos.x += (Math::Rand()-0.5f)*2.0f; pos.z += (Math::Rand()-0.5f)*2.0f;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGAS, 0.5f, 0.0f, 0.0f);
|
||||
pos = glm::vec3(17.0f, 0.0f, 42.0f);
|
||||
pos.x += (Math::Rand()-0.5f)*2.0f; pos.z += (Math::Rand()-0.5f)*2.0f;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGAS, 0.5f, 0.0f, 0.0f);
|
||||
pos = glm::vec3(42.0f, 0.0f, -17.0f);
|
||||
pos.x += (Math::Rand()-0.5f)*2.0f; pos.z += (Math::Rand()-0.5f)*2.0f;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGAS, 0.5f, 0.0f, 0.0f);
|
||||
pos = glm::vec3(17.0f, 0.0f, -42.0f);
|
||||
pos.x += (Math::Rand()-0.5f)*2.0f; pos.z += (Math::Rand()-0.5f)*2.0f;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGAS, 0.5f, 0.0f, 0.0f);
|
||||
pos = glm::vec3(-42.0f, 0.0f, 17.0f);
|
||||
pos.x += (Math::Rand()-0.5f)*2.0f; pos.z += (Math::Rand()-0.5f)*2.0f;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGAS, 0.5f, 0.0f, 0.0f);
|
||||
pos = glm::vec3(-17.0f, 0.0f, 42.0f);
|
||||
pos.x += (Math::Rand()-0.5f)*2.0f; pos.z += (Math::Rand()-0.5f)*2.0f;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGAS, 0.5f, 0.0f, 0.0f);
|
||||
pos = glm::vec3(-42.0f, 0.0f, -17.0f);
|
||||
pos.x += (Math::Rand()-0.5f)*2.0f; pos.z += (Math::Rand()-0.5f)*2.0f;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGAS, 0.5f, 0.0f, 0.0f);
|
||||
pos = glm::vec3(-17.0f, 0.0f, -42.0f);
|
||||
pos.x += (Math::Rand()-0.5f)*2.0f; pos.z += (Math::Rand()-0.5f)*2.0f;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIGAS, 0.5f, 0.0f, 0.0f);
|
||||
|
||||
pos = glm::vec3(42.0f, -2.0f, 17.0f);
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
m_particle->SetPosition(m_partiChannel[0], pos);
|
||||
pos = glm::vec3(17.0f, -2.0f, 42.0f);
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
m_particle->SetPosition(m_partiChannel[1], pos);
|
||||
pos = glm::vec3(42.0f, -2.0f, -17.0f);
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
m_particle->SetPosition(m_partiChannel[2], pos);
|
||||
pos = glm::vec3(17.0f, -2.0f, -42.0f);
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
m_particle->SetPosition(m_partiChannel[3], pos);
|
||||
pos = glm::vec3(-42.0f, -2.0f, 17.0f);
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
m_particle->SetPosition(m_partiChannel[4], pos);
|
||||
pos = glm::vec3(-17.0f, -2.0f, 42.0f);
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
m_particle->SetPosition(m_partiChannel[5], pos);
|
||||
pos = glm::vec3(-42.0f, -2.0f, -17.0f);
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
m_particle->SetPosition(m_partiChannel[6], pos);
|
||||
pos = glm::vec3(-17.0f, -2.0f, -42.0f);
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
m_particle->SetPosition(m_partiChannel[7], pos);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -207,7 +207,7 @@ bool CAutoFactory::EventProcess(const Event &event)
|
|||
ObjectType type;
|
||||
CObject* cargo;
|
||||
CObject* vehicle;
|
||||
Math::Matrix* mat;
|
||||
glm::mat4 mat;
|
||||
CPhysics* physics;
|
||||
glm::vec3 pos, speed;
|
||||
glm::vec2 dim;
|
||||
|
@ -370,7 +370,7 @@ bool CAutoFactory::EventProcess(const Event &event)
|
|||
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
pos = glm::vec3(-12.0f, 20.0f, -4.0f); // position of chimney
|
||||
pos = Math::Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
pos.y += 2.0f;
|
||||
pos.x += (Math::Rand()-0.5f)*2.0f;
|
||||
pos.z += (Math::Rand()-0.5f)*2.0f;
|
||||
|
@ -656,8 +656,8 @@ bool CAutoFactory::CreateVehicle()
|
|||
{
|
||||
pos = glm::vec3(4.0f, 0.0f, 0.0f);
|
||||
}
|
||||
Math::Matrix* mat = m_object->GetWorldMatrix(0);
|
||||
pos = Transform(*mat, pos);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
pos = Math::Transform(mat, pos);
|
||||
|
||||
ObjectCreateParams params;
|
||||
params.pos = pos;
|
||||
|
|
|
@ -91,14 +91,12 @@ void CAutoNuclearPlant::DeleteObject(bool all)
|
|||
|
||||
void CAutoNuclearPlant::Init()
|
||||
{
|
||||
Math::Matrix* mat;
|
||||
|
||||
m_time = 0.0f;
|
||||
m_timeVirus = 0.0f;
|
||||
m_lastParticle = 0.0f;
|
||||
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
m_pos = Math::Transform(*mat, glm::vec3(22.0f, 4.0f, 0.0f));
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
m_pos = Math::Transform(mat, glm::vec3(22.0f, 4.0f, 0.0f));
|
||||
|
||||
m_phase = ANUP_WAIT; // waiting ...
|
||||
m_progress = 0.0f;
|
||||
|
@ -113,7 +111,6 @@ void CAutoNuclearPlant::Init()
|
|||
bool CAutoNuclearPlant::EventProcess(const Event &event)
|
||||
{
|
||||
CObject* cargo;
|
||||
Math::Matrix* mat;
|
||||
glm::vec3 pos, goal, speed;
|
||||
glm::vec2 dim, rot;
|
||||
float angle;
|
||||
|
@ -177,14 +174,14 @@ bool CAutoNuclearPlant::EventProcess(const Event &event)
|
|||
{
|
||||
m_object->SetPartRotationZ(1, 0.0f);
|
||||
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
max = static_cast< int >(10.0f*m_engine->GetParticleDensity());
|
||||
for ( i=0 ; i<max ; i++ )
|
||||
{
|
||||
pos.x = 27.0f;
|
||||
pos.y = 0.0f;
|
||||
pos.z = (Math::Rand()-0.5f)*8.0f;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
speed.y = 0.0f;
|
||||
speed.x = 0.0f;
|
||||
speed.z = 0.0f;
|
||||
|
|
|
@ -75,14 +75,12 @@ void CAutoPowerCaptor::DeleteObject(bool bAll)
|
|||
|
||||
void CAutoPowerCaptor::Init()
|
||||
{
|
||||
Math::Matrix* mat;
|
||||
|
||||
m_time = 0.0f;
|
||||
m_timeVirus = 0.0f;
|
||||
m_lastParticle = 0.0f;
|
||||
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
m_pos = Math::Transform(*mat, glm::vec3(22.0f, 4.0f, 0.0f));
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
m_pos = Math::Transform(mat, glm::vec3(22.0f, 4.0f, 0.0f));
|
||||
|
||||
m_phase = APAP_WAIT; // waiting ...
|
||||
m_progress = 0.0f;
|
||||
|
|
|
@ -206,9 +206,9 @@ bool CAutoPowerStation::EventProcess(const Event &event)
|
|||
glm::vec3 pos, ppos, speed;
|
||||
glm::vec2 dim;
|
||||
|
||||
Math::Matrix* mat = m_object->GetWorldMatrix(0);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
pos = glm::vec3(-15.0f, 7.0f, 0.0f); // battery position
|
||||
pos = Math::Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
speed.x = (Math::Rand()-0.5f)*20.0f;
|
||||
speed.y = (Math::Rand()-0.5f)*20.0f;
|
||||
speed.z = (Math::Rand()-0.5f)*20.0f;
|
||||
|
|
|
@ -499,7 +499,6 @@ bool CAutoResearch::TestResearch(EventType event)
|
|||
|
||||
void CAutoResearch::FireStopUpdate(float progress, bool bLightOn)
|
||||
{
|
||||
Math::Matrix* mat;
|
||||
glm::vec3 pos, speed;
|
||||
glm::vec2 dim;
|
||||
int i;
|
||||
|
@ -527,7 +526,7 @@ void CAutoResearch::FireStopUpdate(float progress, bool bLightOn)
|
|||
return;
|
||||
}
|
||||
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
|
||||
speed = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
dim.x = 2.0f;
|
||||
|
@ -550,7 +549,7 @@ void CAutoResearch::FireStopUpdate(float progress, bool bLightOn)
|
|||
pos.x = listpos[i*2+0];
|
||||
pos.y = 11.5f;
|
||||
pos.z = listpos[i*2+1];
|
||||
pos = Math::Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
m_partiStop[i] = m_particle->CreateParticle(pos, speed,
|
||||
dim, Gfx::PARTISELY,
|
||||
1.0f, 0.0f, 0.0f);
|
||||
|
|
|
@ -55,16 +55,15 @@ void CAutoRoot::DeleteObject(bool bAll)
|
|||
|
||||
void CAutoRoot::Init()
|
||||
{
|
||||
Math::Matrix* mat;
|
||||
glm::vec3 pos, speed;
|
||||
glm::vec2 dim;
|
||||
|
||||
m_time = 0.0f;
|
||||
m_lastParticle = 0.0f;
|
||||
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
pos = glm::vec3(-5.0f, 28.0f, -4.0f); // peak position
|
||||
pos = Math::Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
m_center = pos;
|
||||
|
||||
speed = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
|
|
|
@ -612,7 +612,6 @@ bool CMotionHuman::EventProcess(const Event &event)
|
|||
|
||||
bool CMotionHuman::EventFrame(const Event &event)
|
||||
{
|
||||
Math::Matrix* mat;
|
||||
glm::vec3 dir, actual, pos, speed, pf;
|
||||
glm::vec2 center, dim, p2;
|
||||
float s, a, prog, rTime[2], lTime[2], time, rot, hr, hl;
|
||||
|
@ -1373,12 +1372,12 @@ bool CMotionHuman::EventFrame(const Event &event)
|
|||
m_object->SetLinVibration(dir);
|
||||
SetLinVibration(dir);
|
||||
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
pos = glm::vec3(0.5f, 3.7f, 0.0f);
|
||||
pos.x += (Math::Rand()-0.5f)*1.0f;
|
||||
pos.y += (Math::Rand()-0.5f)*1.0f;
|
||||
pos.z += (Math::Rand()-0.5f)*1.0f;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
speed.x = (Math::Rand()-0.5f)*0.5f;
|
||||
speed.y = (Math::Rand()-0.5f)*0.5f;
|
||||
speed.z = (Math::Rand()-0.5f)*0.5f;
|
||||
|
|
|
@ -233,7 +233,6 @@ bool CMotionToto::EventProcess(const Event &event)
|
|||
|
||||
bool CMotionToto::EventFrame(const Event &event)
|
||||
{
|
||||
Math::Matrix* mat;
|
||||
glm::vec3 eye, lookat, dir, perp, nPos, aPos, pos, speed;
|
||||
glm::vec3 vibLin, vibCir, dirSpeed, aAntenna;
|
||||
glm::vec2 dim;
|
||||
|
@ -700,7 +699,7 @@ bool CMotionToto::EventFrame(const Event &event)
|
|||
m_object->SetPartRotationX(3, 0.0f);
|
||||
}
|
||||
|
||||
mat = m_object->GetWorldMatrix(0); // must be done every time!
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0); // must be done every time!
|
||||
|
||||
// Generates particles.
|
||||
if ( m_time-m_lastMotorParticle >= m_engine->ParticleAdapt(0.05f) )
|
||||
|
@ -725,8 +724,8 @@ bool CMotionToto::EventFrame(const Event &event)
|
|||
speed.x += Math::Rand()*2.0f;
|
||||
speed.z += (Math::Rand()-0.5f)*2.0f;
|
||||
|
||||
pos = Transform(*mat, pos);
|
||||
speed = Transform(*mat, speed)-pos;
|
||||
pos = Math::Transform(mat, pos);
|
||||
speed = Math::Transform(mat, speed)-pos;
|
||||
|
||||
dim.x = 0.12f;
|
||||
dim.y = dim.x;
|
||||
|
@ -744,8 +743,8 @@ bool CMotionToto::EventFrame(const Event &event)
|
|||
speed.z += (Math::Rand()-0.5f)*2.0f;
|
||||
|
||||
// mat = m_object->GetWorldMatrix(0);
|
||||
pos = Transform(*mat, pos);
|
||||
speed = Transform(*mat, speed)-pos;
|
||||
pos = Math::Transform(mat, pos);
|
||||
speed = Math::Transform(mat, speed)-pos;
|
||||
|
||||
dim.x = (Math::Rand()*0.4f+0.4f)*(1.0f+Math::Min(linSpeed*0.1f, 5.0f));
|
||||
dim.y = dim.x;
|
||||
|
@ -758,7 +757,7 @@ bool CMotionToto::EventFrame(const Event &event)
|
|||
pos.x = (Math::Rand()-0.5f)*1.0f;
|
||||
pos.y = (Math::Rand()-0.5f)*1.0f+3.5f;
|
||||
pos.z = (Math::Rand()-0.5f)*1.0f;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
speed = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
dim.x = (Math::Rand()*0.3f+0.3f);
|
||||
dim.y = dim.x;
|
||||
|
@ -782,7 +781,7 @@ bool CMotionToto::EventFrame(const Event &event)
|
|||
pos.x = (Math::Rand()-0.5f)*1.4f;
|
||||
pos.y = (Math::Rand()-0.5f)*1.4f+3.5f;
|
||||
pos.z = (Math::Rand()-0.5f)*1.4f;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
speed = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
dim.x = (Math::Rand()*0.5f+0.5f);
|
||||
dim.y = dim.x;
|
||||
|
|
|
@ -1382,7 +1382,6 @@ bool CMotionVehicle::EventProcess(const Event &event)
|
|||
|
||||
bool CMotionVehicle::EventFrame(const Event &event)
|
||||
{
|
||||
Math::Matrix* mat;
|
||||
Character* character;
|
||||
glm::vec3 pos, angle, floor;
|
||||
ObjectType type;
|
||||
|
@ -1489,12 +1488,12 @@ bool CMotionVehicle::EventFrame(const Event &event)
|
|||
if ( glm::distance(pos, m_engine->GetEyePt()) < 50.0f ) // suspension?
|
||||
{
|
||||
character = m_object->GetCharacter();
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
|
||||
pos.x = -character->wheelBack; // right back wheel
|
||||
pos.z = -character->wheelRight;
|
||||
pos.y = 0.0f;
|
||||
pos = Math::Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
h = m_terrain->GetHeightToFloor(pos);
|
||||
if ( h > 0.5f ) h = 0.5f;
|
||||
if ( h < -0.5f ) h = -0.5f;
|
||||
|
@ -1507,7 +1506,7 @@ bool CMotionVehicle::EventFrame(const Event &event)
|
|||
pos.x = -character->wheelBack; // left back wheel
|
||||
pos.z = character->wheelLeft;
|
||||
pos.y = 0.0f;
|
||||
pos = Math::Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
h = m_terrain->GetHeightToFloor(pos);
|
||||
if ( h > 0.5f ) h = 0.5f;
|
||||
if ( h < -0.5f ) h = -0.5f;
|
||||
|
@ -1520,7 +1519,7 @@ bool CMotionVehicle::EventFrame(const Event &event)
|
|||
pos.x = character->wheelFront; // right front wheel
|
||||
pos.z = -character->wheelRight;
|
||||
pos.y = 0.0f;
|
||||
pos = Math::Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
h = m_terrain->GetHeightToFloor(pos);
|
||||
if ( h > 0.5f ) h = 0.5f;
|
||||
if ( h < -0.5f ) h = -0.5f;
|
||||
|
@ -1533,7 +1532,7 @@ bool CMotionVehicle::EventFrame(const Event &event)
|
|||
pos.x = character->wheelFront; // left front wheel
|
||||
pos.z = character->wheelLeft;
|
||||
pos.y = 0.0f;
|
||||
pos = Math::Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
h = m_terrain->GetHeightToFloor(pos);
|
||||
if ( h > 0.5f ) h = 0.5f;
|
||||
if ( h < -0.5f ) h = -0.5f;
|
||||
|
@ -1625,18 +1624,18 @@ bool CMotionVehicle::EventFrame(const Event &event)
|
|||
if ( glm::distance(pos, m_engine->GetEyePt()) < 50.0f ) // suspension?
|
||||
{
|
||||
character = m_object->GetCharacter();
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
|
||||
pos.x = character->wheelFront; // right front wheel
|
||||
pos.z = -character->wheelRight;
|
||||
pos.y = 0.0f;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
a1 = atanf(m_terrain->GetHeightToFloor(pos)/character->wheelFront);
|
||||
|
||||
pos.x = -character->wheelBack; // right back wheel
|
||||
pos.z = -character->wheelRight;
|
||||
pos.y = 0.0f;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
a2 = atanf(m_terrain->GetHeightToFloor(pos)/character->wheelBack);
|
||||
|
||||
a = (a2-a1)/2.0f;
|
||||
|
@ -1647,13 +1646,13 @@ bool CMotionVehicle::EventFrame(const Event &event)
|
|||
pos.x = character->wheelFront; // left front wheel
|
||||
pos.z = character->wheelLeft;
|
||||
pos.y = 0.0f;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
a1 = atanf(m_terrain->GetHeightToFloor(pos)/character->wheelFront);
|
||||
|
||||
pos.x = -character->wheelBack; // left back wheel
|
||||
pos.z = character->wheelLeft;
|
||||
pos.y = 0.0f;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
a2 = atanf(m_terrain->GetHeightToFloor(pos)/character->wheelBack);
|
||||
|
||||
a = (a2-a1)/2.0f;
|
||||
|
@ -1740,10 +1739,10 @@ bool CMotionVehicle::EventFrameFly(const Event &event)
|
|||
|
||||
if ( m_physics->GetLand() ) // on the ground?
|
||||
{
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
paw[0] = Transform(*mat, glm::vec3( 4.2f, 0.0f, 0.0f)); // front
|
||||
paw[1] = Transform(*mat, glm::vec3(-3.0f, 0.0f, -3.7f)); // right back
|
||||
paw[2] = Transform(*mat, glm::vec3(-3.0f, 0.0f, 3.7f)); // left back
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
paw[0] = Math::Transform(mat, glm::vec3( 4.2f, 0.0f, 0.0f)); // front
|
||||
paw[1] = Math::Transform(mat, glm::vec3(-3.0f, 0.0f, -3.7f)); // right back
|
||||
paw[2] = Math::Transform(mat, glm::vec3(-3.0f, 0.0f, 3.7f)); // left back
|
||||
|
||||
for ( i=0 ; i<3 ; i++ )
|
||||
{
|
||||
|
|
|
@ -230,7 +230,6 @@ bool CMotionWorm::EventProcess(const Event &event)
|
|||
|
||||
bool CMotionWorm::EventFrame(const Event &event)
|
||||
{
|
||||
Math::Matrix* mat;
|
||||
glm::vec3 pos, p, angle, speed;
|
||||
glm::vec2 center, pp, dim;
|
||||
float height[WORM_PART+2];
|
||||
|
@ -286,7 +285,7 @@ bool CMotionWorm::EventFrame(const Event &event)
|
|||
pos = m_object->GetPosition();
|
||||
floor = m_terrain->GetFloorLevel(pos, true);
|
||||
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
|
||||
px = 1.0f+WORM_PART/2;
|
||||
for ( i=0 ; i<WORM_PART+2 ; i++ )
|
||||
|
@ -311,7 +310,7 @@ bool CMotionWorm::EventFrame(const Event &event)
|
|||
pos.x = pp.x;
|
||||
pos.z = pp.y;
|
||||
|
||||
p = Transform(*mat, pos);
|
||||
p = Math::Transform(mat, pos);
|
||||
pos.y += m_terrain->GetFloorLevel(p, true)-floor;
|
||||
m_object->SetPartPosition(i+1, pos);
|
||||
|
||||
|
|
|
@ -635,10 +635,10 @@ void COldObject::InitPart(int part)
|
|||
m_objectPart[part].bRotate = true;
|
||||
m_objectPart[part].bZoom = false;
|
||||
|
||||
m_objectPart[part].matTranslate.LoadIdentity();
|
||||
m_objectPart[part].matRotate.LoadIdentity();
|
||||
m_objectPart[part].matTransform.LoadIdentity();
|
||||
m_objectPart[part].matWorld.LoadIdentity();;
|
||||
m_objectPart[part].matTranslate = glm::mat4(1.0f);
|
||||
m_objectPart[part].matRotate = glm::mat4(1.0f);
|
||||
m_objectPart[part].matTransform = glm::mat4(1.0f);
|
||||
m_objectPart[part].matWorld = glm::mat4(1.0f);
|
||||
|
||||
m_objectPart[part].masterParti = -1;
|
||||
}
|
||||
|
@ -1720,12 +1720,12 @@ void COldObject::SetTransporterPart(int part)
|
|||
|
||||
// Returns matrices of an object portion.
|
||||
|
||||
Math::Matrix* COldObject::GetRotateMatrix(int part)
|
||||
Math::Matrix COldObject::GetRotateMatrix(int part)
|
||||
{
|
||||
return &m_objectPart[part].matRotate;
|
||||
return m_objectPart[part].matRotate;
|
||||
}
|
||||
|
||||
Math::Matrix* COldObject::GetWorldMatrix(int part)
|
||||
Math::Matrix COldObject::GetWorldMatrix(int part)
|
||||
{
|
||||
if ( m_objectPart[0].bTranslate ||
|
||||
m_objectPart[0].bRotate )
|
||||
|
@ -1733,7 +1733,7 @@ Math::Matrix* COldObject::GetWorldMatrix(int part)
|
|||
UpdateTransformObject();
|
||||
}
|
||||
|
||||
return &m_objectPart[part].matWorld;
|
||||
return m_objectPart[part].matWorld;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1847,10 +1847,10 @@ bool COldObject::UpdateTransformObject(int part, bool bForceUpdate)
|
|||
{
|
||||
if ( m_objectPart[part].bTranslate )
|
||||
{
|
||||
m_objectPart[part].matTranslate.LoadIdentity();
|
||||
m_objectPart[part].matTranslate.Set(1, 4, position.x);
|
||||
m_objectPart[part].matTranslate.Set(2, 4, position.y);
|
||||
m_objectPart[part].matTranslate.Set(3, 4, position.z);
|
||||
m_objectPart[part].matTranslate = glm::mat4(1.0f);
|
||||
m_objectPart[part].matTranslate[3][0] = position.x;
|
||||
m_objectPart[part].matTranslate[3][1] = position.y;
|
||||
m_objectPart[part].matTranslate[3][2] = position.z;
|
||||
}
|
||||
|
||||
if ( m_objectPart[part].bRotate )
|
||||
|
@ -1860,18 +1860,15 @@ bool COldObject::UpdateTransformObject(int part, bool bForceUpdate)
|
|||
|
||||
if ( m_objectPart[part].bZoom )
|
||||
{
|
||||
Math::Matrix mz;
|
||||
mz.LoadIdentity();
|
||||
mz.Set(1, 1, m_objectPart[part].zoom.x);
|
||||
mz.Set(2, 2, m_objectPart[part].zoom.y);
|
||||
mz.Set(3, 3, m_objectPart[part].zoom.z);
|
||||
m_objectPart[part].matTransform = Math::MultiplyMatrices(m_objectPart[part].matTranslate,
|
||||
Math::MultiplyMatrices(m_objectPart[part].matRotate, mz));
|
||||
glm::mat4 mz = glm::mat4(1.0f);
|
||||
mz[0][0] = m_objectPart[part].zoom.x;
|
||||
mz[1][1] = m_objectPart[part].zoom.y;
|
||||
mz[2][2] = m_objectPart[part].zoom.z;
|
||||
m_objectPart[part].matTransform = m_objectPart[part].matTranslate * m_objectPart[part].matRotate * mz;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_objectPart[part].matTransform = Math::MultiplyMatrices(m_objectPart[part].matTranslate,
|
||||
m_objectPart[part].matRotate);
|
||||
m_objectPart[part].matTransform = m_objectPart[part].matTranslate * m_objectPart[part].matRotate;
|
||||
}
|
||||
bModif = true;
|
||||
}
|
||||
|
@ -1884,10 +1881,8 @@ bool COldObject::UpdateTransformObject(int part, bool bForceUpdate)
|
|||
|
||||
if ( part == 0 && m_transporter != nullptr ) // transported by a transporter?
|
||||
{
|
||||
Math::Matrix* matWorldTransporter;
|
||||
matWorldTransporter = m_transporter->GetWorldMatrix(m_transporterLink);
|
||||
m_objectPart[part].matWorld = Math::MultiplyMatrices(*matWorldTransporter,
|
||||
m_objectPart[part].matTransform);
|
||||
glm::mat4 matWorldTransporter = m_transporter->GetWorldMatrix(m_transporterLink);
|
||||
m_objectPart[part].matWorld = matWorldTransporter * m_objectPart[part].matTransform;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1897,8 +1892,7 @@ bool COldObject::UpdateTransformObject(int part, bool bForceUpdate)
|
|||
}
|
||||
else
|
||||
{
|
||||
m_objectPart[part].matWorld = Math::MultiplyMatrices(m_objectPart[parent].matWorld,
|
||||
m_objectPart[part].matTransform);
|
||||
m_objectPart[part].matWorld = m_objectPart[parent].matWorld * m_objectPart[part].matTransform;
|
||||
}
|
||||
}
|
||||
bModif = true;
|
||||
|
@ -1988,17 +1982,17 @@ void COldObject::FlatParent()
|
|||
|
||||
for ( i=0 ; i<m_totalPart ; i++ )
|
||||
{
|
||||
m_objectPart[i].position.x = m_objectPart[i].matWorld.Get(1, 4);
|
||||
m_objectPart[i].position.y = m_objectPart[i].matWorld.Get(2, 4);
|
||||
m_objectPart[i].position.z = m_objectPart[i].matWorld.Get(3, 4);
|
||||
m_objectPart[i].position.x = m_objectPart[i].matWorld[3][0];
|
||||
m_objectPart[i].position.y = m_objectPart[i].matWorld[3][1];
|
||||
m_objectPart[i].position.z = m_objectPart[i].matWorld[3][2];
|
||||
|
||||
m_objectPart[i].matWorld.Set(1, 4, 0.0f);
|
||||
m_objectPart[i].matWorld.Set(2, 4, 0.0f);
|
||||
m_objectPart[i].matWorld.Set(3, 4, 0.0f);
|
||||
m_objectPart[i].matWorld[3][0] = 0.0f;
|
||||
m_objectPart[i].matWorld[3][1] = 0.0f;
|
||||
m_objectPart[i].matWorld[3][2] = 0.0f;
|
||||
|
||||
m_objectPart[i].matTranslate.Set(1, 4, 0.0f);
|
||||
m_objectPart[i].matTranslate.Set(2, 4, 0.0f);
|
||||
m_objectPart[i].matTranslate.Set(3, 4, 0.0f);
|
||||
m_objectPart[i].matTranslate[3][0] = 0.0f;
|
||||
m_objectPart[i].matTranslate[3][1] = 0.0f;
|
||||
m_objectPart[i].matTranslate[3][2] = 0.0f;
|
||||
|
||||
m_objectPart[i].parentPart = -1; // more parents
|
||||
}
|
||||
|
|
|
@ -185,8 +185,8 @@ public:
|
|||
CObject* GetTransporter() override;
|
||||
void SetTransporterPart(int part) override;
|
||||
|
||||
Math::Matrix* GetRotateMatrix(int part);
|
||||
Math::Matrix* GetWorldMatrix(int part) override;
|
||||
glm::mat4 GetRotateMatrix(int part);
|
||||
glm::mat4 GetWorldMatrix(int part) override;
|
||||
|
||||
void AdjustCamera(glm::vec3 &eye, float &dirH, float &dirV,
|
||||
glm::vec3 &lookat, glm::vec3 &upVec,
|
||||
|
|
|
@ -78,7 +78,7 @@ void COldObjectInterface::SetMasterParticle(int part, int parti)
|
|||
throw std::logic_error("SetMasterParticle: not implemented!");
|
||||
}
|
||||
|
||||
Math::Matrix* COldObjectInterface::GetWorldMatrix(int part)
|
||||
glm::mat4 COldObjectInterface::GetWorldMatrix(int part)
|
||||
{
|
||||
throw std::logic_error("GetWorldMatrix: not implemented!");
|
||||
}
|
||||
|
|
|
@ -28,11 +28,6 @@
|
|||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
namespace Math
|
||||
{
|
||||
struct Matrix;
|
||||
} // namespace Math
|
||||
|
||||
class CAuto;
|
||||
|
||||
|
||||
|
@ -70,7 +65,7 @@ public:
|
|||
|
||||
virtual void SetMasterParticle(int part, int parti);
|
||||
|
||||
virtual Math::Matrix* GetWorldMatrix(int part);
|
||||
virtual glm::mat4 GetWorldMatrix(int part);
|
||||
|
||||
virtual Character* GetCharacter();
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ CStaticObject::CStaticObject(int id,
|
|||
m_position = position;
|
||||
m_rotation.y = angleY;
|
||||
|
||||
Math::Matrix worldMatrix = ComputeWorldMatrix(position, angleY);
|
||||
glm::mat4 worldMatrix = ComputeWorldMatrix(position, angleY);
|
||||
m_meshHandle = m_engine->AddStaticMesh(key, mesh, worldMatrix);
|
||||
|
||||
if (model.HasShadowSpot())
|
||||
|
@ -74,15 +74,15 @@ CStaticObject::~CStaticObject()
|
|||
m_engine->DeleteStaticMesh(m_meshHandle);
|
||||
}
|
||||
|
||||
Math::Matrix CStaticObject::ComputeWorldMatrix(const glm::vec3& position, float angleY)
|
||||
glm::mat4 CStaticObject::ComputeWorldMatrix(const glm::vec3& position, float angleY)
|
||||
{
|
||||
Math::Matrix translationMatrix;
|
||||
glm::mat4 translationMatrix;
|
||||
Math::LoadTranslationMatrix(translationMatrix, position);
|
||||
|
||||
Math::Matrix rotationMatrix;
|
||||
glm::mat4 rotationMatrix;
|
||||
Math::LoadRotationZXYMatrix(rotationMatrix, glm::vec3(0.0f, angleY, 0.0f));
|
||||
|
||||
return Math::MultiplyMatrices(translationMatrix, rotationMatrix);
|
||||
return translationMatrix * rotationMatrix;
|
||||
}
|
||||
|
||||
void CStaticObject::Read(CLevelParserLine* line)
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
|
||||
#include "object/object.h"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
|
@ -70,8 +72,7 @@ protected:
|
|||
void TransformCameraCollisionSphere(Math::Sphere& collisionSphere) override;
|
||||
|
||||
private:
|
||||
static Math::Matrix ComputeWorldMatrix(const glm::vec3& position,
|
||||
float angleY);
|
||||
static glm::mat4 ComputeWorldMatrix(const glm::vec3& position, float angleY);
|
||||
|
||||
private:
|
||||
Gfx::CEngine* m_engine;
|
||||
|
|
|
@ -203,7 +203,6 @@ void CTaskBuild::BlackLight()
|
|||
|
||||
bool CTaskBuild::EventProcess(const Event &event)
|
||||
{
|
||||
Math::Matrix* mat;
|
||||
glm::vec3 pos, dir, speed, pv, pm, tilt;
|
||||
glm::vec2 dim;
|
||||
float a, g, cirSpeed, dist, linSpeed, diff;
|
||||
|
@ -324,6 +323,8 @@ bool CTaskBuild::EventProcess(const Event &event)
|
|||
dim.y = dim.x;
|
||||
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIFIRE);
|
||||
|
||||
glm::mat4 mat{};
|
||||
|
||||
pos = glm::vec3(0.0f, 0.5f, 0.0f);
|
||||
switch(m_object->GetType())
|
||||
{
|
||||
|
@ -343,7 +344,7 @@ bool CTaskBuild::EventProcess(const Event &event)
|
|||
mat = m_object->GetWorldMatrix(0);
|
||||
break;
|
||||
}
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
speed = m_metal->GetPosition();
|
||||
speed.x += (Math::Rand()-0.5f)*5.0f;
|
||||
speed.z += (Math::Rand()-0.5f)*5.0f;
|
||||
|
|
|
@ -63,7 +63,6 @@ CTaskFire::~CTaskFire()
|
|||
bool CTaskFire::EventProcess(const Event &event)
|
||||
{
|
||||
CPhysics* physics;
|
||||
Math::Matrix* mat;
|
||||
glm::vec3 pos, speed, dir, vib;
|
||||
ObjectType type;
|
||||
glm::vec2 dim;
|
||||
|
@ -96,12 +95,12 @@ bool CTaskFire::EventProcess(const Event &event)
|
|||
|
||||
if ( m_bOrganic )
|
||||
{
|
||||
mat = m_object->GetWorldMatrix(1); // insect-cannon
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(1); // insect-cannon
|
||||
|
||||
for ( i=0 ; i<6 ; i++ )
|
||||
{
|
||||
pos = glm::vec3(0.0f, 2.5f, 0.0f);
|
||||
pos = Math::Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
|
||||
speed = glm::vec3(200.0f, 0.0f, 0.0f);
|
||||
|
||||
|
@ -114,7 +113,7 @@ bool CTaskFire::EventProcess(const Event &event)
|
|||
speed.x += (Math::Rand()-0.5f)*10.0f;
|
||||
speed.y += (Math::Rand()-0.5f)*20.0f;
|
||||
speed.z += (Math::Rand()-0.5f)*30.0f;
|
||||
speed = Math::Transform(*mat, speed);
|
||||
speed = Math::Transform(mat, speed);
|
||||
speed -= pos;
|
||||
|
||||
dim.x = Math::Rand()*0.5f+0.5f;
|
||||
|
@ -126,20 +125,20 @@ bool CTaskFire::EventProcess(const Event &event)
|
|||
}
|
||||
else if ( m_bRay )
|
||||
{
|
||||
mat = m_object->GetWorldMatrix(2); // cannon
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(2); // cannon
|
||||
|
||||
for ( i=0 ; i<4 ; i++ )
|
||||
{
|
||||
pos = glm::vec3(4.0f, 0.0f, 0.0f);
|
||||
pos.y += (rand()%3-1)*1.5f;
|
||||
pos.z += (rand()%3-1)*1.5f;
|
||||
pos = Math::Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
|
||||
speed = glm::vec3(200.0f, 0.0f, 0.0f);
|
||||
speed.x += (Math::Rand()-0.5f)*6.0f;
|
||||
speed.y += (Math::Rand()-0.5f)*12.0f;
|
||||
speed.z += (Math::Rand()-0.5f)*12.0f;
|
||||
speed = Math::Transform(*mat, speed);
|
||||
speed = Math::Transform(mat, speed);
|
||||
speed -= pos;
|
||||
|
||||
dim.x = 1.0f;
|
||||
|
@ -152,7 +151,7 @@ bool CTaskFire::EventProcess(const Event &event)
|
|||
speed.x += (Math::Rand()-0.5f)*1.0f;
|
||||
speed.y += (Math::Rand()-0.5f)*2.0f;
|
||||
speed.z += (Math::Rand()-0.5f)*2.0f;
|
||||
speed = Math::Transform(*mat, speed);
|
||||
speed = Math::Transform(mat, speed);
|
||||
speed -= pos;
|
||||
speed.y += 5.0f;
|
||||
|
||||
|
@ -165,6 +164,8 @@ bool CTaskFire::EventProcess(const Event &event)
|
|||
{
|
||||
type = m_object->GetType();
|
||||
|
||||
glm::mat4 mat = glm::mat4(1.0f);
|
||||
|
||||
if ( type == OBJECT_MOBILErc )
|
||||
{
|
||||
mat = m_object->GetWorldMatrix(2); // cannon
|
||||
|
@ -186,7 +187,7 @@ bool CTaskFire::EventProcess(const Event &event)
|
|||
}
|
||||
pos.y += (Math::Rand()-0.5f)*1.0f;
|
||||
pos.z += (Math::Rand()-0.5f)*1.0f;
|
||||
pos = Math::Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
|
||||
speed = glm::vec3(200.0f, 0.0f, 0.0f);
|
||||
|
||||
|
@ -199,7 +200,7 @@ bool CTaskFire::EventProcess(const Event &event)
|
|||
speed.x += (Math::Rand()-0.5f)*3.0f;
|
||||
speed.y += (Math::Rand()-0.5f)*6.0f;
|
||||
speed.z += (Math::Rand()-0.5f)*6.0f;
|
||||
speed = Math::Transform(*mat, speed);
|
||||
speed = Math::Transform(mat, speed);
|
||||
speed -= pos;
|
||||
|
||||
dim.x = Math::Rand()*0.7f+0.7f;
|
||||
|
@ -215,13 +216,13 @@ bool CTaskFire::EventProcess(const Event &event)
|
|||
pos = glm::vec3(-1.0f, 1.0f, 0.0f);
|
||||
pos.y += (Math::Rand()-0.5f)*0.4f;
|
||||
pos.z += (Math::Rand()-0.5f)*0.4f;
|
||||
pos = Math::Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
|
||||
speed = glm::vec3(-4.0f, 0.0f, 0.0f);
|
||||
speed.x += (Math::Rand()-0.5f)*2.0f;
|
||||
speed.y += (Math::Rand()-0.2f)*4.0f;
|
||||
speed.z += (Math::Rand()-0.5f)*4.0f;
|
||||
speed = Math::Transform(*mat, speed);
|
||||
speed = Math::Transform(mat, speed);
|
||||
speed -= pos;
|
||||
|
||||
dim.x = Math::Rand()*1.2f+1.2f;
|
||||
|
|
|
@ -248,17 +248,17 @@ Error CTaskFlag::CreateFlag(int rank)
|
|||
OBJECT_FLAGv,
|
||||
};
|
||||
|
||||
Math::Matrix* mat = m_object->GetWorldMatrix(0);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
glm::vec3 pos;
|
||||
switch ( m_object->GetType() )
|
||||
{
|
||||
case OBJECT_HUMAN:
|
||||
case OBJECT_TECH:
|
||||
pos = Transform(*mat, glm::vec3(4.0f, 0.0f, 0.0f));
|
||||
pos = Math::Transform(mat, glm::vec3(4.0f, 0.0f, 0.0f));
|
||||
break;
|
||||
|
||||
default:
|
||||
pos = Transform(*mat, glm::vec3(6.0f, 0.0f, 0.0f));
|
||||
pos = Math::Transform(mat, glm::vec3(6.0f, 0.0f, 0.0f));
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -1129,7 +1129,6 @@ CObject* CTaskGoto::SearchTarget(glm::vec3 pos, float margin)
|
|||
bool CTaskGoto::AdjustTarget(CObject* pObj, glm::vec3 &pos, float &distance)
|
||||
{
|
||||
ObjectType type;
|
||||
Math::Matrix* mat;
|
||||
glm::vec3 goal;
|
||||
float dist, suppl;
|
||||
|
||||
|
@ -1204,8 +1203,8 @@ bool CTaskGoto::AdjustTarget(CObject* pObj, glm::vec3 &pos, float &distance)
|
|||
assert(pObj->Implements(ObjectInterfaceType::Powered));
|
||||
pos = dynamic_cast<CPoweredObject&>(*pObj).GetPowerPosition();
|
||||
pos.x -= TAKE_DIST+TAKE_DIST_OTHER+distance;
|
||||
mat = pObj->GetWorldMatrix(0);
|
||||
pos = Transform(*mat, pos);
|
||||
glm::mat4 mat = pObj->GetWorldMatrix(0);
|
||||
pos = Math::Transform(mat, pos);
|
||||
return false; // single approach
|
||||
}
|
||||
|
||||
|
@ -1251,7 +1250,6 @@ bool CTaskGoto::GetHotPoint(CObject *pObj, glm::vec3 &pos,
|
|||
bool bTake, float distance, float &suppl)
|
||||
{
|
||||
ObjectType type;
|
||||
Math::Matrix* mat;
|
||||
|
||||
pos = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
suppl = 0.0f;
|
||||
|
@ -1259,110 +1257,110 @@ bool CTaskGoto::GetHotPoint(CObject *pObj, glm::vec3 &pos,
|
|||
|
||||
if ( type == OBJECT_DERRICK )
|
||||
{
|
||||
mat = pObj->GetWorldMatrix(0);
|
||||
glm::mat4 mat = pObj->GetWorldMatrix(0);
|
||||
pos.x += 8.0f;
|
||||
if ( bTake && distance != 0.0f ) suppl = 4.0f;
|
||||
if ( bTake ) pos.x += TAKE_DIST+distance+suppl;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( type == OBJECT_CONVERT )
|
||||
{
|
||||
mat = pObj->GetWorldMatrix(0);
|
||||
glm::mat4 mat = pObj->GetWorldMatrix(0);
|
||||
pos.x += 0.0f;
|
||||
if ( bTake && distance != 0.0f ) suppl = 4.0f;
|
||||
if ( bTake ) pos.x += TAKE_DIST+distance+suppl;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( type == OBJECT_RESEARCH )
|
||||
{
|
||||
mat = pObj->GetWorldMatrix(0);
|
||||
glm::mat4 mat = pObj->GetWorldMatrix(0);
|
||||
pos.x += 10.0f;
|
||||
if ( bTake && distance != 0.0f ) suppl = 2.5f;
|
||||
if ( bTake ) pos.x += TAKE_DIST+TAKE_DIST_OTHER+distance+suppl;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( type == OBJECT_ENERGY )
|
||||
{
|
||||
mat = pObj->GetWorldMatrix(0);
|
||||
glm::mat4 mat = pObj->GetWorldMatrix(0);
|
||||
pos.x += 6.0f;
|
||||
if ( bTake && distance != 0.0f ) suppl = 6.0f;
|
||||
if ( bTake ) pos.x += TAKE_DIST+TAKE_DIST_OTHER+distance;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( type == OBJECT_TOWER )
|
||||
{
|
||||
mat = pObj->GetWorldMatrix(0);
|
||||
glm::mat4 mat = pObj->GetWorldMatrix(0);
|
||||
pos.x += 5.0f;
|
||||
if ( bTake && distance != 0.0f ) suppl = 4.0f;
|
||||
if ( bTake ) pos.x += TAKE_DIST+TAKE_DIST_OTHER+distance+suppl;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( type == OBJECT_LABO )
|
||||
{
|
||||
mat = pObj->GetWorldMatrix(0);
|
||||
glm::mat4 mat = pObj->GetWorldMatrix(0);
|
||||
pos.x += 6.0f;
|
||||
if ( bTake && distance != 0.0f ) suppl = 6.0f;
|
||||
if ( bTake ) pos.x += TAKE_DIST+TAKE_DIST_OTHER+distance;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( type == OBJECT_NUCLEAR )
|
||||
{
|
||||
mat = pObj->GetWorldMatrix(0);
|
||||
glm::mat4 mat = pObj->GetWorldMatrix(0);
|
||||
pos.x += 22.0f;
|
||||
if ( bTake && distance != 0.0f ) suppl = 4.0f;
|
||||
if ( bTake ) pos.x += TAKE_DIST+TAKE_DIST_OTHER+distance+suppl;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( type == OBJECT_FACTORY )
|
||||
{
|
||||
mat = pObj->GetWorldMatrix(0);
|
||||
glm::mat4 mat = pObj->GetWorldMatrix(0);
|
||||
pos.x += 4.0f;
|
||||
if ( bTake && distance != 0.0f ) suppl = 6.0f;
|
||||
if ( bTake ) pos.x += TAKE_DIST+distance+suppl;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( type == OBJECT_STATION )
|
||||
{
|
||||
mat = pObj->GetWorldMatrix(0);
|
||||
glm::mat4 mat = pObj->GetWorldMatrix(0);
|
||||
pos.x += 4.0f;
|
||||
if ( bTake && distance != 0.0f ) suppl = 4.0f;
|
||||
if ( bTake ) pos.x += distance;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( type == OBJECT_REPAIR )
|
||||
{
|
||||
mat = pObj->GetWorldMatrix(0);
|
||||
glm::mat4 mat = pObj->GetWorldMatrix(0);
|
||||
pos.x += 4.0f;
|
||||
if ( bTake && distance != 0.0f ) suppl = 4.0f;
|
||||
if ( bTake ) pos.x += distance;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( type == OBJECT_PARA && m_object->Implements(ObjectInterfaceType::Flying) )
|
||||
{
|
||||
mat = pObj->GetWorldMatrix(0);
|
||||
glm::mat4 mat = pObj->GetWorldMatrix(0);
|
||||
if ( bTake && distance != 0.0f ) suppl = 20.0f;
|
||||
if ( bTake ) pos.x += distance+suppl;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -870,7 +870,6 @@ CObject* CTaskManip::SearchOtherObject(bool bAdvance, glm::vec3 &pos,
|
|||
float &distance, float &angle,
|
||||
float &height)
|
||||
{
|
||||
Math::Matrix* mat;
|
||||
float iAngle, oAngle, oLimit, aLimit, dLimit;
|
||||
|
||||
distance = 1000000.0f;
|
||||
|
@ -910,8 +909,8 @@ CObject* CTaskManip::SearchOtherObject(bool bAdvance, glm::vec3 &pos,
|
|||
if (power->GetScaleY() != 1.0f) continue;
|
||||
}
|
||||
|
||||
mat = pObj->GetWorldMatrix(0);
|
||||
glm::vec3 oPos = Transform(*mat, dynamic_cast<CPoweredObject&>(*pObj).GetPowerPosition());
|
||||
glm::mat4 mat = pObj->GetWorldMatrix(0);
|
||||
glm::vec3 oPos = Math::Transform(mat, dynamic_cast<CPoweredObject&>(*pObj).GetPowerPosition());
|
||||
|
||||
oAngle = pObj->GetRotationY();
|
||||
if ( type == OBJECT_TOWER ||
|
||||
|
@ -1128,8 +1127,8 @@ bool CTaskManip::TransporterDeposeObject()
|
|||
|
||||
m_cargoType = cargo->GetType();
|
||||
|
||||
Math::Matrix* mat = cargo->GetWorldMatrix(0);
|
||||
glm::vec3 pos = Transform(*mat, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
glm::mat4 mat = cargo->GetWorldMatrix(0);
|
||||
glm::vec3 pos = Math::Transform(mat, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
m_terrain->AdjustToFloor(pos);
|
||||
cargo->SetPosition(pos);
|
||||
cargo->SetRotationY(m_object->GetRotationY()+Math::PI/2.0f);
|
||||
|
@ -1149,8 +1148,8 @@ bool CTaskManip::TransporterDeposeObject()
|
|||
|
||||
m_cargoType = cargo->GetType();
|
||||
|
||||
Math::Matrix* mat = cargo->GetWorldMatrix(0);
|
||||
glm::vec3 pos = Transform(*mat, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
glm::mat4 mat = cargo->GetWorldMatrix(0);
|
||||
glm::vec3 pos = Math::Transform(mat, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
m_terrain->AdjustToFloor(pos);
|
||||
cargo->SetPosition(pos);
|
||||
cargo->SetRotationY(m_object->GetRotationY()+Math::PI/2.0f);
|
||||
|
@ -1221,8 +1220,8 @@ bool CTaskManip::TransporterDeposeObject()
|
|||
|
||||
bool CTaskManip::IsFreeDeposeObject(glm::vec3 pos)
|
||||
{
|
||||
Math::Matrix* mat = m_object->GetWorldMatrix(0);
|
||||
glm::vec3 iPos = Transform(*mat, pos);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
glm::vec3 iPos = Math::Transform(mat, pos);
|
||||
|
||||
for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
|
|
|
@ -197,9 +197,9 @@ Error CTaskRecover::Start()
|
|||
float energy = dynamic_cast<CPowerContainerObject&>(*power).GetEnergy();
|
||||
if ( energy < ENERGY_RECOVER+0.05f ) return ERR_RECOVER_ENERGY;
|
||||
|
||||
Math::Matrix* mat = m_object->GetWorldMatrix(0);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
glm::vec3 pos = glm::vec3(RECOVER_DIST, 3.3f, 0.0f);
|
||||
pos = Transform(*mat, pos); // position in front
|
||||
pos = Math::Transform(mat, pos); // position in front
|
||||
m_recoverPos = pos;
|
||||
|
||||
m_ruin = SearchRuin();
|
||||
|
@ -228,7 +228,6 @@ Error CTaskRecover::Start()
|
|||
|
||||
Error CTaskRecover::IsEnded()
|
||||
{
|
||||
Math::Matrix* mat;
|
||||
glm::vec3 pos, speed, goal;
|
||||
glm::vec2 dim;
|
||||
float angle, dist, time;
|
||||
|
@ -272,9 +271,9 @@ Error CTaskRecover::IsEnded()
|
|||
{
|
||||
m_physics->SetMotorSpeedX(0.0f);
|
||||
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
pos = glm::vec3(RECOVER_DIST, 3.3f, 0.0f);
|
||||
pos = Transform(*mat, pos); // position in front
|
||||
pos = Math::Transform(mat, pos); // position in front
|
||||
m_recoverPos = pos;
|
||||
|
||||
i = m_sound->Play(SOUND_MANIP, m_object->GetPosition(), 0.0f, 0.9f, true);
|
||||
|
@ -308,11 +307,11 @@ Error CTaskRecover::IsEnded()
|
|||
m_metal->SetLock(true); // metal not yet usable
|
||||
m_metal->SetScale(0.0f);
|
||||
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
pos = glm::vec3(RECOVER_DIST, 3.1f, 3.9f);
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
goal = glm::vec3(RECOVER_DIST, 3.1f, -3.9f);
|
||||
goal = Transform(*mat, goal);
|
||||
goal = Math::Transform(mat, goal);
|
||||
m_particle->CreateRay(pos, goal, Gfx::PARTIRAY2,
|
||||
{ 2.0f, 2.0f }, 8.0f);
|
||||
|
||||
|
|
|
@ -53,7 +53,6 @@ CTaskSearch::~CTaskSearch()
|
|||
|
||||
bool CTaskSearch::EventProcess(const Event &event)
|
||||
{
|
||||
Math::Matrix* mat;
|
||||
glm::vec3 pos, speed;
|
||||
glm::vec2 dim;
|
||||
float angle;
|
||||
|
@ -82,9 +81,9 @@ bool CTaskSearch::EventProcess(const Event &event)
|
|||
{
|
||||
m_lastParticle = m_time;
|
||||
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
pos = glm::vec3(6.5f, 0.2f, 0.0f);
|
||||
pos = Math::Transform(*mat, pos); // sensor position
|
||||
pos = Math::Transform(mat, pos); // sensor position
|
||||
|
||||
speed.x = (Math::Rand()-0.5f)*20.0f;
|
||||
speed.z = (Math::Rand()-0.5f)*20.0f;
|
||||
|
@ -239,9 +238,9 @@ bool CTaskSearch::Abort()
|
|||
|
||||
bool CTaskSearch::CreateMark()
|
||||
{
|
||||
Math::Matrix* mat = m_object->GetWorldMatrix(0);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
glm::vec3 pos = glm::vec3(7.5f, 0.0f, 0.0f);
|
||||
pos = Math::Transform(*mat, pos); // sensor position
|
||||
pos = Math::Transform(mat, pos); // sensor position
|
||||
|
||||
Gfx::TerrainRes res = m_terrain->GetResource(pos);
|
||||
if ( res == Gfx::TR_NULL ) return false;
|
||||
|
|
|
@ -70,7 +70,6 @@ CTaskShield::~CTaskShield()
|
|||
|
||||
bool CTaskShield::EventProcess(const Event &event)
|
||||
{
|
||||
Math::Matrix* mat;
|
||||
Math::Matrix matrix;
|
||||
glm::vec3 pos, speed, goal, angle;
|
||||
Gfx::Color color;
|
||||
|
@ -85,9 +84,9 @@ bool CTaskShield::EventProcess(const Event &event)
|
|||
m_time += event.rTime;
|
||||
m_delay -= event.rTime;
|
||||
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
pos = glm::vec3(7.0f, 15.0f, 0.0f);
|
||||
pos = Math::Transform(*mat, pos); // sphere position
|
||||
pos = Math::Transform(mat, pos); // sphere position
|
||||
m_shieldPos = pos;
|
||||
|
||||
if ( m_rankSphere != -1 )
|
||||
|
@ -271,9 +270,9 @@ Error CTaskShield::Start(TaskShieldMode mode, float delay)
|
|||
pos.z = 0.0f;
|
||||
m_object->SetPartPosition(3, pos);
|
||||
|
||||
Math::Matrix* mat = m_object->GetWorldMatrix(0);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
pos = glm::vec3(7.0f, 15.0f, 0.0f);
|
||||
pos = Transform(*mat, pos); // sphere position
|
||||
pos = Math::Transform(mat, pos); // sphere position
|
||||
m_shieldPos = pos;
|
||||
|
||||
pos = m_shieldPos;
|
||||
|
@ -312,9 +311,9 @@ Error CTaskShield::Start(TaskShieldMode mode, float delay)
|
|||
float energy = dynamic_cast<CPowerContainerObject&>(*power).GetEnergy();
|
||||
if ( energy == 0.0f ) return ERR_SHIELD_ENERGY;
|
||||
|
||||
Math::Matrix* mat = m_object->GetWorldMatrix(0);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
glm::vec3 pos = glm::vec3(7.0f, 15.0f, 0.0f);
|
||||
pos = Transform(*mat, pos); // sphere position
|
||||
pos = Math::Transform(mat, pos); // sphere position
|
||||
m_shieldPos = pos;
|
||||
|
||||
m_sound->Play(SOUND_PSHHH2, m_shieldPos, 1.0f, 0.7f);
|
||||
|
|
|
@ -397,8 +397,8 @@ CObject* CTaskTake::SearchFriendObject(float &angle,
|
|||
if ( power->GetScaleY() != 1.0f ) continue;
|
||||
}
|
||||
|
||||
Math::Matrix* mat = pObj->GetWorldMatrix(0);
|
||||
glm::vec3 oPos = Math::Transform(*mat, dynamic_cast<CPoweredObject&>(*pObj).GetPowerPosition());
|
||||
glm::mat4 mat = pObj->GetWorldMatrix(0);
|
||||
glm::vec3 oPos = Math::Transform(mat, dynamic_cast<CPoweredObject&>(*pObj).GetPowerPosition());
|
||||
|
||||
float distance = fabs(glm::distance(oPos, iPos) - (iRad+1.0f));
|
||||
if ( distance <= dLimit )
|
||||
|
@ -483,8 +483,8 @@ bool CTaskTake::TransporterDeposeObject()
|
|||
|
||||
m_cargoType = cargo->GetType();
|
||||
|
||||
Math::Matrix* mat = cargo->GetWorldMatrix(0);
|
||||
glm::vec3 pos = Transform(*mat, glm::vec3(-0.5f, 1.0f, 0.0f));
|
||||
glm::mat4 mat = cargo->GetWorldMatrix(0);
|
||||
glm::vec3 pos = Math::Transform(mat, glm::vec3(-0.5f, 1.0f, 0.0f));
|
||||
m_terrain->AdjustToFloor(pos);
|
||||
cargo->SetPosition(pos);
|
||||
cargo->SetRotationY(m_object->GetRotationY()+Math::PI/2.0f);
|
||||
|
@ -530,8 +530,8 @@ bool CTaskTake::TransporterDeposeObject()
|
|||
|
||||
bool CTaskTake::IsFreeDeposeObject(glm::vec3 pos)
|
||||
{
|
||||
Math::Matrix* mat = m_object->GetWorldMatrix(0);
|
||||
glm::vec3 iPos = Transform(*mat, pos);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
glm::vec3 iPos = Math::Transform(mat, pos);
|
||||
|
||||
for (CObject* pObj : CObjectManager::GetInstancePointer()->GetAllObjects())
|
||||
{
|
||||
|
|
|
@ -69,7 +69,6 @@ CTaskTerraform::~CTaskTerraform()
|
|||
bool CTaskTerraform::EventProcess(const Event &event)
|
||||
{
|
||||
CObject* power;
|
||||
Math::Matrix* mat;
|
||||
glm::vec3 pos, dir, speed;
|
||||
glm::vec2 dim;
|
||||
float energy;
|
||||
|
@ -143,7 +142,7 @@ bool CTaskTerraform::EventProcess(const Event &event)
|
|||
{
|
||||
m_lastParticle = m_time;
|
||||
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
|
||||
if ( m_phase == TTP_CHARGE )
|
||||
{
|
||||
|
@ -151,7 +150,7 @@ bool CTaskTerraform::EventProcess(const Event &event)
|
|||
pos = glm::vec3(-6.0f, 5.5f+2.0f*m_progress, 0.0f);
|
||||
pos.x += (Math::Rand()-0.5f)*1.0f;
|
||||
pos.z += (Math::Rand()-0.5f)*1.0f;
|
||||
pos = Math::Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
speed.x = (Math::Rand()-0.5f)*6.0f*(1.0f+m_progress*4.0f);
|
||||
speed.z = (Math::Rand()-0.5f)*6.0f*(1.0f+m_progress*4.0f);
|
||||
speed.y = 6.0f+Math::Rand()*4.0f*(1.0f+m_progress*2.0f);
|
||||
|
@ -166,11 +165,11 @@ bool CTaskTerraform::EventProcess(const Event &event)
|
|||
pos = glm::vec3(-1.0f, 5.8f, 3.5f);
|
||||
pos.x += (Math::Rand()-0.5f)*1.0f;
|
||||
pos.z += (Math::Rand()-0.5f)*1.0f;
|
||||
pos = Math::Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
speed.x = Math::Rand()*4.0f;
|
||||
speed.z = Math::Rand()*2.0f;
|
||||
speed.y = 2.5f+Math::Rand()*1.0f;
|
||||
speed = Math::Transform(*mat, speed);
|
||||
speed = Math::Transform(mat, speed);
|
||||
speed -= m_object->GetPosition();
|
||||
dim.x = Math::Rand()*1.0f+1.0f;
|
||||
dim.y = dim.x;
|
||||
|
@ -180,11 +179,11 @@ bool CTaskTerraform::EventProcess(const Event &event)
|
|||
pos = glm::vec3(-1.0f, 5.8f, -3.5f);
|
||||
pos.x += (Math::Rand()-0.5f)*1.0f;
|
||||
pos.z += (Math::Rand()-0.5f)*1.0f;
|
||||
pos = Math::Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
speed.x = Math::Rand()*4.0f;
|
||||
speed.z = -Math::Rand()*2.0f;
|
||||
speed.y = 2.5f+Math::Rand()*1.0f;
|
||||
speed = Math::Transform(*mat, speed);
|
||||
speed = Math::Transform(mat, speed);
|
||||
speed -= m_object->GetPosition();
|
||||
dim.x = Math::Rand()*1.0f+1.0f;
|
||||
dim.y = dim.x;
|
||||
|
@ -201,7 +200,6 @@ bool CTaskTerraform::EventProcess(const Event &event)
|
|||
Error CTaskTerraform::Start()
|
||||
{
|
||||
CObject* power;
|
||||
Math::Matrix* mat;
|
||||
glm::vec3 pos, speed;
|
||||
float energy;
|
||||
|
||||
|
@ -222,9 +220,9 @@ Error CTaskTerraform::Start()
|
|||
if ( speed.x != 0.0f ||
|
||||
speed.z != 0.0f ) return ERR_MANIP_MOTOR;
|
||||
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
pos = glm::vec3(9.0f, 0.0f, 0.0f);
|
||||
pos = Math::Transform(*mat, pos); // battery position
|
||||
pos = Math::Transform(mat, pos); // battery position
|
||||
m_terraPos = pos;
|
||||
|
||||
m_phase = TTP_CHARGE;
|
||||
|
|
|
@ -1523,7 +1523,7 @@ bool CPhysics::EventFrame(const Event &event)
|
|||
newangle = angle + event.rTime*m_cirMotion.realSpeed;
|
||||
Math::LoadRotationZXYMatrix(matRotate, newangle);
|
||||
newpos = event.rTime*m_linMotion.realSpeed;
|
||||
newpos = Transform(matRotate, newpos);
|
||||
newpos = Math::Transform(matRotate, newpos);
|
||||
newpos += pos;
|
||||
|
||||
m_terrain->AdjustToStandardBounds(newpos);
|
||||
|
@ -1960,7 +1960,6 @@ void CPhysics::SoundMotorFull(float rTime, ObjectType type)
|
|||
|
||||
void CPhysics::SoundMotorSlow(float rTime, ObjectType type)
|
||||
{
|
||||
Math::Matrix* mat;
|
||||
glm::vec3 pos{ 0, 0, 0 }, speed{ 0, 0, 0 };
|
||||
glm::vec2 dim;
|
||||
SoundType sound;
|
||||
|
@ -2078,9 +2077,9 @@ void CPhysics::SoundMotorSlow(float rTime, ObjectType type)
|
|||
speed.y -= Math::Rand()*3.0f;
|
||||
speed.z += (Math::Rand()-0.5f)*6.0f;
|
||||
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
pos = Transform(*mat, pos);
|
||||
speed = Transform(*mat, speed)-pos;
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
pos = Math::Transform(mat, pos);
|
||||
speed = Math::Transform(mat, speed)-pos;
|
||||
|
||||
dim.x = Math::Rand()*1.0f+1.0f;
|
||||
dim.y = dim.x;
|
||||
|
@ -2126,7 +2125,6 @@ void CPhysics::SoundMotorStop(float rTime, ObjectType type)
|
|||
void CPhysics::SoundReactorFull(float rTime, ObjectType type)
|
||||
{
|
||||
SoundType sound;
|
||||
Math::Matrix* mat;
|
||||
glm::vec3 pos{ 0, 0, 0 }, speed{ 0, 0, 0 };
|
||||
glm::vec2 dim;
|
||||
float freq;
|
||||
|
@ -2194,8 +2192,8 @@ void CPhysics::SoundReactorFull(float rTime, ObjectType type)
|
|||
}
|
||||
pos.x += (Math::Rand()-0.5f)*2.0f;
|
||||
pos.z += (Math::Rand()-0.5f)*2.0f;
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
pos = Transform(*mat, pos);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
pos = Math::Transform(mat, pos);
|
||||
speed.x = (Math::Rand()-0.5f)*5.0f;
|
||||
speed.z = (Math::Rand()-0.5f)*5.0f;
|
||||
speed.y = -(4.0f+Math::Rand()*4.0f);
|
||||
|
@ -2219,8 +2217,8 @@ void CPhysics::SoundReactorFull(float rTime, ObjectType type)
|
|||
}
|
||||
pos.x += (Math::Rand()-0.5f)*1.0f;
|
||||
pos.z += (Math::Rand()-0.5f)*1.0f;
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
pos = Transform(*mat, pos);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
pos = Math::Transform(mat, pos);
|
||||
speed.x = (Math::Rand()-0.5f)*2.0f;
|
||||
speed.z = (Math::Rand()-0.5f)*2.0f;
|
||||
speed.y = -(4.0f+Math::Rand()*4.0f);
|
||||
|
@ -2334,7 +2332,7 @@ void CPhysics::FloorAdapt(float aTime, float rTime,
|
|||
fabs(m_linMotion.realSpeed.y*0.3f);
|
||||
m_linMotion.currentSpeed = norm*force;
|
||||
Math::LoadRotationXZYMatrix(matRotate, -angle);
|
||||
m_linMotion.currentSpeed = Transform(matRotate, m_linMotion.currentSpeed);
|
||||
m_linMotion.currentSpeed = Math::Transform(matRotate, m_linMotion.currentSpeed);
|
||||
|
||||
if ( aTime-m_soundTimeBoum > 0.5f )
|
||||
{
|
||||
|
@ -2618,7 +2616,7 @@ int CPhysics::ObjectAdapt(const glm::vec3 &pos, const glm::vec3 &angle)
|
|||
|
||||
m_linMotion.currentSpeed = glm::normalize(iPos-oPos)*force;
|
||||
Math::LoadRotationXZYMatrix(matRotate, -angle);
|
||||
m_linMotion.currentSpeed = Transform(matRotate, m_linMotion.currentSpeed);
|
||||
m_linMotion.currentSpeed = Math::Transform(matRotate, m_linMotion.currentSpeed);
|
||||
if ( !m_object->Implements(ObjectInterfaceType::Flying) )
|
||||
{
|
||||
m_linMotion.currentSpeed.y = 0.0f;
|
||||
|
@ -2633,7 +2631,7 @@ int CPhysics::ObjectAdapt(const glm::vec3 &pos, const glm::vec3 &angle)
|
|||
oAngle = pObj->GetRotation();
|
||||
oSpeed = glm::normalize(oPos-iPos)*force;
|
||||
Math::LoadRotationXZYMatrix(matRotate, -oAngle);
|
||||
oSpeed = Transform(matRotate, oSpeed);
|
||||
oSpeed = Math::Transform(matRotate, oSpeed);
|
||||
if ( !pObj->Implements(ObjectInterfaceType::Flying) )
|
||||
{
|
||||
oSpeed.y = 0.0f;
|
||||
|
@ -2961,7 +2959,6 @@ void CPhysics::FrameParticle(float aTime, float rTime)
|
|||
|
||||
void CPhysics::PowerParticle(float factor, bool bBreak)
|
||||
{
|
||||
Math::Matrix* mat;
|
||||
glm::vec3 pos{ 0, 0, 0 }, ppos{ 0, 0, 0 }, eye{ 0, 0, 0 }, speed{ 0, 0, 0 };
|
||||
glm::vec2 dim;
|
||||
bool bCarryPower;
|
||||
|
@ -2978,12 +2975,12 @@ void CPhysics::PowerParticle(float factor, bool bBreak)
|
|||
}
|
||||
}
|
||||
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
|
||||
pos = m_object->GetPowerPosition();
|
||||
pos.x -= 0.3f;
|
||||
pos.y += 1.0f; // battery center position
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
|
||||
speed.x = (Math::Rand()-0.5f)*12.0f;
|
||||
speed.y = (Math::Rand()-0.5f)*12.0f;
|
||||
|
@ -3001,7 +2998,7 @@ void CPhysics::PowerParticle(float factor, bool bBreak)
|
|||
if ( bCarryPower ) // carry a battery?
|
||||
{
|
||||
pos = glm::vec3(3.0f, 5.6f, 0.0f); // position of battery holder // TODO: Move to CTransportableObject
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
|
||||
speed.x = (Math::Rand()-0.5f)*12.0f;
|
||||
speed.y = (Math::Rand()-0.5f)*12.0f;
|
||||
|
@ -3056,7 +3053,6 @@ void CPhysics::CrashParticle(float crash)
|
|||
|
||||
void CPhysics::MotorParticle(float aTime, float rTime)
|
||||
{
|
||||
Math::Matrix* mat;
|
||||
glm::vec3 pos{ 0, 0, 0 }, speed{ 0, 0, 0 };
|
||||
glm::vec2 dim;
|
||||
ObjectType type;
|
||||
|
@ -3160,12 +3156,12 @@ void CPhysics::MotorParticle(float aTime, float rTime)
|
|||
{
|
||||
m_lastSlideParticle = aTime;
|
||||
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
pos.x = (Math::Rand()-0.5f)*1.0f;
|
||||
pos.y = -m_object->GetCharacter()->height;
|
||||
pos.z = Math::Rand()*0.4f+1.0f;
|
||||
if ( rand()%2 == 0 ) pos.z = -pos.z;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
speed = glm::vec3(0.0f, 1.0f, 0.0f);
|
||||
dim.x = Math::Rand()*(h-5.0f)/2.0f+1.0f;
|
||||
if ( dim.x > 2.5f ) dim.x = 2.5f;
|
||||
|
@ -3189,12 +3185,12 @@ void CPhysics::MotorParticle(float aTime, float rTime)
|
|||
{
|
||||
m_lastSlideParticle = aTime;
|
||||
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
pos.x = (Math::Rand()-0.5f)*8.0f;
|
||||
pos.y = 0.0f;
|
||||
pos.z = Math::Rand()*2.0f+3.0f;
|
||||
if ( rand()%2 == 0 ) pos.z = -pos.z;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
speed = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
dim.x = Math::Rand()*(h-5.0f)/2.0f+1.0f;
|
||||
if ( dim.x > 3.0f ) dim.x = 3.0f;
|
||||
|
@ -3217,12 +3213,12 @@ void CPhysics::MotorParticle(float aTime, float rTime)
|
|||
{
|
||||
m_lastSlideParticle = aTime;
|
||||
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
pos.x = (Math::Rand()-0.5f)*9.0f;
|
||||
pos.y = 0.0f;
|
||||
pos.z = Math::Rand()*3.0f+3.0f;
|
||||
if ( rand()%2 == 0 ) pos.z = -pos.z;
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
speed = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
dim.x = Math::Rand()*(h-5.0f)/2.0f+1.0f;
|
||||
if ( dim.x > 3.0f ) dim.x = 3.0f;
|
||||
|
@ -3250,8 +3246,8 @@ void CPhysics::MotorParticle(float aTime, float rTime)
|
|||
m_lastMotorParticle = aTime;
|
||||
|
||||
pos = glm::vec3(-1.6f, -0.5f, 0.0f);
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
pos = Transform(*mat, pos);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
pos = Math::Transform(mat, pos);
|
||||
|
||||
speed.x = (Math::Rand()-0.5f)*0.6f;
|
||||
speed.z = (Math::Rand()-0.5f)*0.6f;
|
||||
|
@ -3282,8 +3278,8 @@ void CPhysics::MotorParticle(float aTime, float rTime)
|
|||
pos.x += (Math::Rand()-0.5f)*3.0f;
|
||||
pos.y += (Math::Rand()-0.5f)*1.5f;
|
||||
pos.z += (Math::Rand()-0.5f)*3.0f;
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
pos = Transform(*mat, pos);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
pos = Math::Transform(mat, pos);
|
||||
|
||||
h = m_floorHeight;
|
||||
if ( h > 10.0f ) // high enough?
|
||||
|
@ -3303,7 +3299,7 @@ void CPhysics::MotorParticle(float aTime, float rTime)
|
|||
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTISCRAPS, 2.0f, 10.0f);
|
||||
|
||||
pos = glm::vec3(-1.6f, -0.5f, 0.0f);
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
|
||||
speed.x = (Math::Rand()-0.5f)*1.0f;
|
||||
speed.z = (Math::Rand()-0.5f)*1.0f;
|
||||
|
@ -3362,8 +3358,8 @@ void CPhysics::MotorParticle(float aTime, float rTime)
|
|||
|
||||
pos.x += (Math::Rand()-0.5f)*2.0f;
|
||||
pos.z += (Math::Rand()-0.5f)*2.0f;
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
pos = Transform(*mat, pos);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
pos = Math::Transform(mat, pos);
|
||||
speed = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
dim.x = Math::Rand()*h/5.0f+2.0f;
|
||||
dim.y = dim.x;
|
||||
|
@ -3384,8 +3380,8 @@ void CPhysics::MotorParticle(float aTime, float rTime)
|
|||
|
||||
pos.x += (Math::Rand()-0.5f)*1.0f;
|
||||
pos.z += (Math::Rand()-0.5f)*1.0f;
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
pos = Transform(*mat, pos);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
pos = Math::Transform(mat, pos);
|
||||
speed = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
dim.x = 1.0f;
|
||||
dim.y = dim.x;
|
||||
|
@ -3403,8 +3399,8 @@ void CPhysics::MotorParticle(float aTime, float rTime)
|
|||
pos.x += (Math::Rand()-0.5f)*6.0f;
|
||||
pos.y += (Math::Rand()-0.5f)*3.0f;
|
||||
pos.z += (Math::Rand()-0.5f)*6.0f;
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
pos = Transform(*mat, pos);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
pos = Math::Transform(mat, pos);
|
||||
|
||||
h = m_floorHeight;
|
||||
if ( h > 10.0f ) // high enough?
|
||||
|
@ -3424,7 +3420,7 @@ void CPhysics::MotorParticle(float aTime, float rTime)
|
|||
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTISCRAPS, 2.0f, 10.0f);
|
||||
|
||||
pos = glm::vec3(0.0f, 1.0f, 0.0f);
|
||||
pos = Transform(*mat, pos);
|
||||
pos = Math::Transform(mat, pos);
|
||||
|
||||
speed.x = (Math::Rand()-0.5f)*1.0f;
|
||||
speed.z = (Math::Rand()-0.5f)*1.0f;
|
||||
|
@ -3464,8 +3460,8 @@ void CPhysics::MotorParticle(float aTime, float rTime)
|
|||
m_lastMotorParticle = aTime;
|
||||
|
||||
pos = glm::vec3(0.0f, 3.0f, 0.0f);
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
pos = Transform(*mat, pos);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
pos = Math::Transform(mat, pos);
|
||||
pos.x += (Math::Rand()-0.5f)*1.0f;
|
||||
pos.z += (Math::Rand()-0.5f)*1.0f;
|
||||
speed.y = (Math::Rand()-0.5f)*8.0f+8.0f;
|
||||
|
@ -3490,8 +3486,8 @@ void CPhysics::MotorParticle(float aTime, float rTime)
|
|||
m_lastMotorParticle = aTime;
|
||||
|
||||
pos = glm::vec3(0.0f, 3.0f, 0.0f);
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
pos = Transform(*mat, pos);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
pos = Math::Transform(mat, pos);
|
||||
pos.x += (Math::Rand()-0.5f)*1.0f;
|
||||
pos.z += (Math::Rand()-0.5f)*1.0f;
|
||||
speed.y = (Math::Rand()-0.5f)*8.0f+8.0f;
|
||||
|
@ -3527,8 +3523,8 @@ void CPhysics::MotorParticle(float aTime, float rTime)
|
|||
pos = glm::vec3(-2.5f, 10.3f, -1.3f);
|
||||
pos.x += (Math::Rand()-0.5f)*1.0f;
|
||||
pos.z += (Math::Rand()-0.5f)*1.0f;
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
pos = Transform(*mat, pos);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
pos = Math::Transform(mat, pos);
|
||||
|
||||
speed.x = (Math::Rand()-0.5f)*2.0f;
|
||||
speed.z = (Math::Rand()-0.5f)*2.0f;
|
||||
|
@ -3564,9 +3560,9 @@ void CPhysics::MotorParticle(float aTime, float rTime)
|
|||
speed.y -= 0.5f+Math::Rand()*2.0f;
|
||||
speed.z += (Math::Rand()-0.5f)*3.0f;
|
||||
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
pos = Transform(*mat, pos);
|
||||
speed = Transform(*mat, speed)-pos;
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
pos = Math::Transform(mat, pos);
|
||||
speed = Math::Transform(mat, speed)-pos;
|
||||
|
||||
dim.x = Math::Rand()*0.4f+0.3f;
|
||||
dim.y = dim.x;
|
||||
|
@ -3696,11 +3692,10 @@ void CPhysics::WaterParticle(float aTime, glm::vec3 pos, ObjectType type,
|
|||
|
||||
void CPhysics::WheelParticle(TraceColor color, float width)
|
||||
{
|
||||
Math::Matrix* mat;
|
||||
glm::vec3 goal1{ 0, 0, 0 }, goal2{ 0, 0, 0 }, wheel1{ 0, 0, 0 }, wheel2{ 0, 0, 0 };
|
||||
float dist1, dist2, step;
|
||||
|
||||
mat = m_object->GetWorldMatrix(0);
|
||||
glm::mat4 mat = m_object->GetWorldMatrix(0);
|
||||
|
||||
// Draw a trace on the ground.
|
||||
if ( color != TraceColor::Default )
|
||||
|
@ -3716,12 +3711,12 @@ void CPhysics::WheelParticle(TraceColor color, float width)
|
|||
goal1.x = step/2.0f;
|
||||
goal1.y = 0.0f;
|
||||
goal1.z = -width/2.0f;
|
||||
goal1 = Transform(*mat, goal1);
|
||||
goal1 = Math::Transform(mat, goal1);
|
||||
|
||||
goal2.x = step/2.0f;
|
||||
goal2.y = 0.0f;
|
||||
goal2.z = width/2.0f;
|
||||
goal2 = Transform(*mat, goal2);
|
||||
goal2 = Math::Transform(mat, goal2);
|
||||
|
||||
if ( !m_bWheelParticleBrake )
|
||||
{
|
||||
|
|
|
@ -3742,7 +3742,7 @@ void CScriptFunctions::uObject(CBotVar* botThis, void* user)
|
|||
Math::Matrix matRotate;
|
||||
Math::LoadRotationZXYMatrix(matRotate, object->GetRotation());
|
||||
pos = physics->GetLinMotion(MO_CURSPEED);
|
||||
pos = Transform(matRotate, pos);
|
||||
pos = Math::Transform(matRotate, pos);
|
||||
|
||||
pSub = pVar->GetItemList(); // "x"
|
||||
pSub->SetValFloat(pos.x/g_unit);
|
||||
|
|
|
@ -716,11 +716,11 @@ void CScreenApperance::SetCamera(float x, float y, float cameraDistance)
|
|||
p2D.x = p2D.x * 2.0f - 1.0f; // [0..1] -> [-1..1]
|
||||
p2D.y = p2D.y * 2.0f - 1.0f;
|
||||
|
||||
p3D.x = p2D.x * p2D.z / matProj.Get(1,1);
|
||||
p3D.y = p2D.y * p2D.z / matProj.Get(2,2);
|
||||
p3D.x = p2D.x * p2D.z / matProj[0][0];
|
||||
p3D.y = p2D.y * p2D.z / matProj[1][1];
|
||||
p3D.z = p2D.z;
|
||||
|
||||
p3D = Math::Transform(matView.Inverse(), p3D);
|
||||
p3D = Math::Transform(glm::inverse(matView), p3D);
|
||||
p3D = -p3D;
|
||||
|
||||
camera->SetScriptCamera(glm::vec3(cameraDistance, p3D.y, p3D.x),
|
||||
|
|
|
@ -31,265 +31,3 @@
|
|||
|
||||
|
||||
const float TEST_TOLERANCE = 1e-6f;
|
||||
|
||||
|
||||
TEST(MatrixTest, TransposeTest)
|
||||
{
|
||||
const Math::Matrix mat(
|
||||
{
|
||||
{ -0.07011674491203920f, 1.26145596067429810f, 2.09476603598066902f, 0.35560176915570696f },
|
||||
{ -1.34075615966224704f, 1.17988499016709314f, 0.00601713429241016f, -0.75213676977972566f },
|
||||
{ 0.59186722295223981f, 0.88089224074765293f, 0.70994467464257294f, 0.36730385425340212f },
|
||||
{ -0.95649396555068111f, 0.75912182022565566f, 1.34883305778387186f, -1.34957997578168754f }
|
||||
}
|
||||
);
|
||||
|
||||
const Math::Matrix expectedTranspose(
|
||||
{
|
||||
{ -0.07011674491203920f, -1.34075615966224704f, 0.59186722295223981f, -0.95649396555068111f },
|
||||
{ 1.26145596067429810f, 1.17988499016709314f, 0.88089224074765293f, 0.75912182022565566f },
|
||||
{ 2.09476603598066902f, 0.00601713429241016f, 0.70994467464257294f, 1.34883305778387186f },
|
||||
{ 0.35560176915570696f, -0.75213676977972566f, 0.36730385425340212f, -1.34957997578168754f }
|
||||
}
|
||||
);
|
||||
|
||||
Math::Matrix transpose = Math::Transpose(mat);
|
||||
|
||||
EXPECT_TRUE(Math::MatricesEqual(transpose, expectedTranspose, TEST_TOLERANCE));
|
||||
}
|
||||
|
||||
TEST(MatrixTest, CofactorTest)
|
||||
{
|
||||
const Math::Matrix mat1(
|
||||
{
|
||||
{ 0.610630320796245f, 1.059932357918312f, -1.581674311378210f, 1.782214448453331f },
|
||||
{ 0.191028848211526f, -0.813898708757524f, 1.516114203870644f, 0.395202639476002f },
|
||||
{ 0.335142750345279f, -0.346586619596529f, 0.545382042472336f, -0.879268918923072f },
|
||||
{ 1.417588151657198f, 1.450841789070141f, 0.219080104196171f, 0.378724047481655f }
|
||||
}
|
||||
);
|
||||
|
||||
const Math::Matrix expectedCofactors1(
|
||||
{
|
||||
{ -2.402679369186782f, 2.282452509293019f, 1.722732204057644f, -0.746939701104385f },
|
||||
{ -0.687677756877654f, 1.168949180331164f, -0.985354966837796f, -1.334071111592705f },
|
||||
{ -5.115621958424845f, 4.229724770159009f, 2.529000630782808f, 1.481632618355891f },
|
||||
{ 0.147480897398694f, -2.140677680337111f, -1.207189492265546f, 0.151236920408051f }
|
||||
}
|
||||
);
|
||||
|
||||
for (int r = 0; r < 4; ++r)
|
||||
{
|
||||
for (int c = 0; c < 4; ++c)
|
||||
{
|
||||
float ret = mat1.Cofactor(r, c);
|
||||
float exp = expectedCofactors1.m[4*c+r];
|
||||
EXPECT_TRUE(Math::IsEqual(ret, exp, TEST_TOLERANCE));
|
||||
}
|
||||
}
|
||||
|
||||
const Math::Matrix mat2(
|
||||
{
|
||||
{ 0.9845099464982393f, -0.9091233416532389f, -0.6272243714245945f, 0.4645001858944354f },
|
||||
{ -0.1333308471483736f, 0.9128181433725897f, -1.0937461393836190f, 0.3180936795928376f },
|
||||
{ -0.0654324396846289f, 0.1014641705415945f, 1.5107709042683430f, -0.0240560430414690f },
|
||||
{ 0.0179638644093347f, -1.0695585982782767f, -0.1741250853101032f, 1.0803106709464336f }
|
||||
}
|
||||
);
|
||||
|
||||
const Math::Matrix expectedCofactors2(
|
||||
{
|
||||
{ 2.0861102207614466f, 0.2989010779528912f, 0.0746276150537432f, 0.2732659822656097f },
|
||||
{ 0.6850002886584565f, 1.5513169659641379f, -0.0503743176545917f, 1.5163672441575642f },
|
||||
{ 1.2385556680997216f, 1.1827709562505695f, 1.2282813085138962f, 1.3483789679871401f },
|
||||
{ -1.0710790241539783f, -0.5589604503588883f, 0.0100959837872308f, 1.1897872684455839f }
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
for (int r = 0; r < 4; ++r)
|
||||
{
|
||||
for (int c = 0; c < 4; ++c)
|
||||
{
|
||||
float ret = mat2.Cofactor(r, c);
|
||||
float exp = expectedCofactors2.m[4*c+r];
|
||||
EXPECT_TRUE(Math::IsEqual(ret, exp, TEST_TOLERANCE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(MatrixTest, DetTest)
|
||||
{
|
||||
const Math::Matrix mat1(
|
||||
{
|
||||
{ -0.95880162984708284f, 0.24004047608997131f, -0.78172309932665407f, -0.11604124457222834f },
|
||||
{ -0.36230592086261376f, -0.75778166876017261f, 0.33041059404631740f, -1.06001391941094836f },
|
||||
{ 0.00260215210936187f, 1.27485610196385113f, -0.26149859846418033f, -0.59669701186364876f },
|
||||
{ 0.36899429848485432f, 3.01720896813933104f, 2.10311476609438719f, -1.68627076626448269f }
|
||||
}
|
||||
);
|
||||
|
||||
const float expectedDet1 = 4.07415413729671f;
|
||||
|
||||
float ret1 = mat1.Det();
|
||||
EXPECT_TRUE(Math::IsEqual(ret1, expectedDet1, TEST_TOLERANCE));
|
||||
|
||||
const Math::Matrix mat2(
|
||||
{
|
||||
{ -1.0860073221346871f, 0.9150354098189495f, -0.2723201933559999f, 0.2922832160271507f },
|
||||
{ -1.0248331304801788f, -2.5081237461125205f, -1.0277123574586633f, -0.2254690663329798f },
|
||||
{ -1.4227635282899367f, -0.0403846809122684f, 0.9216148477171653f, 1.2517067488015878f },
|
||||
{ -0.1160254467152022f, 0.8270675274393656f, 1.0327218739781614f, -0.3674886870220400f }
|
||||
}
|
||||
);
|
||||
|
||||
const float expectedDet2 = -6.35122307880942f;
|
||||
|
||||
float ret2 = mat2.Det();
|
||||
EXPECT_TRUE(Math::IsEqual(ret2, expectedDet2, TEST_TOLERANCE));
|
||||
}
|
||||
|
||||
TEST(MatrixTest, InverseTest)
|
||||
{
|
||||
const Math::Matrix mat1(
|
||||
{
|
||||
{ -2.2829352811514658f, -0.9103222363187888f, 0.2792976509411680f, -0.7984393573193174f },
|
||||
{ 2.4823665798689589f, -0.0599056759070980f, 0.3832364352926366f, -1.6404257204372739f },
|
||||
{ -0.3841952272526398f, -0.8377700696457873f, -0.3416328338427138f, 1.1746577275723329f },
|
||||
{ 0.1746031241954947f, -0.4952532117949962f, 0.2155084379835037f, -1.6586460437329220f }
|
||||
}
|
||||
);
|
||||
|
||||
const Math::Matrix expectedInverse1(
|
||||
{
|
||||
{ -0.119472603171041f, 0.331675963276297f, 0.187516809009720f, -0.137720814290806f },
|
||||
{ -0.387591686166085f, -0.487284946727583f, -0.798527541290274f, 0.102991635972060f },
|
||||
{ 2.601905603425902f, 2.606899016264679f, -0.528006148839176f, -4.204703326522837f },
|
||||
{ 0.441220327151392f, 0.519128136207318f, 0.189567009205522f, -1.194469716136194f }
|
||||
}
|
||||
);
|
||||
|
||||
Math::Matrix inverse1 = mat1.Inverse();
|
||||
|
||||
EXPECT_TRUE(Math::MatricesEqual(inverse1, expectedInverse1, TEST_TOLERANCE));
|
||||
|
||||
const Math::Matrix mat2(
|
||||
{
|
||||
{ -0.05464332404298505f, -0.64357755258235749f, -0.13017671677619302f, -0.56742332785888006f },
|
||||
{ 0.29048383600458222f, -0.91517047043724875f, 0.84517524415561684f, 0.51628195547960565f },
|
||||
{ 0.00946488004480186f, -0.89077382212689293f, 0.73565573766341397f, -0.15932513521840930f },
|
||||
{ -1.01244718912499132f, -0.27840911963972276f, -0.39189681211309862f, 1.18315064340192055f }
|
||||
}
|
||||
);
|
||||
|
||||
const Math::Matrix expectedInverse2(
|
||||
{
|
||||
{ 0.771302711132012f, 1.587542278361995f, -2.003075114445104f, -0.592574156227379f },
|
||||
{ -1.208929259769431f, -0.786598967848473f, 0.607335305808052f, -0.154759693303324f },
|
||||
{ -1.500037668208218f, -0.774300278997914f, 1.917800427261255f, -0.123268572651291f },
|
||||
{ -0.121314770937944f, 0.916925149209746f, -0.935924950785014f, 0.260875394250671f }
|
||||
}
|
||||
);
|
||||
|
||||
Math::Matrix inverse2 = mat2.Inverse();
|
||||
|
||||
EXPECT_TRUE(Math::MatricesEqual(inverse2, expectedInverse2, TEST_TOLERANCE));
|
||||
}
|
||||
|
||||
TEST(MatrixTest, MultiplyTest)
|
||||
{
|
||||
const Math::Matrix mat1A(
|
||||
{
|
||||
{ 0.6561727049162027f, -1.4180263627131411f, -0.8271026046117423f, 2.3919331748512578f },
|
||||
{ -0.6035665535146352f, 0.0150827348790615f, -0.7090794192822540f, 0.9057604704594814f },
|
||||
{ -0.9871045001223655f, -0.4980646811455065f, 0.3806177002298990f, 0.1520583649240934f },
|
||||
{ -0.2721911170792712f, 0.7627928194552067f, -0.1504091336784158f, 0.9747545351840121f }
|
||||
}
|
||||
);
|
||||
|
||||
const Math::Matrix mat1B(
|
||||
{
|
||||
{ -0.2643735892448818f, -0.7542994492819621f, 0.6082322350568750f, 0.0581733424861419f },
|
||||
{ 1.0293246070431237f, 0.1979285388251341f, -0.2932031385332818f, 0.8838407179018929f },
|
||||
{ 0.3448687251553114f, 0.5031654871245456f, 0.7554693012922442f, -0.4845315903845708f },
|
||||
{ -1.8662838497278593f, -0.7843850624747805f, 0.1389026096476257f, -1.3686415408300689f }
|
||||
}
|
||||
);
|
||||
|
||||
const Math::Matrix expectedMultiply1(
|
||||
{
|
||||
{ -6.382352236417988f, -3.067984733682130f, 0.522270304251466f, -4.088079444498280f },
|
||||
{ -1.759853366848825f, -0.608994052024491f, -0.781406179437379f, -0.917870775786188f },
|
||||
{ -0.404226802169062f, 0.718232546720114f, -0.145688356880835f, -0.890167707987175f },
|
||||
{ -1.013918490922430f, -0.483971504099758f, -0.367442194643757f, -0.602858486133615f }
|
||||
}
|
||||
);
|
||||
|
||||
Math::Matrix multiply1 = Math::MultiplyMatrices(mat1A, mat1B);
|
||||
EXPECT_TRUE(Math::MatricesEqual(multiply1, expectedMultiply1, TEST_TOLERANCE));
|
||||
|
||||
const Math::Matrix mat2A(
|
||||
{
|
||||
{ 0.8697203025776754f, 2.1259475710644935f, 1.7856691009707812f, -2.1563963348328126f },
|
||||
{ 1.5888074489288735f, -0.0794849733953615f, 0.7307782768677457f, 0.7943129159612630f },
|
||||
{ 0.2859761537233830f, -0.6231231890384962f, -0.0496743172880377f, -0.8137857518646087f },
|
||||
{ 1.2670547229512983f, -0.5305171374831831f, -0.4987412674062375f, -1.1257327113869595f }
|
||||
}
|
||||
);
|
||||
|
||||
const Math::Matrix mat2B(
|
||||
{
|
||||
{ 1.1321105701165317f, 0.1759563504574463f, -2.0675778912000418f, 1.4840339814245538f },
|
||||
{ -1.5117280888829916f, -0.0933013188828093f, -0.2079262944351640f, 0.9575727579539316f },
|
||||
{ 0.3615378398970173f, 1.2465163589027248f, 1.1326150997082589f, 0.9921208694352303f },
|
||||
{ -0.7357104529373861f, -0.4774022005969588f, -0.2118739096676499f, 1.1427567093270703f }
|
||||
}
|
||||
);
|
||||
|
||||
const Math::Matrix expectedMultiply2(
|
||||
{
|
||||
{ 0.00283516267056338f, 3.21001319965989307f, 0.23910503934370686f, 2.63380716363006107f },
|
||||
{ 1.59868505822469742f, 0.81869715594617765f, -2.60905981088293570f, 3.91445839239110294f },
|
||||
{ 1.84650099286297942f, 0.43504079532852930f, -0.34555619012424243f, -1.15152951542451487f },
|
||||
{ 2.88434318563174585f, 0.18818239851585700f, -2.83579436909308980f, -0.40890672198610400f }
|
||||
}
|
||||
);
|
||||
|
||||
Math::Matrix multiply2 = Math::MultiplyMatrices(mat2A, mat2B);
|
||||
EXPECT_TRUE(Math::MatricesEqual(multiply2, expectedMultiply2, TEST_TOLERANCE));
|
||||
}
|
||||
|
||||
TEST(MatrixTest, MultiplyVectorTest)
|
||||
{
|
||||
const Math::Matrix mat1(
|
||||
{
|
||||
{ 0.188562846910008f, -0.015148651460679f, 0.394512304108827f, 0.906910631257135f },
|
||||
{ -0.297506779519667f, 0.940119328178913f, 0.970957796752517f, 0.310559318965526f },
|
||||
{ -0.819770525290873f, -2.316574438778879f, 0.155756069319732f, -0.855661405742964f },
|
||||
{ 0.000000000000000f, 0.000000000000000f, 0.000000000000000f, 1.000000000000000f }
|
||||
}
|
||||
);
|
||||
|
||||
const glm::vec3 vec1(-0.824708565156661f, -1.598287748103842f, -0.422498044734181f);
|
||||
|
||||
const glm::vec3 expectedMultiply1(0.608932463260470f, -1.356893266403749f, 3.457156276255142f);
|
||||
|
||||
glm::vec3 multiply1 = Math::MatrixVectorMultiply(mat1, vec1, false);
|
||||
EXPECT_TRUE(glm::all(glm::epsilonEqual(multiply1, expectedMultiply1, TEST_TOLERANCE)));
|
||||
|
||||
const Math::Matrix mat2(
|
||||
{
|
||||
{ -0.63287117038834284f, 0.55148060401816856f, -0.02042395559467368f, -1.50367083897656850f },
|
||||
{ 0.69629042156335297f, 0.12982747869796774f, -1.16250029235919405f, 1.19084447253756909f },
|
||||
{ 0.44164132914357224f, -0.15169304045662041f, -0.00880583574621390f, -0.55817802940035310f },
|
||||
{ 0.95680476533530789f, -1.51912346889253125f, -0.74209769406615944f, -0.20938988867903682f }
|
||||
}
|
||||
);
|
||||
|
||||
const glm::vec3 vec2(0.330987381051962f, 1.494375516393466f, 1.483422335561857f);
|
||||
|
||||
const glm::vec3 expectedMultiply2(0.2816820577317669f, 0.0334468811767428f, 0.1996974284970455f);
|
||||
|
||||
glm::vec3 multiply2 = Math::MatrixVectorMultiply(mat2, vec2, true);
|
||||
EXPECT_TRUE(glm::all(glm::epsilonEqual(multiply2, expectedMultiply2, TEST_TOLERANCE)));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue