# Khaotic Engine Reborn: object Class Reference

Loading...
Searching...
No Matches
object Class Reference
Inheritance diagram for object:

## Public Member Functions

| object (application_class &app)
| object (const object &)=delete
object & | operator= (const object &)=delete
bool | Initialize (ID3D11Device *device, ID3D11DeviceContext *deviceContext, char *modelFilename, TextureContainer &texturesContainer)
void | SetScaleMatrix (XMMATRIX scaleMatrix)
void | SetRotateMatrix (XMMATRIX rotateMatrix)
void | SetTranslateMatrix (XMMATRIX translateMatrix)
void | SetSRMatrix (XMMATRIX srMatrix)
void | SetWorldMatrix (XMMATRIX worldMatrix)
void | SetPosition (XMVECTOR position)
void | SetRotation (XMVECTOR rotation)
void | SetScale (XMVECTOR scale)
XMMATRIX | GetScaleMatrix () const
XMMATRIX | GetRotateMatrix () const
XMMATRIX | GetTranslateMatrix () const
XMMATRIX | GetSRMatrix () const
XMMATRIX | GetWorldMatrix () const
XMVECTOR | GetPosition ()
XMVECTOR | GetRotation ()
XMVECTOR | GetScale ()
void | SetVelocity (XMVECTOR)
void | AddVelocity (float deltaTime)
XMVECTOR | GetVelocity () const
void | SetAcceleration (XMVECTOR)
XMVECTOR | GetAcceleration () const
void | SetMass (float)
float | GetMass () const
void | SetGrounded (bool)
bool | IsGrounded () const
bool | IsPhysicsEnabled () const
void | SetPhysicsEnabled (bool state)
void | SetVisible (bool state)
bool | IsVisible () const
void | UpdateWorldMatrix ()
void | UpdateSRMatrix ()
void | UpdateScaleMatrix ()
void | UpdateRotateMatrix ()
void | UpdateTranslateMatrix ()
void | UpdatePosition (float deltaTime)
void | Update ()
std::string | GetName ()
void | SetName (std::string name)
int | SetId (int id)
int | GetId () const
void | SetType (ObjectType type)
ObjectType | GetType () const
ShaderType | GetActiveShader () const
void | SetActiveShader (ShaderType activeShader)
float | GetBoundingRadius () const
void | SetBoundingRadius (float radius)
void | SetModelPath (std::wstring &path)
std::wstring & | GetModelPath ()
ShaderType | StringToShaderType (const std::string &shaderType)
std::string | ShaderTypeToString (ShaderType shaderType)
ObjectType | StringToObjectType (const std::string &objectType)
std::string | ObjectTypeToString (ObjectType objectType)
void | LaunchObject ()
bool | LoadTexturesFromPath (std::vector< std::wstring > &texturePaths, TextureContainer &texturesContainer, d_3d_class *m_Direct3D)
bool | SetupInstancing (ID3D11Device *device, const std::vector< XMMATRIX > &instanceTransforms)
void | EnableInstancing (bool enabled)
void | SetInstanceCount (int count)
bool | IsInstancingEnabled () const
int | GetInstanceCount () const
ID3D11Buffer * | GetInstanceBuffer () const
void | SetAlpha (float alpha)
float | GetAlpha () const
void | SetInitialStretch (float initialStretch)
float | GetInitialStretch () const
void | SetSpringConstant (float springConstant)
float | GetSpringConstant () const
bool | IsGravityEnabled () const
void | SetGravityEnabled (bool state)
std::shared_ptr< model_class > | get_model () const
void | SetModel (std::shared_ptr< model_class > model)

## Public Attributes

bool | m_demoSpinning = false
XMVECTOR | m_previousPosition
XMVECTOR | m_velocity
int | m_id
bool | m_gravityEnabled = true

## Detailed Description

Definition at line 29 of file object.h.

## Constructor & Destructor Documentation

## object() [1/2]

object::object | ( | application_class & | app | ) |

Definition at line 8 of file object.cpp.

