Вообщем проблема состоит в том, что при нажатии на кнопку происходит считывание из файла через поток (координаты модели), после чего необходимо по полученным данным нарисовать её на форме... так вот функция DrawScene вообще отказывается работать( выскакивает ошибка exception, при попытки трассировки вообще отказывается запускаться ...
Код:
#include <fstream.h>
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
const int MAX_POINT_COUNT =100;
const int MAX_POLY_COUNT =100;
const int MAX_MODEL_COUNT = 3;
struct point
{
double x,y,z;
};
struct polygon
{
int points[3];
};
struct model3d
{
int PointCount;
point points[MAX_POINT_COUNT];
int PolygonCount;
polygon polygons[MAX_POLY_COUNT];
};
struct scene3d
{
int ModelCount;
model3d models[MAX_MODEL_COUNT];
};
void LoadScene(scene3d &scene,const char* filename)
{
model3d *model;
int i,m;
ifstream f1(filename);
if(f1)
{
f1>>scene.ModelCount;
for(m=0;m<scene.ModelCount;m++)
{
model=&scene.models[m];
f1>>model->PointCount;
for(i=0;i<model->PointCount;i++)
{
f1>>model->points[i].x>>model->points[i].y>>model->points[i].z;
model->points[i].x*=20;
model->points[i].y*=20;
model->points[i].z*=20;
}
f1>>model->PolygonCount;
for(i=0;i<model->PolygonCount;i++)
f1>>model->polygons[i].points[0]>>model->polygons[i].points[1]>>model->polygons[i].points[2];
}
f1.close();
}
else ShowMessage("Error: File not Found :(");
}
void DrawScene(scene3d scene)
{
int m,i;
TColor oldColor = Form1->Canvas->Brush->Color;
model3d *model;
Form1->Canvas->Brush->Color = RGB(255, 0, 0);
for(m=0;m<scene.ModelCount;m++)
{
model=&scene.models[m];
for(i=0;i<model->PolygonCount;i++)
{
Form1->Canvas->MoveTo(320+model->points[model->polygons[i].points[0]].x,
240+model->points[model->polygons[i].points[0]].y);
Form1->Canvas->LineTo(320+model->points[model->polygons[i].points[1]].x,
240+model->points[model->polygons[i].points[1]].y);
Form1->Canvas->MoveTo(320+model->points[model->polygons[i].points[1]].x,
240+model->points[model->polygons[i].points[1]].y);
Form1->Canvas->LineTo(320+model->points[model->polygons[i].points[2]].x,
240+model->points[model->polygons[i].points[2]].y);
Form1->Canvas->MoveTo(320+model->points[model->polygons[i].points[2]].x,
240+model->points[model->polygons[i].points[2]].y);
Form1->Canvas->LineTo(320+model->points[model->polygons[i].points[0]].x,
240+model->points[model->polygons[i].points[0]].y);
}
}
}
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
scene3d scene;
LoadScene(scene,"model.txt");
DrawScene(scene);
}
после нажатия на кнопку указывает на строку DrawScene(scene);
Есть идеи?)