From 6bad25fccb4e551dc0935df3e3552b48762eb5dd Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 13 Sep 2011 06:34:13 +0000 Subject: [PATCH] Deleted unused files. --- common/keyboard.cpp | 1 - common/piece.cpp | 47 - common/pieceinf.cpp | 88 -- common/project.cpp | 19 - common/typedefs.h | 1 - tools/convert/convert.c | 1720 ------------------------------------ tools/convert/convert.h | 221 ----- tools/convert/library.txt | 101 --- tools/convert/moved.txt | 365 -------- tools/convert/texture.cpp | 120 --- tools/convert/texture.h | 678 -------------- tools/setup/setup.ico | Bin 1078 -> 1078 bytes win/LeoCAD.rc | 11 +- win/barcmdui.cpp | 79 -- win/barcmdui.h | 12 - win/leocad.vcxproj | 4 - win/leocad.vcxproj.filters | 12 - win/res/bitmap1.bmp | Bin 478 -> 0 bytes win/res/bitmap2.bmp | Bin 238 -> 0 bytes win/res/caddoc.ico | Bin 1078 -> 0 bytes win/res/cursor1.cur | Bin 326 -> 0 bytes win/res/editor.bmp | Bin 630 -> 0 bytes win/res/itoolbar.bmp | Bin 718 -> 0 bytes win/res/leocad.ico | Bin 1078 -> 0 bytes win/res/pieceed.bmp | Bin 478 -> 0 bytes win/resource.h | 3 +- win/rmodel.cpp | 1536 -------------------------------- win/rmodel.h | 97 -- 28 files changed, 2 insertions(+), 5113 deletions(-) delete mode 100644 tools/convert/convert.c delete mode 100644 tools/convert/convert.h delete mode 100755 tools/convert/library.txt delete mode 100644 tools/convert/moved.txt delete mode 100644 tools/convert/texture.cpp delete mode 100644 tools/convert/texture.h delete mode 100644 win/barcmdui.cpp delete mode 100644 win/barcmdui.h delete mode 100644 win/res/bitmap1.bmp delete mode 100644 win/res/bitmap2.bmp delete mode 100644 win/res/caddoc.ico delete mode 100644 win/res/cursor1.cur delete mode 100644 win/res/editor.bmp delete mode 100644 win/res/itoolbar.bmp delete mode 100644 win/res/leocad.ico delete mode 100644 win/res/pieceed.bmp delete mode 100644 win/rmodel.cpp delete mode 100644 win/rmodel.h diff --git a/common/keyboard.cpp b/common/keyboard.cpp index ceff07c2..3261d426 100644 --- a/common/keyboard.cpp +++ b/common/keyboard.cpp @@ -74,7 +74,6 @@ LC_KEYBOARD_COMMAND DefaultKeyboardShortcuts[] = { LC_VIEW_CAMERA_MAIN, "Camera Main", LC_KEYMOD_VIEWONLY, LC_KEY_M, 0 }, // { LC_VIEW_CAMERA_MENU, "", 0, 0, 0 }, // { LC_VIEW_CAMERA_RESET, "", 0, 0, 0 }, -// { LC_VIEW_AUTOPAN, "", 0, 0, 0 }, // { LC_HELP_ABOUT, "", 0, 0, 0 }, // { LC_TOOLBAR_ANIMATION, "", 0, 0, 0 }, // { LC_TOOLBAR_ADDKEYS, "", 0, 0, 0 }, diff --git a/common/piece.cpp b/common/piece.cpp index 8569d2a0..324e6c16 100644 --- a/common/piece.cpp +++ b/common/piece.cpp @@ -1834,50 +1834,3 @@ void Piece::RemoveConnections(CONNECTION_TYPE* pConnections) for (i = 0; i < RebuildList.GetSize(); i++) RebuildList[i]->BuildDrawInfo(); } - -/* -// Performs exact collision detection using the RAPID library. -// Check if there are 2 objects at the same place at the same time -BOOL CPiece::Collide(CPiece* pPiece) -{ - return CollideAt(pPiece, m_fRotation, m_fPosition); -} - -// Use this to check if the piece can be modified -BOOL CPiece::CollideAt(CPiece* pPiece, float rot[4], float pos[3]) -{ - double rotation1[3][3], rotation2[3][3]; - double translation1[3], translation2[3]; - - CMatrix m1(rot, pos); - rotation1[0][0] = m1.m[0]; - rotation1[0][1] = m1.m[4]; - rotation1[0][2] = m1.m[8]; - rotation1[1][0] = m1.m[1]; - rotation1[1][1] = m1.m[5]; - rotation1[1][2] = m1.m[9]; - rotation1[2][0] = m1.m[2]; - rotation1[2][1] = m1.m[6]; - rotation1[2][2] = m1.m[10]; - translation1[0] = m1.m[12]; - translation1[1] = m1.m[13]; - translation1[2] = m1.m[14]; - - CMatrix m2(pPiece->m_fRotation, pPiece->m_fPosition); - rotation2[0][0] = m2.m[0]; - rotation2[0][1] = m2.m[4]; - rotation2[0][2] = m2.m[8]; - rotation2[1][0] = m2.m[1]; - rotation2[1][1] = m2.m[5]; - rotation2[1][2] = m2.m[9]; - rotation2[2][0] = m2.m[2]; - rotation2[2][1] = m2.m[6]; - rotation2[2][2] = m2.m[10]; - translation2[0] = m2.m[12]; - translation2[1] = m2.m[13]; - translation2[2] = m2.m[14]; - - return CollisionCheck(rotation1, translation1, m_pInfo->m_pRModel, - rotation2, translation2, pPiece->m_pInfo->m_pRModel); -} -*/ diff --git a/common/pieceinf.cpp b/common/pieceinf.cpp index 244ecc21..e6b79431 100644 --- a/common/pieceinf.cpp +++ b/common/pieceinf.cpp @@ -1410,94 +1410,6 @@ void PieceInfo::LoadInformation() } free(buf); - -/* - // Now create the information for the CD - // If the object is big this can block the program for serveral seconds. - // ATTENTION: The RAPID CD library is based on triangles. - - if (pInfo->pRModel) - delete pInfo->pRModel; - - pInfo->pRModel = new CRModel(); - pInfo->pRModel->BeginModel(); - - UINT col, loc, j, i; - int vert = 0; - - for (UINT c = 0; c < pInfo->cons; c++) - { - if (pInfo->connection[c].info == NULL) - continue; - if (pInfo->count > 65535) - { - UINT* info = (UINT*)pInfo->connection[c].info; - loc = 1; - col = info[0]; - while (col) - { - loc++; - - j = info[loc]; - for (i = 0; i < j; i+=4) - { - pInfo->pRModel->AddTri(&pInfo->vertex[info[loc+i+1]*3], &pInfo->vertex[info[loc+i+2]*3], - &pInfo->vertex[info[loc+i+3]*3], vert); - vert++; - pInfo->pRModel->AddTri(&pInfo->vertex[info[loc+i+3]*3], &pInfo->vertex[info[loc+i+4]*3], - &pInfo->vertex[info[loc+i+1]*3], vert); - vert++; - } - loc += j+1; - j = info[loc]; - for (i = 0; i < j; i+=3) - { - pInfo->pRModel->AddTri(&pInfo->vertex[info[loc+i+1]*3], &pInfo->vertex[info[loc+i+2]*3], - &pInfo->vertex[info[loc+i+3]*3], vert); - vert++; - } - loc += j+1; - loc += info[loc]+1; - - col--; - } - } - else - { - WORD* info = (WORD*)pInfo->connection[c].info; - loc = 1; - col = info[0]; - while (col) - { - loc++; - - j = info[loc]; - for (i = 0; i < j; i+=4) - { - pInfo->pRModel->AddTri(&pInfo->vertex[info[loc+i+1]*3], &pInfo->vertex[info[loc+i+2]*3], - &pInfo->vertex[info[loc+i+3]*3], vert); - vert++; - pInfo->pRModel->AddTri(&pInfo->vertex[info[loc+i+3]*3], &pInfo->vertex[info[loc+i+4]*3], - &pInfo->vertex[info[loc+i+1]*3], vert); - vert++; - } - loc += j+1; - j = info[loc]; - for (i = 0; i < j; i+=3) - { - pInfo->pRModel->AddTri(&pInfo->vertex[info[loc+i+1]*3], &pInfo->vertex[info[loc+i+2]*3], - &pInfo->vertex[info[loc+i+3]*3], vert); - vert++; - } - loc += j+1; - loc += info[loc]+1; - - col--; - } - } - } - pInfo->pRModel->EndModel(); -*/ } void PieceInfo::FreeInformation() diff --git a/common/project.cpp b/common/project.cpp index ab5ea3fe..4bb54cf1 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -6095,25 +6095,6 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam) CheckPoint("Reset Cameras"); } break; - case LC_VIEW_AUTOPAN: - { - if (IsDrawing()) - break; - - short x = (short)nParam; - short y = (short)((nParam >> 16) & 0xFFFF); - - x -= x > 0 ? 5 : -5; - y -= y > 0 ? 5 : -5; - - m_pViewCameras[m_nActiveViewport]->DoPan(x/4, y/4, 1, m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation, m_bAddKeys); - m_nDownX = x; - m_nDownY = y; - UpdateOverlayScale(); - SystemUpdateFocus(NULL); - UpdateAllViews(); - } break; - case LC_HELP_ABOUT: { SystemDoDialog(LC_DLG_ABOUT, 0); diff --git a/common/typedefs.h b/common/typedefs.h index ce68b1f5..015f6f61 100644 --- a/common/typedefs.h +++ b/common/typedefs.h @@ -88,7 +88,6 @@ typedef enum LC_VIEW_CAMERA_MAIN, LC_VIEW_CAMERA_MENU, LC_VIEW_CAMERA_RESET, - LC_VIEW_AUTOPAN, LC_HELP_ABOUT, LC_TOOLBAR_ANIMATION, LC_TOOLBAR_ADDKEYS, diff --git a/tools/convert/convert.c b/tools/convert/convert.c deleted file mode 100644 index dfba77f5..00000000 --- a/tools/convert/convert.c +++ /dev/null @@ -1,1720 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include "convert.h" - -typedef struct CONNECTION -{ - unsigned char type; - float pos[3]; - float up[3]; - struct CONNECTION* next; -} CONNECTION; - -typedef struct GROUP -{ - CONNECTION* connections[5]; - void* drawinfo; - unsigned long infosize; - struct GROUP* next; -} GROUP; - -typedef struct lineinfo_s -{ - unsigned char type; - unsigned char color; - float points[12]; - struct lineinfo_s* next; -} lineinfo_t; - -typedef struct TEXTURE -{ - float points[20]; - unsigned char color; - char name[9]; - struct TEXTURE* next; -} TEXTURE; - -float* _fVerts; -unsigned int _nVertsCount; -CONNECTION* _pConnections; -GROUP* _pGroups; -TEXTURE* _pTextures; -char _strName[9]; -char _strDescription[65]; - -// stud, technic stud, stud under 1x? plate, stud under ?x? plate -char* valid[12] = { "STUD.DAT", "STUD2.DAT", "STUD3.DAT", "STUD4.DAT" }; -unsigned char numvalid = 4; - -#define LC_MESH 1 -#define LC_STUD 2 -#define LC_STUD2 3 -#define LC_STUD3 4 -#define LC_STUD4 5 - -///////////////////////////////////////////////////// -// functions - -static unsigned long GetDefaultPieceGroup(char* name) -{ - char tmp[9]; - strncpy (tmp, name, 9); -// tmp[8] = 0; - - if (strstr(tmp,"Baseplate") || strstr(tmp,"Plate") || - strstr(tmp,"Platform")) - return 0x001; - - if (strstr(tmp,"Brick") || strstr(tmp,"Cylin") || - strstr(tmp,"Cone")) - return 0x002; - - if (strstr(tmp,"Tile")) - return 0x004; - - if (strstr(tmp,"Slope")) - return 0x008; - - if (strstr(tmp,"Technic") || strstr(tmp,"Crane") || - strstr(tmp,"Wheel") || strstr(tmp,"Tyre") || - strstr(tmp,"Electric")) - return 0x010; - - // space & plane - if (strstr(tmp,"Space") || strstr(tmp,"Plane") || - strstr(tmp,"Windscr") || strstr(tmp,"~2421") || - strstr(tmp,"Wing") || strstr(tmp,"Wedge") || - strstr(tmp,"Propellor") || strstr(tmp,"Rotor") || - strstr(tmp,"Rack") || strstr(tmp,"Tail")) - return 0x020; - - if (strstr(tmp,"Train")) - return 0x040; - - // other parts - if (strstr(tmp,"Arch") || strstr(tmp,"Panel") || - strstr(tmp,"Car") || strstr(tmp,"Window") || - strstr(tmp,"Freestyle") || strstr(tmp,"Support")|| - strstr(tmp,"Fence") || strstr(tmp,"Gate") || - strstr(tmp,"Garage") || strstr(tmp,"Stairs") || - strstr(tmp,"Bracket") || strstr(tmp,"Hinge") || - strstr(tmp,"Homemaker") || strstr(tmp,"Rock") || - strstr(tmp,"Cupboard") || strstr(tmp,"Storage")|| - strstr(tmp,"Scala") || strstr(tmp,"Boat") || - strstr(tmp,"Trailer") || strstr(tmp,"Box") || - strstr(tmp,"Turntab") || strstr(tmp,"Winch") || - strstr(tmp,"Door") || strstr(tmp,"Magnet")) - return 0x080; - - // accessories - if (strstr(tmp,"Minifig") || strstr(tmp,"Antenna")|| - strstr(tmp,"Ladder") || strstr(tmp,"Jack") || - strstr(tmp,"Exhaust") || strstr(tmp,"Lever") || - strstr(tmp,"Roadsign") || strstr(tmp,"Town") || - strstr(tmp,"Leaves") || strstr(tmp,"Horse") || - strstr(tmp,"Tree") || strstr(tmp,"Flower") || - strstr(tmp,"Plant") || - strstr(tmp,"Conveyor") || strstr(tmp,"Tractor")|| - strstr(tmp,"Grab") || strstr(tmp,"Roller") || - strstr(tmp,"Stretch") || strstr(tmp,"Tap ") || - strstr(tmp,"Forklift") || strstr(tmp,"Flag") || - strstr(tmp,"Belville") || strstr(tmp,"Light &")|| - strstr(tmp,"Hose") || strstr(tmp,"Arm P") || - strstr(tmp,"Brush") || strstr(tmp,"Castle") || - strstr(tmp,"Tipper") || strstr(tmp,"Bar")) - return 0x100; - - return 1; -} - -static __inline GROUP* NewGroup() -{ - GROUP* pGroup; - - if (_pGroups) - { - pGroup = _pGroups; - while (pGroup->next) - pGroup = pGroup->next; - pGroup->next = (GROUP*)malloc(sizeof(GROUP)); - pGroup = pGroup->next; - } - else - { - _pGroups = (GROUP*)malloc(sizeof(GROUP)); - pGroup = _pGroups; - } - - memset(pGroup, 0, sizeof(GROUP)); - - return pGroup; -} - -static __inline CONNECTION* AddConnection(CONNECTION* pNew) -{ - CONNECTION* pCon; - - pCon = _pConnections; - while (pCon) - { - if ((pCon->type == pNew->type) && - FloatPointsClose(pCon->pos, pNew->pos) && - FloatPointsClose(pCon->up, pNew->up)) - { - free(pNew); - return pCon; - } - - pCon = pCon->next; - } - - if (_pConnections) - { - pCon = _pConnections; - while (pCon->next) - pCon = pCon->next; - pCon->next = pNew; - } - else - { - _pConnections = pNew; - pNew->next = NULL; - } - - return pNew; -} - -void CleanUp() -{ - GROUP *tmp, *pg = _pGroups; - CONNECTION *ctmp, *pc = _pConnections; - TEXTURE *ttmp, *pt = _pTextures; - _nVertsCount = 0; - _pGroups = NULL; - _pConnections = NULL; - _pTextures = NULL; - - if (_fVerts != NULL) - { - free(_fVerts); - _fVerts = NULL; - } - - while (pt) - { - ttmp = pt->next; - free(pt); - pt = ttmp; - }; - - while (pg != NULL) - { - free (pg->drawinfo); - tmp = pg; - pg = pg->next; - free (tmp); - } - - while (pc != NULL) - { - ctmp = pc; - pc = pc->next; - free (ctmp); - } -} - -void CreateMesh(GROUP* pGroup, lineinfo_t* info) -{ - lineinfo_t *a, *b; - int i, j, k, v; - unsigned int count[256][3], vert = 0; - unsigned char* bytes; - memset (count, 0, sizeof(count)); - - for (a = info->next; a; a = a->next) - { - count[a->color][a->type-2]++; - vert += a->type; - } - - k = 0; - for (i = 0; i < 256; i++) - { - if (count[i][0] || count[i][1] || count[i][2]) - k++; - } - - if (_nVertsCount > 65535) - { - unsigned long* drawinfo; - pGroup->infosize = sizeof(unsigned long)*(vert + (k*4)+1) + 2; - pGroup->drawinfo = malloc(pGroup->infosize); - bytes = (unsigned char*)pGroup->drawinfo; - drawinfo = (unsigned long*)(bytes + 1); - *bytes = LC_MESH; - *drawinfo = k; // number colors - drawinfo++; - - for (i = 16; i < 256; i++) - { - if (count[i][0] || count[i][1] || count[i][2]) - { - *drawinfo = i; - drawinfo++; - - printf("%d ", i); - - for (j = 4; j > 1; j--) - { - *drawinfo = count[i][j-2]*j; - drawinfo++; - printf("%d ", count[i][j-2]*j); - - if (count[i][j-2] != 0) - { - a = info->next; - b = info; - while(a) - if ((a->type == j) && (a->color == i)) - { - for (k = 0; k < a->type; k++) - for (v = 0; v < (int)_nVertsCount; v++) - if (FloatPointsClose(&_fVerts[v*3], &a->points[k*3])) - { - *drawinfo = v; - drawinfo++; - break; - } - - b->next = a->next; - free(a); - a = b->next; - } - else - { - b = a; - a = a->next; - } - } - } - } - - if (i == 16) i = -1; - if (i == 15) i = 23; - } - - printf("\n"); - } - else - { - unsigned short* drawinfo; - pGroup->infosize = sizeof(unsigned short)*(vert + (k*4)+1) + 2; - pGroup->drawinfo = malloc(pGroup->infosize); - bytes = (unsigned char*)pGroup->drawinfo; - drawinfo = (unsigned short*)(bytes + 1); - *bytes = LC_MESH; - *drawinfo = k; // number colors - drawinfo++; - - for (i = 16; i < 256; i++) - { - if (count[i][0] || count[i][1] || count[i][2]) - { - *drawinfo = i; - drawinfo++; - } - - for (j = 4; j > 1; j--) - { - if (count[i][0] || count[i][1] || count[i][2]) - { - *drawinfo = count[i][j-2]*j; - drawinfo++; - } - - if (count[i][j-2] != 0) - { - a = info->next; - b = info; - while(a) - if ((a->type == j) && (a->color == i)) - { - for (k = 0; k < a->type; k++) - for (v = 0; v < (int)_nVertsCount; v++) - if (FloatPointsClose(&_fVerts[v*3], &a->points[k*3])) - { - *drawinfo = v; - drawinfo++; - break; - } - - b->next = a->next; - free(a); - a = b->next; - } - else - { - b = a; - a = a->next; - } - } - } - - if (i == 16) i = -1; - if (i == 15) i = 23; - } - } - - bytes[pGroup->infosize-1] = 0; // End -} - -void decodefile (FILE *F, matrix *mat, unsigned char defcolor, lineinfo_t* info, char* dir) -{ - char buf[1024]; - int type, color; - char fn[260], filename[32]; - float fm[12]; - unsigned char val; - FILE *tf; - - while (fgets(buf, 1024, F)) - { - while (buf[strlen(buf)-1] == 10 || buf[strlen(buf)-1] == 13 || buf[strlen(buf)-1] == 32) - buf[strlen(buf)-1] = 0; - - type = -1; - sscanf(buf, "%d", &type); - - if (type == 6) - { - float* f; - - TEXTURE* tex; - if (_pTextures) - { - tex = _pTextures; - while (tex->next) - tex = tex->next; - tex->next = (TEXTURE*)malloc(sizeof(TEXTURE)); - tex = tex->next; - } - else - { - _pTextures = (TEXTURE*)malloc(sizeof(TEXTURE)); - tex = _pTextures; - } - memset(tex, 0, sizeof(TEXTURE)); - f = tex->points; - - sscanf (buf, "%d %d %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %s", - &type, &color, &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6], &f[7], &f[8], &f[9], - &f[10], &f[11], &f[12], &f[13], &f[14], &f[15], &f[16], &f[17], &f[18], &f[19], tex->name); - tex->color = color; - ConvertPoints (f, 4); - - continue; - } - - if (type > 1 && type < 5) - { - lineinfo_t* newinfo = (lineinfo_t*)malloc(sizeof(lineinfo_t)); - info->next = newinfo; - newinfo->next = 0; - newinfo->type = type; - info = newinfo; - } - - switch (type) - { - case 1: - { - sscanf (buf, "%d %d %f %f %f %f %f %f %f %f %f %f %f %f %s", - &type, &color, &fm[0], &fm[1], &fm[2], &fm[3], &fm[4], &fm[5], &fm[6], &fm[7], &fm[8], &fm[9], &fm[10], &fm[11], filename); - - strcpy (fn, dir); - strcat (fn, "P\\"); - strcat (fn, filename); - - strupr(filename); - for (val = 0; val < numvalid; val++) - if (strcmp(filename, valid[val]) == 0) - break; - if (val != numvalid) - break; - - if (color == 16) color = defcolor; - - tf = fopen (fn, "rt"); - - if (!tf) - { - strcpy (fn, dir); - strcat (fn, "PARTS\\"); - strcat (fn, filename); - tf = fopen (fn, "rt"); - } - - if (!tf) - { - strcpy (fn, dir); - strcat (fn, "PARTS\\S\\"); - strcat (fn, filename); - tf = fopen (fn, "rt"); - } - - if (tf) - { - matrix m1, m2; - LoadIdentity(&m1); - LoadIdentity(&m2); - ConvertFromLDraw (&m1, fm); - Multiply(&m2, mat, &m1); - - decodefile (tf, &m2, (unsigned char)color, info, dir); - while (info->next) - info = info->next; - fclose(tf); - } - } break; - - case 2: - { - sscanf (buf, "%d %d %f %f %f %f %f %f", &type, &color, - &info->points[0], &info->points[1], &info->points[2], - &info->points[3], &info->points[4], &info->points[5]); - if (color == 16) color = defcolor; - if (color > 256) color -= 256; - info->color = color; - ConvertPoints (info->points, 2); - TransformPoints (mat, info->points, 2); - } break; - - case 3: - { - sscanf (buf, "%d %d %f %f %f %f %f %f %f %f %f", &type, &color, - &info->points[0], &info->points[1], &info->points[2], - &info->points[3], &info->points[4], &info->points[5], - &info->points[6], &info->points[7], &info->points[8]); - if (color == 16) color = defcolor; - if (color > 256) color -= 256; - info->color = color; - ConvertPoints (info->points, 3); - TransformPoints (mat, info->points, 3); - } break; - - case 4: - { - sscanf (buf, "%d %d %f %f %f %f %f %f %f %f %f %f %f %f", &type, &color, - &info->points[0], &info->points[1], &info->points[2], - &info->points[3], &info->points[4], &info->points[5], - &info->points[6], &info->points[7], &info->points[8], - &info->points[9], &info->points[10], &info->points[11]); - if (color == 16) color = defcolor; - if (color > 256) color -= 256; - info->color = color; - ConvertPoints (info->points, 4); - TransformPoints (mat, info->points, 4); - FixQuads(info->points); - -#ifdef TRIANGULATE - LINEINFO* newinfo = (LINEINFO*)malloc(sizeof(LINEINFO)); - info->next = newinfo; - info->type = 3; - newinfo->next = NULL; - newinfo->type = 3; - newinfo->color = color; - newinfo->points[0] = info->points[6]; - newinfo->points[1] = info->points[7]; - newinfo->points[2] = info->points[8]; - newinfo->points[3] = info->points[9]; - newinfo->points[4] = info->points[10]; - newinfo->points[5] = info->points[11]; - newinfo->points[6] = info->points[0]; - newinfo->points[7] = info->points[1]; - newinfo->points[8] = info->points[2]; - info = newinfo; -#endif - } break; - - } - memset (buf, 0, sizeof(buf)); - } -} - -void decodeconnections (FILE *F, matrix *mat, unsigned char defcolor, char* dir) -{ - char buf[1024]; - int type, color; - char fn[260], filename[32]; - float fm[12]; - matrix m1, m2; - unsigned char val; - FILE *tf; - GROUP* pGroup; - CONNECTION* pCon; - unsigned char* bytes; - float* floats; - - while (fgets(buf, 1024, F)) - { - while (buf[strlen(buf)-1] == 10 || buf[strlen(buf)-1] == 13 || buf[strlen(buf)-1] == 32) - buf[strlen(buf)-1] = 0; - - type = -1; - sscanf(buf, "%d", &type); - - if (type != 1) - { - memset (buf, 0, sizeof(buf)); - continue; - } - - sscanf (buf, "%d %d %f %f %f %f %f %f %f %f %f %f %f %f %s", - &type, &color, &fm[0], &fm[1], &fm[2], &fm[3], &fm[4], &fm[5], &fm[6], &fm[7], &fm[8], &fm[9], &fm[10], &fm[11], filename); - - strcpy (fn, dir); - strcat (fn, "P\\"); - strcat (fn, filename); - - if (color == 16) color = defcolor; - - strupr(filename); - for (val = 0; val < numvalid; val++) - if (strcmp(filename, valid[val]) == 0) - { - LoadIdentity(&m1); - LoadIdentity(&m2); - ConvertFromLDraw (&m1, fm); - Multiply (&m2, mat, &m1); - - if (val == 0) // STUD.DAT - { - pGroup = NewGroup(); - pCon = (CONNECTION*)malloc(sizeof(CONNECTION)); - memset(pCon, 0, sizeof(CONNECTION)); - - pGroup->infosize = 3*sizeof(unsigned char) + 12*sizeof(float); - pGroup->drawinfo = malloc(pGroup->infosize); - bytes = pGroup->drawinfo; - floats = (float*)(bytes+2); - - bytes[0] = LC_STUD; - bytes[1] = color; // color - floats[0] = m2.m[0]; - floats[1] = m2.m[1]; - floats[2] = m2.m[2]; - floats[3] = m2.m[4]; - floats[4] = m2.m[5]; - floats[5] = m2.m[6]; - floats[6] = m2.m[8]; - floats[7] = m2.m[9]; - floats[8] = m2.m[10]; - floats[9] = m2.m[12]; - floats[10] = m2.m[13]; - floats[11] = m2.m[14]; - bytes[pGroup->infosize-1] = 0; // end - - pCon->type = 0; // stud - pCon->pos[0] = m2.m[12]; - pCon->pos[1] = m2.m[13]; - pCon->pos[2] = m2.m[14]; - pCon->up[2] = 1; - TransformPoints(&m2, pCon->up, 1); - pCon->up[0] -= m2.m[12]; - pCon->up[1] -= m2.m[13]; - pCon->up[2] -= m2.m[14]; - - pCon = AddConnection(pCon); - pGroup->connections[0] = pCon; - } - - if (val == 1) // STUD2.DAT - { - pGroup = NewGroup(); - pCon = (CONNECTION*)malloc(sizeof(CONNECTION)); - memset(pCon, 0, sizeof(CONNECTION)); - - pGroup->infosize = 3*sizeof(unsigned char) + 12*sizeof(float); - pGroup->drawinfo = malloc(pGroup->infosize); - bytes = pGroup->drawinfo; - floats = (float*)(bytes+2); - - bytes[0] = LC_STUD2; - bytes[1] = color; // color - floats[0] = m2.m[0]; - floats[1] = m2.m[1]; - floats[2] = m2.m[2]; - floats[3] = m2.m[4]; - floats[4] = m2.m[5]; - floats[5] = m2.m[6]; - floats[6] = m2.m[8]; - floats[7] = m2.m[9]; - floats[8] = m2.m[10]; - floats[9] = m2.m[12]; - floats[10] = m2.m[13]; - floats[11] = m2.m[14]; - bytes[pGroup->infosize-1] = 0; // end - - pCon->type = 0; // stud - pCon->pos[0] = m2.m[12]; - pCon->pos[1] = m2.m[13]; - pCon->pos[2] = m2.m[14]; - pCon->up[2] = 1; - TransformPoints(&m2, pCon->up, 1); - pCon->up[0] -= m2.m[12]; - pCon->up[1] -= m2.m[13]; - pCon->up[2] -= m2.m[14]; - - pCon = AddConnection(pCon); - pGroup->connections[0] = pCon; - } - - if (val == 2) // STUD3.DAT - { - pGroup = NewGroup(); - pGroup->infosize = 3*sizeof(unsigned char) + 12*sizeof(float); - pGroup->drawinfo = malloc(pGroup->infosize); - bytes = pGroup->drawinfo; - floats = (float*)(bytes+2); - - bytes[0] = LC_STUD3; - bytes[1] = color; // color - floats[0] = m2.m[0]; - floats[1] = m2.m[1]; - floats[2] = m2.m[2]; - floats[3] = m2.m[4]; - floats[4] = m2.m[5]; - floats[5] = m2.m[6]; - floats[6] = m2.m[8]; - floats[7] = m2.m[9]; - floats[8] = m2.m[10]; - floats[9] = m2.m[12]; - floats[10] = m2.m[13]; - floats[11] = m2.m[14]; - bytes[pGroup->infosize-1] = 0; // end - } - - if (val == 3) // STUD4.DAT - { - float t[4][3] = { {0.4f,0.4f,0}, {-0.4f,0.4f,0}, {0.4f,-0.4f,0}, {-0.4f,-0.4f,0} }; - int c; - - pGroup = NewGroup(); - pGroup->infosize = 3*sizeof(unsigned char) + 12*sizeof(float); - pGroup->drawinfo = malloc(pGroup->infosize); - bytes = pGroup->drawinfo; - floats = (float*)(bytes+2); - - bytes[0] = LC_STUD4; - bytes[1] = color; // color - floats[0] = m2.m[0]; - floats[1] = m2.m[1]; - floats[2] = m2.m[2]; - floats[3] = m2.m[4]; - floats[4] = m2.m[5]; - floats[5] = m2.m[6]; - floats[6] = m2.m[8]; - floats[7] = m2.m[9]; - floats[8] = m2.m[10]; - floats[9] = m2.m[12]; - floats[10] = m2.m[13]; - floats[11] = m2.m[14]; - bytes[pGroup->infosize-1] = 0; // end - - for (c = 0; c < 4; c++) - { - pCon = (CONNECTION*)malloc(sizeof(CONNECTION)); - memset(pCon, 0, sizeof(CONNECTION)); - pCon->type = 1; // inv stud - TranslatePoint(&m2, pCon->pos, t[c]); - pCon->pos[2] -= 0.16f; - - pCon->up[2] = 1; - TransformPoints(&m2, pCon->up, 1); - pCon->up[0] -= m2.m[12]; - pCon->up[1] -= m2.m[13]; - pCon->up[2] -= m2.m[14]; - - pGroup->connections[c] = AddConnection(pCon); - } - - pCon = (CONNECTION*)malloc(sizeof(CONNECTION)); - memset(pCon, 0, sizeof(CONNECTION)); - pCon->type = 1; // inv stud - pCon->pos[2] -= 0.16f; - - pCon->up[2] = 1; - TransformPoints(&m2, pCon->up, 1); - pCon->up[0] -= m2.m[12]; - pCon->up[1] -= m2.m[13]; - pCon->up[2] -= m2.m[14]; - - AddConnection(pCon); - } - - memset (buf, 0, sizeof(buf)); - continue; - } - - tf = fopen (fn, "rt"); - - if (!tf) - { - strcpy (fn, dir); - strcat (fn, "PARTS\\"); - strcat (fn, filename); - tf = fopen (fn, "rt"); - } - - if (!tf) - { - strcpy (fn, dir); - strcat (fn, "PARTS\\S\\"); - strcat (fn, filename); - tf = fopen (fn, "rt"); - } - - if (tf) - { - matrix m1, m2; - LoadIdentity(&m1); - LoadIdentity(&m2); - ConvertFromLDraw (&m1, fm); - Multiply(&m2, mat, &m1); - - decodeconnections (tf, &m2, (unsigned char)color, dir); -// while (info->next) -// info = info->next; - fclose(tf); - } - - memset (buf, 0, sizeof(buf)); - } -} - -void ReadFile(char* strFile) -{ - char fn[260], tmp[260], *ptr; - matrix mat; - float* verts; - unsigned long i, j, unique; - lineinfo_t info, *a; - FILE *f; -// drawgroup_t* ldg; - - CleanUp(); - memset(_strName, 0, sizeof(_strName)); - memset(_strDescription, 0, sizeof(_strDescription)); - - strcpy(tmp, strFile); - if (ptr = strrchr(tmp, '.')) *ptr = 0; - ptr = strrchr(tmp, '\\'); - if (ptr == NULL) - ptr = tmp; - else - ptr++; - strcpy (_strName, ptr); - strupr (_strName); - -//(&_fVerts, &_nVertsCount); -//(float** ppVerts, unsigned int* nCount) - LoadIdentity(&mat); - info.next = 0; - info.type = 0; - - f = fopen (strFile, "rt"); - if (fgets (tmp, 100, f)) - { - while (tmp[strlen(tmp)-1]==10||tmp[strlen(tmp)-1]==13||tmp[strlen(tmp)-1]==32) - tmp[strlen(tmp)-1]=0; - tmp[66] = 0; - strcpy (_strDescription, tmp+2); - } - - printf("File %s : %s\n", _strName, _strDescription); - - strcpy (fn, strFile); - if (ptr = strrchr(fn, '.')) *ptr = 0; - memset (tmp, 0, sizeof(char[100])); - ptr = strrchr(fn, '\\'); - if (ptr == 0) - ptr = fn; - else - ptr++; - strcpy (tmp, ptr); - strupr (tmp); - - strcpy (fn, strFile); - ptr = strrchr(fn, '\\'); - *ptr = 0; - ptr = strrchr(fn, '\\'); - *(ptr+1) = 0; - - decodefile (f, &mat, 16, &info, fn); - fclose (f); - - unique = 0; - verts = (float*)malloc(sizeof(float)*1500); - - // Create array of unique vertices - for (a = info.next; a; a = a->next) - { - for (j = 0; j < a->type; j++) - { - for (i = unique-1; i != -1; i--) - if (FloatPointsClose(&verts[i*3], &a->points[j*3])) - break; - - if (i == -1) - { - if ((unique % 500) == 0) - verts = (float*)realloc(verts, sizeof(float)*3*(unique+500)); - memcpy(&verts[unique*3], &a->points[j*3], sizeof(float)*3); - unique++; - } - } - } - - _fVerts = verts; - _nVertsCount = unique; - printf ("%d vertexes\n", unique); - - // Main group - _pGroups = (GROUP*)malloc(sizeof(GROUP)); - memset(_pGroups, 0, sizeof(GROUP)); - CreateMesh(_pGroups, &info); - - a = info.next; - while (a) - { - lineinfo_t* b = a->next; - free(a); - a = b; - } - info.next = 0; - -/* - char filename[32], name[260]; - FILE *tf; - matrix m1,m2; - int type, color; - char buf[1024]; - float fm[12]; -*/ - // Included files - f = fopen (strFile, "rt"); - LoadIdentity(&mat); - decodeconnections(f, &mat, 16, fn); - fclose(f); -/* - while (fgets(buf, 1024, f)) - { - while (buf[strlen(buf)-1] == 10 || buf[strlen(buf)-1] == 13 || buf[strlen(buf)-1] == 32) - buf[strlen(buf)-1] = 0; - - type = -1; - sscanf(buf, "%d", &type); - - if (type == 1) - { - sscanf (buf, "%d %d %f %f %f %f %f %f %f %f %f %f %f %f %s", - &type, &color, &fm[0], &fm[1], &fm[2], &fm[3], &fm[4], &fm[5], &fm[6], &fm[7], &fm[8], &fm[9], &fm[10], &fm[11], filename); - - strupr(filename); - LoadIdentity(&mat); - info.next = 0; - - ldg->next = (drawgroup_t*)malloc(sizeof(drawgroup_t)); - ldg = ldg->next; - memset(ldg, 0, sizeof(drawgroup_t)); - - strcpy (name, fn); - strcat (name, "P\\"); - strcat (name, filename); - - tf = fopen (name, "rt"); - - if (!tf) - { - strcpy (name, fn); - strcat (name, "PARTS\\"); - strcat (name, filename); - tf = fopen (name, "rt"); - } - - if (!tf) - { - strcpy (name, fn); - strcat (name, "PARTS\\S\\"); - strcat (name, filename); - tf = fopen (name, "rt"); - } - - if (ptr = strrchr(filename, '.')) *ptr = 0; - strcpy(ldg->name, filename); - - LoadIdentity(&m1); - LoadIdentity(&m2); - ConvertFromLDraw (&m1, fm); - Multiply (&m2, &mat, &m1); -/* - if (strcmp(ldg->name, "STUD") == 0) - { - ldg->pos[0] = m2.m[12]; - ldg->pos[1] = m2.m[13]; - ldg->pos[2] = m2.m[14]; - ldg->up[2] = 1; - m2.TransformPoints(ldg->up, 1); - ldg->up[0] -= m2.m[12]; - ldg->up[1] -= m2.m[13]; - ldg->up[2] -= m2.m[14]; - ldg->type = 1; - } - - if (strcmp(ldg->name, "STUD4") == 0) - { - ldg->pos[0] = m2.m[12]; - ldg->pos[1] = m2.m[13]; - ldg->pos[2] = m2.m[14]; - ldg->up[2] = 1; - m2.TransformPoints(ldg->up, 1); - ldg->up[0] -= m2.m[12]; - ldg->up[1] -= m2.m[13]; - ldg->up[2] -= m2.m[14]; - ldg->type = 0; - } - - decodefile (tf, &m2, (unsigned char)color, &info, fn); - AddDrawInfo (ldg, &info, verts, unique); - fclose(tf); - } - } -*/ -} - -void SaveFile(FILE *bin, FILE *idx, unsigned long *binoff) -{ - unsigned long i; - float box[6] = { -100, -100, -100, 100, 100, 100 }; - float maxdim; - GROUP* pGroup; - CONNECTION* pCon; - matrix mat; - TEXTURE* tex; - short scale; - unsigned short s; - unsigned char bt; - short sb[6]; - - pGroup = _pGroups; - while (pGroup) - { - unsigned char* bytes = (unsigned char*)pGroup->drawinfo; - float* floats; - - while (*bytes) - { - if (*bytes == LC_MESH) - { - if (_nVertsCount > 65535) - { - unsigned long colors, *p; - p = (unsigned long*)(bytes + 1); - colors = *p; - p++; - - while (colors--) - { - p++; // color code - p += *p + 1; - p += *p + 1; - p += *p + 1; - } - - bytes = (unsigned char*)p; - } - else - { - unsigned short colors, *p; - p = (unsigned short*)(bytes + 1); - colors = *p; - p++; - - while (colors--) - { - p++; // color code - p += *p + 1; - p += *p + 1; - p += *p + 1; - } - - bytes = (unsigned char*)p; - } - } - - if ((*bytes == LC_STUD) || (*bytes == LC_STUD2)) - { - float stud[6] = { 0.16f, 0.16f, 0.16f, -0.16f, -0.16f, 0 }; - floats = (float*)(bytes+2); - - LoadIdentity(&mat); - mat.m[0] = floats[0]; - mat.m[1] = floats[1]; - mat.m[2] = floats[2]; - mat.m[4] = floats[3]; - mat.m[5] = floats[4]; - mat.m[6] = floats[5]; - mat.m[8] = floats[6]; - mat.m[9] = floats[7]; - mat.m[10] = floats[8]; - mat.m[12] = floats[9]; - mat.m[13] = floats[10]; - mat.m[14] = floats[11]; - TransformPoints (&mat, stud, 2); - - for (i = 0; i < 2; i++) - { - if (stud[(3*i)] > box[0]) box[0] = stud[(3*i)]; - if (stud[(3*i)+1] > box[1]) box[1] = stud[(3*i)+1]; - if (stud[(3*i)+2] > box[2]) box[2] = stud[(3*i)+2]; - if (stud[(3*i)] < box[3]) box[3] = stud[(3*i)]; - if (stud[(3*i)+1] < box[4]) box[4] = stud[(3*i)+1]; - if (stud[(3*i)+2] < box[5]) box[5] = stud[(3*i)+2]; - } - - bytes += 2*sizeof(unsigned char) + 12*sizeof(float); - } - - if ((*bytes == LC_STUD4) || (*bytes == LC_STUD3)) - bytes += 2*sizeof(unsigned char) + 12*sizeof(float); - } - - pGroup = pGroup->next; - } - - for (i = 0; i < _nVertsCount; i++) - { - if (_fVerts[(3*i)] > box[0]) box[0] = _fVerts[(3*i)]; - if (_fVerts[(3*i)+1] > box[1]) box[1] = _fVerts[(3*i)+1]; - if (_fVerts[(3*i)+2] > box[2]) box[2] = _fVerts[(3*i)+2]; - if (_fVerts[(3*i)] < box[3]) box[3] = _fVerts[(3*i)]; - if (_fVerts[(3*i)+1] < box[4]) box[4] = _fVerts[(3*i)+1]; - if (_fVerts[(3*i)+2] < box[5]) box[5] = _fVerts[(3*i)+2]; - } - - maxdim = 0; - for (i = 0; i < 6; i++) - if (fabs(box[i]) > maxdim) maxdim = (float)fabs(box[i]); - scale = 10000; - if (maxdim > 3.2f) - scale = 1000; - if (maxdim > 32.0f) - scale = 100; - - // write the vertex data - fwrite(&_nVertsCount, sizeof(_nVertsCount), 1, bin); - for (i = 0; i < _nVertsCount; i++) - { - float tmp[3] = { scale*_fVerts[(i*3)], scale*_fVerts[(i*3)+1], scale*_fVerts[(i*3)+2] }; - short sh[3] = { (short)tmp[0], (short)tmp[1], (short)tmp[2] }; - fwrite(&sh, sizeof(sh), 1, bin); - } - - s = 0; - pCon = _pConnections; - while (pCon) - { - s++; - pCon = pCon->next; - } - fwrite(&s, sizeof(s), 1, bin); - - pCon = _pConnections; - while (pCon) - { - float tmp[3] = { scale*pCon->pos[0], scale*pCon->pos[1], scale*pCon->pos[2] }; - short sh[3] = { (short)tmp[0], (short)tmp[1], (short)tmp[2] }; - - fwrite(&pCon->type, sizeof(pCon->type), 1, bin); - fwrite(&sh, sizeof(sh), 1, bin); - - sh[0] = (short)(pCon->up[0]*(1<<14)); - sh[1] = (short)(pCon->up[1]*(1<<14)); - sh[2] = (short)(pCon->up[2]*(1<<14)); - fwrite(&sh, sizeof(sh), 1, bin); - - pCon = pCon->next; - } - - // Textures - bt = 0; - for (tex = _pTextures; tex; tex = tex->next) - bt++; - fwrite(&bt, 1, 1, bin); - - for (tex = _pTextures; tex; tex = tex->next) - { - fwrite(&tex->color, 1, 1, bin); - fwrite(tex->name, 8, 1, bin); - - for (i = 0; i < 12; i++) - { - float tmp[1] = { tex->points[i]*scale }; - short sh[1] = { (short)tmp[0] }; - fwrite(&sh, sizeof(sh), 1, bin); - } - for (i = 12; i < 20; i++) - { - float tmp[1] = { tex->points[i] }; - short sh[1] = { (short)tmp[0] }; - fwrite(&sh, sizeof(sh), 1, bin); - } - } - - s = 0; - pGroup = _pGroups; - while (pGroup) - { - s++; - pGroup = pGroup->next; - } - fwrite(&s, sizeof(s), 1, bin); - - pGroup = _pGroups; - while (pGroup) - { - for (bt = 0; bt < 5; bt++) - if (!pGroup->connections[bt]) - break; - fwrite(&bt, sizeof(bt), 1, bin); - - for (bt = 0; bt < 5; bt++) - { - if (!pGroup->connections[bt]) - break; - - s = 0; - pCon = _pConnections; - while (pCon) - { - if (pCon == pGroup->connections[bt]) - break; - pCon = pCon->next; - s++; - } - fwrite(&s, sizeof(s), 1, bin); - } - - fwrite(pGroup->drawinfo, pGroup->infosize, 1, bin); - - pGroup = pGroup->next; - } - - fwrite(_strName, 8, 1, idx); - fwrite(_strDescription, 64, 1, idx); - for (i = 0; i < 6; i++) - { - float ff, f = 1.0f * box[i]; - f *= scale; - ff = f; -// sb[i] = scale*box[i]; - sb[i] = (short)ff; - } - fwrite(&sb, sizeof(sb), 1, idx); - bt = 0x01; // LC_PIECE_COUNT - if (scale == 10000) bt |= 0x10; // LC_PIECE_SMALL - if (scale == 1000) bt |= 0x20; // LC_PIECE_MEDIUM - fwrite(&bt, sizeof(bt), 1, idx); - i = GetDefaultPieceGroup(_strDescription); - fwrite(&i, sizeof(i), 1, idx); - fwrite(binoff, sizeof(*binoff), 1, idx); - i = ftell(bin) - *binoff; - fwrite(&i, sizeof(i), 1, idx); - *binoff = ftell(bin); -} - -int main(int argc, char *argv[]) -{ - struct _finddata_t c_file; - long hFile; - char tmp[260]; - FILE *bin, *idx; - unsigned long binoff; - unsigned short count, moved; - - if (argc != 2) - { - argv[1] = "f:\\ldraw\\parts\\"; - -// printf("Usage: convert \n"); -// return 1; - } - - _fVerts = 0; - _nVertsCount = 0; - _pGroups = 0; - _pConnections = 0; - _pTextures = 0; - - strcpy(tmp, argv[1]); - strcat(tmp, "*.dat"); - - if((hFile = _findfirst(tmp, &c_file )) == -1L) - printf( "No *.dat files in current directory!\n"); - else - { - char strbin[32] = "LeoCAD piece library data file\0\0"; - char stridx[32] = "LeoCAD piece library index file\0"; - unsigned char bt; - - bin = fopen("PIECES.BIN", "wb"); - idx = fopen("PIECES.IDX", "wb"); - fwrite(strbin, 32, 1, bin); - binoff = 32; - fwrite(stridx, 32, 1, idx); - bt = 3; // version - fwrite(&bt, 1, 1, idx); - bt = 3; // last update - fwrite(&bt, 1, 1, idx); - - strcpy(tmp, argv[1]); - strcat(tmp, c_file.name); - count = 1; - - ReadFile(tmp); - printf("Saving...\n"); - SaveFile(bin, idx, &binoff); - - while(_findnext(hFile, &c_file) == 0) - { - strcpy(tmp, argv[1]); - strcat(tmp, c_file.name); - count++; - - ReadFile(tmp); - printf("Saving...\n"); - SaveFile(bin, idx, &binoff); - } - _findclose(hFile); - - fclose(bin); - - { - char buf[100], f1[9], f2[9], *ptr, *ptr2; - FILE* f; - - moved = 0; - f = fopen("MOVED.TXT", "rt"); - - while (fgets(buf, 100, f) != NULL) - { - if (ptr = strchr(buf, ' ')) - { - *ptr = 0; - memset(f1, 0, 9); - strcpy(f1, buf); - ptr++; - if (ptr2 = strchr(ptr, ' ')) - { - *ptr2 = 0; - memset(f2, 0, 9); - strcpy(f2, ptr); - moved++; - strupr(f1); - strupr(f2); - fwrite(f1, 8, 1, idx); - fwrite(f2, 8, 1, idx); - } - } - } - fclose(f); - } - - fwrite(&moved, sizeof(moved), 1, idx); - fwrite(&binoff, sizeof(binoff), 1, idx); - fwrite(&count, sizeof(count), 1, idx); - fclose(idx); - } - - CleanUp(); - return 0; -} - -/* -void Inline(drawgroup_t* pdg) -{ - unsigned int count[256][3], vert, j, k, v, loc; - int i; - unsigned int colcount; - int curcol; - unsigned int* drawinfo; - drawgroup_t *ldg, *dg; - - if (pdg->info == NULL) - { - ldg = &_DrawGroup; - dg = _DrawGroup.next; - - while (dg) - { - if (dg == pdg) - { - ldg->next = dg->next; - free(pdg); - return; - } - ldg = dg; - dg = dg->next; - } - } - - - vert = 0; - memset (count, 0, sizeof(count)); - - loc = 1; - colcount = _DrawGroup.info[0]; - while (colcount) - { - curcol = _DrawGroup.info[loc]; - loc++; - for (j = 0; j < 3; j++) - { - count[curcol][j] += _DrawGroup.info[loc]; - loc += _DrawGroup.info[loc]+1; - } - colcount--; - } - - loc = 1; - colcount = pdg->info[0]; - while (colcount) - { - int curcol = pdg->info[loc]; - loc++; - for (j = 0; j < 3; j++) - { - count[curcol][j] += pdg->info[loc]; - loc += pdg->info[loc]+1; - } - colcount--; - } - - k = 0; - for (i = 0; i < 256; i++) - { - if (count[i][0] || count[i][1] || count[i][2]) - { - k++; - vert += count[i][0] + count[i][1] + count[i][2]; - } - } - vert += (k*4)+1; - - drawinfo = (unsigned int*)malloc(vert*sizeof(unsigned int)); - drawinfo[0] = k; - vert = 1; - - for (i = 16; i < 256; i++) - { - if (count[i][0] || count[i][1] || count[i][2]) - { - drawinfo[vert] = i; - vert++; - } - - for (j = 0; j < 3; j++) - { - if (count[i][0] || count[i][1] || count[i][2]) - { - drawinfo[vert] = count[i][j]; - vert++; - } - - if (count[i][j] != 0) - { - { - unsigned int* info = _DrawGroup.info; - loc = 1; - colcount = info[0]; - while (colcount) - { - int curcol = info[loc]; - loc++; - - for (v = 0; v < 3; v++) - { - if ((v == j) && (curcol == i)) - { - memcpy(&drawinfo[vert], &info[loc+1], info[loc]*sizeof(unsigned int)); - vert += info[loc]; - } - loc += info[loc]+1; - } - colcount--; - } - } - - { - unsigned int* info = pdg->info; - loc = 1; - colcount = info[0]; - while (colcount) - { - int curcol = info[loc]; - loc++; - - for (v = 0; v < 3; v++) - { - if ((v == j) && (curcol == i)) - { - memcpy(&drawinfo[vert], &info[loc+1], info[loc]*sizeof(unsigned int)); - vert += info[loc]; - } - loc += info[loc]+1; - } - colcount--; - } - } - } - } - if (i == 16) i = -1; - if (i == 15) i = 23; - } - free(_DrawGroup.info); - _DrawGroup.info = drawinfo; - _DrawGroup.infosize = vert; - - ldg = &_DrawGroup; - dg = _DrawGroup.next; - - while (dg) - { - if (dg == pdg) - { - ldg->next = dg->next; - free(pdg->info); - free(pdg); - break; - } - ldg = dg; - dg = dg->next; - } -} - -void decode (char* strFile, float** ppVerts, unsigned int* nCount, char* strDescription) -{ - char tmp[100]; - matrix mat; - lineinfo_t info; - FILE *f; - char *ptr; - char fn[260]; - lineinfo_t *a; - unsigned int i, j, unique; - float* verts; - drawgroup_t* ldg; - char buf[1024]; - int type, color; - char filename[32], name[260]; - float fm[12]; - FILE *tf; - matrix m1,m2; - - LoadIdentity(&mat); - info.next = 0; - info.type = 0; - - f = fopen (strFile, "rt"); - if (fgets (tmp, 100, f)) - { - while (tmp[strlen(tmp)-1]==10||tmp[strlen(tmp)-1]==13||tmp[strlen(tmp)-1]==32) - tmp[strlen(tmp)-1]=0; - tmp[66] = 0; - strcpy (strDescription, tmp+2); - } - - printf("Decoding %s : %s\n", _strName, _strDescription); - - strcpy (fn, strFile); - if (ptr = strrchr(fn, '.')) *ptr = 0; - memset (tmp, 0, sizeof(char[100])); - ptr = strrchr(fn, '\\'); - if (ptr == 0) - ptr = fn; - else - ptr++; - strcpy (tmp, ptr); - strupr (tmp); - - strcpy (fn, strFile); - ptr = strrchr(fn, '\\'); - *ptr = 0; - ptr = strrchr(fn, '\\'); - *(ptr+1) = 0; - - decodefile (f, &mat, 16, &info, fn); - fclose (f); - - unique = 0; - verts = (float*)malloc(sizeof(float)*1500); - - // Create array of unique vertices - for (a = info.next; a; a = a->next) - { - for (j = 0; j < a->type; j++) - { - for (i = unique-1; i != -1; i--) - if (FloatPointsClose(&verts[i*3], &a->points[j*3])) - break; - - if (i == -1) - { - if ((unique % 500) == 0) - verts = (float*)realloc(verts, sizeof(float)*3*(unique+500)); - memcpy(&verts[unique*3], &a->points[j*3], sizeof(float)*3); - unique++; - } - } - } - - a = info.next; - while (a) - { - lineinfo_t* b = a->next; - free(a); - a = b; - } - info.next = 0; - - *ppVerts = verts; - *nCount = unique; - - printf ("%d vertexes\n", unique); - - // Main group - f = fopen (strFile, "rt"); - LoadIdentity(&mat); - decodefile (f, &mat, 16, &info, fn); - fclose(f); - AddDrawInfo (&_DrawGroup, &info, verts, unique); - Inline(&_DrawGroup); - ldg = &_DrawGroup; - - // Included files - f = fopen (strFile, "rt"); - while (fgets(buf, 1024, f)) - { - while (buf[strlen(buf)-1] == 10 || buf[strlen(buf)-1] == 13 || buf[strlen(buf)-1] == 32) - buf[strlen(buf)-1] = 0; - - type = -1; - sscanf(buf, "%d", &type); - - if (type == 1) - { - sscanf (buf, "%d %d %f %f %f %f %f %f %f %f %f %f %f %f %s", - &type, &color, &fm[0], &fm[1], &fm[2], &fm[3], &fm[4], &fm[5], &fm[6], &fm[7], &fm[8], &fm[9], &fm[10], &fm[11], filename); - - strupr(filename); - LoadIdentity(&mat); - info.next = 0; - - ldg->next = (drawgroup_t*)malloc(sizeof(drawgroup_t)); - ldg = ldg->next; - memset(ldg, 0, sizeof(drawgroup_t)); - - strcpy (name, fn); - strcat (name, "P\\"); - strcat (name, filename); - - tf = fopen (name, "rt"); - - if (!tf) - { - strcpy (name, fn); - strcat (name, "PARTS\\"); - strcat (name, filename); - tf = fopen (name, "rt"); - } - - if (!tf) - { - strcpy (name, fn); - strcat (name, "PARTS\\S\\"); - strcat (name, filename); - tf = fopen (name, "rt"); - } - - if (ptr = strrchr(filename, '.')) *ptr = 0; - strcpy(ldg->name, filename); - - LoadIdentity(&m1); - LoadIdentity(&m2); - ConvertFromLDraw (&m1, fm); - Multiply (&m2, &mat, &m1); -#if 0 - if (strcmp(ldg->name, "STUD") == 0) - { - ldg->pos[0] = m2.m[12]; - ldg->pos[1] = m2.m[13]; - ldg->pos[2] = m2.m[14]; - ldg->up[2] = 1; - m2.TransformPoints(ldg->up, 1); - ldg->up[0] -= m2.m[12]; - ldg->up[1] -= m2.m[13]; - ldg->up[2] -= m2.m[14]; - ldg->type = 1; - } - - if (strcmp(ldg->name, "STUD4") == 0) - { - ldg->pos[0] = m2.m[12]; - ldg->pos[1] = m2.m[13]; - ldg->pos[2] = m2.m[14]; - ldg->up[2] = 1; - m2.TransformPoints(ldg->up, 1); - ldg->up[0] -= m2.m[12]; - ldg->up[1] -= m2.m[13]; - ldg->up[2] -= m2.m[14]; - ldg->type = 0; - } -#endif - decodefile (tf, &m2, (unsigned char)color, &info, fn); - AddDrawInfo (ldg, &info, verts, unique); - fclose(tf); - } - } - fclose(f); -} - -void OpenFile(char* strFile) -{ - char tmp[260], *ptr; - CleanUp(); - -// if (stricmp() strFile.Right(4).CompareNoCase(_T(".DAT")) == 0) - { - memset(_strName, 0, sizeof(_strName)); - memset(_strDescription, 0, sizeof(_strDescription)); - - strcpy(tmp, strFile); - if (ptr = strrchr(tmp, '.')) *ptr = 0; - ptr = strrchr(tmp, '\\'); - if (ptr == NULL) - ptr = tmp; - else - ptr++; - strcpy (_strName, ptr); - strupr (_strName); - - decode (strFile, &_fVerts, &_nVertsCount, _strDescription); - } -} -*/ - diff --git a/tools/convert/convert.h b/tools/convert/convert.h deleted file mode 100644 index 370df214..00000000 --- a/tools/convert/convert.h +++ /dev/null @@ -1,221 +0,0 @@ -// Hide math stuff here. -// - -static float Identity[16] = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; - -// Perform a 4x4 matrix multiplication (product = a x b). -// WARNING: (product != b) assumed -static __inline void matmul(float *product, const float *a, const float *b) -{ - int i; - -// #define M(row,col) m[col*4+row] -#define A(row,col) a[(col<<2)+row] -#define B(row,col) b[(col<<2)+row] -#define P(row,col) product[(col<<2)+row] - - for (i = 0; i < 4; i++) - { - float ai0=A(i,0), ai1=A(i,1), ai2=A(i,2), ai3=A(i,3); - P(i,0) = ai0 * B(0,0) + ai1 * B(1,0) + ai2 * B(2,0) + ai3 * B(3,0); - P(i,1) = ai0 * B(0,1) + ai1 * B(1,1) + ai2 * B(2,1) + ai3 * B(3,1); - P(i,2) = ai0 * B(0,2) + ai1 * B(1,2) + ai2 * B(2,2) + ai3 * B(3,2); - P(i,3) = ai0 * B(0,3) + ai1 * B(1,3) + ai2 * B(2,3) + ai3 * B(3,3); - } - -#undef A -#undef B -#undef P -} - -typedef struct -{ - float m[16]; -} matrix; - -static __inline void ConvertFromLDraw(matrix* m, float f[12]) -{ - float trans[16] = { 1,0,0,0, 0,0,-1,0, 0,1,0,0, 0,0,0,1 }; - float t[16] = { 1,0,0,0, 0,0,1,0, 0,-1,0,0, 0,0,0,1 }; - m->m[0] = f[3]; m->m[1] = f[6]; m->m[2] = f[9]; - m->m[4] = f[4]; m->m[5] = f[7]; m->m[6] = f[10]; - m->m[8] = f[5]; m->m[9] = f[8]; m->m[10]= f[11]; - m->m[12]= f[0]/25; m->m[13]= f[1]/25; m->m[14]= f[2]/25; - matmul (m->m, m->m, t); - matmul (trans, trans, m->m); - memcpy (&m[0], &trans[0], sizeof(m->m)); -} - -static __inline void LoadIdentity(matrix* m) -{ - memcpy (&m->m[0], &Identity, sizeof(float[16])); -} - -static __inline void Multiply(matrix* m, matrix* m1, matrix* m2) -{ - matmul (m->m, m1->m, m2->m); -} - -static __inline void TransformPoint(matrix* m, float out[], const float in[3]) -{ - out[0] = m->m[0]*in[0] + m->m[4]*in[1] + m->m[8]*in[2] + m->m[12]; - out[1] = m->m[1]*in[0] + m->m[5]*in[1] + m->m[9]*in[2] + m->m[13]; - out[2] = m->m[2]*in[0] + m->m[6]*in[1] + m->m[10]*in[2] + m->m[14]; -} - -static __inline void TranslatePoint(matrix* m, float* in, float* t) -{ - in[0] = m->m[0]*t[0] + m->m[4]*t[1] + m->m[8]*t[2] + m->m[12]; - in[1] = m->m[1]*t[0] + m->m[5]*t[1] + m->m[9]*t[2] + m->m[13]; - in[2] = m->m[2]*t[0] + m->m[6]*t[1] + m->m[10]*t[2] + m->m[14]; -} - -static __inline void TransformPoints (matrix* m, float p[], int n) -{ - int i; - float tmp[3]; - - for (i = 0; i < n*3; i += 3) - { - tmp[0] = p[i]; - tmp[1] = p[i+1]; - tmp[2] = p[i+2]; - TransformPoint (m, &p[i], tmp); - } -} - -static __inline void ConvertPoints (float pts[], int count) -{ - float tmp; - int i; - - for (i = 0; i < count; i++) - { - pts[3*i] /= 25; - tmp = pts[3*i+1]; - pts[3*i+1] = pts[3*i+2]/25; - pts[3*i+2] = -tmp/25; - } -} - -static __inline void Resequence(float v[4][3], int a, int b, int c, int d) -{ - float o[4][3]; - memcpy(o, v, sizeof(o)); - memcpy(v[0], o[a], sizeof(o[0])); - memcpy(v[1], o[b], sizeof(o[0])); - memcpy(v[2], o[c], sizeof(o[0])); - memcpy(v[3], o[d], sizeof(o[0])); -} - -static __inline void Sub3(float v[], float q1[], float q2[]) -{ - v[0] = q1[0]-q2[0]; - v[1] = q1[1]-q2[1]; - v[2] = q1[2]-q2[2]; -} - -static __inline float Dot3(float q1[], float q2[]) -{ - return q1[0]*q2[0]+q1[1]*q2[1]+q1[2]*q2[2]; -} - -static __inline void Cross3(float v[], float q1[], float q2[]) -{ - v[0] = (q1[1]*q2[2]) - (q1[2]*q2[1]); - v[1] = (q1[2]*q2[0]) - (q1[0]*q2[2]); - v[2] = (q1[0]*q2[1]) - (q1[1]*q2[0]); -} - -static __inline void TestQuads(float quad[4][3]) -{ - float v01[3], v02[3], v03[3]; - float v12[3], v13[3], v23[3]; - float cp1[3], cp2[3]; - float dotA, dotB, dotC; - int A, B, C; - - // Calculate A - Sub3(v01, quad[1], quad[0]); - Sub3(v02, quad[2], quad[0]); - Sub3(v03, quad[3], quad[0]); - Cross3(cp1, v01, v02); - Cross3(cp2, v02, v03); - dotA = Dot3(cp1, cp2); - A = (dotA > 0.0f); - - if (A) - { - // 3 is in I, typical case, OK: 0123 D02 (convex/concave) - // CONVEXINFO: quad is convex if (!B && !C): OK: 0123 D02/13 (convex) - } - else - { - // Calculate B and C (may be postponed/discarded) - // NOTE: postponed ! - Sub3(v12, quad[2], quad[1]); - Sub3(v13, quad[3], quad[1]); - Sub3(v23, quad[3], quad[2]); - Cross3(cp1, v12, v01); - Cross3(cp2, v01, v13); - dotB = Dot3(cp1, cp2); - B = (dotB > 0.0f); - Cross3(cp1, v02, v12); - Cross3(cp2, v12, v23); - dotC = -Dot3(cp1, cp2); - C = (dotC > 0.0f); - - // 3 is in II, III, IV or V. Calculation of B and C could be postponed - // to here if CONVEXINFO (above) is not needed - if (B) - { - // 3 is in II or III - if (C) - { - // 3 is in II, OK: 0123 D13 (concave) - Resequence(quad, 1, 2, 3, 0); // just to shift diagonal - } - else - { - // 3 is in III, bow-tie error: using 0312 D01/D23 (convex) - Resequence(quad, 0, 3, 1, 2); - } - } - else - { - // 3 is in IV or V - if (C) - { - // 3 is in IV, bow-tie error: using 0132 D12/D03 (convex) - Resequence(quad, 0, 1, 3, 2); - } - else - { - // 3 is in V, OK: 0123 D13 (concave) - Resequence(quad, 1, 2, 3, 0); // just to shift diagonal - } - } - } - // The four vertices quad[0], quad[1], quad[2] and quad[3] now have - // the correct sequence, the polygon can be divided by the diagonal 02 - // into two triangles, 012 and 230. -} - -static __inline void FixQuads(float quad[]) -{ - float t[4][3]; - memcpy(t, quad, sizeof(t)); - TestQuads(t); - memcpy(quad, t, sizeof(t)); -} - -static __inline int FloatPointsClose (float pt1[], float pt2[]) -{ - if (fabs(pt1[0] - pt2[0]) > 0.01) - return 0; - if (fabs(pt1[1] - pt2[1]) > 0.01) - return 0; - if (fabs(pt1[2] - pt2[2]) > 0.01) - return 0; - return 1; -} diff --git a/tools/convert/library.txt b/tools/convert/library.txt deleted file mode 100755 index 680ea2c5..00000000 --- a/tools/convert/library.txt +++ /dev/null @@ -1,101 +0,0 @@ - -PIECES.IDX -char[32] "LeoCAD piece library index file" -unsigned char file version (currently = 3) -unsigned char last updated installed - -PIECE_DATA: -char[8] name -char[64] description -short[6] bounding box (scaled) -unsigned char flags -unsigned long default group -unsigned long offset in PIECES.BIN -unsigned long info size - -MOVED_DATA: -char[8] old name -char[8] new name - -unsigned short moved count -unsigned long PIECES.BIN File size -unsigned short piece count - ------------------------------------------------------------ - -PIECES.BIN -char[32] "LeoCAD piece library data file" - -PIECE_DATA: -unsigned long vertex count -short[] vertex data (scaled) -unsigned short connection count -CONNECTION_DATA: - unsigned short connection type - short[3] position (scaled) - short[3] up (<<14) - -unsigned short group count -GROUP_DATA: - unsigned char group connection count - unsigned short connections index - void draw information - ------------------------------------------------------------ - -TEXTURES.IDX -char[32] "LeoCAD texture index file" -unsigned char file version (currently = 1) -unsigned char last updated installed - -TEXTURE_DATA: -char[8] name -unsigned short width -unsigned short height -unsigned char type (LUMINANCE, RGB, RGBA) -unsigned long offset in TEXTURES.BIN - -unsigned long TEXTURES.BIN File size -unsigned short piece count - ------------------------------------------------------------ - -TEXTURES.BIN - -char[32] "LeoCAD texture data file" - ------------------------------------------------------------ - -UPDATExx.LUP - -char[32] "LeoCAD piece library update" -unsigned char file version (currently = 2) -unsigned char updated number - -char[8] piece name -unsigned char update type (del = 0, desc = 1, draw = 2, new = 4) - -desc: -char[64] description -unsigned long default group - -drawinfo: -short[6] bounding box (scaled) -unsigned char flags -unsigned long info size -void* data - -new: -char[64] description -short[6] bounding box (scaled) -unsigned long default group -unsigned char flags -unsigned long info size -void* data - -MOVED_DATA: -char[8] old name -char[8] new name - -unsigned short moved count -unsigned short changes count diff --git a/tools/convert/moved.txt b/tools/convert/moved.txt deleted file mode 100644 index d43133a3..00000000 --- a/tools/convert/moved.txt +++ /dev/null @@ -1,365 +0,0 @@ -4 3193 -5 3192 -6 3464 -9 3460 -11 3579 -12 7930 -13 7026 -16 3596 -18 3626A -19 3624 -22 3581 -25 3582 -26 3497 -28 3062B -34 7049 -40 3046 -47 3659 -48 3049 -56 3660 -57 3045 -62 3145 -64 3359 -65 3358 -89 9244 -93 3479 -94 3865 -95 2748 -96 3831 -97 3830 -98 3685 -99 3684 -100 3665 -101 3623 -102 3644 -103 73037 -114 3848 -116 3847 -117 3846 -117P47 3846P47 -118 3849 -121 3787 -122 122C01 -123 3641 -132 3483 -134 3794 -138 3855 -140 3821 -141 3822 -142 3741 -143 3742 -144 3854 -145 3856 -146 2529 -148 3957 -149 3962 -150 3899 -157 4070 -158 3189 -159 3188 -163 3315 -175 4178 -176 4023 -177 73092 -178 4175 -179 4073 -180 4161 -195 4170 -196 4171 -197 73090 -198 4176 -199 3675 -205 32073 -206 73071 -211 6100 -212 4229 -216 3612 -217 4228 -231 4349 -234 4286 -236 73312 -238 3048 -239 4528 -240 4287 -241 4529 -246 73435 -247 73436 -247B 73435 -248 3676 -252 4599 -256 3058 -257 4476 -258 4169 -259 4168 -262 3811 -262P01 3811P01 -274 4590 -275 4460 -278 4490 -249 4495 -291 4868 -292 4869 -293 3867 -294 4447 -295 4448 -296 4740 -297 4593 -299 4589 -302 4872 -305 2335 -306 2343 -307 4735 -321 2412 -324 2458 -338 2433 -339 4474 -340 2583 -352 4095 -368 2569 -369 3187 -370 3186 -371 2920 -372 2337 -373 6019 -376 4733 -380 6016 -381 6048 -386 6020 -387 6060 -388 6070 -391 6558 -395 3587 -396 4595 -401 2516 -404 6541 -407 71076 -408 71075 -415 6217 -418 6037 -426 6043 -427 6046 -428 75535 -432 6126 -461 3688 -497 7039 -513 3144 -583 30031 -588 71137 -602 32000 -605 6152 -708 3062A -720 3218 -808 2348A -810 6238 -829 3433 -860 6120 -960 2620 -961 4284 -965 4089 -2348 2348B -2358P01 80547 -2418 2418B -2455 3755 -2561 2566 -2562 2536 -2748 3857 -2837A 2838C01 -2872 2921 -3062 3062B -3137A 3137 -3137B 20 -3149A 313 -3149B 314 -3149C 3149 -3324A 3324 -3465 3480 -3463 3481 -3626 3626B -3626-4T 3626B-4T -3626P01 3626BP01 -3626P02 3626BP02 -3709 3709B -3944 3961 -3945 3839B -3946 3963 -3949 3838 -3950 3959 -3951 3939 -3951P68 3939P68 -4203 4201 -4601 4624 -6237 601 -73590 73590B -9326 973 -9326-4T 973S01 -9326P01 973P01 -9326P02 973P02 -9326P11 973P11 -9326P14 973P14 -9326P15 973P15 -9326P16 973P16 -9326P17 973P17 -9326P18 973P18 -9326P47 973P47 -9326P51 973P51 -9326P52 973P52 -9326P60 973P60 -9326P61 973P61 -9326P63 973P63 -9326P68 973P68 -9326T01 973P01 -9326T02 973P02 -4265 4265B -571 6629 -973P101 973PS1 -3839 3839B -4081 4081B -151 32316 -3002PEYE 3003PE1 -4085 4085C -3068P101 3068PS1 -3228 3228A -2412 2412A -2431P52 2431BP52 -2431P79 2431BP79 -3069P05 3069BP05 -3069P06 3069BP06 -3069P07 3069BP07 -3069P09 3069BP09 -3069P101 3069PS1 -3069P21 3069BP21 -3069P68 3069BP68 -3070DISP 3070BPC2 -3070P06 3070BP06 -6069P101 6069PS1 -788 4323 -3068P07 3068BP07 -3068P08 3068BP08 -3068P18 3068BP18 -3068P80 3068BP80 -3069P25 3069BP25 -3039P101 3039PS1 -124 3876 -133 3217 -3068P22 3068BP22 -3068P23 3068BP23 -3068P50 3068BP50 -3068P52 3068BP52 -3068P66 3068BP66 -3068P67 3068BP67 -3068P81 3068BP81 -3068P87 3068BP87 -3068PS1 3068BPS1 -3069P13 3069BP13 -4215 4215B -4215P01 4215AP01 -4215P02 4215AP02 -4215P03 4215AP03 -4215P24 4215AP24 -4215P66 4215AP66 -4215P05 4215AP05 -4215P06 4215AP06 -4215P07 4215AP07 -4215P77 4215AP25 -4215P04 4215AP04 -2431B 2431 -2431BP52 2431P52 -2431BP79 2431P79 -174 4081B -3069P01 3069BP01 -3070 3070A -3846P43 3846P45 -973P15 973P1D -161 4085C -3068 3068A -3069 3069A -3962 3962B -578 30374 -6538 6538A -973P11 973P1A -30389 30389A -3942 3942B -4285 4285B -193 193A -3005-1 3005PT1 -3005-1B 3005PV1 -3005-2 3005PT2 -3005-3 3005PT3 -3005-4 3005PT4 -3005-6B 3005PV6 -3005-7 3005PT7 -3005-E 3005PTE -3005-F 3005PTF -3005-H 3005PTH -3005-I 3005PTI -3005-J 3005PTJ -3005-L 3005PTL -3005-M 3005PTM -3005-N 3005PTN -3005-O 3005PTO -3005-Q 3005PTQ -3005-R 3005PTR -3005-T 3005PTT -3005-U 3005PTU -3005-V 3005PTV -3005-W 3005PTW -3005-Y 3005PTY -3005-Z 3005PTZ -3068BP50 3068BP05 -3068P10 3068BP10 -3068P17 3068AP17 -3068P51 3068BP51 -3068P57 3068BP57 -3068P68 3068BP68 -3068PLC 3068BP16 -3068WARN 3068BP06 -4150P07 4150C07 -4345 4345B -4688 4866 -2362 2362B -2362P53 2362AP53 -2362P54 2362AP54 -3005-0 3005PT0 -3005-5 3005PT5 -3005-A 3005PTA -3005-AE 3005PUA -3005-B 3005PTB -3005-C 3005PTC -3005-D 3005PTD -3005-G 3005PTG -3005-K 3005PTK -3005-P 3005PTP -3005-S 3005PTS -3005-X 3005PTX -4864 4864B -4864P33 4864BP10 -4864P34 4864BP11 -4864P66 4864AP02 -4864P89 4864AP03 -3040 3040B -3475 3475B -550 3245B -2476 2476A -298 4592 -298C01 4592C01 -300 44294 -30359 30359A -4738 4738A -480 30554 -4864P35 4864AP01 -530 41334 -552 32209 -554 42446 -6238 6238A -770 2586 -770P4B 2586P4B -770P4C 2586P4C -770P4D 2586P4D -770PH1 2586PH1 -770PS1 2586PS1 -770PW1 2586PW1 -6141 4073 -44237 2456 -30499 3684 -30039 3070B -30002 2343 \ No newline at end of file diff --git a/tools/convert/texture.cpp b/tools/convert/texture.cpp deleted file mode 100644 index bc91dddf..00000000 --- a/tools/convert/texture.cpp +++ /dev/null @@ -1,120 +0,0 @@ -#include -#include -#include -#include -#include "texture.h" - -void ConvertFile(char* szFilename, FILE* idx, FILE* bin, unsigned long* binoff) -{ - long i, j; - unsigned short width, height; - unsigned char* buf = ReadBMP(szFilename, &width, &height); - unsigned char bt; - unsigned short sh; - char* p; - p = strrchr(szFilename, '.'); - *p = 0; - p = strrchr(szFilename, '\\'); - strupr(p); - p++; - - char name[9]; - memset(name, 0, 9); - strcpy(name, p); - - fwrite(name, 8, 1, idx); - sh = (unsigned short)width; - fwrite(&sh, sizeof(sh), 1, idx); - sh = (unsigned short)height; - fwrite(&sh, sizeof(sh), 1, idx); - - if (strcmp("SYSFONT", name) == 0) - { - bt = 0; // luminance - fwrite(&bt, 1, 1, idx); - - // Store top->bottom only this one - for (i = 0; i < height; i++) - { - unsigned char* b = buf+(height-i-1)*width*3; - - for (j = 0; j < width; j++) - { - if (b[j*3] > 0 || b[j*3+1] > 0 || b[j*3+2] > 0) - bt = 0; - else - bt = 255; - fwrite(&bt, 1, 1, bin); - } - } - - fwrite(binoff, sizeof(*binoff), 1, idx); - *binoff += width*height; - } - - if (strcmp("SPACE", name) == 0) - { - bt = 2; // RGBA - fwrite(&bt, 1, 1, idx); - for (i = 0; i < width*height; i++) - { - if (buf[i*3] == 255 && buf[i*3+1] == 0 && buf[i*3+2] == 255) - { - buf[i*3] = buf[i*3+1] = buf[i*3+2] = 255; - bt = 0; - } - else - bt = 255; - - fwrite(&buf[i*3], 3, 1, bin); - fwrite(&bt, 1, 1, bin); - } - - fwrite(binoff, sizeof(*binoff), 1, idx); - *binoff += width*height*4; - } - - free (buf); -} - -static char* filepath = "f:\\ldraw\\textures\\"; -static char* filenames[] = { "SYSFONT", "SPACE" }; -static int filecount = 2; - -int main(int argc, char *argv[]) -{ - char tmp[260]; - FILE *bin, *idx; - unsigned long binoff; - unsigned short count = 0; - - char strbin[32] = "LeoCAD texture data file\0\0\0\0\0\0\0"; - char stridx[32] = "LeoCAD texture index file\0\0\0\0\0\0"; - unsigned char bt; - - bin = fopen("TEXTURES.BIN", "wb"); - idx = fopen("TEXTURES.IDX", "wb"); - fwrite(strbin, 32, 1, bin); - binoff = 32; - fwrite(stridx, 32, 1, idx); - bt = 1; // version - fwrite(&bt, 1, 1, idx); - bt = 3; // last update - fwrite(&bt, 1, 1, idx); - - for (int i = 0; i < filecount; i++) - { - strcpy(tmp, filepath); - strcat(tmp, filenames[i]); - strcat(tmp, ".bmp"); - count++; - ConvertFile(tmp, idx, bin, &binoff); - } - - fclose(bin); - fwrite(&binoff, sizeof(binoff), 1, idx); - fwrite(&count, sizeof(count), 1, idx); - fclose(idx); - - return 0; -} \ No newline at end of file diff --git a/tools/convert/texture.h b/tools/convert/texture.h deleted file mode 100644 index a02af441..00000000 --- a/tools/convert/texture.h +++ /dev/null @@ -1,678 +0,0 @@ - -static unsigned char* ReadBMP (char* filename, unsigned short *width, unsigned short *height) -{ - int bmWidth; - int bmHeight; - unsigned char bmPlanes; - unsigned char bmBitsPixel; - typedef struct { - unsigned char rgbBlue; - unsigned char rgbGreen; - unsigned char rgbRed; - unsigned char rgbReserved; - } RGBQUAD; - unsigned char m1,m2; - unsigned long sizeimage; - short res1,res2; - long filesize, pixoff; - long bmisize, compression; - long xscale, yscale; - long colors, impcol; - unsigned long m_bytesRead = 0; - unsigned char* outbuf; - FILE *fp; - - fp = fopen(filename,"rb"); - if (fp == NULL) - return NULL; - else - { - long rc; - rc = fread(&m1, 1, 1, fp); - m_bytesRead++; - if (rc == -1) - { - fclose(fp); - return NULL; - } - - rc = fread(&m2, 1, 1, fp); - m_bytesRead++; - if ((m1!='B') || (m2!='M')) - { - fclose(fp); - return NULL; - } - - rc = fread((long*)&(filesize),4,1,fp); m_bytesRead+=4; - if (rc != 1) { fclose(fp); return NULL; } - - rc = fread((int*)&(res1),2,1,fp); m_bytesRead+=2; - if (rc != 1) { fclose(fp); return NULL; } - - rc = fread((int*)&(res2),2,1,fp); m_bytesRead+=2; - if (rc != 1) { fclose(fp); return NULL; } - - rc = fread((long*)&(pixoff),4,1,fp); m_bytesRead+=4; - if (rc != 1) { fclose(fp); return NULL; } - - rc = fread((long*)&(bmisize),4,1,fp); m_bytesRead+=4; - if (rc != 1) { fclose(fp); return NULL; } - - rc = fread((long *)&(bmWidth),4,1,fp); m_bytesRead+=4; - if (rc != 1) { fclose(fp); return NULL; } - - rc = fread((long*)&(bmHeight),4,1,fp); m_bytesRead+=4; - if (rc != 1) { fclose(fp); return NULL; } - - rc = fread((int*)&(bmPlanes),2,1,fp); m_bytesRead+=2; - if (rc != 1) { fclose(fp); return NULL; } - - rc = fread((int*)&(bmBitsPixel),2,1,fp); m_bytesRead+=2; - if (rc != 1) { fclose(fp); return NULL; } - - rc = fread((long*)&(compression),4,1,fp); m_bytesRead+=4; - if (rc != 1) { fclose(fp); return NULL; } - - rc = fread((long*)&(sizeimage),4,1,fp); m_bytesRead+=4; - if (rc != 1) {fclose(fp); return NULL; } - - rc = fread((long*)&(xscale),4,1,fp); m_bytesRead+=4; - if (rc != 1) { fclose(fp); return NULL; } - - rc = fread((long*)&(yscale),4,1,fp); m_bytesRead+=4; - if (rc != 1) { fclose(fp); return NULL; } - - rc = fread((long*)&(colors),4,1,fp); m_bytesRead+=4; - if (rc != 1) { fclose(fp); return NULL; } - - rc = fread((long*)&(impcol),4,1,fp); m_bytesRead+=4; - if (rc != 1) { fclose(fp); return NULL; } - - // I don't do RLE files - if (compression != 0) // BI_RGB - { - fclose(fp); - return NULL; - } - - if (colors == 0) - colors = 1 << bmBitsPixel; - - RGBQUAD *colormap = NULL; - - switch (bmBitsPixel) - { - case 24: - break; - // read pallete - case 1: - case 4: - case 8: - colormap = new RGBQUAD[colors]; - if (colormap == NULL) - { - fclose(fp); - return NULL; - } - - int i; - for (i = 0; i < colors; i++) - { - unsigned char r ,g, b, dummy; - - rc = fread(&b, 1, 1, fp); - m_bytesRead++; - if (rc!=1) - { - delete [] colormap; - fclose(fp); - return NULL; - } - - rc = fread(&g, 1, 1, fp); - m_bytesRead++; - if (rc!=1) - { - delete [] colormap; - fclose(fp); - return NULL; - } - - rc = fread(&r, 1, 1, fp); - m_bytesRead++; - if (rc != 1) - { - delete [] colormap; - fclose(fp); - return NULL; - } - - - rc = fread(&dummy, 1, 1, fp); - m_bytesRead++; - if (rc != 1) - { - delete [] colormap; - fclose(fp); - return NULL; - } - - colormap[i].rgbRed=r; - colormap[i].rgbGreen=g; - colormap[i].rgbBlue=b; - } - break; - } - - if ((long)m_bytesRead > pixoff) - { - delete [] colormap; - fclose(fp); - return NULL; - } - - while ((long)m_bytesRead < pixoff) - { - char dummy; - fread(&dummy,1,1,fp); - m_bytesRead++; - } - - int w = bmWidth; - int h = bmHeight; - - // set the output params - outbuf = (unsigned char*)malloc(w*h*3); - long row_size = w * 3; - long bufsize = (long)w * 3 * (long)h; - - if (outbuf != NULL) - { - *width = w; - *height = h; - long row = 0; - long rowOffset = 0; - - // read rows in reverse order - for (row = 0; row < bmHeight; row++) - { - // which row are we working on? - rowOffset = (long unsigned)row*row_size; - - if (bmBitsPixel == 24) - { - for (int col=0;col> bit_count) & mask; - - // lookup the color from the colormap - stuff it in our buffer - // swap red and blue - *(outbuf + rowOffset + col * 3 + 2) = colormap[pix].rgbBlue; - *(outbuf + rowOffset + col * 3 + 1) = colormap[pix].rgbGreen; - *(outbuf + rowOffset + col * 3 + 0) = colormap[pix].rgbRed; - } - - // read DWORD padding - while ((m_bytesRead-pixoff)&3) - { - char dummy; - if (fread(&dummy,1,1,fp)!=1) - { - free(outbuf); - if (colormap) - delete [] colormap; - fclose(fp); - return NULL; - } - m_bytesRead++; - } - } - } - } - - if (colormap) - delete [] colormap; - - fclose(fp); - } - -// VerticalFlip(image); - return outbuf; -} - - - - - -/* -#define WIDTHBYTES(bits) (((bits) + 31) / 32 * 4) - -static BOOL VertFlipBuf(BYTE* inbuf, UINT widthBytes, UINT height) -{ - BYTE *tb1, *tb2; - ULONG off1 = 0, off2 = 0; - - if (inbuf == NULL) - return FALSE; - - tb1 = (BYTE*)malloc(widthBytes); - if (tb1 == NULL) - return FALSE; - - tb2 = (BYTE*)malloc(widthBytes); - if (tb2 == NULL) - { - free(tb1); - return FALSE; - } - - for (UINT row_cnt = 0; row_cnt < (height+1)/2; row_cnt++) - { - off1 = row_cnt*widthBytes; - off2 = ((height-1)-row_cnt)*widthBytes; - - memcpy(tb1, inbuf+off1, widthBytes); - memcpy(tb2, inbuf+off2, widthBytes); - memcpy(inbuf+off1, tb2, widthBytes); - memcpy(inbuf+off2, tb1, widthBytes); - } - - free (tb1); - free (tb2); - - return TRUE; -} - -static BYTE* MakeDwordAlignedBuf(BYTE *dataBuf, UINT widthPix, UINT height, UINT *uiOutWidthBytes) -{ - if (dataBuf == NULL) - return NULL; - - UINT uiWidthBytes = WIDTHBYTES(widthPix * 24); - DWORD dwNewsize = (DWORD)((DWORD)uiWidthBytes * (DWORD)height); - BYTE *pNew; - - pNew = (BYTE*)new BYTE[dwNewsize]; - if (pNew == NULL) - return NULL; - - // copy row-by-row - UINT uiInWidthBytes = widthPix * 3; - UINT uiCount; - for (uiCount=0;uiCount < height;uiCount++) - { - BYTE* bpInAdd; - BYTE* bpOutAdd; - ULONG lInOff; - ULONG lOutOff; - - lInOff = uiInWidthBytes * uiCount; - lOutOff = uiWidthBytes * uiCount; - - bpInAdd = dataBuf + lInOff; - bpOutAdd = pNew + lOutOff; - - memcpy(bpOutAdd,bpInAdd,uiInWidthBytes); - } - - *uiOutWidthBytes = uiWidthBytes; - return pNew; -} - -static BOOL BGRFromRGB(BYTE *buf, UINT widthPix, UINT height) -{ - if (buf == NULL) - return FALSE; - - UINT col, row; - for (row=0;rowpixoff) { - delete [] colormap; - fclose(fp); - return NULL; - } - - while ((long)m_bytesRead=0;row--) { - - // which row are we working on? - rowOffset=(long unsigned)row*row_size; - - if (inBM.bmBitsPixel==24) { - - for (int col=0;col> bit_count) & mask; - - // lookup the color from the colormap - stuff it in our buffer - // swap red and blue - *(outBuf + rowOffset + col * 3 + 2) = colormap[pix].rgbBlue; - *(outBuf + rowOffset + col * 3 + 1) = colormap[pix].rgbGreen; - *(outBuf + rowOffset + col * 3 + 0) = colormap[pix].rgbRed; - } - - // read DWORD padding - while ((m_bytesRead-pixoff)&3) { - char dummy; - if (fread(&dummy,1,1,fp)!=1) { - delete [] outBuf; - if (colormap) - delete [] colormap; - fclose(fp); - return NULL; - } - m_bytesRead++; - } - } - } - - } - - if (colormap) { - delete [] colormap; - } - - fclose(fp); - - } - - return outBuf; -} -*/ \ No newline at end of file diff --git a/tools/setup/setup.ico b/tools/setup/setup.ico index bc88f8252221f428096f0403803bff9bc548a8e0..acd77af162334633b1fbec2410b303f23d35226e 100644 GIT binary patch delta 52 ycmdnSv5iBGfq{{Mi9tX>fB^(F7#SFVLJSHD5dI4$1_nQ%*k(Rv4aSXXFPH#~cm`Ym delta 50 xcmdnSv5iB8fq{{Mi9ta@fB^(vFflNw0cimN2w#Jdfq{>Cvk&7drj2SEi~yAu23i0B diff --git a/win/LeoCAD.rc b/win/LeoCAD.rc index 5c78866a..f190cd3e 100644 --- a/win/LeoCAD.rc +++ b/win/LeoCAD.rc @@ -88,8 +88,6 @@ IDB_PIECE BITMAP "res\\piece.bmp" IDB_CAMERA BITMAP "res\\camera.bmp" IDB_LIGHT BITMAP "res\\light.bmp" IDR_FULLSCREEN BITMAP "res\\fullscr.bmp" -IDR_PIECEEDITOR BITMAP "res\\pieceed.bmp" -IDB_EDITOR_ICONS BITMAP "res\\editor.bmp" IDR_LIBRARY BITMAP "res\\library.bmp" IDR_TERRAIN BITMAP "res\\terrain.bmp" IDR_PREVIEW BITMAP "res\\preview.bmp" @@ -161,13 +159,6 @@ BEGIN BUTTON ID_VIEW_FULLSCREEN END -IDR_PIECEEDITOR TOOLBAR 16, 15 -BEGIN - BUTTON ID_EDITOR_FILE_NEW - BUTTON ID_EDITOR_FILE_OPEN - BUTTON ID_EDITOR_FILE_SAVE -END - IDR_LIBRARY TOOLBAR 16, 15 BEGIN BUTTON ID_LIBDLG_FILE_OPEN @@ -1513,7 +1504,7 @@ IDC_MOVE CURSOR "res\\Move.cur" IDC_PAINT CURSOR "res\\Paint.cur" IDC_PAN CURSOR "res\\Pan.cur" IDC_ANGLE CURSOR "res\\Angle.cur" -IDC_ROTATE CURSOR "res\\Rotate.cur" +IDC_ROTATE CURSOR "res\\rotate.cur" IDC_LIGHT CURSOR "res\\bulb.cur" IDC_ZOOM_REGION CURSOR "res\\Zoomrect.cur" IDC_SELECT_GROUP CURSOR "res\\SelctGrp.cur" diff --git a/win/barcmdui.cpp b/win/barcmdui.cpp deleted file mode 100644 index 62fadcd5..00000000 --- a/win/barcmdui.cpp +++ /dev/null @@ -1,79 +0,0 @@ -//////////////////////////////////////////////////////////////// -// The following stuff is to make the command update UI mechanism -// work properly for flat tool bars. The main idea is to convert -// a "checked" button state into a "pressed" button state. Changed -// lines marked with "PD" - -#include "StdAfx.h" -#include "BarCmdUI.h" - -void CFlatOrCoolBarCmdUI::Enable(BOOL bOn) -{ - m_bEnableChanged = TRUE; - CToolBar* pToolBar = (CToolBar*)m_pOther; - ASSERT(pToolBar != NULL); - ASSERT_KINDOF(CToolBar, pToolBar); - ASSERT(m_nIndex < m_nIndexMax); - - UINT nNewStyle = pToolBar->GetButtonStyle(m_nIndex) & ~TBBS_DISABLED; - if (!bOn) - { - nNewStyle |= TBBS_DISABLED; - // WINBUG: If a button is currently pressed and then is disabled - // COMCTL32.DLL does not unpress the button, even after the mouse - // button goes up! We work around this bug by forcing TBBS_PRESSED - // off when a button is disabled. - nNewStyle &= ~TBBS_PRESSED; - } - ASSERT(!(nNewStyle & TBBS_SEPARATOR)); - pToolBar->SetButtonStyle(m_nIndex, nNewStyle); -} - -// Take your pick: -#define MYTBBS_CHECKED TBBS_CHECKED // use "checked" state -//#define MYTBBS_CHECKED TBBS_PRESSED // use pressed state - -////////////////// -// This is the only function that has changed: instead of TBBS_CHECKED, -// I use TBBS_PRESSED--PD -// -void CFlatOrCoolBarCmdUI::SetCheck(int nCheck) -{ - ASSERT(nCheck >= 0 && nCheck <= 2); // 0=>off, 1=>on, 2=>indeterminate - CToolBar* pToolBar = (CToolBar*)m_pOther; - ASSERT(pToolBar != NULL); - ASSERT_KINDOF(CToolBar, pToolBar); - ASSERT(m_nIndex < m_nIndexMax); - - - UINT nOldStyle = pToolBar->GetButtonStyle(m_nIndex); // PD - UINT nNewStyle = nOldStyle & - ~(MYTBBS_CHECKED | TBBS_PRESSED |TBBS_INDETERMINATE); // PD - - // fix check & hot bug - if ((pToolBar->SendMessage (TB_GETHOTITEM,0,0) == (int)m_nIndex) - && (nCheck == 1)) - nNewStyle |= TBBS_PRESSED; - else - { - if (nCheck == 1) - nNewStyle |= MYTBBS_CHECKED; // PD - else if (nCheck == 2) - nNewStyle |= TBBS_INDETERMINATE; - } - - // Following is to fix display bug for TBBS_CHECKED: - // If new state is unchecked, repaint--but only if style actually changing. - // (Otherwise will end up with flicker) - // - if (nNewStyle != nOldStyle) { - ASSERT(!(nNewStyle & TBBS_SEPARATOR)); - pToolBar->SetButtonStyle(m_nIndex, nNewStyle); - pToolBar->Invalidate(); - } -} - -void CFlatOrCoolBarCmdUI::SetText(LPCTSTR) -{ - // ignore for now, but you should really set the text -} diff --git a/win/barcmdui.h b/win/barcmdui.h deleted file mode 100644 index aaca532d..00000000 --- a/win/barcmdui.h +++ /dev/null @@ -1,12 +0,0 @@ -//////////////// -// The following class was copied from BARTOOL.CPP in the MFC source. -// All I changed was SetCheck--PD. -// -class CFlatOrCoolBarCmdUI : public CCmdUI // class private to this file ! -{ -public: // re-implementations only - virtual void Enable(BOOL bOn); - virtual void SetCheck(int nCheck); - virtual void SetText(LPCTSTR lpszText); -}; - diff --git a/win/leocad.vcxproj b/win/leocad.vcxproj index 338746e0..686f8cc3 100644 --- a/win/leocad.vcxproj +++ b/win/leocad.vcxproj @@ -104,7 +104,6 @@ true - @@ -139,7 +138,6 @@ - @@ -418,7 +416,6 @@ - @@ -453,7 +450,6 @@ - diff --git a/win/leocad.vcxproj.filters b/win/leocad.vcxproj.filters index c1b46639..b0260af7 100644 --- a/win/leocad.vcxproj.filters +++ b/win/leocad.vcxproj.filters @@ -35,9 +35,6 @@ Source Files - - Source Files - Source Files @@ -137,9 +134,6 @@ Source Files - - Source Files - Source Files @@ -586,9 +580,6 @@ Header Files - - Header Files - Header Files @@ -688,9 +679,6 @@ Header Files - - Header Files - Header Files diff --git a/win/res/bitmap1.bmp b/win/res/bitmap1.bmp deleted file mode 100644 index 2ad8b742dd60cd3b8f7d06cb0660feace7bc102c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 478 zcmZWkF^&Tv40NPOOB3;pEAxhErChWBNJ$YL>7Y1iX`>ENnwtc%svq*UKLliLfcg<$y;>(=_3fMAJ>JNd&_Z3XcDS zl{=pND>^qKMzWng`bJ8EC2n=XXZD3!h?*)#3+qG9!eeIg$9^S3-OINKPe^S zc(%0`GJQ3^NitoWUI^Qd#(>qKq9FII9=&La|ej7;s}db(_rVg@%nbks~>f9eOIT zyZ%WASjf26&~x$G3|wL{o24*45b^IQ`xelUpKGG&yo%6)}cqI-sE1YW!^h|BWb=GajZNPss=h559wp;JK?X~?s zMpcWdsOEsl8mS|-b498YHS)iJP4Ic0PyJ;$^(pYb*#ftf`A375e@a@rJc?W?&uvEf E21d9(P5=M^ diff --git a/win/res/cursor1.cur b/win/res/cursor1.cur deleted file mode 100644 index 25fc2d2e192a5f14d4a60b50793eb57d3ccbfed6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 326 zcma*hF$%&!5Jus*S|~OOf~{Lx<_1QwNa+#0Nmdk6dIXQ;b?nAx+JJGEZ+7@$hlL4= zoMFv^D!~TW$%tCX^R3eNVT*`i_$z7OE}mdNq$q>EbG>b*#^$| z2cPgx1`w;dC%+g(*b;&hNGLHzScPI+O3?^sX$im z6gaCsoNvh4{m~Xr)$hfRShTM8DfnJS_gzIp0Bo&#rOND531Vu>Mf}ak=RR RU-e5FA8{eRz`gV1cV9Ra5uyM9 diff --git a/win/res/leocad.ico b/win/res/leocad.ico deleted file mode 100644 index 3fbcef3773745e576f87cbeb3e666c0277c6c72e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1078 zcmbu8Jx;?w5QU!|BD+Aga{{a_5Vwd6mz2pp90_SlHl4d%$wf*ZB6L*Af{;QHWqGs4 z5JQ9_G2Z$4cHVj&X#xZYk>?r2o&oK$o^vL!*Rt_@@CBa2yF*G$GoU_2{omi4j|jOVj5Cf3VL1miimAlA!? z2^Gk$7_c@pZtd$M1e9 z-4i{2ayV>51Ych#MX2%tpMVPvH%Hj?oj-d6j10%^#3R)&1?1fH$Wb~VphtiD zk$s2MIWu*x;q*N@Cvz^7pVRv}H>}T_;Z(B2nf8g1sl*Zs>r E0Jj128UO$Q diff --git a/win/res/pieceed.bmp b/win/res/pieceed.bmp deleted file mode 100644 index f8137dde8282fe25b4364ecfb3462b47f9806b4c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 478 zcma)&u@S;B3`La-cPX<5W$v;8J$q29LTyH3gJcqBaG%0F$qttQ1>crre@oxCF4t!x zfjj<;4Oovga>9$;>UnGqZW3Y2G?jp7Da*1D{UFDboPC8coWj|^pbm7V5w~DEvbPo< zwVX`b5wQK_lk>wjKbL~Ymz~a93e?L&u - -#ifdef _DEBUG -#undef THIS_FILE -static char THIS_FILE[]=__FILE__; -#define new DEBUG_NEW -#endif - -////////////////////////////////////////////////////////////////////// -// Math functions - -static inline void Midentity(double M[3][3]) -{ - M[0][0] = M[1][1] = M[2][2] = 1.0; - M[0][1] = M[1][2] = M[2][0] = 0.0; - M[0][2] = M[1][0] = M[2][1] = 0.0; -} - -static inline void McM(double Mr[3][3], double M[3][3]) -{ - Mr[0][0] = M[0][0]; Mr[0][1] = M[0][1]; Mr[0][2] = M[0][2]; - Mr[1][0] = M[1][0]; Mr[1][1] = M[1][1]; Mr[1][2] = M[1][2]; - Mr[2][0] = M[2][0]; Mr[2][1] = M[2][1]; Mr[2][2] = M[2][2]; -} - -static inline void VcV(double Vr[3], double V[3]) -{ - Vr[0] = V[0]; Vr[1] = V[1]; Vr[2] = V[2]; -} - -static inline void MxM(double Mr[3][3], double M1[3][3], double M2[3][3]) -{ - Mr[0][0] = (M1[0][0] * M2[0][0] + M1[0][1] * M2[1][0] + M1[0][2] * M2[2][0]); - Mr[1][0] = (M1[1][0] * M2[0][0] + M1[1][1] * M2[1][0] + M1[1][2] * M2[2][0]); - Mr[2][0] = (M1[2][0] * M2[0][0] + M1[2][1] * M2[1][0] + M1[2][2] * M2[2][0]); - Mr[0][1] = (M1[0][0] * M2[0][1] + M1[0][1] * M2[1][1] + M1[0][2] * M2[2][1]); - Mr[1][1] = (M1[1][0] * M2[0][1] + M1[1][1] * M2[1][1] + M1[1][2] * M2[2][1]); - Mr[2][1] = (M1[2][0] * M2[0][1] + M1[2][1] * M2[1][1] + M1[2][2] * M2[2][1]); - Mr[0][2] = (M1[0][0] * M2[0][2] + M1[0][1] * M2[1][2] + M1[0][2] * M2[2][2]); - Mr[1][2] = (M1[1][0] * M2[0][2] + M1[1][1] * M2[1][2] + M1[1][2] * M2[2][2]); - Mr[2][2] = (M1[2][0] * M2[0][2] + M1[2][1] * M2[1][2] + M1[2][2] * M2[2][2]); -} - -static inline void MTxM(double Mr[3][3], double M1[3][3], double M2[3][3]) -{ - Mr[0][0] = (M1[0][0] * M2[0][0] + M1[1][0] * M2[1][0] + M1[2][0] * M2[2][0]); - Mr[1][0] = (M1[0][1] * M2[0][0] + M1[1][1] * M2[1][0] + M1[2][1] * M2[2][0]); - Mr[2][0] = (M1[0][2] * M2[0][0] + M1[1][2] * M2[1][0] + M1[2][2] * M2[2][0]); - Mr[0][1] = (M1[0][0] * M2[0][1] + M1[1][0] * M2[1][1] + M1[2][0] * M2[2][1]); - Mr[1][1] = (M1[0][1] * M2[0][1] + M1[1][1] * M2[1][1] + M1[2][1] * M2[2][1]); - Mr[2][1] = (M1[0][2] * M2[0][1] + M1[1][2] * M2[1][1] + M1[2][2] * M2[2][1]); - Mr[0][2] = (M1[0][0] * M2[0][2] + M1[1][0] * M2[1][2] + M1[2][0] * M2[2][2]); - Mr[1][2] = (M1[0][1] * M2[0][2] + M1[1][1] * M2[1][2] + M1[2][1] * M2[2][2]); - Mr[2][2] = (M1[0][2] * M2[0][2] + M1[1][2] * M2[1][2] + M1[2][2] * M2[2][2]); -} - -static inline void sMxVpV(double Vr[3], double s1, double M1[3][3], double V1[3], double V2[3]) -{ - Vr[0] = s1 * (M1[0][0] * V1[0] + M1[0][1] * V1[1] + M1[0][2] * V1[2]) + V2[0]; - Vr[1] = s1 * (M1[1][0] * V1[0] + M1[1][1] * V1[1] + M1[1][2] * V1[2]) + V2[1]; - Vr[2] = s1 * (M1[2][0] * V1[0] + M1[2][1] * V1[1] + M1[2][2] * V1[2]) + V2[2]; -} - -static inline void MTxV(double Vr[3], double M1[3][3], double V1[3]) -{ - Vr[0] = (M1[0][0] * V1[0] + M1[1][0] * V1[1] + M1[2][0] * V1[2]); - Vr[1] = (M1[0][1] * V1[0] + M1[1][1] * V1[1] + M1[2][1] * V1[2]); - Vr[2] = (M1[0][2] * V1[0] + M1[1][2] * V1[1] + M1[2][2] * V1[2]); -} - -static inline void sMTxV(double Vr[3], double s1, double M1[3][3], double V1[3]) -{ - Vr[0] = s1*(M1[0][0] * V1[0] + M1[1][0] * V1[1] + M1[2][0] * V1[2]); - Vr[1] = s1*(M1[0][1] * V1[0] + M1[1][1] * V1[1] + M1[2][1] * V1[2]); - Vr[2] = s1*(M1[0][2] * V1[0] + M1[1][2] * V1[1] + M1[2][2] * V1[2]); -} - -static inline void VmV(double Vr[3], const double V1[3], const double V2[3]) -{ - Vr[0] = V1[0] - V2[0]; - Vr[1] = V1[1] - V2[1]; - Vr[2] = V1[2] - V2[2]; -} - -static inline void VcrossV(double Vr[3], const double V1[3], const double V2[3]) -{ - Vr[0] = V1[1]*V2[2] - V1[2]*V2[1]; - Vr[1] = V1[2]*V2[0] - V1[0]*V2[2]; - Vr[2] = V1[0]*V2[1] - V1[1]*V2[0]; -} - -static inline double Vlength(double V[3]) -{ - return sqrt(V[0]*V[0] + V[1]*V[1] + V[2]*V[2]); -} - -static inline double VdotV(double V1[3], double V2[3]) -{ - return (V1[0]*V2[0] + V1[1]*V2[1] + V1[2]*V2[2]); -} - -////////////////////////////////////////////////////////////////////// - -static int tri_contact (double *P1, double *P2, double *P3, double *Q1, double *Q2, double *Q3); -static int obb_disjoint(double B[3][3], double T[3], double a[3], double b[3]); -#define myfabs(x) ((x < 0) ? -x : x) - -////////////////////////////////////////////////////////////////////// -// Construction/Destruction -////////////////////////////////////////////////////////////////////// - -static BOOL RAPID_initialized = FALSE; -static void RAPID_initialize(); - -CRModel::CRModel() -{ - if (!RAPID_initialized) RAPID_initialize(); - - b = NULL; - num_boxes_alloced = 0; - - tris = NULL; - num_tris = 0; - num_tris_alloced = 0; - build_state = RAPID_BUILD_STATE_CONST; -} - -CRModel::~CRModel() -{ - if (!RAPID_initialized) RAPID_initialize(); - - // the boxes and triangles pointed to should be deleted. - delete [] b; - delete [] tris; -} - -int CRModel::BeginModel() -{ - int bs = build_state; - - if (!RAPID_initialized) RAPID_initialize(); - - // free whatever storage we had. Remember, it's okay to delete null - // pointers in C++, so we don't have to check them first. - delete [] b; - b = NULL; - num_boxes_alloced = 0; - delete [] tris; - tris = NULL; - num_tris = 0; - num_tris_alloced = 0; - - build_state = RAPID_BUILD_STATE_BEGIN; - - if ((bs == RAPID_BUILD_STATE_CONST) || - (bs == RAPID_BUILD_STATE_PROCESSED)) - return RAPID_OK; - - if ((bs == RAPID_BUILD_STATE_BEGIN) || - (bs == RAPID_BUILD_STATE_ADDTRI)) - return RAPID_ERR_BUILD_OUT_OF_SEQUENCE; - - return RAPID_OK; -} - -int CRModel::EndModel() -{ - if (!RAPID_initialized) RAPID_initialize(); - - if (num_tris == 0) - return RAPID_ERR_BUILD_EMPTY_MODEL; - - int myrc = build_hierarchy(); - - // only change to processed state if successful. - if (myrc == RAPID_OK) - build_state = RAPID_BUILD_STATE_PROCESSED; - - return myrc; -} - -// int CRModel::AddTri(const double *p1, const double *p2, const double *p3, int id) -int CRModel::AddTri(float *p1, float *p2, float *p3, int id) -{ - if (!RAPID_initialized) RAPID_initialize(); - - int myrc = RAPID_OK; // we'll return this unless a problem is found - - // client forgot to call BeginModel() before calling AddTri(). - if (build_state == RAPID_BUILD_STATE_PROCESSED) - return RAPID_ERR_BUILD_OUT_OF_SEQUENCE; - - // first make sure that we haven't filled up our allocation. - // if we have, allocate a new array of twice the size, and copy - // the old data to it. - if (num_tris == num_tris_alloced) - { - // decide on new size -- accounting for first time, where none are - // allocated - int n = num_tris_alloced*2; - if (n == 0) n = 1; - - // make new array, and copy the old one to it - tri *t = new tri[n]; - - // if we can't get any more space, return an error - if (!t) - { - // we are leaving the model unchanged. - return RAPID_ERR_MODEL_OUT_OF_MEMORY; - } - - int i; - for(i=0; i3 && rfabs(d[0])+g==rfabs(d[0]) && rfabs(d[1])+g==rfabs(d[1])) - a[0][1]=0.0; - else if (rfabs(a[0][1])>tresh) - { - h = d[1]-d[0]; - if (rfabs(h)+g == rfabs(h)) t=(a[0][1])/h; - else - { - theta=0.5*h/(a[0][1]); - t=1.0/(rfabs(theta)+sqrt(1.0+theta*theta)); - if (theta < 0.0) t = -t; - } - c=1.0/sqrt(1+t*t); s=t*c; tau=s/(1.0+c); h=t*a[0][1]; - z[0] -= h; z[1] += h; d[0] -= h; d[1] += h; - a[0][1]=0.0; - ROT(a,0,2,1,2); ROT(v,0,0,0,1); ROT(v,1,0,1,1); ROT(v,2,0,2,1); - nrot++; - } - } - - { - g = 100.0*rfabs(a[0][2]); - if (i>3 && rfabs(d[0])+g==rfabs(d[0]) && rfabs(d[2])+g==rfabs(d[2])) - a[0][2]=0.0; - else if (rfabs(a[0][2])>tresh) - { - h = d[2]-d[0]; - if (rfabs(h)+g == rfabs(h)) t=(a[0][2])/h; - else - { - theta=0.5*h/(a[0][2]); - t=1.0/(rfabs(theta)+sqrt(1.0+theta*theta)); - if (theta < 0.0) t = -t; - } - c=1.0/sqrt(1+t*t); s=t*c; tau=s/(1.0+c); h=t*a[0][2]; - z[0] -= h; z[2] += h; d[0] -= h; d[2] += h; - a[0][2]=0.0; - ROT(a,0,1,1,2); ROT(v,0,0,0,2); ROT(v,1,0,1,2); ROT(v,2,0,2,2); - nrot++; - } - } - - - { - g = 100.0*rfabs(a[1][2]); - if (i>3 && rfabs(d[1])+g==rfabs(d[1]) && rfabs(d[2])+g==rfabs(d[2])) - a[1][2]=0.0; - else if (rfabs(a[1][2])>tresh) - { - h = d[2]-d[1]; - if (rfabs(h)+g == rfabs(h)) t=(a[1][2])/h; - else - { - theta=0.5*h/(a[1][2]); - t=1.0/(rfabs(theta)+sqrt(1.0+theta*theta)); - if (theta < 0.0) t = -t; - } - c=1.0/sqrt(1+t*t); s=t*c; tau=s/(1.0+c); h=t*a[1][2]; - z[1] -= h; z[2] += h; d[1] -= h; d[2] += h; - a[1][2]=0.0; - ROT(a,0,1,0,2); ROT(v,0,1,0,2); ROT(v,1,1,1,2); ROT(v,2,1,2,2); - nrot++; - } - } - - b[0] += z[0]; d[0] = b[0]; z[0] = 0.0; - b[1] += z[1]; d[1] = b[1]; z[1] = 0.0; - b[2] += z[2]; d[2] = b[2]; z[2] = 0.0; - - } - -// fprintf(stderr, "eigen: too many iterations in Jacobi transform (%d).\n", i); - - return i; -} - -// not a full sort -- just makes column 1 the largest -static int eigen_and_sort1(double evecs[3][3], double cov[3][3]) -{ - double t; - double evals[3]; - int n; - - n = Meigen(evecs, evals, cov); - - if (evals[2] > evals[0]) - { - if (evals[2] > evals[1]) - { - // 2 is largest, swap with column 0 - t = evecs[0][2]; - evecs[0][2] = evecs[0][0]; - evecs[0][0] = t; - t = evecs[1][2]; - evecs[1][2] = evecs[1][0]; - evecs[1][0] = t; - t = evecs[2][2]; - evecs[2][2] = evecs[2][0]; - evecs[2][0] = t; - } - else - { - // 1 is largest, swap with column 0 - t = evecs[0][1]; - evecs[0][1] = evecs[0][0]; - evecs[0][0] = t; - t = evecs[1][1]; - evecs[1][1] = evecs[1][0]; - evecs[1][0] = t; - t = evecs[2][1]; - evecs[2][1] = evecs[2][0]; - evecs[2][0] = t; - } - } - else - { - if (evals[0] > evals[1]) - { - // 0 is largest, do nothing - } - else - { - // 1 is largest - t = evecs[0][1]; - evecs[0][1] = evecs[0][0]; - evecs[0][0] = t; - t = evecs[1][1]; - evecs[1][1] = evecs[1][0]; - evecs[1][0] = t; - t = evecs[2][1]; - evecs[2][1] = evecs[2][0]; - evecs[2][0] = t; - } - } - - // we are returning the number of iterations Meigen took. - // too many iterations means our chosen orientation is bad. - return n; -} - -static inline void minmax(double &mn, double &mx, double v) -{ - if (v < mn) mn = v; - else if (v > mx) mx = v; -} - -typedef struct -{ - double A; - double m[3]; - double s[3][3]; -} moment; - -typedef struct -{ - double A; - double m[3]; - double s[3][3]; -} accum; - -static inline void clear_accum(accum &a) -{ - a.m[0] = a.m[1] = a.m[2] = 0.0; - a.s[0][0] = a.s[0][1] = a.s[0][2] = 0.0; - a.s[1][0] = a.s[1][1] = a.s[1][2] = 0.0; - a.s[2][0] = a.s[2][1] = a.s[2][2] = 0.0; - a.A = 0.0; -} - -static inline void accum_moment(accum &a, moment &b) -{ - a.m[0] += b.m[0] * b.A; - a.m[1] += b.m[1] * b.A; - a.m[2] += b.m[2] * b.A; - - a.s[0][0] += b.s[0][0]; - a.s[0][1] += b.s[0][1]; - a.s[0][2] += b.s[0][2]; - a.s[1][0] += b.s[1][0]; - a.s[1][1] += b.s[1][1]; - a.s[1][2] += b.s[1][2]; - a.s[2][0] += b.s[2][0]; - a.s[2][1] += b.s[2][1]; - a.s[2][2] += b.s[2][2]; - - a.A += b.A; -} - -static inline void mean_from_moment(double M[3], moment &m) -{ - M[0] = m.m[0]; - M[1] = m.m[1]; - M[2] = m.m[2]; -} - -static inline void mean_from_accum(double M[3], accum &a) -{ - M[0] = a.m[0] / a.A; - M[1] = a.m[1] / a.A; - M[2] = a.m[2] / a.A; -} - -static inline void covariance_from_accum(double C[3][3], accum &a) -{ - int i,j; - for(i=0; i<3; i++) - for(j=0; j<3; j++) - C[i][j] = a.s[i][j] - a.m[i]*a.m[j]/a.A; -} - -static inline void compute_moment(moment &M, double p[3], double q[3], double r[3]) -{ - double u[3], v[3], w[3]; - - // compute the area of the triangle - VmV(u, q, p); - VmV(v, r, p); - VcrossV(w, u, v); - M.A = 0.5 * Vlength(w); - - if (M.A == 0.0) - { - // This triangle has zero area. The second order components - // would be eliminated with the usual formula, so, for the - // sake of robustness we use an alternative form. These are the - // centroid and second-order components of the triangle's vertices. - - // centroid - M.m[0] = (p[0] + q[0] + r[0]) /3; - M.m[1] = (p[1] + q[1] + r[1]) /3; - M.m[2] = (p[2] + q[2] + r[2]) /3; - - // second-order components - M.s[0][0] = (p[0]*p[0] + q[0]*q[0] + r[0]*r[0]); - M.s[0][1] = (p[0]*p[1] + q[0]*q[1] + r[0]*r[1]); - M.s[0][2] = (p[0]*p[2] + q[0]*q[2] + r[0]*r[2]); - M.s[1][1] = (p[1]*p[1] + q[1]*q[1] + r[1]*r[1]); - M.s[1][2] = (p[1]*p[2] + q[1]*q[2] + r[1]*r[2]); - M.s[2][2] = (p[2]*p[2] + q[2]*q[2] + r[2]*r[2]); - M.s[2][1] = M.s[1][2]; - M.s[1][0] = M.s[0][1]; - M.s[2][0] = M.s[0][2]; - - return; - } - - // get the centroid - M.m[0] = (p[0] + q[0] + r[0])/3; - M.m[1] = (p[1] + q[1] + r[1])/3; - M.m[2] = (p[2] + q[2] + r[2])/3; - - // get the second order components -- note the weighting by the area - M.s[0][0] = M.A*(9*M.m[0]*M.m[0]+p[0]*p[0]+q[0]*q[0]+r[0]*r[0])/12; - M.s[0][1] = M.A*(9*M.m[0]*M.m[1]+p[0]*p[1]+q[0]*q[1]+r[0]*r[1])/12; - M.s[1][1] = M.A*(9*M.m[1]*M.m[1]+p[1]*p[1]+q[1]*q[1]+r[1]*r[1])/12; - M.s[0][2] = M.A*(9*M.m[0]*M.m[2]+p[0]*p[2]+q[0]*q[2]+r[0]*r[2])/12; - M.s[1][2] = M.A*(9*M.m[1]*M.m[2]+p[1]*p[2]+q[1]*q[2]+r[1]*r[2])/12; - M.s[2][2] = M.A*(9*M.m[2]*M.m[2]+p[2]*p[2]+q[2]*q[2]+r[2]*r[2])/12; - M.s[2][1] = M.s[1][2]; - M.s[1][0] = M.s[0][1]; - M.s[2][0] = M.s[0][2]; -} - -static inline void compute_moments(moment *M, tri *tris, int num_tris) -{ - int i; - - // first collect all the moments, and obtain the area of the - // smallest nonzero area triangle. - - double Amin = 0.0; - int zero = 0; - int nonzero = 0; - for(i=0; i tri structures in an array starting at . -// -// We are told that the mean point is and the orientation -// for the parent box will be . The split axis is to be the -// vector given by . -// -// , , and are model space coordinates. -int CRModel::build_hierarchy() -{ - // allocate the boxes and set the box list globals - num_boxes_alloced = num_tris * 2; - b = new box[num_boxes_alloced]; - if (b == 0) return RAPID_ERR_MODEL_OUT_OF_MEMORY; - RAPID_boxes = b; - RAPID_boxes_inited = 1; // we are in process of initializing b[0]. - - // Determine initial orientation, mean point, and splitting axis. - int i; - accum M; - - // double F1[3]; - // double S1[6]; - double C[3][3]; - - RAPID_moment = new moment[num_tris]; - if (RAPID_moment == 0) - { - delete [] b; - return RAPID_ERR_MODEL_OUT_OF_MEMORY; - } - compute_moments(RAPID_moment, tris, num_tris); - - clear_accum(M); - for(i=0; ipR. - // The axis along which to split will be column 0 of this->pR. - // The mean point is passed in on this->pT. - - // When this routine completes, the position and orientation in model - // space will be established, as well as its dimensions. Child boxes - // will be constructed and placed in the parent's CS. - - if (n == 1) - { - return split_recurse(t); - } - - // walk along the tris for the box, and do the following: - // 1. collect the max and min of the vertices along the axes of . - // 2. decide which group the triangle goes in, performing appropriate swap. - // 3. accumulate the mean point and covariance data for that triangle. - - accum M1, M2; - double C[3][3]; - double c[3]; - double minval[3], maxval[3]; - - int rc; // for return code on procedure calls. - int in; - tri *ptr; - int i; - double axdmp; - int n1 = 0; // The number of tris in group 1. - // Group 2 will have n - n1 tris. - - // project approximate mean point onto splitting axis, and get coord. - axdmp = (pR[0][0] * pT[0] + pR[1][0] * pT[1] + pR[2][0] * pT[2]); - - clear_accum(M1); - clear_accum(M2); - - MTxV(c, pR, RAPID_tri[t[0]].p1); - minval[0] = maxval[0] = c[0]; - minval[1] = maxval[1] = c[1]; - minval[2] = maxval[2] = c[2]; - for(i=0; ip1); - minmax(minval[0], maxval[0], c[0]); - minmax(minval[1], maxval[1], c[1]); - minmax(minval[2], maxval[2], c[2]); - - MTxV(c, pR, ptr->p2); - minmax(minval[0], maxval[0], c[0]); - minmax(minval[1], maxval[1], c[1]); - minmax(minval[2], maxval[2], c[2]); - - MTxV(c, pR, ptr->p3); - minmax(minval[0], maxval[0], c[0]); - minmax(minval[1], maxval[1], c[1]); - minmax(minval[2], maxval[2], c[2]); - - // grab the mean point of the in'th triangle, project - // it onto the splitting axis (1st column of pR) and - // see where it lies with respect to axdmp. - mean_from_moment(c, RAPID_moment[in]); - - if (((pR[0][0]*c[0] + pR[1][0]*c[1] + pR[2][0]*c[2]) < axdmp) - && ((n!=2)) || ((n==2) && (i==0))) - { - // accumulate first and second order moments for group 1 - accum_moment(M1, RAPID_moment[in]); - - // put it in group 1 by swapping t[i] with t[n1] - int temp = t[i]; - t[i] = t[n1]; - t[n1] = temp; - n1++; - } - else - { - // accumulate first and second order moments for group 2 - accum_moment(M2, RAPID_moment[in]); - - // leave it in group 2 - // do nothing...it happens by default - } - } - - // done using this->pT as a mean point. - - - // error check! - if ((n1 == 0) || (n1 == n)) - { - // our partitioning has failed: all the triangles fell into just - // one of the groups. So, we arbitrarily partition them into - // equal parts, and proceed. - - n1 = n/2; - - // now recompute accumulated stuff - reaccum_moments(M1, t, n1); - reaccum_moments(M2, t + n1, n - n1); - } - - // With the max and min data, determine the center point and dimensions - // of the parent box. - - c[0] = (minval[0] + maxval[0])*0.5; - c[1] = (minval[1] + maxval[1])*0.5; - c[2] = (minval[2] + maxval[2])*0.5; - - pT[0] = c[0] * pR[0][0] + c[1] * pR[0][1] + c[2] * pR[0][2]; - pT[1] = c[0] * pR[1][0] + c[1] * pR[1][1] + c[2] * pR[1][2]; - pT[2] = c[0] * pR[2][0] + c[1] * pR[2][1] + c[2] * pR[2][2]; - d[0] = (maxval[0] - minval[0])*0.5; - d[1] = (maxval[1] - minval[1])*0.5; - d[2] = (maxval[2] - minval[2])*0.5; - - // allocate new boxes - P = RAPID_boxes + RAPID_boxes_inited++; - N = RAPID_boxes + RAPID_boxes_inited++; - - // Compute the orienations for the child boxes (eigenvectors of - // covariance matrix). Select the direction of maximum spread to be - // the split axis for each child. - - double tR[3][3]; - - if (n1 > 1) - { - mean_from_accum(P->pT, M1); - covariance_from_accum(C, M1); - - if (eigen_and_sort1(tR, C) > 30) - { - // unable to find an orientation. We'll just pick identity. - Midentity(tR); - } - - McM(P->pR, tR); - if ((rc = P->split_recurse(t, n1)) != RAPID_OK) return rc; - } - else - { - if ((rc = P->split_recurse(t)) != RAPID_OK) return rc; - } - McM(C, P->pR); MTxM(P->pR, pR, C); // and F1 - VmV(c, P->pT, pT); MTxV(P->pT, pR, c); - - if ((n-n1) > 1) - { - mean_from_accum(N->pT, M2); - covariance_from_accum (C, M2); - - if (eigen_and_sort1(tR, C) > 30) - { - // unable to find an orientation. We'll just pick identity. - Midentity(tR); - } - - McM(N->pR, tR); - if ((rc = N->split_recurse(t + n1, n - n1)) != RAPID_OK) return rc; - } - else - { - if ((rc = N->split_recurse(t+n1)) != RAPID_OK) return rc; - } - McM(C, N->pR); MTxM(N->pR, pR, C); - VmV(c, N->pT, pT); MTxV(N->pT, pR, c); - - return RAPID_OK; -} - -int box::split_recurse(int *t) -{ - // For a single triangle, orientation is easily determined. - // The major axis is parallel to the longest edge. - // The minor axis is normal to the triangle. - // The in-between axis is determine by these two. - - // this->pR, this->d, and this->pT are set herein. - - P = N = 0; - tri *ptr = RAPID_tri + t[0]; - - // Find the major axis: parallel to the longest edge. - double u12[3], u23[3], u31[3]; - - // First compute the squared-lengths of each edge - VmV(u12, ptr->p1, ptr->p2); - double d12 = VdotV(u12,u12); - VmV(u23, ptr->p2, ptr->p3); - double d23 = VdotV(u23,u23); - VmV(u31, ptr->p3, ptr->p1); - double d31 = VdotV(u31,u31); - - // Find the edge of longest squared-length, normalize it to - // unit length, and put result into a0. - double a0[3]; - double l; - if (d12 > d23) - { - if (d12 > d31) - { - l = 1.0 / sqrt(d12); - a0[0] = u12[0] * l; - a0[1] = u12[1] * l; - a0[2] = u12[2] * l; - } - else - { - l = 1.0 / sqrt(d31); - a0[0] = u31[0] * l; - a0[1] = u31[1] * l; - a0[2] = u31[2] * l; - } - } - else - { - if (d23 > d31) - { - l = 1.0 / sqrt(d23); - a0[0] = u23[0] * l; - a0[1] = u23[1] * l; - a0[2] = u23[2] * l; - } - else - { - l = 1.0 / sqrt(d31); - a0[0] = u31[0] * l; - a0[1] = u31[1] * l; - a0[2] = u31[2] * l; - } - } - - // Now compute unit normal to triangle, and put into a2. - double a2[3]; - VcrossV(a2, u12, u23); - l = 1.0 / Vlength(a2); a2[0] *= l; a2[1] *= l; a2[2] *= l; - - // a1 is a2 cross a0. - double a1[3]; - VcrossV(a1, a2, a0); - - // Now make the columns of this->pR the vectors a0, a1, and a2. - pR[0][0] = a0[0]; pR[0][1] = a1[0]; pR[0][2] = a2[0]; - pR[1][0] = a0[1]; pR[1][1] = a1[1]; pR[1][2] = a2[1]; - pR[2][0] = a0[2]; pR[2][1] = a1[2]; pR[2][2] = a2[2]; - - // Now compute the maximum and minimum extents of each vertex - // along each of the box axes. From this we will compute the - // box center and box dimensions. - double minval[3], maxval[3]; - double c[3]; - - MTxV(c, pR, ptr->p1); - minval[0] = maxval[0] = c[0]; - minval[1] = maxval[1] = c[1]; - minval[2] = maxval[2] = c[2]; - - MTxV(c, pR, ptr->p2); - minmax(minval[0], maxval[0], c[0]); - minmax(minval[1], maxval[1], c[1]); - minmax(minval[2], maxval[2], c[2]); - - MTxV(c, pR, ptr->p3); - minmax(minval[0], maxval[0], c[0]); - minmax(minval[1], maxval[1], c[1]); - minmax(minval[2], maxval[2], c[2]); - - // With the max and min data, determine the center point and dimensions - // of the box - c[0] = (minval[0] + maxval[0])*0.5; - c[1] = (minval[1] + maxval[1])*0.5; - c[2] = (minval[2] + maxval[2])*0.5; - - pT[0] = c[0] * pR[0][0] + c[1] * pR[0][1] + c[2] * pR[0][2]; - pT[1] = c[0] * pR[1][0] + c[1] * pR[1][1] + c[2] * pR[1][2]; - pT[2] = c[0] * pR[2][0] + c[1] * pR[2][1] + c[2] * pR[2][2]; - - d[0] = (maxval[0] - minval[0])*0.5; - d[1] = (maxval[1] - minval[1])*0.5; - d[2] = (maxval[2] - minval[2])*0.5; - - // Assign the one triangle to this box - trp = ptr; - - return RAPID_OK; -} - -////////////////////////////////////////////////////////////////////// -// Overlap - -static inline double _max(double a, double b, double c) -{ - double t = a; - if (b > t) t = b; - if (c > t) t = c; - return t; -} - -static inline double _min(double a, double b, double c) -{ - double t = a; - if (b < t) t = b; - if (c < t) t = c; - return t; -} - -static int project6(double *ax, double *p1, double *p2, double *p3, double *q1, double *q2, double *q3) -{ - double P1 = VdotV(ax, p1); - double P2 = VdotV(ax, p2); - double P3 = VdotV(ax, p3); - double Q1 = VdotV(ax, q1); - double Q2 = VdotV(ax, q2); - double Q3 = VdotV(ax, q3); - - double mx1 = _max(P1, P2, P3); - double mn1 = _min(P1, P2, P3); - double mx2 = _max(Q1, Q2, Q3); - double mn2 = _min(Q1, Q2, Q3); - - if (mn1 > mx2) return 0; - if (mn2 > mx1) return 0; - - return 1; -} - -// very robust triangle intersection test -// uses no divisions and works on coplanar triangles -// -// One triangle is (p1,p2,p3). Other is (q1,q2,q3). -// Edges are (e1,e2,e3) and (f1,f2,f3). -// Normals are n1 and m1 -// Outwards are (g1,g2,g3) and (h1,h2,h3). -// -// We assume that the triangle vertices are in the same coordinate system. -static int tri_contact (double *P1, double *P2, double *P3, double *Q1, double *Q2, double *Q3) -{ - // First thing we do is establish a new c.s. so that p1 is at (0,0,0). - double p1[3], p2[3], p3[3]; - double q1[3], q2[3], q3[3]; - double e1[3], e2[3], e3[3]; - double f1[3], f2[3], f3[3]; - double g1[3], g2[3], g3[3]; - double h1[3], h2[3], h3[3]; - double n1[3], m1[3]; - double z[3]; - - double ef11[3], ef12[3], ef13[3]; - double ef21[3], ef22[3], ef23[3]; - double ef31[3], ef32[3], ef33[3]; - - z[0] = 0.0; z[1] = 0.0; z[2] = 0.0; - - p1[0] = P1[0] - P1[0]; p1[1] = P1[1] - P1[1]; p1[2] = P1[2] - P1[2]; - p2[0] = P2[0] - P1[0]; p2[1] = P2[1] - P1[1]; p2[2] = P2[2] - P1[2]; - p3[0] = P3[0] - P1[0]; p3[1] = P3[1] - P1[1]; p3[2] = P3[2] - P1[2]; - - q1[0] = Q1[0] - P1[0]; q1[1] = Q1[1] - P1[1]; q1[2] = Q1[2] - P1[2]; - q2[0] = Q2[0] - P1[0]; q2[1] = Q2[1] - P1[1]; q2[2] = Q2[2] - P1[2]; - q3[0] = Q3[0] - P1[0]; q3[1] = Q3[1] - P1[1]; q3[2] = Q3[2] - P1[2]; - - e1[0] = p2[0] - p1[0]; e1[1] = p2[1] - p1[1]; e1[2] = p2[2] - p1[2]; - e2[0] = p3[0] - p2[0]; e2[1] = p3[1] - p2[1]; e2[2] = p3[2] - p2[2]; - e3[0] = p1[0] - p3[0]; e3[1] = p1[1] - p3[1]; e3[2] = p1[2] - p3[2]; - - f1[0] = q2[0] - q1[0]; f1[1] = q2[1] - q1[1]; f1[2] = q2[2] - q1[2]; - f2[0] = q3[0] - q2[0]; f2[1] = q3[1] - q2[1]; f2[2] = q3[2] - q2[2]; - f3[0] = q1[0] - q3[0]; f3[1] = q1[1] - q3[1]; f3[2] = q1[2] - q3[2]; - - VcrossV(n1, e1, e2); - VcrossV(m1, f1, f2); - - VcrossV(g1, e1, n1); - VcrossV(g2, e2, n1); - VcrossV(g3, e3, n1); - VcrossV(h1, f1, m1); - VcrossV(h2, f2, m1); - VcrossV(h3, f3, m1); - - VcrossV(ef11, e1, f1); - VcrossV(ef12, e1, f2); - VcrossV(ef13, e1, f3); - VcrossV(ef21, e2, f1); - VcrossV(ef22, e2, f2); - VcrossV(ef23, e2, f3); - VcrossV(ef31, e3, f1); - VcrossV(ef32, e3, f2); - VcrossV(ef33, e3, f3); - - // now begin the series of tests - if (!project6(n1, p1, p2, p3, q1, q2, q3)) return 0; - if (!project6(m1, p1, p2, p3, q1, q2, q3)) return 0; - - if (!project6(ef11, p1, p2, p3, q1, q2, q3)) return 0; - if (!project6(ef12, p1, p2, p3, q1, q2, q3)) return 0; - if (!project6(ef13, p1, p2, p3, q1, q2, q3)) return 0; - if (!project6(ef21, p1, p2, p3, q1, q2, q3)) return 0; - if (!project6(ef22, p1, p2, p3, q1, q2, q3)) return 0; - if (!project6(ef23, p1, p2, p3, q1, q2, q3)) return 0; - if (!project6(ef31, p1, p2, p3, q1, q2, q3)) return 0; - if (!project6(ef32, p1, p2, p3, q1, q2, q3)) return 0; - if (!project6(ef33, p1, p2, p3, q1, q2, q3)) return 0; - - if (!project6(g1, p1, p2, p3, q1, q2, q3)) return 0; - if (!project6(g2, p1, p2, p3, q1, q2, q3)) return 0; - if (!project6(g3, p1, p2, p3, q1, q2, q3)) return 0; - if (!project6(h1, p1, p2, p3, q1, q2, q3)) return 0; - if (!project6(h2, p1, p2, p3, q1, q2, q3)) return 0; - if (!project6(h3, p1, p2, p3, q1, q2, q3)) return 0; - - return 1; -} - - -/* -This is a test between two boxes, box A and box B. It is assumed that -the coordinate system is aligned and centered on box A. The 3x3 -matrix B specifies box B's orientation with respect to box A. -Specifically, the columns of B are the basis vectors (axis vectors) of -box B. The center of box B is located at the vector T. The -dimensions of box B are given in the array b. The orientation and -placement of box A, in this coordinate system, are the identity matrix -and zero vector, respectively, so they need not be specified. The -dimensions of box A are given in array a. - -This test operates in two modes, depending on how the library is -compiled. It indicates whether the two boxes are overlapping, by -returning a boolean. - -The second version of the routine will return a conservative bounds on -the distance between the polygon sets which the boxes enclose. It is -used when RAPID is being used to estimate the distance between two -models. -*/ -static int obb_disjoint(double B[3][3], double T[3], double a[3], double b[3]) -{ - register double t, s; - register int r; - double Bf[3][3]; - const double reps = 1e-6; - - // Bf = fabs(B) - Bf[0][0] = myfabs(B[0][0]); Bf[0][0] += reps; - Bf[0][1] = myfabs(B[0][1]); Bf[0][1] += reps; - Bf[0][2] = myfabs(B[0][2]); Bf[0][2] += reps; - Bf[1][0] = myfabs(B[1][0]); Bf[1][0] += reps; - Bf[1][1] = myfabs(B[1][1]); Bf[1][1] += reps; - Bf[1][2] = myfabs(B[1][2]); Bf[1][2] += reps; - Bf[2][0] = myfabs(B[2][0]); Bf[2][0] += reps; - Bf[2][1] = myfabs(B[2][1]); Bf[2][1] += reps; - Bf[2][2] = myfabs(B[2][2]); Bf[2][2] += reps; - -// printf("Box test: Bf[3][3], B[3][3], T[3], a[3], b[3]\n"); - - // if any of these tests are one-sided, then the polyhedra are disjoint - r = 1; - - // A1 x A2 = A0 - t = myfabs(T[0]); - - r &= (t <= - (a[0] + b[0] * Bf[0][0] + b[1] * Bf[0][1] + b[2] * Bf[0][2])); - if (!r) return 1; - - // B1 x B2 = B0 - s = T[0]*B[0][0] + T[1]*B[1][0] + T[2]*B[2][0]; - t = myfabs(s); - - r &= ( t <= - (b[0] + a[0] * Bf[0][0] + a[1] * Bf[1][0] + a[2] * Bf[2][0])); - if (!r) return 2; - - // A2 x A0 = A1 - t = myfabs(T[1]); - - r &= ( t <= - (a[1] + b[0] * Bf[1][0] + b[1] * Bf[1][1] + b[2] * Bf[1][2])); - if (!r) return 3; - - // A0 x A1 = A2 - t = myfabs(T[2]); - - r &= ( t <= - (a[2] + b[0] * Bf[2][0] + b[1] * Bf[2][1] + b[2] * Bf[2][2])); - if (!r) return 4; - - // B2 x B0 = B1 - s = T[0]*B[0][1] + T[1]*B[1][1] + T[2]*B[2][1]; - t = myfabs(s); - - r &= ( t <= - (b[1] + a[0] * Bf[0][1] + a[1] * Bf[1][1] + a[2] * Bf[2][1])); - if (!r) return 5; - - // B0 x B1 = B2 - s = T[0]*B[0][2] + T[1]*B[1][2] + T[2]*B[2][2]; - t = myfabs(s); - - r &= ( t <= - (b[2] + a[0] * Bf[0][2] + a[1] * Bf[1][2] + a[2] * Bf[2][2])); - if (!r) return 6; - - // A0 x B0 - s = T[2] * B[1][0] - T[1] * B[2][0]; - t = myfabs(s); - - r &= ( t <= - (a[1] * Bf[2][0] + a[2] * Bf[1][0] + - b[1] * Bf[0][2] + b[2] * Bf[0][1])); - if (!r) return 7; - - // A0 x B1 - s = T[2] * B[1][1] - T[1] * B[2][1]; - t = myfabs(s); - - r &= ( t <= - (a[1] * Bf[2][1] + a[2] * Bf[1][1] + - b[0] * Bf[0][2] + b[2] * Bf[0][0])); - if (!r) return 8; - - // A0 x B2 - s = T[2] * B[1][2] - T[1] * B[2][2]; - t = myfabs(s); - - r &= ( t <= - (a[1] * Bf[2][2] + a[2] * Bf[1][2] + - b[0] * Bf[0][1] + b[1] * Bf[0][0])); - if (!r) return 9; - - // A1 x B0 - s = T[0] * B[2][0] - T[2] * B[0][0]; - t = myfabs(s); - - r &= ( t <= - (a[0] * Bf[2][0] + a[2] * Bf[0][0] + - b[1] * Bf[1][2] + b[2] * Bf[1][1])); - if (!r) return 10; - - // A1 x B1 - s = T[0] * B[2][1] - T[2] * B[0][1]; - t = myfabs(s); - - r &= ( t <= - (a[0] * Bf[2][1] + a[2] * Bf[0][1] + - b[0] * Bf[1][2] + b[2] * Bf[1][0])); - if (!r) return 11; - - // A1 x B2 - s = T[0] * B[2][2] - T[2] * B[0][2]; - t = myfabs(s); - - r &= (t <= - (a[0] * Bf[2][2] + a[2] * Bf[0][2] + - b[0] * Bf[1][1] + b[1] * Bf[1][0])); - if (!r) return 12; - - // A2 x B0 - s = T[1] * B[0][0] - T[0] * B[1][0]; - t = myfabs(s); - - r &= (t <= - (a[0] * Bf[1][0] + a[1] * Bf[0][0] + - b[1] * Bf[2][2] + b[2] * Bf[2][1])); - if (!r) return 13; - - // A2 x B1 - s = T[1] * B[0][1] - T[0] * B[1][1]; - t = myfabs(s); - - r &= ( t <= - (a[0] * Bf[1][1] + a[1] * Bf[0][1] + - b[0] * Bf[2][2] + b[2] * Bf[2][0])); - if (!r) return 14; - - // A2 x B2 - s = T[1] * B[0][2] - T[0] * B[1][2]; - t = myfabs(s); - - r &= ( t <= - (a[0] * Bf[1][2] + a[1] * Bf[0][2] + - b[0] * Bf[2][1] + b[1] * Bf[2][0])); - if (!r) return 15; - - return 0; // should equal 0 -} - -////////////////////////////////////////////////////////////////////// -// Collide - -static double RAPID_mR[3][3]; -static double RAPID_mT[3]; -static double RAPID_ms; - -static int RAPID_first_contact; - -static int RAPID_num_box_tests; -static int RAPID_num_tri_tests; -static int RAPID_num_contacts; - -static int RAPID_num_cols_alloced = 0; -static collision_pair *RAPID_contact = 0; - -static int add_collision(int id1, int id2) -{ - if (!RAPID_contact) - { - RAPID_contact = new collision_pair[10]; - if (!RAPID_contact) - return RAPID_ERR_COLLIDE_OUT_OF_MEMORY; - - RAPID_num_cols_alloced = 10; - RAPID_num_contacts = 0; - } - - if (RAPID_num_contacts == RAPID_num_cols_alloced) - { - collision_pair *t = new collision_pair[RAPID_num_cols_alloced*2]; - if (!t) - { - return RAPID_ERR_COLLIDE_OUT_OF_MEMORY; - } - RAPID_num_cols_alloced *= 2; - - for(int i=0; itrp->p1, RAPID_mT); - sMxVpV(i2, RAPID_ms, RAPID_mR, b1->trp->p2, RAPID_mT); - sMxVpV(i3, RAPID_ms, RAPID_mR, b1->trp->p3, RAPID_mT); - - RAPID_num_tri_tests++; - - int f = tri_contact(i1, i2, i3, b2->trp->p1,b2->trp->p2, b2->trp->p3); - - if (f) - { - // add_collision may be unable to allocate enough memory, - // so be prepared to pass along an OUT_OF_MEMORY return code. - if ((rc = add_collision(b1->trp->id, b2->trp->id)) != RAPID_OK) - return rc; - } - - return RAPID_OK; -} - -static int collide_recursive(box *b1, box *b2, double R[3][3], double T[3], double s) -{ - double d[3]; // temp storage for scaled dimensions of box b2. - int rc; // return codes - - if (1) - { -// printf("Next collision: b1, b2, R, T, s\n"); -// printf("b1=%x, b2=%x\n", b1, b2); -// Mprint(R); -// Vprint(T); -// printf("%lf\n", s); - - if (RAPID_first_contact && (RAPID_num_contacts > 0)) - return RAPID_OK; - - // test top level - RAPID_num_box_tests++; - - int f1; - - d[0] = s * b2->d[0]; - d[1] = s * b2->d[1]; - d[2] = s * b2->d[2]; - f1 = obb_disjoint(R, T, b1->d, d); - -// if (f1 != 0) -// printf("BOX TEST %d DISJOINT! (code %d)\n", RAPID_num_box_tests, f1); -// else -// printf("BOX TEST %d OVERLAP! (code %d)\n", RAPID_num_box_tests, f1); - - if (f1 != 0) - return RAPID_OK; // stop processing this test, go to top of loop - - // contact between boxes - if (b1->leaf() && b2->leaf()) - { - // it is a leaf pair - compare the polygons therein - // tri_contact uses the model-to-model transforms stored in - // RAPID_mR, RAPID_mT, RAPID_ms. - - // this will pass along any OUT_OF_MEMORY return codes which - // may be generated. - return tri_contact(b1, b2); - } - - double U[3]; - - double cR[3][3], cT[3], cs; - - // Currently, the transform from model 2 to model 1 space is - // given by [B T s], where y = [B T s].x = s.B.x + T. - - if (b2->leaf() || (!b1->leaf() && (b1->size() > b2->size()))) - { - // here we descend to children of b1. The transform from - // a child of b1 to b1 is stored in [b1->N->pR,b1->N->pT], - // but we will denote it [B1 T1 1] for short. Notice that - // children boxes always have same scaling as parent, so s=1 - // for such nested transforms. - - // Here, we compute [B1 T1 1]'[B T s] = [B1'B B1'(T-T1) s] - // for each child, and store the transform into the collision - // test queue. - - MTxM(cR, b1->N->pR, R); - VmV(U, T, b1->N->pT); MTxV(cT, b1->N->pR, U); - cs = s; - - if ((rc = collide_recursive(b1->N, b2, cR, cT, cs)) != RAPID_OK) - return rc; - - MTxM(cR, b1->P->pR, R); - VmV(U, T, b1->P->pT); MTxV(cT, b1->P->pR, U); - cs = s; - - if ((rc = collide_recursive(b1->P, b2, cR, cT, cs)) != RAPID_OK) - return rc; - - return RAPID_OK; - } - else - { - // here we descend to the children of b2. See comments for - // other 'if' clause for explanation. - - MxM(cR, R, b2->N->pR); - sMxVpV(cT, s, R, b2->N->pT, T); - cs = s; - - if ((rc = collide_recursive(b1, b2->N, cR, cT, cs)) != RAPID_OK) - return rc; - - MxM(cR, R, b2->P->pR); - sMxVpV(cT, s, R, b2->P->pT, T); - cs = s; - - if ((rc = collide_recursive(b1, b2->P, cR, cT, cs)) != RAPID_OK) - return rc; - - return RAPID_OK; - } - - } - - return RAPID_OK; -} - -// return TRUE if objects collide -BOOL CollisionCheck(double R1[3][3], double T1[3], CRModel *RAPID_model1, - double R2[3][3], double T2[3], CRModel *RAPID_model2, int flag) -{ - int ret = RAPID_Collide(R1, T1, 1.0, RAPID_model1, R2, T2, 1.0, RAPID_model2, flag); - - return (ret == RAPID_OK) && (RAPID_num_contacts > 0); -} - -static int RAPID_Collide(double R1[3][3], double T1[3], double s1, CRModel *RAPID_model1, - double R2[3][3], double T2[3], double s2, CRModel *RAPID_model2, int flag) -{ - if (!RAPID_initialized) RAPID_initialize(); - - if (RAPID_model1->build_state != RAPID_BUILD_STATE_PROCESSED) - return RAPID_ERR_UNPROCESSED_MODEL; - - if (RAPID_model2->build_state != RAPID_BUILD_STATE_PROCESSED) - return RAPID_ERR_UNPROCESSED_MODEL; - - box *b1 = RAPID_model1->b; - box *b2 = RAPID_model2->b; - - RAPID_first_contact = 0; - if (flag == RAPID_FIRST_CONTACT) RAPID_first_contact = 1; - - double tR1[3][3], tR2[3][3], R[3][3]; - double tT1[3], tT2[3], T[3], U[3]; - double s; - - // [R1,T1,s1] and [R2,T2,s2] are how the two triangle sets - // (i.e. models) are positioned in world space. [tR1,tT1,s1] and - // [tR2,tT2,s2] are how the top level boxes are positioned in world - // space - - MxM(tR1, R1, b1->pR); // tR1 = R1 * b1->pR; - sMxVpV(tT1, s1, R1, b1->pT, T1); // tT1 = s1 * R1 * b1->pT + T1; - MxM(tR2, R2, b2->pR); // tR2 = R2 * b2->pR; - sMxVpV(tT2, s2, R2, b2->pT, T2); // tT2 = s2 * R2 * b2->pT + T2; - - // (R,T,s) is the placement of b2's top level box within - // the coordinate system of b1's top level box. - - MTxM(R, tR1, tR2); // R = tR1.T()*tR2; - VmV(U, tT2, tT1); sMTxV(T, 1.0/s1, tR1, U); // T = tR1.T()*(tT2-tT1)/s1; - - s = s2/s1; - - // To transform tri's from model1's CS to model2's CS use this: - // x2 = ms . mR . x1 + mT - - { - MTxM(RAPID_mR, R2, R1); - VmV(U, T1, T2); sMTxV(RAPID_mT, 1.0/s2, R2, U); - RAPID_ms = s1/s2; - } - - - // reset the report fields - RAPID_num_box_tests = 0; - RAPID_num_tri_tests = 0; - RAPID_num_contacts = 0; - - // make the call - return collide_recursive(b1, b2, R, T, s); -} - -static void RAPID_initialize() -{ - RAPID_num_box_tests = 0; - RAPID_num_contacts = 0; - RAPID_contact = 0; - - RAPID_initialized = TRUE; -} diff --git a/win/rmodel.h b/win/rmodel.h deleted file mode 100644 index c81dcbe5..00000000 --- a/win/rmodel.h +++ /dev/null @@ -1,97 +0,0 @@ -// RModel.h: interface for the CRModel class. -// -////////////////////////////////////////////////////////////////////// - -#if !defined(AFX_RMODEL_H__2071A861_CBE3_11D2_8204_A9244A508F02__INCLUDED_) -#define AFX_RMODEL_H__2071A861_CBE3_11D2_8204_A9244A508F02__INCLUDED_ - -#if _MSC_VER >= 1000 -#pragma once -#endif // _MSC_VER >= 1000 - -/////////////////////////////////////// -// RAPID API RETURN VALUES -#define RAPID_OK 0 -#define RAPID_ERR_MODEL_OUT_OF_MEMORY 1 -#define RAPID_ERR_COLLIDE_OUT_OF_MEMORY 2 -#define RAPID_ERR_UNPROCESSED_MODEL 3 -#define RAPID_ERR_BUILD_OUT_OF_SEQUENCE 4 -#define RAPID_ERR_BUILD_EMPTY_MODEL 5 - -#define RAPID_BUILD_STATE_CONST 0 // "empty" state, after constructor -#define RAPID_BUILD_STATE_BEGIN 1 // after BeginModel() -#define RAPID_BUILD_STATE_ADDTRI 2 // after AddTri() -#define RAPID_BUILD_STATE_PROCESSED 3 // after EndModel() - -// Find all pairwise intersecting triangles -#define RAPID_ALL_CONTACTS 1 -// Just report one intersecting triangle pair, if there are any. -#define RAPID_FIRST_CONTACT 2 - -typedef struct -{ - int id1; - int id2; -} collision_pair; - -typedef struct -{ - int id; - double p1[3], p2[3], p3[3]; -} tri; - -typedef struct box -{ - // placement in parent's space - // box to parent space: x_m = pR*x_b + pT - // parent to box space: x_b = pR.T()*(x_m - pT) - double pR[3][3]; - double pT[3]; - - // dimensions - double d[3]; // this is "radius", that is, half the measure of a side length - - box *P; // points to but does not "own". - box *N; - - tri *trp; - - int leaf() { return (!P && !N); } - double size() { return d[0]; } - - int split_recurse(int *t, int n); - int split_recurse(int *t); // specialized for leaf nodes -} box; - -class CRModel -{ -public: - CRModel(); - ~CRModel(); - - int BeginModel(); - int EndModel(); -// int AddTri(const double *p1, const double *p2, const double *p3, int id); - int AddTri(float *p1, float *p2, float *p3, int id); - -protected: - box *b; - int num_boxes_alloced; - - tri *tris; - int num_tris; - int num_tris_alloced; - - int build_state; - - int build_hierarchy(); - - friend int RAPID_Collide(double R1[3][3], double T1[3], double s1, CRModel *RAPID_model1, - double R2[3][3], double T2[3], double s2, CRModel *RAPID_model2, int flag); -}; - -// The only global function that should be called -BOOL CollisionCheck(double R1[3][3], double T1[3], CRModel *RAPID_model1, - double R2[3][3], double T2[3], CRModel *RAPID_model2, int flag = RAPID_FIRST_CONTACT); - -#endif // !defined(AFX_RMODEL_H__2071A861_CBE3_11D2_8204_A9244A508F02__INCLUDED_)