Pb de tableau

Résolu
Asaturne Messages postés 6 Date d'inscription lundi 15 septembre 2003 Statut Membre Dernière intervention 22 mars 2005 - 22 mars 2005 à 18:24
Asaturne Messages postés 6 Date d'inscription lundi 15 septembre 2003 Statut Membre Dernière intervention 22 mars 2005 - 22 mars 2005 à 19:10
Suite du probleme que j ai eu plus tot voir le sujet "Pb de debutant" datant de mi-fevrier.

Je vous explique le concept de cette classe : cette classe represente un cube qui peut etre droppe dans un niveau. Lors de l'appui d'une touche, tous les cubes doivent pouvoir se connecter pour pouvoir par la suite parcourir le niveau a l'aide de ces cubes. Malheureusement je bloque sur une fonction avec pour theme un retour de tableau par l'intermediaire d'un pointeur. En esperant que vous pourrez m aider ...
Je sais ce probleme peut paraitre idiot mais coder une application pour un stage tout en apprenant un lanagage (le c, non appris pendant mes cours ... merci IUT montpellier) n est pas de ce qu il y a de plus facile.

En vous remerciant d'avance

Voici le header.

// Mappoint.h: interface for the Mappoint class.
//
//////////////////////////////////////////////////////////////////////


#if !defined(AFX_MAPPOINT_H__4B97FC50_0B56_468B_99C5_2B09A321470F__INCLUDED_)
#define AFX_MAPPOINT_H__4B97FC50_0B56_468B_99C5_2B09A321470F__INCLUDED_


#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000



class Mappoint;


#include <TL-Engine.h> // TL-Engine include file and namespace
using namespace tle;
#include "Waypoint2.h"
#include "Dropper.h"
#include "Mappoint_Array.h"


class Mappoint
{


float posX;
float posY;
float posZ;


IMesh* MappointMesh;
IModel* MappointModel;


int type;
int Radius;



Mappoint *Neighboors[3][3][3]; //Matrix who contains adress of nodes next to the current node



public:
//////////////////////////////////-CONSTRUCTORS-////////////////////////////////////////////////////////
Mappoint(); //Default Constructor
Mappoint(I3DEngine *engine, Dropper *player, int type); //Good constructor


virtual ~Mappoint();
////////////////////////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////-METHODS-//////////////////////////////////////////////////////////////
float GetX();
float GetY();
float GetZ();
//void RemoveConnexion(Dropper);
//*Waypoint CreatePath(Dropper);
//*Waypoinr MakePath(int Start,int End);
//SaveConnexions
//LoadConnexions


private:
bool BulletShoot(Mappoint *mpt,I3DEngine *engine,IModel *level,int a);
void Drawline(float x2,float y2,float z2,I3DEngine *engine);
bool *Mappoint::TestCollision(Mappoint_Array *mptA,I3DEngine *engine, IModel *level);
void MakeConnection(bool result[][3][3],Mappoint_Array *mptA);
};


#endif // !defined(AFX_MAPPOINT_H__4B97FC50_0B56_468B_99C5_2B09A321470F__INCLUDED_)

et voici le corps

// Mappoint.cpp: implementation of the Mappoint class.
//
//////////////////////////////////////////////////////////////////////


#include "Mappoint.h"
#include <math.h>


//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////


Mappoint::Mappoint()
{Radius=20;}

Mappoint::Mappoint(I3DEngine *engine, Dropper *player, int type)
{
posX=player->GetX();
posY=player->GetY();
posZ=player->GetZ();

this->type=type;

IMesh* MappointMesh = engine->LoadMesh("Cube.x");
IModel* MappointModel = MappointMesh->CreateModel(posX,posY,posZ);
MappointModel->SetSkin ("Tiles3.jpg");
Radius=20;
}



Mappoint::~Mappoint()
{}


float Mappoint::GetX(){return posX;}
float Mappoint::GetY(){return posY;}
float Mappoint::GetZ(){return posZ;}


bool Mappoint::BulletShoot(Mappoint *mpt,I3DEngine *engine,IModel *level,int a)
//Create a bullet who act as a collision detector, his move depends on the value of "a" who represents one of the 26 mappoints
//return true if the bullet "hit" mpt , else false
{}