: m_Application(app)// initialize the reference here
{
m_scaleMatrix = XMMatrixIdentity();
m_rotateMatrix = XMMatrixIdentity();
m_translateMatrix = XMMatrixIdentity();
m_srMatrix = XMMatrixIdentity();
m_worldMatrix = XMMatrixIdentity();
m_previousPosition = XMVectorZero();
m_velocity = XMVectorZero();
m_acceleration = XMVectorZero();
m_mass = NULL;
m_isGrounded = false;
m_id = NULL;
m_boundingRadius = 1.0f;
}

## object() [2/2]

object::object | ( |  | ) |

Definition at line 24 of file object.cpp.

: m_Application(*static_cast< application_class*>(nullptr)) // Remplacer suivant votre logique
{
m_scaleMatrix = XMMatrixIdentity();
m_rotateMatrix = XMMatrixIdentity();
m_translateMatrix = XMMatrixIdentity();
m_srMatrix = XMMatrixIdentity();
m_worldMatrix = XMMatrixIdentity();
m_previousPosition = XMVectorZero();
m_velocity = XMVectorZero();
m_acceleration = XMVectorZero();
m_mass = NULL;
m_isGrounded = false;
m_id = NULL;
m_boundingRadius = 1.0f;
}
application_class
Definition application_class.h:79

## ~object()

object::~object | ( |  | ) |

Definition at line 41 of file object.cpp.

{
}

## Member Function Documentation

## AddVelocity()

void object::AddVelocity | ( | float | deltaTime | ) |

Definition at line 240 of file object.cpp.

{
m_velocity += m_acceleration * deltaTime;
}

## get_model()

std::shared_ptr< model_class > object::get_model | ( |  | ) | const

inline

Definition at line 130 of file object.h.

{ return m_model_; }

## GetAcceleration()

XMVECTOR object::GetAcceleration | ( |  | ) | const

Definition at line 255 of file object.cpp.

{
return m_acceleration;
}

## GetActiveShader()

ShaderType object::GetActiveShader | ( |  | ) | const

inline

Definition at line 97 of file object.h.

{ return m_activeShader; };

## GetAlpha()

float object::GetAlpha | ( |  | ) | const

inline

Definition at line 121 of file object.h.

{ return m_alpha; }

## GetBoundingRadius()

float object::GetBoundingRadius | ( |  | ) | const

Definition at line 300 of file object.cpp.

{
return m_boundingRadius;
}

## GetId()

int object::GetId | ( |  | ) | const

Definition at line 285 of file object.cpp.

{
return m_id;
}

## GetInitialStretch()

float object::GetInitialStretch | ( |  | ) | const

inline

Definition at line 123 of file object.h.

{ return m_initialStretch; }

## GetMass()

float object::GetMass | ( |  | ) | const

Definition at line 265 of file object.cpp.

{
return m_mass;
}

## GetModelPath()

std::wstring & object::GetModelPath | ( |  | ) |

inline

Definition at line 104 of file object.h.

{ return m_modelPath; }

## GetName()

std::string object::GetName | ( |  | ) |

Definition at line 225 of file object.cpp.

{
return m_name;
}

## GetPosition()

XMVECTOR object::GetPosition | ( |  | ) |

Definition at line 123 of file object.cpp.

{
XMFLOAT4X4 matrix;
XMStoreFloat4x4(&matrix, m_translateMatrix);
return XMVectorSet(matrix._41, matrix._42, matrix._43, 0.0f);
}

## GetRotateMatrix()

XMMATRIX object::GetRotateMatrix | ( |  | ) | const

Definition at line 103 of file object.cpp.

{
return m_rotateMatrix;
}

## GetRotation()

XMVECTOR object::GetRotation | ( |  | ) |

Definition at line 130 of file object.cpp.

{
XMFLOAT4X4 matrix;
XMStoreFloat4x4(&matrix, m_rotateMatrix);
float rotationX = atan2f(matrix._32, matrix._33);
float rotationY = atan2f(-matrix._31, sqrtf(matrix._32 * matrix._32 + matrix._33 * matrix._33));
float rotationZ = atan2f(matrix._21, matrix._11);
return XMVectorSet(rotationX, rotationY, rotationZ, 0.0f);
}

