added picker() command in shell
This commit is contained in:
parent
2e12020d64
commit
2f29a5627a
@ -13,6 +13,7 @@
|
|||||||
#include "scene/physicsdebugnode.h"
|
#include "scene/physicsdebugnode.h"
|
||||||
#include "imgui/imgui.h"
|
#include "imgui/imgui.h"
|
||||||
#include "tools/loader.h"
|
#include "tools/loader.h"
|
||||||
|
#include "guitools.h"
|
||||||
|
|
||||||
Engine::Engine() :
|
Engine::Engine() :
|
||||||
m_window(nullptr),
|
m_window(nullptr),
|
||||||
@ -23,11 +24,13 @@ Engine::Engine() :
|
|||||||
m_toggleShellAction(NO_ACTION),
|
m_toggleShellAction(NO_ACTION),
|
||||||
m_exitGameAction(NO_ACTION),
|
m_exitGameAction(NO_ACTION),
|
||||||
m_showMouseAction(NO_ACTION),
|
m_showMouseAction(NO_ACTION),
|
||||||
m_mouseVisible(true)
|
m_mouseVisible(true),
|
||||||
|
m_pickerEnabled(false)
|
||||||
{
|
{
|
||||||
m_clock = new sf::Clock();
|
m_clock = new sf::Clock();
|
||||||
m_clock->restart();
|
m_clock->restart();
|
||||||
m_renderer = new SparrowRenderer();
|
m_renderer = new SparrowRenderer();
|
||||||
|
m_guiTools = new GuiTools(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Engine::~Engine()
|
Engine::~Engine()
|
||||||
@ -116,6 +119,8 @@ void Engine::update()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_guiTools->update();
|
||||||
|
|
||||||
// update Physics
|
// update Physics
|
||||||
if(m_world != nullptr)
|
if(m_world != nullptr)
|
||||||
{
|
{
|
||||||
@ -205,6 +210,7 @@ void Engine::disablePhysicsDebug()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Engine::toggleMouseVisibility()
|
void Engine::toggleMouseVisibility()
|
||||||
{
|
{
|
||||||
m_mouseVisible = !m_mouseVisible;
|
m_mouseVisible = !m_mouseVisible;
|
||||||
|
@ -8,6 +8,7 @@ class SparrowRenderer;
|
|||||||
class SceneTree;
|
class SceneTree;
|
||||||
class SparrowShell;
|
class SparrowShell;
|
||||||
class PhysicsDebugNode;
|
class PhysicsDebugNode;
|
||||||
|
class GuiTools;
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
@ -33,6 +34,7 @@ public:
|
|||||||
void enablePhysicsDebug();
|
void enablePhysicsDebug();
|
||||||
void disablePhysicsDebug();
|
void disablePhysicsDebug();
|
||||||
|
|
||||||
|
|
||||||
void toggleMouseVisibility();
|
void toggleMouseVisibility();
|
||||||
|
|
||||||
// special inputs
|
// special inputs
|
||||||
@ -49,11 +51,13 @@ public:
|
|||||||
SparrowRenderer* getRenderer() const {return m_renderer;}
|
SparrowRenderer* getRenderer() const {return m_renderer;}
|
||||||
btDiscreteDynamicsWorld* getPhysics() const {return m_world;}
|
btDiscreteDynamicsWorld* getPhysics() const {return m_world;}
|
||||||
SparrowShell* getShell() const {return m_sparrowshell;}
|
SparrowShell* getShell() const {return m_sparrowshell;}
|
||||||
|
GuiTools* getGuiTools() const {return m_guiTools;}
|
||||||
SceneTree* getScene() const;
|
SceneTree* getScene() const;
|
||||||
|
|
||||||
unsigned int getTime() const;
|
unsigned int getTime() const;
|
||||||
unsigned int getDeltaTime() const;
|
unsigned int getDeltaTime() const;
|
||||||
|
|
||||||
|
|
||||||
// SceneTree* createScene();
|
// SceneTree* createScene();
|
||||||
void createScene(std::string scene_name);
|
void createScene(std::string scene_name);
|
||||||
//void setCurrentScene(std::string scene_name){m_current_scene = scene_name;}
|
//void setCurrentScene(std::string scene_name){m_current_scene = scene_name;}
|
||||||
@ -73,6 +77,7 @@ private:
|
|||||||
btDiscreteDynamicsWorld* m_world;
|
btDiscreteDynamicsWorld* m_world;
|
||||||
PhysicsDebugNode *m_physicsDebugNode;
|
PhysicsDebugNode *m_physicsDebugNode;
|
||||||
SparrowRenderer* m_renderer;
|
SparrowRenderer* m_renderer;
|
||||||
|
GuiTools* m_guiTools;
|
||||||
|
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
@ -81,6 +86,7 @@ private:
|
|||||||
int m_exitGameAction;
|
int m_exitGameAction;
|
||||||
int m_showMouseAction;
|
int m_showMouseAction;
|
||||||
bool m_mouseVisible;
|
bool m_mouseVisible;
|
||||||
|
bool m_pickerEnabled;
|
||||||
void checkSpecialInputs();
|
void checkSpecialInputs();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
52
src/guitools.cpp
Normal file
52
src/guitools.cpp
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#include "guitools.h"
|
||||||
|
#include "imgui/imgui.h"
|
||||||
|
|
||||||
|
#include "engine.h"
|
||||||
|
#include "scene/scenetree.h"
|
||||||
|
#include "SparrowRenderer/deferredpipeline.h"
|
||||||
|
#include "scene/playercharacternode.h"
|
||||||
|
|
||||||
|
#include <btBulletCollisionCommon.h>
|
||||||
|
#include <btBulletDynamicsCommon.h>
|
||||||
|
#include <BulletDynamics/Character/btKinematicCharacterController.h>
|
||||||
|
|
||||||
|
GuiTools::GuiTools(Engine* engine) :
|
||||||
|
m_engine(engine),
|
||||||
|
m_pickerEnabled(false)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiTools::update()
|
||||||
|
{
|
||||||
|
if(m_pickerEnabled)
|
||||||
|
{
|
||||||
|
DeferredPipeline* pip = (DeferredPipeline*) m_engine->getScene()->getPipeline();
|
||||||
|
FirstPersonCamera* cam = (FirstPersonCamera*) pip->getCamera();
|
||||||
|
glm::vec3 dir_cam = cam->getDirection()*100;
|
||||||
|
btVector3 start(cam->getEyePosition().x,cam->getEyePosition().y,cam->getEyePosition().z);
|
||||||
|
btVector3 end(start.x() + dir_cam.x,start.y() + dir_cam.y,start.z() + dir_cam.z);
|
||||||
|
btCollisionWorld::ClosestRayResultCallback RayCallback(start, end);
|
||||||
|
m_engine->getPhysics()->rayTest(start,end,RayCallback);
|
||||||
|
|
||||||
|
ImGui::Begin("Picker", &m_pickerEnabled);
|
||||||
|
if(RayCallback.hasHit())
|
||||||
|
{
|
||||||
|
btVector3 target = RayCallback.m_hitPointWorld;
|
||||||
|
ImGui::Text("Target coordinates : (%.3f,%.3f,%.3f)",target.x(),target.y(),target.z());
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ImGui::Text("Nothing");
|
||||||
|
}
|
||||||
|
// if(ImGui::Button("Teleport"))
|
||||||
|
//move player to target coordinate
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuiTools::togglePicker()
|
||||||
|
{
|
||||||
|
m_pickerEnabled = !m_pickerEnabled;
|
||||||
|
}
|
16
src/guitools.h
Normal file
16
src/guitools.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#ifndef GUITOOLS_H
|
||||||
|
#define GUITOOLS_H
|
||||||
|
|
||||||
|
class Engine;
|
||||||
|
|
||||||
|
class GuiTools
|
||||||
|
{
|
||||||
|
Engine* m_engine;
|
||||||
|
bool m_pickerEnabled;
|
||||||
|
public:
|
||||||
|
GuiTools(Engine*);
|
||||||
|
void update();
|
||||||
|
void togglePicker();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // GUITOOLS_H
|
@ -189,7 +189,7 @@ void PlayerCharacterNode::update()
|
|||||||
btCollisionWorld::ClosestRayResultCallback RayCallback(start, end);
|
btCollisionWorld::ClosestRayResultCallback RayCallback(start, end);
|
||||||
getEngine().getPhysics()->rayTest(start, end, RayCallback);
|
getEngine().getPhysics()->rayTest(start, end, RayCallback);
|
||||||
float controlRatio = 0.f; // 1 = total control, 0 = no control, can be seen as a slipperiness factor
|
float controlRatio = 0.f; // 1 = total control, 0 = no control, can be seen as a slipperiness factor
|
||||||
if(RayCallback.hasHit()) // if ground is nearby
|
if(RayCallback.hasHit() ) // if ground is nearby
|
||||||
{
|
{
|
||||||
onGround = true;
|
onGround = true;
|
||||||
btVector3 normal = RayCallback.m_hitNormalWorld;
|
btVector3 normal = RayCallback.m_hitNormalWorld;
|
||||||
@ -199,10 +199,13 @@ void PlayerCharacterNode::update()
|
|||||||
if(onGround)
|
if(onGround)
|
||||||
{
|
{
|
||||||
float displacement = RayCallback.m_hitPointWorld.y() - (end.y() + start.y())/2.f;
|
float displacement = RayCallback.m_hitPointWorld.y() - (end.y() + start.y())/2.f;
|
||||||
|
//if (m_last_displacement > displacement){
|
||||||
if(abs(displacement) > 0.1f)
|
if(abs(displacement) > 0.1f)
|
||||||
pos.setY(pos.y() + deltaTime*0.01f*(displacement > 0 ? 1 : -1));
|
pos.setY(pos.y() + deltaTime*0.01f*(displacement > 0 ? 1 : -1));
|
||||||
else
|
else
|
||||||
pos.setY(pos.y() + displacement/4);
|
pos.setY(pos.y() + displacement/4);
|
||||||
|
//}
|
||||||
|
m_last_displacement = displacement;
|
||||||
btTransform transform = btTransform::getIdentity();
|
btTransform transform = btTransform::getIdentity();
|
||||||
transform.setOrigin(pos);
|
transform.setOrigin(pos);
|
||||||
m_rigidBody->setWorldTransform(transform);
|
m_rigidBody->setWorldTransform(transform);
|
||||||
|
@ -47,6 +47,8 @@ class PlayerCharacterNode : public CameraNode
|
|||||||
|
|
||||||
std::vector<int> m_inputActions;
|
std::vector<int> m_inputActions;
|
||||||
|
|
||||||
|
float m_last_displacement;
|
||||||
|
|
||||||
enum PlayerAction {FORWARD, BACKWARD, STRAFE_LEFT, STRAFE_RIGHT, JUMP, RUN, TOGGLE_NOCLIP};
|
enum PlayerAction {FORWARD, BACKWARD, STRAFE_LEFT, STRAFE_RIGHT, JUMP, RUN, TOGGLE_NOCLIP};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -3,10 +3,12 @@
|
|||||||
#include "sparrowshell/sparrowshell.h"
|
#include "sparrowshell/sparrowshell.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
#include "Version.h"
|
#include "Version.h"
|
||||||
#include "SparrowInput/Version.h"
|
#include "SparrowInput/Version.h"
|
||||||
#include "SparrowRenderer/Version.h"
|
#include "SparrowRenderer/Version.h"
|
||||||
#include "SparrowSerializer/Version.h"
|
#include "SparrowSerializer/Version.h"
|
||||||
|
#include "guitools.h"
|
||||||
|
|
||||||
#define LUA_DEFINE(var) S[#var]=var
|
#define LUA_DEFINE(var) S[#var]=var
|
||||||
#define LUA_SET_FUN(var) m_script.set_function(#var,&ScriptNode::var,this);this->functions_name.push_back(#var);
|
#define LUA_SET_FUN(var) m_script.set_function(#var,&ScriptNode::var,this);this->functions_name.push_back(#var);
|
||||||
@ -17,6 +19,7 @@ ScriptNode::ScriptNode()
|
|||||||
LUA_SET_FUN(print);
|
LUA_SET_FUN(print);
|
||||||
LUA_SET_FUN(version);
|
LUA_SET_FUN(version);
|
||||||
LUA_SET_FUN(clear);
|
LUA_SET_FUN(clear);
|
||||||
|
LUA_SET_FUN(picker);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptNode::update(){
|
void ScriptNode::update(){
|
||||||
@ -67,3 +70,20 @@ void ScriptNode::clear(){
|
|||||||
float ScriptNode::getDeltaTime(){
|
float ScriptNode::getDeltaTime(){
|
||||||
return this->getEngine().getDeltaTime()/1000.;
|
return this->getEngine().getDeltaTime()/1000.;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScriptNode::testfunc(int i, float x=0.f,float y=0.f, float z=0.f){
|
||||||
|
std::string s;
|
||||||
|
s= "Pop item ";
|
||||||
|
s+= std::to_string(i)+" at position (";
|
||||||
|
s+=std::to_string(x);
|
||||||
|
s+=",";
|
||||||
|
s+=std::to_string(y);
|
||||||
|
s+=",";
|
||||||
|
s+=std::to_string(z);
|
||||||
|
s+=")";
|
||||||
|
this->getEngine().getShell()->out(s.append("\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptNode::picker(){
|
||||||
|
this->getEngine().getGuiTools()->togglePicker();
|
||||||
|
}
|
||||||
|
@ -21,6 +21,8 @@ public:
|
|||||||
void version();
|
void version();
|
||||||
void clear();
|
void clear();
|
||||||
float getDeltaTime();
|
float getDeltaTime();
|
||||||
|
void testfunc(int, float,float,float);
|
||||||
|
void picker();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -355,7 +355,6 @@ int main(){
|
|||||||
SparrowShell* shell = engine.getShell();
|
SparrowShell* shell = engine.getShell();
|
||||||
shell->setMoveCursorLeftAction(DefaultKeysMap::MOVE_CURSOR_LEFT);
|
shell->setMoveCursorLeftAction(DefaultKeysMap::MOVE_CURSOR_LEFT);
|
||||||
shell->setMoveCursorRightAction(DefaultKeysMap::MOVE_CURSOR_RIGHT);
|
shell->setMoveCursorRightAction(DefaultKeysMap::MOVE_CURSOR_RIGHT);
|
||||||
//shell->setPlopTest(DefaultKeysMap::PLOP_TEST);
|
|
||||||
input->addContext(Context("shell",DefaultKeysMap::getShellContext()));
|
input->addContext(Context("shell",DefaultKeysMap::getShellContext()));
|
||||||
input->updateKeyBindings();
|
input->updateKeyBindings();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user