00001
00002
00003 #include <windows.h>
00004 #include "bspline.h"
00005 #include "locmath.h"
00006 #include "tll.h"
00007 #include "mmgr.h"
00008
00009 extern int visible;
00010 extern int numSplines;
00011 extern int cameraMode;
00012 extern int currentSpline;
00013 extern int lookAtPath;
00014 extern char* SplineFileName;
00015 extern SPLINE* spline;
00016 extern LinkedList<SPLINE> SplineList;
00017
00018 void AddSpline(int Number)
00019 {
00020 SPLINE* spline2 = new SPLINE;
00021 spline2->Active = 1;
00022 spline2->Repeat = 1;
00023 spline2->Degree = 3;
00024 spline2->NumControl = 7;
00025 spline2->NumPoints = 100;
00026 spline2->Control = new VECTOR[100];
00027 spline2->Output = new VECTOR[1000];
00028 spline2->StartTime = 5000;
00029 spline2->EndTime = 25000;
00030 spline2->CopyOfStartTime = spline2->StartTime;
00031 spline2->CopyOfEndTime = spline2->EndTime;
00032
00033 spline2->Red = ((float)(rand()%226) + 30.0) / 255;
00034 spline2->Green = ((float)(rand()%226) + 30.0) / 255;
00035 spline2->Blue = ((float)(rand()%226) + 30.0) / 255;
00036
00037 for (int loop = 0; loop < 100; loop++)
00038 {
00039 spline2->Control[loop].x = (rand()%60) - 29; spline2->Control[loop].y = (rand()%60) - 29; spline2->Control[loop].z = (rand()%60) - 29;
00040 }
00041
00042 spline2->linkPosition = Number;
00043 SplineList.Insert(spline2);
00044 }
00045
00046 void DeleteSpline(int Number)
00047 {
00048 SplineList.Delete(Number);
00049 }
00050
00051 int LoadSplines(char* SplineFileName)
00052 {
00053 const int stringLength = 33;
00054 char tempString[stringLength];
00055 FILE* SplineFile;
00056 SplineFile = fopen(SplineFileName, "rt");
00057 if (!SplineFile)
00058 {
00059 MessageBox(NULL, "Spline File didn't open", "Error", MB_OK | MB_ICONERROR);
00060 return 0;
00061 }
00062 fseek(SplineFile, 0, SEEK_SET);
00063 int InitialNumSplines = numSplines;
00064 if (!fgets(tempString, stringLength, SplineFile))
00065 {
00066 MessageBox(NULL, "Error reading from the spline data file", "Error", MB_OK | MB_ICONERROR);
00067 numSplines = InitialNumSplines;
00068 return FALSE;
00069 }
00070 numSplines = atoi(tempString);
00071 if (InitialNumSplines > numSplines)
00072 {
00073 for (int loop = InitialNumSplines - 1; loop >= numSplines; loop--)
00074 {
00075 DeleteSpline(loop);
00076 }
00077 }
00078 if (numSplines > InitialNumSplines)
00079 {
00080 for (int loop = InitialNumSplines; loop < numSplines; loop++)
00081 {
00082 AddSpline(loop);
00083 }
00084 }
00085 for (int loop = 0; loop < numSplines; loop++)
00086 {
00087 spline = SplineList.Get(loop);
00088
00089 fgets(tempString, stringLength, SplineFile);
00090 spline->Active = atoi(tempString);
00091
00092 fgets(tempString, stringLength, SplineFile);
00093 spline->Repeat = atoi(tempString);
00094
00095 fgets(tempString, stringLength, SplineFile);
00096 spline->Degree = atoi(tempString);
00097
00098 fgets(tempString, stringLength, SplineFile);
00099 spline->NumControl = atoi(tempString);
00100
00101 fgets(tempString, stringLength, SplineFile);
00102 spline->NumPoints = atoi(tempString);
00103
00104 fgets(tempString, stringLength, SplineFile);
00105 spline->StartTime = atof(tempString);
00106
00107 fgets(tempString, stringLength, SplineFile);
00108 spline->EndTime = atof(tempString);
00109
00110 fgets(tempString, stringLength, SplineFile);
00111 spline->Red = atof(tempString);
00112
00113 fgets(tempString, stringLength, SplineFile);
00114 spline->Green = atof(tempString);
00115
00116 fgets(tempString, stringLength, SplineFile);
00117 spline->Blue = atof(tempString);
00118
00119 for (int loop2 = 0; loop2 <= spline->NumControl; loop2++)
00120 {
00121 fgets(tempString, stringLength, SplineFile);
00122 spline->Control[loop2].x = atof(tempString);
00123 fgets(tempString, stringLength, SplineFile);
00124 spline->Control[loop2].y = atof(tempString);
00125 fgets(tempString, stringLength, SplineFile);
00126 spline->Control[loop2].z = atof(tempString);
00127 }
00128 spline->CopyOfStartTime = spline->StartTime;
00129 spline->CopyOfEndTime = spline->EndTime;
00130 }
00131
00132 currentSpline = numSplines - 1;
00133 if (lookAtPath >= numSplines)
00134 lookAtPath = numSplines - 1;
00135 if (fclose(SplineFile))
00136 MessageBox(NULL, "File didn't close", "Error", MB_OK | MB_ICONERROR);
00137 return 1;
00138 }
00139
00140 void SetSplines()
00141 {
00142 srand((unsigned)time(NULL));
00143
00144 for (int loop = 0; loop < numSplines; loop++)
00145 {
00146 AddSpline(loop);
00147 }
00148
00149 LoadSplines(SplineFileName);
00150 }
00151