diff --git a/src/tools/trackgen/ac3d.cpp b/src/tools/trackgen/ac3d.cpp index 5f0db33a..6340196e 100644 --- a/src/tools/trackgen/ac3d.cpp +++ b/src/tools/trackgen/ac3d.cpp @@ -481,6 +481,75 @@ void Ac3d::Matrix::setRotation(const std::array &rotation) (*this)[2][0] = rotation[6]; (*this)[2][1] = rotation[7]; (*this)[2][2] = rotation[8]; } +const double PI = 3.14159265358979323846; + +void Ac3d::Matrix::setRotation(double x, double y, double z) +{ + double cx, sx, cy, sy, cz, sz, szsy, czsy, szcy; + + if (x == 0) + { + cx = 1; + sx = 0; + } + else + { + const double ax = x * PI / 180.0; + sx = sin(ax); + cx = cos(ax); + } + + if (y == 0) + { + cy = 1; + sy = 0; + } + else + { + const double ay = y * PI / 180.0; + sy = sin(ay); + cy = cos(ay); + } + + if (z == 0) + { + cz = 1; + sz = 0; + szsy = 0; + szcy = 0; + czsy = sy; + } + else + { + const double az = z * PI / 180.0; + sz = sin(az); + cz = cos(az); + szsy = sz * sy; + czsy = cz * sy; + szcy = sz * cy; + } + + (*this)[0][0] = cx * cz - sx * szsy; + (*this)[1][0] = -sx * cy; + (*this)[2][0] = sz * cx + sx * czsy; + (*this)[3][0] = 0; + + (*this)[0][1] = cz * sx + szsy * cx; + (*this)[1][1] = cx * cy; + (*this)[2][1] = sz * sx - czsy * cx; + (*this)[3][1] = 0; + + (*this)[0][2] = -szcy; + (*this)[1][2] = sy; + (*this)[2][2] = cz * cy; + (*this)[3][2] = 0; + + (*this)[0][3] = 0; + (*this)[1][3] = 0; + (*this)[2][3] = 0; + (*this)[3][3] = 1; +} + void Ac3d::Matrix::setScale(double scale) { (*this)[0][0] = scale; @@ -489,6 +558,14 @@ void Ac3d::Matrix::setScale(double scale) (*this)[3][2] = 1; } +void Ac3d::Matrix::setScale(double x, double y, double z) +{ + (*this)[0][0] = x; + (*this)[1][1] = y; + (*this)[2][2] = z; + (*this)[3][2] = 1; +} + void Ac3d::Matrix::makeIdentity() { (*this)[0][0] = 1; (*this)[0][1] = 0; (*this)[0][2] = 0; (*this)[0][3] = 0; @@ -525,6 +602,12 @@ void Ac3d::Matrix::makeRotation(const std::array &rotation) } +void Ac3d::Matrix::makeRotation(double x, double y, double z) +{ + makeIdentity(); + setRotation(x, y, z); +} + void Ac3d::Matrix::makeScale(double scale) { (*this)[0][0] = scale; (*this)[0][1] = 0; (*this)[0][2] = 0; (*this)[0][3] = 0; @@ -533,6 +616,14 @@ void Ac3d::Matrix::makeScale(double scale) (*this)[3][0] = 0; (*this)[3][1] = 0; (*this)[3][2] = 0; (*this)[3][3] = 1; } +void Ac3d::Matrix::makeScale(double x, double y, double z) +{ + (*this)[0][0] = x; (*this)[0][1] = 0; (*this)[0][2] = 0; (*this)[0][3] = 0; + (*this)[1][0] = 0; (*this)[1][1] = y; (*this)[1][2] = 0; (*this)[1][3] = 0; + (*this)[2][0] = 0; (*this)[2][1] = 0; (*this)[2][2] = z; (*this)[2][3] = 0; + (*this)[3][0] = 0; (*this)[3][1] = 0; (*this)[3][2] = 0; (*this)[3][3] = 1; +} + void Ac3d::Matrix::transformPoint(v3d &point) const { v3d dst; diff --git a/src/tools/trackgen/ac3d.h b/src/tools/trackgen/ac3d.h index 09045c5d..ccba12bc 100644 --- a/src/tools/trackgen/ac3d.h +++ b/src/tools/trackgen/ac3d.h @@ -155,12 +155,16 @@ struct Ac3d void setLocation(const v3 &location); void setLocation(double x, double y, double z); void setRotation(const std::array &rotation); + void setRotation(double x, double y, double z); void setScale(double scale); + void setScale(double x, double y, double z); void makeIdentity(); void makeLocation(const v3 &location); void makeLocation(double x, double y, double z); void makeRotation(const std::array &rotation); + void makeRotation(double x, double y, double z); void makeScale(double scale); + void makeScale(double x, double y, double z); void transformPoint(v3d &point) const; void transformNormal(v3d &normal) const; Matrix multiply(const Matrix &matrix); diff --git a/src/tools/trackgen/objects.cpp b/src/tools/trackgen/objects.cpp index ed11c5bf..82e7bead 100644 --- a/src/tools/trackgen/objects.cpp +++ b/src/tools/trackgen/objects.cpp @@ -45,11 +45,11 @@ #include "elevation.h" #include "objects.h" -static float GroupSize; -static float XGroupOffset; -static float YGroupOffset; -static int XGroupNb; -static int ObjUniqId = 0; +static float GroupSize; +static float XGroupOffset; +static float YGroupOffset; +static int XGroupNb; +static int ObjUniqId = 0; struct objdef { @@ -70,15 +70,7 @@ struct objdef std::string fileName; }; -std::vector objects; - -int -GetObjectsNb(void *TrackHandle) -{ - static const char *section = TRK_SECT_TERRAIN "/" TRK_SECT_OBJMAP; - - return GfParmGetEltNb(TrackHandle, section); -} +static std::vector objects; static void ApplyTransform(sgMat4 m, ssgBase *node) diff --git a/src/tools/trackgen/objects.h b/src/tools/trackgen/objects.h index 4e4628ee..1dd098e9 100644 --- a/src/tools/trackgen/objects.h +++ b/src/tools/trackgen/objects.h @@ -27,7 +27,6 @@ #define _OBJECTS_H_ extern void GenerateObjects(tTrack *track, void *TrackHandle, void *CfgHandle, Ac3d &allAc3d, bool all, const std::string &meshFile, const std::string &outputFile); -extern int GetObjectsNb(void *TrackHandle); #endif /* _OBJECTS_H_ */