## GetScale()

XMVECTOR object::GetScale | ( |  | ) |

Definition at line 140 of file object.cpp.

{
XMFLOAT4X4 matrix;
XMStoreFloat4x4(&matrix, m_scaleMatrix);
// Utiliser des vecteurs pour les lignes de la matrice
XMVECTOR row1 = XMLoadFloat3(reinterpret_cast<XMFLOAT3*>(&matrix._11));
XMVECTOR row2 = XMLoadFloat3(reinterpret_cast<XMFLOAT3*>(&matrix._21));
XMVECTOR row3 = XMLoadFloat3(reinterpret_cast<XMFLOAT3*>(&matrix._31));
// Calculer les longueurs des vecteurs
XMVECTOR scale = XMVectorSet(
XMVectorGetX(XMVector3Length(row1)),
XMVectorGetX(XMVector3Length(row2)),
XMVectorGetX(XMVector3Length(row3)),
0.0f
);
return scale;
}

## GetScaleMatrix()

XMMATRIX object::GetScaleMatrix | ( |  | ) | const

Definition at line 98 of file object.cpp.

{
return m_scaleMatrix;
}

## GetSpringConstant()

float object::GetSpringConstant | ( |  | ) | const

inline

Definition at line 125 of file object.h.

{ return m_springConstant; }

## GetSRMatrix()

XMMATRIX object::GetSRMatrix | ( |  | ) | const

Definition at line 113 of file object.cpp.

{
return m_srMatrix;
}

## GetTranslateMatrix()

XMMATRIX object::GetTranslateMatrix | ( |  | ) | const

Definition at line 108 of file object.cpp.

{
return m_translateMatrix;
}

## GetType()

ObjectType object::GetType | ( |  | ) | const

inline

Definition at line 95 of file object.h.

{ return m_type; };

## GetVelocity()

XMVECTOR object::GetVelocity | ( |  | ) | const

Definition at line 245 of file object.cpp.

{
return m_velocity;
}

## GetWorldMatrix()

XMMATRIX object::GetWorldMatrix | ( |  | ) | const

Definition at line 118 of file object.cpp.

{
return m_worldMatrix;
}

## Initialize()

bool object::Initialize | ( | ID3D11Device * | device,
|  | ID3D11DeviceContext * | deviceContext,
|  | char * | modelFilename,
|  | TextureContainer & | texturesContainer )

Definition at line 45 of file object.cpp.

{
std::string filename(modelFilename);
auto it = g_model_cache.find(filename);
if (it != g_model_cache.end())
{
m_model_ = it->second;
}
else
{
auto new_model = std::make_shared<model_class>();
if (!new_model->Initialize(device, deviceContext, modelFilename, texturesContainer))
{
return false;
}
g_model_cache[filename] = new_model;
m_model_ = new_model;
}
return true;
}

## IsGravityEnabled()

bool object::IsGravityEnabled | ( |  | ) | const

inline

Definition at line 127 of file object.h.

{ return m_gravityEnabled; }

## IsGrounded()

bool object::IsGrounded | ( |  | ) | const

Definition at line 275 of file object.cpp.

{
return m_isGrounded;
}

## IsPhysicsEnabled()

bool object::IsPhysicsEnabled | ( |  | ) | const

Definition at line 290 of file object.cpp.

{
return m_isPhysicsEnabled;
}

## IsVisible()

bool object::IsVisible | ( |  | ) | const

inline

Definition at line 78 of file object.h.

{ return m_isVisible; }

## LaunchObject()

void object::LaunchObject | ( |  | ) |

Definition at line 359 of file object.cpp.

