diff --git a/.idea/.idea.KhaoticEngineReborn/.idea/projectSettingsUpdater.xml b/.idea/.idea.KhaoticEngineReborn/.idea/projectSettingsUpdater.xml
index 64af657..4bb9f4d 100644
--- a/.idea/.idea.KhaoticEngineReborn/.idea/projectSettingsUpdater.xml
+++ b/.idea/.idea.KhaoticEngineReborn/.idea/projectSettingsUpdater.xml
@@ -1,7 +1,6 @@
-
-
+
\ No newline at end of file
diff --git a/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml b/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
index dfbbc08..51139dd 100644
--- a/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
+++ b/.idea/.idea.KhaoticEngineReborn/.idea/workspace.xml
@@ -4,7 +4,16 @@
-
+
+
+
+
+
+
+
+
+
+
@@ -17,8 +26,8 @@
-
-
+
+
@@ -34,30 +43,38 @@
- {
- "keyToString": {
- "ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
- "C++ Project.enginecustom.executor": "Run",
- "C/C++ Project.enginecustom.executor": "Run",
- "RunOnceActivity.ShowReadmeOnStart": "true",
- "RunOnceActivity.git.unshallow": "true",
- "SHARE_PROJECT_CONFIGURATION_FILES": "true",
- "git-widget-placeholder": "main",
- "ignore.virus.scanning.warn.message": "true",
- "node.js.detected.package.eslint": "true",
- "node.js.detected.package.tslint": "true",
- "node.js.selected.package.eslint": "(autodetect)",
- "node.js.selected.package.tslint": "(autodetect)",
- "nodejs_package_manager_path": "npm",
- "settings.editor.selected.configurable": "preferences.pluginManager",
- "vue.rearranger.settings.migration": "true"
+
-
+}]]>
+
-
+
+
@@ -65,19 +82,18 @@
-
-
-
+
+
@@ -85,11 +101,11 @@
-
-
+
+
@@ -97,10 +113,20 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
-
@@ -157,6 +183,7 @@
+
diff --git a/enginecustom/imgui.ini b/enginecustom/imgui.ini
index 333c5e1..30c04b2 100644
--- a/enginecustom/imgui.ini
+++ b/enginecustom/imgui.ini
@@ -13,7 +13,7 @@ DockId=0x00000005,0
Pos=8,27
Size=289,826
Collapsed=0
-DockId=0x00000009,0
+DockId=0x00000009,1
[Window][Terrain]
Pos=8,27
@@ -35,7 +35,7 @@ DockId=0x00000001,2
[Window][Engine Settings]
Pos=8,27
-Size=289,974
+Size=289,826
Collapsed=0
DockId=0x00000009,0
diff --git a/enginecustom/src/inc/system/imguiManager.h b/enginecustom/src/inc/system/imguiManager.h
index a97742d..6d794da 100644
--- a/enginecustom/src/inc/system/imguiManager.h
+++ b/enginecustom/src/inc/system/imguiManager.h
@@ -67,6 +67,7 @@ private:
bool showLogWindow;
bool m_isPhyiscsEnabled = false;
+ bool m_isGravityEnabled = false;
ImGuiIO* io;
diff --git a/enginecustom/src/inc/system/object.h b/enginecustom/src/inc/system/object.h
index e34aaaa..e12eb06 100644
--- a/enginecustom/src/inc/system/object.h
+++ b/enginecustom/src/inc/system/object.h
@@ -95,11 +95,23 @@ public:
ObjectType StringToObjectType(const std::string& objectType);
std::string ObjectTypeToString(ObjectType objectType);
+ void LaunchObject();
+ void SetAlpha(float alpha) { m_alpha = alpha; }
+ float GetAlpha() const { return m_alpha; }
+ void SetInitialStretch(float initialStretch) { m_initialStretch = initialStretch; }
+ float GetInitialStretch() const { return m_initialStretch; }
+ void SetSpringConstant(float springConstant) { m_springConstant = springConstant; }
+ float GetSpringConstant() const { return m_springConstant; }
+
+ bool IsGravityEnabled() const { return m_gravityEnabled; }
+ void SetGravityEnabled(bool state) { m_gravityEnabled = state; }
+
public :
bool m_demoSpinning = false;
XMVECTOR m_previousPosition;
XMVECTOR m_velocity;
int m_id;
+ bool m_gravityEnabled = true;
private:
XMMATRIX m_scaleMatrix;
@@ -121,4 +133,9 @@ private:
float m_boundingRadius;
std::wstring m_modelPath;
+ float m_alpha = 0.0f;
+ float m_initialStretch = 0.0f;
+ float m_springConstant = 10.0f;
+
+
};
diff --git a/enginecustom/src/src/system/applicationclass.cpp b/enginecustom/src/src/system/applicationclass.cpp
index 2263f0c..d0190db 100644
--- a/enginecustom/src/src/system/applicationclass.cpp
+++ b/enginecustom/src/src/system/applicationclass.cpp
@@ -2150,7 +2150,9 @@ bool ApplicationClass::RenderPhysics(bool keyLeft, bool keyRight, bool keyUp, bo
object->SetVelocity(velocity);
}
- m_Physics->ApplyGravity(object, deltaTime);
+ if (object->m_gravityEnabled) {
+ m_Physics->ApplyGravity(object, deltaTime);
+ }
if (XMVectorGetY(object->GetPosition()) < -30.0f) {
XMVECTOR currentPosition = object->GetPosition();
diff --git a/enginecustom/src/src/system/imguiManager.cpp b/enginecustom/src/src/system/imguiManager.cpp
index 4da9189..43be80d 100644
--- a/enginecustom/src/src/system/imguiManager.cpp
+++ b/enginecustom/src/src/system/imguiManager.cpp
@@ -401,6 +401,14 @@ void imguiManager::WidgetObjectWindow(ApplicationClass* app)
object->SetPhysicsEnabled(m_isPhyiscsEnabled);
}
+ // Gravity Enabled checkbox
+ std::string gravityLabel = "Gravity##" + std::to_string(index);
+ if (ImGui::Checkbox(gravityLabel.c_str(), &object->m_gravityEnabled))
+ {
+ object->SetGravityEnabled(object->m_gravityEnabled);
+ }
+
+
// 3 radio button on the same line to set the ObjectType
std::string typeLabel = "Type##" + std::to_string(index);
ObjectType type = object->GetType();
@@ -419,6 +427,40 @@ void imguiManager::WidgetObjectWindow(ApplicationClass* app)
object->SetType(ObjectType::Sphere);
}
+ // button to launch the object
+ std::string launchLabel = "Launch##" + std::to_string(index);
+
+ // paraeter to set the alpha, initial stretch and spring constant
+ float alpha = object->GetAlpha();
+ float initialStretch = object->GetInitialStretch();
+ float springConstant = object->GetSpringConstant();
+ if (ImGui::DragFloat("Alpha##" , &alpha, 0.01f, 0.0f, 1.0f))
+ {
+ object->SetAlpha(alpha);
+ }
+ if (ImGui::DragFloat("Initial Stretch##", &initialStretch, 0.01f, 0.0f, 1.0f))
+ {
+ object->SetInitialStretch(initialStretch);
+ }
+ if (ImGui::DragFloat("Spring Constant##", &springConstant, 0.01f, 0.0f, 100.0f))
+ {
+ object->SetSpringConstant(springConstant);
+ }
+
+ if (ImGui::Button(launchLabel.c_str()))
+ {
+ object->LaunchObject();
+ }
+ ImGui::SameLine();
+ // button to stop the object
+ std::string stopLabel = "Stop##" + std::to_string(index);
+ if (ImGui::Button(stopLabel.c_str()))
+ {
+ object->SetVelocity(XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f));
+ object->SetPosition(XMVectorSet(0.0f, 0.0f, 0.0f, 0.0f));
+ }
+
+
ImGui::Separator();
diff --git a/enginecustom/src/src/system/object.cpp b/enginecustom/src/src/system/object.cpp
index 6869f78..eff3c1a 100644
--- a/enginecustom/src/src/system/object.cpp
+++ b/enginecustom/src/src/system/object.cpp
@@ -306,4 +306,46 @@ ShaderType Object::StringToShaderType(const std::string& str) {
if (str == "SUNLIGHT") return ShaderType::SUNLIGHT;
// Add other cases as needed
return ShaderType::TEXTURE;
+}
+
+void Object::LaunchObject()
+{
+ // 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);
}
\ No newline at end of file