pepy/src/Pepy.hpp

106 lines
2.7 KiB
C++

/* Pepy by @ohsqueezy [ohsqueezy.itch.io] */
#ifndef PEPY_H_
#define PEPY_H_
/* GLM */
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/glm.hpp>
#include <glm/gtx/compatibility.hpp>
/* [SPACE BOX] headers */
#include "Game.hpp"
#include "VBO.hpp"
#include "math.hpp"
/* Project headers */
#include "Model.hpp"
class angle_sort
{
glm::vec2 m_origin;
glm::vec2 m_dreference;
// z-coordinate of cross-product, aka determinant
static double xp(glm::vec2 a, glm::vec2 b) { return a.x * b.y - a.y * b.x; }
public:
angle_sort(const glm::vec2 origin, const glm::vec2 reference) : m_origin(origin), m_dreference(reference - origin) {}
bool operator()(const glm::vec2 a, const glm::vec2 b) const
{
const glm::vec2 da = a - m_origin, db = b - m_origin;
const double detb = xp(m_dreference, db);
// nothing is less than zero degrees
if (detb == 0 && db.x * m_dreference.x + db.y * m_dreference.y >= 0) return false;
const double deta = xp(m_dreference, da);
// zero degrees is less than anything else
if (deta == 0 && da.x * m_dreference.x + da.y * m_dreference.y >= 0) return true;
if (deta * detb >= 0) {
// both on same side of reference, compare to each other
return xp(da, db) > 0;
}
// vectors "less than" zero degrees are actually large, near 2 pi
return deta > 0;
}
};
class Pepy : public Game
{
private:
/* Convention for calling parent class in a consistent way across classes */
typedef Game super;
bool shaking = true, flying = false, stopped = false, boom = false, grabbed = false;
sb::VAO cuckoo_vao, wad_vao;
sb::VBO vbo;
GLuint shader;
Model cuckoo;
std::vector<std::pair<Plane, glm::vec2>> wad;
std::map<std::string, GLuint> uniform;
float hue_offset = 0.0f, time_seconds = 0.0f, aspect_ratio = 1.0f, cuckoo_speed = 0.0f,
countdown = configuration()["sim"]["cuckoo-time"];
glm::mat4 orthographic_projection {1};
glm::vec3 cuckoo_offset {0.0f, 0.0f, 0.0f};
glm::vec2 cuckoo_velocity {0.0f, 0.0f};
Plane background;
/*!
* Situate the balls in their starting position. Useful for reseting to initial state.
*/
void situate_balls();
/*!
* Call the Game class's GL load functions then load graphics (vertices, UVs, shaders, buffers, uniforms) into OpenGL.
*/
void load_gl_context();
/*!
* Get current mouse coordinates as NDC.
*
* @return vector of X/Y coordinates of current mouse position
*/
glm::vec2 mouse_ndc();
/*!
* Update state and draw the screen.
*/
void update();
public:
Pepy();
void respond(SDL_Event&);
};
#endif