{
// Constants
const float gravity = -9.81f;
// Convert alpha from degrees to radians if needed
float alphaRadians = m_alpha * (XM_PI / 180.0f);
// Scale factors to make the physics simulation more visible
float scaleFactor = 200.0f; // Adjust this based on your world scale
// Calculate initial velocity magnitude using the same formula as the Python code
// v_eject = l1 * sqrt(k/m) * sqrt(1 - (m*g*sin(alpha)/(k*l1))^2)
float velocityMagnitude = m_initialStretch * sqrtf(m_springConstant / m_mass) *
sqrtf(1.0f - powf((m_mass * gravity * sinf(alphaRadians) / (m_springConstant * m_initialStretch)), 2.0f));
// Apply scale factor
velocityMagnitude *= scaleFactor;
// Calculate velocity components
XMVECTOR velocity = XMVectorSet(
velocityMagnitude * cosf(alphaRadians), // vx = v0 * cos(alpha)
velocityMagnitude * sinf(alphaRadians), // vy = v0 * sin(alpha)
0.0f, // z-component (0 for 2D trajectory)
0.0f
);
// Apply velocity to object
SetVelocity(velocity);
// Enable physics for the object to handle the trajectory
SetPhysicsEnabled(true);
// Reset grounded state
SetGrounded(false);
// Debug output
char buffer[256];
sprintf_s(buffer, "Launch velocity: %f m/s at angle %f degrees", XMVectorGetX(XMVector3Length(velocity)), m_alpha);
OutputDebugStringA(buffer);
}

## LoadTexturesFromPath()

bool object::LoadTexturesFromPath | ( | std::vector< std::wstring > & | texturePaths,
|  | TextureContainer & | texturesContainer,
|  | d_3d_class * | m_Direct3D )

Definition at line 401 of file object.cpp.

{
HRESULT result;
int i = 0;
TextureType type;
for (const auto& texturePath : texturePaths)
{
ID3D11ShaderResourceView* texture = nullptr;
result = DirectX::CreateWICTextureFromFile(m_Direct3D->get_device(), m_Direct3D->get_device_context(), texturePath.c_str(), nullptr, &texture);
if (FAILED(result))
{
// Utiliser _com_error pour obtenir des informations détaillées sur l'erreur
_com_error err(result);
LPCTSTR errMsg = err.ErrorMessage();
//convertie errMessage en std::wstring
std::wstring ws(errMsg);
std::string str(ws.begin(), ws.end());
Logger::Get().Log("Failed to load texture: " + std::string(texturePath.begin(), texturePath.end()) +
"\nError: " + std::to_string(result) +
"\nDescription: " + str,
__FILE__, __LINE__, Logger::LogLevel::Error);
return false; // Assurez-vous de retourner false ou de gérer l'erreur de manière appropriée
}
texturesContainer.AssignTexture(texturesContainer, texture,texturePath , i);
i++;
}
return true;
}

## ObjectTypeToString()

std::string object::ObjectTypeToString | ( | ObjectType | objectType | ) |

Definition at line 317 of file object.cpp.

{
switch (type) {
case ObjectType::Cube: return "Cube";
case ObjectType::Sphere: return "Sphere";
// Ajoutez d'autres cas si nécessaire
default: return "Unknown";
}
}

## SetAcceleration()

void object::SetAcceleration | ( | XMVECTOR | acceleration | ) |

Definition at line 250 of file object.cpp.

{
m_acceleration = acceleration;
}

## SetActiveShader()

void object::SetActiveShader | ( | ShaderType | activeShader | ) |

inline

Definition at line 98 of file object.h.

{ m_activeShader = activeShader; };

## SetAlpha()

void object::SetAlpha | ( | float | alpha | ) |

inline

Definition at line 120 of file object.h.

{ m_alpha = alpha; }

## SetBoundingRadius()

void object::SetBoundingRadius | ( | float | radius | ) |

inline

Definition at line 101 of file object.h.

{ m_boundingRadius = radius; }

## SetGravityEnabled()

void object::SetGravityEnabled | ( | bool | state | ) |

inline

Definition at line 128 of file object.h.

{ m_gravityEnabled = state; }

## SetGrounded()

void object::SetGrounded | ( | bool | isGrounded | ) |

Definition at line 270 of file object.cpp.

{
m_isGrounded = isGrounded;
}

## SetId()

int object::SetId | ( | int | id | ) |

Definition at line 280 of file object.cpp.

{
return m_id = id;
}

## SetInitialStretch()

void object::SetInitialStretch | ( | float | initialStretch | ) |

inline

Definition at line 122 of file object.h.

