Changed Math::Vector into alias to glm::vec3

dev
Tomasz Kapuściński 2021-12-28 23:01:30 +01:00
parent 70151279f6
commit d25d6124a9
40 changed files with 539 additions and 748 deletions

View File

@ -197,8 +197,8 @@ void CInput::EventProcess(Event& event)
} }
} }
event.motionInput = Math::Clamp(m_joyMotion + m_keyMotion, Math::Vector(-1.0f, -1.0f, -1.0f), Math::Vector(1.0f, 1.0f, 1.0f)); event.motionInput = Math::Clamp(m_joyMotion + m_keyMotion, glm::vec3(-1.0f, -1.0f, -1.0f), glm::vec3(1.0f, 1.0f, 1.0f));
event.cameraInput = Math::Clamp(m_joyMotionCam + m_cameraKeyMotion, Math::Vector(-1.0f, -1.0f, -1.0f), Math::Vector(1.0f, 1.0f, 1.0f)); event.cameraInput = Math::Clamp(m_joyMotionCam + m_cameraKeyMotion, glm::vec3(-1.0f, -1.0f, -1.0f), glm::vec3(1.0f, 1.0f, 1.0f));
} }
void CInput::MouseMove(const glm::ivec2& pos) void CInput::MouseMove(const glm::ivec2& pos)
@ -219,10 +219,10 @@ bool CInput::GetMouseButtonState(int index) const
void CInput::ResetKeyStates() void CInput::ResetKeyStates()
{ {
GetLogger()->Trace("Reset key states\n"); GetLogger()->Trace("Reset key states\n");
m_keyMotion = Math::Vector(0.0f, 0.0f, 0.0f); m_keyMotion = glm::vec3(0.0f, 0.0f, 0.0f);
m_joyMotion = Math::Vector(0.0f, 0.0f, 0.0f); m_joyMotion = glm::vec3(0.0f, 0.0f, 0.0f);
m_cameraKeyMotion = Math::Vector(0.0f, 0.0f, 0.0f); m_cameraKeyMotion = glm::vec3(0.0f, 0.0f, 0.0f);
m_joyMotionCam = Math::Vector(0.0f, 0.0f, 0.0f); m_joyMotionCam = glm::vec3(0.0f, 0.0f, 0.0f);
for(int i=0; i<INPUT_SLOT_MAX; i++) for(int i=0; i<INPUT_SLOT_MAX; i++)
m_keyPresses[i] = false; m_keyPresses[i] = false;
} }

View File

@ -145,14 +145,14 @@ private:
//! Motion vector set by keyboard or joystick buttons //! Motion vector set by keyboard or joystick buttons
Math::Vector m_keyMotion; glm::vec3 m_keyMotion{ 0, 0, 0 };
//! Motion vector set by joystick axes //! Motion vector set by joystick axes
Math::Vector m_joyMotion; glm::vec3 m_joyMotion{ 0, 0, 0 };
//! Camera motion vector set by joystick axes //! Camera motion vector set by joystick axes
Math::Vector m_joyMotionCam; glm::vec3 m_joyMotionCam{ 0, 0, 0 };
//! Camera controls on the numpad //! Camera controls on the numpad
Math::Vector m_cameraKeyMotion; glm::vec3 m_cameraKeyMotion{ 0, 0, 0 };
//! Bindings for user inputs //! Bindings for user inputs
InputBinding m_inputBindings[INPUT_SLOT_MAX]; InputBinding m_inputBindings[INPUT_SLOT_MAX];

View File

@ -867,11 +867,11 @@ struct Event
//! Motion vector set by keyboard or joystick (managed by CInput) //! Motion vector set by keyboard or joystick (managed by CInput)
//! Scope: all system events //! Scope: all system events
Math::Vector motionInput; glm::vec3 motionInput{ 0, 0, 0 };
//! Motion vector set by numeric keyboard (managed by CInput) //! Motion vector set by numeric keyboard (managed by CInput)
//! Scope: all system events //! Scope: all system events
Math::Vector cameraInput; glm::vec3 cameraInput{ 0, 0, 0 };
//! Current state of keyboard modifier keys: bitmask made of KEY_MOD(...) macro values (from common/key.h) //! Current state of keyboard modifier keys: bitmask made of KEY_MOD(...) macro values (from common/key.h)
//! Scope: all system events //! Scope: all system events

View File

@ -41,7 +41,6 @@ struct ImageData;
namespace Math namespace Math
{ {
struct Matrix; struct Matrix;
struct Vector;
} // namespace Math } // namespace Math
@ -524,7 +523,7 @@ public:
//! Tests whether a sphere is (partially) within the frustum volume //! Tests whether a sphere is (partially) within the frustum volume
//! Returns a mask of frustum planes for which the test is positive //! Returns a mask of frustum planes for which the test is positive
virtual int ComputeSphereVisibility(const Math::Vector &center, float radius) = 0; virtual int ComputeSphereVisibility(const glm::vec3& center, float radius) = 0;
//! Changes rendering viewport //! Changes rendering viewport
virtual void SetViewport(int x, int y, int width, int height) = 0; virtual void SetViewport(int x, int y, int width, int height) = 0;

View File

@ -62,9 +62,9 @@ struct Light
//! Color of specular light //! Color of specular light
Color specular = Color(1.0f, 1.0f, 1.0f); Color specular = Color(1.0f, 1.0f, 1.0f);
//! Position in world space (for point & spot lights) //! Position in world space (for point & spot lights)
Math::Vector position = Math::Vector(0.0f, 0.0f, 0.0f); glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f);
//! Direction in world space (for directional & spot lights) //! Direction in world space (for directional & spot lights)
Math::Vector direction = Math::Vector(0.0f, 0.0f, 1.0f); glm::vec3 direction = glm::vec3(0.0f, 0.0f, 1.0f);
//! Constant attenuation factor //! Constant attenuation factor
float attenuation0 = 1.0f; float attenuation0 = 1.0f;
//! Linear attenuation factor //! Linear attenuation factor

View File

@ -53,16 +53,16 @@ enum VertexType
* This structure was created as analog to DirectX's D3DVERTEX. * This structure was created as analog to DirectX's D3DVERTEX.
* *
* It contains: * It contains:
* - vertex coordinates (x,y,z) as Math::Vector, * - vertex coordinates (x,y,z) as glm::vec3,
* - normal coordinates (nx,ny,nz) as Math::Vector * - normal coordinates (nx,ny,nz) as glm::vec3
* - texture coordinates (u,v) as glm::vec2. * - texture coordinates (u,v) as glm::vec2.
*/ */
struct Vertex struct Vertex
{ {
static constexpr VertexType VERTEX_TYPE = VERTEX_TYPE_NORMAL; static constexpr VertexType VERTEX_TYPE = VERTEX_TYPE_NORMAL;
Math::Vector coord = Math::Vector(); glm::vec3 coord = { 0, 0, 0 };
Math::Vector normal = Math::Vector(); glm::vec3 normal = { 0, 0, 0 };
glm::vec2 texCoord = { 0, 0 }; glm::vec2 texCoord = { 0, 0 };
}; };
@ -71,14 +71,14 @@ struct Vertex
* \brief Colored vertex * \brief Colored vertex
* *
* It contains: * It contains:
* - vertex coordinates (x,y,z) as Math::Vector, * - vertex coordinates (x,y,z) as glm::vec3,
* - RGBA color as Color * - RGBA color as Color
*/ */
struct VertexCol struct VertexCol
{ {
static constexpr VertexType VERTEX_TYPE = VERTEX_TYPE_COL; static constexpr VertexType VERTEX_TYPE = VERTEX_TYPE_COL;
Math::Vector coord = Math::Vector(); glm::vec3 coord = { 0, 0, 0 };
Color color = Color(); Color color = Color();
}; };
@ -93,8 +93,8 @@ struct VertexTex2
{ {
static constexpr VertexType VERTEX_TYPE = VERTEX_TYPE_TEX2; static constexpr VertexType VERTEX_TYPE = VERTEX_TYPE_TEX2;
Math::Vector coord = Math::Vector(); glm::vec3 coord = { 0, 0, 0 };
Math::Vector normal = Math::Vector(); glm::vec3 normal = { 0, 0, 0 };
glm::vec2 texCoord = { 0, 0 }; glm::vec2 texCoord = { 0, 0 };
glm::vec2 texCoord2 = { 0, 0 }; glm::vec2 texCoord2 = { 0, 0 };

View File

@ -823,12 +823,12 @@ void CCamera::IsCollisionBack()
else else
iType = m_cameraObj->GetType(); iType = m_cameraObj->GetType();
Math::Vector min; Math::Vector min{};
min.x = Math::Min(m_actualEye.x, m_actualLookat.x); min.x = Math::Min(m_actualEye.x, m_actualLookat.x);
min.y = Math::Min(m_actualEye.y, m_actualLookat.y); min.y = Math::Min(m_actualEye.y, m_actualLookat.y);
min.z = Math::Min(m_actualEye.z, m_actualLookat.z); min.z = Math::Min(m_actualEye.z, m_actualLookat.z);
Math::Vector max; Math::Vector max{};
max.x = Math::Max(m_actualEye.x, m_actualLookat.x); max.x = Math::Max(m_actualEye.x, m_actualLookat.x);
max.y = Math::Max(m_actualEye.y, m_actualLookat.y); max.y = Math::Max(m_actualEye.y, m_actualLookat.y);
max.z = Math::Max(m_actualEye.z, m_actualLookat.z); max.z = Math::Max(m_actualEye.z, m_actualLookat.z);
@ -880,7 +880,7 @@ void CCamera::IsCollisionBack()
oPos.y-oRadius > max.y || oPos.y-oRadius > max.y ||
oPos.z-oRadius > max.z ) continue; oPos.z-oRadius > max.z ) continue;
Math::Vector proj = Projection(m_actualEye, m_actualLookat, oPos); Math::Vector proj = Math::Projection(m_actualEye, m_actualLookat, oPos);
float dpp = Math::Distance(proj, oPos); float dpp = Math::Distance(proj, oPos);
if ( dpp > oRadius ) continue; if ( dpp > oRadius ) continue;
@ -935,7 +935,7 @@ void CCamera::IsCollisionFix(Math::Vector &eye, Math::Vector lookat)
if (dist < objRadius) if (dist < objRadius)
{ {
dist = Math::Distance(eye, lookat); dist = Math::Distance(eye, lookat);
Math::Vector proj = Projection(eye, lookat, objPos); Math::Vector proj = Math::Projection(eye, lookat, objPos);
eye = (lookat - eye) * objRadius / dist + proj; eye = (lookat - eye) * objRadius / dist + proj;
return; return;
} }
@ -1230,7 +1230,7 @@ bool CCamera::EventFrameBack(const Event &event)
m_centeringCurrentH = m_centeringAngleH * centeringH; m_centeringCurrentH = m_centeringAngleH * centeringH;
m_centeringCurrentV = m_centeringAngleV * centeringV; m_centeringCurrentV = m_centeringAngleV * centeringV;
m_eyePt = RotateView(lookatPt, h, v, d); m_eyePt = Math::RotateView(lookatPt, h, v, d);
bool ground = true; bool ground = true;
if (m_cameraObj->Implements(ObjectInterfaceType::Movable)) if (m_cameraObj->Implements(ObjectInterfaceType::Movable))
@ -1275,7 +1275,7 @@ bool CCamera::EventFrameFix(const Event &event)
float v = m_fixDirectionV; float v = m_fixDirectionV;
float d = m_fixDist; float d = m_fixDist;
m_eyePt = RotateView(lookatPt, h, v, d); m_eyePt = Math::RotateView(lookatPt, h, v, d);
if (m_type == CAM_TYPE_PLANE) m_eyePt.y += m_fixDist / 2.0f; if (m_type == CAM_TYPE_PLANE) m_eyePt.y += m_fixDist / 2.0f;
m_eyePt = ExcludeTerrain(m_eyePt, lookatPt, h, v); m_eyePt = ExcludeTerrain(m_eyePt, lookatPt, h, v);
m_eyePt = ExcludeObject(m_eyePt, lookatPt, h, v); m_eyePt = ExcludeObject(m_eyePt, lookatPt, h, v);
@ -1354,7 +1354,7 @@ bool CCamera::EventFrameVisit(const Event &event)
float angleH = (m_visitTime / 10.0f) * (Math::PI * 2.0f); float angleH = (m_visitTime / 10.0f) * (Math::PI * 2.0f);
float angleV = m_visitDirectionV; float angleV = m_visitDirectionV;
Math::Vector eye = RotateView(m_visitGoal, angleH, angleV, m_visitDist); Math::Vector eye = Math::RotateView(m_visitGoal, angleH, angleV, m_visitDist);
eye = ExcludeTerrain(eye, m_visitGoal, angleH, angleV); eye = ExcludeTerrain(eye, m_visitGoal, angleH, angleV);
eye = ExcludeObject(eye, m_visitGoal, angleH, angleV); eye = ExcludeObject(eye, m_visitGoal, angleH, angleV);
UpdateCameraAnimation(eye, m_visitGoal, event.rTime); UpdateCameraAnimation(eye, m_visitGoal, event.rTime);
@ -1414,7 +1414,7 @@ Math::Vector CCamera::ExcludeTerrain(Math::Vector eye, Math::Vector lookat,
if ( pos.y > eye.y ) if ( pos.y > eye.y )
{ {
angleV = -Math::RotateAngle(dist, pos.y-lookat.y); angleV = -Math::RotateAngle(dist, pos.y-lookat.y);
eye = RotateView(lookat, angleH, angleV, dist); eye = Math::RotateView(lookat, angleH, angleV, dist);
} }
} }
return eye; return eye;
@ -1454,7 +1454,7 @@ void CCamera::SetCameraSpeed(float speed)
Math::Vector CCamera::CalculateCameraMovement(const Event &event, bool keysAllowed) Math::Vector CCamera::CalculateCameraMovement(const Event &event, bool keysAllowed)
{ {
Math::Vector delta; Math::Vector delta{};
delta.x += m_mouseDelta.x * 2*Math::PI; delta.x += m_mouseDelta.x * 2*Math::PI;
delta.y -= m_mouseDelta.y * Math::PI; delta.y -= m_mouseDelta.y * Math::PI;
@ -1478,7 +1478,7 @@ Math::Vector CCamera::CalculateCameraMovement(const Event &event, bool keysAllow
} }
} }
if (delta.Length() > 0) if (glm::length(delta) > 0)
AbortCentering(); // special stops framing AbortCentering(); // special stops framing
return delta; return delta;

View File

@ -140,7 +140,7 @@ public:
* \param lookat Initial lookat position * \param lookat Initial lookat position
* \param delay Time of the initial entry animation * \param delay Time of the initial entry animation
*/ */
void Init(Math::Vector eye, Math::Vector lookat, float delay); void Init(glm::vec3 eye, glm::vec3 lookat, float delay);
//! Sets the object controlling the camera //! Sets the object controlling the camera
void SetControllingObject(CObject* object); void SetControllingObject(CObject* object);
@ -159,12 +159,12 @@ public:
//! Returns the current point of view of the camera //! Returns the current point of view of the camera
void GetCamera(Math::Vector &eye, Math::Vector &lookat); void GetCamera(glm::vec3 &eye, glm::vec3 &lookat);
//! \name Visit camera management (CAM_TYPE_VISIT) - camera in this mode shows a position, constantly rotating around it //! \name Visit camera management (CAM_TYPE_VISIT) - camera in this mode shows a position, constantly rotating around it
//@{ //@{
//! Start visit camera //! Start visit camera
void StartVisit(Math::Vector goal, float dist); void StartVisit(glm::vec3 goal, float dist);
//! Stop visit camera //! Stop visit camera
void StopVisit(); void StopVisit();
//@} //@}
@ -182,7 +182,7 @@ public:
//! \name Camera shake effects //! \name Camera shake effects
//@{ //@{
//! Starts a camera shake effect //! Starts a camera shake effect
void StartEffect(CameraEffect effect, Math::Vector pos, float force); void StartEffect(CameraEffect effect, glm::vec3 pos, float force);
//! Removes the camera shake effect //! Removes the camera shake effect
void FlushEffect(); void FlushEffect();
//@} //@}
@ -190,7 +190,7 @@ public:
//! \name Camera overlay effects //! \name Camera overlay effects
//@{ //@{
//! Starts camera overlay effect //! Starts camera overlay effect
void StartOver(CameraOverEffect effect, Math::Vector pos, float force); void StartOver(CameraOverEffect effect, glm::vec3 pos, float force);
//! Removes camera overlay effect //! Removes camera overlay effect
void FlushOver(); void FlushOver();
//! Specifies camera overlay effect base color //! Specifies camera overlay effect base color
@ -200,13 +200,13 @@ public:
//! \name Script camera - cutscenes controlled by external code //! \name Script camera - cutscenes controlled by external code
//@{ //@{
//! Script camera: Set camera position //! Script camera: Set camera position
void SetScriptCamera(Math::Vector eye, Math::Vector lookat); void SetScriptCamera(glm::vec3 eye, glm::vec3 lookat);
//! Script camera: Animate to given camera position //! Script camera: Animate to given camera position
void SetScriptCameraAnimate(Math::Vector eye, Math::Vector lookat); void SetScriptCameraAnimate(glm::vec3 eye, glm::vec3 lookat);
//! Script camera: Animate to given eye position //! Script camera: Animate to given eye position
void SetScriptCameraAnimateEye(Math::Vector eye); void SetScriptCameraAnimateEye(glm::vec3 eye);
//! Script camera: Animate to given lookat position //! Script camera: Animate to given lookat position
void SetScriptCameraAnimateLookat(Math::Vector lookat); void SetScriptCameraAnimateLookat(glm::vec3 lookat);
//@} //@}
//! \name Configuration settings //! \name Configuration settings
@ -250,7 +250,7 @@ protected:
* \param rTime Time since last time this function was called (used to calculate animation) * \param rTime Time since last time this function was called (used to calculate animation)
* \see SetViewParams * \see SetViewParams
*/ */
void UpdateCameraAnimation(const Math::Vector &eyePt, const Math::Vector &lookatPt, float rTime); void UpdateCameraAnimation(const glm::vec3 &eyePt, const glm::vec3 &lookatPt, float rTime);
/** /**
* \brief Avoid the obstacles * \brief Avoid the obstacles
@ -261,16 +261,16 @@ protected:
* \param eye Eye position, may be adjusted * \param eye Eye position, may be adjusted
* \param lookat Lookat point * \param lookat Lookat point
*/ */
void IsCollision(Math::Vector &eye, Math::Vector lookat); void IsCollision(glm::vec3 &eye, glm::vec3 lookat);
//! Avoid the obstacles (CAM_TYPE_BACK) //! Avoid the obstacles (CAM_TYPE_BACK)
void IsCollisionBack(); void IsCollisionBack();
//! Avoid the obstacles (CAM_TYPE_FIX or CAM_TYPE_PLANE) //! Avoid the obstacles (CAM_TYPE_FIX or CAM_TYPE_PLANE)
void IsCollisionFix(Math::Vector &eye, Math::Vector lookat); void IsCollisionFix(glm::vec3 &eye, glm::vec3 lookat);
//! Adjusts the camera not to enter the ground //! Adjusts the camera not to enter the ground
Math::Vector ExcludeTerrain(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV); glm::vec3 ExcludeTerrain(glm::vec3 eye, glm::vec3 lookat, float &angleH, float &angleV);
//! Adjusts the camera not to enter an object //! Adjusts the camera not to enter an object
Math::Vector ExcludeObject(Math::Vector eye, Math::Vector lookat, float &angleH, float &angleV); glm::vec3 ExcludeObject(glm::vec3 eye, glm::vec3 lookat, float &angleH, float &angleV);
/** /**
* \brief Updates the location and direction of the camera in the 3D engine * \brief Updates the location and direction of the camera in the 3D engine
@ -279,14 +279,14 @@ protected:
* \param up Up vector * \param up Up vector
* \see CEngine::SetViewParams * \see CEngine::SetViewParams
*/ */
void SetViewParams(const Math::Vector &eye, const Math::Vector &lookat, const Math::Vector &up = Math::Vector(0.0f, 1.0f, 0.0f)); void SetViewParams(const glm::vec3 &eye, const glm::vec3 &lookat, const glm::vec3 &up = glm::vec3(0.0f, 1.0f, 0.0f));
/** /**
* \brief Calculate camera movement (from user inputs) to apply * \brief Calculate camera movement (from user inputs) to apply
* \return Math::Vector where x, y represent respectively horizontal and vertical angle change in radians and z represents zoom (distance change) * \return glm::vec3 where x, y represent respectively horizontal and vertical angle change in radians and z represents zoom (distance change)
* \remarks Should not be called more often than once every EVENT_FRAME * \remarks Should not be called more often than once every EVENT_FRAME
**/ **/
Math::Vector CalculateCameraMovement(const Event &event, bool keysAllowed = true); glm::vec3 CalculateCameraMovement(const Event &event, bool keysAllowed = true);
protected: protected:
CEngine* m_engine; CEngine* m_engine;
@ -306,22 +306,22 @@ protected:
float m_initDelay; float m_initDelay;
//! Current eye //! Current eye
Math::Vector m_actualEye; glm::vec3 m_actualEye{ 0, 0, 0 };
//! Current aim //! Current aim
Math::Vector m_actualLookat; glm::vec3 m_actualLookat{ 0, 0, 0 };
//! Final eye //! Final eye
Math::Vector m_finalEye; glm::vec3 m_finalEye{ 0, 0, 0 };
//! Final lookat //! Final lookat
Math::Vector m_finalLookat; glm::vec3 m_finalLookat{ 0, 0, 0 };
//! Eye position at the moment of entering CAM_TYPE_INFO/CAM_TYPE_VISIT //! Eye position at the moment of entering CAM_TYPE_INFO/CAM_TYPE_VISIT
Math::Vector m_prevEye; glm::vec3 m_prevEye{ 0, 0, 0 };
//! Lookat position at the moment of entering CAM_TYPE_INFO/CAM_TYPE_VISIT //! Lookat position at the moment of entering CAM_TYPE_INFO/CAM_TYPE_VISIT
Math::Vector m_prevLookat; glm::vec3 m_prevLookat{ 0, 0, 0 };
float m_focus; float m_focus;
//! CAM_TYPE_FREE: eye //! CAM_TYPE_FREE: eye
Math::Vector m_eyePt; glm::vec3 m_eyePt{ 0, 0, 0 };
//! CAM_TYPE_FREE: horizontal direction //! CAM_TYPE_FREE: horizontal direction
float m_directionH; float m_directionH;
//! CAM_TYPE_FREE: vertical direction //! CAM_TYPE_FREE: vertical direction
@ -350,7 +350,7 @@ protected:
float m_fixDirectionV; float m_fixDirectionV;
//! CAM_TYPE_VISIT: target position //! CAM_TYPE_VISIT: target position
Math::Vector m_visitGoal; glm::vec3 m_visitGoal{ 0, 0, 0 };
//! CAM_TYPE_VISIT: distance //! CAM_TYPE_VISIT: distance
float m_visitDist; float m_visitDist;
//! CAM_TYPE_VISIT: relative time //! CAM_TYPE_VISIT: relative time
@ -379,10 +379,10 @@ protected:
float m_centeringProgress; float m_centeringProgress;
CameraEffect m_effectType; CameraEffect m_effectType;
Math::Vector m_effectPos; glm::vec3 m_effectPos{ 0, 0, 0 };
float m_effectForce; float m_effectForce;
float m_effectProgress; float m_effectProgress;
Math::Vector m_effectOffset; glm::vec3 m_effectOffset{ 0, 0, 0 };
CameraOverEffect m_overType; CameraOverEffect m_overType;
float m_overForce; float m_overForce;
@ -393,8 +393,8 @@ protected:
float m_overFadeIn; float m_overFadeIn;
float m_overFadeOut; float m_overFadeOut;
Math::Vector m_scriptEye; glm::vec3 m_scriptEye{ 0, 0, 0 };
Math::Vector m_scriptLookat; glm::vec3 m_scriptLookat{ 0, 0, 0 };
//! Is camera frozen? //! Is camera frozen?
bool m_freeze = false; bool m_freeze = false;

View File

