📄 hotreadr.cpp
字号:
bead -> beadElement = (void *) poly;
bead -> type = BEAD_TYPE_POLYGON;
InsertPolygon (bead);
// Create another polygon if face is twosided
if (poly -> faceType & FACE_TYPE_TWOSIDED) {
GLbeadTree *bead1 = allocateBead ();
if (bead1) {
GLbeadPolygon *poly1 = allocatePolygon (totalvert);
if (poly1) {
k = totalvert-1;
*poly1 = *poly;
poly1 -> subface = 0; // subface can't use twosided.
for (j=0; j < totalvert; j++) {
poly1 -> vertices[j] = poly -> vertices[k--];
}
if (totalvert > 2) {
poly1 -> vertices[totalvert] = poly1 -> vertices[0]; // close it
CalculatePlane (poly1);
}
bead1 -> beadElement = (void *) poly1;
bead1 -> type = BEAD_TYPE_POLYGON;
InsertPolygon (bead1);
bead -> next = bead1;
}
else {
glReleaseMemory ((char *) bead1);
DisplayErrorMessage ((GLbyte *) "Can not allocate polygon memory for twosided face");
}
}
else {
DisplayErrorMessage ((GLbyte *) "Can not allocate bead memory for twosided face");
}
}
}
break;
case 'Grou': // Group
bead -> type = BEAD_TYPE_GROUP;
break;
case 'Obje': // Object
bead -> type = BEAD_TYPE_OBJECT;
if (!strnicmp ((const char *) beadName, "SLOT", 4)) {
GLint slotindex;
sscanf ((const char *) beadName, "SLOT%d", &slotindex);
if (slotindex < 1) {
DisplayErrorMessage ((GLbyte *) "Wrong Slot index! (Index must be a number from 1 to max)");
return 0;
}
if (slotindex > MAX_SLOT) {
DisplayErrorMessage ((GLbyte *) "Total Slot beads exceed the maximum allowed");
return 0;
}
GLbeadSlot *slotbead = (GLbeadSlot *) glAllocateMemory(sizeof(GLbeadSlot));
if (!slotbead) {
DisplayErrorMessage ((GLbyte *) "Can not allocate bead slot memory");
return 0;
}
if (objData -> TotalObjectSlot < slotindex)
objData -> TotalObjectSlot = slotindex;
slotindex--; // index start from 0
GlobalSlotTable[slotindex] = slotbead;
bead -> beadElement = (void *) slotindex;
bead -> type = BEAD_TYPE_OBJECT_SLOT;
}
break;
case 'BSP\0':
{
in.read ("%s", inString); // "Plane"
GLplane *plane = (GLplane *) glAllocateMemory(sizeof(GLplane));
if (!plane) {
DisplayErrorMessage ((GLbyte *) "Can not allocate BSP memory");
return 0;
}
in.read ("%f", &plane -> a);
in.read ("%f", &plane -> b);
in.read ("%f", &plane -> c);
in.read ("%f", &plane -> d);
bead -> beadElement = (void *) plane;
bead -> type = BEAD_TYPE_BSP;
}
break;
case 'Degr': // DegreeOfFreedom
{
GLint dofindex;
if (!strnicmp ((const char *) beadName, "DOF", 3)) {
sscanf ((const char *) beadName, "DOF%d", &dofindex);
}
else if (!strnicmp ((const char *) beadName, "D", 1)) {
sscanf ((const char *) beadName, "D%d", &dofindex);
}
else {
DisplayErrorMessage ((GLbyte *) "Wrong DOF name! (Must be DOFn where n is number from 1 to max)");
return 0;
}
if (dofindex < 1) {
DisplayErrorMessage ((GLbyte *) "Wrong DOF index! (Index must be a number from 1 to max)");
return 0;
}
if (dofindex > MAX_DEGREE_OF_FREEDOM) {
DisplayErrorMessage ((GLbyte *) "Total DOF beads exceed the maximum allowed");
return 0;
}
GLbeadDegreeOfFreedom *dof = (GLbeadDegreeOfFreedom *)
glAllocateMemory (sizeof (GLbeadDegreeOfFreedom));
if (!dof) {
DisplayErrorMessage ((GLbyte *) "Can not allocate Degree of Freedom memory");
return 0;
}
if (objData -> TotalDOF < dofindex) objData -> TotalDOF = dofindex;
GlobalDOFTable[dofindex] = dof;
dof -> objectMatrix.M11 = dof -> objectMatrix.M22 =
dof -> objectMatrix.M33 = dof -> modelMatrix.M11 =
dof -> modelMatrix.M22 = dof -> modelMatrix.M33 = (GLfloat) 1.0;
dof -> dofIndex = dofindex;
dof -> modelFlag = 0;
GLvertex XAxis, XYPlaneAxis;
XAxis.x = XAxis.y = XAxis.z = 0.0f;
XYPlaneAxis.x = XYPlaneAxis.y = XYPlaneAxis.z = 0.0f;
GLfloat fv;
while (1) {
in.read ("%s", inString);
type = GetStringType ((GLbyte *) inString);
if (type == 'ZZZZ') break;
if (!strcmp (inString, "Origin")) {
in.read ("%f", &dof -> modelOrigin.x);
in.read ("%f", &dof -> modelOrigin.y);
in.read ("%f", &dof -> modelOrigin.z);
}
else if (!strcmp (inString, "Yaw")) {
in.read ("%f", &fv);
in.read ("%f", &fv);
in.read ("%f", &fv);
in.read ("%f", &fv);
}
else if (!strcmp (inString, "Pitch")) {
in.read ("%f", &fv);
in.read ("%f", &fv);
in.read ("%f", &fv);
in.read ("%f", &fv);
}
else if (!strcmp (inString, "Roll")) {
in.read ("%f", &fv);
in.read ("%f", &fv);
in.read ("%f", &fv);
in.read ("%f", &fv);
}
else if (!strcmp (inString, "Scale")) {
in.read ("%f", &fv);
in.read ("%f", &fv);
in.read ("%f", &fv);
in.read ("%f", &fv);
}
else if (!strcmp (inString, "XTranslation")) {
in.read ("%f", &fv);
in.read ("%f", &fv);
in.read ("%f", &fv);
in.read ("%f", &fv);
}
else if (!strcmp (inString, "YTranslation")) {
in.read ("%f", &fv);
in.read ("%f", &fv);
in.read ("%f", &fv);
in.read ("%f", &fv);
}
else if (!strcmp (inString, "ZTranslation")) {
in.read ("%f", &fv);
in.read ("%f", &fv);
in.read ("%f", &fv);
in.read ("%f", &fv);
}
else if (!strcmp (inString, "PointXAxis")) {
in.read ("%f", &XAxis.x);
in.read ("%f", &XAxis.y);
in.read ("%f", &XAxis.z);
}
else if (!strcmp (inString, "PointXYPlane")) {
in.read ("%f", &XYPlaneAxis.x);
in.read ("%f", &XYPlaneAxis.y);
in.read ("%f", &XYPlaneAxis.z);
}
else if (!strcmp (inString, "XAxis")) {
GLvertex XAxis;
in.read ("%f", &XAxis.x);
in.read ("%f", &XAxis.y);
in.read ("%f", &XAxis.z);
}
else if (!strcmp (inString, "YAxis")) {
GLvertex YAxis;
in.read ("%f", &YAxis.x);
in.read ("%f", &YAxis.y);
in.read ("%f", &YAxis.z);
}
else if (!strcmp (inString, "ZAxis")) {
GLvertex ZAxis;
in.read ("%f", &ZAxis.x);
in.read ("%f", &ZAxis.y);
in.read ("%f", &ZAxis.z);
}
else if (!strcmp (inString, "AxisRotation")) {
GLint yaw, pitch, roll;
in.read ("%d", &yaw);
in.read ("%d", &pitch);
in.read ("%d", &roll);
}
}
GLvertex YAxis, ZAxis;
XAxis.x -= dof -> modelOrigin.x;
XAxis.y -= dof -> modelOrigin.y;
XAxis.z -= dof -> modelOrigin.z;
XYPlaneAxis.x -= dof -> modelOrigin.x;
XYPlaneAxis.y -= dof -> modelOrigin.y;
XYPlaneAxis.z -= dof -> modelOrigin.z;
glNormalizedVector (&XAxis);
glNormalizedVector (&XYPlaneAxis);
glCrossProduct (&XAxis, &XYPlaneAxis, &ZAxis);
glNormalizedVector (&ZAxis);
glCrossProduct (&ZAxis, &XAxis, &YAxis);
glNormalizedVector (&YAxis);
dof -> axisMatrix.M11 = ZAxis.z;
dof -> axisMatrix.M12 = ZAxis.x;
dof -> axisMatrix.M13 = ZAxis.y;
dof -> axisMatrix.M21 = XAxis.z;
dof -> axisMatrix.M22 = XAxis.x;
dof -> axisMatrix.M23 = XAxis.y;
dof -> axisMatrix.M31 = YAxis.z;
dof -> axisMatrix.M32 = YAxis.x;
dof -> axisMatrix.M33 = YAxis.y;
if (!( dof -> axisMatrix.M11 == 1.0f &&
dof -> axisMatrix.M12 == 0.0f &&
dof -> axisMatrix.M13 == 0.0f &&
dof -> axisMatrix.M21 == 0.0f &&
dof -> axisMatrix.M22 == 1.0f &&
dof -> axisMatrix.M23 == 0.0f &&
dof -> axisMatrix.M31 == 0.0f &&
dof -> axisMatrix.M32 == 0.0f &&
dof -> axisMatrix.M33 == 1.0f))
dof -> modelFlag |= DOF_ROTATE_AXIS;
bead -> beadElement = (void *) dofindex;
bead -> type = BEAD_TYPE_DOF;
}
break;
case 'Swit': // Switch
{
if (strnicmp ((const char *) beadName, "SW", 2)) {
DisplayErrorMessage ((GLbyte *) "Wrong Switch name! (Must be SWn where n is number from 1 to max)");
return 0;
}
GLint swindex;
sscanf ((const char *) beadName, "SW%d", &swindex);
if (swindex < 1) {
DisplayErrorMessage ((GLbyte *) "Wrong Switch index! (Index must be a number from 1 to max)");
return 0;
}
if (swindex >= 10000) {
// if swindex >= 10000 --> special flag to indicate that this switch will be
// renamed. Format: 1XX## where ## is sequential number and XX is the new index
// It was done this way because we can not specify the same sw index in gamegen
swindex -= 10000;
swindex /= 100;
}
if (swindex > MAX_SWITCH) {
DisplayErrorMessage ((GLbyte *) "Total switch exceed maximum allowed!");
return 0;
}
in.read ("%s", inString); // "TotalMask"
in.read ("%s", inString);
in.read ("%s", inString); // "MaskValue"
in.read ("%s", inString);
if (objData -> TotalSwitch < swindex) objData -> TotalSwitch = swindex;
swindex--; // index start from 0
GlobalSwitchTable[swindex] =
glConvertHexStringToInt ((GLbyte *) inString);
bead -> beadElement = (void *) swindex;
bead -> type = BEAD_TYPE_SWITCH;
}
break;
case 'Box\0': // Bounding Box
{
GLbeadBoundingBox *bound = (GLbeadBoundingBox *)
glAllocateMemory (sizeof (GLbeadBoundingBox));
if (!bound) {
DisplayErrorMessage ((GLbyte *) "Can not allocate Bounding Box memory");
return 0;
}
in.read ("%s", inString); // "Minimum"
in.read ("%f", &bound -> min.x);
in.read ("%f", &bound -> min.y);
in.read ("%f", &bound -> min.z);
in.read ("%s", inString); // "Maximum"
in.read ("%f", &bound -> max.x);
in.read ("%f", &bound -> max.y);
in.read ("%f", &bound -> max.z);
bead -> beadElement = (void *) bound;
bead -> type = BEAD_TYPE_BOUNDING_BOX;
if (objData -> objectRadius == (GLfloat) 0.0) {
objData -> objectMax = bound -> max;
objData -> objectMin = bound -> min;
objData -> objectRadius = CalculateRadius (&bound -> max, &bound -> min);
}
}
break;
case 'Sphe': // BoundingSphere
{
GLbeadBoundingSphere *bound = (GLbeadBoundingSphere *)
glAllocateMemory (sizeof (GLbeadBoundingSphere));
if (!bound) {
DisplayErrorMessage ((GLbyte *) "Can not allocate Bounding Sphere memory");
return 0;
}
in.read ("%s", inString); // "Radius"
in.read ("%f", &bound -> radius);
bead -> beadElement = (void *) bound;
bead -> type = BEAD_TYPE_BOUNDING_SPHERE;
if (objData -> objectRadius == (GLfloat) 0.0) {
objData -> objectMax.x =
objData -> objectMax.y =
objData -> objectMax.z = bound -> radius;
objData -> objectMin.x =
objData -> objectMin.y =
objData -> objectMin.z = -bound -> radius;
objData -> objectRadius = bound -> radius;
}
}
break;
case 'Matr':
{
in.read ("%s", inString); // "Plane"
GLmatrix *mat = (GLmatrix *) glAllocateMemory(sizeof(GLmatrix));
if (!mat) {
DisplayErrorMessage ((GLbyte *) "Can not allocate matrix memory");
return 0;
}
GLfloat f;
in.read ("%f", &mat -> M11);
in.read ("%f", &mat -> M12);
in.read ("%f", &mat -> M13);
in.read ("%f", &f);
in.read ("%f", &mat -> M21);
in.read ("%f", &mat -> M22);
in.read ("%f", &mat -> M23);
in.read ("%f", &f);
in.read ("%f", &mat -> M31);
in.read ("%f", &mat -> M32);
in.read ("%f", &mat -> M33);
in.read ("%f", &f);
in.read ("%f", &f);
in.read ("%f", &f);
in.read ("%f", &f);
in.read ("%f", &f);
bead -> beadElement = (void *) mat;
bead -> type = BEAD_TYPE_MATRIX;
}
break;
}
}
in.movefileptr (filepos);
in.read ("%s", inString);
type = GetStringType ((GLbyte *) inString);
if (type == 'Chil') {
in.read ("%s", inString);
if (*inString != '0') {
int filepos = in.getfileptr ();
pos = findString (inString);
if (parenttype != 'Obje' && parenttype != 'Grou') {
if (pos == -1) {
GlobalErrorFlag |= 1;
return 0;
}
}
if (pos != -1) {
in.movefileptr (pos);
bead -> child = readBeadData ();
in.movefileptr (filepos);
}
}
}
}
GLbeadTree *bead1 = bead;
while (bead1 -> next) bead1 = bead1 -> next;
bead1 -> next = readBeadData ();
return bead;
}
return 0;
}
// return -1 if can not find string, else return file position after string
GLint CHOTReader::findString (char *string)
{
char str[256];
GLint i, j;
GLint filepos = in.getfileptr ();
j = 0;
while (1) {
do {
in.readline (str, 255);
if (in.eof()) {
if (j) {
sprintf (str, "Unexpected end of file! Can not find \'%s\'!", string);
DisplayErrorMessage ((GLbyte *) str);
in.movefileptr (filepos);
return -1;
}
in.movefileptr (); // find from the beginning
i = 0;
j = 1;
}
else i = *((int *) str);
} while (i != '====');
in.read ("%s", str);
if (!strcmp (str, string)) {
i = in.getfileptr ();
in.movefileptr (filepos);
return i;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -