Order Freeing Memory
This commit is contained in:
parent
3887733e67
commit
2e223e4ae1
7
RubiksCube/.gitignore
vendored
7
RubiksCube/.gitignore
vendored
@ -27,7 +27,6 @@
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
|
||||
@ -50,12 +49,14 @@
|
||||
mono_crash.*
|
||||
|
||||
# Build results
|
||||
|
||||
x64/
|
||||
x86/
|
||||
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
[Ww][Ii][Nn]32/
|
||||
[Aa][Rr][Mm]/
|
||||
[Aa][Rr][Mm]64/
|
||||
|
||||
@ -15,9 +15,10 @@ private:
|
||||
GLFWwindow* _window;
|
||||
InputSystem* _inputSystem;
|
||||
|
||||
glm::mat4 _view;
|
||||
glm::mat4 _projection;
|
||||
|
||||
float _distance;
|
||||
|
||||
glm::quat _orientation;
|
||||
|
||||
glm::vec2 _dragStart;
|
||||
@ -26,12 +27,14 @@ private:
|
||||
float _scrollPositionPrevious;
|
||||
float _scrollPositionDelta;
|
||||
|
||||
glm::mat4 _initialCameraView;
|
||||
|
||||
static inline float cameraDistance = 8.15f;
|
||||
|
||||
static inline Camera* _instance;
|
||||
|
||||
public:
|
||||
const glm::mat4& View() const { return _view * glm::mat4_cast(_orientation); }
|
||||
const glm::mat4& View() const { return LocalToWorld(); }
|
||||
const glm::mat4& Projection() const { return _projection; }
|
||||
|
||||
public:
|
||||
@ -40,9 +43,14 @@ public:
|
||||
_window = window;
|
||||
_inputSystem = inputSystem;
|
||||
|
||||
_distance = 0.0f;
|
||||
|
||||
_wasMouseClicked = false;
|
||||
|
||||
_view = glm::lookAt(glm::vec3(0.0f, 0.0f, cameraDistance), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
_initialCameraView = glm::lookAt(glm::vec3(0.0f, 0.0f, cameraDistance), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
|
||||
SetTransform(_initialCameraView);
|
||||
|
||||
_projection = glm::mat4(1.0f);
|
||||
}
|
||||
|
||||
@ -57,7 +65,7 @@ public:
|
||||
_projection = glm::perspective(glm::radians(45.0f), aspec, 0.1f, 100.0f);
|
||||
|
||||
if (_inputSystem->WasKeyPressed(GLFW_KEY_SPACE))
|
||||
_orientation = glm::quat(1.0f, glm::vec3(0.0f, 0.0f, 0.0f));
|
||||
_orientation = glm::quat(1.0f, glm::vec3(0.0f, 0.0f, 0.0f));
|
||||
|
||||
glm::fvec2 velocity(0.0f, 0.0f);
|
||||
if (_inputSystem->IsKeyPressed(GLFW_KEY_UP))
|
||||
@ -91,9 +99,12 @@ public:
|
||||
_orientation += 0.5f * (float)deltaTime * velocityQuaternion * _orientation;
|
||||
_orientation = glm::normalize(_orientation);
|
||||
|
||||
_view = glm::translate(_view, glm::vec3(0.0f, 0.0f, _scrollPositionDelta));
|
||||
_distance += _scrollPositionDelta;
|
||||
|
||||
_scrollPositionDelta = 0.0f;
|
||||
|
||||
SetTransform(_initialCameraView * glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, _distance)) * glm::mat4_cast(_orientation));
|
||||
|
||||
// since callbacks need to be static use a singleton
|
||||
glfwSetScrollCallback(_window, Camera::scrollCallbackGlobal);
|
||||
}
|
||||
|
||||
@ -42,13 +42,7 @@ Cube::Cube() : Entity(nullptr)
|
||||
}
|
||||
|
||||
Cube::~Cube() {
|
||||
for(int x=0;x<3;x++) {
|
||||
for(int y=0;y<3;y++) {
|
||||
for(int z=0;z<3;z++) {
|
||||
delete _children[x][y][z];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Cube::_FindAxisChildren(const glm::ivec3& axis, int index, std::vector<glm::ivec3>& result) const {
|
||||
|
||||
@ -23,6 +23,9 @@ Entity::Entity(Entity* parent) : _localToWorld(1.0f), _worldToLocal(1.0f)
|
||||
}
|
||||
|
||||
Entity::~Entity() {
|
||||
if (_parent == nullptr)
|
||||
return;
|
||||
|
||||
_parent->RemoveChild(this);
|
||||
}
|
||||
|
||||
|
||||
@ -22,6 +22,7 @@ public:
|
||||
Entity(Entity* parent);
|
||||
virtual ~Entity();
|
||||
|
||||
const std::unordered_set<Entity*>& Children() { return _children; }
|
||||
void AddChild(Entity* entity);
|
||||
void RemoveChild(Entity* entity);
|
||||
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
#include "SceneInterface.h"
|
||||
|
||||
#include "ShaderUtil.h"
|
||||
|
||||
#include "SceneInterface.h"
|
||||
|
||||
#include "PartitionedCube.h"
|
||||
|
||||
#include "Plane.h"
|
||||
@ -9,21 +10,16 @@
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext.hpp>
|
||||
#include <glm/gtx/string_cast.hpp>
|
||||
|
||||
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
SceneInterface::SceneInterface()
|
||||
{
|
||||
SceneInterface::SceneInterface() {
|
||||
|
||||
}
|
||||
|
||||
SceneInterface::~SceneInterface()
|
||||
{
|
||||
SceneInterface::~SceneInterface() {
|
||||
std::reverse(_entities.begin(), _entities.end());
|
||||
|
||||
for(Entity* entity : _entities) {
|
||||
delete entity;
|
||||
}
|
||||
@ -31,8 +27,7 @@ SceneInterface::~SceneInterface()
|
||||
delete currentAction;
|
||||
}
|
||||
|
||||
void SceneInterface::Initialize(GLFWwindow* window)
|
||||
{
|
||||
void SceneInterface::Initialize(GLFWwindow* window) {
|
||||
_inputSystem.SetWindow(window);
|
||||
|
||||
_inputSystem.ObserveKey(GLFW_KEY_SPACE);
|
||||
@ -140,8 +135,7 @@ void SceneInterface::EnqueueAction(Action* action) {
|
||||
_actions.push(action);
|
||||
}
|
||||
|
||||
void SceneInterface::Update(float deltaTime)
|
||||
{
|
||||
void SceneInterface::Update(float deltaTime) {
|
||||
_inputSystem.Update();
|
||||
|
||||
for(Entity* entity : _entities) {
|
||||
@ -296,6 +290,8 @@ void SceneInterface::OnDragStart() {
|
||||
continue;
|
||||
}
|
||||
|
||||
_spinDelta = 0.0f;
|
||||
_spinIndex = -1;
|
||||
_plane = plane;
|
||||
|
||||
_mousePositionPlane = intersectionPlane;
|
||||
@ -361,6 +357,9 @@ void SceneInterface::OnDragStop() {
|
||||
// Undo any temporarilies
|
||||
_cube->UndoTransformTemp();
|
||||
|
||||
if (_spinDelta < 0.001f)
|
||||
return;
|
||||
|
||||
// Transform Instantly to current angle
|
||||
_cube->Transform(_spinAxis, _spinIndex, glm::rotate(glm::mat4(1.0f), _spinDelta, glm::vec3(_spinAxis)));
|
||||
|
||||
@ -406,7 +405,6 @@ void SceneInterface::Render(float aspectRatio) {
|
||||
// std::cout << "model : " << glm::to_string(_cube.Transform()) << std::endl;
|
||||
}
|
||||
|
||||
void SceneInterface::ClearResources()
|
||||
{
|
||||
void SceneInterface::ClearResources() {
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user