trackgen: fix object placement
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@9459 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 970011e7a832d86b54411a71d58df5a1fe8c345b Former-commit-id: 206b7456ca56e8332ea46c7ed51a42667dd164fe
This commit is contained in:
parent
61eda576e1
commit
7ee438afe0
3 changed files with 41 additions and 14 deletions
|
@ -1240,6 +1240,17 @@ void Ac3d::Object::generateNormals()
|
|||
}
|
||||
}
|
||||
|
||||
double Ac3d::Object::getTerrainHeight(double x, double y) const
|
||||
{
|
||||
double terrainHeight = -1000000;
|
||||
V3d terrainNormal;
|
||||
|
||||
getTerrainHeight(x, y, terrainHeight, terrainNormal);
|
||||
|
||||
return terrainHeight;
|
||||
|
||||
}
|
||||
|
||||
void Ac3d::Object::getTerrainHeight(double x, double y, double &terrainHeight, V3d &normal) const
|
||||
{
|
||||
if (getBoundingBox().pointInside(x, y))
|
||||
|
@ -1497,12 +1508,17 @@ double Ac3d::getTerrainHeight(double x, double y) const
|
|||
* terrain, with y axis pointing towards uphill
|
||||
*/
|
||||
double Ac3d::getTerrainAngle(double x, double y) const
|
||||
{
|
||||
return root.getTerrainAngle(x, y);
|
||||
}
|
||||
|
||||
double Ac3d::Object::getTerrainAngle(double x, double y) const
|
||||
{
|
||||
double terrainHeight = -1000000;
|
||||
V3d terrainNormal;
|
||||
double angle = 0;
|
||||
|
||||
root.getTerrainHeight(x, y, terrainHeight, terrainNormal);
|
||||
getTerrainHeight(x, y, terrainHeight, terrainNormal);
|
||||
|
||||
if (terrainHeight != -1000000)
|
||||
angle = 180.0 - atan2(terrainNormal[0], terrainNormal[1]) * 180.0 / PI;
|
||||
|
|
|
@ -334,6 +334,8 @@ struct Ac3d
|
|||
void generateTriangles();
|
||||
void generateNormals();
|
||||
void getTerrainHeight(double x, double y, double &terrainHeight, V3d &normal) const;
|
||||
double getTerrainHeight(double x, double y) const;
|
||||
double getTerrainAngle(double x, double y) const;
|
||||
bool pointInside(const Surface &surface, double x, double y, double &z, V3d &normal) const;
|
||||
};
|
||||
|
||||
|
|
|
@ -218,7 +218,7 @@ InitObjects(tTrack *track, void *TrackHandle)
|
|||
}
|
||||
|
||||
void
|
||||
AddObject(tTrack *track, void *trackHandle, const Ac3d &terrainRoot, const Ac3d &trackRoot, Ac3d &objectsRoot, unsigned int clr, tdble x, tdble y, bool multipleMaterials, bool individual)
|
||||
AddObject(tTrack *track, void *trackHandle, const Ac3d::Object *terrainRoot, const Ac3d::Object *trackRoot, Ac3d &objectsRoot, unsigned int clr, tdble x, tdble y, bool multipleMaterials, bool individual)
|
||||
{
|
||||
for (auto &curObj : objects)
|
||||
{
|
||||
|
@ -227,11 +227,12 @@ AddObject(tTrack *track, void *trackHandle, const Ac3d &terrainRoot, const Ac3d
|
|||
Ac3d::Matrix m;
|
||||
tdble dv = 0;
|
||||
tdble angle = 0;
|
||||
float z = 0;
|
||||
double z = 0;
|
||||
tdble orientation = 0;
|
||||
tdble height = 0;
|
||||
double height = 0;
|
||||
std::string name;
|
||||
|
||||
Ac3d::V3d normal;
|
||||
|
||||
if (individual)
|
||||
{
|
||||
orientation = GfParmGetCurNum(trackHandle, TRK_SECT_TERRAIN_OBJECTS, TRK_ATT_ORIENTATION, "deg", 0);
|
||||
|
@ -272,7 +273,7 @@ AddObject(tTrack *track, void *trackHandle, const Ac3d &terrainRoot, const Ac3d
|
|||
|
||||
if (curObj.terrainOriented)
|
||||
{
|
||||
angle = terrainRoot.getTerrainAngle(x, y);
|
||||
angle = terrainRoot->getTerrainAngle(x, y);
|
||||
}
|
||||
|
||||
if (curObj.trackOriented)
|
||||
|
@ -294,10 +295,10 @@ AddObject(tTrack *track, void *trackHandle, const Ac3d &terrainRoot, const Ac3d
|
|||
}
|
||||
else
|
||||
{
|
||||
z = terrainRoot.getTerrainHeight(x, y);
|
||||
z = terrainRoot->getTerrainHeight(x, y);
|
||||
if (z == -1000000.0f)
|
||||
{
|
||||
z = trackRoot.getTerrainHeight(x, y);
|
||||
z = trackRoot->getTerrainHeight(x, y);
|
||||
|
||||
if (z == -1000000.0f)
|
||||
{
|
||||
|
@ -431,35 +432,43 @@ GenerateObjects(tTrack *track, void *TrackHandle, void *CfgHandle, Ac3d &allAc3d
|
|||
std::string inputPath(track->filename);
|
||||
inputPath.resize(inputPath.find_last_of('/'));
|
||||
|
||||
Ac3d TerrainRoot;
|
||||
Ac3d::Object *TerrainRoot;
|
||||
Ac3d Terrain;
|
||||
if (!terrainFile.empty())
|
||||
{
|
||||
try
|
||||
{
|
||||
TerrainRoot.readFile(terrainFile);
|
||||
TerrainRoot.flipAxes(true); // convert to track coordinate system
|
||||
Terrain.readFile(terrainFile);
|
||||
Terrain.flipAxes(true); // convert to track coordinate system
|
||||
}
|
||||
catch (const Ac3d::Exception &e)
|
||||
{
|
||||
GfOut("Reading terrain file %s: %s\n", terrainFile.c_str(), e.what());
|
||||
exit(1);
|
||||
}
|
||||
TerrainRoot = &Terrain.root;
|
||||
}
|
||||
else
|
||||
TerrainRoot = &allAc3d.root.kids.front();
|
||||
|
||||
Ac3d TrackRoot;
|
||||
Ac3d::Object *TrackRoot;
|
||||
Ac3d Track;
|
||||
if (!trackFile.empty())
|
||||
{
|
||||
try
|
||||
{
|
||||
TrackRoot.readFile(trackFile);
|
||||
TrackRoot.flipAxes(true); // convert to track coordinate system
|
||||
Track.readFile(trackFile);
|
||||
Track.flipAxes(true); // convert to track coordinate system
|
||||
}
|
||||
catch (const Ac3d::Exception &e)
|
||||
{
|
||||
GfOut("Reading track file %s: %s\n", trackFile.c_str(), e.what());
|
||||
exit(1);
|
||||
}
|
||||
TrackRoot = &Track.root;
|
||||
}
|
||||
else
|
||||
TrackRoot = &allAc3d.root.kids.back();
|
||||
|
||||
InitObjects(track, TrackHandle);
|
||||
|
||||
|
|
Loading…
Reference in a new issue