From b9c2eec9287c86f53bf03c4c3222b7e5eceadcf6 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Fri, 13 Jan 2023 16:34:40 +0900 Subject: [PATCH] Rename V3, etc. to A3F, etc. --- CMakeLists.txt | 8 ++++---- src/3d/a3f.cc | 26 ++++++++++++++++++++++++++ src/3d/a3f.h | 22 ++++++++++++++++++++++ src/3d/a3f_conv.cc | 9 +++++++++ src/3d/a3f_conv.h | 15 +++++++++++++++ src/3d/obj.cc | 14 +++++++------- src/3d/obj.h | 18 +++++++++--------- src/3d/qm.cc | 6 +++--- src/3d/v3.cc | 22 ---------------------- src/3d/v3.h | 22 ---------------------- src/3d/v3_conv.cc | 9 --------- src/3d/v3_conv.h | 15 --------------- wasm_build/Makefile | 8 ++++---- 13 files changed, 99 insertions(+), 95 deletions(-) create mode 100644 src/3d/a3f.cc create mode 100644 src/3d/a3f.h create mode 100644 src/3d/a3f_conv.cc create mode 100644 src/3d/a3f_conv.h delete mode 100644 src/3d/v3.cc delete mode 100644 src/3d/v3.h delete mode 100644 src/3d/v3_conv.cc delete mode 100644 src/3d/v3_conv.h diff --git a/CMakeLists.txt b/CMakeLists.txt index dcae071..09f62ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,8 +22,8 @@ set(RPSDuelNative_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/3d_renderer.cc" "${CMAKE_CURRENT_SOURCE_DIR}/src/constants.cc" "${CMAKE_CURRENT_SOURCE_DIR}/src/3d/obj.cc" - "${CMAKE_CURRENT_SOURCE_DIR}/src/3d/v3.cc" - "${CMAKE_CURRENT_SOURCE_DIR}/src/3d/v3_conv.cc" + "${CMAKE_CURRENT_SOURCE_DIR}/src/3d/a3f.cc" + "${CMAKE_CURRENT_SOURCE_DIR}/src/3d/a3f_conv.cc" "${CMAKE_CURRENT_SOURCE_DIR}/src/3d/qm.cc" ) @@ -35,8 +35,8 @@ set(RPSDuelNative_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/src/basic_renderer.h" "${CMAKE_CURRENT_SOURCE_DIR}/src/3d_renderer.h" "${CMAKE_CURRENT_SOURCE_DIR}/src/3d/obj.h" - "${CMAKE_CURRENT_SOURCE_DIR}/src/3d/v3.h" - "${CMAKE_CURRENT_SOURCE_DIR}/src/3d/v3_conv.h" + "${CMAKE_CURRENT_SOURCE_DIR}/src/3d/a3f.h" + "${CMAKE_CURRENT_SOURCE_DIR}/src/3d/a3f_conv.h" "${CMAKE_CURRENT_SOURCE_DIR}/src/3d/qm.h" ) diff --git a/src/3d/a3f.cc b/src/3d/a3f.cc new file mode 100644 index 0000000..4d1f3e2 --- /dev/null +++ b/src/3d/a3f.cc @@ -0,0 +1,26 @@ +#include "a3f.h" + +A3F operator+(const A3F &a, const A3F &b) { + return A3F{a[0] + b[0], a[1] + b[1], a[2] + b[2]}; +} + +A3F operator-(const A3F &a, const A3F &b) { + return A3F{a[0] - b[0], a[1] - b[1], a[2] - b[2]}; +} + +A3F operator*(const A3F &v, float s) { + return A3F{v[0] * s, v[1] * s, v[2] * s}; +} + +A3F operator/(const A3F &v, float s) { + return A3F{v[0] / s, v[1] / s, v[2] / s}; +} + +float A3F_F::dotp(const A3F &a, const A3F &b) { + return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; +} + +A3F A3F_F::crossp(const A3F &a, const A3F &b) { + return A3F{a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], + a[0] * b[1] - a[1] * b[0]}; +} diff --git a/src/3d/a3f.h b/src/3d/a3f.h new file mode 100644 index 0000000..219b05f --- /dev/null +++ b/src/3d/a3f.h @@ -0,0 +1,22 @@ +#ifndef ROCK_PAPER_SCISSORS_3D_ARRAY3F_H_ +#define ROCK_PAPER_SCISSORS_3D_ARRAY3F_H_ + +#include + +using A3F = std::array; + +A3F operator+(const A3F &a, const A3F &b); +A3F operator-(const A3F &a, const A3F &b); + +A3F operator*(const A3F &v, float s); +A3F operator/(const A3F &v, float s); + +using A3C = std::array; +using A4C = std::array; + +namespace A3F_F { +extern float dotp(const A3F &a, const A3F &b); +extern A3F crossp(const A3F &a, const A3F &b); +} // namespace A3F_F + +#endif diff --git a/src/3d/a3f_conv.cc b/src/3d/a3f_conv.cc new file mode 100644 index 0000000..cdebf19 --- /dev/null +++ b/src/3d/a3f_conv.cc @@ -0,0 +1,9 @@ +#include "a3f_conv.h" + +Vector3 A3FToRV3(const A3F &v) { return Vector3{v[0], v[1], v[2]}; } + +A3F RV3ToA3F(const Vector3 &v) { return A3F{v.x, v.y, v.z}; } + +Color A4CToC(const A4C &v) { return Color{v[0], v[1], v[2], v[3]}; } + +A4C CToA4C(const Color &c) { return A4C{c.r, c.g, c.b, c.a}; } diff --git a/src/3d/a3f_conv.h b/src/3d/a3f_conv.h new file mode 100644 index 0000000..597afdb --- /dev/null +++ b/src/3d/a3f_conv.h @@ -0,0 +1,15 @@ +#ifndef ROCK_PAPER_SCISSORS_3D_A3F_CONV_H_ +#define ROCK_PAPER_SCISSORS_3D_A3F_CONV_H_ + +#include "a3f.h" + +// third party includes +#include + +extern Vector3 A3FToRV3(const A3F &v); +extern A3F RV3ToA3F(const Vector3 &v); + +extern Color A4CToC(const A4C &v); +extern A4C CToA4C(const Color &c); + +#endif diff --git a/src/3d/obj.cc b/src/3d/obj.cc index bd8d6fa..7ebaf1e 100644 --- a/src/3d/obj.cc +++ b/src/3d/obj.cc @@ -19,11 +19,11 @@ void Object3D::set_model(Model *model) { } } -const V3 &Object3D::get_pos() const { return pos; } +const A3F &Object3D::get_pos() const { return pos; } -void Object3D::set_pos(const V3 &pos) { this->pos = pos; } +void Object3D::set_pos(const A3F &pos) { this->pos = pos; } -void Object3D::set_pos(V3 &&pos) { this->pos = std::forward(pos); } +void Object3D::set_pos(A3F &&pos) { this->pos = std::forward(pos); } void Object3D::set_pos_x(float x) { pos[0] = x; } @@ -31,12 +31,12 @@ void Object3D::set_pos_y(float y) { pos[1] = y; } void Object3D::set_pos_z(float z) { pos[2] = z; } -const VC4 &Object3D::get_color() const { return color; } +const A4C &Object3D::get_color() const { return color; } -void Object3D::set_color(const VC4 &color) { this->color = color; } +void Object3D::set_color(const A4C &color) { this->color = color; } -void Object3D::set_color(VC4 &&color) { - this->color = std::forward(color); +void Object3D::set_color(A4C &&color) { + this->color = std::forward(color); } void Object3D::set_color_r(unsigned char r) { color[0] = r; } diff --git a/src/3d/obj.h b/src/3d/obj.h index 5c41956..e6f5f97 100644 --- a/src/3d/obj.h +++ b/src/3d/obj.h @@ -5,7 +5,7 @@ #include // local includes -#include "v3.h" +#include "a3f.h" // forward declarations struct Model; @@ -21,24 +21,24 @@ class Object3D { void set_model(Model *model); - const V3 &get_pos() const; - void set_pos(const V3 &pos); - void set_pos(V3 &&pos); + const A3F &get_pos() const; + void set_pos(const A3F &pos); + void set_pos(A3F &&pos); void set_pos_x(float x); void set_pos_y(float y); void set_pos_z(float z); - const VC4 &get_color() const; - void set_color(const VC4 &color); - void set_color(VC4 &&color); + const A4C &get_color() const; + void set_color(const A4C &color); + void set_color(A4C &&color); void set_color_r(unsigned char r); void set_color_g(unsigned char g); void set_color_b(unsigned char b); void set_color_a(unsigned char a); protected: - V3 pos; - VC4 color; + A3F pos; + A4C color; std::optional model; }; diff --git a/src/3d/qm.cc b/src/3d/qm.cc index f346a3e..570b544 100644 --- a/src/3d/qm.cc +++ b/src/3d/qm.cc @@ -11,7 +11,7 @@ // local includes #include "../constants.h" -#include "v3_conv.h" +#include "a3f_conv.h" QuestionMark::QuestionMark() : Object3D() @@ -68,7 +68,7 @@ void QuestionMark::draw() { } Vector3 unit{1.0F, 1.0F, 1.0F}; - Vector3 vec3pos = V3ToRV3(pos); + Vector3 vec3pos = A3FToRV3(pos); float angle = angle_timer / angle_timer_max * 2.0F - 1.0F; angle = angle >= 0.0F ? (std::cos(PI_F * angle) * QM_MAX_ANGLE_OFFSET) : (std::cos(PI_F * (-angle)) * QM_MAX_ANGLE_OFFSET); @@ -78,7 +78,7 @@ void QuestionMark::draw() { : ((std::cos(PI_F * (-offset)) + 1.0F) / 2.0F * QM_MAX_Y_OFFSET); vec3pos.y += offset; DrawModelEx(*model.value(), vec3pos, {0.0F, 1.0F, 0.0F}, angle, unit, - VC4ToC(color)); + A4CToC(color)); } void QuestionMark::randomize_timer_values() { diff --git a/src/3d/v3.cc b/src/3d/v3.cc deleted file mode 100644 index fae3d69..0000000 --- a/src/3d/v3.cc +++ /dev/null @@ -1,22 +0,0 @@ -#include "v3.h" - -V3 operator+(const V3 &a, const V3 &b) { - return V3{a[0] + b[0], a[1] + b[1], a[2] + b[2]}; -} - -V3 operator-(const V3 &a, const V3 &b) { - return V3{a[0] - b[0], a[1] - b[1], a[2] - b[2]}; -} - -V3 operator*(const V3 &v, float s) { return V3{v[0] * s, v[1] * s, v[2] * s}; } - -V3 operator/(const V3 &v, float s) { return V3{v[0] / s, v[1] / s, v[2] / s}; } - -float V3F::dotp(const V3 &a, const V3 &b) { - return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; -} - -V3 V3F::crossp(const V3 &a, const V3 &b) { - return V3{a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], - a[0] * b[1] - a[1] * b[0]}; -} diff --git a/src/3d/v3.h b/src/3d/v3.h deleted file mode 100644 index a03d2da..0000000 --- a/src/3d/v3.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef ROCK_PAPER_SCISSORS_3D_V3_H_ -#define ROCK_PAPER_SCISSORS_3D_V3_H_ - -#include - -using V3 = std::array; - -V3 operator+(const V3 &a, const V3 &b); -V3 operator-(const V3 &a, const V3 &b); - -V3 operator*(const V3 &v, float s); -V3 operator/(const V3 &v, float s); - -using VC3 = std::array; -using VC4 = std::array; - -namespace V3F { -extern float dotp(const V3 &a, const V3 &b); -extern V3 crossp(const V3 &a, const V3 &b); -} // namespace V3F - -#endif diff --git a/src/3d/v3_conv.cc b/src/3d/v3_conv.cc deleted file mode 100644 index 6eb61a8..0000000 --- a/src/3d/v3_conv.cc +++ /dev/null @@ -1,9 +0,0 @@ -#include "v3_conv.h" - -Vector3 V3ToRV3(const V3 &v) { return Vector3{v[0], v[1], v[2]}; } - -V3 RV3ToV3(const Vector3 &v) { return V3{v.x, v.y, v.z}; } - -Color VC4ToC(const VC4 &v) { return Color{v[0], v[1], v[2], v[3]}; } - -VC4 CToVC4(const Color &c) { return VC4{c.r, c.g, c.b, c.a}; } diff --git a/src/3d/v3_conv.h b/src/3d/v3_conv.h deleted file mode 100644 index 72443fa..0000000 --- a/src/3d/v3_conv.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef ROCK_PAPER_SCISSORS_3D_V3_CONF_H_ -#define ROCK_PAPER_SCISSORS_3D_V3_CONF_H_ - -#include "v3.h" - -// third party includes -#include - -extern Vector3 V3ToRV3(const V3 &v); -extern V3 RV3ToV3(const Vector3 &v); - -extern Color VC4ToC(const VC4 &v); -extern VC4 CToVC4(const Color &c); - -#endif diff --git a/wasm_build/Makefile b/wasm_build/Makefile index 898a0e2..395b76f 100644 --- a/wasm_build/Makefile +++ b/wasm_build/Makefile @@ -12,8 +12,8 @@ SOURCES = \ ../src/3d_renderer.cc \ ../src/constants.cc \ ../src/3d/obj.cc \ - ../src/3d/v3.cc \ - ../src/3d/v3_conv.cc \ + ../src/3d/a3f.cc \ + ../src/3d/a3f_conv.cc \ ../src/3d/qm.cc HEADERS = \ @@ -24,8 +24,8 @@ HEADERS = \ ../src/game_renderer.h \ ../src/3d_renderer.h \ ../src/3d/obj.h \ - ../src/3d/v3.h \ - ../src/3d/v3_conv.h \ + ../src/3d/a3f.h \ + ../src/3d/a3f_conv.h \ ../src/3d/qm.h CXX = source ${HOME}/git/emsdk/emsdk_env.sh && em++ -- 2.49.0