SHADE_Y3/SHADE_Engine/SHGhostBody.cpp

51 lines
2.5 KiB
C++
Raw Normal View History

2023-03-20 14:53:36 +08:00
/****************************************************************************************
* \file SHGhostBody.cpp
* \author Diren D Bharwani, diren.dbharwani, 390002520
* \brief Implementation for the Ghost Body meant for Simulation.
*
* \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
* disclosure of this file or its contents without the prior written consent
* of DigiPen Institute of Technology is prohibited.
****************************************************************************************/
#include <SHpch.h>
// Primary Header
#include "SHGhostBody.h"
namespace SHADE
{
/*-----------------------------------------------------------------------------------*/
/* Constructors & Destructor Definitions */
/*-----------------------------------------------------------------------------------*/
SHGhostBody::SHGhostBody(const SHRigidBodyComponent& rigidBody) noexcept
: linearVelocity { rigidBody.GetLinearVelocity() }
, angularVelocity { rigidBody.GetAngularVelocity() }
, localCentroid { rigidBody.GetLocalCentroid() }
, accumulatedForce { rigidBody.GetForce() }
, accumulatedTorque{ rigidBody.GetTorque() }
, gravityScale { rigidBody.GetGravityScale() }
, mass { rigidBody.GetMass() }
, drag { rigidBody.GetDrag() }
, angularDrag { rigidBody.GetAngularDrag() }
, position { rigidBody.GetPosition() }
, orientation { SHQuaternion::FromEuler(rigidBody.GetRotation()) }
, useGravity { rigidBody.IsGravityEnabled() }
{
const SHVec3 LOCAL_INERTIA = rigidBody.GetLocalInertia();
localInvInertia.x = 1.0f / LOCAL_INERTIA.x;
localInvInertia.y = 1.0f / LOCAL_INERTIA.y;
localInvInertia.z = 1.0f / LOCAL_INERTIA.z;
linearLock.x = rigidBody.GetFreezePositionX() ? 1.0f : 0.0f;
linearLock.y = rigidBody.GetFreezePositionY() ? 1.0f : 0.0f;
linearLock.z = rigidBody.GetFreezePositionZ() ? 1.0f : 0.0f;
angularLock.x = rigidBody.GetFreezeRotationX() ? 1.0f : 0.0f;
angularLock.y = rigidBody.GetFreezeRotationY() ? 1.0f : 0.0f;
angularLock.z = rigidBody.GetFreezeRotationZ() ? 1.0f : 0.0f;
}
} // namespace SHADE