Skip to content

Commit

Permalink
v2.23
Browse files Browse the repository at this point in the history
  • Loading branch information
OneLoneCoder authored Feb 28, 2023
2 parents 410cae6 + 5228ea6 commit d1da307
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 28 deletions.
37 changes: 20 additions & 17 deletions olcPixelGameEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@
+FillTexturedPolygon() - Hijacks DecalStructure for configuration
+olc::vf2d arguments for Sprite::Sample() functions
2.22: = Fix typo on dragged file buffers for unicode builds
2.23: Fixed Emscripten host sizing errors - Thanks Moros
Fixed v2d_generic.clamp() function
!! Apple Platforms will not see these updates immediately - Sorry, I dont have a mac to test... !!
!! Volunteers willing to help appreciated, though PRs are manually integrated with credit !!
Expand Down Expand Up @@ -395,7 +397,7 @@ int main()
#include <cstring>
#pragma endregion

#define PGE_VER 222
#define PGE_VER 223

// O------------------------------------------------------------------------------O
// | COMPILER CONFIGURATION ODDITIES |
Expand Down Expand Up @@ -683,7 +685,7 @@ namespace olc
v2d_generic min(const v2d_generic& v) const { return v2d_generic(std::min(x, v.x), std::min(y, v.y)); }
v2d_generic cart() { return { std::cos(y) * x, std::sin(y) * x }; }
v2d_generic polar() { return { mag(), std::atan2(y, x) }; }
v2d_generic clamp(const v2d_generic& v1, const v2d_generic& v2) const { return this->max(v1)->min(v2); }
v2d_generic clamp(const v2d_generic& v1, const v2d_generic& v2) const { return this->max(v1).min(v2); }
v2d_generic lerp(const v2d_generic& v1, const double t) { return this->operator*(T(1.0 - t)) + (v1 * T(t)); }
T dot(const v2d_generic& rhs) const { return this->x * rhs.x + this->y * rhs.y; }
T cross(const v2d_generic& rhs) const { return this->x * rhs.y - this->y * rhs.x; }
Expand Down Expand Up @@ -1358,8 +1360,9 @@ namespace olc
#endif

#if defined(OLC_PLATFORM_X11)
namespace X11
{#include <GL/glx.h>}
namespace X11 {
#include <GL/glx.h>
}
#define CALLSTYLE
#endif

Expand Down Expand Up @@ -4595,17 +4598,17 @@ namespace olc
// #include <OpenGL/glu.h>
//#endif

//#if defined(OLC_PLATFORM_EMSCRIPTEN)
// #include <EGL/egl.h>
// #include <GLES2/gl2.h>
// #define GL_GLEXT_PROTOTYPES
// #include <GLES2/gl2ext.h>
// #include <emscripten/emscripten.h>
// #define CALLSTYLE
// typedef EGLBoolean(locSwapInterval_t)(EGLDisplay display, EGLint interval);
// #define GL_CLAMP GL_CLAMP_TO_EDGE
// #define OGL_LOAD(t, n) n;
//#endif
#if defined(OLC_PLATFORM_EMSCRIPTEN)
#include <EGL/egl.h>
#include <GLES2/gl2.h>
#define GL_GLEXT_PROTOTYPES
#include <GLES2/gl2ext.h>
#include <emscripten/emscripten.h>
#define CALLSTYLE
typedef EGLBoolean(locSwapInterval_t)(EGLDisplay display, EGLint interval);
#define GL_CLAMP GL_CLAMP_TO_EDGE
#define OGL_LOAD(t, n) n;
#endif

namespace olc
{
Expand Down Expand Up @@ -6319,8 +6322,8 @@ namespace olc
let isFullscreen = (document.fullscreenElement != null);

// get the width of the containing element
let width = (isFullscreen || !Module.olc_AssumeDefaultShells) ? window.innerWidth : Module.canvas.parentNode.clientWidth;
let height = (isFullscreen || !Module.olc_AssumeDefaultShells) ? window.innerHeight : Module.canvas.parentNode.clientHeight;
let width = (isFullscreen) ? window.innerWidth : Module.canvas.parentNode.clientWidth;
let height = (isFullscreen) ? window.innerHeight : Module.canvas.parentNode.clientHeight;

// calculate the expected viewport size
let viewWidth = width;
Expand Down
39 changes: 28 additions & 11 deletions utilities/olcUTIL_Geometry2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,43 +277,60 @@ namespace olc::utils::geom2d

// Returns closest point to point
template<typename T1, typename T2>
inline olc::v2d_generic<T2> closest(const olc::v2d_generic<T1>& p1, const olc::v2d_generic<T2>& p2)
inline olc::v2d_generic<T1> closest(const olc::v2d_generic<T1>& p1, const olc::v2d_generic<T2>& p2)
{
return p1;
}

// Returns closest point on line to point
template<typename T1, typename T2>
inline olc::v2d_generic<T2> closest(const line<T1>& l, const olc::v2d_generic<T2>& p)
inline olc::v2d_generic<T1> closest(const line<T1>& l, const olc::v2d_generic<T2>& p)
{
auto d = l.vector();
double u = std::clamp(double(d.dot(p - l.start) / d.mag2()), 0.0, 1.0);
return l.start + d * u;
double u = std::clamp(double(d.dot(p - l.start)) / d.mag2(), 0.0, 1.0);
return l.start + u * d;
}

// Returns closest point on circle to point
template<typename T1, typename T2>
inline olc::v2d_generic<T2> closest(const circle<T1>& c, const olc::v2d_generic<T2>& p)
inline olc::v2d_generic<T1> closest(const circle<T1>& c, const olc::v2d_generic<T2>& p)
{
return c.pos + (p - c.pos).norm() * c.radius;
return c.pos + olc::vd2d(p - c.pos).norm() * c.radius;
}

// Returns closest point on rectangle to point
template<typename T1, typename T2>
inline olc::v2d_generic<T2> closest(const rect<T1>& r, const olc::v2d_generic<T2>& p)
inline olc::v2d_generic<T1> closest(const rect<T1>& r, const olc::v2d_generic<T2>& p)
{
// This could be a "constrain" function hmmmm
// TODO: Not quite what i wanted, should restrain to boundary
return olc::v2d_generic<T2>{ std::clamp(p.x, r.pos.x, r.pos.x + r.size.x), std::clamp(p.y, r.pos.y, r.pos.y + r.size.y) };
return olc::v2d_generic<T1>{ std::clamp(p.x, r.pos.x, r.pos.x + r.size.x), std::clamp(p.y, r.pos.y, r.pos.y + r.size.y) };

}

// Returns closest point on triangle to point
template<typename T1, typename T2>
inline olc::v2d_generic<T2> closest(const triangle<T1>& t, const olc::v2d_generic<T2>& p)
inline olc::v2d_generic<T1> closest(const triangle<T1>& t, const olc::v2d_generic<T2>& p)
{
// TODO:
return olc::v2d_generic<T2>();
olc::utils::geom2d::line<T1> l{t.pos[0], t.pos[1]};
auto p0 = closest(l, p);
auto d0 = (p0 - p).mag2();

l.end = t.pos[2];
auto p1 = closest(l, p);
auto d1 = (p1 - p).mag2();

l.start = t.pos[1];
auto p2 = closest(l, p);
auto d2 = (p2 - p).mag2();

if((d0 <= d1) && (d0 <= d2)) {
return p0;
} else if((d1 <= d0) && (d1 <= d2)) {
return p1;
} else {
return p2;
}
}


Expand Down

0 comments on commit d1da307

Please sign in to comment.