Оператор ЭВМ
Регистрация: 16.09.2009
Сообщений: 23
Написано одно полезное сообщение
|
Ответ: Проблема с созданием банка

#include <windows.h>
#include <cstring>
#include <string>
#include <fstream>
#include <ctime>
#include "blitz3dsdk.h"
#include "Blitzpx.h"
using namespace std;
/*
Function BodyCreateHull%(mesh%, mass#)
Local nsurf = CountSurfaces(mesh)
Local nvert = 0
For ns = 1 To nsurf
Local surf = GetSurface(mesh,ns)
nvert = nvert + CountVertices(surf)
Next
vbank = CreateBank(nvert*4*3)
nv = 0
For ns = 1 To nsurf
surf = GetSurface(mesh,ns)
nvv = CountVertices(surf)
For nvc = 0 To nvv - 1
PokeFloat vbank,nv*12+0,VertexX(surf,nvc)
PokeFloat vbank,nv*12+4,VertexY(surf,nvc)
PokeFloat vbank,nv*12+8,VertexZ(surf,nvc)
nv = nv+1
Next
Next
Local bbb%= pxBodyCreateHull(vbank, nvert, mass)
FreeBank vbank
Return bbb
End Function
*/
void * CreateBank(int size)
{
return new BYTE[size];
}
void FreeBank(void * bank)
{
delete [] bank;
}
BYTE PeekByte(void * bank, int offset)
{
return *((BYTE*)(((char*)bank) + offset));
}
WORD PeekShort(void * bank, int offset)
{
return *((WORD*)(((char*)bank) + offset));
}
int PeekInt(void * bank, int offset)
{
return *((int*)(((char*)bank) + offset));
}
float PeekFloat(void * bank, int offset)
{
return *((float*)(((char*)bank) + offset));
}
void PokeByte(void * bank, int offset, BYTE value)
{
*((BYTE*)(((char*)bank) + offset))=value;
}
void PokeShort(void * bank, int offset, WORD value)
{
*((WORD*)(((char*)bank) + offset))=value;
}
void PokeInt(void * bank, int offset, int value)
{
*((int*)(((char*)bank) + offset)) = value;
}
void PokeFloat(void * bank, int offset, float value)
{
*((float*)(((char*)bank) + offset)) = value;
}
int GetVertCount(int mesh)
{
int verticesCount = 0;
for(int i = 0; i < bbCountSurfaces(mesh); i++)
{
verticesCount += bbCountVertices(bbGetSurface(mesh, i));
}
return verticesCount ;
}
void * GetVertBank(int mesh)
{
void * bank = CreateBank(GetVertCount(mesh) * 12);
int offset = 0;
for(int i = 0; i < bbCountSurfaces(mesh); i++)
{
int surface = bbGetSurface(mesh, i);
for(int j = 0; j < bbCountVertices(surface); j++)
{
PokeFloat(bank, offset + 0, bbVertexX(surface, j));
PokeFloat(bank, offset + 4, bbVertexY(surface, j));
PokeFloat(bank, offset + 8, bbVertexZ(surface, j));
offset+=12;
}
}
return bank;
}
void GenSB(int &mesh, int &SB)
{
mesh = bbLoadMesh("obj.b3d");
bbFlipMesh(mesh);
int mvn = GetVertCount(mesh);
float* mvbank =(float*)GetVertBank(mesh);
SB=pxBodyCreateHull(mvbank, mvn, 1);
FreeBank((void*)mvbank);
}
class cBox
{
public:
cBox();
~cBox();
int Entity;
int Body;
void Pick();
cBox* Next;
};
cBox::cBox()
{
srand(time(0));
int r,g,b;
r=rand()%255;
g=rand()%255;
b=rand()%255;
Next=NULL;
Entity=bbLoadMesh("obj.b3d");
Body=pxBodyCreateSphere(1,1);
pxBodySetPosition(Body,0,20,0);
bbEntityColor(Entity,r,g,b);
}
cBox::~cBox()
{
bbFreeEntity(Entity);
pxDeleteBody(Body);
}
void cBox::Pick()
{
bbPositionEntity(Entity,pxBodyGetPositionX(Body),pxBodyGetPositionY(Body),pxBodyGetPositionZ(Body));
bbRotateEntity(Entity,pxBodyGetRotationPitch(Body),pxBodyGetRotationYaw(Body),pxBodyGetRotationRoll(Body));
}
class cList
{
public:
cList();
void AddObj();
void PickObj();
void ClearObj();
int GetCount();
private:
cBox *first;
};
cList::cList()
{
first=NULL;
}
void cList::AddObj()
{
if(first)
{
cBox *temp=first;
while(temp->Next) temp=temp->Next;
temp->Next=new cBox();
}
else first=new cBox();
}
void cList::ClearObj()
{
if(first)
{
cBox *temp=first,*buff;
while(temp->Next)
{
buff=temp;
temp=temp->Next;
delete buff;
}
delete temp;
first=NULL;
}
}
int cList::GetCount()
{
cBox *temp=first;
int count=0;
while(temp)
{
count++;
temp=temp->Next;
}
return count;
}
void SetPhysx(int Entity, int Body)
{
bbPositionEntity(Entity,pxBodyGetPositionX(Body),pxBodyGetPositionY(Body),pxBodyGetPositionZ(Body));
bbRotateEntity(Entity,pxBodyGetRotationPitch(Body),pxBodyGetRotationYaw(Body),pxBodyGetRotationRoll(Body));
}
void cList::PickObj()
{
if(first!=NULL)
{
cBox* temp=first;
while(temp)
{
temp->Pick();
temp=temp->Next;
}
}
}
extern int WINAPI WinMain(HINSTANCE hThisInst,HINSTANCE hPrevInst,LPSTR lpszArgs,int nWinMode)
{
bbBeginBlitz3D();
bbGraphics3D(800,600,32,2);
int cam=bbCreateCamera();
bbPositionEntity(cam,0,10,-20);
int plane=bbCreatePlane();
bbEntityColor(plane,64,128,128);
int light=bbCreateLight();
pxCreateWorld(1,"");
pxSetGravity(0,-10,0);
int Obj;
int Bank;
GenSB(Obj, Bank);
cList BoxList;
char buffer[10];
while(!bbKeyHit(KEY_ESCAPE))
{
pxRenderPhysic(60,0);
if(bbKeyHit(KEY_SPACE)) BoxList.AddObj();
if(bbKeyHit(KEY_E)) BoxList.ClearObj();
BoxList.PickObj();
bbUpdateWorld();
bbRenderWorld();
sprintf_s(buffer, "%i", BoxList.GetCount());
bbText(100,100,buffer);
bbFlip();
}
bbEndBlitz3D();
return 0;
}
Выдает ошибку, причем сам блитц: Surface Index Out of Range. По виду все работает и компилируется правильно. Думал что цикл выскакивает за память, или за количество точек, пересмотрел циклы кажется все правильно...
|