SFML erreur C2059 et C3805
Bonjour, j'ai pour but de créer un mini moteur physique graphique avec sfml mais voila que j'ai une erreur de la part de SFML :aie:
J'utilise SFML 2.4.1 x86 et le programme peut gérer plus de 1 vecteur avec la résultante (en fait une infinité tant qu'on agrandit le tableau des vecteurs), il sait aussi calculer le vecteur gravité, il sait afficher les entités concerné tout en les updatant (ça ce dit ?), et... c'est tout :calim2:
Ce programme fonctionnait très bien jusqu'à ce que je modifie le code l'ordi me ponde cette erreur...
Enfin voici le code
Entity.h
Code:
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
|
#pragma once
#include <vector>
#include <cmath>
#include <iostream>
#define G 0.001
#define ColisionRange 2
class Entity
{
public:
Entity();
~Entity();
void EntityInit(int EntityNumber, float Masse, float PosX, float PosY);
void NewVector(int Type, float NormeX, float NormeY);
void CalculResultant();
void CalculMouvement();
void CalculGravity();
void NewEntity(int ID, int Masse, float PosX, float PosY);
void CalculDist();
void CalculPos();
void UpdateTempEntity(float PosX, float PosY);
void ColisionDetection();
float ReturnX(int VectorNumber);
float ReturnY(int VectorNumber);
private:
std::vector<float> m_Entity;
std::vector<float> m_TempEntity;
float m_TempDist, m_TempDistX, m_TempDistY, m_TempForce, m_TempForceX, m_TempForceY;
unsigned int m_Decompt;
};
/*############################
## m_Entity[x] = ... ##
## 0 = ID ##
## 1 = Masse ##
## 2 = PosX ##
## 3 = PosY ##
## 4 = VelocityX ##
## 5 = VelocityY ##
## 6 = ResultanteX ##
## 7 = ResultanteY ##
## 8 = PoidsX ##
## 9 = PoidsY ##
## 10 = TrainéeX ##
## 11 = TrainéeY ##
## 12 = FrottementX ##
## 13 = FrottementY ##
############################*/
/*############################
## m_TempEntity[x] = ... ##
## 0 = PosX ##
## 1 = PosY ##
## 2 = Masse ##
############################*/ |
le entity.cpp
Code:
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;
}
} |
et le main
Code:
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
|
#include <iostream>
#include "Entity.h"
#include <SFML\Graphics.hpp>
using namespace std;
int main()
{
//SFML initialisation
int width(500), height(500);
sf::RenderWindow window(sf::VideoMode(width, height), "test", sf::Style::Default);
window.setFramerateLimit(60);
Entity obj1;
obj1.EntityInit(1, 1, 250, 250);
sf::CircleShape obj1shape(5);
obj1shape.setFillColor(sf::Color::Green);
obj1shape.setPosition(250, 250);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(obj1shape);
window.display();
}
return 0;
} |
Ne pas tenir compte de l'absence totale de l'appel des fonctions de entity.h car l'erreur vient de SFML :
Code:
1 2 3 4 5
| 1>------ Début de la génération*: Projet*: MineEngine, Configuration*: Debug Win32 ------
1> main.cpp
1>f:\documents\programmation\bibliothèque\sfml-2.4.1 x86\include\sfml\window\keyboard.hpp(57): error C2059: erreur de syntaxe*: 'constant'
1>f:\documents\programmation\bibliothèque\sfml-2.4.1 x86\include\sfml\window\keyboard.hpp(57): error C3805: 'constant'*: jeton inattendu, '}' ou ',' attendue
========== Génération*: 0 a réussi, 1 a échoué, 0 mis à jour, 0 a été ignoré ========== |
Merci d'avance de votre aide ;)