{ m_initialStretch = initialStretch; }

## SetMass()

void object::SetMass | ( | float | mass | ) |

Definition at line 260 of file object.cpp.

{
m_mass = mass;
}

## SetModel()

void object::SetModel | ( | std::shared_ptr< model_class > | model | ) |

inline

Definition at line 131 of file object.h.

{ m_model_ = model; }

## SetModelPath()

void object::SetModelPath | ( | std::wstring & | path | ) |

inline

Definition at line 103 of file object.h.

{ m_modelPath = path; }

## SetName()

void object::SetName | ( | std::string | name | ) |

Definition at line 230 of file object.cpp.

{
m_name = name;
}

## SetPhysicsEnabled()

void object::SetPhysicsEnabled | ( | bool | state | ) |

Definition at line 295 of file object.cpp.

{
m_isPhysicsEnabled = state;
}

## SetPosition()

void object::SetPosition | ( | XMVECTOR | position | ) |

Definition at line 163 of file object.cpp.

{
XMFLOAT4X4 matrix;
XMStoreFloat4x4(&matrix, m_translateMatrix);
matrix._41 = XMVectorGetX(position);
matrix._42 = XMVectorGetY(position);
matrix._43 = XMVectorGetZ(position);
m_translateMatrix = XMLoadFloat4x4(&matrix);
}

## SetRotateMatrix()

void object::SetRotateMatrix | ( | XMMATRIX | rotateMatrix | ) |

Definition at line 78 of file object.cpp.

{
m_rotateMatrix = rotateMatrix;
}

## SetRotation()

void object::SetRotation | ( | XMVECTOR | rotation | ) |

Definition at line 173 of file object.cpp.

{
XMFLOAT4X4 matrix;
XMStoreFloat4x4(&matrix, m_rotateMatrix);
XMMATRIX rotationMatrix = XMMatrixRotationRollPitchYaw(XMVectorGetX(rotation), XMVectorGetY(rotation), XMVectorGetZ(rotation));
m_rotateMatrix = rotationMatrix;
}

## SetScale()

void object::SetScale | ( | XMVECTOR | scale | ) |

Definition at line 181 of file object.cpp.

{
XMFLOAT4X4 matrix;
XMStoreFloat4x4(&matrix, m_scaleMatrix);
matrix._11 = XMVectorGetX(scale);
matrix._22 = XMVectorGetY(scale);
matrix._33 = XMVectorGetZ(scale);
m_scaleMatrix = XMLoadFloat4x4(&matrix);
}

## SetScaleMatrix()

void object::SetScaleMatrix | ( | XMMATRIX | scaleMatrix | ) |

Definition at line 73 of file object.cpp.

{
m_scaleMatrix = scaleMatrix;
}

## SetSpringConstant()

void object::SetSpringConstant | ( | float | springConstant | ) |

inline

Definition at line 124 of file object.h.

{ m_springConstant = springConstant; }

## SetSRMatrix()

void object::SetSRMatrix | ( | XMMATRIX | srMatrix | ) |

Definition at line 88 of file object.cpp.

{
m_srMatrix = srMatrix;
}

## SetTranslateMatrix()

void object::SetTranslateMatrix | ( | XMMATRIX | translateMatrix | ) |

Definition at line 83 of file object.cpp.

{
m_translateMatrix = translateMatrix;
}

## SetType()

void object::SetType | ( | ObjectType | type | ) |

Definition at line 312 of file object.cpp.

{
m_type = type;
}

## SetVelocity()

void object::SetVelocity | ( | XMVECTOR | velocity | ) |

Definition at line 235 of file object.cpp.

{
m_velocity = velocity;
}

## SetVisible()

void object::SetVisible | ( | bool | state | ) |

inline

Definition at line 77 of file object.h.

{ m_isVisible = state; }

## SetWorldMatrix()

void object::SetWorldMatrix | ( | XMMATRIX | worldMatrix | ) |

Definition at line 93 of file object.cpp.

{
m_worldMatrix = worldMatrix;
}

## ShaderTypeToString()

std::string object::ShaderTypeToString | ( | ShaderType | shaderType | ) |

