diff --git a/include/fractal.hpp b/include/fractal.hpp index 7659863..21d5318 100644 --- a/include/fractal.hpp +++ b/include/fractal.hpp @@ -9,7 +9,7 @@ #include // TODO: Implement in MTL and create version that doesn't need cos of the angle -mtl::mat<2, 2> create_rotation(mtl::fixed angle_cos); +mtl::mat<2, 2> create_rotation(mtl::fixed angle_cos, mtl::fixed angle_sin); namespace fractal { @@ -36,6 +36,7 @@ enum class token_type_e { struct token_t { token_type_e m_type = token_type_e::empty; mtl::fixed m_value; + mtl::fixed m_value2; uint32_t m_mark; }; @@ -122,7 +123,7 @@ public: * * @exception @c mtl::length_error if the maximum number of tokens is reached */ - token_id_t add_token(token_type_e type, mtl::fixed value = 0, uint32_t mark = 0); + token_id_t add_token(token_type_e type, mtl::fixed value = 0, mtl::fixed value2 = 0, uint32_t mark = 0); /** * @brief Checks if the maximum number of group characteristics has been reached diff --git a/src/fractal.cpp b/src/fractal.cpp index ed8194d..e9eb45b 100644 --- a/src/fractal.cpp +++ b/src/fractal.cpp @@ -11,9 +11,7 @@ using mtl::fixed; using mtl::vec2; using mtl::mat; -mtl::mat<2, 2> create_rotation(mtl::fixed angle_cos) { - fixed angle_sin = fixed(1) - angle_cos * angle_cos; - +mtl::mat<2, 2> create_rotation(mtl::fixed angle_cos, mtl::fixed angle_sin) { return mat<2, 2>({ { angle_cos, -angle_sin }, { angle_sin, angle_cos } @@ -24,12 +22,12 @@ namespace fractal { // ---------- RULESET ---------- -token_id_t ruleset_t::add_token(token_type_e type, mtl::fixed value, uint32_t mark) { +token_id_t ruleset_t::add_token(token_type_e type, mtl::fixed value, mtl::fixed value2, uint32_t mark) { if (m_tokens.full()) { throw mtl::length_error(); } - token_t tok { .m_type = type, .m_value = value, .m_mark = mark}; + token_t tok { .m_type = type, .m_value = value, .m_value2 = value2, .m_mark = mark}; m_tokens.push_back(tok); return m_tokens.size() - 1; diff --git a/src/main.cpp b/src/main.cpp index f1c42fd..92bfabb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,9 +14,15 @@ int main(void) { REG_DISPCNT = DCNT_MODE3 | DCNT_BG2; log::debug << "Hello world!" << mtl::endl; + constexpr float cos_PI_2 = std::cos(M_PI_2); + constexpr float cos_PI_4 = std::cos(M_PI_4); + constexpr float sin_PI_2 = std::sin(M_PI_2); + constexpr float sin_PI_4 = std::sin(M_PI_4); - float cos_PI_2 = std::cos(M_PI_4); fixed cos_PI_2_fx = cos_PI_2; + fixed cos_PI_4_fx = cos_PI_4; + fixed sin_PI_2_fx = sin_PI_2; + fixed sin_PI_4_fx = sin_PI_4; ruleset_t rules; @@ -24,16 +30,16 @@ int main(void) { fixed branch_angle = M_PI_4; token_id_t walk_petal_length = rules.add_token(token_type_e::walk, 8); - token_id_t walk_petal_side = rules.add_token(token_type_e::walk, 4); + token_id_t walk_petal_side = rules.add_token(token_type_e::walk, 2); - token_id_t rotate_axiom = rules.add_token(token_type_e::rotate, cos_PI_2_fx); - token_id_t rotate_petal = rules.add_token(token_type_e::rotate, cos_PI_2_fx); - token_id_t rotate_branchr = rules.add_token(token_type_e::rotate, branch_angle); - token_id_t rotate_branchl = rules.add_token(token_type_e::rotate, branch_angle * -2); + token_id_t rotate_axiom = rules.add_token(token_type_e::rotate, cos_PI_2_fx, sin_PI_2_fx); + token_id_t rotate_petal = rules.add_token(token_type_e::rotate, cos_PI_2_fx, -sin_PI_2_fx); + token_id_t rotate_branchr = rules.add_token(token_type_e::rotate, cos_PI_4_fx, -sin_PI_4_fx); + token_id_t rotate_branchl = rules.add_token(token_type_e::rotate, cos_PI_2_fx, sin_PI_2_fx); token_id_t branch = rules.add_token(token_type_e::empty); token_id_t petal = rules.add_token(token_type_e::empty); - token_id_t mark = rules.add_token(token_type_e::empty, 0, 1); + token_id_t mark = rules.add_token(token_type_e::empty, 0, 0, 1); log::info << "Added tokens" << endl; @@ -45,7 +51,7 @@ int main(void) { etl::vector branch_chr{ petal, rotate_branchr, branch, rotate_branchl, branch }; group_id_t branch_grp = rules.add_group_characteristic(branch_chr); - etl::vector petal_chr{ mark, walk_petal_length, mark, rotate_petal, walk_petal_length, mark }; + etl::vector petal_chr{ mark, walk_petal_length, mark, rotate_petal, walk_petal_side, mark }; group_id_t petal_grp = rules.add_group_characteristic(petal_chr); log::info << "Added group characteristics" << endl;