Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Avoid spawning trucks inside of meshes #752

Merged
merged 1 commit into from
Feb 8, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions source/main/physics/Beam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1092,8 +1092,6 @@ void Beam::resetAngle(float rot)

void Beam::resetPosition(float px, float pz, bool setInitPosition, float miny)
{
int reference_node = setInitPosition ? lowestnode : lowestcontactingnode;

// horizontal displacement
Vector3 offset = Vector3(px, nodes[0].AbsPosition.y, pz) - nodes[0].AbsPosition;
for (int i=0; i<free_node; i++)
Expand All @@ -1102,23 +1100,45 @@ void Beam::resetPosition(float px, float pz, bool setInitPosition, float miny)
}

// vertical displacement
float vertical_offset = -nodes[reference_node].AbsPosition.y + miny;
float vertical_offset = -nodes[lowestcontactingnode].AbsPosition.y + miny;
if (gEnv->terrainManager->getWater())
{
vertical_offset += std::max(0.0f, gEnv->terrainManager->getWater()->getHeight() - (nodes[reference_node].AbsPosition.y + vertical_offset));
vertical_offset += std::max(0.0f, gEnv->terrainManager->getWater()->getHeight() - (nodes[lowestcontactingnode].AbsPosition.y + vertical_offset));
}
for (int i=1; i<free_node; i++)
{
if (nodes[i].contactless) continue;
float terrainHeight = gEnv->terrainManager->getHeightFinder()->getHeightAt(nodes[i].AbsPosition.x, nodes[i].AbsPosition.z);
vertical_offset += std::max(0.0f, terrainHeight - (nodes[i].AbsPosition.y + vertical_offset));
}

for (int i=0; i<free_node; i++)
{
nodes[i].AbsPosition.y += vertical_offset;
}

// mesh displacement
float mesh_offset = 0.0f;
for (int i=0; i<free_node; i++)
{
if (mesh_offset >= 1.0f) break;
if (nodes[i].contactless) continue;
float offset = mesh_offset;
while (offset < 1.0f)
{
Vector3 query = nodes[i].AbsPosition + Vector3(0.0f, offset, 0.0f);
if (!gEnv->collisions->collisionCorrect(&query, false))
{
mesh_offset = offset;
break;
}
offset += 0.001f;
}
}
for (int i=0; i<free_node; i++)
{
nodes[i].AbsPosition.y += mesh_offset;
}

resetPosition(Vector3::ZERO, setInitPosition);
}

Expand Down