This commit is contained in:
Lendemor 2016-12-14 12:25:16 +01:00
commit 80a01cef2f
8 changed files with 40 additions and 16 deletions

View File

@ -17,7 +17,9 @@ Engine::Engine() :
m_input(nullptr),
m_world(nullptr),
m_physicsDebugNode(nullptr),
m_togglePhysicsDebugAction(NO_ACTION)
m_togglePhysicsDebugAction(NO_ACTION),
m_toggleShellAction(NO_ACTION),
m_exitGameAction(NO_ACTION)
{
m_clock = new sf::Clock();
m_clock->restart();
@ -161,6 +163,16 @@ void Engine::setTogglePhysicsDebugAction(int action)
m_togglePhysicsDebugAction = action;
}
void Engine::setToggleShellAction(int action)
{
m_toggleShellAction = action;
}
void Engine::setExitGameAction(int action)
{
m_exitGameAction = action;
}
void Engine::outputShell(std::string str) const
{
m_sparrowshell->out(str);
@ -177,6 +189,14 @@ void Engine::checkSpecialInputs()
else
disablePhysicsDebug();
}
else if(action == m_toggleShellAction)
{
m_sparrowshell->toggleShell();
}
else if(action == m_exitGameAction)
{
m_running = false;
}
}
}

View File

@ -31,7 +31,11 @@ public:
void enablePhysicsDebug();
void disablePhysicsDebug();
// special inputs
void setTogglePhysicsDebugAction(int action);
void setToggleShellAction(int action);
void setExitGameAction(int action);
void start();
void stop();
@ -61,11 +65,13 @@ private:
SparrowShell* m_sparrowshell;
btDiscreteDynamicsWorld* m_world;
PhysicsDebugNode *m_physicsDebugNode;
int m_togglePhysicsDebugAction;
SparrowRenderer* m_renderer;
void update();
int m_togglePhysicsDebugAction;
int m_toggleShellAction;
int m_exitGameAction;
void checkSpecialInputs();
};

View File

@ -50,6 +50,7 @@ void GraphicalContainerNode::removeChild(GraphicalNode *node)
{
m_children.erase(it);
node->m_parent = nullptr;
node->setSceneTree(nullptr);
}
}
}

View File

@ -60,9 +60,6 @@ PlayerCharacterNode::PlayerCharacterNode(bool noClip) :
m_noclipMode(noClip),
m_inputActions({NO_ACTION, NO_ACTION, NO_ACTION, NO_ACTION, NO_ACTION})
{
m_motionState = new btDefaultMotionState();
// Create the shape
btCollisionShape *shape = new btCapsuleShape(PLAYER_RADIUS, PLAYER_HEIGHT);
@ -71,7 +68,7 @@ PlayerCharacterNode::PlayerCharacterNode(bool noClip) :
shape->calculateLocalInertia(1.0, localInertia);
// Create the rigid body object
m_rigidBody = new btRigidBody(1.0, m_motionState, shape, localInertia);
m_rigidBody = new btRigidBody(1.0, nullptr, shape, localInertia);
// capsule always pointing up
m_rigidBody->setSleepingThresholds(0.0, 0.0);

View File

@ -34,7 +34,6 @@ public:
class PlayerCharacterNode : public CameraNode
{
btRigidBody* m_rigidBody;
btDefaultMotionState *m_motionState;
FirstPersonCamera m_fpsCamera;
bool m_noclipMode;

View File

@ -105,9 +105,7 @@ void SparrowShell::update()
m_indexMoved = false;
auto input = getEngine().getInput();
for(auto action : input->getActions()){
if(action == 15){
toggleShell();
}else if(action == 6){
if(action == 6){
out("Plop");
}
}

View File

@ -31,7 +31,7 @@
class myKeysMap : public IKeysMap{
public:
enum{MAIN_ACTION, SECONDARY_ACTION, MOVE_FORWARD, MOVE_BACKWARD, STRAFE_LEFT, STRAFE_RIGHT, TOGGLE_NOCLIP, TOGGLE_PHYSICS_DEBUG, TOGGLE_CONSOLE = 15};
enum{MAIN_ACTION, SECONDARY_ACTION, MOVE_FORWARD, MOVE_BACKWARD, STRAFE_LEFT, STRAFE_RIGHT, TOGGLE_NOCLIP, TOGGLE_PHYSICS_DEBUG, TOGGLE_CONSOLE, EXIT_GAME};
myKeysMap(){
keys.push_back( {MAIN_ACTION, sf::Keyboard::KeyCount + sf::Mouse::Left, IKeysMap::PRESSED} );
@ -43,11 +43,12 @@ public:
keys.push_back( {TOGGLE_NOCLIP, sf::Keyboard::G, IKeysMap::PRESSED} );
keys.push_back( {TOGGLE_PHYSICS_DEBUG, sf::Keyboard::P, IKeysMap::PRESSED} );
keys.push_back( {TOGGLE_CONSOLE, sf::Keyboard::F3, IKeysMap::PRESSED} );
keys.push_back( {EXIT_GAME, sf::Keyboard::Escape, IKeysMap::PRESSED} );
}
static std::vector<int> getMap()
{
return {MAIN_ACTION, SECONDARY_ACTION, MOVE_FORWARD, MOVE_BACKWARD, STRAFE_LEFT, STRAFE_RIGHT, TOGGLE_NOCLIP, TOGGLE_PHYSICS_DEBUG, TOGGLE_CONSOLE};
return {MAIN_ACTION, SECONDARY_ACTION, MOVE_FORWARD, MOVE_BACKWARD, STRAFE_LEFT, STRAFE_RIGHT, TOGGLE_NOCLIP, TOGGLE_PHYSICS_DEBUG, TOGGLE_CONSOLE, EXIT_GAME};
}
};
@ -128,7 +129,7 @@ int main(){
// this creates the opengl context
// the opengl context must exist before any opengl class is used (texture, pipeline, etc..)
engine.createWindow("Sparrow Engine Testing Environment");
engine.createWindow("Sparrow Engine Testing Environment", 1920, 1080, false);
// setting up SparrowEngine
engine.initPhysics();
@ -142,6 +143,8 @@ int main(){
input->setCurrentContext("default");
input->updateKeyBindings();
engine.setTogglePhysicsDebugAction(myKeysMap::TOGGLE_PHYSICS_DEBUG);
engine.setToggleShellAction(myKeysMap::TOGGLE_CONSOLE);
engine.setExitGameAction(myKeysMap::EXIT_GAME);
/*
// trackball camera
@ -151,11 +154,11 @@ int main(){
scene.setMainCamera(trackBallCam);
*/
// first person player controller
PlayerCharacterNode *player = new PlayerCharacterNode();
PlayerCharacterNode *player = new PlayerCharacterNode(false);
player->setInputs(myKeysMap::MOVE_FORWARD, myKeysMap::MOVE_BACKWARD, myKeysMap::STRAFE_LEFT, myKeysMap::STRAFE_RIGHT, myKeysMap::TOGGLE_NOCLIP);
scene->getRootObject()->addChild(player);
scene->setMainCamera(player);
player->setPosition(0.f, 10.f, 0.f);
player->setPosition(0.f, 15.f, 0.f);
engine.getPhysics()->addRigidBody(player->getRigidbody());
// throw cubes and spheres with mouse clicks

View File

@ -118,8 +118,8 @@ void Potator::throwSphere()
glm::vec3 dir(0, 1, 0);
if(m_player != nullptr)
{
pos = m_player->getEyePosition();
dir = m_player->getDirection();
pos = m_player->getEyePosition() + dir*2.f;
}
float throwForce = 20.f;