68#ifndef OLC_PGEX_WIREFRAME_H
69#define OLC_PGEX_WIREFRAME_H
80 std::array<T, 9>
m{ 0 };
81 constexpr size_t idx(
size_t r,
size_t c)
const {
return r * 3 + c; }
88 void clear() { std::fill(
m.begin(),
m.end(),
T(0)); }
89 void identity() {
clear(); (*this)(0, 0) = 1; (*this)(1, 1) = 1; (*this)(2, 2) = 1; }
93 void scale(
float x,
float y) {
identity();
auto&
m = (*this);
m(0, 0) = x;
m(1, 1) = y; }
94 void scale(
const olc::v2d_generic<T>& v) {
return scale(v.x, v.y); }
95 void rotate(
float a) {
identity();
auto&
m = (*this);
m(0, 0) = cos(a);
m(0, 1) = sin(a);
m(1, 0) = -
m(0, 1);
m(1, 1) =
m(0, 0); }
97 olc::v2d_generic<T>
operator * (
const olc::v2d_generic<T>& v)
const
100 olc::v2d_generic<T> vOut;
101 vOut.x =
m(0, 0) * v.x +
m(1, 0) * v.y +
m(2, 0) *
T(1);
102 vOut.y =
m(0, 1) * v.x +
m(1, 1) * v.y +
m(2, 1) *
T(1);
103 T z =
m(0, 2) * v.x +
m(1, 2) * v.y +
m(2, 2) *
T(1);
111 for (
size_t c = 0; c < 3; c++)
112 for (
size_t r = 0; r < 3; r++)
113 out(r, c) =
m(r, 0) * rhs(0, c) +
m(r, 1) * rhs(1, c) +
m(r, 2) * rhs(2, c);
123 typedef std::vector<olc::vf2d>
Mesh;
162 for (
int i = 0; i < nPoints; i++)
164 float fTheta = (float(i) / float(nPoints)) * 2.0f * 3.14159f;
165 m.push_back(
olc::vf2d{ cos(fTheta), sin(fTheta) } *fRadius);
172 return { -offset, {-offset.x + size.
x, -offset.y}, -offset + size, {-offset.
x, -offset.y + size.y} };
175 inline const Mesh MeshGear(
const int nTeeth,
const float fOuterRadius,
const float fInnerRadius)
178 for (
int i = 0; i < nTeeth * 4; i++)
180 float fTheta = (float(i) / float(nTeeth * 4)) * 2.0f * 3.14159f;
181 m.push_back(
olc::vf2d{ cos(fTheta), sin(fTheta) } * 2.0f * (float((i / 2) % 2) ? fOuterRadius : fInnerRadius));
190 for(
size_t i = 0; i < points.size(); i++)
191 render.DrawLine(points[i], points[(i+1)%points.size()], col);
195 for (
size_t i = 0; i < points.size(); i++)
196 render.FillCircle(points[i], render.ScaleToWorld({ 3,3 }).x,
olc::RED);
216#ifdef OLC_PGEX_WIREFRAME
217#undef OLC_PGEX_WIREFRAME
244 if (child !=
nullptr)
246 child->SetPosition(position);
247 child->SetRotation(angle);
Definition olcPGEX_Wireframe.h:127
olc::Matrix2D matLocalRotation
Definition olcPGEX_Wireframe.h:149
olc::Matrix2D matWorld
Definition olcPGEX_Wireframe.h:151
static constexpr uint8_t DRAW_NODES
Definition olcPGEX_Wireframe.h:130
static constexpr uint8_t DRAW_ORIGIN
Definition olcPGEX_Wireframe.h:129
Mesh vLocalPoints
Definition olcPGEX_Wireframe.h:146
Mesh vWorldPoints
Definition olcPGEX_Wireframe.h:147
void Attach(Model *child, const olc::vf2d &position={ 0.0f, 0.0f }, const float angle=0.0f)
void SetRotation(const float angle)
void SetPosition(const olc::vf2d &position)
olc::Matrix2D matLocalTranslation
Definition olcPGEX_Wireframe.h:148
olc::vf2d LocalToWorld(const olc::vf2d &local)
void UpdateInWorld(const Matrix2D &matParent)
olc::Matrix2D matLocal
Definition olcPGEX_Wireframe.h:150
const Mesh & GetWorldPoints() const
void SetMesh(const Mesh &mesh)
const std::vector< Model * > & GetChildren() const
std::vector< Model * > vChildren
Definition olcPGEX_Wireframe.h:154
static constexpr uint8_t DRAW_MEASURES
Definition olcPGEX_Wireframe.h:131
const Mesh MeshRectangle(const olc::vf2d &size, const olc::vf2d &offset={ 0.0f, 0.0f })
Definition olcPGEX_Wireframe.h:170
std::vector< olc::vf2d > Mesh
Definition olcPGEX_Wireframe.h:123
const Mesh MeshCircle(const float fRadius, const int nPoints=100)
Definition olcPGEX_Wireframe.h:159
void DrawModel(T &render, Model &m, const olc::Pixel col=olc::BLACK, const uint8_t flags=-1)
Definition olcPGEX_Wireframe.h:187
const Mesh MeshGear(const int nTeeth, const float fOuterRadius, const float fInnerRadius)
Definition olcPGEX_Wireframe.h:175
Definition olcPixelGameEngine.h:593
static const Pixel BLACK(0, 0, 0)
@ T
Definition olcPixelGameEngine.h:974
static const Pixel BLUE(0, 0, 255)
static const Pixel RED(255, 0, 0)
mat3_generic< float > Matrix2D
Definition olcPGEX_Wireframe.h:118
Definition olcPixelGameEngine.h:924
Definition olcPGEX_Wireframe.h:79
void translate(float x, float y)
Definition olcPGEX_Wireframe.h:91
const T & operator()(size_t row, size_t col) const
Definition olcPGEX_Wireframe.h:83
std::array< T, 9 > m
Definition olcPGEX_Wireframe.h:80
constexpr size_t idx(size_t r, size_t c) const
Definition olcPGEX_Wireframe.h:81
mat3_generic()
Definition olcPGEX_Wireframe.h:84
void scale(const olc::v2d_generic< T > &v)
Definition olcPGEX_Wireframe.h:94
T & operator()(size_t row, size_t col)
Definition olcPGEX_Wireframe.h:82
olc::v2d_generic< T > operator*(const olc::v2d_generic< T > &v) const
Definition olcPGEX_Wireframe.h:97
void clear()
Definition olcPGEX_Wireframe.h:88
void identity()
Definition olcPGEX_Wireframe.h:89
mat3_generic(const mat3_generic &m)=default
void scale(float x, float y)
Definition olcPGEX_Wireframe.h:93
void translate(const olc::v2d_generic< T > &v)
Definition olcPGEX_Wireframe.h:92
mat3_generic & operator=(const mat3_generic &m)=default
void rotate(float a)
Definition olcPGEX_Wireframe.h:95
T x
Definition olcPixelGameEngine.h:604