testing curve

main
Brett 2025-03-18 15:11:00 -04:00
parent 76ba9ff377
commit be5ca99866
5 changed files with 32 additions and 4 deletions

View File

@ -523,5 +523,8 @@
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=StringLiteralTypo/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CommentTypo/@EntryIndexRemoved" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=IdentifierTypo/@EntryIndexRemoved" />
<option name="/Default/CodeStyle/Generate/=CppDefinitions/@KeyIndexDefined" value="true" type="bool" />
<option name="/Default/CodeStyle/Generate/=CppDefinitions/Options/=GenerateInlineDefinitions/@EntryIndexedValue" value="False" type="string" />
<option name="/Default/CodeStyle/Generate/=CppDefinitions/Options/=GenerateInlineDefinitions/@EntryIndexRemoved" />
</component>
</project>

View File

@ -51,7 +51,7 @@ macro(blt_add_project name source type)
project(tower-defense)
endmacro()
project(tower-defense VERSION 0.0.15)
project(tower-defense VERSION 0.0.16)
option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF)
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)

View File

@ -29,9 +29,11 @@ namespace td
class curve_t
{
public:
blt::vec2 get_point(float t) const;
curve_t(blt::vec2 p0, blt::vec2 p1, blt::vec2 p2);
[[nodiscard]] blt::vec2 get_point(float t) const;
private:
blt::vec2 p0, p1, p2;
blt::vec2 m_p0, m_p1, m_p2;
};
class path_segment_t

View File

@ -3,12 +3,18 @@
#include "blt/gfx/renderer/batch_2d_renderer.h"
#include "blt/gfx/renderer/camera.h"
#include "blt/gfx/renderer/resource_manager.h"
#include <map.h>
blt::gfx::matrix_state_manager global_matrices;
blt::gfx::resource_manager resources;
blt::gfx::batch_renderer_2d renderer_2d(resources, global_matrices);
blt::gfx::first_person_camera camera;
float t = 0;
float dir = 1;
td::curve_t curve{blt::vec2{250, 250}, blt::vec2{500, 500}, blt::vec2{750, 250}};
void init(const blt::gfx::window_data&)
{
using namespace blt::gfx;
@ -32,6 +38,20 @@ void update(const blt::gfx::window_data& data)
camera.update_view(global_matrices);
global_matrices.update();
t += 0.01f * dir;
if (t >= 1)
{
t = 1;
dir = -1;
} else if (t <= 0)
{
t = 0;
dir = 1;
}
auto pos = curve.get_point(t);
renderer_2d.drawRectangleInternal(blt::make_color(1, 0, 0), blt::gfx::rectangle2d_t{pos, blt::vec2{25, 25}});
renderer_2d.render(data.width, data.height);
}

View File

@ -19,11 +19,14 @@
namespace td
{
curve_t::curve_t(const blt::vec2 p0, const blt::vec2 p1, const blt::vec2 p2): m_p0(p0), m_p1(p1), m_p2(p2)
{}
blt::vec2 curve_t::get_point(const float t) const
{
const auto t_inv = 1.0f - t;
const auto t_inv_sq = t_inv * t_inv;
const auto t_sq = t * t;
return t_inv_sq * p0 + 2.0f * t_inv * t * p1 + t_sq * p2;
return t_inv_sq * m_p0 + 2.0f * t_inv * t * m_p1 + t_sq * m_p2;
}
}