Definition at line 333 of file object.cpp.

{
switch (type) {
case ShaderType::ALPHA_MAPPING: return "ALPHA_MAPPING";
case ShaderType::CEL_SHADING: return "CEL_SHADING";
case ShaderType::NORMAL_MAPPING: return "NORMAL_MAPPING";
case ShaderType::SPECULAR_MAPPING: return "SPECULAR_MAPPING";
case ShaderType::TEXTURE: return "TEXTURE";
case ShaderType::LIGHTING: return "LIGHTING";
case ShaderType::SUNLIGHT: return "SUNLIGHT";
// Ajoutez d'autres cas si nécessaire
default: return "Unknown";
}
}

## StringToObjectType()

ObjectType object::StringToObjectType | ( | const std::string & | objectType | ) |

Definition at line 326 of file object.cpp.

{
if (str == "Cube") return ObjectType::Cube;
if (str == "Sphere") return ObjectType::Sphere;
// Add other cases as needed
return ObjectType::Unknown;
}

## StringToShaderType()

ShaderType object::StringToShaderType | ( | const std::string & | shaderType | ) |

Definition at line 347 of file object.cpp.

{
if (str == "ALPHA_MAPPING") return ShaderType::ALPHA_MAPPING;
if (str == "CEL_SHADING") return ShaderType::CEL_SHADING;
if (str == "NORMAL_MAPPING") return ShaderType::NORMAL_MAPPING;
if (str == "SPECULAR_MAPPING") return ShaderType::SPECULAR_MAPPING;
if (str == "TEXTURE") return ShaderType::TEXTURE;
if (str == "LIGHTING") return ShaderType::LIGHTING;
if (str == "SUNLIGHT") return ShaderType::SUNLIGHT;
// Add other cases as needed
return ShaderType::TEXTURE;
}

## Update()

void object::Update | ( |  | ) |

Definition at line 216 of file object.cpp.

{
UpdateWorldMatrix();
UpdateSRMatrix();
UpdateTranslateMatrix();
UpdateRotateMatrix();
UpdateScaleMatrix();
}

## UpdatePosition()

void object::UpdatePosition | ( | float | deltaTime | ) |

Definition at line 305 of file object.cpp.

{
XMVECTOR position = GetPosition();
position = position + GetVelocity() * deltaTime;
SetPosition(position);
}

## UpdateRotateMatrix()

void object::UpdateRotateMatrix | ( |  | ) |

Definition at line 206 of file object.cpp.

{
m_rotateMatrix = XMMatrixRotationRollPitchYawFromVector(GetRotation());
}

## UpdateScaleMatrix()

void object::UpdateScaleMatrix | ( |  | ) |

Definition at line 211 of file object.cpp.

{
m_scaleMatrix = XMMatrixScalingFromVector(GetScale());
}

## UpdateSRMatrix()

void object::UpdateSRMatrix | ( |  | ) |

Definition at line 196 of file object.cpp.

{
m_srMatrix = m_scaleMatrix * m_rotateMatrix;
}

## UpdateTranslateMatrix()

void object::UpdateTranslateMatrix | ( |  | ) |

Definition at line 201 of file object.cpp.

{
m_translateMatrix = XMMatrixTranslationFromVector(GetPosition());
}

## UpdateWorldMatrix()

void object::UpdateWorldMatrix | ( |  | ) |

Definition at line 191 of file object.cpp.

{
m_worldMatrix = m_scaleMatrix * m_rotateMatrix * m_translateMatrix;
}

## Member Data Documentation

## m_demoSpinning

bool object::m_demoSpinning = false

Definition at line 134 of file object.h.

## m_gravityEnabled

bool object::m_gravityEnabled = true

Definition at line 138 of file object.h.

## m_id

int object::m_id

Definition at line 137 of file object.h.

## m_previousPosition

XMVECTOR object::m_previousPosition

Definition at line 135 of file object.h.

## m_velocity

XMVECTOR object::m_velocity

Definition at line 136 of file object.h.

The documentation for this class was generated from the following files:

- enginecustom/src/inc/system/object.h
- enginecustom/src/src/system/object.cpp