Merge branch 'ImGui-NoScripting'
This commit is contained in:
commit
1e2a23f96c
@ -105,7 +105,7 @@ void CameraClass::Render()
|
||||
return;
|
||||
}
|
||||
|
||||
XMMATRIX CameraClass::GetViewMatrix(XMMATRIX& viewMatrix)
|
||||
XMMATRIX CameraClass::GetViewMatrix(XMMATRIX& viewMatrix) const
|
||||
{
|
||||
viewMatrix = m_viewMatrix;
|
||||
return viewMatrix;
|
||||
@ -164,7 +164,7 @@ void CameraClass::RenderReflection(float height)
|
||||
return;
|
||||
}
|
||||
|
||||
void CameraClass::GetReflectionViewMatrix(XMMATRIX& reflectionViewMatrix)
|
||||
void CameraClass::GetReflectionViewMatrix(XMMATRIX& reflectionViewMatrix) const
|
||||
{
|
||||
reflectionViewMatrix = m_reflectionViewMatrix;
|
||||
return;
|
||||
|
@ -30,10 +30,10 @@ public:
|
||||
|
||||
|
||||
void Render();
|
||||
XMMATRIX GetViewMatrix(XMMATRIX& viewMatrix);
|
||||
XMMATRIX GetViewMatrix(XMMATRIX& viewMatrix) const;
|
||||
|
||||
void RenderReflection(float);
|
||||
void GetReflectionViewMatrix(XMMATRIX&);
|
||||
void GetReflectionViewMatrix(XMMATRIX&) const;
|
||||
|
||||
private:
|
||||
float m_positionX, m_positionY, m_positionZ;
|
||||
|
@ -10,6 +10,11 @@ PositionClass::PositionClass()
|
||||
m_positionZ = 0.0f;
|
||||
m_leftTurnSpeed = 0.0f;
|
||||
m_rightTurnSpeed = 0.0f;
|
||||
m_horizontalTurnSpeed = 0.0f;
|
||||
m_verticalTurnSpeed = 0.0f;
|
||||
m_verticalTurnSpeed = 0.0f;
|
||||
m_cameraSpeed = 4.0f;
|
||||
m_speed = m_cameraSpeed;
|
||||
}
|
||||
|
||||
|
||||
@ -28,14 +33,14 @@ void PositionClass::SetFrameTime(float time)
|
||||
return;
|
||||
}
|
||||
|
||||
void PositionClass::GetRotation(float& y, float& x)
|
||||
void PositionClass::GetRotation(float& y, float& x) const
|
||||
{
|
||||
y = m_rotationY;
|
||||
x = m_rotationX;
|
||||
return;
|
||||
}
|
||||
|
||||
void PositionClass::GetPosition(float& x, float& y, float& z)
|
||||
void PositionClass::GetPosition(float& x, float& y, float& z) const
|
||||
{
|
||||
x = m_positionX;
|
||||
y = m_positionY;
|
||||
@ -108,11 +113,10 @@ void PositionClass::TurnRight(bool keydown)
|
||||
return;
|
||||
}
|
||||
|
||||
void PositionClass::TurnMouse(int deltaX, int deltaY, bool rightMouseDown)
|
||||
void PositionClass::TurnMouse(float deltaX, float deltaY, float sensitivity, bool rightMouseDown)
|
||||
{
|
||||
float speed = 0.1f;
|
||||
// The turning speed is proportional to the horizontal mouse movement
|
||||
m_horizontalTurnSpeed = deltaX * speed;
|
||||
m_horizontalTurnSpeed = deltaX * sensitivity;
|
||||
|
||||
if (rightMouseDown)
|
||||
{
|
||||
@ -128,7 +132,7 @@ void PositionClass::TurnMouse(int deltaX, int deltaY, bool rightMouseDown)
|
||||
}
|
||||
|
||||
// The turning speed is proportional to the vertical mouse movement
|
||||
m_verticalTurnSpeed = deltaY * speed;
|
||||
m_verticalTurnSpeed = deltaY * sensitivity;
|
||||
|
||||
// Update the rotation using the turning speed
|
||||
m_rotationX += m_verticalTurnSpeed;
|
||||
@ -144,19 +148,53 @@ void PositionClass::TurnMouse(int deltaX, int deltaY, bool rightMouseDown)
|
||||
return;
|
||||
}
|
||||
|
||||
void PositionClass::MoveCamera(bool forward, bool backward, bool left, bool right, bool up, bool down)
|
||||
void PositionClass::MoveCamera(bool forward, bool backward, bool left, bool right, bool up, bool down, bool scrollUp, bool scrollDown, bool rightClick)
|
||||
{
|
||||
float radiansY, radiansX;
|
||||
float speed;
|
||||
float radiansY, radiansX, speed;
|
||||
|
||||
// Set the speed of the camera.
|
||||
speed = 2.0f * m_frameTime;
|
||||
// Set the speed of the camera if the right click is down.
|
||||
if (scrollUp && rightClick)
|
||||
{
|
||||
m_cameraSpeed *= 1.1f;
|
||||
}
|
||||
if (scrollDown && rightClick)
|
||||
{
|
||||
m_cameraSpeed *= 0.9f;
|
||||
|
||||
if (m_cameraSpeed < 0.25f) // Minimum speed.
|
||||
{
|
||||
m_cameraSpeed = 0.25f;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert degrees to radians.
|
||||
radiansY = m_rotationY * 0.0174532925f;
|
||||
radiansX = m_rotationX * 0.0174532925f;
|
||||
|
||||
// Update the position.
|
||||
//////////////////////////
|
||||
// Update the position. //
|
||||
//////////////////////////
|
||||
|
||||
// Moves the camera forward on a greater scale than the arrows.
|
||||
if (scrollUp && !rightClick)
|
||||
{
|
||||
speed = m_speed * 20 * m_frameTime;
|
||||
m_positionX += sinf(radiansY) * cosf(radiansX) * speed;
|
||||
m_positionZ += cosf(radiansY) * cosf(radiansX) * speed;
|
||||
m_positionY -= sinf(radiansX) * speed;
|
||||
}
|
||||
|
||||
// Moves the camera backward on a greater scale than the arrows.
|
||||
if (scrollDown && !rightClick)
|
||||
{
|
||||
speed = m_speed * 20 * m_frameTime;
|
||||
m_positionX -= sinf(radiansY) * cosf(radiansX) * speed;
|
||||
m_positionZ -= cosf(radiansY) * cosf(radiansX) * speed;
|
||||
m_positionY += sinf(radiansX) * speed;
|
||||
}
|
||||
|
||||
// Set the speed of the camera.
|
||||
speed = m_cameraSpeed * m_frameTime;
|
||||
|
||||
// If moving forward, the position moves in the direction of the camera and accordingly to its angle.
|
||||
if (forward)
|
||||
|
@ -19,19 +19,19 @@ public:
|
||||
~PositionClass();
|
||||
|
||||
void SetFrameTime(float);
|
||||
void GetRotation(float&, float&);
|
||||
void GetPosition(float&, float&, float&);
|
||||
void GetRotation(float&, float&) const;
|
||||
void GetPosition(float&, float&, float&) const;
|
||||
|
||||
void TurnLeft(bool);
|
||||
void TurnRight(bool);
|
||||
void TurnMouse(int, int, bool);
|
||||
void MoveCamera(bool, bool, bool, bool, bool, bool);
|
||||
void TurnMouse(float, float, float, bool);
|
||||
void MoveCamera(bool, bool, bool, bool, bool, bool, bool, bool, bool);
|
||||
|
||||
private:
|
||||
float m_frameTime;
|
||||
float m_rotationY, m_rotationX;
|
||||
float m_positionX, m_positionY, m_positionZ;
|
||||
float m_leftTurnSpeed, m_rightTurnSpeed, m_horizontalTurnSpeed, m_verticalTurnSpeed;
|
||||
float m_leftTurnSpeed, m_rightTurnSpeed, m_horizontalTurnSpeed, m_verticalTurnSpeed, m_cameraSpeed, m_speed;
|
||||
};
|
||||
|
||||
#endif
|
@ -24,6 +24,7 @@ ApplicationClass::ApplicationClass() : m_ShouldQuit(false)
|
||||
m_Light = 0;
|
||||
m_RefractionTexture = 0;
|
||||
m_ReflectionTexture = 0;
|
||||
m_Physics = 0;
|
||||
}
|
||||
|
||||
|
||||
@ -360,6 +361,8 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
|
||||
}
|
||||
Logger::Get().Log("Application class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
|
||||
|
||||
m_Physics = new Physics;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -411,6 +414,12 @@ void ApplicationClass::Shutdown()
|
||||
delete m_BathModel;
|
||||
m_BathModel = 0;
|
||||
}
|
||||
// Release the physics object.
|
||||
if (m_Physics)
|
||||
{
|
||||
delete m_Physics;
|
||||
m_Physics = 0;
|
||||
}
|
||||
|
||||
// Release the frustum class object.
|
||||
if (m_Frustum)
|
||||
@ -588,11 +597,10 @@ void ApplicationClass::Shutdown()
|
||||
Logger::Get().Log("Application class shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
|
||||
}
|
||||
|
||||
|
||||
bool ApplicationClass::Frame(InputClass* Input)
|
||||
{
|
||||
int mouseX, mouseY, currentMouseX, currentMouseY;
|
||||
bool result, leftMouseDown, rightMouseDown, keyDown, buttonQ, buttonD, buttonZ, buttonS, buttonA, buttonE;
|
||||
bool result, leftMouseDown, rightMouseDown, keyLeft, keyRight, keyUp, keyDown, buttonQ, buttonD, buttonZ, buttonS, buttonA, buttonE, scrollUp, scrollDown;
|
||||
float rotationY, rotationX, positionX, positionY, positionZ;
|
||||
static float textureTranslation = 0.0f;
|
||||
|
||||
@ -601,9 +609,9 @@ bool ApplicationClass::Frame(InputClass* Input)
|
||||
static int lastMouseX = 0, lastMouseY = 0;
|
||||
|
||||
static float rotation = 360.0f;
|
||||
static float x = 0.f;
|
||||
static float y = 0.f;
|
||||
static float z = -8.f;
|
||||
static float x = 0.0f;
|
||||
static float y = 3.0f;
|
||||
static float z = 0.0f;
|
||||
|
||||
// Update the system stats.
|
||||
m_Timer->Frame();
|
||||
@ -639,17 +647,20 @@ bool ApplicationClass::Frame(InputClass* Input)
|
||||
m_Position->SetFrameTime(m_Timer->GetTime());
|
||||
|
||||
// Check if the left or right arrow key has been pressed, if so rotate the camera accordingly.
|
||||
keyDown = Input->IsLeftArrowPressed();
|
||||
m_Position->TurnLeft(keyDown);
|
||||
//keyDown = Input->IsLeftArrowPressed();
|
||||
//m_Position->TurnLeft(keyDown);
|
||||
|
||||
keyDown = Input->IsRightArrowPressed();
|
||||
m_Position->TurnRight(keyDown);
|
||||
//keyDown = Input->IsRightArrowPressed();
|
||||
//m_Position->TurnRight(keyDown);
|
||||
|
||||
m_Position->TurnMouse(deltaX, deltaY, rightMouseDown);
|
||||
m_Position->TurnMouse(deltaX, deltaY, 0.1f, rightMouseDown);
|
||||
|
||||
// Get the current view point rotation.
|
||||
m_Position->GetRotation(rotationY, rotationX);
|
||||
|
||||
scrollUp = Input->IsScrollUp();
|
||||
scrollDown = Input->IsScrollDown();
|
||||
|
||||
// Check if the a(q), d, w(z), s, q(a), e have been pressed, if so move the camera accordingly.
|
||||
buttonQ = Input->IsAPressed();
|
||||
buttonD = Input->IsDPressed();
|
||||
@ -657,7 +668,7 @@ bool ApplicationClass::Frame(InputClass* Input)
|
||||
buttonS = Input->IsSPressed();
|
||||
buttonA = Input->IsQPressed();
|
||||
buttonE = Input->IsEPressed();
|
||||
m_Position->MoveCamera(buttonZ, buttonS, buttonQ, buttonD, buttonE, buttonA);
|
||||
m_Position->MoveCamera(buttonZ, buttonS, buttonQ, buttonD, buttonE, buttonA, scrollUp, scrollDown, rightMouseDown);
|
||||
m_Position->GetPosition(positionX, positionY, positionZ);
|
||||
|
||||
// Set the postion and rotation of the camera.
|
||||
@ -682,7 +693,7 @@ bool ApplicationClass::Frame(InputClass* Input)
|
||||
}
|
||||
|
||||
// Update the rotation variable each frame.
|
||||
rotation -= 0.0174532925f * speed;
|
||||
rotation -= 0.0174532925f * m_speed;
|
||||
if (rotation < 0.0f)
|
||||
{
|
||||
rotation += 360.0f;
|
||||
@ -708,6 +719,104 @@ bool ApplicationClass::Frame(InputClass* Input)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
//// Update the x position variable each frame.
|
||||
//x -= 0.0174532925f * 0.6f;
|
||||
|
||||
//y -= 0.0174532925f * 0.2f;
|
||||
|
||||
//// Update the z position variable each frame.
|
||||
//z -= 0.0174532925f * 0.2f;
|
||||
|
||||
keyLeft = Input->IsLeftArrowPressed();
|
||||
keyRight = Input->IsRightArrowPressed();
|
||||
keyUp = Input->IsUpArrowPressed();
|
||||
keyDown = Input->IsDownArrowPressed();
|
||||
|
||||
for (auto& object : m_object)
|
||||
{
|
||||
if (object != nullptr) // Check if the object is not null
|
||||
{
|
||||
// Reset acceleration for the new frame
|
||||
object->SetAcceleration(XMVectorZero());
|
||||
|
||||
object->SetGrounded(false);
|
||||
|
||||
for (auto& chunk : m_terrainChunk)
|
||||
{
|
||||
if (m_Physics->IsColliding(object, chunk))
|
||||
{
|
||||
|
||||
// Stop vertical movement, like gravity
|
||||
object->SetVelocity(XMVectorSetY(object->GetVelocity(), 0.0f));
|
||||
object->SetAcceleration(XMVectorSetY(object->GetAcceleration(), 0.0f));
|
||||
|
||||
//// Stop movement in any direction
|
||||
//object->SetVelocity(XMVectorZero());
|
||||
//object->SetAcceleration(XMVectorZero());
|
||||
object->SetGrounded(true);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& object2 : m_object)
|
||||
{
|
||||
if (object->GetId() != object2->GetId() && object2 != nullptr)
|
||||
{
|
||||
if (m_Physics->IsColliding(object, object2))
|
||||
{
|
||||
// Stop movement in any direction
|
||||
object->SetVelocity(XMVectorZero());
|
||||
object->SetAcceleration(XMVectorZero());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Apply forces
|
||||
float forceX = 0, forceY = 0, forceZ = 0, forceW = 0;
|
||||
|
||||
if (keyLeft)
|
||||
{
|
||||
forceX = -10.0f;
|
||||
}
|
||||
if (keyRight)
|
||||
{
|
||||
forceX = 10.0f;
|
||||
}
|
||||
if (keyUp)
|
||||
{
|
||||
forceY = 40.0f;
|
||||
}
|
||||
if (keyDown && !object->IsGrounded())
|
||||
{
|
||||
forceY = -40.0f;
|
||||
}
|
||||
|
||||
XMVECTOR force = XMVectorSet(forceX, forceY, forceZ, forceW);
|
||||
m_Physics->AddForce(object, force);
|
||||
|
||||
// Update velocity based on acceleration
|
||||
object->AddVelocity(frameTime);
|
||||
|
||||
// Update position based on velocity
|
||||
XMVECTOR position = object->GetPosition();
|
||||
position = position + object->GetVelocity() * frameTime;
|
||||
object->SetPosition(position);
|
||||
|
||||
m_Physics->ApplyGravity(object, 1.0f, frameTime);
|
||||
|
||||
// Check if the object has fallen below a certain position
|
||||
if (XMVectorGetY(object->GetPosition()) < -30.0f)
|
||||
{
|
||||
XMVECTOR currentPosition = object->GetPosition(); // Obtain the current position of the object
|
||||
object->SetPosition(XMVectorSetY(currentPosition, 50.0f)); // Define the new position of the object
|
||||
}
|
||||
|
||||
object->m_previousPosition = object->GetPosition();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Render the scene to a render texture.
|
||||
result = RenderSceneToTexture(rotation);
|
||||
@ -946,7 +1055,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
|
||||
}
|
||||
}
|
||||
|
||||
for (auto object : m_object)
|
||||
for (auto& object : m_object)
|
||||
{
|
||||
scaleMatrix = object->GetScaleMatrix();
|
||||
if (object->m_demoSpinning)
|
||||
@ -980,7 +1089,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z, float t
|
||||
}
|
||||
|
||||
// Render terrain
|
||||
for (auto chunk : m_terrainChunk)
|
||||
for (auto& chunk : m_terrainChunk)
|
||||
{
|
||||
|
||||
scaleMatrix = chunk->GetScaleMatrix();
|
||||
@ -1401,6 +1510,9 @@ void ApplicationClass::GenerateTerrain()
|
||||
Filename.push_back("light01.tga");
|
||||
Filename.push_back("moss01.tga");
|
||||
|
||||
std::filesystem::path p(modelFilename);
|
||||
std::string filenameWithoutExtension = p.stem().string();
|
||||
|
||||
// for loop to generate terrain chunks for a 10x10 grid
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
@ -1411,7 +1523,9 @@ void ApplicationClass::GenerateTerrain()
|
||||
|
||||
newTerrain->SetScaleMatrix(scaleMatrix);
|
||||
|
||||
newTerrain->SetTranslateMatrix(XMMatrixTranslation(i / 2 * (scaleX * 2), -5.0f, j * (scaleZ * 2)));
|
||||
newTerrain->SetTranslateMatrix(XMMatrixTranslation(i / 2 * (scaleX * 2), -10.0f, j * (scaleZ * 2)));
|
||||
|
||||
newTerrain->SetName(filenameWithoutExtension);
|
||||
|
||||
m_terrainChunk.push_back(newTerrain);
|
||||
|
||||
@ -1445,9 +1559,12 @@ void ApplicationClass::AddKobject(WCHAR* filepath)
|
||||
|
||||
Object* newObject = new Object();
|
||||
newObject->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, Filename);
|
||||
|
||||
newObject->SetTranslateMatrix(XMMatrixTranslation(0.0f, 0.0f, 0.0f));
|
||||
newObject->SetMass(1.0f);
|
||||
newObject->SetTranslateMatrix(XMMatrixTranslation(0.0f, 50.0f, 0.0f));
|
||||
newObject->SetName(filename);
|
||||
newObject->SetId(m_ObjectId);
|
||||
|
||||
m_ObjectId++;
|
||||
|
||||
m_object.push_back(newObject);
|
||||
}
|
||||
|
@ -26,6 +26,9 @@
|
||||
#include "frustumclass.h"
|
||||
#include "rendertextureclass.h"
|
||||
#include "displayplaneclass.h"
|
||||
#include "translateshaderclass.h"
|
||||
#include "reflectionshaderclass.h"
|
||||
#include "physics.h"
|
||||
|
||||
|
||||
/////////////
|
||||
@ -55,8 +58,8 @@ public:
|
||||
int GetScreenWidth() const;
|
||||
int GetScreenHeight() const;
|
||||
|
||||
float GetSpeed() const { return speed; };
|
||||
void SetSpeed(float speed) { this->speed = speed; };
|
||||
float GetSpeed() const { return m_speed; };
|
||||
void SetSpeed(float speed) { this->m_speed = speed; };
|
||||
|
||||
void AddCube();
|
||||
void DeleteKobject(int index);
|
||||
@ -119,8 +122,9 @@ private :
|
||||
Object* m_SelectedObject;
|
||||
std::vector<Object*> m_cubes;
|
||||
std::vector<Object*> m_terrainChunk;
|
||||
float speed = 0.1f; // speed for the demo spinning object
|
||||
float m_speed = 0.1f; // speed for the demo spinning object
|
||||
std::vector<Object*> m_object;
|
||||
int m_ObjectId = 0;
|
||||
|
||||
// ----------------------------------- //
|
||||
// ------------- LIGHTS -------------- //
|
||||
@ -162,6 +166,9 @@ private :
|
||||
// ------------------------------------------------- //
|
||||
|
||||
bool m_ShouldQuit;
|
||||
Physics* m_Physics;
|
||||
float m_gravity;
|
||||
XMVECTOR m_previousPosition;
|
||||
};
|
||||
|
||||
#endif
|
@ -50,6 +50,7 @@
|
||||
<ClCompile Include="normalmapshaderclass.cpp" />
|
||||
<ClCompile Include="refractionshaderclass.cpp" />
|
||||
<ClCompile Include="shadermanagerclass.cpp" />
|
||||
<ClCompile Include="physics.cpp" />
|
||||
<ClCompile Include="positionclass.cpp" />
|
||||
<ClCompile Include="reflectionshaderclass.cpp" />
|
||||
<ClCompile Include="rendertextureclass.cpp" />
|
||||
@ -97,6 +98,7 @@
|
||||
<ClInclude Include="normalmapshaderclass.h" />
|
||||
<ClInclude Include="refractionshaderclass.h" />
|
||||
<ClInclude Include="shadermanagerclass.h" />
|
||||
<ClInclude Include="physics.h" />
|
||||
<ClInclude Include="positionclass.h" />
|
||||
<ClInclude Include="reflectionshaderclass.h" />
|
||||
<ClInclude Include="rendertextureclass.h" />
|
||||
|
@ -126,9 +126,6 @@
|
||||
<ClCompile Include="alphamapshaderclass.cpp">
|
||||
<Filter>Fichiers sources</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="normalmapshaderclass.cpp">
|
||||
<Filter>Fichiers sources</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="specmapshaderclass.cpp">
|
||||
<Filter>Fichiers sources</Filter>
|
||||
</ClCompile>
|
||||
@ -168,6 +165,12 @@
|
||||
<ClCompile Include="refractionshaderclass.cpp">
|
||||
<Filter>Fichiers sources</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="physics.cpp">
|
||||
<Filter>Fichiers sources</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="normalmapshaderclass.cpp">
|
||||
<Filter>Fichiers sources</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="systemclass.h">
|
||||
@ -311,6 +314,9 @@
|
||||
<ClInclude Include="refractionshaderclass.h">
|
||||
<Filter>Fichiers d%27en-tête</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="physics.h">
|
||||
<Filter>Fichiers d%27en-tête</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="wall.tga">
|
||||
@ -331,10 +337,18 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
<None Include="water.vs" />
|
||||
<None Include="..\KhaoticDemo\water.ps" />
|
||||
<None Include="refraction.vs" />
|
||||
<None Include="refraction.ps" />
|
||||
<None Include="refraction.ps">
|
||||
<Filter>shader</Filter>
|
||||
</None>
|
||||
<None Include="refraction.vs">
|
||||
<Filter>shader</Filter>
|
||||
</None>
|
||||
<None Include="..\KhaoticDemo\water.ps">
|
||||
<Filter>shader</Filter>
|
||||
</None>
|
||||
<None Include="water.vs">
|
||||
<Filter>shader</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="sphere.txt">
|
||||
@ -380,26 +394,6 @@
|
||||
<CopyFileToFolders Include="plane.txt">
|
||||
<Filter>Assets</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="alphamap.ps" />
|
||||
<CopyFileToFolders Include="alphamap.vs" />
|
||||
<CopyFileToFolders Include="light.vs" />
|
||||
<CopyFileToFolders Include="lightmap.ps" />
|
||||
<CopyFileToFolders Include="lightmap.vs" />
|
||||
<CopyFileToFolders Include="Multitexture.ps" />
|
||||
<CopyFileToFolders Include="Multitexture.vs" />
|
||||
<CopyFileToFolders Include="normalmap.ps" />
|
||||
<CopyFileToFolders Include="normalmap.vs" />
|
||||
<CopyFileToFolders Include="reflection.ps" />
|
||||
<CopyFileToFolders Include="reflection.vs" />
|
||||
<CopyFileToFolders Include="specmap.ps" />
|
||||
<CopyFileToFolders Include="specmap.vs" />
|
||||
<CopyFileToFolders Include="texture.ps" />
|
||||
<CopyFileToFolders Include="texture.vs" />
|
||||
<CopyFileToFolders Include="transparent.ps" />
|
||||
<CopyFileToFolders Include="transparent.vs" />
|
||||
<CopyFileToFolders Include="Color.ps" />
|
||||
<CopyFileToFolders Include="translate.ps" />
|
||||
<CopyFileToFolders Include="translate.vs" />
|
||||
<CopyFileToFolders Include="alpha01.tga">
|
||||
<Filter>Assets</Filter>
|
||||
</CopyFileToFolders>
|
||||
@ -430,5 +424,65 @@
|
||||
<CopyFileToFolders Include="sprite04.tga">
|
||||
<Filter>Assets</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="Color.ps">
|
||||
<Filter>shader</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="light.vs">
|
||||
<Filter>shader</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="lightmap.ps">
|
||||
<Filter>shader</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="lightmap.vs">
|
||||
<Filter>shader</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="reflection.ps">
|
||||
<Filter>shader</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="reflection.vs">
|
||||
<Filter>shader</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="translate.ps">
|
||||
<Filter>shader</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="translate.vs">
|
||||
<Filter>shader</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="transparent.ps">
|
||||
<Filter>shader</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="transparent.vs">
|
||||
<Filter>shader</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="Multitexture.ps">
|
||||
<Filter>Texture</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="Multitexture.vs">
|
||||
<Filter>Texture</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="normalmap.ps">
|
||||
<Filter>Texture</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="normalmap.vs">
|
||||
<Filter>Texture</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="specmap.ps">
|
||||
<Filter>Texture</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="specmap.vs">
|
||||
<Filter>Texture</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="texture.ps">
|
||||
<Filter>Texture</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="texture.vs">
|
||||
<Filter>Texture</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="alphamap.vs">
|
||||
<Filter>Texture</Filter>
|
||||
</CopyFileToFolders>
|
||||
<CopyFileToFolders Include="alphamap.ps">
|
||||
<Filter>Texture</Filter>
|
||||
</CopyFileToFolders>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -138,7 +138,7 @@ void InputClass::KeyUp(unsigned int input)
|
||||
}
|
||||
|
||||
|
||||
bool InputClass::IsKeyDown(unsigned int key)
|
||||
bool InputClass::IsKeyDown(unsigned int key) const
|
||||
{
|
||||
// Return what state the key is in (pressed/not pressed).
|
||||
return m_keys[key];
|
||||
@ -267,7 +267,7 @@ void InputClass::ProcessInput()
|
||||
return;
|
||||
}
|
||||
|
||||
bool InputClass::IsEscapePressed()
|
||||
bool InputClass::IsEscapePressed() const
|
||||
{
|
||||
// Do a bitwise and on the keyboard state to check if the escape key is currently being pressed.
|
||||
if (m_keyboardState[DIK_ESCAPE] & 0x80)
|
||||
@ -278,7 +278,7 @@ bool InputClass::IsEscapePressed()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InputClass::IsLeftArrowPressed()
|
||||
bool InputClass::IsLeftArrowPressed() const
|
||||
{
|
||||
if (m_keyboardState[DIK_LEFT] & 0x80)
|
||||
{
|
||||
@ -290,7 +290,7 @@ bool InputClass::IsLeftArrowPressed()
|
||||
}
|
||||
|
||||
|
||||
bool InputClass::IsRightArrowPressed()
|
||||
bool InputClass::IsRightArrowPressed() const
|
||||
{
|
||||
if (m_keyboardState[DIK_RIGHT] & 0x80)
|
||||
{
|
||||
@ -301,11 +301,32 @@ bool InputClass::IsRightArrowPressed()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InputClass::IsUpArrowPressed() const
|
||||
{
|
||||
if (m_keyboardState[DIK_UP] & 0x80)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool InputClass::IsDownArrowPressed() const
|
||||
{
|
||||
if (m_keyboardState[DIK_DOWN] & 0x80)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
// Les touches correspondent aux claviers QWERTY //
|
||||
///////////////////////////////////////////////////
|
||||
|
||||
bool InputClass::IsAPressed()
|
||||
bool InputClass::IsAPressed() const
|
||||
{
|
||||
// Touche A sur QWERTY, Q sur AZERTY
|
||||
if (m_keyboardState[DIK_A] & 0x80)
|
||||
@ -317,7 +338,7 @@ bool InputClass::IsAPressed()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InputClass::IsDPressed()
|
||||
bool InputClass::IsDPressed() const
|
||||
{
|
||||
if (m_keyboardState[DIK_D] & 0x80)
|
||||
{
|
||||
@ -328,7 +349,7 @@ bool InputClass::IsDPressed()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InputClass::IsWPressed()
|
||||
bool InputClass::IsWPressed() const
|
||||
{
|
||||
// Touche W sur QWERTY, Z sur AZERTY
|
||||
if (m_keyboardState[DIK_W] & 0x80)
|
||||
@ -340,7 +361,7 @@ bool InputClass::IsWPressed()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InputClass::IsSPressed()
|
||||
bool InputClass::IsSPressed() const
|
||||
{
|
||||
if (m_keyboardState[DIK_S] & 0x80)
|
||||
{
|
||||
@ -351,7 +372,7 @@ bool InputClass::IsSPressed()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InputClass::IsQPressed()
|
||||
bool InputClass::IsQPressed() const
|
||||
{
|
||||
// Touche Q sur QWERTY, A sur AZERTY
|
||||
if (m_keyboardState[DIK_Q] & 0x80)
|
||||
@ -363,7 +384,7 @@ bool InputClass::IsQPressed()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InputClass::IsEPressed()
|
||||
bool InputClass::IsEPressed() const
|
||||
{
|
||||
if (m_keyboardState[DIK_E] & 0x80)
|
||||
{
|
||||
@ -374,14 +395,14 @@ bool InputClass::IsEPressed()
|
||||
return false;
|
||||
}
|
||||
|
||||
void InputClass::GetMouseLocation(int& mouseX, int& mouseY)
|
||||
void InputClass::GetMouseLocation(int& mouseX, int& mouseY) const
|
||||
{
|
||||
mouseX = m_mouseX;
|
||||
mouseY = m_mouseY;
|
||||
return;
|
||||
}
|
||||
|
||||
bool InputClass::IsLeftMousePressed()
|
||||
bool InputClass::IsLeftMousePressed() const
|
||||
{
|
||||
// Check the left mouse button state.
|
||||
if (m_mouseState.rgbButtons[0] & 0x80)
|
||||
@ -393,7 +414,7 @@ bool InputClass::IsLeftMousePressed()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InputClass::IsRightMousePressed()
|
||||
bool InputClass::IsRightMousePressed() const
|
||||
{
|
||||
// Check the left mouse button state.
|
||||
if (m_mouseState.rgbButtons[1] & 0x80)
|
||||
@ -404,3 +425,23 @@ bool InputClass::IsRightMousePressed()
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InputClass::IsScrollUp() const
|
||||
{
|
||||
if (m_mouseState.lZ > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InputClass::IsScrollDown() const
|
||||
{
|
||||
if (m_mouseState.lZ < 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -32,22 +32,26 @@ public:
|
||||
void Shutdown();
|
||||
bool Frame();
|
||||
|
||||
bool IsEscapePressed();
|
||||
void GetMouseLocation(int&, int&);
|
||||
bool IsLeftMousePressed();
|
||||
bool IsRightMousePressed();
|
||||
bool IsEscapePressed() const;
|
||||
void GetMouseLocation(int&, int&) const;
|
||||
bool IsLeftMousePressed() const;
|
||||
bool IsRightMousePressed() const;
|
||||
void KeyDown(unsigned int);
|
||||
void KeyUp(unsigned int);
|
||||
bool IsLeftArrowPressed();
|
||||
bool IsRightArrowPressed();
|
||||
bool IsAPressed();
|
||||
bool IsDPressed();
|
||||
bool IsWPressed();
|
||||
bool IsSPressed();
|
||||
bool IsQPressed();
|
||||
bool IsEPressed();
|
||||
bool IsLeftArrowPressed() const;
|
||||
bool IsRightArrowPressed() const;
|
||||
bool IsScrollUp() const;
|
||||
bool IsScrollDown() const;
|
||||
bool IsUpArrowPressed() const;
|
||||
bool IsDownArrowPressed() const;
|
||||
bool IsAPressed() const;
|
||||
bool IsDPressed() const;
|
||||
bool IsWPressed() const;
|
||||
bool IsSPressed() const;
|
||||
bool IsQPressed() const;
|
||||
bool IsEPressed()const;
|
||||
|
||||
bool IsKeyDown(unsigned int);
|
||||
bool IsKeyDown(unsigned int) const;
|
||||
|
||||
private:
|
||||
bool m_keys[256];
|
||||
|
@ -7,6 +7,12 @@ Object::Object() : ModelClass()
|
||||
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;
|
||||
}
|
||||
|
||||
Object::~Object()
|
||||
@ -38,27 +44,27 @@ void Object::SetWorldMatrix(XMMATRIX worldMatrix)
|
||||
m_worldMatrix = worldMatrix;
|
||||
}
|
||||
|
||||
XMMATRIX Object::GetScaleMatrix()
|
||||
XMMATRIX Object::GetScaleMatrix() const
|
||||
{
|
||||
return m_scaleMatrix;
|
||||
}
|
||||
|
||||
XMMATRIX Object::GetRotateMatrix()
|
||||
XMMATRIX Object::GetRotateMatrix() const
|
||||
{
|
||||
return m_rotateMatrix;
|
||||
}
|
||||
|
||||
XMMATRIX Object::GetTranslateMatrix()
|
||||
XMMATRIX Object::GetTranslateMatrix() const
|
||||
{
|
||||
return m_translateMatrix;
|
||||
}
|
||||
|
||||
XMMATRIX Object::GetSRMatrix()
|
||||
XMMATRIX Object::GetSRMatrix() const
|
||||
{
|
||||
return m_srMatrix;
|
||||
}
|
||||
|
||||
XMMATRIX Object::GetWorldMatrix()
|
||||
XMMATRIX Object::GetWorldMatrix() const
|
||||
{
|
||||
return m_worldMatrix;
|
||||
}
|
||||
@ -161,4 +167,60 @@ std::string Object::GetName()
|
||||
void Object::SetName(std::string name)
|
||||
{
|
||||
m_name = name;
|
||||
}
|
||||
}
|
||||
|
||||
void Object::SetVelocity(XMVECTOR velocity)
|
||||
{
|
||||
m_velocity = velocity;
|
||||
}
|
||||
|
||||
void Object::AddVelocity(float frameTime)
|
||||
{
|
||||
m_velocity += m_acceleration * frameTime;
|
||||
}
|
||||
|
||||
XMVECTOR Object::GetVelocity() const
|
||||
{
|
||||
return m_velocity;
|
||||
}
|
||||
|
||||
void Object::SetAcceleration(XMVECTOR acceleration)
|
||||
{
|
||||
m_acceleration = acceleration;
|
||||
}
|
||||
|
||||
XMVECTOR Object::GetAcceleration() const
|
||||
{
|
||||
return m_acceleration;
|
||||
}
|
||||
|
||||
void Object::SetMass(float mass)
|
||||
{
|
||||
m_mass = mass;
|
||||
}
|
||||
|
||||
float Object::GetMass() const
|
||||
{
|
||||
return m_mass;
|
||||
}
|
||||
|
||||
void Object::SetGrounded(bool isGrounded)
|
||||
{
|
||||
m_isGrounded = isGrounded;
|
||||
}
|
||||
|
||||
bool Object::IsGrounded() const
|
||||
{
|
||||
return m_isGrounded;
|
||||
}
|
||||
|
||||
int Object::SetId(int id)
|
||||
{
|
||||
return m_id = id;
|
||||
}
|
||||
|
||||
int Object::GetId() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
|
@ -17,16 +17,26 @@ public:
|
||||
void SetRotation(XMVECTOR rotation);
|
||||
void SetScale(XMVECTOR scale);
|
||||
|
||||
XMMATRIX GetScaleMatrix();
|
||||
XMMATRIX GetRotateMatrix();
|
||||
XMMATRIX GetTranslateMatrix();
|
||||
XMMATRIX GetSRMatrix();
|
||||
XMMATRIX GetWorldMatrix();
|
||||
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);
|
||||
XMVECTOR GetVelocity() const;
|
||||
void SetAcceleration(XMVECTOR);
|
||||
XMVECTOR GetAcceleration() const;
|
||||
void SetMass(float);
|
||||
float GetMass() const;
|
||||
void SetGrounded(bool);
|
||||
bool IsGrounded() const;
|
||||
|
||||
void UpdateWorldMatrix();
|
||||
void UpdateSRMatrix();
|
||||
void UpdateScaleMatrix();
|
||||
@ -37,9 +47,14 @@ public:
|
||||
|
||||
std::string GetName();
|
||||
void SetName(std::string name);
|
||||
int SetId(int id);
|
||||
int GetId() const;
|
||||
|
||||
public :
|
||||
bool m_demoSpinning = false;
|
||||
XMVECTOR m_previousPosition;
|
||||
XMVECTOR m_velocity;
|
||||
int m_id;
|
||||
|
||||
private:
|
||||
XMMATRIX m_scaleMatrix;
|
||||
@ -48,6 +63,10 @@ private:
|
||||
XMMATRIX m_srMatrix;
|
||||
XMMATRIX m_worldMatrix;
|
||||
|
||||
XMVECTOR m_acceleration;
|
||||
float m_mass;
|
||||
bool m_isGrounded;
|
||||
|
||||
std::string m_name;
|
||||
|
||||
};
|
||||
|
182
enginecustom/physics.cpp
Normal file
182
enginecustom/physics.cpp
Normal file
@ -0,0 +1,182 @@
|
||||
#include "physics.h"
|
||||
|
||||
|
||||
Physics::Physics()
|
||||
{
|
||||
m_gravity = XMVectorSet(0.0f, -9.81f, 0.0f, 0.0f); // Initialize the gravity vector
|
||||
}
|
||||
|
||||
Physics::Physics(const Physics& other)
|
||||
{
|
||||
m_gravity = other.m_gravity; // Copy the gravity value
|
||||
}
|
||||
|
||||
Physics::~Physics()
|
||||
{
|
||||
}
|
||||
|
||||
// Get the gravity value
|
||||
XMVECTOR Physics::GetGravity() const
|
||||
{
|
||||
return m_gravity;
|
||||
}
|
||||
|
||||
// Define the gravity value
|
||||
void Physics::SetGravity(XMVECTOR gravity)
|
||||
{
|
||||
m_gravity = gravity;
|
||||
}
|
||||
|
||||
// Apply gravity to an object
|
||||
void Physics::ApplyGravity(Object* object, float dragValue, float frameTime)
|
||||
{
|
||||
if (object == nullptr) // Verify if the object is not null
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!object->IsGrounded()) // Verify if the object is grounded
|
||||
{
|
||||
// Calculate the acceleration caused by gravity
|
||||
XMVECTOR gravityAcceleration = m_gravity / object->GetMass();
|
||||
|
||||
// Add the gravity acceleration to the object's current acceleration
|
||||
object->SetAcceleration(object->GetAcceleration() + gravityAcceleration);
|
||||
|
||||
// Calculate the acceleration caused by drag
|
||||
XMVECTOR dragAcceleration = -object->GetVelocity() * dragValue / object->GetMass();
|
||||
|
||||
// Add the drag acceleration to the object's current acceleration
|
||||
object->SetAcceleration(object->GetAcceleration() + dragAcceleration);
|
||||
|
||||
// Get the object velocity
|
||||
XMVECTOR velocity = object->GetVelocity();
|
||||
|
||||
// Update the velocity with the object's acceleration
|
||||
velocity += object->GetAcceleration() * frameTime;
|
||||
|
||||
// Set the new velocity
|
||||
object->SetVelocity(velocity);
|
||||
}
|
||||
}
|
||||
|
||||
void Physics::AddForce(Object* object, XMVECTOR force)
|
||||
{
|
||||
if (object == nullptr) // Verify if the object is not null
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the mass of the object
|
||||
float mass = object->GetMass();
|
||||
|
||||
// Calculate the acceleration caused by the force
|
||||
XMVECTOR acceleration = force / mass;
|
||||
|
||||
// Add the acceleration to the object's current acceleration
|
||||
object->SetAcceleration(object->GetAcceleration() + acceleration);
|
||||
}
|
||||
|
||||
bool Physics::IsColliding(Object* object1, Object* object2)
|
||||
{
|
||||
|
||||
std::string type1 = object1->GetName();
|
||||
std::string type2 = object2->GetName();
|
||||
|
||||
// Treat "plane" objects as "cube"
|
||||
if (type1 == "plane") type1 = "cube";
|
||||
if (type2 == "plane") type2 = "cube";
|
||||
|
||||
if (type1 == "cube" && type2 == "cube")
|
||||
{
|
||||
return CubesOverlap(object1, object2);
|
||||
}
|
||||
if (type1 == "sphere" && type2 == "sphere")
|
||||
{
|
||||
return SpheresOverlap(object1, object2);
|
||||
}
|
||||
if (type1 == "cube" && type2 == "sphere" || (type1 == "sphere" && type2 == "cube"))
|
||||
{
|
||||
if (type1 == "cube")
|
||||
{
|
||||
return SphereCubeOverlap(object1, object2);
|
||||
}
|
||||
else if (type1 == "sphere")
|
||||
{
|
||||
return SphereCubeOverlap(object2, object1);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////
|
||||
// AABB method for collision detection //
|
||||
/////////////////////////////////////////
|
||||
|
||||
bool Physics::CubesOverlap(Object* cube1, Object* cube2)
|
||||
{
|
||||
XMVECTOR position1 = cube1->GetPosition();
|
||||
XMVECTOR position2 = cube2->GetPosition();
|
||||
|
||||
XMVECTOR scale1 = cube1->GetScale();
|
||||
XMVECTOR scale2 = cube2->GetScale();
|
||||
|
||||
XMVECTOR min1 = position1 - scale1;
|
||||
XMVECTOR max1 = position1 + scale1;
|
||||
XMVECTOR min2 = position2 - scale2;
|
||||
XMVECTOR max2 = position2 + scale2;
|
||||
|
||||
return (min1.m128_f32[0] <= max2.m128_f32[0] && max1.m128_f32[0] >= min2.m128_f32[0] &&
|
||||
min1.m128_f32[1] <= max2.m128_f32[1] && max1.m128_f32[1] >= min2.m128_f32[1] &&
|
||||
min1.m128_f32[2] <= max2.m128_f32[2] && max1.m128_f32[2] >= min2.m128_f32[2]);
|
||||
}
|
||||
|
||||
bool Physics::SpheresOverlap(Object* sphere1, Object* sphere2)
|
||||
{
|
||||
XMVECTOR position1 = sphere1->GetPosition();
|
||||
XMVECTOR position2 = sphere2->GetPosition();
|
||||
|
||||
XMVECTOR scale1 = sphere1->GetScale() / 2;
|
||||
XMVECTOR scale2 = sphere2->GetScale() / 2;
|
||||
|
||||
float distance = sqrt(
|
||||
(position1.m128_f32[0] - position2.m128_f32[0]) * (position1.m128_f32[0] - position2.m128_f32[0]) +
|
||||
(position1.m128_f32[1] - position2.m128_f32[1]) * (position1.m128_f32[1] - position2.m128_f32[1]) +
|
||||
(position1.m128_f32[2] - position2.m128_f32[2]) * (position1.m128_f32[2] - position2.m128_f32[2])
|
||||
);
|
||||
|
||||
float radius1 = XMVectorGetX(XMVector3Length(scale1));
|
||||
float radius2 = XMVectorGetX(XMVector3Length(scale2));
|
||||
|
||||
return distance < radius1 + radius2;
|
||||
}
|
||||
|
||||
bool Physics::SphereCubeOverlap(Object* cube, Object* sphere)
|
||||
{
|
||||
XMVECTOR position1 = cube->GetPosition();
|
||||
XMVECTOR position2 = sphere->GetPosition();
|
||||
|
||||
XMVECTOR scale1 = cube->GetScale();
|
||||
XMVECTOR scale2 = sphere->GetScale() / 2;
|
||||
|
||||
XMVECTOR min1 = position1 - scale1;
|
||||
XMVECTOR max1 = position1 + scale1;
|
||||
|
||||
// Get box closest point to sphere center by clamping
|
||||
float x = max(min1.m128_f32[0], min(position2.m128_f32[0], max1.m128_f32[0]));
|
||||
float y = max(min1.m128_f32[1], min(position2.m128_f32[1], max1.m128_f32[1]));
|
||||
float z = max(min1.m128_f32[2], min(position2.m128_f32[2], max1.m128_f32[2]));
|
||||
|
||||
// This is the same as SpheresOverlap
|
||||
float distance = sqrt(
|
||||
(x - position2.m128_f32[0]) * (x - position2.m128_f32[0]) +
|
||||
(y - position2.m128_f32[1]) * (y - position2.m128_f32[1]) +
|
||||
(z - position2.m128_f32[2]) * (z - position2.m128_f32[2])
|
||||
);
|
||||
|
||||
float radius = XMVectorGetX(XMVector3Length(scale2));
|
||||
|
||||
return distance < radius;
|
||||
}
|
||||
|
27
enginecustom/physics.h
Normal file
27
enginecustom/physics.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef _PHYSICS_H_
|
||||
#define _PHYSICS_H_
|
||||
|
||||
#include "object.h"
|
||||
#include "math.h"
|
||||
|
||||
class Physics : public Object
|
||||
{
|
||||
public:
|
||||
Physics();
|
||||
explicit Physics(const Physics&); // Use explicit to avoid implicit conversion
|
||||
~Physics();
|
||||
|
||||
XMVECTOR GetGravity() const; // Get the gravity value
|
||||
void SetGravity(XMVECTOR gravity); // Define the gravity value
|
||||
void ApplyGravity(Object*, float, float); // Apply gravity to an object
|
||||
void AddForce(Object*, XMVECTOR);
|
||||
bool IsColliding(Object*, Object*);
|
||||
bool CubesOverlap(Object*, Object*);
|
||||
bool SpheresOverlap(Object*, Object*);
|
||||
bool SphereCubeOverlap(Object*, Object*);
|
||||
|
||||
private:
|
||||
XMVECTOR m_gravity;
|
||||
};
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user