1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
#include "Entity.h"
using namespace std;
Entity::Entity()
{
m_TempEntity.resize(3);
}
Entity::~Entity()
{
}
void Entity::EntityInit(int ID, float Masse, float PosX, float PosY)
{
m_Entity.resize(14);
m_Entity[0] = ID;
m_Entity[1] = Masse;
m_Entity[2] = PosX;
m_Entity[3] = PosY;
cout << "Successfuly initialise the main entity " << ID << " !" << endl;
}
void Entity::NewVector(int Type, float NormeX, float NormeY)
{
switch (Type)
{
case 0: //Resultante Vector
m_Entity[6] = NormeX;
m_Entity[7] = NormeY;
break;
case 1: //Poids Vector
m_Entity[8] = NormeX;
m_Entity[9] = NormeY;
break;
case 2: //Trainée Vector
m_Entity[10] = NormeX;
m_Entity[11] = NormeY;
break;
case 3: //Frottement Vector
m_Entity[12] = NormeX;
m_Entity[13] = NormeY;
break;
case 4: //Force quelconque Vector
m_Entity.push_back(NormeX);
m_Entity.push_back(NormeY);
break;
default:
break;
}
cout << "Successfuly created the vector " << Type << " !" << endl;
}
void Entity::CalculResultant()
{
//Norme resultante X
m_Decompt = 8; //Commence la somme après le vecteur PoidsX
while (m_Decompt < m_Entity.size())
{
m_Entity[6] += m_Entity[m_Decompt];
m_Decompt += 2;
}
//Norme resultante Y
m_Decompt = 9; //Commence la somme après le vecteur PoidsY
while (m_Decompt < m_Entity.size())
{
m_Entity[7] += m_Entity[m_Decompt];
m_Decompt += 2;
}
cout << "Successfuly calculed the ResultantX : " << m_Entity[6] << " and the ResultantY : " << m_Entity[7] << endl;
}
float Entity::ReturnX(int Type)
{
switch (Type)
{
case 0:
return m_Entity[0]; //Return ID
break;
case 1:
return m_Entity[1]; //Return Masse
break;
default:
return m_Entity[Type * 2 - 2]; //Return Entity vectors
break;
}
}
float Entity::ReturnY(int Type)
{
switch (Type)
{
case 0:
return m_Entity[0]; //Return ID
break;
case 1:
return m_Entity[1]; //Return Masse
break;
default:
return m_Entity[Type * 2 - 1]; //Return Entity vectors
break;
}
}
void Entity::CalculDist()
{
m_TempDistX = 1 * (m_Entity[2] - m_TempEntity[0]); //Calcul DistanceX
m_TempDistY = 1 * (m_Entity[3] - m_TempEntity[1]); //Calcul DistanceY
m_TempDist = pow(pow(m_TempDistX, 2) + pow(m_TempDistY, 2), 0.5); //Calcul Distanc from AB^2 = BC^2 + AC^2
cout << "Successfuly calculed Dist : " << m_TempDist << endl;
}
void Entity::CalculMouvement()
{
m_Entity[4] += m_Entity[6] / m_Entity[1]; //Calcul VelocityX from F = ma
m_Entity[5] += m_Entity[7] / m_Entity[1]; //Calcul VelocityY from F = ma
cout << "Successfuly calculed Mouvement !" << endl;
}
void Entity::NewEntity(int ID, int Masse, float PosX, float PosY)
{
m_TempEntity[0] = PosX;
m_TempEntity[1] = PosY;
m_TempEntity[2] = Masse;
cout << "Successfuly created the entity " << ID << " !" << endl;
}
void Entity::CalculGravity()
{
m_TempForce = (G * m_Entity[1] * m_TempEntity[2]) / pow(m_TempDist, 2); // F = (G*mA*mB) / dist*dist
m_TempForceX = (m_TempDistX * m_TempForce) / m_TempDist; //D'après théorème de thalès
m_TempForceY = (m_TempDistY * m_TempForce) / m_TempDist; //D'après théorème de thalès
NewVector(4, m_TempForceX, m_TempForceY);
cout << "Successfuly calculed Gravity : " << m_TempForce<< endl;
}
void Entity::CalculPos()
{
m_Entity[2] += m_Entity[4];
m_Entity[3] += m_Entity[5];
cout << "Successfuly calculed PosX : " << m_Entity[2] << " and PosY : " << m_Entity[3] << endl;
}
void Entity::UpdateTempEntity(float PosX, float PosY)
{
m_TempEntity[0] = PosX;
m_TempEntity[1] = PosY;
cout << "Successfuly updated TempEntity Pos !" << endl;
}
void Entity::ColisionDetection()
{
if ((m_Entity[2] < m_TempEntity[0] && m_Entity[2] + ColisionRange > m_TempEntity[0]) && (m_Entity[3] < m_TempEntity[1] && m_Entity[3] + ColisionRange > m_TempEntity[1]))
{
cout << "Colision !" << endl;
m_Entity[4] = 0;
m_Entity[5] = 0;
}
} |
Partager