Skip to content

Commit 2e7bf2d

Browse files
authored
Merge pull request #50 from Im-Rises/develop
Develop
2 parents e224f1e + 692c492 commit 2e7bf2d

14 files changed

Lines changed: 113 additions & 82 deletions

File tree

PhysicalEngine/Game.cpp

Lines changed: 70 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ void Game::start(Scene* s) {
5858
scene->addGameObject(sphere);
5959

6060
auto* rigidbodyPrefab = new RigidbodyPrefab(scene);
61+
rigidbodyPrefab->mesh->setColor({ 1.0f, 0.0f, 0, 1.0f });
6162
scene->addGameObject(rigidbodyPrefab);
6263
rigidbodyPrefab->transform.positionX = -1.5;
6364
rigidbodyPrefab->transform.positionY = 3;
@@ -69,6 +70,7 @@ void Game::start(Scene* s) {
6970
rigidbodyPrefab->addComponent(rigidbodyCuboidRectangleCollider);
7071

7172
auto* rigidbodyPrefab2 = new RigidbodyPrefab(scene);
73+
rigidbodyPrefab2->mesh->setColor({ 0, 0.0f, 0.8f, 1.0f });
7274
rigidbodyPrefab2->transform.positionX = 1.5;
7375
rigidbodyPrefab2->transform.positionY = 3;
7476
rigidbodyPrefab2->transform.positionZ = -3;
@@ -80,6 +82,7 @@ void Game::start(Scene* s) {
8082
rigidbodyPrefab2->addComponent(rigidbodyCuboidRectangleCollider2);
8183

8284
auto* rigidbodyPrefab3 = new RigidbodyPrefab(scene);
85+
rigidbodyPrefab3->mesh->setColor({ 0, 0.8f, 0, 1.0f });
8386
rigidbodyPrefab3->transform.positionX = 3;
8487
rigidbodyPrefab3->transform.positionY = 3;
8588
rigidbodyPrefab3->transform.positionZ = 0;
@@ -91,78 +94,78 @@ void Game::start(Scene* s) {
9194
rigidbodyPrefab3->addComponent(rigidbodyCuboidRectangleCollider3);
9295
}
9396

94-
//void Game::goLeft() {
95-
// // m_p->setSpeed(-m_speed, 0, 0);
97+
// void Game::goLeft() {
98+
// // m_p->setSpeed(-m_speed, 0, 0);
9699
//
97-
// for (auto& gameObject : scene->getGameObjects())
98-
// {
99-
// auto* particle = dynamic_cast<Particle*>(gameObject->getComponentByName(PARTICLE_COMPONENT));
100-
// if (particle != nullptr)
101-
// {
102-
// AnchoredSpring* anchoredSpring;
103-
// particle->getForceByClass(anchoredSpring);
104-
// if (anchoredSpring != nullptr)
105-
// {
106-
// anchoredSpring->translate({ -m_speed, 0, 0 });
107-
// }
108-
// }
109-
// }
110-
//}
100+
// for (auto& gameObject : scene->getGameObjects())
101+
// {
102+
// auto* particle = dynamic_cast<Particle*>(gameObject->getComponentByName(PARTICLE_COMPONENT));
103+
// if (particle != nullptr)
104+
// {
105+
// AnchoredSpring* anchoredSpring;
106+
// particle->getForceByClass(anchoredSpring);
107+
// if (anchoredSpring != nullptr)
108+
// {
109+
// anchoredSpring->translate({ -m_speed, 0, 0 });
110+
// }
111+
// }
112+
// }
113+
// }
111114
//
112-
//void Game::goRight() {
113-
// // m_p->setSpeed(m_speed, 0, 0);
115+
// void Game::goRight() {
116+
// // m_p->setSpeed(m_speed, 0, 0);
114117
//
115-
// for (auto& gameObject : scene->getGameObjects())
116-
// {
117-
// auto* particle = dynamic_cast<Particle*>(gameObject->getComponentByName(PARTICLE_COMPONENT));
118-
// if (particle != nullptr)
119-
// {
120-
// AnchoredSpring* anchoredSpring;
121-
// particle->getForceByClass(anchoredSpring);
122-
// if (anchoredSpring != nullptr)
123-
// {
124-
// anchoredSpring->translate({ m_speed, 0, 0 });
125-
// }
126-
// }
127-
// }
128-
//}
118+
// for (auto& gameObject : scene->getGameObjects())
119+
// {
120+
// auto* particle = dynamic_cast<Particle*>(gameObject->getComponentByName(PARTICLE_COMPONENT));
121+
// if (particle != nullptr)
122+
// {
123+
// AnchoredSpring* anchoredSpring;
124+
// particle->getForceByClass(anchoredSpring);
125+
// if (anchoredSpring != nullptr)
126+
// {
127+
// anchoredSpring->translate({ m_speed, 0, 0 });
128+
// }
129+
// }
130+
// }
131+
// }
129132
//
130-
//void Game::goUp() {
131-
// // m_p->setSpeed(0, m_speed, 0);
133+
// void Game::goUp() {
134+
// // m_p->setSpeed(0, m_speed, 0);
132135
//
133-
// for (auto& gameObject : scene->getGameObjects())
134-
// {
135-
// auto* particle = dynamic_cast<Particle*>(gameObject->getComponentByName(PARTICLE_COMPONENT));
136-
// if (particle != nullptr)
137-
// {
138-
// AnchoredSpring* anchoredSpring;
139-
// particle->getForceByClass(anchoredSpring);
140-
// if (anchoredSpring != nullptr)
141-
// {
142-
// anchoredSpring->translate({ 0, m_speed, 0 });
143-
// }
144-
// }
145-
// }
146-
//}
136+
// for (auto& gameObject : scene->getGameObjects())
137+
// {
138+
// auto* particle = dynamic_cast<Particle*>(gameObject->getComponentByName(PARTICLE_COMPONENT));
139+
// if (particle != nullptr)
140+
// {
141+
// AnchoredSpring* anchoredSpring;
142+
// particle->getForceByClass(anchoredSpring);
143+
// if (anchoredSpring != nullptr)
144+
// {
145+
// anchoredSpring->translate({ 0, m_speed, 0 });
146+
// }
147+
// }
148+
// }
149+
// }
147150
//
148-
//void Game::goDown() {
149-
// // m_p->setSpeed(0, -m_speed, 0);
151+
// void Game::goDown() {
152+
// // m_p->setSpeed(0, -m_speed, 0);
150153
//
151-
// for (auto& gameObject : scene->getGameObjects())
152-
// {
153-
// auto* particle = dynamic_cast<Particle*>(gameObject->getComponentByName(PARTICLE_COMPONENT));
154-
// if (particle != nullptr)
155-
// {
156-
// AnchoredSpring* anchoredSpring;
157-
// particle->getForceByClass(anchoredSpring);
158-
// if (anchoredSpring != nullptr)
159-
// {
160-
// anchoredSpring->translate({ 0, -m_speed, 0 });
161-
// }
162-
// }
163-
// }
164-
//}
154+
// for (auto& gameObject : scene->getGameObjects())
155+
// {
156+
// auto* particle = dynamic_cast<Particle*>(gameObject->getComponentByName(PARTICLE_COMPONENT));
157+
// if (particle != nullptr)
158+
// {
159+
// AnchoredSpring* anchoredSpring;
160+
// particle->getForceByClass(anchoredSpring);
161+
// if (anchoredSpring != nullptr)
162+
// {
163+
// anchoredSpring->translate({ 0, -m_speed, 0 });
164+
// }
165+
// }
166+
// }
167+
// }
165168

166-
//float* Game::getPtrSpeed() {
167-
// return &m_speed;
168-
//}
169+
// float* Game::getPtrSpeed() {
170+
// return &m_speed;
171+
// }

PhysicalEngine/PhysicalEngineLauncher.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
#define PROJECT_AUTHOR " - Quentin MOREL\n - Clémence CLAVEL\n - Gabriel REBOUL"
77

8-
#define VERSION_MAJOR "0"
9-
#define VERSION_MINOR "4"
10-
#define VERSION_PATCH "2"
8+
#define VERSION_MAJOR "1"
9+
#define VERSION_MINOR "1"
10+
#define VERSION_PATCH "0"
1111

1212
#define PROJECT_VERSION VERSION_MAJOR "." VERSION_MINOR "." VERSION_PATCH
1313

PhysicalEngine/RigidbodyContact/RigidbodyContactGeneratorRegistry.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void RigidbodyContactGeneratorRegistry::calculateContactSphere(RigidbodySphereCo
5959

6060
if (distance <= rsc->getRadius())
6161
{
62-
Vector3d normal = planeCollider->getNormalVector();
62+
Vector3d normal = planeCollider->getNormalVector().normalize();
6363
Vector3d pointContact = rsc->getGameObject()->transform.getPosition() - (planeCollider->getNormalVector() * rsc->getRadius());
6464
float interpenetration = rsc->getRadius() -distance;
6565
contactInfo.m_normal = normal;
@@ -106,7 +106,7 @@ void RigidbodyContactGeneratorRegistry::calculateContactCuboid(RigidbodyCuboidRe
106106
if (distance < 0)
107107
{
108108
float interpenetration = std::abs(distance);
109-
Vector3d normal = planeCollider->getNormalVector();
109+
Vector3d normal = planeCollider->getNormalVector().normalize();
110110
Vector3d pointContact = points[i];
111111
collision = true;
112112
contactInfo.m_points.push_back(pointContact);
@@ -159,5 +159,5 @@ void RigidbodyContactGeneratorRegistry::calculateContactPlane(RigidbodyPlaneColl
159159
}
160160

161161
float RigidbodyContactGeneratorRegistry::distanceToPlane(Vector3d point, RigidbodyPlaneCollider* plane) {
162-
return point.dot(plane->getNormalVector()) - plane->getCenter().dot(plane->getNormalVector());
162+
return point.dot(plane->getNormalVector().normalize()) - plane->getCenter().dot(plane->getNormalVector().normalize());
163163
}

PhysicalEngine/Scene/Components/Mesh/Cuboid/CuboidRectangle.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,6 @@ Matrix33 CuboidRectangle::getInertiaTensor(float mass) const {
6868
0.0f, 0.0f, (1.0f / 12) * mass * (width * width + height * height) };
6969
return Matrix33(values);
7070
}
71+
const char* CuboidRectangle::getMeshType() const {
72+
return MESH_TYPE;
73+
}

PhysicalEngine/Scene/Components/Mesh/Cuboid/CuboidRectangle.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "../Mesh.h"
55

6-
#define MESHTYPE_CUBOID_RECTANGLE "CuboidRectangle"
6+
#define MESHTYPE_CUBOID_RECTANGLE "Cuboid_Rectangle"
77

88
class CuboidRectangle : public Mesh {
99
private:
@@ -18,6 +18,8 @@ class CuboidRectangle : public Mesh {
1818
CuboidRectangle(float width = 1, float height = 1, float length = 1);
1919

2020
Matrix33 getInertiaTensor(float mass) const override;
21+
22+
const char* getMeshType() const;
2123
};
2224

2325
#endif // !CUBOID_RECTANGLE_H

PhysicalEngine/Scene/Components/Mesh/Cylinder/Cylinder.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,6 @@ void Cylinder::generateTriangles(float radius, float height, int rings) {
131131
indices.push_back(rings * 2 + 1);
132132
}
133133
}
134+
const char* Cylinder::getMeshType() const {
135+
return MESH_TYPE;
136+
}

PhysicalEngine/Scene/Components/Mesh/Cylinder/Cylinder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class Cylinder : public Mesh {
2121
void generateTriangles(float radius, float height, int rings);
2222

2323
Matrix33 getInertiaTensor(float mass) const override;
24+
25+
const char* getMeshType() const;
2426
};
2527

2628

PhysicalEngine/Scene/Components/Mesh/Mesh.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ using namespace std;
1414
const char* Mesh::meshNamesList[3] = { MESHTYPE_CYLINDER, MESHTYPE_SPHERE, MESHTYPE_CUBOID_RECTANGLE };
1515

1616
void Mesh::drawGui() {
17+
ImGui::Text("Mesh type: %s", getMeshType());
1718
ImGui::Text(verticesUseIndices ? "Vertices use indices" : "Vertices don't use indices");
19+
ImGui::DragFloat4("Color", &color[0], 0.01f, 0.0f, 1.0f);
1820
if (ImGui::BeginTable("", 3))
1921
{
2022
ImGui::TableNextColumn();
@@ -76,4 +78,8 @@ Mesh* Mesh::createMesh(const char* meshType) {
7678
}
7779
}
7880
}
79-
}
81+
}
82+
83+
const char* Mesh::getMeshType() const {
84+
return MESH_TYPE;
85+
}

PhysicalEngine/Scene/Components/Mesh/Mesh.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class Mesh : private DefaultComponent {
5454

5555
static Mesh* createMesh(const char* meshType);
5656

57+
virtual const char* getMeshType() const;
58+
5759
#pragma endregion
5860
};
5961

PhysicalEngine/Scene/Components/Mesh/Sphere/Sphere.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,6 @@ Matrix33 Sphere::getInertiaTensor(float mass) const {
9999

100100
return Matrix33(values);
101101
}
102+
const char* Sphere::getMeshType() const {
103+
return MESH_TYPE;
104+
}

0 commit comments

Comments
 (0)