Voilà je suis toujours dans mon pseudo moteur 3D enfin bref je suis en train de coder un petite fonction pour calculer le barycentre enfin calculer le barycentre en lui soit même c'est pas trop compliquer mais moi je me prends toujours la tête alors je presentes mon problème :
Je sais bien que le C++ a inventé les using namespace mais pour moi c'est plus claire comme ca je vois tout de suite de quel classe il sagit puisque j'ai 2 classes CCar
J'ai une classe CCar dans l'espace de nommage VM::Mesh et une autre classe dans l'espace de nommage VM
la classe VM::Mesh::CCar :
CODE
class CCar : public CMesh, CRoue, CVitre
{
public :
CCar();
virtual ~CCar();
// Operateur
inline VM::Mesh::CCar& operator=(const VM::Mesh::CCar&);
// Fonction
void Draw();
// Affecter
bool SetTOri(const CVector3f&);
bool SetBarycentre(const CVector3f&);
// ...
bool SetBody(const std::vector<CVector3f>&);
bool SetRoue(const std::vector<CRoue>&);
bool SetVitre(const std::vector<CVitre>&);
bool SetPhare(const std::vector<CVector3f>&);
bool SetStop(const std::vector<CVector3f>&);
bool SetArr(const std::vector<CVector3f>&);
bool SetClign(const std::vector<CVector3f>&);
// ...
bool SetBodyAt(int, const CVector3f&);
bool SetRoueAt(int, const CRoue&);
bool SetVitreAt(int, const CVitre&);
bool SetPhareAt(int, const CVector3f&);
bool SetStopAt(int, const CVector3f&);
bool SetArrAt(int, const CVector3f&);
bool SetClignAt(int, const CVector3f&);
// Retourner
CVector3f &GetTOri(void);
CVector3f &GetBary(void);
// ...
std::vector<CVector3f> &GetBody(void);
std::vector<CRoue> &GetRoue(void);
std::vector<CVitre> &GetVitre(void);
std::vector<CVector3f> &GetPhare(void);
std::vector<CVector3f> &GetStop(void);
std::vector<CVector3f> &GetArr(void);
std::vector<CVector3f> &GetClign(void);
// ...
CVector3f &GetBodyAt(int);
CRoue &GetRoueAt(int);
CVitre &GetVitreAt(int);
CVector3f &GetPhareAt(int);
CVector3f &GetStopAt(int);
CVector3f &GetArrAt(int);
CVector3f &GetClignAt(int);
// Calculer le barycentre
CVector3f CalculateBaryC(void);
CVector3f CalculateBaryC(std::vector<CVector3f>&);
private :
CVector3f mTOri; // Orientation temporaire
CVector3f mBaryC; // Barycentre
std::vector<CVector3f> mBody; // Tableau de vertex du Body
std::vector<CRoue> mRoue; // Tableau de Roue
std::vector<CVitre> mVitre; // Tableau de Vitre
std::vector<CVector3f> mPhare; // Tableau de position de phare
std::vector<CVector3f> mStop; // Tableau de position de feu stop
std::vector<CVector3f> mArr; // Tableau de position de marche arrière
std::vector<CVector3f> mClign; // Tableau de position de Clignotant
protected :
};
Et la classe VM::CCar
CODE
class CCar : public VM::Mesh::CCar
{
public :
CCar();
virtual ~CCar();
// Pointeur
VM::Mesh::CRoue *pRoue;
VM::Mesh::CVitre *pVitre;
VM::Mesh::CCar *pCar;
// Fonction
bool SetCar(const std::vector<VM::Mesh::CCar>&);
bool SetCarAt(int, const VM::Mesh::CCar&);
std::vector<VM::Mesh::CCar> &GetCar(void);
VM::Mesh::CCar &GetCarAt(int);
bool AddCar(const std::vector<CVector3f>&,
const std::vector<VM::Mesh::CRoue>&,
const std::vector<VM::Mesh::CVitre>&,
const std::vector<CVector3f>&,
const std::vector<CVector3f>&,
const std::vector<CVector3f>&,
const std::vector<CVector3f>&);
private :
std::vector<VM::Mesh::CCar> mCar; // Tableau de voiture
protected :
};
Et là je suis en train d'essayé de coder les fonctions
VM::Mesh::CCar::CCalculateBaryC(std::vector<CVector3f>&);
et
VM::Mesh::CCar::CCalculateBaryC(void);
celle sans paramètre c'est pour calculer le barycentre du mBody du tableau VM::CCar::mCar indexé en 0 et affécté en mBaryC toujours du mCar[0].
et celle avec un paramètre c'est pour renvoyé un CVector3f du tableau en paramètre enfin bref.
Voilà ma fonction sans paramètre :
CODE
// Calculer le Barycentre
CVector3f VM::Mesh::CCar::CalculateBaryC(void)
{
// Declaration
CVector3f BC;
CVector3f temp;
VM::CCar car;
VM::Mesh::CCar mcar;
std::vector<VM::Mesh::CCar> tmcar;
std::vector<VM::CCar> tcar;
std::vector<CVector3f> tv;
// Initialisation
BC.Set(0.0f, 0.0f, 0.0f);
temp.Set(0.0f, 0.0f, 0.0f);
tmcar = car.GetCar();
mcar = tmcar[0];
tv = mcar.GetBody();
// Calculer
if((tmcar[0].GetBody()).empty()) // Si le tableau Body est vide
{
return CVector3f(0.0f, 0.0f, 0.0f);
tmcar[0].SetBarycentre(CVector3f(0.0f, 0.0f, 0.0f));
}
else // sinon
{
int i = tv.size();
for(int u = 0; u <= i; u++)
{
temp += tv[i];
}
BC = temp / i;
return BC;
tmcar[0].SetBarycentre(BC);
}
}
Et apparament j'ai une violation d'acces et on m'avais parlé d'iterator et j'ai pas trop bien compris et sur le net encore moi :S ... Enfin bref si quelqu'un aurai la gentiesse de me donné un peu de son temps pour me dire ce qui cloche sur mon code et pourquoi j'ai cette violation d'acces je suis aussi pres à entendre les critiques sur mes classes aussi ...
SKone le site SK1-SKone Production-SK1
|