Removed ContainerNode and LightNode

This commit is contained in:
Anselme 2018-01-30 17:44:34 +01:00
parent bed507b501
commit 0015acb84c
32 changed files with 289 additions and 334 deletions

View File

@ -23,12 +23,12 @@ Editor::Editor() :
m_selectedMesh(nullptr), m_selectedMesh(nullptr),
m_editedResourcePack(nullptr), m_editedResourcePack(nullptr),
m_objectEditor(nullptr), m_objectEditor(nullptr),
m_pickerEnabled(false),
m_materialEditorEnabled(false), m_materialEditorEnabled(false),
m_editorEnabled(false) m_editorEnabled(false)
{ {
m_objectEditor = new ObjectEditor(); m_objectEditor = new ObjectEditor();
m_children.push_back(m_pickerNode); addChild(m_pickerNode);
m_pickerNode->setEnabled(false);
m_pickerNode->setVisible(false); m_pickerNode->setVisible(false);
} }
@ -39,15 +39,11 @@ Editor::~Editor()
void Editor::update() void Editor::update()
{ {
// no automatic update of children, we want to update them manually SceneNode::update();
// ContainerNode::update();
if(m_editorEnabled) if(m_editorEnabled)
gui(); gui();
if(m_pickerEnabled)
m_pickerNode->update();
if(m_materialEditorEnabled) if(m_materialEditorEnabled)
materialGui(); materialGui();
@ -68,7 +64,7 @@ void Editor::gui()
{ {
ImGui::MenuItem("Material editor", NULL, &m_materialEditorEnabled); ImGui::MenuItem("Material editor", NULL, &m_materialEditorEnabled);
DeferredPipeline* pipeline = dynamic_cast<DeferredPipeline*>(m_scene->getPipeline()); DeferredPipeline* pipeline = dynamic_cast<DeferredPipeline*>(getScene()->getPipeline());
bool pipeline_gui_status = pipeline->isDebugGuiVisible(); bool pipeline_gui_status = pipeline->isDebugGuiVisible();
if(ImGui::MenuItem("Rendering pipeline debug gui", NULL, &pipeline_gui_status)) if(ImGui::MenuItem("Rendering pipeline debug gui", NULL, &pipeline_gui_status))
pipeline->toggleDebugGui(); pipeline->toggleDebugGui();
@ -77,7 +73,7 @@ void Editor::gui()
if(ImGui::MenuItem("Resource pack editor editor", NULL, &resroucePackEditorStatus)) if(ImGui::MenuItem("Resource pack editor editor", NULL, &resroucePackEditorStatus))
toggleResourcePackGui(); toggleResourcePackGui();
bool pickerStatus = m_pickerEnabled; bool pickerStatus = m_pickerNode->isEnabled();
if(ImGui::MenuItem("Picker", NULL, &pickerStatus)) if(ImGui::MenuItem("Picker", NULL, &pickerStatus))
togglePicker(); togglePicker();
@ -97,7 +93,7 @@ void Editor::materialGui()
options += "None\n"; options += "None\n";
meshes.push_back(nullptr); meshes.push_back(nullptr);
int i = 1; int i = 1;
for(SceneIterator<GeometryNode*>* geometryIt = m_scene->getGeometry(); geometryIt->isValid(); geometryIt->next()) for(SceneIterator<GeometryNode*>* geometryIt = getScene()->getGeometry(); geometryIt->isValid(); geometryIt->next())
{ {
options += geometryIt->getItem()->mesh->getName(); options += geometryIt->getItem()->mesh->getName();
options += '\n'; options += '\n';
@ -170,8 +166,9 @@ void Editor::toggleEditor()
void Editor::togglePicker() void Editor::togglePicker()
{ {
m_pickerEnabled = !m_pickerEnabled; bool pickerEnabled = m_pickerNode->isEnabled();
m_pickerNode->setVisible(m_pickerEnabled); m_pickerNode->setEnabled(!pickerEnabled);
m_pickerNode->setVisible(!pickerEnabled);
} }
void Editor::toggleMaterialEditor() void Editor::toggleMaterialEditor()
@ -181,7 +178,7 @@ void Editor::toggleMaterialEditor()
void Editor::toggleRenderingPipelineGui() void Editor::toggleRenderingPipelineGui()
{ {
DeferredPipeline* pipeline = dynamic_cast<DeferredPipeline*>(m_scene->getPipeline()); DeferredPipeline* pipeline = dynamic_cast<DeferredPipeline*>(getScene()->getPipeline());
pipeline->toggleDebugGui(); pipeline->toggleDebugGui();
} }

View File

@ -1,7 +1,7 @@
#ifndef EDITOR_H #ifndef EDITOR_H
#define EDITOR_H #define EDITOR_H
#include "scene/containernode.h" #include "scene/scenenode.h"
class Engine; class Engine;
class ScenePicker; class ScenePicker;
@ -9,13 +9,12 @@ class ResourcePack;
class ObjectEditor; class ObjectEditor;
class Mesh; class Mesh;
class Editor : public ContainerNode class Editor : public SceneNode
{ {
ScenePicker* m_pickerNode; ScenePicker* m_pickerNode;
Mesh* m_selectedMesh; Mesh* m_selectedMesh;
ResourcePack* m_editedResourcePack; ResourcePack* m_editedResourcePack;
ObjectEditor* m_objectEditor; ObjectEditor* m_objectEditor;
bool m_pickerEnabled;
bool m_materialEditorEnabled; bool m_materialEditorEnabled;
bool m_editorEnabled; bool m_editorEnabled;

View File

@ -198,7 +198,7 @@ void Engine::enablePhysicsDebug()
{ {
m_physicsDebugNode = new PhysicsDebugNode(); m_physicsDebugNode = new PhysicsDebugNode();
getScene()->addToIndex(m_physicsDebugNode); getScene()->addToIndex(m_physicsDebugNode);
getScene()->registerMeshType(m_physicsDebugNode->getGeometryNode()->mesh->getFlags()); getScene()->registerMeshType(m_physicsDebugNode->getMesh()->getFlags());
getScene()->getPhysics()->setDebugDrawer(m_physicsDebugNode); getScene()->getPhysics()->setDebugDrawer(m_physicsDebugNode);
getScene()->getPhysics()->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe); getScene()->getPhysics()->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe);
} }

View File

@ -1,12 +1,12 @@
#ifndef KEYMAPPER_H #ifndef KEYMAPPER_H
#define KEYMAPPER_H #define KEYMAPPER_H
#include "scene/containernode.h" #include "scene/scenenode.h"
#include "SparrowInput/keybindings.h" #include "SparrowInput/keybindings.h"
#include <map> #include <map>
#include <set> #include <set>
class KeyMapper : public ContainerNode class KeyMapper : public SceneNode
{ {
bool m_enabled; bool m_enabled;
int m_selected_context; int m_selected_context;

View File

@ -1,73 +0,0 @@
#include "containernode.h"
#include "scenetree.h"
ContainerNode::~ContainerNode()
{
setSceneTree(nullptr);
for(SceneNode* child : m_children)
delete child;
}
void ContainerNode::update()
{
for(SceneNode* node : m_nodesToRemove)
{
for(auto it = m_children.begin(); it != m_children.end();)
{
if(*it == node)
{
it = m_children.erase(it);
node->setSceneTree(nullptr);
node->setParent(nullptr);
}
else
++it;
}
}
m_nodesToRemove.clear();
for(SceneNode* node : m_nodesToAdd)
{
if(m_scene != nullptr)
node->setSceneTree(m_scene);
m_children.push_back(node);
node->setParent(this);
node->setParentTransform(m_transform);
node->setParentVisible(isVisible());
}
m_nodesToAdd.clear();
if(m_transformChanged)
m_combinedTransform = m_transform * m_parentTransform;
for(SceneNode* child : m_children)
{
if(m_transformChanged)
child->setParentTransform(m_combinedTransform);
child->update();
}
}
void ContainerNode::setSceneTree(SceneTree* tree)
{
SceneNode::setSceneTree(tree);
for(SceneNode* child : m_children)
child->setSceneTree(tree);
}
void ContainerNode::addChild(SceneNode *node)
{
if(node != nullptr)
m_nodesToAdd.push_back(node);
}
void ContainerNode::removeChild(SceneNode *node)
{
if(node != nullptr)
m_nodesToRemove.push_back(node);
}
void ContainerNode::updateVisibility(bool visible)
{
for(SceneNode* child : m_children)
child->setParentVisible(visible);
}

View File

@ -1,31 +0,0 @@
#ifndef CONTAINERNODE_H
#define CONTAINERNODE_H
#include "scenenode.h"
#include "glm/vec2.hpp"
#include "glm/mat4x4.hpp"
#include <vector>
class ContainerNode : public SceneNode
{
std::vector<SceneNode*> m_nodesToRemove;
std::vector<SceneNode*> m_nodesToAdd;
protected:
std::vector<SceneNode*> m_children;
glm::mat4 m_combinedTransform;
public:
virtual ~ContainerNode();
virtual void update();
virtual void setSceneTree(SceneTree* tree);
virtual void updateVisibility(bool visible);
void addChild(SceneNode* node);
void removeChild(SceneNode* node);
};
#endif // CONTAINERNODE_H

View File

@ -11,7 +11,7 @@ void GibGeneratorNode::createGib(SceneNode* graphicalPart,
const glm::vec3 &velocity, const glm::vec3 &velocity,
unsigned int lifeSpan) unsigned int lifeSpan)
{ {
if(m_scene != nullptr) if(getScene() != nullptr)
{ {
graphicalPart->moveTo(pos); graphicalPart->moveTo(pos);
@ -23,7 +23,7 @@ void GibGeneratorNode::createGib(SceneNode* graphicalPart,
body->setLinearVelocity(btVector3(velocity.x, velocity.y, velocity.z)); body->setLinearVelocity(btVector3(velocity.x, velocity.y, velocity.z));
body->setUserPointer(graphicalPart); body->setUserPointer(graphicalPart);
getEngine().getScene()->getPhysics()->addRigidBody(body); getScene()->getPhysics()->addRigidBody(body);
m_gibs.push_back(new Gib(body, graphicalPart, getEngine().getTime()+lifeSpan)); m_gibs.push_back(new Gib(body, graphicalPart, getEngine().getTime()+lifeSpan));
addChild(graphicalPart); addChild(graphicalPart);
@ -38,7 +38,7 @@ void GibGeneratorNode::update()
Gib *g = *it; Gib *g = *it;
if(g->expiration < getEngine().getTime()) if(g->expiration < getEngine().getTime())
{ {
getEngine().getScene()->getPhysics()->removeCollisionObject(g->body); getScene()->getPhysics()->removeCollisionObject(g->body);
g->graphics->destroyWhenOrphan(); g->graphics->destroyWhenOrphan();
removeChild(g->graphics); removeChild(g->graphics);
it = m_gibs.erase(it); it = m_gibs.erase(it);
@ -48,5 +48,5 @@ void GibGeneratorNode::update()
++it; ++it;
} }
ContainerNode::update(); SceneNode::update();
} }

View File

@ -1,7 +1,7 @@
#ifndef GIBGENERATORNODE_H #ifndef GIBGENERATORNODE_H
#define GIBGENERATORNODE_H #define GIBGENERATORNODE_H
#include "containernode.h" #include "scenenode.h"
#include <glm/vec3.hpp> #include <glm/vec3.hpp>
#include <BulletDynamics/Dynamics/btRigidBody.h> #include <BulletDynamics/Dynamics/btRigidBody.h>
@ -9,7 +9,7 @@ class btCollisionShape;
class btRigidBody; class btRigidBody;
class SceneNode; class SceneNode;
class GibGeneratorNode : public ContainerNode class GibGeneratorNode : public SceneNode
{ {
struct Gib struct Gib
{ {

View File

@ -25,18 +25,18 @@ BackGroundNode::BackGroundNode(glm::vec2 dimension, glm::vec3 color, float opaci
mesh->setDepth(depth); mesh->setDepth(depth);
mesh->initGL(); mesh->initGL();
m_mesh = new SceneNode(); m_mesh = new SceneNode();
m_mesh->getGeometryNode()->mesh = mesh; m_mesh->setMesh(mesh);
addChild(m_mesh); addChild(m_mesh);
} }
void BackGroundNode::update(){ void BackGroundNode::update(){
if(m_color_updated){ if(m_color_updated){
PBRMaterial* mat = (PBRMaterial*) m_mesh->getGeometryNode()->mesh->getMaterial(); PBRMaterial* mat = (PBRMaterial*) m_mesh->getMesh()->getMaterial();
mat->albedo = m_color; mat->albedo = m_color;
m_color_updated = false; m_color_updated = false;
} }
if(m_opacity_updated){ if(m_opacity_updated){
PBRMaterial* mat = (PBRMaterial*) m_mesh->getGeometryNode()->mesh->getMaterial(); PBRMaterial* mat = (PBRMaterial*) m_mesh->getMesh()->getMaterial();
mat->opacity = m_opacity; mat->opacity = m_opacity;
m_opacity_updated = false; m_opacity_updated = false;
} }

View File

@ -10,9 +10,9 @@ void GUINode::setPosition(glm::vec2 position){
} }
glm::vec2 GUINode::getPosition(){ glm::vec2 GUINode::getPosition(){
return glm::vec2(m_transform[3].x,m_transform[3].y); return glm::vec2(getTransform()[3].x, getTransform()[3].y);
} }
void GUINode::update(){ void GUINode::update(){
ContainerNode::update(); SceneNode::update();
} }

View File

@ -1,9 +1,9 @@
#ifndef GUINODE_H #ifndef GUINODE_H
#define GUINODE_H #define GUINODE_H
#include "scene/containernode.h" #include "scene/scenenode.h"
class GUINode : public ContainerNode class GUINode : public SceneNode
{ {
public: public:
GUINode(); GUINode();

View File

@ -57,7 +57,7 @@ void LabelNode::update(){
Font* font = RESOURCE_GET(Font,"shellfont"); Font* font = RESOURCE_GET(Font,"shellfont");
m_text = font->getTextNode(m_string,m_color,32); m_text = font->getTextNode(m_string,m_color,32);
m_text->setDepth(LABEL_TEXT_DEPTH); m_text->setDepth(LABEL_TEXT_DEPTH);
m_text->getGeometryNode()->mesh->setName("labelText"); m_text->getMesh()->setName("labelText");
addChild(m_text); addChild(m_text);
m_string_updated= false; m_string_updated= false;
m_color_updated=false; m_color_updated=false;
@ -65,7 +65,7 @@ void LabelNode::update(){
} }
if(m_color_updated){ if(m_color_updated){
if(m_text){ if(m_text){
PBRMaterial* mat = (PBRMaterial*) m_text->m_geometry.mesh->getMaterial(); PBRMaterial* mat = (PBRMaterial*) m_text->getMesh()->getMaterial();
mat->albedo = m_color; mat->albedo = m_color;
m_color_updated = false; m_color_updated = false;
} }

View File

@ -27,7 +27,7 @@ ScrollBarNode::ScrollBarNode(glm::vec2 dimension, glm::vec3 bar_color):
mesh->setDepth(SparrowShell::SHELL_DEPTH+1); mesh->setDepth(SparrowShell::SHELL_DEPTH+1);
mesh->initGL(); mesh->initGL();
m_bar = new SceneNode(); m_bar = new SceneNode();
m_bar->getGeometryNode()->mesh = mesh; m_bar->setMesh(mesh);
addChild(m_bar); addChild(m_bar);
} }
@ -62,7 +62,7 @@ void ScrollBarNode::update()
} }
if(m_bar_color_updated) if(m_bar_color_updated)
{ {
PBRMaterial* mat = (PBRMaterial*) m_bar->getGeometryNode()->mesh->getMaterial(); PBRMaterial* mat = (PBRMaterial*) m_bar->getMesh()->getMaterial();
mat->albedo = m_bar_color; mat->albedo = m_bar_color;
m_bar_color_updated = false; m_bar_color_updated = false;
} }

View File

@ -34,7 +34,7 @@ TextInputNode::TextInputNode(glm::vec2 dimension):
mesh->setDepth(30); mesh->setDepth(30);
mesh->initGL(); mesh->initGL();
m_cursor_mesh = new SceneNode(false); m_cursor_mesh = new SceneNode(false);
m_cursor_mesh->getGeometryNode()->mesh = mesh; m_cursor_mesh->setMesh(mesh);
addChild(m_cursor_mesh); addChild(m_cursor_mesh);
} }

View File

@ -1,46 +0,0 @@
#include "lightnode.h"
#include "scenetree.h"
#include <SparrowRenderer/light.h>
#include <glm/mat3x3.hpp>
void LightNode::setSceneTree(SceneTree *tree)
{
SceneNode::setSceneTree(tree);
if(m_scene != nullptr)
m_scene->registerLightType(m_light->getFlags());
}
void LightNode::update()
{
if(m_transformChanged)
{
glm::mat4 combinedTransform(m_parentTransform * m_transform);
switch(m_light->getType())
{
case Light::DIRECTIONNAL :
{
DirectionnalLight *l = (DirectionnalLight*)m_light;
l->setDir(glm::mat3(combinedTransform) * l->getDir());
if(l->isShadowCaster())
l->updateShadowMap(m_scene);
}
break;
case Light::POINT :
{
PointLight *l = (PointLight*)m_light;
l->setPos(l->getPos() + glm::vec3(combinedTransform[3]));
}
break;
case Light::SPOT :
// TODO
break;
case Light::AMBIENT :
default:
break;
}
}
}

View File

@ -1,21 +0,0 @@
#ifndef LIGHTNODE_H
#define LIGHTNODE_H
#include "scenenode.h"
#include "glm/mat4x4.hpp"
#include "SparrowRenderer/scene.h"
class LightNode : public SceneNode
{
Light *m_light;
public:
LightNode(Light* light) : m_light(light) {}
virtual void setSceneTree(SceneTree* tree);
virtual void update();
virtual Light* getLight() { return m_light; }
};
#endif // LIGHTNODE_H

View File

@ -6,39 +6,40 @@
PhysicsDebugNode::PhysicsDebugNode() PhysicsDebugNode::PhysicsDebugNode()
{ {
m_geometry.mesh = new Mesh(); Mesh* mesh = new Mesh();
m_geometry.mesh->setMaterial(new PBRMaterial()); setMesh(mesh);
m_geometry.mesh->setPrimitiveType(GL_LINES); mesh->setMaterial(new PBRMaterial());
m_geometry.mesh->setWireframe(true); mesh->setPrimitiveType(GL_LINES);
mesh->setWireframe(true);
glm::vec3 pos1(0, 1, 0); glm::vec3 pos1(0, 1, 0);
glm::vec3 pos2(0, 0, 0); glm::vec3 pos2(0, 0, 0);
glm::vec3 color(1, 0, 0); glm::vec3 color(1, 0, 0);
m_geometry.mesh->addVertex(pos1, color); mesh->addVertex(pos1, color);
m_geometry.mesh->addVertex(pos2, color); mesh->addVertex(pos2, color);
m_geometry.mesh->updateFlags(); mesh->updateFlags();
} }
PhysicsDebugNode::~PhysicsDebugNode() PhysicsDebugNode::~PhysicsDebugNode()
{ {
delete m_geometry.mesh; delete getMesh();
} }
void PhysicsDebugNode::drawLine(const btVector3& from, const btVector3& to, const btVector3& color) void PhysicsDebugNode::drawLine(const btVector3& from, const btVector3& to, const btVector3& color)
{ {
glm::vec3 glColor(color.x(), color.y(), color.z()); glm::vec3 glColor(color.x(), color.y(), color.z());
m_geometry.mesh->addVertex(glm::vec3(from.x(), from.y(), from.z()), glColor); getMesh()->addVertex(glm::vec3(from.x(), from.y(), from.z()), glColor);
m_geometry.mesh->addVertex(glm::vec3(to.x(), to.y(), to.z()), glColor); getMesh()->addVertex(glm::vec3(to.x(), to.y(), to.z()), glColor);
} }
void PhysicsDebugNode::flushLines() void PhysicsDebugNode::flushLines()
{ {
// a little heavy, but it's a debug mode so it shouldn't be a problem // a little heavy, but it's a debug mode so it shouldn't be a problem
m_geometry.mesh->initGL(); getMesh()->initGL();
} }
void PhysicsDebugNode::clearBuffers() void PhysicsDebugNode::clearBuffers()
{ {
m_geometry.mesh->m_positions3D.clear(); getMesh()->m_positions3D.clear();
m_geometry.mesh->m_normals.clear(); getMesh()->m_normals.clear();
} }

View File

@ -27,7 +27,7 @@ public:
virtual void setDebugMode(int debugMode) { m_debugMode = debugMode; } virtual void setDebugMode(int debugMode) { m_debugMode = debugMode; }
virtual int getDebugMode() const { return m_debugMode; } virtual int getDebugMode() const { return m_debugMode; }
unsigned int getFlags() { m_geometry.mesh->getFlags(); } unsigned int getFlags() { getMesh()->getFlags(); }
void clearBuffers(); void clearBuffers();
}; };

View File

@ -9,7 +9,6 @@
#include "scene/physicsdebugnode.h" #include "scene/physicsdebugnode.h"
#include "scenetree.h" #include "scenetree.h"
#include "lightnode.h"
#include <SFML/System.hpp> #include <SFML/System.hpp>
#include <SFML/Audio.hpp> #include <SFML/Audio.hpp>
@ -309,9 +308,3 @@ void PlayerCharacterNode::toggleNoClip()
m_noclipMode = !m_noclipMode; m_noclipMode = !m_noclipMode;
m_noclip_pos = m_rigidBody->getCenterOfMassPosition(); m_noclip_pos = m_rigidBody->getCenterOfMassPosition();
} }
void PlayerCharacterNode::setSceneTree(SceneTree* tree)
{
m_scene = tree;
// m_playerLightNode->setSceneTree(tree);
}

View File

@ -69,8 +69,6 @@ public:
btRigidBody* getRigidbody() { return m_rigidBody; } btRigidBody* getRigidbody() { return m_rigidBody; }
virtual Camera *getCamera() { return &m_fpsCamera; } virtual Camera *getCamera() { return &m_fpsCamera; }
virtual void setSceneTree(SceneTree* tree);
}; };
#endif // PLAYERCHARACTERNODE_H #endif // PLAYERCHARACTERNODE_H

View File

@ -22,21 +22,102 @@ void SceneNode::setParent(SceneNode* parent)
SceneNode::SceneNode(bool visible) : SceneNode::SceneNode(bool visible) :
m_toDestroy(false), m_toDestroy(false),
m_parentVisible(true),
m_visible(visible),
m_enabled(true),
m_transformChanged(true),
m_parent(nullptr), m_parent(nullptr),
m_scene(nullptr), m_scene(nullptr),
m_geometry(nullptr, glm::mat4()), m_geometry(nullptr, glm::mat4()),
m_transform(m_geometry.modelMatrix), m_light(nullptr),
m_transform(glm::mat4()),
m_rigidBody(nullptr), m_rigidBody(nullptr),
m_parentVisible(true),
m_visible(visible),
m_transformChanged(true),
m_motionState(this) m_motionState(this)
{} {}
SceneNode::~SceneNode()
{
setVisible(false);
setSceneTree(nullptr);
for(SceneNode* child : m_children)
delete child;
}
void SceneNode::updateLightSource()
{
switch(m_light->getType())
{
case Light::DIRECTIONNAL :
{
DirectionnalLight *l = (DirectionnalLight*)m_light;
l->setDir(glm::mat3(m_geometry.modelMatrix) * l->getDir());
if(l->isShadowCaster())
l->updateShadowMap(getScene());
}
break;
case Light::POINT :
{
PointLight *l = (PointLight*)m_light;
l->setPos(l->getPos() + glm::vec3(m_geometry.modelMatrix[3]));
}
break;
case Light::SPOT :
// TODO
break;
case Light::AMBIENT :
default:
break;
}
}
void SceneNode::update() void SceneNode::update()
{ {
if(m_transformChanged) for(SceneNode* node : m_nodesToRemove)
m_geometry.modelMatrix = m_parentTransform * m_transform; {
for(auto it = m_children.begin(); it != m_children.end();)
{
if(*it == node)
{
it = m_children.erase(it);
node->setSceneTree(nullptr);
node->setParent(nullptr);
}
else
++it;
}
}
m_nodesToRemove.clear();
for(SceneNode* node : m_nodesToAdd)
{
if(m_scene != nullptr)
node->setSceneTree(m_scene);
m_children.push_back(node);
node->setParent(this);
node->setParentTransform(m_transform);
node->setParentVisible(isVisible());
}
m_nodesToAdd.clear();
if(m_enabled)
{
if(m_transformChanged)
{
m_geometry.modelMatrix = m_parentTransform * m_transform;
if(m_light != nullptr)
updateLightSource();
}
// TODO : add script execution here
for(SceneNode* child : m_children)
{
if(m_transformChanged)
child->setParentTransform(m_geometry.modelMatrix);
child->update();
}
}
} }
void SceneNode::setSceneTree(SceneTree *tree) void SceneNode::setSceneTree(SceneTree *tree)
@ -51,6 +132,10 @@ void SceneNode::setSceneTree(SceneTree *tree)
m_scene = tree; m_scene = tree;
if(m_scene != nullptr && m_geometry.mesh != nullptr) if(m_scene != nullptr && m_geometry.mesh != nullptr)
m_scene->registerMeshType(m_geometry.mesh->getFlags()); m_scene->registerMeshType(m_geometry.mesh->getFlags());
if(m_scene != nullptr && m_light != nullptr)
m_scene->registerLightType(m_light->getFlags());
for(SceneNode* child : m_children)
child->setSceneTree(tree);
} }
void SceneNode::resetTransform() void SceneNode::resetTransform()
@ -138,14 +223,29 @@ void SceneNode::setParentVisible(bool visible)
m_parentVisible = visible; m_parentVisible = visible;
} }
void SceneNode::addChild(SceneNode *node)
{
if(node != nullptr)
m_nodesToAdd.push_back(node);
}
void SceneNode::removeChild(SceneNode *node)
{
if(node != nullptr)
m_nodesToRemove.push_back(node);
}
void SceneNode::updateVisibility(bool visible) void SceneNode::updateVisibility(bool visible)
{ {
if(!m_scene) for(SceneNode* child : m_children)
return; child->setParentVisible(visible);
if(visible) if(m_scene != nullptr)
m_scene->addToIndex(this); {
else if(visible)
m_scene->removeFromIndex(this); m_scene->addToIndex(this);
else
m_scene->removeFromIndex(this);
}
} }
void SceneNode::SparrowMotionState::getWorldTransform(btTransform& worldTrans ) const void SceneNode::SparrowMotionState::getWorldTransform(btTransform& worldTrans ) const

View File

@ -14,9 +14,6 @@ class btRigidBody;
class SceneNode class SceneNode
{ {
private:
bool m_toDestroy;
public: public:
class SparrowMotionState : public btMotionState class SparrowMotionState : public btMotionState
{ {
@ -32,55 +29,82 @@ public:
virtual void setWorldTransform(const btTransform& worldTrans); virtual void setWorldTransform(const btTransform& worldTrans);
}; };
protected: private:
SceneNode* m_parent; bool m_toDestroy;
SceneTree* m_scene;
/// contains the mesh if this node has one std::vector<SceneNode*> m_nodesToRemove;
GeometryNode m_geometry; std::vector<SceneNode*> m_nodesToAdd;
/// m_parentTransform is the base transform for this element
glm::mat4 m_parentTransform;
/// m_transform is the relative transformation matrix of this node
glm::mat4 m_transform;
/// bullet physics rigidbody
btRigidBody *m_rigidBody;
bool m_parentVisible; bool m_parentVisible;
bool m_visible; bool m_visible;
bool m_enabled;
bool m_transformChanged; bool m_transformChanged;
SceneNode* m_parent;
SceneTree* m_scene;
// contains the mesh if this node has one
GeometryNode m_geometry;
// contains the light source if the node has one
Light* m_light;
// m_transform is the relative transformation matrix of this node
glm::mat4 m_transform;
// m_parentTransform is the base transform for this element
glm::mat4 m_parentTransform;
// bullet physics rigidbody
btRigidBody *m_rigidBody;
// bullet physics handle for our transformation matrix
SparrowMotionState m_motionState; SparrowMotionState m_motionState;
virtual void updateVisibility(bool visible); // node's children
std::vector<SceneNode*> m_children;
Engine& getEngine(); void updateVisibility(bool visible);
void setParent(SceneNode* parent);
void updateLightSource();
public: public:
// constructor/destructor // constructor/destructor
SceneNode(bool visible = true); SceneNode(bool visible = true);
virtual ~SceneNode() { setVisible(false); } virtual ~SceneNode();
// game logic methods // game logic methods
/// @brief update this method is called every tick /// @brief update this method is called every tick by the engine
virtual void update(); virtual void update();
// methods called by the renderer bool isEnabled() { return m_enabled; }
virtual Light* getLight() { return nullptr; } void setEnabled(bool isEnabled) { m_enabled = isEnabled; }
virtual GeometryNode* getGeometryNode() { return &m_geometry; }
// methods called to access the graphic propeties of the node
void setMesh(Mesh* mesh) { m_geometry.mesh = mesh; }
Mesh* getMesh() { return m_geometry.mesh; }
GeometryNode* getGeometryNode() { return &m_geometry; }
void setLight(Light* light) { m_light = light; }
Light* getLight() { return m_light; }
// scene tree structure methods // scene tree structure methods
/// @brief setSceneTree this method can be used to change the scene of the node /// @brief setSceneTree this method can be used to change the scene of the node
virtual void setSceneTree(SceneTree* tree); virtual void setSceneTree(SceneTree* tree);
/// @brief setParent this method can be used to modify the scene tree /// @brief getScene this method returns the scene this node is in
virtual void setParent(SceneNode *parent); SceneTree* getScene() { return m_scene; }
/// @brief addChild this method can be used to add a child to a node
void addChild(SceneNode* node);
/// @brief removeChild this method can be used to remove a child from a node
void removeChild(SceneNode* node);
/// @brief getParent returns the parent of this node, or nullptr if this node is the scene tree root /// @brief getParent returns the parent of this node, or nullptr if this node is the scene tree root
virtual SceneNode* getParent() { return m_parent; } virtual SceneNode* getParent() { return m_parent; }
/// @brief killWhenOrphan this method can be called if you wish to delete this object as soon as it has no parent. /// @brief killWhenOrphan this method can be called if you wish to delete this object as soon as it has no parent.
virtual void destroyWhenOrphan() { m_toDestroy = true; } virtual void destroyWhenOrphan() { m_toDestroy = true; }
/// @brief getChildren returns a vector containing all this node's children
const std::vector<SceneNode*> getChildren() { return m_children; }
// transform methods // transform methods
void setTransform(const Transform& t); void setTransform(const Transform& t);
@ -114,12 +138,14 @@ public:
void setDepth(float depth); void setDepth(float depth);
// physics methods // physics methods
/// @brief getMotionState this is used to synchronize a bullet rigidbody's transform with a GraphicalNode transform /// @brief getMotionState this is used to synchronize a bullet rigidbody's transform with a GraphicalNode transform
SparrowMotionState* getMotionState() { return &m_motionState; } SparrowMotionState* getMotionState() { return &m_motionState; }
/// @brief setRigidBody sets a rigidbody to the node /// @brief setRigidBody sets a rigidbody to the node
void setRigidBody(btRigidBody* body); void setRigidBody(btRigidBody* body);
btRigidBody* getRigidBody() { return m_rigidBody; } btRigidBody* getRigidBody() { return m_rigidBody; }
// global engine methods
Engine& getEngine();
}; };
#endif // SCENENODE_H #endif // SCENENODE_H

View File

@ -5,7 +5,7 @@
#include <string> #include <string>
#include <unordered_set> #include <unordered_set>
#include "SparrowRenderer/scene.h" #include "SparrowRenderer/scene.h"
#include "containernode.h" #include "scenenode.h"
#include "engine.h" #include "engine.h"
class Light; class Light;
@ -32,7 +32,7 @@ public:
void setMainCamera(Camera *camera); void setMainCamera(Camera *camera);
Camera* getCamera() const { return m_camera; } Camera* getCamera() const { return m_camera; }
ContainerNode* getRootObject(){return &m_root;} SceneNode* getRootObject(){return &m_root;}
btDiscreteDynamicsWorld* getPhysics() const {return m_world;} btDiscreteDynamicsWorld* getPhysics() const {return m_world;}
void initPhysics(); void initPhysics();
void registerMeshType(unsigned int meshType); void registerMeshType(unsigned int meshType);
@ -50,7 +50,7 @@ private:
SceneTree(Engine &engine); SceneTree(Engine &engine);
Engine &m_engine; Engine &m_engine;
ContainerNode m_root; SceneNode m_root;
btDiscreteDynamicsWorld* m_world; btDiscreteDynamicsWorld* m_world;
std::vector<Light*> m_lights; std::vector<Light*> m_lights;
std::vector<GeometryNode*> m_geometries; std::vector<GeometryNode*> m_geometries;

View File

@ -17,12 +17,12 @@ private:
friend class LabelNode; friend class LabelNode;
public: public:
TextNode(Mesh* mesh,std::wstring s,float fontSize,bool visible = true) : SceneNode(visible),m_string(s),m_fontSize(fontSize) { m_geometry.mesh = mesh; } TextNode(Mesh* mesh,std::wstring s,float fontSize,bool visible = true) : SceneNode(visible),m_string(s),m_fontSize(fontSize) { setMesh(mesh); }
TextNode(Mesh* mesh,std::string s,float fontSize,bool visible = true) : SceneNode(visible),m_fontSize(fontSize) { TextNode(Mesh* mesh,std::string s,float fontSize,bool visible = true) : SceneNode(visible),m_fontSize(fontSize) {
m_geometry.mesh = mesh; setMesh(mesh);
m_string.assign(s.begin(),s.end()); m_string.assign(s.begin(),s.end());
} }
~TextNode(){delete m_geometry.mesh;} ~TextNode(){delete getMesh();}
void setDimension(glm::vec2 dim){m_dimension = dim;} void setDimension(glm::vec2 dim){m_dimension = dim;}
glm::vec2 getDimension(){return m_dimension;} glm::vec2 getDimension(){return m_dimension;}

View File

@ -39,7 +39,7 @@ ScriptNode::ScriptNode()
void ScriptNode::update(){ void ScriptNode::update(){
static bool test = true; static bool test = true;
if(test && m_scene!= nullptr){ if(test && getScene() != nullptr){
m_script["engine"] = getEngine(); m_script["engine"] = getEngine();
test=false; test=false;
} }

View File

@ -9,7 +9,7 @@ void ShellBuffer::update()
TextNode* tnode; TextNode* tnode;
glm::vec2 text_pos(0,0); glm::vec2 text_pos(0,0);
SparrowShell* shell = dynamic_cast<SparrowShell*>(m_parent); SparrowShell* shell = dynamic_cast<SparrowShell*>(getParent());
if(shell->isEnabled() && m_buffer_modified) if(shell->isEnabled() && m_buffer_modified)
{ {
for(unsigned int i = 0; i< size();i++) for(unsigned int i = 0; i< size();i++)
@ -32,18 +32,19 @@ void ShellBuffer::update()
void ShellBuffer::push(TextNode* tnode){ void ShellBuffer::push(TextNode* tnode){
if(tnode != nullptr) if(tnode != nullptr)
{ {
if(m_scene != nullptr) if(getScene() != nullptr)
tnode->setSceneTree(m_scene); tnode->setSceneTree(getScene());
if (m_children.size() >= m_max_size){ if (m_bufferLines.size() >= m_max_size){
(m_children[m_zero_offset])->setVisible(false); removeChild(m_bufferLines[m_zero_offset]);
m_children[m_zero_offset++] = tnode; m_bufferLines[m_zero_offset++] = tnode;
addChild(tnode);
m_zero_offset %= m_max_size; m_zero_offset %= m_max_size;
}else }else
m_children.push_back(tnode); {
tnode->setParent(this); m_bufferLines.push_back(tnode);
tnode->setParentTransform(m_transform); addChild(tnode);
tnode->setParentVisible(isVisible()); }
m_buffer_modified = true; m_buffer_modified = true;
} }
} }
@ -54,10 +55,9 @@ glm::vec2 ShellBuffer::getDimension(){
} }
void ShellBuffer::clear(){ void ShellBuffer::clear(){
for(auto it = m_children.begin(); it != m_children.end();){ for(auto it = m_bufferLines.begin(); it != m_bufferLines.end();){
TextNode* child = (TextNode*) *it; TextNode* child = (TextNode*) *it;
m_scene->removeFromIndex(child); it = m_bufferLines.erase(it);
it = m_children.erase(it);
delete child; delete child;
} }
m_index = 0; m_index = 0;

View File

@ -12,6 +12,8 @@ private:
float m_font_size; float m_font_size;
unsigned int m_index = 0; unsigned int m_index = 0;
bool m_buffer_modified; bool m_buffer_modified;
std::vector<TextNode*> m_bufferLines;
public: public:
ShellBuffer(int buffer_size): ShellBuffer(int buffer_size):
m_max_size(buffer_size), m_max_size(buffer_size),
@ -22,9 +24,9 @@ public:
setVisible(true); setVisible(true);
moveTo2D(glm::vec2(0)); moveTo2D(glm::vec2(0));
} }
SceneNode* operator[](int i){return m_children[(m_zero_offset+i)%m_max_size];} TextNode* operator[](int i){return m_bufferLines[(m_zero_offset+i)%m_max_size];}
void push(TextNode*); void push(TextNode*);
unsigned int size(){return m_children.size();} unsigned int size(){return m_bufferLines.size();}
void update(); void update();

View File

@ -120,7 +120,7 @@ void SparrowShell::out(std::string str,glm::vec3 color)
TextNode* tnode = shellfont->getTextNode(str,color,m_buffer->getFontSize(),false); TextNode* tnode = shellfont->getTextNode(str,color,m_buffer->getFontSize(),false);
std::string name = "shellTextLine"; std::string name = "shellTextLine";
name += m_buffer->size(); name += m_buffer->size();
tnode->getGeometryNode()->mesh->setName(name); tnode->getMesh()->setName(name);
tnode->setDepth(SHELL_DEPTH+1); tnode->setDepth(SHELL_DEPTH+1);
m_buffer->push(tnode); m_buffer->push(tnode);
scrollDown(); scrollDown();

View File

@ -6,7 +6,7 @@
#include "glm/vec2.hpp" #include "glm/vec2.hpp"
#include "scene/scenetree.h" #include "scene/scenetree.h"
#include "scene/containernode.h" #include "scene/scenenode.h"
#include "scene/gui/guinode.h" #include "scene/gui/guinode.h"
#include "scene/gui/callback.h" #include "scene/gui/callback.h"

View File

@ -14,8 +14,7 @@
#include <scene/scenetree.h> #include <scene/scenetree.h>
#include <scene/textnode.h> #include <scene/textnode.h>
#include <scene/playercharacternode.h> #include <scene/playercharacternode.h>
#include <scene/lightnode.h> #include <scene/scenenode.h>
#include <scene/containernode.h>
#include <tools/graph.h> #include <tools/graph.h>
#include <tools/pathfinder.h> #include <tools/pathfinder.h>
#include <tools/loader.h> #include <tools/loader.h>
@ -84,7 +83,7 @@ public:
void generateTerrain(SceneTree *scene, btDiscreteDynamicsWorld *world) void generateTerrain(SceneTree *scene, btDiscreteDynamicsWorld *world)
{ {
ContainerNode* terrainContainer = new ContainerNode(); SceneNode* terrainContainer = new SceneNode();
scene->getRootObject()->addChild(terrainContainer); scene->getRootObject()->addChild(terrainContainer);
TestGen gen; TestGen gen;
PBRMaterial *mat = new PBRMaterial(); PBRMaterial *mat = new PBRMaterial();
@ -106,7 +105,7 @@ void generateTerrain(SceneTree *scene, btDiscreteDynamicsWorld *world)
chunk->mesh->setMaterial(mat); chunk->mesh->setMaterial(mat);
chunk->mesh->initGL(); chunk->mesh->initGL();
SceneNode *node = new SceneNode(); SceneNode *node = new SceneNode();
node->getGeometryNode()->mesh = chunk->mesh; node->setMesh(chunk->mesh);
node->getGeometryNode()->modelMatrix = glm::translate(glm::scale(glm::mat4(), glm::vec3(2.f)), pos*8.f); node->getGeometryNode()->modelMatrix = glm::translate(glm::scale(glm::mat4(), glm::vec3(2.f)), pos*8.f);
node->setTransform(node->getGeometryNode()->modelMatrix); node->setTransform(node->getGeometryNode()->modelMatrix);
terrainContainer->addChild(node); terrainContainer->addChild(node);
@ -119,7 +118,7 @@ void generateTerrain(SceneTree *scene, btDiscreteDynamicsWorld *world)
void generateSponza(SceneTree *scene, btDiscreteDynamicsWorld *world) void generateSponza(SceneTree *scene, btDiscreteDynamicsWorld *world)
{ {
ContainerNode* sponzaContainer = new ContainerNode(); SceneNode* sponzaContainer = new SceneNode();
scene->getRootObject()->addChild(sponzaContainer); scene->getRootObject()->addChild(sponzaContainer);
Loader::setTexDirectory("data/sponza/"); Loader::setTexDirectory("data/sponza/");
std::vector<Mesh*> meshes = Loader::loadMesh("sponza.obj"); std::vector<Mesh*> meshes = Loader::loadMesh("sponza.obj");
@ -132,7 +131,7 @@ void generateSponza(SceneTree *scene, btDiscreteDynamicsWorld *world)
{ {
m->initGL(); m->initGL();
SceneNode *node = new SceneNode(); SceneNode *node = new SceneNode();
node->getGeometryNode()->mesh = m; node->setMesh(m);
node->getGeometryNode()->modelMatrix = glm::scale(glm::mat4(), glm::vec3(0.01f)); node->getGeometryNode()->modelMatrix = glm::scale(glm::mat4(), glm::vec3(0.01f));
node->setTransform(node->getGeometryNode()->modelMatrix); node->setTransform(node->getGeometryNode()->modelMatrix);
sponzaContainer->addChild(node); sponzaContainer->addChild(node);
@ -213,13 +212,15 @@ public:
//lighting //lighting
Texture* skyboxTexture = RESOURCE_GET(Texture, "radiance"); Texture* skyboxTexture = RESOURCE_GET(Texture, "radiance");
Texture* ambientTexture = RESOURCE_GET(Texture, "irradiance"); Texture* ambientTexture = RESOURCE_GET(Texture, "irradiance");
LightNode *ambientLight = new LightNode(new AmbientLight(ambientTexture, skyboxTexture)); SceneNode *ambientLight = new SceneNode();
ambientLight->setLight(new AmbientLight(ambientTexture, skyboxTexture));
DeferredPipeline* pipeline = dynamic_cast<DeferredPipeline*>(scene->getPipeline()); DeferredPipeline* pipeline = dynamic_cast<DeferredPipeline*>(scene->getPipeline());
pipeline->setSkybox(RESOURCE_GET(Texture, "skybox")); pipeline->setSkybox(RESOURCE_GET(Texture, "skybox"));
DirectionnalLight* sun = new DirectionnalLight(glm::vec3(5, 8, -2), glm::vec3(4.f)); DirectionnalLight* sun = new DirectionnalLight(glm::vec3(5, 8, -2), glm::vec3(4.f));
LightNode *sunLight = new LightNode(sun); SceneNode *sunLight = new SceneNode();
sunLight->setLight(sun);
scene->getRootObject()->addChild(ambientLight); scene->getRootObject()->addChild(ambientLight);
@ -229,8 +230,12 @@ public:
{ {
sun->initShadowMap(4096); sun->initShadowMap(4096);
generateSponza(scene, m_engine->getScene()->getPhysics()); generateSponza(scene, m_engine->getScene()->getPhysics());
scene->getRootObject()->addChild(new LightNode(new PointLight(glm::vec3(-3.5, 2, 1.8), 15, glm::vec3(0.35f)))); SceneNode* light_1 = new SceneNode();
scene->getRootObject()->addChild(new LightNode(new PointLight(glm::vec3(-5, 6, 2), 15, glm::vec3(0.35f)))); light_1->setLight(new PointLight(glm::vec3(-3.5, 2, 1.8), 15, glm::vec3(0.35f)));
scene->getRootObject()->addChild(light_1);
SceneNode* light_2 = new SceneNode();
light_2->setLight(new PointLight(glm::vec3(-5, 6, 2), 15, glm::vec3(0.35f)));
scene->getRootObject()->addChild(light_2);
m_player->setPosition(0.f, 2.f, 0.f); m_player->setPosition(0.f, 2.f, 0.f);
sun->setShadowView(glm::vec3(30, 30, 50)); sun->setShadowView(glm::vec3(30, 30, 50));
} }
@ -244,14 +249,14 @@ public:
else if(m_config->scene == "sandbox") else if(m_config->scene == "sandbox")
{ {
sun->initShadowMap(4096); sun->initShadowMap(4096);
ContainerNode* sandboxContainer = new ContainerNode(); SceneNode* sandboxContainer = new SceneNode();
scene->getRootObject()->addChild(sandboxContainer); scene->getRootObject()->addChild(sandboxContainer);
std::vector<Mesh*> meshes = Loader::loadMesh("sandbox.obj"); std::vector<Mesh*> meshes = Loader::loadMesh("sandbox.obj");
for(Mesh* m : meshes) for(Mesh* m : meshes)
{ {
m->initGL(); m->initGL();
SceneNode *node = new SceneNode(); SceneNode *node = new SceneNode();
node->getGeometryNode()->mesh = m; node->setMesh(m);
sandboxContainer->addChild(node); sandboxContainer->addChild(node);
btRigidBody* body = utils::buildStaticCollider(node->getGeometryNode()); btRigidBody* body = utils::buildStaticCollider(node->getGeometryNode());
node->setRigidBody(body); node->setRigidBody(body);

View File

@ -8,7 +8,7 @@
#include "tools/loader.h" #include "tools/loader.h"
#include "tools/loadingthread.h" #include "tools/loadingthread.h"
#include "SparrowRenderer/texture.h" #include "SparrowRenderer/texture.h"
#include "scene/containernode.h" #include "scene/scenenode.h"
#include "resourcemanager.h" #include "resourcemanager.h"
#include <imgui/imgui.h> #include <imgui/imgui.h>
@ -89,11 +89,11 @@ void Potator::throwShield()
} }
float throwForce = 5.f; float throwForce = 5.f;
ContainerNode *node = new ContainerNode(); SceneNode *node = new SceneNode();
for(Mesh * m : m_shieldMeshes) for(Mesh * m : m_shieldMeshes)
{ {
SceneNode* meshNode = new SceneNode(); SceneNode* meshNode = new SceneNode();
meshNode->getGeometryNode()->mesh = m; meshNode->setMesh(m);
node->addChild(meshNode); node->addChild(meshNode);
} }
createGib(node, m_shieldShape, m_shieldMass, pos, dir*throwForce, 30000); createGib(node, m_shieldShape, m_shieldMass, pos, dir*throwForce, 30000);
@ -110,11 +110,11 @@ void Potator::throwBottle()
} }
float throwForce = 5.f; float throwForce = 5.f;
ContainerNode *node = new ContainerNode(); SceneNode *node = new SceneNode();
for(Mesh * m : m_bottleMeshes) for(Mesh * m : m_bottleMeshes)
{ {
SceneNode* meshNode = new SceneNode(); SceneNode* meshNode = new SceneNode();
meshNode->getGeometryNode()->mesh = m; meshNode->setMesh(m);
node->addChild(meshNode); node->addChild(meshNode);
} }
createGib(node, m_bottleShape, m_bottleMass, pos, dir*throwForce, 30000); createGib(node, m_bottleShape, m_bottleMass, pos, dir*throwForce, 30000);
@ -131,11 +131,11 @@ void Potator::throwSword()
} }
float throwForce = 5.f; float throwForce = 5.f;
ContainerNode *node = new ContainerNode(); SceneNode *node = new SceneNode();
for(Mesh * m : m_swordMeshes) for(Mesh * m : m_swordMeshes)
{ {
SceneNode* meshNode = new SceneNode(); SceneNode* meshNode = new SceneNode();
meshNode->getGeometryNode()->mesh = m; meshNode->setMesh(m);
node->addChild(meshNode); node->addChild(meshNode);
} }
createGib(node, m_swordShape, m_swordMass, pos, dir*throwForce, 30000); createGib(node, m_swordShape, m_swordMass, pos, dir*throwForce, 30000);

View File

@ -34,37 +34,42 @@ Mesh* ScenePicker::generateMesh()
ScenePicker::ScenePicker() : ScenePicker::ScenePicker() :
m_pickSucceeded(false) m_pickSucceeded(false)
{ {
m_geometry.mesh = generateMesh(); setMesh(generateMesh());
} }
ScenePicker::~ScenePicker() ScenePicker::~ScenePicker()
{ {
delete m_geometry.mesh->getMaterial(); delete getMesh()->getMaterial();
delete m_geometry.mesh; delete getMesh();
} }
void ScenePicker::update() void ScenePicker::update()
{ {
pick(); SceneNode::update();
bool isEnabled = true; if(isEnabled())
ImGui::Begin("Picker", &isEnabled);
if(m_pickSucceeded)
{ {
ImGui::Text("Intersection : ( %.3f, %.3f, %.3f )", m_pickedPos.x, m_pickedPos.y, m_pickedPos.z); pick();
if(!isVisible()) setVisible(m_pickSucceeded);
}
else
{
ImGui::Text("No intesection");
if(isVisible()) setVisible(m_pickSucceeded);
}
// if(ImGui::Button("Teleport"))
//move player to target coordinate
ImGui::End();
if(!isEnabled) bool isEnabled = true;
getEngine().getEditor()->togglePicker(); ImGui::Begin("Picker", &isEnabled);
if(m_pickSucceeded)
{
ImGui::Text("Intersection : ( %.3f, %.3f, %.3f )", m_pickedPos.x, m_pickedPos.y, m_pickedPos.z);
if(!isVisible()) setVisible(m_pickSucceeded);
}
else
{
ImGui::Text("No intesection");
if(isVisible()) setVisible(m_pickSucceeded);
}
// if(ImGui::Button("Teleport"))
//move player to target coordinate
ImGui::End();
if(!isEnabled)
getEngine().getEditor()->togglePicker();
}
} }
void ScenePicker::pick() void ScenePicker::pick()
@ -89,7 +94,7 @@ void ScenePicker::pick()
m_pickedNode = static_cast<SceneNode*>(rayCallback.m_collisionObject->getUserPointer()); m_pickedNode = static_cast<SceneNode*>(rayCallback.m_collisionObject->getUserPointer());
btVector3 target = rayCallback.m_hitPointWorld; btVector3 target = rayCallback.m_hitPointWorld;
m_pickedPos = glm::vec3(target.x(), target.y(), target.z()); m_pickedPos = glm::vec3(target.x(), target.y(), target.z());
m_geometry.modelMatrix = glm::translate(glm::mat4(), m_pickedPos); getGeometryNode()->modelMatrix = glm::translate(glm::mat4(), m_pickedPos);
} }
} }
else else