void Mappoint::Drawline(float x2, float y2, float z2, I3DEngine *engine)
{


IMesh* lineMesh = engine->LoadMesh("Cube.x");
IModel* lineModel = lineMesh->CreateModel(this->GetX(),this->GetY(),this->GetZ());


bool finish=false;
while (!finish)
{
if (lineModel->GetX() <= x2){lineModel->MoveX((float)0.01);}
if (lineModel->GetX() >= x2){lineModel->MoveX((float)-0.01);}
if (lineModel->GetY() <= y2){lineModel->MoveY((float)0.01);}
if (lineModel->GetY() >= y2){lineModel->MoveY((float)-0.01);}
if (lineModel->GetZ() <= z2){lineModel->MoveZ((float)0.01);}
if (lineModel->GetZ() >= z2){lineModel->MoveZ((float)-0.01);}

if ( fabs((double)(x2-lineModel->GetX()))<=1 &&
fabs((double)(y2-lineModel->GetY()))<=1 &&
fabs((double)(z2-lineModel->GetZ()))<=1 )
{finish=true; }



IMesh* mesh=engine->LoadMesh("Cube.x");
IModel* model=mesh->CreateModel(lineModel->GetX(),lineModel->GetY(),lineModel->GetZ());
}
}


bool *Mappoint::TestCollision(Mappoint_Array *mptA,I3DEngine *engine, IModel *level)
{

float xcoord=0;
float ycoord=0;
float zcoord=0;


bool *result;


result = (bool*)malloc(27 * sizeof(bool)); // 9 * 3

int i=1;

for(int x=0;x<3;x++)
{ for(int y=0;y<3;y++)
{ for(int z=0;z<3;y++)
{
if (x=0) xcoord=-20;
else if (x=1) xcoord=0;
else xcoord=20;
if (y=0) ycoord=-20;
else if (y=1) ycoord=0;
else ycoord=20;
if (z=0) zcoord=-20;
else if (z=1) zcoord=0;
else zcoord=20;


Mappoint *current=mptA->getMappoint(this->GetX()+xcoord,this->GetY()+ycoord,
this->GetZ()+zcoord);


if (current) { result[x][y][z] = this->BulletShoot(current,engine,level,i);
i++;}

}
i++;
}
i++;
}


result [1][1][1]=false; // le cube d'origine

return result;
}


void Mappoint::MakeConnection(bool result[3][3][3], Mappoint_Array *mptA)
{
float xcoord=0;
float ycoord=0;
float zcoord=0;


for(int x=0;x<3;x++)
{ for(int y=0;y<3;y++)
{ for(int z=0;z<3;y++)
{
if (x=0) xcoord=-20;else if (x=1) xcoord=0;else xcoord=20;
if (y=0) ycoord=-20;else if (y=1) ycoord=0;else ycoord=20;
if (z=0) zcoord=-20;else if (z=1) zcoord=0;else zcoord=20;



if (result[x][y][z]){ Mappoint *current=mptA->getMappoint(this->GetX()+xcoord,this->GetY()+ycoord,this->GetZ()+zcoord);
this->Neighboors[x][y][z]=current;}

}
}
}
}

Enfin , voici le listing des erreurs

Compiling...
Mappoint.cpp
f:\project\application_v2\mappoint.cpp(238) : error C2109: subscript requires array or pointer type
f:\project\application_v2\mappoint.cpp(238) : error C2109: subscript requires array or pointer type
f:\project\application_v2\mappoint.cpp(238) : error C2106: '=' : left operand must be l-value
f:\project\application_v2\mappoint.cpp(247) : error C2109: subscript requires array or pointer type
f:\project\application_v2\mappoint.cpp(247) : error C2109: subscript requires array or pointer type
f:\project\application_v2\mappoint.cpp(247) : error C2106: '=' : left operand must be l-value
Generating Code...
Compiling...
Mappoint_Array.cpp
Generating Code...
Error executing cl.exe.


Application_v2.exe - 6 error(s), 0 warning(s)

2 réponses

Asaturne Messages postés 6 Date d'inscription lundi 15 septembre 2003 Statut Membre Dernière intervention 22 mars 2005
22 mars 2005 à 19:10
okie dokie ...
Je vais essayer ca.
3
ymca2003 Messages postés 2070 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 3 juillet 2006 7
22 mars 2005 à 18:33
result = (bool*)malloc(27 * sizeof(bool)); // 9 * 3

=> cela crée une zone continue en mémoire capable d'accueuillir 27 bool. tu as le droit de dire que cela représente un tableau à 3 dimensions mais le compilateur ne le sait pas.

le plus silmple, vue que les dimensions sont connues, c'est de passer le tableau en paramètre de ta fonction :

void Mappoint::TestCollision(Mappoint_Array *mptA,I3DEngine *engine, IModel *level, boll result[][3][3])

la première dimension n'est pas obligatoire.
0
Rejoignez-nous