@ -76,7 +76,7 @@ bool CCloud::EventFrame(const Event &event)
return true; return true;
} }
void CCloud::AdjustLevel(Math::Vector& pos, Math::Vector& eye, float deep, void CCloud::AdjustLevel(glm::vec3& pos, glm::vec3& eye, float deep,
glm::vec2& uv1, glm::vec2& uv2) glm::vec2& uv1, glm::vec2& uv2)
{ {
uv1.x = (pos.x+20000.0f)/1280.0f; uv1.x = (pos.x+20000.0f)/1280.0f;
@ -132,20 +132,20 @@ void CCloud::Draw()
device->SetTransform(TRANSFORM_WORLD, matrix); device->SetTransform(TRANSFORM_WORLD, matrix);
float size = m_brickSize/2.0f; float size = m_brickSize/2.0f;
Math::Vector eye = m_engine->GetEyePt(); glm::vec3 eye = m_engine->GetEyePt();
Math::Vector n = Math::Vector(0.0f, -1.0f, 0.0f); glm::vec3 n = glm::vec3(0.0f, -1.0f, 0.0f);
// Draws all the lines // Draws all the lines
for (int i = 0; i < static_cast<int>( m_lines.size() ); i++) for (int i = 0; i < static_cast<int>( m_lines.size() ); i++)
{ {
Math::Vector pos; glm::vec3 pos{};
pos.y = m_level; pos.y = m_level;
pos.z = m_lines[i].pz; pos.z = m_lines[i].pz;
pos.x = m_lines[i].px1; pos.x = m_lines[i].px1;
int vertexIndex = 0; int vertexIndex = 0;
Math::Vector p; glm::vec3 p{};
glm::vec2 uv1, uv2; glm::vec2 uv1, uv2;
p.x = pos.x-size; p.x = pos.x-size;

View File

@ -81,7 +81,7 @@ protected:
//! Makes the clouds evolve //! Makes the clouds evolve
bool EventFrame(const Event &event); bool EventFrame(const Event &event);
//! Adjusts the position to normal, to imitate the clouds at movement //! Adjusts the position to normal, to imitate the clouds at movement
void AdjustLevel(Math::Vector& pos, Math::Vector& eye, float deep, void AdjustLevel(glm::vec3& pos, glm::vec3& eye, float deep,
glm::vec2& uv1, glm::vec2& uv2); glm::vec2& uv1, glm::vec2& uv2);
//! Updates the positions, relative to the ground //! Updates the positions, relative to the ground
void CreateLine(int x, int y, int len); void CreateLine(int x, int y, int len);
@ -106,7 +106,7 @@ protected:
int m_subdiv = 8; int m_subdiv = 8;
//! Wind speed //! Wind speed
Math::Vector m_wind; glm::vec3 m_wind{ 0, 0, 0 };
//! Brick mosaic //! Brick mosaic
int m_brickCount = 0; int m_brickCount = 0;
//! Size of a brick element //! Size of a brick element

View File

@ -185,8 +185,8 @@ CEngine::CEngine(CApplication *app, CSystemUtils* systemUtils)
m_highlight = false; m_highlight = false;
std::fill_n(m_highlightRank, 100, -1); std::fill_n(m_highlightRank, 100, -1);
m_highlightTime = 0.0f; m_highlightTime = 0.0f;
m_eyePt = Math::Vector(0.0f, 0.0f, 0.0f); m_eyePt = glm::vec3(0.0f, 0.0f, 0.0f);
m_lookatPt = Math::Vector(0.0f, 0.0f, 1.0f); m_lookatPt = glm::vec3(0.0f, 0.0f, 1.0f);
m_drawWorld = true; m_drawWorld = true;
m_drawFront = false; m_drawFront = false;
m_particleDensity = 1.0f; m_particleDensity = 1.0f;
@ -233,8 +233,8 @@ CEngine::CEngine(CApplication *app, CSystemUtils* systemUtils)
// Compute bias matrix for shadow mapping // Compute bias matrix for shadow mapping
Math::Matrix temp1, temp2; Math::Matrix temp1, temp2;
Math::LoadScaleMatrix(temp1, Math::Vector(0.5f, 0.5f, 0.5f)); Math::LoadScaleMatrix(temp1, glm::vec3(0.5f, 0.5f, 0.5f));
Math::LoadTranslationMatrix(temp2, Math::Vector(1.0f, 1.0f, 1.0f)); Math::LoadTranslationMatrix(temp2, glm::vec3(1.0f, 1.0f, 1.0f));
m_shadowBias = Math::MultiplyMatrices(temp1, temp2); m_shadowBias = Math::MultiplyMatrices(temp1, temp2);
m_lastState = -1; m_lastState = -1;
@ -604,7 +604,7 @@ int CEngine::GetStatisticTriangle()
return m_statisticTriangle; return m_statisticTriangle;
} }
void CEngine::SetStatisticPos(Math::Vector pos) void CEngine::SetStatisticPos(glm::vec3 pos)
{ {
m_statisticPos = pos; m_statisticPos = pos;
} }
@ -853,9 +853,9 @@ void CEngine::DebugObject(int objRank)
std::string vecStr; std::string vecStr;
vecStr = p1.bboxMin.ToString(); vecStr = Math::ToString(p1.bboxMin);
l->Debug(" bboxMin: %s\n", vecStr.c_str()); l->Debug(" bboxMin: %s\n", vecStr.c_str());
vecStr = p1.bboxMax.ToString(); vecStr = Math::ToString(p1.bboxMax);
l->Debug(" bboxMax: %s\n", vecStr.c_str()); l->Debug(" bboxMax: %s\n", vecStr.c_str());
l->Debug(" totalTriangles: %d\n", p1.totalTriangles); l->Debug(" totalTriangles: %d\n", p1.totalTriangles);
l->Debug(" radius: %f\n", p1.boundingSphere.radius); l->Debug(" radius: %f\n", p1.boundingSphere.radius);
@ -994,7 +994,7 @@ void CEngine::SetObjectTransparency(int objRank, float value)
m_objects[objRank].transparency = value; m_objects[objRank].transparency = value;
} }
void CEngine::GetObjectBBox(int objRank, Math::Vector& min, Math::Vector& max) void CEngine::GetObjectBBox(int objRank, glm::vec3& min, glm::vec3& max)
{ {
assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() )); assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
@ -1251,7 +1251,7 @@ void CEngine::TrackTextureMapping(int objRank, const Material& mat, int state,
while (pos < 0.0f) while (pos < 0.0f)
pos += 1.0f; // never negative! pos += 1.0f; // never negative!
Math::Vector current; glm::vec3 current{ 0, 0, 0 };
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
@ -1401,7 +1401,7 @@ void CEngine::SetObjectShadowSpotType(int objRank, EngineShadowType type)
m_shadowSpots[shadowRank].type = type; m_shadowSpots[shadowRank].type = type;
} }
void CEngine::SetObjectShadowSpotPos(int objRank, const Math::Vector& pos) void CEngine::SetObjectShadowSpotPos(int objRank, const glm::vec3& pos)
{ {
assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() )); assert(objRank >= 0 && objRank < static_cast<int>( m_objects.size() ));
@ -1502,7 +1502,7 @@ bool CEngine::GetBBox2D(int objRank, glm::vec2& min, glm::vec2& max)
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
{ {
Math::Vector p; glm::vec3 p{ 0, 0, 0 };
if ( i & (1<<0) ) p.x = p1.bboxMin.x; if ( i & (1<<0) ) p.x = p1.bboxMin.x;
else p.x = p1.bboxMax.x; else p.x = p1.bboxMax.x;
@ -1511,7 +1511,7 @@ bool CEngine::GetBBox2D(int objRank, glm::vec2& min, glm::vec2& max)
if ( i & (1<<2) ) p.z = p1.bboxMin.z; if ( i & (1<<2) ) p.z = p1.bboxMin.z;
else p.z = p1.bboxMax.z; else p.z = p1.bboxMax.z;
Math::Vector pp; glm::vec3 pp{ 0, 0, 0 };
if (TransformPoint(pp, objRank, p)) if (TransformPoint(pp, objRank, p))
{ {
if (pp.x < min.x) min.x = pp.x; if (pp.x < min.x) min.x = pp.x;
@ -1573,10 +1573,10 @@ void CEngine::DeleteGroundSpot(int rank)
assert(rank >= 0 && rank < static_cast<int>( m_groundSpots.size() )); assert(rank >= 0 && rank < static_cast<int>( m_groundSpots.size() ));
m_groundSpots[rank].used = false; m_groundSpots[rank].used = false;
m_groundSpots[rank].pos = Math::Vector(0.0f, 0.0f, 0.0f); m_groundSpots[rank].pos = glm::vec3(0.0f, 0.0f, 0.0f);
} }
void CEngine::SetObjectGroundSpotPos(int rank, const Math::Vector& pos) void CEngine::SetObjectGroundSpotPos(int rank, const glm::vec3& pos)
{ {
assert(rank >= 0 && rank < static_cast<int>( m_groundSpots.size() )); assert(rank >= 0 && rank < static_cast<int>( m_groundSpots.size() ));
@ -1612,7 +1612,7 @@ void CEngine::SetObjectGroundSpotSmooth(int rank, float smooth)
m_groundSpots[rank].smooth = smooth; m_groundSpots[rank].smooth = smooth;
} }
void CEngine::CreateGroundMark(Math::Vector pos, float radius, void CEngine::CreateGroundMark(glm::vec3 pos, float radius,
float delay1, float delay2, float delay3, float delay1, float delay2, float delay3,
int dx, int dy, char* table) int dx, int dy, char* table)
{ {
@ -1643,11 +1643,11 @@ void CEngine::ComputeDistance()
if (! m_objects[i].used) if (! m_objects[i].used)
continue; continue;
Math::Vector v; glm::vec3 v{};
v.x = m_eyePt.x - m_objects[i].transform.Get(1, 4); 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.y = m_eyePt.y - m_objects[i].transform.Get(2, 4);
v.z = m_eyePt.z - m_objects[i].transform.Get(3, 4); v.z = m_eyePt.z - m_objects[i].transform.Get(3, 4);
m_objects[i].distance = v.Length(); m_objects[i].distance = glm::length(v);
} }
} }
@ -1662,8 +1662,8 @@ void CEngine::UpdateGeometry()
if (! p1.used) if (! p1.used)
continue; continue;
p1.bboxMin.LoadZero(); p1.bboxMin = { 0, 0, 0 };
p1.bboxMax.LoadZero(); p1.bboxMax = { 0, 0, 0 };
for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++) for (int l2 = 0; l2 < static_cast<int>( p1.next.size() ); l2++)
{ {
@ -1770,7 +1770,7 @@ bool CEngine::DetectBBox(int objRank, const glm::vec2& mouse)
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
{ {
Math::Vector p; glm::vec3 p{ 0, 0, 0 };
if ( i & (1<<0) ) p.x = p1.bboxMin.x; if ( i & (1<<0) ) p.x = p1.bboxMin.x;
else p.x = p1.bboxMax.x; else p.x = p1.bboxMax.x;
@ -1779,7 +1779,7 @@ bool CEngine::DetectBBox(int objRank, const glm::vec2& mouse)
if ( i & (1<<2) ) p.z = p1.bboxMin.z; if ( i & (1<<2) ) p.z = p1.bboxMin.z;
else p.z = p1.bboxMax.z; else p.z = p1.bboxMax.z;
Math::Vector pp; glm::vec3 pp{ 0, 0, 0 };
if ( TransformPoint(pp, objRank, p) ) if ( TransformPoint(pp, objRank, p) )
{ {
if (pp.x < min.x) min.x = pp.x; if (pp.x < min.x) min.x = pp.x;
@ -1795,11 +1795,11 @@ bool CEngine::DetectBBox(int objRank, const glm::vec2& mouse)
mouse.y <= max.y ); mouse.y <= max.y );
} }
int CEngine::DetectObject(const glm::vec2& mouse, Math::Vector& targetPos, bool terrain) int CEngine::DetectObject(const glm::vec2& mouse, glm::vec3& targetPos, bool terrain)
{ {
float min = 1000000.0f; float min = 1000000.0f;
int nearest = -1; int nearest = -1;
Math::Vector pos; glm::vec3 pos{ 0, 0, 0 };
for (int objRank = 0; objRank < static_cast<int>( m_objects.size() ); objRank++) for (int objRank = 0; objRank < static_cast<int>( m_objects.size() ); objRank++)
{ {
@ -1863,11 +1863,11 @@ int CEngine::DetectObject(const glm::vec2& mouse, Math::Vector& targetPos, bool
return nearest; return nearest;
} }
bool CEngine::DetectTriangle(const glm::vec2& mouse, Vertex3D* triangle, int objRank, float& dist, Math::Vector& pos) bool CEngine::DetectTriangle(const glm::vec2& mouse, Vertex3D* triangle, int objRank, float& dist, glm::vec3& pos)
{ {
assert(objRank >= 0 && objRank < static_cast<int>(m_objects.size())); assert(objRank >= 0 && objRank < static_cast<int>(m_objects.size()));
Math::Vector p2D[3], p3D; glm::vec3 p2D[3], p3D{ 0, 0, 0 };
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
@ -1910,11 +1910,11 @@ bool CEngine::DetectTriangle(const glm::vec2& mouse, Vertex3D* triangle, int obj
if (! Math::IsInsideTriangle(a, b, c, mouse)) if (! Math::IsInsideTriangle(a, b, c, mouse))
return false; return false;
Math::Vector a2 = Math::Transform(m_objects[objRank].transform, triangle[0].position); glm::vec3 a2 = Math::Transform(m_objects[objRank].transform, triangle[0].position);
Math::Vector b2 = Math::Transform(m_objects[objRank].transform, triangle[1].position); glm::vec3 b2 = Math::Transform(m_objects[objRank].transform, triangle[1].position);
Math::Vector c2 = Math::Transform(m_objects[objRank].transform, triangle[2].position); glm::vec3 c2 = Math::Transform(m_objects[objRank].transform, triangle[2].position);
Math::Vector e = Math::Transform(m_matView.Inverse(), Math::Vector(0.0f, 0.0f, -1.0f)); glm::vec3 e = Math::Transform(m_matView.Inverse(), glm::vec3(0.0f, 0.0f, -1.0f));
Math::Vector f = Math::Transform(m_matView.Inverse(), Math::Vector( glm::vec3 f = Math::Transform(m_matView.Inverse(), glm::vec3(
(mouse.x*2.0f-1.0f)*m_matProj.Inverse().Get(1,1), (mouse.x*2.0f-1.0f)*m_matProj.Inverse().Get(1,1),
(mouse.y*2.0f-1.0f)*m_matProj.Inverse().Get(2,2), (mouse.y*2.0f-1.0f)*m_matProj.Inverse().Get(2,2),
0.0f)); 0.0f));
@ -1946,57 +1946,57 @@ bool CEngine::IsVisible(const Math::Matrix& matrix, int objRank)
return false; return false;
} }
int CEngine::ComputeSphereVisibility(const Math::Matrix& m, const Math::Vector& center, float radius) int CEngine::ComputeSphereVisibility(const Math::Matrix& m, const glm::vec3& center, float radius)
{ {
Math::Vector vec[6]; glm::vec3 vec[6];
float originPlane[6]; float originPlane[6];
// Left plane // Left plane
vec[0].x = m.Get(4, 1) + m.Get(1, 1); vec[0].x = m.Get(4, 1) + m.Get(1, 1);
vec[0].y = m.Get(4, 2) + m.Get(1, 2); vec[0].y = m.Get(4, 2) + m.Get(1, 2);
vec[0].z = m.Get(4, 3) + m.Get(1, 3); vec[0].z = m.Get(4, 3) + m.Get(1, 3);
float l1 = vec[0].Length(); float l1 = glm::length(vec[0]);
vec[0].Normalize(); vec[0] = glm::normalize(vec[0]);
originPlane[0] = (m.Get(4, 4) + m.Get(1, 4)) / l1; originPlane[0] = (m.Get(4, 4) + m.Get(1, 4)) / l1;
// Right plane // Right plane
vec[1].x = m.Get(4, 1) - m.Get(1, 1); vec[1].x = m.Get(4, 1) - m.Get(1, 1);
vec[1].y = m.Get(4, 2) - m.Get(1, 2); vec[1].y = m.Get(4, 2) - m.Get(1, 2);
vec[1].z = m.Get(4, 3) - m.Get(1, 3); vec[1].z = m.Get(4, 3) - m.Get(1, 3);
float l2 = vec[1].Length(); float l2 = glm::length(vec[1]);
vec[1].Normalize(); vec[1] = glm::normalize(vec[1]);
originPlane[1] = (m.Get(4, 4) - m.Get(1, 4)) / l2; originPlane[1] = (m.Get(4, 4) - m.Get(1, 4)) / l2;
// Bottom plane // Bottom plane
vec[2].x = m.Get(4, 1) + m.Get(2, 1); vec[2].x = m.Get(4, 1) + m.Get(2, 1);
vec[2].y = m.Get(4, 2) + m.Get(2, 2); vec[2].y = m.Get(4, 2) + m.Get(2, 2);
vec[2].z = m.Get(4, 3) + m.Get(2, 3); vec[2].z = m.Get(4, 3) + m.Get(2, 3);
float l3 = vec[2].Length(); float l3 = glm::length(vec[2]);
vec[2].Normalize(); vec[2] = glm::normalize(vec[2]);
originPlane[2] = (m.Get(4, 4) + m.Get(2, 4)) / l3; originPlane[2] = (m.Get(4, 4) + m.Get(2, 4)) / l3;
// Top plane // Top plane
vec[3].x = m.Get(4, 1) - m.Get(2, 1); vec[3].x = m.Get(4, 1) - m.Get(2, 1);
vec[3].y = m.Get(4, 2) - m.Get(2, 2); vec[3].y = m.Get(4, 2) - m.Get(2, 2);
vec[3].z = m.Get(4, 3) - m.Get(2, 3); vec[3].z = m.Get(4, 3) - m.Get(2, 3);
float l4 = vec[3].Length(); float l4 = glm::length(vec[3]);
vec[3].Normalize(); vec[3] = glm::normalize(vec[3]);
originPlane[3] = (m.Get(4, 4) - m.Get(2, 4)) / l4; originPlane[3] = (m.Get(4, 4) - m.Get(2, 4)) / l4;
// Front plane // Front plane
vec[4].x = m.Get(4, 1) + m.Get(3, 1); vec[4].x = m.Get(4, 1) + m.Get(3, 1);
vec[4].y = m.Get(4, 2) + m.Get(3, 2); vec[4].y = m.Get(4, 2) + m.Get(3, 2);
vec[4].z = m.Get(4, 3) + m.Get(3, 3); vec[4].z = m.Get(4, 3) + m.Get(3, 3);
float l5 = vec[4].Length(); float l5 = glm::length(vec[4]);
vec[4].Normalize(); vec[4] = glm::normalize(vec[4]);
originPlane[4] = (m.Get(4, 4) + m.Get(3, 4)) / l5; originPlane[4] = (m.Get(4, 4) + m.Get(3, 4)) / l5;
// Back plane // Back plane
vec[5].x = m.Get(4, 1) - m.Get(3, 1); vec[5].x = m.Get(4, 1) - m.Get(3, 1);
vec[5].y = m.Get(4, 2) - m.Get(3, 2); vec[5].y = m.Get(4, 2) - m.Get(3, 2);
vec[5].z = m.Get(4, 3) - m.Get(3, 3); vec[5].z = m.Get(4, 3) - m.Get(3, 3);
float l6 = vec[5].Length(); float l6 = glm::length(vec[5]);
vec[5].Normalize(); vec[5] = glm::normalize(vec[5]);
originPlane[5] = (m.Get(4, 4) - m.Get(3, 4)) / l6; originPlane[5] = (m.Get(4, 4) - m.Get(3, 4)) / l6;
int result = 0; int result = 0;
@ -2017,7 +2017,7 @@ int CEngine::ComputeSphereVisibility(const Math::Matrix& m, const Math::Vector&
return result; return result;
} }
bool CEngine::InPlane(Math::Vector normal, float originPlane, Math::Vector center, float radius) bool CEngine::InPlane(glm::vec3 normal, float originPlane, glm::vec3 center, float radius)
{ {
float distance = originPlane + Math::DotProduct(normal, center); float distance = originPlane + Math::DotProduct(normal, center);
@ -2027,7 +2027,7 @@ bool CEngine::InPlane(Math::Vector normal, float originPlane, Math::Vector cente
return true; return true;
} }
bool CEngine::TransformPoint(Math::Vector& p2D, int objRank, Math::Vector p3D) bool CEngine::TransformPoint(glm::vec3& p2D, int objRank, glm::vec3 p3D)
{ {
assert(objRank >= 0 && objRank < static_cast<int>(m_objects.size())); assert(objRank >= 0 && objRank < static_cast<int>(m_objects.size()));
@ -2319,7 +2319,7 @@ void CEngine::SetMaterial(const Material& mat)
m_device->SetMaterial(mat); m_device->SetMaterial(mat);
} }
void CEngine::SetViewParams(const Math::Vector &eyePt, const Math::Vector &lookatPt, const Math::Vector &upVec) void CEngine::SetViewParams(const glm::vec3 &eyePt, const glm::vec3 &lookatPt, const glm::vec3 &upVec)
{ {
m_eyePt = eyePt; m_eyePt = eyePt;
m_lookatPt = lookatPt; m_lookatPt = lookatPt;
@ -3232,12 +3232,12 @@ const Math::Matrix& CEngine::GetMatProj()
return m_matProj; return m_matProj;
} }
Math::Vector CEngine::GetEyePt() glm::vec3 CEngine::GetEyePt()
{ {
return m_eyePt; return m_eyePt;
} }
Math::Vector CEngine::GetLookatPt() glm::vec3 CEngine::GetLookatPt()
{ {
return m_lookatPt; return m_lookatPt;
} }
@ -3252,7 +3252,7 @@ float CEngine::GetEyeDirV()
return m_eyeDirV; return m_eyeDirV;
} }
bool CEngine::IsVisiblePoint(const Math::Vector &pos) bool CEngine::IsVisiblePoint(const glm::vec3 &pos)
{ {
return Math::Distance(m_eyePt, pos) <= (m_deepView[0] * m_clippingDistance); return Math::Distance(m_eyePt, pos) <= (m_deepView[0] * m_clippingDistance);
} }
@ -3836,15 +3836,15 @@ void CEngine::RenderDebugSphere(const Math::Sphere& sphere, const Math::Matrix&
static constexpr int NUM_LINE_STRIPS = 2 + LONGITUDE_DIVISIONS + LATITUDE_DIVISIONS; static constexpr int NUM_LINE_STRIPS = 2 + LONGITUDE_DIVISIONS + LATITUDE_DIVISIONS;
static constexpr int VERTS_IN_LINE_STRIP = 32; static constexpr int VERTS_IN_LINE_STRIP = 32;
static std::array<Math::Vector, NUM_LINE_STRIPS * VERTS_IN_LINE_STRIP> verticesTemplate = [] static std::array<glm::vec3, NUM_LINE_STRIPS * VERTS_IN_LINE_STRIP> verticesTemplate = []
{ {
std::array<Math::Vector, NUM_LINE_STRIPS * VERTS_IN_LINE_STRIP> vertices; std::array<glm::vec3, NUM_LINE_STRIPS * VERTS_IN_LINE_STRIP> vertices;
auto SpherePoint = [&](float latitude, float longitude) auto SpherePoint = [&](float latitude, float longitude)
{ {
float latitudeAngle = (latitude - 0.5f) * 2.0f * Math::PI; float latitudeAngle = (latitude - 0.5f) * 2.0f * Math::PI;
float longitudeAngle = longitude * 2.0f * Math::PI; float longitudeAngle = longitude * 2.0f * Math::PI;
return Math::Vector(sinf(latitudeAngle) * cosf(longitudeAngle), return glm::vec3(sinf(latitudeAngle) * cosf(longitudeAngle),
cosf(latitudeAngle), cosf(latitudeAngle),
sinf(latitudeAngle) * sinf(longitudeAngle)); sinf(latitudeAngle) * sinf(longitudeAngle));
}; };
@ -3898,7 +3898,7 @@ void CEngine::RenderDebugSphere(const Math::Sphere& sphere, const Math::Matrix&
} }
} }
void CEngine::RenderDebugBox(const Math::Vector& mins, const Math::Vector& maxs, const Math::Matrix& transform, const Gfx::Color& color) void CEngine::RenderDebugBox(const glm::vec3& mins, const glm::vec3& maxs, const Math::Matrix& transform, const Gfx::Color& color)
{ {
static constexpr int NUM_LINE_STRIPS = 4; static constexpr int NUM_LINE_STRIPS = 4;
static constexpr int VERTS_IN_LINE_STRIP = 4; static constexpr int VERTS_IN_LINE_STRIP = 4;
@ -3922,25 +3922,25 @@ void CEngine::RenderDebugBox(const Math::Vector& mins, const Math::Vector& maxs,
auto vert = m_pendingDebugDraws.vertices.begin() + firstVert; auto vert = m_pendingDebugDraws.vertices.begin() + firstVert;
*vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{mins.x, mins.y, mins.z}), color}; *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{mins.x, mins.y, mins.z}), color};
*vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{maxs.x, mins.y, mins.z}), color}; *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{maxs.x, mins.y, mins.z}), color};
*vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{maxs.x, maxs.y, mins.z}), color}; *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{maxs.x, maxs.y, mins.z}), color};
*vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{maxs.x, maxs.y, maxs.z}), color}; *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{maxs.x, maxs.y, maxs.z}), color};
*vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{mins.x, mins.y, maxs.z}), color}; *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{mins.x, mins.y, maxs.z}), color};
*vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{mins.x, mins.y, mins.z}), color}; *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{mins.x, mins.y, mins.z}), color};
*vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{mins.x, maxs.y, mins.z}), color}; *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{mins.x, maxs.y, mins.z}), color};
*vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{maxs.x, maxs.y, mins.z}), color}; *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{maxs.x, maxs.y, mins.z}), color};
*vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{maxs.x, mins.y, maxs.z}), color}; *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{maxs.x, mins.y, maxs.z}), color};
*vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{mins.x, mins.y, maxs.z}), color}; *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{mins.x, mins.y, maxs.z}), color};
*vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{mins.x, maxs.y, maxs.z}), color}; *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{mins.x, maxs.y, maxs.z}), color};
*vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{mins.x, maxs.y, mins.z}), color}; *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{mins.x, maxs.y, mins.z}), color};
*vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{maxs.x, mins.y, mins.z}), color}; *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{maxs.x, mins.y, mins.z}), color};
*vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{maxs.x, mins.y, maxs.z}), color}; *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{maxs.x, mins.y, maxs.z}), color};
*vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{maxs.x, maxs.y, maxs.z}), color}; *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{maxs.x, maxs.y, maxs.z}), color};
*vert++ = VertexCol{Math::MatrixVectorMultiply(transform, Math::Vector{mins.x, maxs.y, maxs.z}), color}; *vert++ = VertexCol{Math::MatrixVectorMultiply(transform, glm::vec3{mins.x, maxs.y, maxs.z}), color};
} }
void CEngine::RenderPendingDebugDraws() void CEngine::RenderPendingDebugDraws()
@ -4045,11 +4045,11 @@ void CEngine::RenderShadowMap()
m_shadowParams[region].scale); m_shadowParams[region].scale);
// recompute matrices // recompute matrices
Math::Vector worldUp(0.0f, 1.0f, 0.0f); glm::vec3 worldUp(0.0f, 1.0f, 0.0f);
Math::Vector lightDir = Math::Vector(1.0f, 2.0f, -1.0f); glm::vec3 lightDir = glm::vec3(1.0f, 2.0f, -1.0f);
Math::Vector dir = m_lookatPt - m_eyePt; glm::vec3 dir = m_lookatPt - m_eyePt;
dir.y = 0.0f; dir.y = 0.0f;
dir.Normalize(); dir = glm::normalize(dir);
float range = m_shadowParams[region].range; float range = m_shadowParams[region].range;
@ -4062,14 +4062,14 @@ void CEngine::RenderShadowMap()
dist = 75.0f * scale; dist = 75.0f * scale;
} }
Math::Vector pos = m_lookatPt + 0.25f * dist * dir; glm::vec3 pos = m_lookatPt + 0.25f * dist * dir;
{ {
// To prevent 'shadow shimmering', we ensure that the position only moves in texel-sized // To prevent 'shadow shimmering', we ensure that the position only moves in texel-sized
// increments. To do this we transform the position to a space where the light's forward/right/up // increments. To do this we transform the position to a space where the light's forward/right/up
// axes are aligned with the x/y/z axes (not necessarily in that order, and +/- signs don't matter). // axes are aligned with the x/y/z axes (not necessarily in that order, and +/- signs don't matter).
Math::Matrix lightRotation; Math::Matrix lightRotation;
Math::LoadViewMatrix(lightRotation, Math::Vector{}, lightDir, worldUp); Math::LoadViewMatrix(lightRotation, glm::vec3{0, 0, 0}, lightDir, worldUp);
pos = Math::MatrixVectorMultiply(lightRotation, pos); pos = Math::MatrixVectorMultiply(lightRotation, pos);
// ...then we round to the nearest worldUnitsPerTexel: // ...then we round to the nearest worldUnitsPerTexel:
const float worldUnitsPerTexel = (dist * 2.0f) / m_shadowMap.size.x; const float worldUnitsPerTexel = (dist * 2.0f) / m_shadowMap.size.x;
@ -4082,13 +4082,13 @@ void CEngine::RenderShadowMap()
pos = Math::MatrixVectorMultiply(lightRotation.Inverse(), pos); pos = Math::MatrixVectorMultiply(lightRotation.Inverse(), pos);
} }
Math::Vector lookAt = pos - lightDir; glm::vec3 lookAt = pos - lightDir;
Math::LoadOrthoProjectionMatrix(m_shadowProjMat, -dist, dist, -dist, dist, -depth, depth); Math::LoadOrthoProjectionMatrix(m_shadowProjMat, -dist, dist, -dist, dist, -depth, depth);
Math::LoadViewMatrix(m_shadowViewMat, pos, lookAt, worldUp); Math::LoadViewMatrix(m_shadowViewMat, pos, lookAt, worldUp);
Math::Matrix scaleMat; Math::Matrix scaleMat;
Math::LoadScaleMatrix(scaleMat, Math::Vector(1.0f, 1.0f, -1.0f)); Math::LoadScaleMatrix(scaleMat, glm::vec3(1.0f, 1.0f, -1.0f));
m_shadowViewMat = Math::MultiplyMatrices(scaleMat, m_shadowViewMat); m_shadowViewMat = Math::MultiplyMatrices(scaleMat, m_shadowViewMat);
Math::Matrix temporary = Math::MultiplyMatrices(m_shadowProjMat, m_shadowViewMat); Math::Matrix temporary = Math::MultiplyMatrices(m_shadowProjMat, m_shadowViewMat);
@ -4550,7 +4550,7 @@ void CEngine::UpdateGroundSpotTextures()
{ {
for (int ix = 0; ix < 256; ix++) for (int ix = 0; ix < 256; ix++)
{ {
Math::Vector pos; glm::vec3 pos{};
pos.x = (256.0f * (s%4) + ix) * 3200.0f/1024.0f - 1600.0f; pos.x = (256.0f * (s%4) + ix) * 3200.0f/1024.0f - 1600.0f;
pos.z = (256.0f * (s/4) + iy) * 3200.0f/1024.0f - 1600.0f; pos.z = (256.0f * (s/4) + iy) * 3200.0f/1024.0f - 1600.0f;
pos.y = 0.0f; pos.y = 0.0f;
@ -4648,7 +4648,7 @@ void CEngine::UpdateGroundSpotTextures()
{ {
for (float y = min.y; y < max.y; y += 1.0f) for (float y = min.y; y < max.y; y += 1.0f)
{ {
Math::Vector pos( glm::vec3 pos(
x / 4.0f / 254.0f * 3200.0f - 1600.0f, x / 4.0f / 254.0f * 3200.0f - 1600.0f,
0.0f, 0.0f,
y / 4.0f / 254.0f * 3200.0f - 1600.0f y / 4.0f / 254.0f * 3200.0f - 1600.0f
@ -4738,7 +4738,7 @@ void CEngine::DrawShadowSpots()
ts.y += dp; ts.y += dp;
ti.y -= dp; ti.y -= dp;
Math::Vector n(0.0f, 1.0f, 0.0f); glm::vec3 n(0.0f, 1.0f, 0.0f);
float startDeepView = m_deepView[m_rankView] * m_fogStart[m_rankView] * m_clippingDistance; float startDeepView = m_deepView[m_rankView] * m_fogStart[m_rankView] * m_clippingDistance;
float endDeepView = m_deepView[m_rankView] * m_clippingDistance; float endDeepView = m_deepView[m_rankView] * m_clippingDistance;
@ -4749,7 +4749,7 @@ void CEngine::DrawShadowSpots()
if (m_shadowSpots[i].hide || !m_shadowSpots[i].used) if (m_shadowSpots[i].hide || !m_shadowSpots[i].used)
continue; continue;
Math::Vector pos = m_shadowSpots[i].pos; // pos = center of the shadow on the ground glm::vec3 pos = m_shadowSpots[i].pos; // pos = center of the shadow on the ground
if (m_eyePt.y == pos.y) if (m_eyePt.y == pos.y)
continue; // camera at the same level? continue; // camera at the same level?
@ -4809,7 +4809,7 @@ void CEngine::DrawShadowSpots()
radius *= 1.0f-d/D; // smaller if close radius *= 1.0f-d/D; // smaller if close
Math::Vector corner[4]; glm::vec3 corner[4];
if (m_shadowSpots[i].type == ENG_SHADOW_NORM) if (m_shadowSpots[i].type == ENG_SHADOW_NORM)
{ {
@ -4956,10 +4956,10 @@ void CEngine::DrawBackgroundGradient(const Color& up, const Color& down)
VertexCol vertex[4] = VertexCol vertex[4] =
{ {
{ Math::Vector(p1.x, p1.y, 0.0f), color[1] }, { glm::vec3(p1.x, p1.y, 0.0f), color[1] },
{ Math::Vector(p1.x, p2.y, 0.0f), color[0] }, { glm::vec3(p1.x, p2.y, 0.0f), color[0] },
{ Math::Vector(p2.x, p1.y, 0.0f), color[1] }, { glm::vec3(p2.x, p1.y, 0.0f), color[1] },
{ Math::Vector(p2.x, p2.y, 0.0f), color[0] } { glm::vec3(p2.x, p2.y, 0.0f), color[0] }
}; };
m_device->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, vertex, 4); m_device->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, vertex, 4);
@ -4974,7 +4974,7 @@ void CEngine::DrawBackgroundImage()
p2.x = 1.0f; p2.x = 1.0f;
p2.y = 1.0f; p2.y = 1.0f;
Math::Vector n = Math::Vector(0.0f, 0.0f, -1.0f); // normal glm::vec3 n = glm::vec3(0.0f, 0.0f, -1.0f); // normal
float u1, u2, v1, v2; float u1, u2, v1, v2;
if (m_backgroundFull) if (m_backgroundFull)
@ -5068,7 +5068,7 @@ void CEngine::DrawForegroundImage()
if (m_foregroundName.empty()) if (m_foregroundName.empty())
return; return;
Math::Vector n = Math::Vector(0.0f, 0.0f, -1.0f); // normal glm::vec3 n = glm::vec3(0.0f, 0.0f, -1.0f); // normal
glm::vec2 p1(0.0f, 0.0f); glm::vec2 p1(0.0f, 0.0f);
glm::vec2 p2(1.0f, 1.0f); glm::vec2 p2(1.0f, 1.0f);
@ -5082,10 +5082,10 @@ void CEngine::DrawForegroundImage()
Vertex vertex[4] = Vertex vertex[4] =
{ {
{ Math::Vector(p1.x, p1.y, 0.0f), n, { u1, v2 } }, { glm::vec3(p1.x, p1.y, 0.0f), n, { u1, v2 } },
{ Math::Vector(p1.x, p2.y, 0.0f), n, { u1, v1 } }, { glm::vec3(p1.x, p2.y, 0.0f), n, { u1, v1 } },
{ Math::Vector(p2.x, p1.y, 0.0f), n, { u2, v2 } }, { glm::vec3(p2.x, p1.y, 0.0f), n, { u2, v2 } },
{ Math::Vector(p2.x, p2.y, 0.0f), n, { u2, v1 } } { glm::vec3(p2.x, p2.y, 0.0f), n, { u2, v1 } }
}; };
SetTexture(m_foregroundTex); SetTexture(m_foregroundTex);
@ -5128,10 +5128,10 @@ void CEngine::DrawOverColor()
VertexCol vertex[4] = VertexCol vertex[4] =
{ {
{ Math::Vector(p1.x, p1.y, 0.0f), color[1] }, { glm::vec3(p1.x, p1.y, 0.0f), color[1] },
{ Math::Vector(p1.x, p2.y, 0.0f), color[0] }, { glm::vec3(p1.x, p2.y, 0.0f), color[0] },
{ Math::Vector(p2.x, p1.y, 0.0f), color[1] }, { glm::vec3(p2.x, p1.y, 0.0f), color[1] },
{ Math::Vector(p2.x, p2.y, 0.0f), color[0] } { glm::vec3(p2.x, p2.y, 0.0f), color[0] }
}; };
m_device->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, vertex, 4); m_device->DrawPrimitive(PrimitiveType::TRIANGLE_STRIP, vertex, 4);
@ -5202,32 +5202,32 @@ void CEngine::DrawHighlight()
VertexCol line[3] = VertexCol line[3] =
{ {
{ Math::Vector(), color }, { { 0, 0, 0 }, color },
{ Math::Vector(), color }, { { 0, 0, 0 }, color},
{ Math::Vector(), color } { { 0, 0, 0 }, color}
}; };
float dx = (p2.x - p1.x) / 5.0f; float dx = (p2.x - p1.x) / 5.0f;
float dy = (p2.y - p1.y) / 5.0f; float dy = (p2.y - p1.y) / 5.0f;
line[0].coord = Math::Vector(p1.x, p1.y + dy, 0.0f); line[0].coord = glm::vec3(p1.x, p1.y + dy, 0.0f);
line[1].coord = Math::Vector(p1.x, p1.y, 0.0f); line[1].coord = glm::vec3(p1.x, p1.y, 0.0f);
line[2].coord = Math::Vector(p1.x + dx, p1.y, 0.0f); line[2].coord = glm::vec3(p1.x + dx, p1.y, 0.0f);
m_device->DrawPrimitive(PrimitiveType::LINE_STRIP, line, 3); m_device->DrawPrimitive(PrimitiveType::LINE_STRIP, line, 3);
line[0].coord = Math::Vector(p2.x - dx, p1.y, 0.0f); line[0].coord = glm::vec3(p2.x - dx, p1.y, 0.0f);
line[1].coord = Math::Vector(p2.x, p1.y, 0.0f); line[1].coord = glm::vec3(p2.x, p1.y, 0.0f);
line[2].coord = Math::Vector(p2.x, p1.y + dy, 0.0f); line[2].coord = glm::vec3(p2.x, p1.y + dy, 0.0f);
m_device->DrawPrimitive(PrimitiveType::LINE_STRIP, line, 3); m_device->DrawPrimitive(PrimitiveType::LINE_STRIP, line, 3);
line[0].coord = Math::Vector(p2.x, p2.y - dy, 0.0f); line[0].coord = glm::vec3(p2.x, p2.y - dy, 0.0f);
line[1].coord = Math::Vector(p2.x, p2.y, 0.0f); line[1].coord = glm::vec3(p2.x, p2.y, 0.0f);
line[2].coord = Math::Vector(p2.x - dx, p2.y, 0.0f); line[2].coord = glm::vec3(p2.x - dx, p2.y, 0.0f);
m_device->DrawPrimitive(PrimitiveType::LINE_STRIP, line, 3); m_device->DrawPrimitive(PrimitiveType::LINE_STRIP, line, 3);
line[0].coord = Math::Vector(p1.x + dx, p2.y, 0.0f); line[0].coord = glm::vec3(p1.x + dx, p2.y, 0.0f);
line[1].coord = Math::Vector(p1.x, p2.y, 0.0f); line[1].coord = glm::vec3(p1.x, p2.y, 0.0f);
line[2].coord = Math::Vector(p1.x, p2.y - dy, 0.0f); line[2].coord = glm::vec3(p1.x, p2.y - dy, 0.0f);
m_device->DrawPrimitive(PrimitiveType::LINE_STRIP, line, 3); m_device->DrawPrimitive(PrimitiveType::LINE_STRIP, line, 3);
} }
@ -5504,11 +5504,11 @@ void CEngine::UpdateObjectShadowSpotNormal(int objRank)
// Calculating the normal to the ground in nine strategic locations, // Calculating the normal to the ground in nine strategic locations,
// then perform a weighted average (the dots in the center are more important). // then perform a weighted average (the dots in the center are more important).
Math::Vector pos = m_shadowSpots[shadowRank].pos; glm::vec3 pos = m_shadowSpots[shadowRank].pos;
float radius = m_shadowSpots[shadowRank].radius; float radius = m_shadowSpots[shadowRank].radius;
Math::Vector n[20]; glm::vec3 n[20];
Math::Vector norm; glm::vec3 norm = { 0, 0, 0 };
int i = 0; int i = 0;
m_terrain->GetNormal(norm, pos); m_terrain->GetNormal(norm, pos);
@ -5516,7 +5516,7 @@ void CEngine::UpdateObjectShadowSpotNormal(int objRank)
n[i++] = norm; n[i++] = norm;
n[i++] = norm; n[i++] = norm;
Math::Vector shPos = pos; glm::vec3 shPos = pos;
shPos.x += radius*0.6f; shPos.x += radius*0.6f;
shPos.z += radius*0.6f; shPos.z += radius*0.6f;
m_terrain->GetNormal(norm, shPos); m_terrain->GetNormal(norm, shPos);
@ -5568,7 +5568,7 @@ void CEngine::UpdateObjectShadowSpotNormal(int objRank)
m_terrain->GetNormal(norm, shPos); m_terrain->GetNormal(norm, shPos);
n[i++] = norm; n[i++] = norm;
norm.LoadZero(); norm = { 0, 0, 0 };
for (int j = 0; j < i; j++) for (int j = 0; j < i; j++)
{ {
norm += n[j]; norm += n[j];

View File

@ -243,9 +243,9 @@ struct EngineBaseObject
//! Number of triangles //! Number of triangles
int totalTriangles = 0; int totalTriangles = 0;
//! Bounding box min (origin 0,0,0 always included) //! Bounding box min (origin 0,0,0 always included)
Math::Vector bboxMin; glm::vec3 bboxMin{ 0, 0, 0 };
//! bounding box max (origin 0,0,0 always included) //! bounding box max (origin 0,0,0 always included)
Math::Vector bboxMax; glm::vec3 bboxMax{ 0, 0, 0 };
//! A bounding sphere that contains all the vertices in this EngineBaseObject //! A bounding sphere that contains all the vertices in this EngineBaseObject
Math::Sphere boundingSphere; Math::Sphere boundingSphere;
//! Next tier (Tex) //! Next tier (Tex)
@ -318,9 +318,9 @@ struct EngineShadow
//! Type of shadow //! Type of shadow
EngineShadowType type = ENG_SHADOW_NORM; EngineShadowType type = ENG_SHADOW_NORM;
//! Position of the shadow //! Position of the shadow
Math::Vector pos; glm::vec3 pos{ 0, 0, 0 };
//! Normal to the terrain //! Normal to the terrain
Math::Vector normal; glm::vec3 normal{ 0, 0, 0 };
//! Angle of the shadow //! Angle of the shadow
float angle = 0.0f; float angle = 0.0f;
//! Radius of the shadow //! Radius of the shadow
@ -353,11 +353,11 @@ struct EngineGroundSpot
//! Transition area //! Transition area
float smooth = 0.0f; float smooth = 0.0f;
//! Position for the shadow //! Position for the shadow
Math::Vector pos; glm::vec3 pos{ 0, 0, 0 };
//! Radius of the shadow //! Radius of the shadow
float radius = 0.0f; float radius = 0.0f;
//! Position of the shadow drawn //! Position of the shadow drawn
Math::Vector drawPos; glm::vec3 drawPos{ 0, 0, 0 };
//! Radius of the shadow drawn //! Radius of the shadow drawn
float drawRadius = 0.0f; float drawRadius = 0.0f;
@ -398,13 +398,13 @@ struct EngineGroundMark
//! Fixed time //! Fixed time
float fix = 0.0f; float fix = 0.0f;
//! Position for marks //! Position for marks
Math::Vector pos; glm::vec3 pos{ 0, 0, 0 };
//! Radius of marks //! Radius of marks
float radius = 0.0f; float radius = 0.0f;
//! Color intensity //! Color intensity
float intensity = 0.0f; float intensity = 0.0f;
//! Draw position for marks //! Draw position for marks
Math::Vector drawPos; glm::vec3 drawPos{ 0, 0, 0 };
//! Radius for marks //! Radius for marks
float drawRadius = 0.0f; float drawRadius = 0.0f;
//! Draw intensity for marks //! Draw intensity for marks
@ -685,7 +685,7 @@ public:
int GetStatisticTriangle(); int GetStatisticTriangle();
//! Sets the coordinates to display in stats window //! Sets the coordinates to display in stats window
void SetStatisticPos(Math::Vector pos); void SetStatisticPos(glm::vec3 pos);
//! Sets text to display as mission timer //! Sets text to display as mission timer
void SetTimerDisplay(const std::string& text); void SetTimerDisplay(const std::string& text);
@ -777,7 +777,7 @@ public:
void SetObjectTransparency(int objRank, float value); void SetObjectTransparency(int objRank, float value);
//! Returns the bounding box for an object //! Returns the bounding box for an object
void GetObjectBBox(int objRank, Math::Vector& min, Math::Vector& max); void GetObjectBBox(int objRank, glm::vec3& min, glm::vec3& max);
//! Returns the total number of triangles of given object //! Returns the total number of triangles of given object
int GetObjectTotalTriangles(int objRank); int GetObjectTotalTriangles(int objRank);
@ -807,7 +807,7 @@ public:
//! Detects the target object that is selected with the mouse //! Detects the target object that is selected with the mouse
/** Returns the rank of the object or -1. */ /** Returns the rank of the object or -1. */
int DetectObject(const glm::vec2& mouse, Math::Vector& targetPos, bool terrain = false); int DetectObject(const glm::vec2& mouse, glm::vec3& targetPos, bool terrain = false);
//! Creates a shadow for the given object //! Creates a shadow for the given object
void CreateShadowSpot(int objRank); void CreateShadowSpot(int objRank);
@ -818,7 +818,7 @@ public:
//! Management of different shadow params //! Management of different shadow params
void SetObjectShadowSpotHide(int objRank, bool hide); void SetObjectShadowSpotHide(int objRank, bool hide);
void SetObjectShadowSpotType(int objRank, EngineShadowType type); void SetObjectShadowSpotType(int objRank, EngineShadowType type);
void SetObjectShadowSpotPos(int objRank, const Math::Vector& pos); void SetObjectShadowSpotPos(int objRank, const glm::vec3& pos);
void SetObjectShadowSpotAngle(int objRank, float angle); void SetObjectShadowSpotAngle(int objRank, float angle);
void SetObjectShadowSpotRadius(int objRank, float radius); void SetObjectShadowSpotRadius(int objRank, float radius);
void SetObjectShadowSpotIntensity(int objRank, float intensity); void SetObjectShadowSpotIntensity(int objRank, float intensity);
@ -840,7 +840,7 @@ public:
//@{ //@{
//! Management of different ground spot params //! Management of different ground spot params
void SetObjectGroundSpotPos(int rank, const Math::Vector& pos); void SetObjectGroundSpotPos(int rank, const glm::vec3& pos);
void SetObjectGroundSpotRadius(int rank, float radius); void SetObjectGroundSpotRadius(int rank, float radius);
void SetObjectGroundSpotColor(int rank, const Color& color); void SetObjectGroundSpotColor(int rank, const Color& color);
void SetObjectGroundSpotMinMax(int rank, float min, float max); void SetObjectGroundSpotMinMax(int rank, float min, float max);
@ -848,7 +848,7 @@ public:
//@} //@}
//! Creates the ground mark with the given params //! Creates the ground mark with the given params
void CreateGroundMark(Math::Vector pos, float radius, void CreateGroundMark(glm::vec3 pos, float radius,
float delay1, float delay2, float delay3, float delay1, float delay2, float delay3,
int dx, int dy, char* table); int dx, int dy, char* table);
//! Deletes the ground mark //! Deletes the ground mark
@ -867,7 +867,7 @@ public:
void SetMaterial(const Material& mat); void SetMaterial(const Material& mat);
//! Specifies the location and direction of view //! Specifies the location and direction of view
void SetViewParams(const Math::Vector &eyePt, const Math::Vector &lookatPt, const Math::Vector &upVec); void SetViewParams(const glm::vec3 &eyePt, const glm::vec3 &lookatPt, const glm::vec3 &upVec);
//! Updates the textures used for drawing ground spot //! Updates the textures used for drawing ground spot
void UpdateGroundSpotTextures(); void UpdateGroundSpotTextures();
@ -1158,15 +1158,15 @@ public:
//! Returns the projection matrix //! Returns the projection matrix
const Math::Matrix& GetMatProj(); const Math::Matrix& GetMatProj();
//! Returns the camera center point //! Returns the camera center point
TEST_VIRTUAL Math::Vector GetEyePt(); TEST_VIRTUAL glm::vec3 GetEyePt();
//! Returns the camera target point //! Returns the camera target point
TEST_VIRTUAL Math::Vector GetLookatPt(); TEST_VIRTUAL glm::vec3 GetLookatPt();
//! Returns the horizontal direction angle of view //! Returns the horizontal direction angle of view
float GetEyeDirH(); float GetEyeDirH();
//! Returns the vertical direction angle of view //! Returns the vertical direction angle of view
float GetEyeDirV(); float GetEyeDirV();
//! Indicates whether a point is visible //! Indicates whether a point is visible
bool IsVisiblePoint(const Math::Vector& pos); bool IsVisiblePoint(const glm::vec3& pos);
//! Resets the projection matrix after changes //! Resets the projection matrix after changes
void UpdateMatProj(); void UpdateMatProj();
@ -1175,7 +1175,7 @@ public:
void ApplyChange(); void ApplyChange();
void RenderDebugSphere(const Math::Sphere&, const Math::Matrix& transform = Math::Matrix{}, const Color& = Color{0.0f, 0.0f, 1.0f, 1.0f}); void RenderDebugSphere(const Math::Sphere&, const Math::Matrix& transform = Math::Matrix{}, const Color& = Color{0.0f, 0.0f, 1.0f, 1.0f});
void RenderDebugBox(const Math::Vector& mins, const Math::Vector& maxs, const Math::Matrix& transform = Math::Matrix{}, const Color& = Color{0.0f, 0.0f, 1.0f, 1.0f}); void RenderDebugBox(const glm::vec3& mins, const glm::vec3& maxs, const Math::Matrix& transform = Math::Matrix{}, const Color& = Color{0.0f, 0.0f, 1.0f, 1.0f});
void SetDebugLights(bool debugLights); void SetDebugLights(bool debugLights);
bool GetDebugLights(); bool GetDebugLights();
@ -1263,9 +1263,9 @@ protected:
//! Tests whether the given object is visible //! Tests whether the given object is visible
bool IsVisible(const Math::Matrix& matrix, int objRank); bool IsVisible(const Math::Matrix& matrix, int objRank);
int ComputeSphereVisibility(const Math::Matrix& m, const Math::Vector& center, float radius); int ComputeSphereVisibility(const Math::Matrix& m, const glm::vec3& center, float radius);
bool InPlane(Math::Vector normal, float originPlane, Math::Vector center, float radius); bool InPlane(glm::vec3 normal, float originPlane, glm::vec3 center, float radius);
//! Detects whether an object is affected by the mouse //! Detects whether an object is affected by the mouse
bool DetectBBox(int objRank, const glm::vec2& mouse); bool DetectBBox(int objRank, const glm::vec2& mouse);
@ -1274,11 +1274,11 @@ protected:
bool GetBBox2D(int objRank, glm::vec2& min, glm::vec2& max); bool GetBBox2D(int objRank, glm::vec2& min, glm::vec2& max);
//! Detects whether the mouse is in a triangle. //! Detects whether the mouse is in a triangle.
bool DetectTriangle(const glm::vec2& mouse, Vertex3D* triangle, int objRank, float& dist, Math::Vector& pos); bool DetectTriangle(const glm::vec2& mouse, Vertex3D* triangle, int objRank, float& dist, glm::vec3& pos);
//! Transforms a 3D point (x, y, z) in 2D space (x, y, -) of the window //! Transforms a 3D point (x, y, z) in 2D space (x, y, -) of the window
/** The coordinated p2D.z gives the distance. */ /** The coordinated p2D.z gives the distance. */
bool TransformPoint(Math::Vector& p2D, int objRank, Math::Vector p3D); bool TransformPoint(glm::vec3& p2D, int objRank, glm::vec3 p3D);
//! Calculates the distances between the viewpoint and the origin of different objects //! Calculates the distances between the viewpoint and the origin of different objects
void ComputeDistance(); void ComputeDistance();
@ -1382,9 +1382,9 @@ protected:
EngineGroundMark m_groundMark; EngineGroundMark m_groundMark;
//! Location of camera //! Location of camera
Math::Vector m_eyePt; glm::vec3 m_eyePt{ 0, 0, 0 };
//! Camera target //! Camera target
Math::Vector m_lookatPt; glm::vec3 m_lookatPt{ 0, 0, 0 };
float m_eyeDirH; float m_eyeDirH;
float m_eyeDirV; float m_eyeDirV;
int m_rankView; int m_rankView;
@ -1395,7 +1395,7 @@ protected:
float m_fogStart[2]; float m_fogStart[2];
Color m_waterAddColor; Color m_waterAddColor;
int m_statisticTriangle; int m_statisticTriangle;
Math::Vector m_statisticPos; glm::vec3 m_statisticPos{ 0, 0, 0 };
bool m_updateGeometry; bool m_updateGeometry;
bool m_updateStaticBuffers; bool m_updateStaticBuffers;
bool m_firstGroundSpot; bool m_firstGroundSpot;

View File

@ -130,9 +130,9 @@ void CLightManager::DebugDumpLights()
l->Debug(" diffuse = %s\n", str.c_str()); l->Debug(" diffuse = %s\n", str.c_str());
str = light.specular.ToString(); str = light.specular.ToString();
l->Debug(" specular = %s\n", str.c_str()); l->Debug(" specular = %s\n", str.c_str());
str = light.position.ToString(); str = Math::ToString(light.position);
l->Debug(" position = %s\n", str.c_str()); l->Debug(" position = %s\n", str.c_str());
str = light.direction.ToString(); str = Math::ToString(light.direction);
l->Debug(" direction = %s\n", str.c_str()); l->Debug(" direction = %s\n", str.c_str());
l->Debug(" attenuation0 = %f\n", light.attenuation0); l->Debug(" attenuation0 = %f\n", light.attenuation0);
l->Debug(" attenuation1 = %f\n", light.attenuation1); l->Debug(" attenuation1 = %f\n", light.attenuation1);
@ -515,7 +515,7 @@ float CLightManager::CLightsComparator::GetLightWeight(const DynamicLight& dynLi
else if (dynLight.excludeType != ENG_OBJTYPE_NULL) else if (dynLight.excludeType != ENG_OBJTYPE_NULL)
enabled = dynLight.excludeType != m_objectType; enabled = dynLight.excludeType != m_objectType;
return enabled ? ( (dynLight.light.position - m_eyePos).Length() * dynLight.priority ) : 10000.0f; return enabled ? ( glm::length(dynLight.light.position - m_eyePos) * dynLight.priority ) : 10000.0f;
} }
bool CLightManager::CLightsComparator::operator()(const DynamicLight& left, const DynamicLight& right) bool CLightManager::CLightsComparator::operator()(const DynamicLight& left, const DynamicLight& right)

View File

@ -2621,7 +2621,7 @@ void CParticle::TrackDraw(int i, ParticleType type)
Math::Vector p2 = m_track[i].pos[h]; Math::Vector p2 = m_track[i].pos[h];
Math::Vector n = Normalize(p1-eye); Math::Vector n = glm::normalize(p1-eye);
Math::Vector p; Math::Vector p;
glm::vec2 rot; glm::vec2 rot;

View File

@ -547,7 +547,7 @@ VertexTex2 CTerrain::GetVertex(int x, int y, int step)
if (x-step >= 0 && y-step >= 0) if (x-step >= 0 && y-step >= 0)
s += Math::NormalToPlane(a,f,o); s += Math::NormalToPlane(a,f,o);
s = Normalize(s); s = glm::normalize(s);
v.normal = s; v.normal = s;
int brick = m_brickCount/m_textureSubdivCount; int brick = m_brickCount/m_textureSubdivCount;
@ -1453,11 +1453,11 @@ float CTerrain::GetFloorLevel(const Math::Vector &pos, bool brut, bool water)
Math::Vector ps = pos; Math::Vector ps = pos;
if ( fabs(pos.z-p2.z) < fabs(pos.x-p2.x) ) if ( fabs(pos.z-p2.z) < fabs(pos.x-p2.x) )
{ {
if ( !IntersectY(p1, p2, p3, ps) ) return 0.0f; if ( !Math::IntersectY(p1, p2, p3, ps) ) return 0.0f;
} }
else else
{ {
if ( !IntersectY(p2, p4, p3, ps) ) return 0.0f; if ( !Math::IntersectY(p2, p4, p3, ps) ) return 0.0f;
} }
if (! brut) AdjustBuildingLevel(ps); if (! brut) AdjustBuildingLevel(ps);
@ -1489,11 +1489,11 @@ float CTerrain::GetHeightToFloor(const Math::Vector &pos, bool brut, bool water)
Math::Vector ps = pos; Math::Vector ps = pos;
if ( fabs(pos.z-p2.z) < fabs(pos.x-p2.x) ) if ( fabs(pos.z-p2.z) < fabs(pos.x-p2.x) )
{ {
if ( !IntersectY(p1, p2, p3, ps) ) return 0.0f; if ( !Math::IntersectY(p1, p2, p3, ps) ) return 0.0f;
} }
else else
{ {
if ( !IntersectY(p2, p4, p3, ps) ) return 0.0f; if ( !Math::IntersectY(p2, p4, p3, ps) ) return 0.0f;
} }
if (! brut) AdjustBuildingLevel(ps); if (! brut) AdjustBuildingLevel(ps);
@ -1720,7 +1720,7 @@ void CTerrain::AdjustBuildingLevel(Math::Vector &p)
return; return;
} }
Math::Vector border; Math::Vector border{ 0, 0, 0 };
border.x = ((p.x - m_buildingLevels[i].center.x) * m_buildingLevels[i].max) / border.x = ((p.x - m_buildingLevels[i].center.x) * m_buildingLevels[i].max) /
dist + m_buildingLevels[i].center.x; dist + m_buildingLevels[i].center.x;
border.z = ((p.z - m_buildingLevels[i].center.z) * m_buildingLevels[i].max) / border.z = ((p.z - m_buildingLevels[i].center.z) * m_buildingLevels[i].max) /
@ -1780,7 +1780,7 @@ void CTerrain::ShowFlatGround(Math::Vector pos)
int i = x + y*41; int i = x + y*41;
table[i] = 0; table[i] = 0;
Math::Vector p; Math::Vector p{};
p.x = (x-20)*radius; p.x = (x-20)*radius;
p.z = (y-20)*radius; p.z = (y-20)*radius;
p.y = 0.0f; p.y = 0.0f;
@ -1820,7 +1820,7 @@ float CTerrain::GetFlatZoneRadius(Math::Vector center, float max)
for (int i = 0; i < nb; i++) for (int i = 0; i < nb; i++)
{ {
glm::vec2 result = Math::RotatePoint(c, angle, p); glm::vec2 result = Math::RotatePoint(c, angle, p);
Math::Vector pos; Math::Vector pos{ 0, 0, 0 };
pos.x = result.x; pos.x = result.x;
pos.z = result.y; pos.z = result.y;
float h = GetFloorLevel(pos, true); float h = GetFloorLevel(pos, true);

View File

@ -371,7 +371,7 @@ protected:
*/ */
struct BuildingLevel struct BuildingLevel
{ {
Math::Vector center; Math::Vector center{ 0, 0, 0 };
float factor = 0.0f; float factor = 0.0f;
float min = 0.0f; float min = 0.0f;
float max = 0.0f; float max = 0.0f;
@ -385,7 +385,7 @@ protected:
std::vector<BuildingLevel> m_buildingLevels; std::vector<BuildingLevel> m_buildingLevels;
//! Wind speed //! Wind speed
Math::Vector m_wind; Math::Vector m_wind{ 0, 0, 0 };
//! Global flying height limit //! Global flying height limit
float m_flyingMaxHeight; float m_flyingMaxHeight;
@ -396,7 +396,7 @@ protected:
*/ */
struct FlyingLimit struct FlyingLimit
{ {
Math::Vector center; Math::Vector center{ 0, 0, 0 };
float extRadius = 0.0f; float extRadius = 0.0f;
float intRadius = 0.0f; float intRadius = 0.0f;
float maxHeight = 0.0f; float maxHeight = 0.0f;

View File

@ -98,7 +98,7 @@ void CWater::LavaFrame(float rTime)
float distance = Math::Rand()*200.0f; float distance = Math::Rand()*200.0f;
float shift = (Math::Rand()-0.5f)*200.0f; float shift = (Math::Rand()-0.5f)*200.0f;
Math::Vector dir = Normalize(lookat-eye); Math::Vector dir = glm::normalize(lookat-eye);
Math::Vector pos = eye + dir*distance; Math::Vector pos = eye + dir*distance;
Math::Vector perp; Math::Vector perp;

View File

@ -30,7 +30,7 @@ namespace Gfx
*/ */
struct ModelCrashSphere struct ModelCrashSphere
{ {
Math::Vector position; Math::Vector position{ 0, 0, 0 };
float radius = 0.0f; float radius = 0.0f;
std::string sound; std::string sound;
float hardness = 0.0f; float hardness = 0.0f;

View File

@ -42,32 +42,32 @@ int CModelMesh::GetTriangleCount() const
return m_triangles.size(); return m_triangles.size();
} }
const Math::Vector& CModelMesh::GetPosition() const const glm::vec3& CModelMesh::GetPosition() const
{ {
return m_position; return m_position;
} }
void CModelMesh::SetPosition(const Math::Vector& position) void CModelMesh::SetPosition(const glm::vec3& position)
{ {
m_position = position; m_position = position;
} }
const Math::Vector& CModelMesh::GetRotation() const const glm::vec3& CModelMesh::GetRotation() const
{ {
return m_rotation; return m_rotation;
} }
void CModelMesh::SetRotation(const Math::Vector& rotation) void CModelMesh::SetRotation(const glm::vec3& rotation)
{ {
m_rotation = rotation; m_rotation = rotation;
} }
const Math::Vector& CModelMesh::GetScale() const const glm::vec3& CModelMesh::GetScale() const
{ {
return m_scale; return m_scale;
} }
void CModelMesh::SetScale(const Math::Vector& scale) void CModelMesh::SetScale(const glm::vec3& scale)
{ {
m_scale = scale; m_scale = scale;
} }

View File

@ -21,8 +21,6 @@
#include "graphics/model/model_triangle.h" #include "graphics/model/model_triangle.h"
#include "math/vector.h"
#include <vector> #include <vector>
namespace Gfx namespace Gfx
@ -45,19 +43,19 @@ public:
int GetTriangleCount() const; int GetTriangleCount() const;
//! Returns the mesh position //! Returns the mesh position
const Math::Vector& GetPosition() const; const glm::vec3& GetPosition() const;
//! Sets the mesh rotation //! Sets the mesh rotation
void SetPosition(const Math::Vector& position); void SetPosition(const glm::vec3& position);
//! Returns the mesh rotation //! Returns the mesh rotation
const Math::Vector& GetRotation() const; const glm::vec3& GetRotation() const;
//! Sets the mesh rotation //! Sets the mesh rotation
void SetRotation(const Math::Vector& rotation); void SetRotation(const glm::vec3& rotation);
//! Returns the mesh scale //! Returns the mesh scale
const Math::Vector& GetScale() const; const glm::vec3& GetScale() const;
//! Sets the mesh scale //! Sets the mesh scale
void SetScale(const Math::Vector& scale); void SetScale(const glm::vec3& scale);
//! Returns the name of parent mesh //! Returns the name of parent mesh
const std::string& GetParent() const; const std::string& GetParent() const;
@ -66,9 +64,9 @@ public:
private: private:
std::vector<ModelTriangle> m_triangles; std::vector<ModelTriangle> m_triangles;
Math::Vector m_position; glm::vec3 m_position;
Math::Vector m_rotation; glm::vec3 m_rotation;
Math::Vector m_scale; glm::vec3 m_scale;
std::string m_parent; std::string m_parent;
}; };

View File

@ -39,7 +39,7 @@ namespace ModelOutput
void WriteShadowSpot(const ModelShadowSpot& shadowSpot, std::ostream &stream); void WriteShadowSpot(const ModelShadowSpot& shadowSpot, std::ostream &stream);
void WriteCameraCollisionSphere(const Math::Sphere& sphere, std::ostream &stream); void WriteCameraCollisionSphere(const Math::Sphere& sphere, std::ostream &stream);
void WriteTextMesh(const CModelMesh* mesh, const std::string& meshName, std::ostream &stream); void WriteTextMesh(const CModelMesh* mesh, const std::string& meshName, std::ostream &stream);
std::string VectorToString(const Math::Vector& vector); std::string VectorToString(const glm::vec3& vector);
std::string TransparentModeToString(ModelTransparentMode mode); std::string TransparentModeToString(ModelTransparentMode mode);
std::string SpecialMarkToString(ModelSpecialMark specialMark); std::string SpecialMarkToString(ModelSpecialMark specialMark);
@ -203,7 +203,7 @@ void ModelOutput::WriteTextMesh(const CModelMesh* mesh, const std::string& meshN
} }
} }
std::string ModelOutput::VectorToString(const Math::Vector& vector) std::string ModelOutput::VectorToString(const glm::vec3& vector)
{ {
std::ostringstream str; std::ostringstream str;
str << vector.x << " " << vector.y << " " << vector.z; str << vector.x << " " << vector.y << " " << vector.z;

View File

@ -131,9 +131,9 @@ void CGL33Device::DebugLights()
if (l.type == LIGHT_DIRECTIONAL) if (l.type == LIGHT_DIRECTIONAL)
{ {
Gfx::VertexCol v[2]; Gfx::VertexCol v[2];
v[0].coord = -Math::Normalize(l.direction) * 100.0f + Math::Vector(0.0f, 0.0f, 1.0f) * i; v[0].coord = -Math::Normalize(l.direction) * 100.0f + glm::vec3(0.0f, 0.0f, 1.0f) * float(i);
v[0].color = HSV2RGB(color); v[0].color = HSV2RGB(color);
v[1].coord = Math::Normalize(l.direction) * 100.0f + Math::Vector(0.0f, 0.0f, 1.0f) * i; v[1].coord = Math::Normalize(l.direction) * 100.0f + glm::vec3(0.0f, 0.0f, 1.0f) * float(i);
v[1].color = HSV2RGB(color); v[1].color = HSV2RGB(color);
while (v[0].coord.y < 60.0f && v[0].coord.y < 60.0f) while (v[0].coord.y < 60.0f && v[0].coord.y < 60.0f)
{ {
@ -154,28 +154,28 @@ void CGL33Device::DebugLights()
for (int i = 0; i < 8; ++i) for (int i = 0; i < 8; ++i)
v[i].color = HSV2RGB(color); v[i].color = HSV2RGB(color);
v[0].coord = l.position + Math::Vector(-1.0f, -1.0f, -1.0f) * 4.0f; v[0].coord = l.position + glm::vec3(-1.0f, -1.0f, -1.0f) * 4.0f;
v[1].coord = l.position + Math::Vector( 1.0f, -1.0f, -1.0f) * 4.0f; v[1].coord = l.position + glm::vec3( 1.0f, -1.0f, -1.0f) * 4.0f;
v[2].coord = l.position + Math::Vector( 1.0f, 1.0f, -1.0f) * 4.0f; v[2].coord = l.position + glm::vec3( 1.0f, 1.0f, -1.0f) * 4.0f;
v[3].coord = l.position + Math::Vector(-1.0f, 1.0f, -1.0f) * 4.0f; v[3].coord = l.position + glm::vec3(-1.0f, 1.0f, -1.0f) * 4.0f;
v[4].coord = l.position + Math::Vector(-1.0f, -1.0f, -1.0f) * 4.0f; v[4].coord = l.position + glm::vec3(-1.0f, -1.0f, -1.0f) * 4.0f;
DrawPrimitive(PrimitiveType::LINE_STRIP, v, 5); DrawPrimitive(PrimitiveType::LINE_STRIP, v, 5);
v[0].coord = l.position + Math::Vector(-1.0f, -1.0f, 1.0f) * 4.0f; v[0].coord = l.position + glm::vec3(-1.0f, -1.0f, 1.0f) * 4.0f;
v[1].coord = l.position + Math::Vector( 1.0f, -1.0f, 1.0f) * 4.0f; v[1].coord = l.position + glm::vec3( 1.0f, -1.0f, 1.0f) * 4.0f;
v[2].coord = l.position + Math::Vector( 1.0f, 1.0f, 1.0f) * 4.0f; v[2].coord = l.position + glm::vec3( 1.0f, 1.0f, 1.0f) * 4.0f;
v[3].coord = l.position + Math::Vector(-1.0f, 1.0f, 1.0f) * 4.0f; v[3].coord = l.position + glm::vec3(-1.0f, 1.0f, 1.0f) * 4.0f;
v[4].coord = l.position + Math::Vector(-1.0f, -1.0f, 1.0f) * 4.0f; v[4].coord = l.position + glm::vec3(-1.0f, -1.0f, 1.0f) * 4.0f;
DrawPrimitive(PrimitiveType::LINE_STRIP, v, 5); DrawPrimitive(PrimitiveType::LINE_STRIP, v, 5);
v[0].coord = l.position + Math::Vector(-1.0f, -1.0f, -1.0f) * 4.0f; v[0].coord = l.position + glm::vec3(-1.0f, -1.0f, -1.0f) * 4.0f;
v[1].coord = l.position + Math::Vector(-1.0f, -1.0f, 1.0f) * 4.0f; v[1].coord = l.position + glm::vec3(-1.0f, -1.0f, 1.0f) * 4.0f;
v[2].coord = l.position + Math::Vector( 1.0f, -1.0f, -1.0f) * 4.0f; v[2].coord = l.position + glm::vec3( 1.0f, -1.0f, -1.0f) * 4.0f;
v[3].coord = l.position + Math::Vector( 1.0f, -1.0f, 1.0f) * 4.0f; v[3].coord = l.position + glm::vec3( 1.0f, -1.0f, 1.0f) * 4.0f;
v[4].coord = l.position + Math::Vector( 1.0f, 1.0f, -1.0f) * 4.0f; v[4].coord = l.position + glm::vec3( 1.0f, 1.0f, -1.0f) * 4.0f;
v[5].coord = l.position + Math::Vector( 1.0f, 1.0f, 1.0f) * 4.0f; v[5].coord = l.position + glm::vec3( 1.0f, 1.0f, 1.0f) * 4.0f;
v[6].coord = l.position + Math::Vector(-1.0f, 1.0f, -1.0f) * 4.0f; v[6].coord = l.position + glm::vec3(-1.0f, 1.0f, -1.0f) * 4.0f;
v[7].coord = l.position + Math::Vector(-1.0f, 1.0f, 1.0f) * 4.0f; v[7].coord = l.position + glm::vec3(-1.0f, 1.0f, 1.0f) * 4.0f;
DrawPrimitive(PrimitiveType::LINES, v, 8); DrawPrimitive(PrimitiveType::LINES, v, 8);
} }
else if (l.type == LIGHT_SPOT) else if (l.type == LIGHT_SPOT)
@ -184,11 +184,11 @@ void CGL33Device::DebugLights()
for (int i = 0; i < 5; ++i) for (int i = 0; i < 5; ++i)
v[i].color = HSV2RGB(color); v[i].color = HSV2RGB(color);
v[0].coord = l.position + Math::Vector(-1.0f, 0.0f, -1.0f) * 4.0f; v[0].coord = l.position + glm::vec3(-1.0f, 0.0f, -1.0f) * 4.0f;
v[1].coord = l.position + Math::Vector( 1.0f, 0.0f, -1.0f) * 4.0f; v[1].coord = l.position + glm::vec3( 1.0f, 0.0f, -1.0f) * 4.0f;
v[2].coord = l.position + Math::Vector( 1.0f, 0.0f, 1.0f) * 4.0f; v[2].coord = l.position + glm::vec3( 1.0f, 0.0f, 1.0f) * 4.0f;
v[3].coord = l.position + Math::Vector(-1.0f, 0.0f, 1.0f) * 4.0f; v[3].coord = l.position + glm::vec3(-1.0f, 0.0f, 1.0f) * 4.0f;
v[4].coord = l.position + Math::Vector(-1.0f, 0.0f, -1.0f) * 4.0f; v[4].coord = l.position + glm::vec3(-1.0f, 0.0f, -1.0f) * 4.0f;
DrawPrimitive(PrimitiveType::LINE_STRIP, v, 5); DrawPrimitive(PrimitiveType::LINE_STRIP, v, 5);
v[0].coord = l.position; v[0].coord = l.position;
@ -600,7 +600,7 @@ void CGL33Device::SetTransform(TransformType type, const Math::Matrix &matrix)
else if (type == TRANSFORM_VIEW) else if (type == TRANSFORM_VIEW)
{ {
Math::Matrix scale; Math::Matrix scale;
Math::Vector cameraPosition; glm::vec3 cameraPosition;
scale.Set(3, 3, -1.0f); scale.Set(3, 3, -1.0f);
m_viewMat = Math::MultiplyMatrices(scale, matrix); m_viewMat = Math::MultiplyMatrices(scale, matrix);
@ -611,9 +611,9 @@ void CGL33Device::SetTransform(TransformType type, const Math::Matrix &matrix)
if (m_uniforms.cameraPosition >= 0) if (m_uniforms.cameraPosition >= 0)
{ {
cameraPosition.LoadZero(); cameraPosition = { 0, 0, 0 };
cameraPosition = MatrixVectorMultiply(m_viewMat.Inverse(), cameraPosition); cameraPosition = MatrixVectorMultiply(m_viewMat.Inverse(), cameraPosition);
glUniform3fv(m_uniforms.cameraPosition, 1, cameraPosition.Array()); glUniform3fv(m_uniforms.cameraPosition, 1, glm::value_ptr(cameraPosition));
} }
} }
else if (type == TRANSFORM_PROJECTION) else if (type == TRANSFORM_PROJECTION)
@ -1329,7 +1329,7 @@ void CGL33Device::DestroyVertexBuffer(CVertexBuffer* buffer)
/* Based on libwine's implementation */ /* Based on libwine's implementation */
int CGL33Device::ComputeSphereVisibility(const Math::Vector &center, float radius) int CGL33Device::ComputeSphereVisibility(const glm::vec3 &center, float radius)
{ {
if (m_combinedMatrixOutdated) if (m_combinedMatrixOutdated)
{ {
@ -1339,55 +1339,55 @@ int CGL33Device::ComputeSphereVisibility(const Math::Vector &center, float radiu
Math::Matrix &m = m_combinedMatrix; Math::Matrix &m = m_combinedMatrix;
Math::Vector vec[6]; glm::vec3 vec[6];
float originPlane[6]; float originPlane[6];
// Left plane // Left plane
vec[0].x = m.Get(4, 1) + m.Get(1, 1); vec[0].x = m.Get(4, 1) + m.Get(1, 1);
vec[0].y = m.Get(4, 2) + m.Get(1, 2); vec[0].y = m.Get(4, 2) + m.Get(1, 2);
vec[0].z = m.Get(4, 3) + m.Get(1, 3); vec[0].z = m.Get(4, 3) + m.Get(1, 3);
float l1 = vec[0].Length(); float l1 = glm::length(vec[0]);
vec[0].Normalize(); vec[0] = glm::normalize(vec[0]);
originPlane[0] = (m.Get(4, 4) + m.Get(1, 4)) / l1; originPlane[0] = (m.Get(4, 4) + m.Get(1, 4)) / l1;
// Right plane // Right plane
vec[1].x = m.Get(4, 1) - m.Get(1, 1); vec[1].x = m.Get(4, 1) - m.Get(1, 1);
vec[1].y = m.Get(4, 2) - m.Get(1, 2); vec[1].y = m.Get(4, 2) - m.Get(1, 2);
vec[1].z = m.Get(4, 3) - m.Get(1, 3); vec[1].z = m.Get(4, 3) - m.Get(1, 3);
float l2 = vec[1].Length(); float l2 = glm::length(vec[1]);
vec[1].Normalize(); vec[1] = glm::normalize(vec[1]);
originPlane[1] = (m.Get(4, 4) - m.Get(1, 4)) / l2; originPlane[1] = (m.Get(4, 4) - m.Get(1, 4)) / l2;
// Bottom plane // Bottom plane
vec[2].x = m.Get(4, 1) + m.Get(2, 1); vec[2].x = m.Get(4, 1) + m.Get(2, 1);
vec[2].y = m.Get(4, 2) + m.Get(2, 2); vec[2].y = m.Get(4, 2) + m.Get(2, 2);
vec[2].z = m.Get(4, 3) + m.Get(2, 3); vec[2].z = m.Get(4, 3) + m.Get(2, 3);
float l3 = vec[2].Length(); float l3 = glm::length(vec[2]);
vec[2].Normalize(); vec[2] = glm::normalize(vec[2]);
originPlane[2] = (m.Get(4, 4) + m.Get(2, 4)) / l3; originPlane[2] = (m.Get(4, 4) + m.Get(2, 4)) / l3;
// Top plane // Top plane
vec[3].x = m.Get(4, 1) - m.Get(2, 1); vec[3].x = m.Get(4, 1) - m.Get(2, 1);
vec[3].y = m.Get(4, 2) - m.Get(2, 2); vec[3].y = m.Get(4, 2) - m.Get(2, 2);
vec[3].z = m.Get(4, 3) - m.Get(2, 3); vec[3].z = m.Get(4, 3) - m.Get(2, 3);
float l4 = vec[3].Length(); float l4 = glm::length(vec[3]);
vec[3].Normalize(); vec[3] = glm::normalize(vec[3]);
originPlane[3] = (m.Get(4, 4) - m.Get(2, 4)) / l4; originPlane[3] = (m.Get(4, 4) - m.Get(2, 4)) / l4;
// Front plane // Front plane
vec[4].x = m.Get(4, 1) + m.Get(3, 1); vec[4].x = m.Get(4, 1) + m.Get(3, 1);
vec[4].y = m.Get(4, 2) + m.Get(3, 2); vec[4].y = m.Get(4, 2) + m.Get(3, 2);
vec[4].z = m.Get(4, 3) + m.Get(3, 3); vec[4].z = m.Get(4, 3) + m.Get(3, 3);
float l5 = vec[4].Length(); float l5 = glm::length(vec[4]);
vec[4].Normalize(); vec[4] = glm::normalize(vec[4]);
originPlane[4] = (m.Get(4, 4) + m.Get(3, 4)) / l5; originPlane[4] = (m.Get(4, 4) + m.Get(3, 4)) / l5;
// Back plane // Back plane
vec[5].x = m.Get(4, 1) - m.Get(3, 1); vec[5].x = m.Get(4, 1) - m.Get(3, 1);
vec[5].y = m.Get(4, 2) - m.Get(3, 2); vec[5].y = m.Get(4, 2) - m.Get(3, 2);
vec[5].z = m.Get(4, 3) - m.Get(3, 3); vec[5].z = m.Get(4, 3) - m.Get(3, 3);
float l6 = vec[5].Length(); float l6 = glm::length(vec[5]);
vec[5].Normalize(); vec[5] = glm::normalize(vec[5]);
originPlane[5] = (m.Get(4, 4) - m.Get(3, 4)) / l6; originPlane[5] = (m.Get(4, 4) - m.Get(3, 4)) / l6;
int result = 0; int result = 0;

View File

@ -169,7 +169,7 @@ public:
void DrawVertexBuffer(CVertexBuffer*) override; void DrawVertexBuffer(CVertexBuffer*) override;
void DestroyVertexBuffer(CVertexBuffer*) override; void DestroyVertexBuffer(CVertexBuffer*) override;
int ComputeSphereVisibility(const Math::Vector &center, float radius) override; int ComputeSphereVisibility(const glm::vec3 &center, float radius) override;
void SetViewport(int x, int y, int width, int height) override; void SetViewport(int x, int y, int width, int height) override;

View File

@ -447,7 +447,7 @@ void CRobotMain::ChangePhase(Phase phase)
m_engine->SetOverColor(); m_engine->SetOverColor();
m_engine->DeleteGroundMark(0); m_engine->DeleteGroundMark(0);
SetSpeed(1.0f); SetSpeed(1.0f);
m_terrain->SetWind(Math::Vector(0.0f, 0.0f, 0.0f)); m_terrain->SetWind(glm::vec3(0.0f, 0.0f, 0.0f));
m_terrain->FlushBuildingLevel(); m_terrain->FlushBuildingLevel();
m_terrain->FlushFlyingLimit(); m_terrain->FlushFlyingLimit();
m_lightMan->FlushLights(); m_lightMan->FlushLights();
@ -458,7 +458,7 @@ void CRobotMain::ChangePhase(Phase phase)
m_planet->Flush(); m_planet->Flush();
m_interface->Flush(); m_interface->Flush();
m_newScriptName.clear(); m_newScriptName.clear();
m_sound->SetListener(Math::Vector(0.0f, 0.0f, 0.0f), Math::Vector(0.0f, 0.0f, 1.0f)); m_sound->SetListener(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f));
m_sound->StopAll(); m_sound->StopAll();
m_camera->SetType(Gfx::CAM_TYPE_NULL); m_camera->SetType(Gfx::CAM_TYPE_NULL);
m_movie->Flush(); m_movie->Flush();
@ -602,7 +602,7 @@ void CRobotMain::ChangePhase(Phase phase)
} }
else else
{ {
m_displayText->DisplayError(INFO_WIN, Math::Vector(0.0f,0.0f,0.0f), 15.0f, 60.0f, 1000.0f); m_displayText->DisplayError(INFO_WIN, glm::vec3(0.0f,0.0f,0.0f), 15.0f, 60.0f, 1000.0f);
} }
StartMusic(); StartMusic();
} }
@ -632,7 +632,7 @@ void CRobotMain::ChangePhase(Phase phase)
glm::vec2 ddim; glm::vec2 ddim;
ddim.x = dim.x*2; ddim.y = dim.y*2; ddim.x = dim.x*2; ddim.y = dim.y*2;
m_interface->CreateButton(pos, ddim, 16, EVENT_BUTTON_OK); m_interface->CreateButton(pos, ddim, 16, EVENT_BUTTON_OK);
m_displayText->DisplayError(INFO_LOST, Math::Vector(0.0f,0.0f,0.0f), 15.0f, 60.0f, 1000.0f); m_displayText->DisplayError(INFO_LOST, glm::vec3(0.0f,0.0f,0.0f), 15.0f, 60.0f, 1000.0f);
StartMusic(); StartMusic();
} }
@ -1043,7 +1043,7 @@ bool CRobotMain::ProcessEvent(Event &event)
CLevelParserLine line("CreateObject"); CLevelParserLine line("CreateObject");
line.AddParam("type", MakeUnique<CLevelParserParam>(obj->GetType())); line.AddParam("type", MakeUnique<CLevelParserParam>(obj->GetType()));
Math::Vector pos = obj->GetPosition()/g_unit; glm::vec3 pos = obj->GetPosition()/g_unit;
pos.y = 0.0f; pos.y = 0.0f;
line.AddParam("pos", MakeUnique<CLevelParserParam>(pos)); line.AddParam("pos", MakeUnique<CLevelParserParam>(pos));
@ -1538,7 +1538,7 @@ void CRobotMain::ExecuteCmd(const std::string& cmd)
} }
if (m_phase == PHASE_SIMUL) if (m_phase == PHASE_SIMUL)
m_displayText->DisplayError(ERR_CMD, Math::Vector(0.0f,0.0f,0.0f)); m_displayText->DisplayError(ERR_CMD, glm::vec3(0.0f,0.0f,0.0f));
} }
@ -1805,7 +1805,7 @@ void CRobotMain::FrameVisit(float rTime)
// Moves the arrow. // Moves the arrow.
m_visitTime += rTime; m_visitTime += rTime;
Math::Vector pos = m_visitPosArrow; glm::vec3 pos = m_visitPosArrow;
pos.y += 1.5f+sinf(m_visitTime*4.0f)*4.0f; pos.y += 1.5f+sinf(m_visitTime*4.0f)*4.0f;
m_visitArrow->SetPosition(pos); m_visitArrow->SetPosition(pos);
m_visitArrow->SetRotationY(m_visitTime*2.0f); m_visitArrow->SetRotationY(m_visitTime*2.0f);
@ -1819,7 +1819,7 @@ void CRobotMain::FrameVisit(float rTime)
pos = m_visitPos; pos = m_visitPos;
float level = m_terrain->GetFloorLevel(pos)+2.0f; float level = m_terrain->GetFloorLevel(pos)+2.0f;
if (pos.y < level) pos.y = level; // not below the ground if (pos.y < level) pos.y = level; // not below the ground
Math::Vector speed(0.0f, 0.0f, 0.0f); glm::vec3 speed(0.0f, 0.0f, 0.0f);
glm::vec2 dim; glm::vec2 dim;
dim.x = 30.0f; dim.x = 30.0f;
dim.y = dim.x; dim.y = dim.x;
@ -2026,7 +2026,7 @@ CObject* CRobotMain::GetSelect()
//! Detects the object aimed by the mouse //! Detects the object aimed by the mouse
CObject* CRobotMain::DetectObject(const glm::vec2& pos) CObject* CRobotMain::DetectObject(const glm::vec2& pos)
{ {
Math::Vector p; glm::vec3 p;
int objRank = m_engine->DetectObject(pos, p); int objRank = m_engine->DetectObject(pos, p);
for (CObject* obj : m_objMan->GetAllObjects()) for (CObject* obj : m_objMan->GetAllObjects())
@ -2372,7 +2372,7 @@ void CRobotMain::UpdateInfoText()
CObject* obj = GetSelect(); CObject* obj = GetSelect();
if (obj != nullptr) if (obj != nullptr)
{ {
Math::Vector pos = obj->GetPosition(); glm::vec3 pos = obj->GetPosition();
m_engine->SetStatisticPos(pos / g_unit); m_engine->SetStatisticPos(pos / g_unit);
} }
} }
@ -2384,8 +2384,8 @@ void CRobotMain::UpdateInfoText()
void CRobotMain::InitEye() void CRobotMain::InitEye()
{ {
if (m_phase == PHASE_SIMUL) if (m_phase == PHASE_SIMUL)
m_camera->Init(Math::Vector( 0.0f, 10.0f, 0.0f), m_camera->Init(glm::vec3( 0.0f, 10.0f, 0.0f),
Math::Vector(10.0f, 5.0f, 0.0f), 0.0f); glm::vec3(10.0f, 5.0f, 0.0f), 0.0f);
} }
//! Advances the entire scene //! Advances the entire scene
@ -2431,7 +2431,7 @@ bool CRobotMain::EventFrame(const Event &event)
if ( obj->GetProxyActivate() ) // active if it is near? if ( obj->GetProxyActivate() ) // active if it is near?
{ {
Math::Vector eye = m_engine->GetLookatPt(); glm::vec3 eye = m_engine->GetLookatPt();
float dist = Math::Distance(eye, obj->GetPosition()); float dist = Math::Distance(eye, obj->GetPosition());
if ( dist < obj->GetProxyDistance() ) if ( dist < obj->GetProxyDistance() )
{ {
@ -2482,7 +2482,7 @@ bool CRobotMain::EventFrame(const Event &event)
{ {
if (!m_immediatSatCom && !m_beginSatCom && !m_movieLock) if (!m_immediatSatCom && !m_beginSatCom && !m_movieLock)
{ {
m_displayText->DisplayError(INFO_BEGINSATCOM, Math::Vector(0.0f, 0.0f, 0.0f)); m_displayText->DisplayError(INFO_BEGINSATCOM, glm::vec3(0.0f, 0.0f, 0.0f));
m_beginSatCom = true; // message appears m_beginSatCom = true; // message appears
} }
@ -3155,7 +3155,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
if (line->GetCommand() == "Planet" && !resetObject) if (line->GetCommand() == "Planet" && !resetObject)
{ {
Math::Vector ppos, uv1, uv2; glm::vec3 ppos, uv1, uv2;
ppos = line->GetParam("pos")->AsPoint(); ppos = line->GetParam("pos")->AsPoint();
uv1 = line->GetParam("uv1")->AsPoint(); uv1 = line->GetParam("uv1")->AsPoint();
@ -3237,7 +3237,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
if (line->GetCommand() == "TerrainWater" && !resetObject) if (line->GetCommand() == "TerrainWater" && !resetObject)
{ {
Math::Vector pos; glm::vec3 pos;
pos.x = line->GetParam("moveX")->AsFloat(0.0f); pos.x = line->GetParam("moveX")->AsFloat(0.0f);
pos.y = line->GetParam("moveY")->AsFloat(0.0f); pos.y = line->GetParam("moveY")->AsFloat(0.0f);
pos.z = pos.x; pos.z = pos.x;
@ -3374,7 +3374,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
line->GetParam("max")->AsFloat(100.0f)*g_unit, line->GetParam("max")->AsFloat(100.0f)*g_unit,
line->GetParam("slope")->AsFloat(5.0f), line->GetParam("slope")->AsFloat(5.0f),
line->GetParam("freq")->AsFloat(100.0f), line->GetParam("freq")->AsFloat(100.0f),
line->GetParam("center")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f))*g_unit, line->GetParam("center")->AsPoint(glm::vec3(0.0f, 0.0f, 0.0f))*g_unit,
line->GetParam("radius")->AsFloat(0.0f)*g_unit); line->GetParam("radius")->AsFloat(0.0f)*g_unit);
continue; continue;
} }
@ -3414,7 +3414,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
throw CLevelParserException("There can be only one LevelController in the level"); throw CLevelParserException("There can be only one LevelController in the level");
} }
m_controller = m_objMan->CreateObject(Math::Vector(0.0f, 0.0f, 0.0f), 0.0f, OBJECT_CONTROLLER); m_controller = m_objMan->CreateObject(glm::vec3(0.0f, 0.0f, 0.0f), 0.0f, OBJECT_CONTROLLER);
assert(m_controller->Implements(ObjectInterfaceType::Programmable)); assert(m_controller->Implements(ObjectInterfaceType::Programmable));
assert(m_controller->Implements(ObjectInterfaceType::ProgramStorage)); assert(m_controller->Implements(ObjectInterfaceType::ProgramStorage));
@ -3493,7 +3493,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
if (line->GetCommand() == "CreateFog" && !resetObject) if (line->GetCommand() == "CreateFog" && !resetObject)
{ {
Gfx::ParticleType type = static_cast<Gfx::ParticleType>(Gfx::PARTIFOG0+(line->GetParam("type")->AsInt())); Gfx::ParticleType type = static_cast<Gfx::ParticleType>(Gfx::PARTIFOG0+(line->GetParam("type")->AsInt()));
Math::Vector pos = line->GetParam("pos")->AsPoint()*g_unit; glm::vec3 pos = line->GetParam("pos")->AsPoint()*g_unit;
float height = line->GetParam("height")->AsFloat(1.0f)*g_unit; float height = line->GetParam("height")->AsFloat(1.0f)*g_unit;
float ddim = line->GetParam("dim")->AsFloat(50.0f)*g_unit; float ddim = line->GetParam("dim")->AsFloat(50.0f)*g_unit;
float delay = line->GetParam("delay")->AsFloat(2.0f); float delay = line->GetParam("delay")->AsFloat(2.0f);
@ -3502,7 +3502,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
glm::vec2 dim; glm::vec2 dim;
dim.x = ddim; dim.x = ddim;
dim.y = dim.x; dim.y = dim.x;
m_particle->CreateParticle(pos, Math::Vector(0.0f, 0.0f, 0.0f), dim, type, delay, 0.0f, 0.0f); m_particle->CreateParticle(pos, glm::vec3(0.0f, 0.0f, 0.0f), dim, type, delay, 0.0f, 0.0f);
continue; continue;
} }
@ -3560,7 +3560,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
int rank = m_engine->CreateGroundSpot(); int rank = m_engine->CreateGroundSpot();
if (rank != -1) if (rank != -1)
{ {
m_engine->SetObjectGroundSpotPos(rank, line->GetParam("pos")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f))*g_unit); m_engine->SetObjectGroundSpotPos(rank, line->GetParam("pos")->AsPoint(glm::vec3(0.0f, 0.0f, 0.0f))*g_unit);
m_engine->SetObjectGroundSpotRadius(rank, line->GetParam("radius")->AsFloat(10.0f)*g_unit); m_engine->SetObjectGroundSpotRadius(rank, line->GetParam("radius")->AsFloat(10.0f)*g_unit);
m_engine->SetObjectGroundSpotColor(rank, line->GetParam("color")->AsColor(Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f))); m_engine->SetObjectGroundSpotColor(rank, line->GetParam("color")->AsColor(Gfx::Color(0.533f, 0.533f, 0.533f, 0.533f)));
m_engine->SetObjectGroundSpotSmooth(rank, line->GetParam("smooth")->AsFloat(1.0f)); m_engine->SetObjectGroundSpotSmooth(rank, line->GetParam("smooth")->AsFloat(1.0f));
@ -3585,9 +3585,9 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
m_mapImage = line->GetParam("image")->AsBool(false); m_mapImage = line->GetParam("image")->AsBool(false);
if (m_mapImage) if (m_mapImage)
{ {
Math::Vector offset; glm::vec3 offset;
strcpy(m_mapFilename, line->GetParam("filename")->AsPath("textures").c_str()); strcpy(m_mapFilename, line->GetParam("filename")->AsPath("textures").c_str());
offset = line->GetParam("offset")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f)); offset = line->GetParam("offset")->AsPoint(glm::vec3(0.0f, 0.0f, 0.0f));
m_map->SetFixParam(line->GetParam("zoom")->AsFloat(1.0f), m_map->SetFixParam(line->GetParam("zoom")->AsFloat(1.0f),
offset.x, offset.z, offset.x, offset.z,
line->GetParam("angle")->AsFloat(0.0f)*Math::PI/180.0f, line->GetParam("angle")->AsFloat(0.0f)*Math::PI/180.0f,
@ -3621,12 +3621,12 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
if (line->GetCommand() == "Camera") if (line->GetCommand() == "Camera")
{ {
m_camera->Init(line->GetParam("eye")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f))*g_unit, m_camera->Init(line->GetParam("eye")->AsPoint(glm::vec3(0.0f, 0.0f, 0.0f))*g_unit,
line->GetParam("lookat")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f))*g_unit, line->GetParam("lookat")->AsPoint(glm::vec3(0.0f, 0.0f, 0.0f))*g_unit,
resetObject ? 0.0f : line->GetParam("delay")->AsFloat(0.0f)); resetObject ? 0.0f : line->GetParam("delay")->AsFloat(0.0f));
if (line->GetParam("fadeIn")->AsBool(false)) if (line->GetParam("fadeIn")->AsBool(false))
m_camera->StartOver(Gfx::CAM_OVER_EFFECT_FADEIN_WHITE, Math::Vector(0.0f, 0.0f, 0.0f), 1.0f); m_camera->StartOver(Gfx::CAM_OVER_EFFECT_FADEIN_WHITE, glm::vec3(0.0f, 0.0f, 0.0f), 1.0f);
continue; continue;
} }
@ -3865,7 +3865,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
if (!m_sceneReadPath.empty() && sel != nullptr) // loading file? if (!m_sceneReadPath.empty() && sel != nullptr) // loading file?
{ {
Math::Vector pos = sel->GetPosition(); glm::vec3 pos = sel->GetPosition();
m_camera->Init(pos, pos, 0.0f); m_camera->Init(pos, pos, 0.0f);
SelectObject(sel); SelectObject(sel);
@ -3903,7 +3903,7 @@ void CRobotMain::LevelLoadingError(const std::string& error, const std::runtime_
} }
//! Creates a directional light //! Creates a directional light
int CRobotMain::CreateLight(Math::Vector direction, Gfx::Color color) int CRobotMain::CreateLight(glm::vec3 direction, Gfx::Color color)
{ {
if (direction.x == 0.0f && if (direction.x == 0.0f &&
direction.y == 0.0f && direction.y == 0.0f &&
@ -3924,7 +3924,7 @@ int CRobotMain::CreateLight(Math::Vector direction, Gfx::Color color)
} }
//! Creates a light spot //! Creates a light spot
int CRobotMain::CreateSpot(Math::Vector pos, Gfx::Color color) int CRobotMain::CreateSpot(glm::vec3 pos, Gfx::Color color)
{ {
if (!m_engine->GetLightMode()) return -1; if (!m_engine->GetLightMode()) return -1;
@ -3935,7 +3935,7 @@ int CRobotMain::CreateSpot(Math::Vector pos, Gfx::Color color)
light.diffuse = color; light.diffuse = color;
light.ambient = color * 0.1f; light.ambient = color * 0.1f;
light.position = pos; light.position = pos;
light.direction = Math::Vector(0.0f, -1.0f, 0.0f); light.direction = glm::vec3(0.0f, -1.0f, 0.0f);
light.spotIntensity = 1.0f; light.spotIntensity = 1.0f;
light.spotAngle = 90.0f*Math::PI/180.0f; light.spotAngle = 90.0f*Math::PI/180.0f;
light.attenuation0 = 2.0f; light.attenuation0 = 2.0f;
@ -4105,7 +4105,7 @@ void CRobotMain::ChangeColor()
//! Calculates the distance to the nearest object //! Calculates the distance to the nearest object
namespace namespace
{ {
float SearchNearestObject(CObjectManager* objMan, Math::Vector center, CObject* exclu) float SearchNearestObject(CObjectManager* objMan, glm::vec3 center, CObject* exclu)
{ {
float min = 100000.0f; float min = 100000.0f;
for (CObject* obj : objMan->GetAllObjects()) for (CObject* obj : objMan->GetAllObjects())
@ -4119,7 +4119,7 @@ float SearchNearestObject(CObjectManager* objMan, Math::Vector center, CObject*
if (type == OBJECT_BASE) if (type == OBJECT_BASE)
{ {
Math::Vector oPos = obj->GetPosition(); glm::vec3 oPos = obj->GetPosition();
if (oPos.x != center.x || if (oPos.x != center.x ||
oPos.z != center.z) oPos.z != center.z)
{ {
@ -4134,7 +4134,7 @@ float SearchNearestObject(CObjectManager* objMan, Math::Vector center, CObject*
type == OBJECT_REPAIR || type == OBJECT_REPAIR ||
type == OBJECT_DESTROYER) type == OBJECT_DESTROYER)
{ {
Math::Vector oPos = obj->GetPosition(); glm::vec3 oPos = obj->GetPosition();
float dist = Math::Distance(center, oPos) - 8.0f; float dist = Math::Distance(center, oPos) - 8.0f;
if (dist < 0.0f) dist = 0.0f; if (dist < 0.0f) dist = 0.0f;
min = Math::Min(min, dist); min = Math::Min(min, dist);
@ -4142,7 +4142,7 @@ float SearchNearestObject(CObjectManager* objMan, Math::Vector center, CObject*
for (const auto &crashSphere : obj->GetAllCrashSpheres()) for (const auto &crashSphere : obj->GetAllCrashSpheres())
{ {
Math::Vector oPos = crashSphere.sphere.pos; glm::vec3 oPos = crashSphere.sphere.pos;
float oRadius = crashSphere.sphere.radius; float oRadius = crashSphere.sphere.radius;
float dist = Math::Distance(center, oPos) - oRadius; float dist = Math::Distance(center, oPos) - oRadius;
@ -4155,7 +4155,7 @@ float SearchNearestObject(CObjectManager* objMan, Math::Vector center, CObject*
} }
//! Calculates a free space //! Calculates a free space
bool CRobotMain::FreeSpace(Math::Vector &center, float minRadius, float maxRadius, bool CRobotMain::FreeSpace(glm::vec3 &center, float minRadius, float maxRadius,
float space, CObject *exclu) float space, CObject *exclu)
{ {
if (minRadius < maxRadius) // from internal to external? if (minRadius < maxRadius) // from internal to external?
@ -4169,7 +4169,7 @@ bool CRobotMain::FreeSpace(Math::Vector &center, float minRadius, float maxRadiu
p.x = center.x+radius; p.x = center.x+radius;
p.y = center.z; p.y = center.z;
p = Math::RotatePoint({ center.x, center.z }, angle, p); p = Math::RotatePoint({ center.x, center.z }, angle, p);
Math::Vector pos; glm::vec3 pos;
pos.x = p.x; pos.x = p.x;
pos.z = p.y; pos.z = p.y;
pos.y = 0.0f; pos.y = 0.0f;
@ -4198,7 +4198,7 @@ bool CRobotMain::FreeSpace(Math::Vector &center, float minRadius, float maxRadiu
p.x = center.x+radius; p.x = center.x+radius;
p.y = center.z; p.y = center.z;
p = Math::RotatePoint({ center.x, center.z }, angle, p); p = Math::RotatePoint({ center.x, center.z }, angle, p);
Math::Vector pos; glm::vec3 pos;
pos.x = p.x; pos.x = p.x;
pos.z = p.y; pos.z = p.y;
pos.y = 0.0f; pos.y = 0.0f;
@ -4220,7 +4220,7 @@ bool CRobotMain::FreeSpace(Math::Vector &center, float minRadius, float maxRadiu
} }
//! Calculates a flat free space //! Calculates a flat free space
bool CRobotMain::FlatFreeSpace(Math::Vector &center, float minFlat, float minRadius, float maxRadius, bool CRobotMain::FlatFreeSpace(glm::vec3 &center, float minFlat, float minRadius, float maxRadius,
float space, CObject *exclu) float space, CObject *exclu)
{ {
if (minRadius < maxRadius) // from internal to external? if (minRadius < maxRadius) // from internal to external?
@ -4234,7 +4234,7 @@ bool CRobotMain::FlatFreeSpace(Math::Vector &center, float minFlat, float minRad
p.x = center.x+radius; p.x = center.x+radius;
p.y = center.z; p.y = center.z;
p = Math::RotatePoint({ center.x, center.z }, angle, p); p = Math::RotatePoint({ center.x, center.z }, angle, p);
Math::Vector pos; glm::vec3 pos;
pos.x = p.x; pos.x = p.x;
pos.z = p.y; pos.z = p.y;
pos.y = 0.0f; pos.y = 0.0f;
@ -4267,7 +4267,7 @@ bool CRobotMain::FlatFreeSpace(Math::Vector &center, float minFlat, float minRad
p.x = center.x+radius; p.x = center.x+radius;
p.y = center.z; p.y = center.z;
p = Math::RotatePoint({ center.x, center.z }, angle, p); p = Math::RotatePoint({ center.x, center.z }, angle, p);
Math::Vector pos; glm::vec3 pos;
pos.x = p.x; pos.x = p.x;
pos.z = p.y; pos.z = p.y;
pos.y = 0.0f; pos.y = 0.0f;
@ -4293,7 +4293,7 @@ bool CRobotMain::FlatFreeSpace(Math::Vector &center, float minFlat, float minRad
} }
//! Calculates the maximum radius of a free space //! Calculates the maximum radius of a free space
float CRobotMain::GetFlatZoneRadius(Math::Vector center, float maxRadius, float CRobotMain::GetFlatZoneRadius(glm::vec3 center, float maxRadius,
CObject *exclu) CObject *exclu)
{ {
float dist = SearchNearestObject(m_objMan.get(), center, exclu); float dist = SearchNearestObject(m_objMan.get(), center, exclu);
@ -4326,7 +4326,7 @@ void CRobotMain::ShowDropZone(CObject* metal, CObject* transporter)
{ {
if (metal == nullptr) return; if (metal == nullptr) return;
Math::Vector center = metal->GetPosition(); glm::vec3 center = metal->GetPosition();
// Calculates the maximum radius possible depending on other items. // Calculates the maximum radius possible depending on other items.
float oMax = 30.0f; // radius to build the biggest building float oMax = 30.0f; // radius to build the biggest building
@ -4339,7 +4339,7 @@ void CRobotMain::ShowDropZone(CObject* metal, CObject* transporter)
if (obj == metal) continue; if (obj == metal) continue;
if (obj == transporter) continue; if (obj == transporter) continue;
Math::Vector oPos; glm::vec3 oPos;
ObjectType type = obj->GetType(); ObjectType type = obj->GetType();
if (type == OBJECT_BASE) if (type == OBJECT_BASE)
@ -4413,7 +4413,7 @@ void CRobotMain::FlushShowLimit(int i)
//! Specifies the boundaries to show //! Specifies the boundaries to show
void CRobotMain::SetShowLimit(int i, Gfx::ParticleType parti, CObject *obj, void CRobotMain::SetShowLimit(int i, Gfx::ParticleType parti, CObject *obj,
Math::Vector pos, float radius, float duration) glm::vec3 pos, float radius, float duration)
{ {
FlushShowLimit(i); // erases the current boundaries FlushShowLimit(i); // erases the current boundaries
@ -4443,7 +4443,7 @@ void CRobotMain::SetShowLimit(int i, Gfx::ParticleType parti, CObject *obj,
for (int j = 0; j < m_showLimit[i].total; j++) for (int j = 0; j < m_showLimit[i].total; j++)
{ {
m_showLimit[i].parti[j] = m_particle->CreateParticle(pos, Math::Vector(0.0f, 0.0f, 0.0f), dim, parti, duration); m_showLimit[i].parti[j] = m_particle->CreateParticle(pos, glm::vec3(0.0f, 0.0f, 0.0f), dim, parti, duration);
} }
} }
@ -4504,7 +4504,7 @@ void CRobotMain::FrameShowLimit(float rTime)
rotate.y = center.y; rotate.y = center.y;
rotate = Math::RotatePoint(center, angle, rotate); rotate = Math::RotatePoint(center, angle, rotate);
Math::Vector pos; glm::vec3 pos;
pos.x = rotate.x; pos.x = rotate.x;
pos.z = rotate.y; pos.z = rotate.y;
pos.y = 0.0f; pos.y = 0.0f;
@ -4845,7 +4845,7 @@ bool CRobotMain::IOWriteScene(std::string filename, std::string filecbot, std::s
//! Notifies the user that scene write is finished //! Notifies the user that scene write is finished
void CRobotMain::IOWriteSceneFinished() void CRobotMain::IOWriteSceneFinished()
{ {
m_displayText->DisplayError(INFO_WRITEOK, Math::Vector(0.0f,0.0f,0.0f)); m_displayText->DisplayError(INFO_WRITEOK, glm::vec3(0.0f,0.0f,0.0f));
m_shotSaving--; m_shotSaving--;
} }
@ -5246,7 +5246,7 @@ Error CRobotMain::ProcessEndMissionTake()
std::string text; std::string text;
GetResource(RES_ERR, INFO_TEAM_DEAD, text); GetResource(RES_ERR, INFO_TEAM_DEAD, text);
text = StrUtils::Format(text.c_str(), GetTeamName(team).c_str()); text = StrUtils::Format(text.c_str(), GetTeamName(team).c_str());
m_displayText->DisplayText(text.c_str(), Math::Vector(0.0f,0.0f,0.0f), 15.0f, 60.0f, 10.0f, Ui::TT_ERROR); m_displayText->DisplayText(text.c_str(), glm::vec3(0.0f,0.0f,0.0f), 15.0f, 60.0f, 10.0f, Ui::TT_ERROR);
m_displayText->SetEnable(false); // To prevent "bot destroyed" messages m_displayText->SetEnable(false); // To prevent "bot destroyed" messages
m_objMan->DestroyTeam(team); m_objMan->DestroyTeam(team);
@ -5260,11 +5260,11 @@ Error CRobotMain::ProcessEndMissionTake()
{ {
GetLogger()->Info("Team %d won\n", team); GetLogger()->Info("Team %d won\n", team);
m_displayText->DisplayText(("<<< Team "+boost::lexical_cast<std::string>(team)+" won the game >>>").c_str(), Math::Vector(0.0f,0.0f,0.0f)); m_displayText->DisplayText(("<<< Team "+boost::lexical_cast<std::string>(team)+" won the game >>>").c_str(), glm::vec3(0.0f,0.0f,0.0f));
if (m_missionTimerEnabled && m_missionTimerStarted) if (m_missionTimerEnabled && m_missionTimerStarted)
{ {
GetLogger()->Info("Mission time: %s\n", TimeFormat(m_missionTimer).c_str()); GetLogger()->Info("Mission time: %s\n", TimeFormat(m_missionTimer).c_str());
m_displayText->DisplayText(("Time: " + TimeFormat(m_missionTimer)).c_str(), Math::Vector(0.0f,0.0f,0.0f)); m_displayText->DisplayText(("Time: " + TimeFormat(m_missionTimer)).c_str(), glm::vec3(0.0f,0.0f,0.0f));
} }
m_missionTimerEnabled = m_missionTimerStarted = false; m_missionTimerEnabled = m_missionTimerStarted = false;
m_winDelay = m_endTakeWinDelay; // wins in two seconds m_winDelay = m_endTakeWinDelay; // wins in two seconds
@ -5277,7 +5277,7 @@ Error CRobotMain::ProcessEndMissionTake()
std::string text; std::string text;
GetResource(RES_ERR, INFO_TEAM_FINISH, text); GetResource(RES_ERR, INFO_TEAM_FINISH, text);
text = StrUtils::Format(text.c_str(), GetTeamName(team).c_str()); text = StrUtils::Format(text.c_str(), GetTeamName(team).c_str());
m_displayText->DisplayText(text.c_str(), Math::Vector(0.0f,0.0f,0.0f)); m_displayText->DisplayText(text.c_str(), glm::vec3(0.0f,0.0f,0.0f));
if (m_scoreboard) if (m_scoreboard)
m_scoreboard->ProcessEndTake(team); m_scoreboard->ProcessEndTake(team);
m_objMan->DestroyTeam(team, DestructionType::Win); m_objMan->DestroyTeam(team, DestructionType::Win);
@ -5329,7 +5329,7 @@ Error CRobotMain::CheckEndMission(bool frame)
{ {
if (m_lostDelay == 0.0f) if (m_lostDelay == 0.0f)
{ {
m_displayText->DisplayError(INFO_LOST, Math::Vector(0.0f,0.0f,0.0f)); m_displayText->DisplayError(INFO_LOST, glm::vec3(0.0f,0.0f,0.0f));
m_lostDelay = m_endTakeLostDelay; // lost in 6 seconds m_lostDelay = m_endTakeLostDelay; // lost in 6 seconds
m_winDelay = 0.0f; m_winDelay = 0.0f;
} }
@ -5361,11 +5361,11 @@ Error CRobotMain::CheckEndMission(bool frame)
if (m_winDelay == 0.0f) if (m_winDelay == 0.0f)
{ {
m_displayText->DisplayError(INFO_WIN, Math::Vector(0.0f,0.0f,0.0f)); m_displayText->DisplayError(INFO_WIN, glm::vec3(0.0f,0.0f,0.0f));
if (m_missionTimerEnabled && m_missionTimerStarted) if (m_missionTimerEnabled && m_missionTimerStarted)
{ {
GetLogger()->Info("Mission time: %s\n", TimeFormat(m_missionTimer).c_str()); GetLogger()->Info("Mission time: %s\n", TimeFormat(m_missionTimer).c_str());
m_displayText->DisplayText(("Time: " + TimeFormat(m_missionTimer)).c_str(), Math::Vector(0.0f,0.0f,0.0f)); m_displayText->DisplayText(("Time: " + TimeFormat(m_missionTimer)).c_str(), glm::vec3(0.0f,0.0f,0.0f));
} }
m_missionTimerEnabled = m_missionTimerStarted = false; m_missionTimerEnabled = m_missionTimerStarted = false;
m_winDelay = m_endTakeWinDelay; // wins in two seconds m_winDelay = m_endTakeWinDelay; // wins in two seconds
@ -5712,7 +5712,7 @@ void CRobotMain::DisplayError(Error err, CObject* pObj, float time)
m_displayText->DisplayError(err, pObj, time); m_displayText->DisplayError(err, pObj, time);
} }
void CRobotMain::DisplayError(Error err, Math::Vector goal, float height, float dist, float time) void CRobotMain::DisplayError(Error err, glm::vec3 goal, float height, float dist, float time)
{ {
m_displayText->DisplayError(err, goal, height, dist, time); m_displayText->DisplayError(err, goal, height, dist, time);
} }
@ -5840,7 +5840,7 @@ void CRobotMain::QuickLoad()
std::string dir = m_playerProfile->GetSaveFile(std::string("quicksave")); std::string dir = m_playerProfile->GetSaveFile(std::string("quicksave"));
if(!CResourceManager::Exists(dir)) if(!CResourceManager::Exists(dir))
{ {
m_displayText->DisplayError(ERR_NO_QUICK_SLOT, Math::Vector(0.0f,0.0f,0.0f), 15.0f, 60.0f, 1000.0f); m_displayText->DisplayError(ERR_NO_QUICK_SLOT, glm::vec3(0.0f,0.0f,0.0f), 15.0f, 60.0f, 1000.0f);
GetLogger()->Debug("Quicksave slot not found\n"); GetLogger()->Debug("Quicksave slot not found\n");
return; return;
} }
@ -6051,15 +6051,15 @@ float CRobotMain::GetGlobalCellCapacity()
void CRobotMain::StartDetectEffect(COldObject* object, CObject* target) void CRobotMain::StartDetectEffect(COldObject* object, CObject* target)
{ {
Math::Matrix* mat; Math::Matrix* mat;
Math::Vector pos, goal; glm::vec3 pos, goal;
glm::vec2 dim; glm::vec2 dim;
mat = object->GetWorldMatrix(0); mat = object->GetWorldMatrix(0);
pos = Math::Transform(*mat, Math::Vector(2.0f, 3.0f, 0.0f)); pos = Math::Transform(*mat, glm::vec3(2.0f, 3.0f, 0.0f));
if ( target == nullptr ) if ( target == nullptr )
{ {
goal = Math::Transform(*mat, Math::Vector(50.0f, 3.0f, 0.0f)); goal = Math::Transform(*mat, glm::vec3(50.0f, 3.0f, 0.0f));
} }
else else
{ {
@ -6079,7 +6079,7 @@ void CRobotMain::StartDetectEffect(COldObject* object, CObject* target)
goal = Math::SegmentPoint(pos, goal, Math::Distance(pos, goal)-1.0f); goal = Math::SegmentPoint(pos, goal, Math::Distance(pos, goal)-1.0f);
dim.x = 6.0f; dim.x = 6.0f;
dim.y = dim.x; dim.y = dim.x;
m_particle->CreateParticle(goal, Math::Vector(0.0f, 0.0f, 0.0f), dim, m_particle->CreateParticle(goal, glm::vec3(0.0f, 0.0f, 0.0f), dim,
target != nullptr ? Gfx::PARTIGLINT : Gfx::PARTIGLINTr, 0.5f); target != nullptr ? Gfx::PARTIGLINT : Gfx::PARTIGLINTr, 0.5f);
} }

View File

@ -46,6 +46,8 @@
#include <deque> #include <deque>
#include <stdexcept> #include <stdexcept>
#include <glm/glm.hpp>
enum Phase enum Phase
{ {
PHASE_WELCOME1, PHASE_WELCOME1,
@ -136,7 +138,7 @@ const int MAXSCENE = 999;
struct ShowLimit struct ShowLimit
{ {
bool used = false; bool used = false;
Math::Vector pos; glm::vec3 pos;
float radius = 0.0f; float radius = 0.0f;
int total = 0; int total = 0;
int parti[MAXSHOWPARTI] = {}; int parti[MAXSHOWPARTI] = {};
@ -153,8 +155,8 @@ struct MinMax
struct Viewpoint struct Viewpoint
{ {
Math::Vector eye{}; glm::vec3 eye{};
Math::Vector look{}; glm::vec3 look{};
int button = 13; // 13 is the camera button int button = 13; // 13 is the camera button
}; };
@ -295,15 +297,15 @@ public:
void ClearInterface(); void ClearInterface();
void ChangeColor(); void ChangeColor();
bool FreeSpace(Math::Vector &center, float minRadius, float maxRadius, float space, CObject *exclu); bool FreeSpace(glm::vec3 &center, float minRadius, float maxRadius, float space, CObject *exclu);
bool FlatFreeSpace(Math::Vector &center, float minFlat, float minRadius, float maxRadius, float space, CObject *exclu); bool FlatFreeSpace(glm::vec3 &center, float minFlat, float minRadius, float maxRadius, float space, CObject *exclu);
//! \name In-world indicators //! \name In-world indicators
//@{ //@{
float GetFlatZoneRadius(Math::Vector center, float maxRadius, CObject *exclu); float GetFlatZoneRadius(glm::vec3 center, float maxRadius, CObject *exclu);
void HideDropZone(CObject* metal); void HideDropZone(CObject* metal);
void ShowDropZone(CObject* metal, CObject* transporter); void ShowDropZone(CObject* metal, CObject* transporter);
void FlushShowLimit(int i); void FlushShowLimit(int i);
void SetShowLimit(int i, Gfx::ParticleType parti, CObject *obj, Math::Vector pos, void SetShowLimit(int i, Gfx::ParticleType parti, CObject *obj, glm::vec3 pos,
float radius, float duration=SHOWLIMITTIME); float radius, float duration=SHOWLIMITTIME);
void StartShowLimit(); void StartShowLimit();
void FrameShowLimit(float rTime); void FrameShowLimit(float rTime);
@ -336,13 +338,13 @@ public:
CObject* IOReadObject(CLevelParserLine *line, const std::string& programDir, const std::string& objCounterText, float objectProgress, int objRank = -1); CObject* IOReadObject(CLevelParserLine *line, const std::string& programDir, const std::string& objCounterText, float objectProgress, int objRank = -1);
//@} //@}
int CreateSpot(Math::Vector pos, Gfx::Color color); int CreateSpot(glm::vec3 pos, Gfx::Color color);
//! Find the currently selected object //! Find the currently selected object
CObject* GetSelect(); CObject* GetSelect();
void DisplayError(Error err, CObject* pObj, float time=10.0f); void DisplayError(Error err, CObject* pObj, float time=10.0f);
void DisplayError(Error err, Math::Vector goal, float height=15.0f, float dist=60.0f, float time=10.0f); void DisplayError(Error err, glm::vec3 goal, float height=15.0f, float dist=60.0f, float time=10.0f);
void UpdateCustomLevelList(); void UpdateCustomLevelList();
std::string GetCustomLevelName(int id); std::string GetCustomLevelName(int id);
@ -499,7 +501,7 @@ protected:
void LevelLoadingError(const std::string& error, const std::runtime_error& exception, Phase exitPhase = PHASE_LEVEL_LIST); void LevelLoadingError(const std::string& error, const std::runtime_error& exception, Phase exitPhase = PHASE_LEVEL_LIST);
int CreateLight(Math::Vector direction, Gfx::Color color); int CreateLight(glm::vec3 direction, Gfx::Color color);
void HiliteClear(); void HiliteClear();
void HiliteObject(const glm::vec2& pos); void HiliteObject(const glm::vec2& pos);
void HiliteFrame(float rTime); void HiliteFrame(float rTime);
@ -676,8 +678,8 @@ protected:
CObject* m_visitArrow = nullptr; CObject* m_visitArrow = nullptr;
float m_visitTime = 0.0f; float m_visitTime = 0.0f;
float m_visitParticle = 0.0f; float m_visitParticle = 0.0f;
Math::Vector m_visitPos; glm::vec3 m_visitPos;
Math::Vector m_visitPosArrow; glm::vec3 m_visitPosArrow;
ActivePause* m_visitPause = nullptr; ActivePause* m_visitPause = nullptr;
std::vector<std::unique_ptr<CSceneEndCondition>> m_endTake; std::vector<std::unique_ptr<CSceneEndCondition>> m_endTake;

View File

@ -271,7 +271,7 @@ inline void LoadViewMatrix(Math::Matrix &mat, const Math::Vector &from,
// difference from the eyepoint to the lookat point. // difference from the eyepoint to the lookat point.
Math::Vector view = at - from; Math::Vector view = at - from;
float length = view.Length(); float length = glm::length(view);
assert(! IsZero(length) ); assert(! IsZero(length) );
// Normalize the z basis vector // Normalize the z basis vector
@ -285,16 +285,16 @@ inline void LoadViewMatrix(Math::Matrix &mat, const Math::Vector &from,
// If this vector has near-zero length because the input specified a // If this vector has near-zero length because the input specified a
// bogus up vector, let's try a default up vector // bogus up vector, let's try a default up vector
if ( IsZero(length = up.Length()) ) if ( IsZero(length = glm::length(up)) )
{ {
up = Math::Vector(0.0f, 1.0f, 0.0f) - view.y * view; up = Math::Vector(0.0f, 1.0f, 0.0f) - view.y * view;
// If we still have near-zero length, resort to a different axis. // If we still have near-zero length, resort to a different axis.
if ( IsZero(length = up.Length()) ) if ( IsZero(length = glm::length(up)) )
{ {
up = Math::Vector(0.0f, 0.0f, 1.0f) - view.z * view; up = Math::Vector(0.0f, 0.0f, 1.0f) - view.z * view;
assert(! IsZero(up.Length()) ); assert(! IsZero(glm::length(up)) );
} }
} }
@ -518,9 +518,7 @@ inline Math::Vector NormalToPlane(const Math::Vector &p1, const Math::Vector &p2
*/ */
inline Math::Vector SegmentPoint(const Math::Vector &p1, const Math::Vector &p2, float dist) inline Math::Vector SegmentPoint(const Math::Vector &p1, const Math::Vector &p2, float dist)
{ {
Math::Vector direction = p2 - p1; Math::Vector direction = glm::normalize(p2 - p1);
direction.Normalize();
return p1 + direction * dist; return p1 + direction * dist;
} }

View File

@ -48,7 +48,7 @@ inline Sphere BoundingSphereForBox(Vector mins, Vector maxs)
{ {
auto centroid = (maxs + mins) / 2.0f; auto centroid = (maxs + mins) / 2.0f;
auto halfExtent = (maxs - centroid); auto halfExtent = (maxs - centroid);
return Sphere{centroid, halfExtent.Length()}; return Sphere{centroid, glm::length(halfExtent)};
} }
} // namespace Math } // namespace Math

View File

@ -38,212 +38,10 @@ namespace Math
{ {
/** using Vector = glm::vec3;
* \struct Vector
* \brief 3D (3x1) vector
*
* Represents a universal 3x1 vector that can be used in OpenGL and DirectX engines.
* Contains the required methods for operating on vectors.
*
* All methods are made inline to maximize optimization.
*
* Unit tests for the structure and related functions are in module: math/test/vector_test.cpp.
*
*/
struct Vector
{
//! X - 1st coord
float x;
//! Y - 2nd coord
float y;
//! Z - 3rd coord
float z;
//! Creates a zero vector (0, 0, 0)
inline Vector()
: x(0.0f)
, y(0.0f)
, z(0.0f)
{}
//! Creates a vector from given values
inline explicit Vector(float _x, float _y, float _z)
: x(_x)
, y(_y)
, z(_z)
{}
inline Vector(const glm::vec3& vector)
: x(vector.x)
, y(vector.y)
, z(vector.z)
{}
//! Loads the zero vector (0, 0, 0)
inline void LoadZero()
{
x = y = z = 0.0f;
}
//! Returns the struct cast to \c float* array; use with care!
inline float* Array()
{
return reinterpret_cast<float*>(this);
}
//! Returns the struct cast to <tt>const float*</tt> array; use with care!
inline const float* Array() const
{
return reinterpret_cast<const float*>(this);
}
operator glm::vec3() const
{
return { x, y, z };
}
//! Returns the vector length
inline float Length() const
{
return sqrtf(x*x + y*y + z*z);
}
//! Normalizes the vector
inline void Normalize()
{
float l = Length();
if (IsZero(l))
return;
x /= l;
y /= l;
z /= l;
}
//! Calculates the cross product with another vector
/**
* \param right right-hand side vector
* \returns the cross product
*/
inline Vector CrossMultiply(const Vector &right) const
{
float px = y * right.z - z * right.y;
float py = z * right.x - x * right.z;
float pz = x * right.y - y * right.x;
return Vector(px, py, pz);
}
//! Calculates the dot product with another vector
/**
* \param right right-hand side vector
* \returns the dot product
*/
inline float DotMultiply(const Vector &right) const
{
return x * right.x + y * right.y + z * right.z;
}
//! Returns the cosine of angle between this and another vector
inline float CosAngle(const Vector &right) const
{
return DotMultiply(right) / (Length() * right.Length());
}
//! Returns angle (in radians) between this and another vector
inline float Angle(const Vector &right) const
{
return acos(CosAngle(right));
}
/* Operators */
//! Returns the inverted vector
inline Vector operator-() const
{
return Vector(-x, -y, -z);
}
//! Adds the given vector
inline const Vector& operator+=(const Vector &right)
{
x += right.x;
y += right.y;
z += right.z;
return *this;
}
//! Adds two vectors
inline friend const Vector operator+(const Vector &left, const Vector &right)
{
return Vector(left.x + right.x, left.y + right.y, left.z + right.z);
}
//! Subtracts the given vector
inline const Vector& operator-=(const Vector &right)
{
x -= right.x;
y -= right.y;
z -= right.z;
return *this;
}
//! Subtracts two vectors
inline friend const Vector operator-(const Vector &left, const Vector &right)
{
return Vector(left.x - right.x, left.y - right.y, left.z - right.z);
}
//! Multiplies by given scalar
inline const Vector& operator*=(const float &right)
{
x *= right;
y *= right;
z *= right;
return *this;
}
//! Multiplies vector by scalar
inline friend const Vector operator*(const float &left, const Vector &right)
{
return Vector(left * right.x, left * right.y, left * right.z);
}
//! Multiplies vector by scalar
inline friend const Vector operator*(const Vector &left, const float &right)
{
return Vector(left.x * right, left.y * right, left.z * right);
}
//! Divides by given scalar
inline const Vector& operator/=(const float &right)
{
x /= right;
y /= right;
z /= right;
return *this;
}
//! Divides vector by scalar
inline friend const Vector operator/(const Vector &left, const float &right)
{
return Vector(left.x / right, left.y / right, left.z / right);
}
//! Returns a string "[x, y, z]"
inline std::string ToString() const
{
std::stringstream s;
s.precision(3);
s << "[" << x << ", " << y << ", " << z << "]";
return s.str();
}
}; // struct Vector
//! Checks if two vectors are equal within given \a tolerance //! Checks if two vectors are equal within given \a tolerance
inline bool VectorsEqual(const Math::Vector &a, const Math::Vector &b, float tolerance = TOLERANCE) inline bool VectorsEqual(const glm::vec3 &a, const glm::vec3 &b, float tolerance = TOLERANCE)
{ {
return IsEqual(a.x, b.x, tolerance) return IsEqual(a.x, b.x, tolerance)
&& IsEqual(a.y, b.y, tolerance) && IsEqual(a.y, b.y, tolerance)
@ -251,47 +49,47 @@ inline bool VectorsEqual(const Math::Vector &a, const Math::Vector &b, float tol
} }
//! Convenience function for getting normalized vector //! Convenience function for getting normalized vector
inline Vector Normalize(const Math::Vector &v) inline Vector Normalize(const glm::vec3 &v)
{ {
Vector result = v; return glm::normalize(v);
result.Normalize();
return result;
} }
//! Convenience function for calculating dot product //! Convenience function for calculating dot product
inline float DotProduct(const Math::Vector &left, const Math::Vector &right) inline float DotProduct(const glm::vec3 &left, const glm::vec3 &right)
{ {
return left.DotMultiply(right); return glm::dot(left, right);
} }
//! Convenience function for calculating cross product //! Convenience function for calculating cross product
inline Vector CrossProduct(const Math::Vector &left, const Math::Vector &right) inline Vector CrossProduct(const glm::vec3 &left, const glm::vec3 &right)
{ {
return left.CrossMultiply(right); return glm::cross(left, right);
} }
//! Convenience function for calculating angle (in radians) between two vectors //! Convenience function for calculating angle (in radians) between two vectors
inline float Angle(const Math::Vector &a, const Math::Vector &b) inline float Angle(const glm::vec3 &a, const glm::vec3 &b)
{ {
return a.Angle(b); return std::acosf(glm::dot(a, b) / (glm::length(a) * glm::length(b)));
} }
//! Returns the distance between the ends of two vectors //! Returns the distance between the ends of two vectors
inline float Distance(const Math::Vector &a, const Math::Vector &b) inline float Distance(const glm::vec3 &a, const glm::vec3 &b)
{ {
return sqrtf( (a.x-b.x)*(a.x-b.x) + return glm::distance(a, b);
(a.y-b.y)*(a.y-b.y) +
(a.z-b.z)*(a.z-b.z) );
} }
//! Clamps the vector \a vec to range between \a min and \a max //! Clamps the vector \a vec to range between \a min and \a max
inline Vector Clamp(const Vector &vec, const Vector &min, const Vector &max) inline Vector Clamp(const Vector &vec, const Vector &min, const Vector &max)
{ {
Vector clamped; return glm::clamp(vec, min, max);
clamped.x = Min(Max(min.x, vec.x), max.x); }
clamped.y = Min(Max(min.y, vec.y), max.y);
clamped.z = Min(Max(min.z, vec.z), max.z); inline std::string ToString(const Vector& vector)
return clamped; {
std::stringstream s;
s.precision(3);
s << "[" << vector.x << ", " << vector.y << ", " << vector.z << "]";
return s.str();
} }

View File

@ -64,7 +64,7 @@ void CAutoFlag::Init()
angle = Math::RotateAngle(wind.x, -wind.z); angle = Math::RotateAngle(wind.x, -wind.z);
m_object->SetRotationY(angle); // directs the flag in the wind m_object->SetRotationY(angle); // directs the flag in the wind
m_strong = wind.Length(); m_strong = glm::length(wind);
} }

View File

@ -400,7 +400,7 @@ bool CMotionToto::EventFrame(const Event &event)
//? shift *= focus; //? shift *= focus;
verti /= focus; verti /= focus;
dir = Normalize(lookat-eye); dir = glm::normalize(lookat-eye);
nPos = eye + dir*distance; nPos = eye + dir*distance;
perp.x = -dir.z; perp.x = -dir.z;

View File

@ -141,23 +141,23 @@ bool CObject::CanCollideWith(CObject* other)
return true; return true;
} }
Math::Vector CObject::GetPosition() const glm::vec3 CObject::GetPosition() const
{ {
return m_position; return m_position;
} }
void CObject::SetPosition(const Math::Vector& pos) void CObject::SetPosition(const glm::vec3& pos)
{ {
// TODO: provide default implementation... // TODO: provide default implementation...
throw std::logic_error("CObject::SetPosition() - not implemented!"); throw std::logic_error("CObject::SetPosition() - not implemented!");
} }
Math::Vector CObject::GetRotation() const glm::vec3 CObject::GetRotation() const
{ {
return m_rotation; return m_rotation;
} }
void CObject::SetRotation(const Math::Vector& rotation) void CObject::SetRotation(const glm::vec3& rotation)
{ {
// TODO: provide default implementation... // TODO: provide default implementation...
throw std::logic_error("CObject::SetRotation() - not implemented!"); throw std::logic_error("CObject::SetRotation() - not implemented!");
@ -165,21 +165,21 @@ void CObject::SetRotation(const Math::Vector& rotation)
void CObject::SetRotationX(float angle) void CObject::SetRotationX(float angle)
{ {
Math::Vector rotation = GetRotation(); glm::vec3 rotation = GetRotation();
rotation.x = angle; rotation.x = angle;
return SetRotation(rotation); return SetRotation(rotation);
} }
void CObject::SetRotationY(float angle) void CObject::SetRotationY(float angle)
{ {
Math::Vector rotation = GetRotation(); glm::vec3 rotation = GetRotation();
rotation.y = angle; rotation.y = angle;
return SetRotation(rotation); return SetRotation(rotation);
} }
void CObject::SetRotationZ(float angle) void CObject::SetRotationZ(float angle)
{ {
Math::Vector rotation = GetRotation(); glm::vec3 rotation = GetRotation();
rotation.z = angle; rotation.z = angle;
return SetRotation(rotation); return SetRotation(rotation);
} }
@ -199,12 +199,12 @@ float CObject::GetRotationZ()
return GetRotation().z; return GetRotation().z;
} }
Math::Vector CObject::GetScale() const glm::vec3 CObject::GetScale() const
{ {
return m_scale; return m_scale;
} }
void CObject::SetScale(const Math::Vector& scale) void CObject::SetScale(const glm::vec3& scale)
{ {
// TODO: provide default implementation... // TODO: provide default implementation...
throw std::logic_error("CObject::SetScale() - not implemented!"); throw std::logic_error("CObject::SetScale() - not implemented!");
@ -212,26 +212,26 @@ void CObject::SetScale(const Math::Vector& scale)
void CObject::SetScale(float scale) void CObject::SetScale(float scale)
{ {
SetScale(Math::Vector(scale, scale, scale)); SetScale(glm::vec3(scale, scale, scale));
} }
void CObject::SetScaleX(float angle) void CObject::SetScaleX(float angle)
{ {
Math::Vector scale = GetScale(); glm::vec3 scale = GetScale();
scale.x = angle; scale.x = angle;
return SetScale(scale); return SetScale(scale);
} }
void CObject::SetScaleY(float angle) void CObject::SetScaleY(float angle)
{ {
Math::Vector scale = GetScale(); glm::vec3 scale = GetScale();
scale.y = angle; scale.y = angle;
return SetScale(scale); return SetScale(scale);
} }
void CObject::SetScaleZ(float angle) void CObject::SetScaleZ(float angle)
{ {
Math::Vector scale = GetScale(); glm::vec3 scale = GetScale();
scale.z = angle; scale.z = angle;
return SetScale(scale); return SetScale(scale);
} }

View File

@ -100,16 +100,16 @@ public:
} }
//! Returns object's position //! Returns object's position
virtual Math::Vector GetPosition() const; virtual glm::vec3 GetPosition() const;
//! Sets object's position //! Sets object's position
virtual void SetPosition(const Math::Vector& pos); virtual void SetPosition(const glm::vec3& pos);
//! Returns object's rotation (Euler angles) //! Returns object's rotation (Euler angles)
/** Angles are given in radians */ /** Angles are given in radians */
virtual Math::Vector GetRotation() const; virtual glm::vec3 GetRotation() const;
//! Sets object's rotation (Euler angles) //! Sets object's rotation (Euler angles)
/** Angles are given in radians */ /** Angles are given in radians */
virtual void SetRotation(const Math::Vector& rotation); virtual void SetRotation(const glm::vec3& rotation);
//!@{ //!@{
//! Shortcuts for rotation components //! Shortcuts for rotation components
@ -122,9 +122,9 @@ public:
//!@} //!@}
//! Returns object's scale //! Returns object's scale
virtual Math::Vector GetScale() const; virtual glm::vec3 GetScale() const;
//! Sets objects's scale //! Sets objects's scale
virtual void SetScale(const Math::Vector& scale); virtual void SetScale(const glm::vec3& scale);
//! Sets objects's scale (uniform value) //! Sets objects's scale (uniform value)
void SetScale(float scale); void SetScale(float scale);
@ -221,9 +221,9 @@ protected:
const int m_id; //!< unique identifier const int m_id; //!< unique identifier
ObjectType m_type; //!< object type ObjectType m_type; //!< object type
ObjectInterfaceTypes m_implementedInterfaces; //!< interfaces that the object implements ObjectInterfaceTypes m_implementedInterfaces; //!< interfaces that the object implements
Math::Vector m_position; glm::vec3 m_position{ 0, 0, 0 };
Math::Vector m_rotation; glm::vec3 m_rotation{ 0, 0, 0 };
Math::Vector m_scale; glm::vec3 m_scale{ 0, 0, 0 };
std::vector<CrashSphere> m_crashSpheres; //!< crash spheres std::vector<CrashSphere> m_crashSpheres; //!< crash spheres
Math::Sphere m_cameraCollisionSphere; Math::Sphere m_cameraCollisionSphere;
bool m_animateOnReset; bool m_animateOnReset;

View File

@ -25,7 +25,7 @@
struct ObjectCreateParams struct ObjectCreateParams
{ {
Math::Vector pos; glm::vec3 pos;
float angle; float angle;
ObjectType type; ObjectType type;
float power; float power;
@ -38,7 +38,7 @@ struct ObjectCreateParams
ObjectCreateParams() ObjectCreateParams()
{ {
pos = Math::Vector(0.0f, 0.0f, 0.0f); pos = glm::vec3(0.0f, 0.0f, 0.0f);
angle = 0.0f; angle = 0.0f;
type = OBJECT_NULL; type = OBJECT_NULL;
power = -1.0f; power = -1.0f;

View File

@ -158,7 +158,7 @@ CObject* CObjectManager::CreateObject(ObjectCreateParams params)
return objectPtr; return objectPtr;
} }
CObject* CObjectManager::CreateObject(Math::Vector pos, float angle, ObjectType type, float power) CObject* CObjectManager::CreateObject(glm::vec3 pos, float angle, ObjectType type, float power)
{ {
ObjectCreateParams params; ObjectCreateParams params;
params.pos = pos; params.pos = pos;
@ -248,7 +248,7 @@ std::vector<CObject*> CObjectManager::RadarAll(CObject* pThis, ObjectType type,
std::vector<CObject*> CObjectManager::RadarAll(CObject* pThis, std::vector<ObjectType> type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes) std::vector<CObject*> CObjectManager::RadarAll(CObject* pThis, std::vector<ObjectType> type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes)
{ {
Math::Vector iPos; glm::vec3 iPos{};
float iAngle; float iAngle;
if (pThis != nullptr) if (pThis != nullptr)
{ {
@ -258,13 +258,13 @@ std::vector<CObject*> CObjectManager::RadarAll(CObject* pThis, std::vector<Objec
} }
else else
{ {
iPos = Math::Vector(); iPos = glm::vec3(0, 0, 0);
iAngle = 0.0f; iAngle = 0.0f;
} }
return RadarAll(pThis, iPos, iAngle, type, angle, focus, minDist, maxDist, furthest, filter, cbotTypes); return RadarAll(pThis, iPos, iAngle, type, angle, focus, minDist, maxDist, furthest, filter, cbotTypes);
} }
std::vector<CObject*> CObjectManager::RadarAll(CObject* pThis, Math::Vector thisPosition, float thisAngle, ObjectType type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes) std::vector<CObject*> CObjectManager::RadarAll(CObject* pThis, glm::vec3 thisPosition, float thisAngle, ObjectType type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes)
{ {
std::vector<ObjectType> types; std::vector<ObjectType> types;
if (type != OBJECT_NULL) if (type != OBJECT_NULL)
@ -272,10 +272,10 @@ std::vector<CObject*> CObjectManager::RadarAll(CObject* pThis, Math::Vector this
return RadarAll(pThis, thisPosition, thisAngle, types, angle, focus, minDist, maxDist, furthest, filter, cbotTypes); return RadarAll(pThis, thisPosition, thisAngle, types, angle, focus, minDist, maxDist, furthest, filter, cbotTypes);
} }
std::vector<CObject*> CObjectManager::RadarAll(CObject* pThis, Math::Vector thisPosition, float thisAngle, std::vector<ObjectType> type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes) std::vector<CObject*> CObjectManager::RadarAll(CObject* pThis, glm::vec3 thisPosition, float thisAngle, std::vector<ObjectType> type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes)
{ {
CObject *pObj; CObject *pObj;
Math::Vector iPos, oPos; glm::vec3 iPos{ 0, 0, 0 }, oPos{ 0, 0, 0 };
float iAngle, d, a; float iAngle, d, a;
ObjectType oType; ObjectType oType;
@ -432,13 +432,13 @@ CObject* CObjectManager::Radar(CObject* pThis, std::vector<ObjectType> type, flo
return best.size() > 0 ? best[0] : nullptr; return best.size() > 0 ? best[0] : nullptr;
} }
CObject* CObjectManager::Radar(CObject* pThis, Math::Vector thisPosition, float thisAngle, ObjectType type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes) CObject* CObjectManager::Radar(CObject* pThis, glm::vec3 thisPosition, float thisAngle, ObjectType type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes)
{ {
std::vector<CObject*> best = RadarAll(pThis, thisPosition, thisAngle, type, angle, focus, minDist, maxDist, furthest, filter, cbotTypes); std::vector<CObject*> best = RadarAll(pThis, thisPosition, thisAngle, type, angle, focus, minDist, maxDist, furthest, filter, cbotTypes);
return best.size() > 0 ? best[0] : nullptr; return best.size() > 0 ? best[0] : nullptr;
} }
CObject* CObjectManager::Radar(CObject* pThis, Math::Vector thisPosition, float thisAngle, std::vector<ObjectType> type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes) CObject* CObjectManager::Radar(CObject* pThis, glm::vec3 thisPosition, float thisAngle, std::vector<ObjectType> type, float angle, float focus, float minDist, float maxDist, bool furthest, RadarFilter filter, bool cbotTypes)
{ {
std::vector<CObject*> best = RadarAll(pThis, thisPosition, thisAngle, type, angle, focus, minDist, maxDist, furthest, filter, cbotTypes); std::vector<CObject*> best = RadarAll(pThis, thisPosition, thisAngle, type, angle, focus, minDist, maxDist, furthest, filter, cbotTypes);
return best.size() > 0 ? best[0] : nullptr; return best.size() > 0 ? best[0] : nullptr;
@ -454,12 +454,12 @@ CObject* CObjectManager::FindNearest(CObject* pThis, std::vector<ObjectType> ty
return Radar(pThis, type, 0.0f, Math::PI*2.0f, 0.0f, maxDist, false, FILTER_NONE, cbotTypes); return Radar(pThis, type, 0.0f, Math::PI*2.0f, 0.0f, maxDist, false, FILTER_NONE, cbotTypes);
} }
CObject* CObjectManager::FindNearest(CObject* pThis, Math::Vector thisPosition, ObjectType type, float maxDist, bool cbotTypes) CObject* CObjectManager::FindNearest(CObject* pThis, glm::vec3 thisPosition, ObjectType type, float maxDist, bool cbotTypes)
{ {
return Radar(pThis, thisPosition, 0.0f, type, 0.0f, Math::PI*2.0f, 0.0f, maxDist, false, FILTER_NONE, cbotTypes); return Radar(pThis, thisPosition, 0.0f, type, 0.0f, Math::PI*2.0f, 0.0f, maxDist, false, FILTER_NONE, cbotTypes);
} }
CObject* CObjectManager::FindNearest(CObject* pThis, Math::Vector thisPosition, std::vector<ObjectType> type, float maxDist, bool cbotTypes) CObject* CObjectManager::FindNearest(CObject* pThis, glm::vec3 thisPosition, std::vector<ObjectType> type, float maxDist, bool cbotTypes)
{ {
return Radar(pThis, thisPosition, 0.0f, type, 0.0f, Math::PI*2.0f, 0.0f, maxDist, false, FILTER_NONE, cbotTypes); return Radar(pThis, thisPosition, 0.0f, type, 0.0f, Math::PI*2.0f, 0.0f, maxDist, false, FILTER_NONE, cbotTypes);
} }

View File

@ -160,7 +160,7 @@ public:
//! Creates an object //! Creates an object
//@{ //@{
CObject* CreateObject(ObjectCreateParams params); CObject* CreateObject(ObjectCreateParams params);
CObject* CreateObject(Math::Vector pos, float angle, ObjectType type, float power = -1.0f); CObject* CreateObject(glm::vec3 pos, float angle, ObjectType type, float power = -1.0f);
//@} //@}
//! Deletes the object //! Deletes the object
@ -215,7 +215,7 @@ public:
RadarFilter filter = FILTER_NONE, RadarFilter filter = FILTER_NONE,
bool cbotTypes = false); bool cbotTypes = false);
std::vector<CObject*> RadarAll(CObject* pThis, std::vector<CObject*> RadarAll(CObject* pThis,
Math::Vector thisPosition, glm::vec3 thisPosition,
float thisAngle, float thisAngle,
ObjectType type = OBJECT_NULL, ObjectType type = OBJECT_NULL,
float angle = 0.0f, float angle = 0.0f,
@ -226,7 +226,7 @@ public:
RadarFilter filter = FILTER_NONE, RadarFilter filter = FILTER_NONE,
bool cbotTypes = false); bool cbotTypes = false);
std::vector<CObject*> RadarAll(CObject* pThis, std::vector<CObject*> RadarAll(CObject* pThis,
Math::Vector thisPosition, glm::vec3 thisPosition,
float thisAngle, float thisAngle,
std::vector<ObjectType> type = std::vector<ObjectType>(), std::vector<ObjectType> type = std::vector<ObjectType>(),
float angle = 0.0f, float angle = 0.0f,
@ -258,7 +258,7 @@ public:
RadarFilter filter = FILTER_NONE, RadarFilter filter = FILTER_NONE,
bool cbotTypes = false); bool cbotTypes = false);
CObject* Radar(CObject* pThis, CObject* Radar(CObject* pThis,
Math::Vector thisPosition, glm::vec3 thisPosition,
float thisAngle, float thisAngle,
ObjectType type = OBJECT_NULL, ObjectType type = OBJECT_NULL,
float angle = 0.0f, float angle = 0.0f,
@ -269,7 +269,7 @@ public:
RadarFilter filter = FILTER_NONE, RadarFilter filter = FILTER_NONE,
bool cbotTypes = false); bool cbotTypes = false);
CObject* Radar(CObject* pThis, CObject* Radar(CObject* pThis,
Math::Vector thisPosition, glm::vec3 thisPosition,
float thisAngle, float thisAngle,
std::vector<ObjectType> type = std::vector<ObjectType>(), std::vector<ObjectType> type = std::vector<ObjectType>(),
float angle = 0.0f, float angle = 0.0f,
@ -291,12 +291,12 @@ public:
float maxDist = 1000.0f, float maxDist = 1000.0f,
bool cbotTypes = false); bool cbotTypes = false);
CObject* FindNearest(CObject* pThis, CObject* FindNearest(CObject* pThis,
Math::Vector thisPosition, glm::vec3 thisPosition,
ObjectType type = OBJECT_NULL, ObjectType type = OBJECT_NULL,
float maxDist = 1000.0f, float maxDist = 1000.0f,
bool cbotTypes = false); bool cbotTypes = false);
CObject* FindNearest(CObject* pThis, CObject* FindNearest(CObject* pThis,
Math::Vector thisPosition, glm::vec3 thisPosition,
std::vector<ObjectType> type = std::vector<ObjectType>(), std::vector<ObjectType> type = std::vector<ObjectType>(),
float maxDist = 1000.0f, float maxDist = 1000.0f,
bool cbotTypes = false); bool cbotTypes = false);

View File

@ -84,7 +84,7 @@ CPhysics::CPhysics(COldObject* object)
m_gravity = 9.81f; // default gravity m_gravity = 9.81f; // default gravity
m_time = 0.0f; m_time = 0.0f;
m_timeUnderWater = 0.0f; m_timeUnderWater = 0.0f;
m_motorSpeed = Math::Vector(0.0f, 0.0f, 0.0f); m_motorSpeed = glm::vec3(0.0f, 0.0f, 0.0f);
m_bMotor = false; m_bMotor = false;
m_bLand = true; // ground m_bLand = true; // ground
m_bSwim = false; // in air m_bSwim = false; // in air
@ -181,7 +181,7 @@ bool CPhysics::Write(CLevelParserLine* line)
bool CPhysics::Read(CLevelParserLine* line) bool CPhysics::Read(CLevelParserLine* line)
{ {
m_motorSpeed = line->GetParam("motor")->AsPoint(Math::Vector(0.0f, 0.0f, 0.0f)); m_motorSpeed = line->GetParam("motor")->AsPoint(glm::vec3(0.0f, 0.0f, 0.0f));
if ( m_object->Implements(ObjectInterfaceType::Flying) ) if ( m_object->Implements(ObjectInterfaceType::Flying) )
{ {
@ -302,7 +302,7 @@ bool CPhysics::GetFreeze()
// y = up/down // y = up/down
// z = turn // z = turn
void CPhysics::SetMotorSpeed(Math::Vector speed) void CPhysics::SetMotorSpeed(glm::vec3 speed)
{ {
m_motorSpeed = speed; m_motorSpeed = speed;
} }
@ -334,7 +334,7 @@ void CPhysics::SetMotorSpeedZ(float speed)
m_motorSpeed.z = speed; m_motorSpeed.z = speed;
} }
Math::Vector CPhysics::GetMotorSpeed() glm::vec3 CPhysics::GetMotorSpeed()
{ {
return m_motorSpeed; return m_motorSpeed;
} }
@ -358,7 +358,7 @@ float CPhysics::GetMotorSpeedZ()
// Management of linear and angular velocities. // Management of linear and angular velocities.
// Specifies the speed parallel to the direction of travel. // Specifies the speed parallel to the direction of travel.
void CPhysics::SetLinMotion(PhysicsMode mode, Math::Vector value) void CPhysics::SetLinMotion(PhysicsMode mode, glm::vec3 value)
{ {
if ( mode == MO_ADVACCEL ) m_linMotion.advanceAccel = value; if ( mode == MO_ADVACCEL ) m_linMotion.advanceAccel = value;
if ( mode == MO_RECACCEL ) m_linMotion.recedeAccel = value; if ( mode == MO_RECACCEL ) m_linMotion.recedeAccel = value;
@ -374,7 +374,7 @@ void CPhysics::SetLinMotion(PhysicsMode mode, Math::Vector value)
if ( mode == MO_REASPEED ) m_linMotion.realSpeed = value; if ( mode == MO_REASPEED ) m_linMotion.realSpeed = value;
} }
Math::Vector CPhysics::GetLinMotion(PhysicsMode mode) glm::vec3 CPhysics::GetLinMotion(PhysicsMode mode)
{ {
if ( mode == MO_ADVACCEL ) return m_linMotion.advanceAccel; if ( mode == MO_ADVACCEL ) return m_linMotion.advanceAccel;
if ( mode == MO_RECACCEL ) return m_linMotion.recedeAccel; if ( mode == MO_RECACCEL ) return m_linMotion.recedeAccel;
@ -388,7 +388,7 @@ Math::Vector CPhysics::GetLinMotion(PhysicsMode mode)
if ( mode == MO_MOTSPEED ) return m_linMotion.motorSpeed; if ( mode == MO_MOTSPEED ) return m_linMotion.motorSpeed;
if ( mode == MO_CURSPEED ) return m_linMotion.currentSpeed; if ( mode == MO_CURSPEED ) return m_linMotion.currentSpeed;
if ( mode == MO_REASPEED ) return m_linMotion.realSpeed; if ( mode == MO_REASPEED ) return m_linMotion.realSpeed;
return Math::Vector(0.0f, 0.0f, 0.0f); return glm::vec3(0.0f, 0.0f, 0.0f);
} }
void CPhysics::SetLinMotionX(PhysicsMode mode, float value) void CPhysics::SetLinMotionX(PhysicsMode mode, float value)
@ -496,7 +496,7 @@ float CPhysics::GetLinMotionZ(PhysicsMode mode)
// Specifies the rotation around the axis of walk. // Specifies the rotation around the axis of walk.
void CPhysics::SetCirMotion(PhysicsMode mode, Math::Vector value) void CPhysics::SetCirMotion(PhysicsMode mode, glm::vec3 value)
{ {
if ( mode == MO_ADVACCEL ) m_cirMotion.advanceAccel = value; if ( mode == MO_ADVACCEL ) m_cirMotion.advanceAccel = value;
if ( mode == MO_RECACCEL ) m_cirMotion.recedeAccel = value; if ( mode == MO_RECACCEL ) m_cirMotion.recedeAccel = value;
@ -512,7 +512,7 @@ void CPhysics::SetCirMotion(PhysicsMode mode, Math::Vector value)
if ( mode == MO_REASPEED ) m_cirMotion.realSpeed = value; if ( mode == MO_REASPEED ) m_cirMotion.realSpeed = value;
} }
Math::Vector CPhysics::GetCirMotion(PhysicsMode mode) glm::vec3 CPhysics::GetCirMotion(PhysicsMode mode)
{ {
if ( mode == MO_ADVACCEL ) return m_cirMotion.advanceAccel; if ( mode == MO_ADVACCEL ) return m_cirMotion.advanceAccel;
if ( mode == MO_RECACCEL ) return m_cirMotion.recedeAccel; if ( mode == MO_RECACCEL ) return m_cirMotion.recedeAccel;
@ -526,7 +526,7 @@ Math::Vector CPhysics::GetCirMotion(PhysicsMode mode)
if ( mode == MO_MOTSPEED ) return m_cirMotion.motorSpeed; if ( mode == MO_MOTSPEED ) return m_cirMotion.motorSpeed;
if ( mode == MO_CURSPEED ) return m_cirMotion.currentSpeed; if ( mode == MO_CURSPEED ) return m_cirMotion.currentSpeed;
if ( mode == MO_REASPEED ) return m_cirMotion.realSpeed; if ( mode == MO_REASPEED ) return m_cirMotion.realSpeed;
return Math::Vector(0.0f, 0.0f, 0.0f); return glm::vec3(0.0f, 0.0f, 0.0f);
} }
void CPhysics::SetCirMotionX(PhysicsMode mode, float value) void CPhysics::SetCirMotionX(PhysicsMode mode, float value)
@ -757,7 +757,7 @@ void CPhysics::MotorUpdate(float aTime, float rTime)
{ {
ObjectType type; ObjectType type;
CPowerContainerObject* power = nullptr; CPowerContainerObject* power = nullptr;
Math::Vector pos, motorSpeed; glm::vec3 pos{ 0, 0, 0 }, motorSpeed{ 0, 0, 0 };
float energy, speed, factor, h; float energy, speed, factor, h;
type = m_object->GetType(); type = m_object->GetType();
@ -1013,7 +1013,7 @@ void CPhysics::MotorUpdate(float aTime, float rTime)
void CPhysics::EffectUpdate(float aTime, float rTime) void CPhysics::EffectUpdate(float aTime, float rTime)
{ {
Character* character; Character* character;
Math::Vector vibLin, vibCir, incl; glm::vec3 vibLin{ 0, 0, 0 }, vibCir{ 0, 0, 0 }, incl{ 0, 0, 0 };
float speedLin, speedCir, accel; float speedLin, speedCir, accel;
ObjectType type; ObjectType type;
bool bOnBoard; bool bOnBoard;
@ -1142,10 +1142,10 @@ void CPhysics::EffectUpdate(float aTime, float rTime)
} }
else else
{ {
m_motion->SetLinVibration(Math::Vector(0.0f, 0.0f, 0.0f)); m_motion->SetLinVibration(glm::vec3(0.0f, 0.0f, 0.0f));
//? m_motion->SetCirVibration(Math::Vector(0.0f, 0.0f, 0.0f)); //? m_motion->SetCirVibration(glm::vec3(0.0f, 0.0f, 0.0f));
//? m_motion->SetTilt(Math::Vector(0.0f, 0.0f, 0.0f)); //? m_motion->SetTilt(glm::vec3(0.0f, 0.0f, 0.0f));
} }
} }
@ -1204,9 +1204,9 @@ void CPhysics::EffectUpdate(float aTime, float rTime)
{ {
if ( m_bLand ) // on the ground? if ( m_bLand ) // on the ground?
{ {
m_motion->SetLinVibration(Math::Vector(0.0f, 0.0f, 0.0f)); m_motion->SetLinVibration(glm::vec3(0.0f, 0.0f, 0.0f));
m_motion->SetCirVibration(Math::Vector(0.0f, 0.0f, 0.0f)); m_motion->SetCirVibration(glm::vec3(0.0f, 0.0f, 0.0f));
m_motion->SetTilt(Math::Vector(0.0f, 0.0f, 0.0f)); m_motion->SetTilt(glm::vec3(0.0f, 0.0f, 0.0f));
} }
else // in flight? else // in flight?
{ {
@ -1442,7 +1442,7 @@ bool CPhysics::EventFrame(const Event &event)
{ {
ObjectType type; ObjectType type;
Math::Matrix objRotate, matRotate; Math::Matrix objRotate, matRotate;
Math::Vector iPos, iAngle, tAngle, pos, newpos, angle, newangle, n; glm::vec3 iPos{ 0, 0, 0 }, iAngle{ 0, 0, 0 }, tAngle{ 0, 0, 0 }, pos{ 0, 0, 0 }, newpos{ 0, 0, 0 }, angle{ 0, 0, 0 }, newangle{ 0, 0, 0 }, n{ 0, 0, 0 };
float h, w; float h, w;
int i; int i;
@ -1745,7 +1745,7 @@ void CPhysics::SoundMotor(float rTime)
void CPhysics::WaterFrame(float aTime, float rTime) void CPhysics::WaterFrame(float aTime, float rTime)
{ {
ObjectType type; ObjectType type;
Math::Vector pos, speed; glm::vec3 pos{ 0, 0, 0 }, speed{ 0, 0, 0 };
glm::vec2 dim; glm::vec2 dim;
float level; float level;
@ -1961,7 +1961,7 @@ void CPhysics::SoundMotorFull(float rTime, ObjectType type)
void CPhysics::SoundMotorSlow(float rTime, ObjectType type) void CPhysics::SoundMotorSlow(float rTime, ObjectType type)
{ {
Math::Matrix* mat; Math::Matrix* mat;
Math::Vector pos, speed; glm::vec3 pos{ 0, 0, 0 }, speed{ 0, 0, 0 };
glm::vec2 dim; glm::vec2 dim;
SoundType sound; SoundType sound;
float amplitude; float amplitude;
@ -2069,7 +2069,7 @@ void CPhysics::SoundMotorSlow(float rTime, ObjectType type)
max = static_cast<int>(10.0f*m_engine->GetParticleDensity()); max = static_cast<int>(10.0f*m_engine->GetParticleDensity());
for ( i=0 ; i<max ; i++ ) for ( i=0 ; i<max ; i++ )
{ {
pos = Math::Vector(-5.0f, 2.0f, 0.0f); pos = glm::vec3(-5.0f, 2.0f, 0.0f);
pos.x += Math::Rand()*4.0f; pos.x += Math::Rand()*4.0f;
pos.z += (Math::Rand()-0.5f)*2.0f; pos.z += (Math::Rand()-0.5f)*2.0f;
@ -2127,7 +2127,7 @@ void CPhysics::SoundReactorFull(float rTime, ObjectType type)
{ {
SoundType sound; SoundType sound;
Math::Matrix* mat; Math::Matrix* mat;
Math::Vector pos, speed; glm::vec3 pos{ 0, 0, 0 }, speed{ 0, 0, 0 };
glm::vec2 dim; glm::vec2 dim;
float freq; float freq;
int i; int i;
@ -2186,11 +2186,11 @@ void CPhysics::SoundReactorFull(float rTime, ObjectType type)
if ( m_object->GetType() == OBJECT_HUMAN || if ( m_object->GetType() == OBJECT_HUMAN ||
m_object->GetType() == OBJECT_TECH ) m_object->GetType() == OBJECT_TECH )
{ {
pos = Math::Vector(-1.6f, -0.5f, 0.0f); pos = glm::vec3(-1.6f, -0.5f, 0.0f);
} }
else else
{ {
pos = Math::Vector(0.0f, -1.0f, 0.0f); pos = glm::vec3(0.0f, -1.0f, 0.0f);
} }
pos.x += (Math::Rand()-0.5f)*2.0f; pos.x += (Math::Rand()-0.5f)*2.0f;
pos.z += (Math::Rand()-0.5f)*2.0f; pos.z += (Math::Rand()-0.5f)*2.0f;
@ -2211,11 +2211,11 @@ void CPhysics::SoundReactorFull(float rTime, ObjectType type)
if ( m_object->GetType() == OBJECT_HUMAN || if ( m_object->GetType() == OBJECT_HUMAN ||
m_object->GetType() == OBJECT_TECH ) m_object->GetType() == OBJECT_TECH )
{ {
pos = Math::Vector(-1.6f, -0.5f, 0.0f); pos = glm::vec3(-1.6f, -0.5f, 0.0f);
} }
else else
{ {
pos = Math::Vector(0.0f, -1.0f, 0.0f); pos = glm::vec3(0.0f, -1.0f, 0.0f);
} }
pos.x += (Math::Rand()-0.5f)*1.0f; pos.x += (Math::Rand()-0.5f)*1.0f;
pos.z += (Math::Rand()-0.5f)*1.0f; pos.z += (Math::Rand()-0.5f)*1.0f;
@ -2285,11 +2285,11 @@ void CPhysics::SoundReactorStop(float rTime, ObjectType type)
// Adapts the physics of the object based on the ground. // Adapts the physics of the object based on the ground.
void CPhysics::FloorAdapt(float aTime, float rTime, void CPhysics::FloorAdapt(float aTime, float rTime,
Math::Vector &pos, Math::Vector &angle) glm::vec3 &pos, glm::vec3 &angle)
{ {
Character* character; Character* character;
ObjectType type; ObjectType type;
Math::Vector norm; glm::vec3 norm{ 0, 0, 0 };
Math::Matrix matRotate; Math::Matrix matRotate;
float level, h, f, a1, volume, freq, force; float level, h, f, a1, volume, freq, force;
bool bSlopingTerrain; bool bSlopingTerrain;
@ -2459,10 +2459,10 @@ void CPhysics::FloorAdapt(float aTime, float rTime,
// Calculates the angle of an object with the field. // Calculates the angle of an object with the field.
void CPhysics::FloorAngle(const Math::Vector &pos, Math::Vector &angle) void CPhysics::FloorAngle(const glm::vec3 &pos, glm::vec3 &angle)
{ {
Character* character; Character* character;
Math::Vector pw, norm; glm::vec3 pw{ 0, 0, 0 }, norm{ 0, 0, 0 };
float a1, a2; float a1, a2;
character = m_object->GetCharacter(); character = m_object->GetCharacter();
@ -2498,10 +2498,10 @@ void CPhysics::FloorAngle(const Math::Vector &pos, Math::Vector &angle)
// Returns 1 -> immobile object (because collision) // Returns 1 -> immobile object (because collision)
// Returns 2 -> destroyed object // Returns 2 -> destroyed object
int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle) int CPhysics::ObjectAdapt(const glm::vec3 &pos, const glm::vec3 &angle)
{ {
Math::Matrix matRotate; Math::Matrix matRotate;
Math::Vector iPos, oAngle, oSpeed; glm::vec3 iPos{ 0, 0, 0 }, oAngle{ 0, 0, 0 }, oSpeed{ 0, 0, 0 };
float distance, force, volume; float distance, force, volume;
int colType; int colType;
ObjectType iType, oType; ObjectType iType, oType;
@ -2515,7 +2515,7 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle)
return 0; return 0;
auto firstCrashSphere = m_object->GetFirstCrashSphere(); auto firstCrashSphere = m_object->GetFirstCrashSphere();
Math::Vector iiPos = firstCrashSphere.sphere.pos; glm::vec3 iiPos = firstCrashSphere.sphere.pos;
float iRad = firstCrashSphere.sphere.radius; float iRad = firstCrashSphere.sphere.radius;
iPos = iiPos + (pos - m_object->GetPosition()); iPos = iiPos + (pos - m_object->GetPosition());
@ -2540,7 +2540,7 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle)
!pObj->GetLock() && !pObj->GetLock() &&
m_object->GetTrainer() ) // driving vehicle? m_object->GetTrainer() ) // driving vehicle?
{ {
Math::Vector oPos = pObj->GetPosition(); glm::vec3 oPos = pObj->GetPosition();
distance = Math::DistanceProjected(oPos, iPos); distance = Math::DistanceProjected(oPos, iPos);
if ( distance < 4.0f ) if ( distance < 4.0f )
{ {
@ -2551,7 +2551,7 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle)
if ( oType == OBJECT_TARGET2 && !pObj->GetLock() ) if ( oType == OBJECT_TARGET2 && !pObj->GetLock() )
{ {
Math::Vector oPos = pObj->GetPosition(); glm::vec3 oPos = pObj->GetPosition();
distance = Math::Distance(oPos, iPos); distance = Math::Distance(oPos, iPos);
if ( distance < 10.0f*1.5f ) if ( distance < 10.0f*1.5f )
{ {
@ -2562,7 +2562,7 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle)
for (const auto& crashSphere : pObj->GetAllCrashSpheres()) for (const auto& crashSphere : pObj->GetAllCrashSpheres())
{ {
Math::Vector oPos = crashSphere.sphere.pos; glm::vec3 oPos = crashSphere.sphere.pos;
float oRad = crashSphere.sphere.radius; float oRad = crashSphere.sphere.radius;
// Aliens ignore small objects // Aliens ignore small objects
@ -2592,7 +2592,7 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle)
if ( colType == 0 ) continue; // ignores? if ( colType == 0 ) continue; // ignores?
} }
force = m_linMotion.realSpeed.Length(); force = glm::length(m_linMotion.realSpeed);
force *= crashSphere.hardness; force *= crashSphere.hardness;
volume = fabs(force*0.05f); volume = fabs(force*0.05f);
if ( volume > 1.0f ) volume = 1.0f; if ( volume > 1.0f ) volume = 1.0f;
@ -2616,7 +2616,7 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle)
m_repeatCollision = 10; m_repeatCollision = 10;
} }
m_linMotion.currentSpeed = Normalize(iPos-oPos)*force; m_linMotion.currentSpeed = glm::normalize(iPos-oPos)*force;
Math::LoadRotationXZYMatrix(matRotate, -angle); Math::LoadRotationXZYMatrix(matRotate, -angle);
m_linMotion.currentSpeed = Transform(matRotate, m_linMotion.currentSpeed); m_linMotion.currentSpeed = Transform(matRotate, m_linMotion.currentSpeed);
if ( !m_object->Implements(ObjectInterfaceType::Flying) ) if ( !m_object->Implements(ObjectInterfaceType::Flying) )
@ -2631,7 +2631,7 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle)
if ( ph != nullptr ) if ( ph != nullptr )
{ {
oAngle = pObj->GetRotation(); oAngle = pObj->GetRotation();
oSpeed = Normalize(oPos-iPos)*force; oSpeed = glm::normalize(oPos-iPos)*force;
Math::LoadRotationXZYMatrix(matRotate, -oAngle); Math::LoadRotationXZYMatrix(matRotate, -oAngle);
oSpeed = Transform(matRotate, oSpeed); oSpeed = Transform(matRotate, oSpeed);
if ( !pObj->Implements(ObjectInterfaceType::Flying) ) if ( !pObj->Implements(ObjectInterfaceType::Flying) )
@ -2660,7 +2660,7 @@ int CPhysics::ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle)
// Shakes an object. // Shakes an object.
bool CPhysics::JostleObject(CJostleableObject* pObj, Math::Vector iPos, float iRad) bool CPhysics::JostleObject(CJostleableObject* pObj, glm::vec3 iPos, float iRad)
{ {
Math::Sphere jostlingSphere = pObj->GetJostlingSphere(); Math::Sphere jostlingSphere = pObj->GetJostlingSphere();
@ -2672,9 +2672,9 @@ bool CPhysics::JostleObject(CJostleableObject* pObj, Math::Vector iPos, float iR
if ( f < 0.0f ) f = 0.0f; if ( f < 0.0f ) f = 0.0f;
if ( f > 1.0f ) f = 1.0f; if ( f > 1.0f ) f = 1.0f;
Math::Vector speed = m_linMotion.realSpeed; glm::vec3 speed = m_linMotion.realSpeed;
speed.y = 0.0f; speed.y = 0.0f;
float force = speed.Length()*f*0.05f; float force = glm::length(speed)*f*0.05f;
if ( force > 1.0f ) force = 1.0f; if ( force > 1.0f ) force = 1.0f;
if ( m_soundTimeJostle >= 0.20f ) if ( m_soundTimeJostle >= 0.20f )
@ -2962,7 +2962,7 @@ void CPhysics::FrameParticle(float aTime, float rTime)
void CPhysics::PowerParticle(float factor, bool bBreak) void CPhysics::PowerParticle(float factor, bool bBreak)
{ {
Math::Matrix* mat; Math::Matrix* mat;
Math::Vector pos, ppos, eye, speed; glm::vec3 pos{ 0, 0, 0 }, ppos{ 0, 0, 0 }, eye{ 0, 0, 0 }, speed{ 0, 0, 0 };
glm::vec2 dim; glm::vec2 dim;
bool bCarryPower; bool bCarryPower;
@ -3000,7 +3000,7 @@ void CPhysics::PowerParticle(float factor, bool bBreak)
if ( bCarryPower ) // carry a battery? if ( bCarryPower ) // carry a battery?
{ {
pos = Math::Vector(3.0f, 5.6f, 0.0f); // position of battery holder // TODO: Move to CTransportableObject pos = glm::vec3(3.0f, 5.6f, 0.0f); // position of battery holder // TODO: Move to CTransportableObject
pos = Transform(*mat, pos); pos = Transform(*mat, pos);
speed.x = (Math::Rand()-0.5f)*12.0f; speed.x = (Math::Rand()-0.5f)*12.0f;
@ -3023,7 +3023,7 @@ void CPhysics::PowerParticle(float factor, bool bBreak)
void CPhysics::CrashParticle(float crash) void CPhysics::CrashParticle(float crash)
{ {
Math::Vector pos, ppos, speed; glm::vec3 pos{ 0, 0, 0 }, ppos{ 0, 0, 0 }, speed{ 0, 0, 0 };
glm::vec2 dim; glm::vec2 dim;
float len; float len;
int i, max; int i, max;
@ -3057,7 +3057,7 @@ void CPhysics::CrashParticle(float crash)
void CPhysics::MotorParticle(float aTime, float rTime) void CPhysics::MotorParticle(float aTime, float rTime)
{ {
Math::Matrix* mat; Math::Matrix* mat;
Math::Vector pos, speed; glm::vec3 pos{ 0, 0, 0 }, speed{ 0, 0, 0 };
glm::vec2 dim; glm::vec2 dim;
ObjectType type; ObjectType type;
glm::vec2 c, p; glm::vec2 c, p;
@ -3166,7 +3166,7 @@ void CPhysics::MotorParticle(float aTime, float rTime)
pos.z = Math::Rand()*0.4f+1.0f; pos.z = Math::Rand()*0.4f+1.0f;
if ( rand()%2 == 0 ) pos.z = -pos.z; if ( rand()%2 == 0 ) pos.z = -pos.z;
pos = Transform(*mat, pos); pos = Transform(*mat, pos);
speed = Math::Vector(0.0f, 1.0f, 0.0f); speed = glm::vec3(0.0f, 1.0f, 0.0f);
dim.x = Math::Rand()*(h-5.0f)/2.0f+1.0f; dim.x = Math::Rand()*(h-5.0f)/2.0f+1.0f;
if ( dim.x > 2.5f ) dim.x = 2.5f; if ( dim.x > 2.5f ) dim.x = 2.5f;
dim.y = dim.x; dim.y = dim.x;
@ -3195,7 +3195,7 @@ void CPhysics::MotorParticle(float aTime, float rTime)
pos.z = Math::Rand()*2.0f+3.0f; pos.z = Math::Rand()*2.0f+3.0f;
if ( rand()%2 == 0 ) pos.z = -pos.z; if ( rand()%2 == 0 ) pos.z = -pos.z;
pos = Transform(*mat, pos); pos = Transform(*mat, pos);
speed = Math::Vector(0.0f, 0.0f, 0.0f); speed = glm::vec3(0.0f, 0.0f, 0.0f);
dim.x = Math::Rand()*(h-5.0f)/2.0f+1.0f; dim.x = Math::Rand()*(h-5.0f)/2.0f+1.0f;
if ( dim.x > 3.0f ) dim.x = 3.0f; if ( dim.x > 3.0f ) dim.x = 3.0f;
dim.y = dim.x; dim.y = dim.x;
@ -3223,7 +3223,7 @@ void CPhysics::MotorParticle(float aTime, float rTime)
pos.z = Math::Rand()*3.0f+3.0f; pos.z = Math::Rand()*3.0f+3.0f;
if ( rand()%2 == 0 ) pos.z = -pos.z; if ( rand()%2 == 0 ) pos.z = -pos.z;
pos = Transform(*mat, pos); pos = Transform(*mat, pos);
speed = Math::Vector(0.0f, 0.0f, 0.0f); speed = glm::vec3(0.0f, 0.0f, 0.0f);
dim.x = Math::Rand()*(h-5.0f)/2.0f+1.0f; dim.x = Math::Rand()*(h-5.0f)/2.0f+1.0f;
if ( dim.x > 3.0f ) dim.x = 3.0f; if ( dim.x > 3.0f ) dim.x = 3.0f;
dim.y = dim.x; dim.y = dim.x;
@ -3249,7 +3249,7 @@ void CPhysics::MotorParticle(float aTime, float rTime)
aTime-m_lastMotorParticle < m_engine->ParticleAdapt(0.05f) ) return; aTime-m_lastMotorParticle < m_engine->ParticleAdapt(0.05f) ) return;
m_lastMotorParticle = aTime; m_lastMotorParticle = aTime;
pos = Math::Vector(-1.6f, -0.5f, 0.0f); pos = glm::vec3(-1.6f, -0.5f, 0.0f);
mat = m_object->GetWorldMatrix(0); mat = m_object->GetWorldMatrix(0);
pos = Transform(*mat, pos); pos = Transform(*mat, pos);
@ -3278,7 +3278,7 @@ void CPhysics::MotorParticle(float aTime, float rTime)
if ( aTime-m_lastMotorParticle < m_engine->ParticleAdapt(0.02f) ) return; if ( aTime-m_lastMotorParticle < m_engine->ParticleAdapt(0.02f) ) return;
m_lastMotorParticle = aTime; m_lastMotorParticle = aTime;
pos = Math::Vector(-1.6f, -1.0f, 0.0f); pos = glm::vec3(-1.6f, -1.0f, 0.0f);
pos.x += (Math::Rand()-0.5f)*3.0f; pos.x += (Math::Rand()-0.5f)*3.0f;
pos.y += (Math::Rand()-0.5f)*1.5f; pos.y += (Math::Rand()-0.5f)*1.5f;
pos.z += (Math::Rand()-0.5f)*3.0f; pos.z += (Math::Rand()-0.5f)*3.0f;
@ -3288,7 +3288,7 @@ void CPhysics::MotorParticle(float aTime, float rTime)
h = m_floorHeight; h = m_floorHeight;
if ( h > 10.0f ) // high enough? if ( h > 10.0f ) // high enough?
{ {
speed = Math::Vector(0.0f, -10.0f, 0.0f); // against the bottom speed = glm::vec3(0.0f, -10.0f, 0.0f); // against the bottom
} }
else else
{ {
@ -3302,7 +3302,7 @@ void CPhysics::MotorParticle(float aTime, float rTime)
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTISCRAPS, 2.0f, 10.0f); m_particle->CreateParticle(pos, speed, dim, Gfx::PARTISCRAPS, 2.0f, 10.0f);
pos = Math::Vector(-1.6f, -0.5f, 0.0f); pos = glm::vec3(-1.6f, -0.5f, 0.0f);
pos = Transform(*mat, pos); pos = Transform(*mat, pos);
speed.x = (Math::Rand()-0.5f)*1.0f; speed.x = (Math::Rand()-0.5f)*1.0f;
@ -3356,15 +3356,15 @@ void CPhysics::MotorParticle(float aTime, float rTime)
m_lastMotorParticle = aTime; m_lastMotorParticle = aTime;
r = rand()%3; r = rand()%3;
if ( r == 0 ) pos = Math::Vector(-3.0f, 0.0f, -4.0f); if ( r == 0 ) pos = glm::vec3(-3.0f, 0.0f, -4.0f);
if ( r == 1 ) pos = Math::Vector(-3.0f, 0.0f, 4.0f); if ( r == 1 ) pos = glm::vec3(-3.0f, 0.0f, 4.0f);
if ( r == 2 ) pos = Math::Vector( 4.0f, 0.0f, 0.0f); if ( r == 2 ) pos = glm::vec3( 4.0f, 0.0f, 0.0f);
pos.x += (Math::Rand()-0.5f)*2.0f; pos.x += (Math::Rand()-0.5f)*2.0f;
pos.z += (Math::Rand()-0.5f)*2.0f; pos.z += (Math::Rand()-0.5f)*2.0f;
mat = m_object->GetWorldMatrix(0); mat = m_object->GetWorldMatrix(0);
pos = Transform(*mat, pos); pos = Transform(*mat, pos);
speed = Math::Vector(0.0f, 0.0f, 0.0f); speed = glm::vec3(0.0f, 0.0f, 0.0f);
dim.x = Math::Rand()*h/5.0f+2.0f; dim.x = Math::Rand()*h/5.0f+2.0f;
dim.y = dim.x; dim.y = dim.x;
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTICRASH, 2.0f); m_particle->CreateParticle(pos, speed, dim, Gfx::PARTICRASH, 2.0f);
@ -3378,15 +3378,15 @@ void CPhysics::MotorParticle(float aTime, float rTime)
m_lastMotorParticle = aTime; m_lastMotorParticle = aTime;
r = rand()%3; r = rand()%3;
if ( r == 0 ) pos = Math::Vector(-3.0f, 0.0f, -4.0f); if ( r == 0 ) pos = glm::vec3(-3.0f, 0.0f, -4.0f);
if ( r == 1 ) pos = Math::Vector(-3.0f, 0.0f, 4.0f); if ( r == 1 ) pos = glm::vec3(-3.0f, 0.0f, 4.0f);
if ( r == 2 ) pos = Math::Vector( 4.0f, 0.0f, 0.0f); if ( r == 2 ) pos = glm::vec3( 4.0f, 0.0f, 0.0f);
pos.x += (Math::Rand()-0.5f)*1.0f; pos.x += (Math::Rand()-0.5f)*1.0f;
pos.z += (Math::Rand()-0.5f)*1.0f; pos.z += (Math::Rand()-0.5f)*1.0f;
mat = m_object->GetWorldMatrix(0); mat = m_object->GetWorldMatrix(0);
pos = Transform(*mat, pos); pos = Transform(*mat, pos);
speed = Math::Vector(0.0f, 0.0f, 0.0f); speed = glm::vec3(0.0f, 0.0f, 0.0f);
dim.x = 1.0f; dim.x = 1.0f;
dim.y = dim.x; dim.y = dim.x;
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIEJECT); m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIEJECT);
@ -3399,7 +3399,7 @@ void CPhysics::MotorParticle(float aTime, float rTime)
if ( aTime-m_lastMotorParticle < m_engine->ParticleAdapt(0.02f) ) return; if ( aTime-m_lastMotorParticle < m_engine->ParticleAdapt(0.02f) ) return;
m_lastMotorParticle = aTime; m_lastMotorParticle = aTime;
pos = Math::Vector(0.0f, -1.0f, 0.0f); pos = glm::vec3(0.0f, -1.0f, 0.0f);
pos.x += (Math::Rand()-0.5f)*6.0f; pos.x += (Math::Rand()-0.5f)*6.0f;
pos.y += (Math::Rand()-0.5f)*3.0f; pos.y += (Math::Rand()-0.5f)*3.0f;
pos.z += (Math::Rand()-0.5f)*6.0f; pos.z += (Math::Rand()-0.5f)*6.0f;
@ -3409,7 +3409,7 @@ void CPhysics::MotorParticle(float aTime, float rTime)
h = m_floorHeight; h = m_floorHeight;
if ( h > 10.0f ) // high enough? if ( h > 10.0f ) // high enough?
{ {
speed = Math::Vector(0.0f, -10.0f, 0.0f); // against the bottom speed = glm::vec3(0.0f, -10.0f, 0.0f); // against the bottom
} }
else else
{ {
@ -3423,7 +3423,7 @@ void CPhysics::MotorParticle(float aTime, float rTime)
m_particle->CreateParticle(pos, speed, dim, Gfx::PARTISCRAPS, 2.0f, 10.0f); m_particle->CreateParticle(pos, speed, dim, Gfx::PARTISCRAPS, 2.0f, 10.0f);
pos = Math::Vector(0.0f, 1.0f, 0.0f); pos = glm::vec3(0.0f, 1.0f, 0.0f);
pos = Transform(*mat, pos); pos = Transform(*mat, pos);
speed.x = (Math::Rand()-0.5f)*1.0f; speed.x = (Math::Rand()-0.5f)*1.0f;
@ -3463,7 +3463,7 @@ void CPhysics::MotorParticle(float aTime, float rTime)
if ( aTime-m_lastMotorParticle < m_engine->ParticleAdapt(0.06f) ) return; if ( aTime-m_lastMotorParticle < m_engine->ParticleAdapt(0.06f) ) return;
m_lastMotorParticle = aTime; m_lastMotorParticle = aTime;
pos = Math::Vector(0.0f, 3.0f, 0.0f); pos = glm::vec3(0.0f, 3.0f, 0.0f);
mat = m_object->GetWorldMatrix(0); mat = m_object->GetWorldMatrix(0);
pos = Transform(*mat, pos); pos = Transform(*mat, pos);
pos.x += (Math::Rand()-0.5f)*1.0f; pos.x += (Math::Rand()-0.5f)*1.0f;
@ -3489,7 +3489,7 @@ void CPhysics::MotorParticle(float aTime, float rTime)
if ( aTime-m_lastMotorParticle < m_engine->ParticleAdapt(0.06f) ) return; if ( aTime-m_lastMotorParticle < m_engine->ParticleAdapt(0.06f) ) return;
m_lastMotorParticle = aTime; m_lastMotorParticle = aTime;
pos = Math::Vector(0.0f, 3.0f, 0.0f); pos = glm::vec3(0.0f, 3.0f, 0.0f);
mat = m_object->GetWorldMatrix(0); mat = m_object->GetWorldMatrix(0);
pos = Transform(*mat, pos); pos = Transform(*mat, pos);
pos.x += (Math::Rand()-0.5f)*1.0f; pos.x += (Math::Rand()-0.5f)*1.0f;
@ -3524,7 +3524,7 @@ void CPhysics::MotorParticle(float aTime, float rTime)
if ( aTime-m_lastMotorParticle < m_engine->ParticleAdapt(0.1f) ) return; if ( aTime-m_lastMotorParticle < m_engine->ParticleAdapt(0.1f) ) return;
m_lastMotorParticle = aTime; m_lastMotorParticle = aTime;
pos = Math::Vector(-2.5f, 10.3f, -1.3f); pos = glm::vec3(-2.5f, 10.3f, -1.3f);
pos.x += (Math::Rand()-0.5f)*1.0f; pos.x += (Math::Rand()-0.5f)*1.0f;
pos.z += (Math::Rand()-0.5f)*1.0f; pos.z += (Math::Rand()-0.5f)*1.0f;
mat = m_object->GetWorldMatrix(0); mat = m_object->GetWorldMatrix(0);
@ -3546,7 +3546,7 @@ void CPhysics::MotorParticle(float aTime, float rTime)
if ( aTime-m_lastMotorParticle < m_engine->ParticleAdapt(0.05f) ) return; if ( aTime-m_lastMotorParticle < m_engine->ParticleAdapt(0.05f) ) return;
m_lastMotorParticle = aTime; m_lastMotorParticle = aTime;
pos = Math::Vector(-3.4f, 1.8f, 0.5f); pos = glm::vec3(-3.4f, 1.8f, 0.5f);
speed = pos; speed = pos;
if ( m_linMotion.currentSpeed.x < 0.0f ) if ( m_linMotion.currentSpeed.x < 0.0f )
@ -3578,10 +3578,10 @@ void CPhysics::MotorParticle(float aTime, float rTime)
// Generates some particles after falling into the water. // Generates some particles after falling into the water.
void CPhysics::WaterParticle(float aTime, Math::Vector pos, ObjectType type, void CPhysics::WaterParticle(float aTime, glm::vec3 pos, ObjectType type,
float floor, float advance, float turn) float floor, float advance, float turn)
{ {
Math::Vector ppos, speed; glm::vec3 ppos{ 0, 0, 0 }, speed{ 0, 0, 0 };
glm::vec2 dim; glm::vec2 dim;
float delay, level, min, max, force, volume, diam; float delay, level, min, max, force, volume, diam;
int i, nb; int i, nb;
@ -3625,7 +3625,7 @@ void CPhysics::WaterParticle(float aTime, Math::Vector pos, ObjectType type,
pos.y = m_water->GetLevel()-1.0f; pos.y = m_water->GetLevel()-1.0f;
dim.x = 2.0f*force; // height dim.x = 2.0f*force; // height
dim.y = diam; // diameter dim.y = diam; // diameter
m_particle->CreateParticle(pos, Math::Vector(0.0f, 0.0f, 0.0f), dim, Gfx::PARTIPLOUF0, 1.4f, 0.0f, 0.0f); m_particle->CreateParticle(pos, glm::vec3(0.0f, 0.0f, 0.0f), dim, Gfx::PARTIPLOUF0, 1.4f, 0.0f, 0.0f);
force = (0.5f+force*0.5f); force = (0.5f+force*0.5f);
nb = static_cast<int>(force*50.0f*m_engine->GetParticleDensity()); nb = static_cast<int>(force*50.0f*m_engine->GetParticleDensity());
@ -3697,7 +3697,7 @@ void CPhysics::WaterParticle(float aTime, Math::Vector pos, ObjectType type,
void CPhysics::WheelParticle(TraceColor color, float width) void CPhysics::WheelParticle(TraceColor color, float width)
{ {
Math::Matrix* mat; Math::Matrix* mat;
Math::Vector goal1, goal2, wheel1, wheel2; glm::vec3 goal1{ 0, 0, 0 }, goal2{ 0, 0, 0 }, wheel1{ 0, 0, 0 }, wheel2{ 0, 0, 0 };
float dist1, dist2, step; float dist1, dist2, step;
mat = m_object->GetWorldMatrix(0); mat = m_object->GetWorldMatrix(0);

View File

@ -72,23 +72,23 @@ enum PhysicsMode
struct Motion struct Motion
{ {
Math::Vector advanceAccel; // acceleration starting (+) glm::vec3 advanceAccel{ 0, 0, 0 }; // acceleration starting (+)
Math::Vector recedeAccel; // acceleration starting (+) glm::vec3 recedeAccel{ 0, 0, 0 }; // acceleration starting (+)
Math::Vector stopAccel; // acceleration stoping (+) glm::vec3 stopAccel{ 0, 0, 0 }; // acceleration stoping (+)
Math::Vector motorAccel; // current acceleration (+/-) glm::vec3 motorAccel{ 0, 0, 0 }; // current acceleration (+/-)
Math::Vector advanceSpeed; // forward speed (+) glm::vec3 advanceSpeed{ 0, 0, 0 }; // forward speed (+)
Math::Vector recedeSpeed; // reversing speed (+) glm::vec3 recedeSpeed{ 0, 0, 0 }; // reversing speed (+)
Math::Vector motorSpeed; // desired speed (+/-) glm::vec3 motorSpeed{ 0, 0, 0 }; // desired speed (+/-)
Math::Vector currentSpeed; // current speed (+/-) glm::vec3 currentSpeed{ 0, 0, 0 }; // current speed (+/-)
Math::Vector terrainForce; // power of resistance of the ground (+) glm::vec3 terrainForce{ 0, 0, 0 }; // power of resistance of the ground (+)
Math::Vector terrainSpeed; // speed of the ground (+/-) glm::vec3 terrainSpeed{ 0, 0, 0 }; // speed of the ground (+/-)
Math::Vector terrainSlide; // limit sliding speed (+) glm::vec3 terrainSlide{ 0, 0, 0 }; // limit sliding speed (+)
Math::Vector realSpeed; // real speed(+/-) glm::vec3 realSpeed{ 0, 0, 0 }; // real speed(+/-)
Math::Vector finalInclin; // final inclination glm::vec3 finalInclin{ 0, 0, 0 }; // final inclination
}; };
@ -114,8 +114,8 @@ public:
float GetFloorHeight(); float GetFloorHeight();
void SetLinMotion(PhysicsMode mode, Math::Vector value); void SetLinMotion(PhysicsMode mode, glm::vec3 value);
Math::Vector GetLinMotion(PhysicsMode mode); glm::vec3 GetLinMotion(PhysicsMode mode);
void SetLinMotionX(PhysicsMode mode, float value); void SetLinMotionX(PhysicsMode mode, float value);
void SetLinMotionY(PhysicsMode mode, float value); void SetLinMotionY(PhysicsMode mode, float value);
void SetLinMotionZ(PhysicsMode mode, float value); void SetLinMotionZ(PhysicsMode mode, float value);
@ -123,8 +123,8 @@ public:
float GetLinMotionY(PhysicsMode mode); float GetLinMotionY(PhysicsMode mode);
float GetLinMotionZ(PhysicsMode mode); float GetLinMotionZ(PhysicsMode mode);
void SetCirMotion(PhysicsMode mode, Math::Vector value); void SetCirMotion(PhysicsMode mode, glm::vec3 value);
Math::Vector GetCirMotion(PhysicsMode mode); glm::vec3 GetCirMotion(PhysicsMode mode);
void SetCirMotionX(PhysicsMode mode, float value); void SetCirMotionX(PhysicsMode mode, float value);
void SetCirMotionY(PhysicsMode mode, float value); void SetCirMotionY(PhysicsMode mode, float value);
void SetCirMotionZ(PhysicsMode mode, float value); void SetCirMotionZ(PhysicsMode mode, float value);
@ -149,11 +149,11 @@ public:
void SetFreeze(bool bFreeze); void SetFreeze(bool bFreeze);
bool GetFreeze(); bool GetFreeze();
void SetMotorSpeed(Math::Vector speed); void SetMotorSpeed(glm::vec3 speed);
void SetMotorSpeedX(float speed); void SetMotorSpeedX(float speed);
void SetMotorSpeedY(float speed); void SetMotorSpeedY(float speed);
void SetMotorSpeedZ(float speed); void SetMotorSpeedZ(float speed);
Math::Vector GetMotorSpeed(); glm::vec3 GetMotorSpeed();
float GetMotorSpeedX(); float GetMotorSpeedX();
float GetMotorSpeedY(); float GetMotorSpeedY();
float GetMotorSpeedZ(); float GetMotorSpeedZ();
@ -181,10 +181,10 @@ protected:
void MotorUpdate(float aTime, float rTime); void MotorUpdate(float aTime, float rTime);
void EffectUpdate(float aTime, float rTime); void EffectUpdate(float aTime, float rTime);
void UpdateMotionStruct(float rTime, Motion &motion); void UpdateMotionStruct(float rTime, Motion &motion);
void FloorAdapt(float aTime, float rTime, Math::Vector &pos, Math::Vector &angle); void FloorAdapt(float aTime, float rTime, glm::vec3 &pos, glm::vec3 &angle);
void FloorAngle(const Math::Vector &pos, Math::Vector &angle); void FloorAngle(const glm::vec3 &pos, glm::vec3 &angle);
int ObjectAdapt(const Math::Vector &pos, const Math::Vector &angle); int ObjectAdapt(const glm::vec3 &pos, const glm::vec3 &angle);
bool JostleObject(CJostleableObject* pObj, Math::Vector iPos, float iRad); bool JostleObject(CJostleableObject* pObj, glm::vec3 iPos, float iRad);
bool JostleObject(CObject* pObj, float force); bool JostleObject(CObject* pObj, float force);
bool ExploOther(ObjectType iType, CObject *pObj, ObjectType oType, float force); bool ExploOther(ObjectType iType, CObject *pObj, ObjectType oType, float force);
int ExploHimself(ObjectType iType, ObjectType oType, float force); int ExploHimself(ObjectType iType, ObjectType oType, float force);
@ -192,7 +192,7 @@ protected:
void PowerParticle(float factor, bool bBreak); void PowerParticle(float factor, bool bBreak);
void CrashParticle(float crash); void CrashParticle(float crash);
void MotorParticle(float aTime, float rTime); void MotorParticle(float aTime, float rTime);
void WaterParticle(float aTime, Math::Vector pos, ObjectType type, float floor, float advance, float turn); void WaterParticle(float aTime, glm::vec3 pos, ObjectType type, float floor, float advance, float turn);
void WheelParticle(TraceColor color, float width); void WheelParticle(TraceColor color, float width);
void SetFalling(); void SetFalling();
@ -210,7 +210,7 @@ protected:
float m_gravity; // force of gravity float m_gravity; // force of gravity
float m_time; // absolute time float m_time; // absolute time
Math::Vector m_motorSpeed; // motor speed (-1..1) glm::vec3 m_motorSpeed{ 0, 0, 0 }; // motor speed (-1..1)
Motion m_linMotion; // linear motion Motion m_linMotion; // linear motion
Motion m_cirMotion; // circular motion Motion m_cirMotion; // circular motion
bool m_bMotor; bool m_bMotor;
@ -231,7 +231,7 @@ protected:
float m_lastPloufParticle; float m_lastPloufParticle;
float m_lastFlameParticle; float m_lastFlameParticle;
bool m_bWheelParticleBrake; bool m_bWheelParticleBrake;
Math::Vector m_wheelParticlePos[2]; glm::vec3 m_wheelParticlePos[2];
float m_absorbWater; float m_absorbWater;
float m_reactorTemperature; float m_reactorTemperature;
float m_timeReactorFail; float m_timeReactorFail;

View File

@ -574,8 +574,7 @@ void CALSound::SetListener(const Math::Vector &eye, const Math::Vector &lookat)
{ {
m_eye = eye; m_eye = eye;
m_lookat = lookat; m_lookat = lookat;
Math::Vector forward = lookat - eye; Math::Vector forward = glm::normalize(lookat - eye);
forward.Normalize();
float orientation[] = {forward.x, forward.y, forward.z, 0.f, -1.0f, 0.0f}; float orientation[] = {forward.x, forward.y, forward.z, 0.f, -1.0f, 0.0f};
alListener3f(AL_POSITION, eye.x, eye.y, eye.z); alListener3f(AL_POSITION, eye.x, eye.y, eye.z);

View File

@ -26,12 +26,9 @@
#include "sound/sound_type.h" #include "sound/sound_type.h"
#include <string> #include "math/vector.h"
namespace Math #include <string>
{
struct Vector;
} // namespace Math
/*! /*!
* Maximum possible audio volume * Maximum possible audio volume

View File

@ -38,7 +38,7 @@ TEST(VectorTest, LengthTest)
Math::Vector vec(-1.288447945923275, 0.681452565308134, -0.633761098985957); Math::Vector vec(-1.288447945923275, 0.681452565308134, -0.633761098985957);
const float expectedLength = 1.58938001708428; const float expectedLength = 1.58938001708428;
EXPECT_TRUE(Math::IsEqual(vec.Length(), expectedLength, TEST_TOLERANCE)); EXPECT_TRUE(Math::IsEqual(glm::length(vec), expectedLength, TEST_TOLERANCE));
} }
TEST(VectorTest, NormalizeTest) TEST(VectorTest, NormalizeTest)
@ -46,7 +46,7 @@ TEST(VectorTest, NormalizeTest)
Math::Vector vec(1.848877241804398, -0.157262961268577, -1.963031403332377); Math::Vector vec(1.848877241804398, -0.157262961268577, -1.963031403332377);
const Math::Vector expectedNormalized(0.6844609421393856, -0.0582193085618106, -0.7267212194481797); const Math::Vector expectedNormalized(0.6844609421393856, -0.0582193085618106, -0.7267212194481797);
vec.Normalize(); vec = glm::normalize(vec);
EXPECT_TRUE(Math::VectorsEqual(vec, expectedNormalized, TEST_TOLERANCE)); EXPECT_TRUE(Math::VectorsEqual(vec, expectedNormalized, TEST_TOLERANCE));
} }
@ -69,7 +69,7 @@ TEST(VectorTest, CrossTest)
Math::Vector expectedCross(-1.937932065431669, 2.978844370287636, -0.437739173833581); Math::Vector expectedCross(-1.937932065431669, 2.978844370287636, -0.437739173833581);
Math::Vector expectedReverseCross = -expectedCross; Math::Vector expectedReverseCross = -expectedCross;
EXPECT_TRUE(Math::VectorsEqual(vecA.CrossMultiply(vecB), expectedCross, TEST_TOLERANCE)); EXPECT_TRUE(Math::VectorsEqual(glm::cross(vecA, vecB), expectedCross, TEST_TOLERANCE));
EXPECT_TRUE(Math::VectorsEqual(vecB.CrossMultiply(vecA), expectedReverseCross, TEST_TOLERANCE)); EXPECT_TRUE(Math::VectorsEqual(glm::cross(vecB, vecA), expectedReverseCross, TEST_TOLERANCE));
} }