Skip to content

Commit

Permalink
[Physics] Fixed an issue where the shape had a collision offset of 0.…
Browse files Browse the repository at this point in the history
…5 on the X and Z axis compared to the visual geometry of the terrain (in the forest world)
  • Loading branch information
PanosK92 committed Dec 19, 2023
1 parent 2bf6360 commit 0507c52
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
14 changes: 7 additions & 7 deletions runtime/Rendering/Renderer_Primitives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ namespace Spartan

void Renderer::DrawLine(const Vector3& from, const Vector3& to, const Vector4& color_from, const Vector4& color_to, const float duration /*= 0.0f*/, const bool depth /*= true*/)
{
// Get vertex index.
// get vertex index
uint32_t& index = depth ? m_lines_index_depth_on : m_lines_index_depth_off;

// Grow vertex vector (if needed).
uint32_t vertex_count = static_cast<uint32_t>(m_line_vertices.size());
// grow vertex vector (if needed)
uint32_t vertex_count = static_cast<uint32_t>(m_line_vertices.size());
if (index + 2 >= vertex_count)
{
uint32_t new_vertex_count = vertex_count == 0 ? 32768 : vertex_count * 2;

// If this is not the first allocation, inform the user.
// if this is not the first allocation, inform the user
if (vertex_count != 0)
{
SP_LOG_INFO("Line buffer can hold %d vertices but %d are needed, resizing the buffer to fit %d vertices.", vertex_count, index + 2, new_vertex_count);
}

m_lines_index_depth_off = numeric_limits<uint32_t>::max(); // max because it's incremented below.
m_lines_index_depth_on = (new_vertex_count / 2) - 1; // -1 because it's incremented below.
m_lines_index_depth_off = numeric_limits<uint32_t>::max(); // max because it's incremented below
m_lines_index_depth_on = (new_vertex_count / 2) - 1; // -1 because it's incremented below

m_line_vertices.reserve(new_vertex_count);
m_line_vertices.resize(new_vertex_count);
Expand All @@ -68,7 +68,7 @@ namespace Spartan
m_lines_duration.resize(new_vertex_count);
}

// Write lines.
// write lines
{
index++;
m_line_vertices[index] = RHI_Vertex_PosCol(from, color_from);
Expand Down
5 changes: 3 additions & 2 deletions runtime/World/Components/PhysicsBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -876,10 +876,11 @@ namespace Spartan
m_shape = shape_local;

// calculate the offset needed to re-center the terrain
float offset = (terrain->GetMaxY() + terrain->GetMinY()) / 2.0f;
float offset_xz = -0.5f; // don't know why bullet needs this
float offset_y = (terrain->GetMaxY() + terrain->GetMinY()) / 2.0f;

// set the center of mass to adjust for Bullet's re-centering
SetCenterOfMass(Vector3(0, offset, 0));
SetCenterOfMass(Vector3(offset_xz, offset_y, offset_xz));

break;
}
Expand Down
7 changes: 4 additions & 3 deletions runtime/World/Components/Terrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ namespace Spartan
{
namespace
{
const uint32_t smoothing_iterations = 1; // smooths out the data of the height map by averaging the neighboring pixels

bool generate_height_points_from_height_map(vector<float>& height_data_out, shared_ptr<RHI_Texture> height_texture, float min_y, float max_y)
{
vector<byte> height_data = height_texture->GetMip(0, 0).bytes;
Expand Down Expand Up @@ -75,9 +77,8 @@ namespace Spartan

// smooth out the height map values, this will reduce hard terrain edges
{
const uint32_t smoothing_iterations = 1;
const uint32_t width = height_texture->GetWidth();
const uint32_t height = height_texture->GetHeight();
const uint32_t width = height_texture->GetWidth();
const uint32_t height = height_texture->GetHeight();

for (uint32_t iteration = 0; iteration < smoothing_iterations; iteration++)
{
Expand Down
2 changes: 1 addition & 1 deletion runtime/World/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ namespace Spartan

void World::CreateDefaultWorldForest()
{
Vector3 camera_position = Vector3(-261.7231f, 70.7239f, 436.0732f);
Vector3 camera_position = Vector3(-259.1407f, 71.0f, 432.8229f);
Vector3 camera_rotation = Vector3(0.0f, 144.0f, 0.0f);
create_default_world_common(camera_position, camera_rotation, LightIntensity::sky_sunlight_morning_evening, nullptr, true, false);

Expand Down

0 comments on commit 0507c52

Please sign in to comment.