move curve rendering to the blt::gfx engine
parent
3647c8be48
commit
8638f2f589
|
@ -33,7 +33,7 @@
|
|||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/LINE_BREAK_BEFORE_DEREF_IN_TRAILING_RETURN_TYPES/@EntryValue" value="ON_SINGLE_LINE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/LINE_BREAK_AFTER_DEREF_IN_TRAILING_RETURN_TYPES/@EntryValue" value="ON_SINGLE_LINE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_USER_LINEBREAKS/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BRACED_INIT_LIST_STYLE/@EntryValue" value="CHOP_IF_LONG" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BRACED_INIT_LIST_STYLE/@EntryValue" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_EXISTING_ENUM_ARRANGEMENT/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_CAST_EXPRESSION_PARENTHESES/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/DISABLE_SPACE_CHANGES_BEFORE_TRAILING_COMMENT/@EntryValue" value="true" type="bool" />
|
||||
|
@ -523,8 +523,5 @@
|
|||
<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>
|
|
@ -2,6 +2,21 @@
|
|||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/cmake-build-debug-addrsan/_deps/freetype-src" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/cmake-build-debug-addrsan/_deps/freetype-src/subprojects/dlg" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/cmake-build-debug-addrsan/_deps/imgui-src" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/cmake-build-debug/_deps/freetype-src" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/cmake-build-debug/_deps/freetype-src/subprojects/dlg" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/cmake-build-debug/_deps/imgui-src" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/cmake-build-release/_deps/freetype-src" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/cmake-build-release/_deps/freetype-src/subprojects/dlg" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/cmake-build-release/_deps/imgui-src" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/cmake-build-relwithdebinfo-addrsan/_deps/freetype-src" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/cmake-build-relwithdebinfo-addrsan/_deps/freetype-src/subprojects/dlg" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/cmake-build-relwithdebinfo-addrsan/_deps/imgui-src" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/cmake-build-relwithdebinfo/_deps/freetype-src" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/cmake-build-relwithdebinfo/_deps/freetype-src/subprojects/dlg" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/cmake-build-relwithdebinfo/_deps/imgui-src" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/lib/blt-with-graphics" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/lib/blt-with-graphics/libraries/BLT" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/lib/blt-with-graphics/libraries/BLT/libraries/parallel-hashmap" vcs="Git" />
|
||||
|
|
|
@ -51,7 +51,7 @@ macro(blt_add_project name source type)
|
|||
project(tower-defense)
|
||||
endmacro()
|
||||
|
||||
project(tower-defense VERSION 0.0.17)
|
||||
project(tower-defense VERSION 0.0.18)
|
||||
|
||||
option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF)
|
||||
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)
|
||||
|
|
|
@ -127,7 +127,7 @@ namespace td
|
|||
void add_enemy(enemy_id_t enemy_id, const enemy_t& enemy)
|
||||
{
|
||||
const auto index = static_cast<blt::i32>(enemy_id);
|
||||
if (enemies_registry.size() <= index)
|
||||
if (static_cast<blt::i32>(enemies_registry.size()) <= index)
|
||||
enemies_registry.resize(index + 1, enemy_t{"no_enemy_texture", {}});
|
||||
enemies_registry[index] = enemy;
|
||||
}
|
||||
|
|
|
@ -27,43 +27,6 @@
|
|||
namespace td
|
||||
{
|
||||
|
||||
struct curve_mesh_data_t
|
||||
{
|
||||
struct line_vertex_t
|
||||
{
|
||||
blt::vec3 pos;
|
||||
blt::vec2 uv;
|
||||
};
|
||||
|
||||
[[nodiscard]] std::unique_ptr<blt::gfx::vertex_array_t> to_vertex_array() const;
|
||||
void populate_vertex_array(blt::gfx::vertex_array_t& va) const;
|
||||
|
||||
[[nodiscard]] std::vector<line_vertex_t> calculate_vertices() const;
|
||||
|
||||
curve_mesh_data_t& with(const curve_mesh_data_t& mesh)
|
||||
{
|
||||
lines.insert(lines.end(), mesh.lines.begin(), mesh.lines.end());
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::vector<blt::gfx::line2d_t> lines;
|
||||
};
|
||||
|
||||
class curve_t
|
||||
{
|
||||
public:
|
||||
curve_t(blt::vec2 p0, blt::vec2 p1, blt::vec2 p2);
|
||||
curve_t(blt::vec2 p0, blt::vec2 p1, blt::vec2 p2, blt::vec2 p3);
|
||||
|
||||
[[nodiscard]] blt::vec2 get_point(float t) const;
|
||||
|
||||
[[nodiscard]] std::vector<blt::gfx::line2d_t> to_lines(blt::i32 segments) const;
|
||||
|
||||
[[nodiscard]] curve_mesh_data_t to_mesh(blt::i32 segments) const;
|
||||
private:
|
||||
blt::vec2 m_p0, m_p1, m_p2, m_p3;
|
||||
};
|
||||
|
||||
class path_segment_t
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 8a98d767677d9bdc06889f21aa6c7ffc60a3efb5
|
||||
Subproject commit f60ce3dc0b6528e0fd8ce65eb4def187c8d5834a
|
13
src/main.cpp
13
src/main.cpp
|
@ -13,7 +13,8 @@ blt::gfx::first_person_camera camera;
|
|||
float t = 0;
|
||||
float dir = 1;
|
||||
|
||||
td::curve_t curve{blt::vec2{250, 250}, blt::vec2{400, 500}, blt::vec2{600, 500}, blt::vec2{750, 250}};
|
||||
blt::gfx::curve2d_t curve{blt::vec2{250, 250}, blt::vec2{400, 500}, blt::vec2{600, 500}, blt::vec2{750, 250}};
|
||||
blt::gfx::curve2d_mesh_data_t mesh;
|
||||
|
||||
void init(const blt::gfx::window_data&)
|
||||
{
|
||||
|
@ -28,6 +29,7 @@ void init(const blt::gfx::window_data&)
|
|||
global_matrices.create_internals();
|
||||
resources.load_resources();
|
||||
renderer_2d.create();
|
||||
mesh = curve.to_mesh(32);
|
||||
}
|
||||
|
||||
void update(const blt::gfx::window_data& data)
|
||||
|
@ -50,10 +52,11 @@ void update(const blt::gfx::window_data& data)
|
|||
}
|
||||
|
||||
auto pos = curve.get_point(t);
|
||||
renderer_2d.drawRectangleInternal(blt::make_color(1, 0, 0), blt::gfx::rectangle2d_t{pos, blt::vec2{25, 25}});
|
||||
auto lines = curve.to_lines(32);
|
||||
for (const auto& line : lines)
|
||||
renderer_2d.drawLineInternal(blt::make_color(0, 1,0), line);
|
||||
renderer_2d.drawRectangle(blt::gfx::rectangle2d_t{pos, blt::vec2{25, 25}}, blt::make_color(1, 0, 0));
|
||||
renderer_2d.drawCurve(mesh, blt::make_color(0, 1, 0));
|
||||
// auto lines = curve.to_lines(32);
|
||||
// for (const auto& line : lines)
|
||||
// renderer_2d.drawLineInternal(blt::make_color(0, 1,0), line);
|
||||
|
||||
renderer_2d.render(data.width, data.height);
|
||||
}
|
||||
|
|
52
src/map.cpp
52
src/map.cpp
|
@ -19,57 +19,5 @@
|
|||
|
||||
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(p1), m_p3(p2)
|
||||
{}
|
||||
|
||||
curve_t::curve_t(const blt::vec2 p0, const blt::vec2 p1, const blt::vec2 p2, const blt::vec2 p3): m_p0(p0), m_p1(p1), m_p2(p2), m_p3(p3)
|
||||
{}
|
||||
|
||||
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_inv_cub = t_inv_sq * t_inv;
|
||||
const auto t_sq = t * t;
|
||||
const auto t_cub = t_sq * t;
|
||||
return t_inv_cub * m_p0 + 3 * t_inv_sq * t * m_p1 + 3 * t_inv * t_sq * m_p2 + t_cub * m_p3;
|
||||
}
|
||||
|
||||
std::vector<blt::gfx::line2d_t> curve_t::to_lines(const blt::i32 segments) const
|
||||
{
|
||||
std::vector<blt::gfx::line2d_t> lines;
|
||||
float t = 0;
|
||||
const float diff = 1.0f / static_cast<float>(segments);
|
||||
|
||||
for (blt::i32 i = 0; i < segments; ++i)
|
||||
{
|
||||
auto begin = get_point(t);
|
||||
t += diff;
|
||||
auto end = get_point(t);
|
||||
|
||||
lines.emplace_back(begin, end);
|
||||
}
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
std::unique_ptr<blt::gfx::vertex_array_t> curve_mesh_data_t::to_vertex_array() const
|
||||
{}
|
||||
|
||||
void curve_mesh_data_t::populate_vertex_array(blt::gfx::vertex_array_t& va) const
|
||||
{}
|
||||
|
||||
std::vector<curve_mesh_data_t::line_vertex_t> curve_mesh_data_t::calculate_vertices() const
|
||||
{
|
||||
std::vector<line_vertex_t> vertices;
|
||||
|
||||
return vertices;
|
||||
}
|
||||
|
||||
curve_mesh_data_t curve_t::to_mesh(const blt::i32 segments) const
|
||||
{
|
||||
curve_mesh_data_t mesh_data;
|
||||
mesh_data.lines = to_lines(segments);
|
||||
return mesh_data;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue