This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void CQuadTree::Update() | |
{ | |
// Iterate over every object in the tree. | |
// This is why we stored them locally in Insert() | |
for(size_t i = 0; i < mp_allBodies.size(); ++i) | |
{ | |
// Object has moved. | |
if(mp_allBodies[i]->needs_update) | |
{ | |
// Remove the reference to the object from its current node. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CEntity* CQuadTree::RCollides(const CEnity* pBody, | |
const QTNode* pStart) const | |
{ | |
// Is leaf? | |
if(pStart->pChildren == nullptr) | |
{ | |
// Iterate over each object in the node and check for | |
// collision. We also compare the objects to make sure | |
// we don't count a collision of an object with itself, | |
// which would obviously make no sense. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool CQuadTree::RRemove(CEntity* pEnt, QTNode* pStart) | |
{ | |
// Leaf node? | |
if(pStart->pChildren == nullptr) | |
{ | |
// Iterate over the entities and remove a match (if any). | |
for(auto i : pStart->nodeObjects) | |
{ | |
// Is this the object we are looking for? | |
if(*i == pEnt) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The one used by the public, all it does is start | |
// the recursive algorithm with the root. | |
bool CQuadTree::Insert(CEntity* pEnt) | |
{ | |
// If inserted, we want to add to the whole internal list of | |
// objects, which is used later in CQuadTree::Update(). | |
if(this->RInsert(pBody, &m_Root)) | |
{ | |
mp_allBodies.push_back(pBody); | |
return true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void CQuadTree::Split(QTNode* pNode) | |
{ | |
// Children already exist? This shouldn't happen. | |
if(pNode->pChildren != nullptr) | |
{ | |
// Delete the actual nodes. | |
for(size_t i = 0; i < 4; ++i) delete pNode->pChildren[i]; | |
// Then delete the pointer array to the nodes. | |
delete[] pNode->pChildren; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// See this here: https://gist.github.com/Ruskiy69/5257421 | |
#include "gists/QTreeNode.hpp" | |
class CQuadTree | |
{ | |
public: | |
// Provide the starting dimensions to the root node. | |
// This will likely be something like Window::GetWidth() | |
// and Window::GetHeight() in a game. | |
CQuadTree(const uint16_t w, const uint16_t h); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <list> | |
#include <cstdint> | |
// A generic object class (supporting collision) that is within the nodes. | |
// See here: https://github.com/Ruskiy69/IronClad/blob/master/Source/include/Entity/RigidBody.hpp | |
// For a real definition of the objects I use. | |
class CQuadTree; | |
class CEntity; | |
// This is a rectangle representation containing x, y position, and |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void CAnimation::SwapSpriteSheet(const AnimationHeader& Header) | |
{ | |
// New texture for the renderer and new dimensions for the shader. | |
m_Mesh.GetSurfaces()[0]->pMaterial->pTexture = Header.pTexture; | |
m_TexcDim = math::vector2_t(1.f / Header.columns, 1.f / Header.rows); | |
m_SheetDetails = Header; | |
m_loops_done = 0; | |
// Adjust shader for new texture dimensions. | |
gfx::CShaderPair* pShader = m_Mesh.GetSurfaces()[0]->pMaterial->pShader; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool CAnimation::NextSprite() | |
{ | |
// Stay within bounds! | |
if(++m_active >= this->GetAnimationCount()) | |
{ | |
++m_loops_done; | |
m_active = 0; | |
} | |
// Adjust for current texture |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version 330 core | |
uniform sampler2D texture; | |
uniform vec2 tc_offset; | |
uniform vec2 tc_start; | |
smooth in vec2 fs_texc; | |
smooth in vec4 fs_color; | |
out vec4 out_color; |