camera movement
This commit is contained in:
parent
a6bbc2d683
commit
935b547a16
|
|
@ -11,6 +11,8 @@ namespace RNR
|
||||||
|
|
||||||
void QtInputManager::keyEvent(QKeyEvent* e)
|
void QtInputManager::keyEvent(QKeyEvent* e)
|
||||||
{
|
{
|
||||||
|
if(e->isAutoRepeat())
|
||||||
|
return;
|
||||||
if(e->type() == QEvent::KeyPress)
|
if(e->type() == QEvent::KeyPress)
|
||||||
keyDown(e->key());
|
keyDown(e->key());
|
||||||
else if(e->type() == QEvent::KeyRelease)
|
else if(e->type() == QEvent::KeyRelease)
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ namespace RNR
|
||||||
class IInputManager
|
class IInputManager
|
||||||
{
|
{
|
||||||
World* m_world;
|
World* m_world;
|
||||||
|
std::vector<int> scancodes_down;
|
||||||
protected:
|
protected:
|
||||||
MouseState state;
|
MouseState state;
|
||||||
public:
|
public:
|
||||||
|
|
@ -21,8 +22,11 @@ namespace RNR
|
||||||
|
|
||||||
virtual void resetMouse() {};
|
virtual void resetMouse() {};
|
||||||
|
|
||||||
void setWorld(World* world) { m_world = world; }
|
void setWorld(World* world) { m_world = world; world->setInputManager(this); }
|
||||||
|
|
||||||
|
void frame();
|
||||||
|
|
||||||
|
bool isKeyDown(int scancode);
|
||||||
void keyDown(int scancode);
|
void keyDown(int scancode);
|
||||||
void keyUp(int scancode);
|
void keyUp(int scancode);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,14 +15,11 @@ namespace RNR
|
||||||
CoordinateFrame m_focus;
|
CoordinateFrame m_focus;
|
||||||
virtual void deserializeProperty(char* prop_name, pugi::xml_node prop);
|
virtual void deserializeProperty(char* prop_name, pugi::xml_node prop);
|
||||||
virtual void addProperties(std::vector<ReflectionProperty>& properties);
|
virtual void addProperties(std::vector<ReflectionProperty>& properties);
|
||||||
|
|
||||||
float m_cf_yaw;
|
|
||||||
float m_cf_pitch;
|
|
||||||
public:
|
public:
|
||||||
Camera();
|
Camera();
|
||||||
~Camera();
|
~Camera();
|
||||||
|
|
||||||
void cameraFrame(float xd, float yd);
|
void cameraFrame(float xd, float yd, bool movement_disable = true);
|
||||||
|
|
||||||
virtual std::string getClassName() { return "Camera"; }
|
virtual std::string getClassName() { return "Camera"; }
|
||||||
CoordinateFrame& getCFrame() { return m_cframe; };
|
CoordinateFrame& getCFrame() { return m_cframe; };
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@
|
||||||
|
|
||||||
namespace RNR
|
namespace RNR
|
||||||
{
|
{
|
||||||
|
class IInputManager;
|
||||||
|
|
||||||
struct WorldUndeserialized
|
struct WorldUndeserialized
|
||||||
{
|
{
|
||||||
Instance* instance;
|
Instance* instance;
|
||||||
|
|
@ -31,6 +33,7 @@ namespace RNR
|
||||||
Ogre::SceneManager* m_ogreSceneManager;
|
Ogre::SceneManager* m_ogreSceneManager;
|
||||||
TopMenuBar* m_tmb;
|
TopMenuBar* m_tmb;
|
||||||
InstanceFactory* m_instanceFactory;
|
InstanceFactory* m_instanceFactory;
|
||||||
|
IInputManager* m_inputManager;
|
||||||
float m_lastDelta;
|
float m_lastDelta;
|
||||||
|
|
||||||
void xmlAddItem(pugi::xml_node node, Instance* parent);
|
void xmlAddItem(pugi::xml_node node, Instance* parent);
|
||||||
|
|
@ -48,6 +51,8 @@ namespace RNR
|
||||||
|
|
||||||
float getLastDelta() { return m_lastDelta; }
|
float getLastDelta() { return m_lastDelta; }
|
||||||
DataModel* getDatamodel() { return m_datamodel; }
|
DataModel* getDatamodel() { return m_datamodel; }
|
||||||
|
void setInputManager(IInputManager* inputManager) { m_inputManager = inputManager; }
|
||||||
|
IInputManager* getInputManager() { return m_inputManager; }
|
||||||
void setDatamodel(DataModel* instance) { m_datamodel = instance; }
|
void setDatamodel(DataModel* instance) { m_datamodel = instance; }
|
||||||
Workspace* getWorkspace() { return m_workspace; }
|
Workspace* getWorkspace() { return m_workspace; }
|
||||||
void setWorkspace(Workspace* workspace) { m_workspace = workspace; }
|
void setWorkspace(Workspace* workspace) { m_workspace = workspace; }
|
||||||
|
|
|
||||||
|
|
@ -14,12 +14,24 @@ namespace RNR
|
||||||
|
|
||||||
void IInputManager::keyDown(int scancode)
|
void IInputManager::keyDown(int scancode)
|
||||||
{
|
{
|
||||||
|
auto it = std::find(scancodes_down.begin(), scancodes_down.end(), scancode);
|
||||||
|
if(it == scancodes_down.end())
|
||||||
|
scancodes_down.push_back(scancode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IInputManager::keyUp(int scancode)
|
void IInputManager::keyUp(int scancode)
|
||||||
{
|
{
|
||||||
|
auto it = std::find(scancodes_down.begin(), scancodes_down.end(), scancode);
|
||||||
|
if(it != scancodes_down.end())
|
||||||
|
scancodes_down.erase(it);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IInputManager::isKeyDown(int scancode)
|
||||||
|
{
|
||||||
|
auto it = std::find(scancodes_down.begin(), scancodes_down.end(), scancode);
|
||||||
|
if(it != scancodes_down.end())
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IInputManager::mouseMoveAbsolute(float x, float y)
|
void IInputManager::mouseMoveAbsolute(float x, float y)
|
||||||
|
|
@ -45,6 +57,14 @@ namespace RNR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IInputManager::frame()
|
||||||
|
{
|
||||||
|
Workspace* workspace = m_world->getWorkspace();
|
||||||
|
Camera* camera = workspace->getCurrentCamera();
|
||||||
|
if(camera)
|
||||||
|
camera->cameraFrame(0, 0, false); // update camera position
|
||||||
|
}
|
||||||
|
|
||||||
void IInputManager::mousePrimaryState(bool down)
|
void IInputManager::mousePrimaryState(bool down)
|
||||||
{
|
{
|
||||||
state.mouse_primary = down;
|
state.mouse_primary = down;
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
#include <App/V8/DataModel/Camera.hpp>
|
#include <App/V8/DataModel/Camera.hpp>
|
||||||
|
#include <App/V8/World/World.hpp>
|
||||||
|
#include <App/InputManager.hpp>
|
||||||
#include <Helpers/XML.hpp>
|
#include <Helpers/XML.hpp>
|
||||||
|
|
||||||
namespace RNR
|
namespace RNR
|
||||||
{
|
{
|
||||||
Camera::Camera()
|
Camera::Camera()
|
||||||
{
|
{
|
||||||
m_cf_yaw = 0.f;
|
|
||||||
m_cf_pitch = 0.f;
|
|
||||||
setName("Camera");
|
setName("Camera");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -27,7 +27,7 @@ namespace RNR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::cameraFrame(float xd, float yd)
|
void Camera::cameraFrame(float xd, float yd, bool movement_disable)
|
||||||
{
|
{
|
||||||
Ogre::Radian pitch = Ogre::Radian(yd);
|
Ogre::Radian pitch = Ogre::Radian(yd);
|
||||||
Ogre::Radian yaw = Ogre::Radian(xd);
|
Ogre::Radian yaw = Ogre::Radian(xd);
|
||||||
|
|
@ -44,6 +44,28 @@ namespace RNR
|
||||||
Ogre::Matrix3 rotation;
|
Ogre::Matrix3 rotation;
|
||||||
rotation.FromEulerAnglesYXZ(yaw, pitch, Ogre::Radian(0));
|
rotation.FromEulerAnglesYXZ(yaw, pitch, Ogre::Radian(0));
|
||||||
getCFrame().setRotation(rotation);
|
getCFrame().setRotation(rotation);
|
||||||
|
|
||||||
|
if(!movement_disable)
|
||||||
|
{
|
||||||
|
float speed = 50;
|
||||||
|
Ogre::Vector3 position = getCFrame().getPosition();
|
||||||
|
Ogre::Vector3 movement = Ogre::Vector3(0, 0, 0);
|
||||||
|
|
||||||
|
IInputManager* input = world->getInputManager();
|
||||||
|
if(input->isKeyDown('W'))
|
||||||
|
movement.z = -speed;
|
||||||
|
else if(input->isKeyDown('S'))
|
||||||
|
movement.z = speed;
|
||||||
|
if(input->isKeyDown('A'))
|
||||||
|
movement.x = -speed;
|
||||||
|
else if(input->isKeyDown('D'))
|
||||||
|
movement.x = speed;
|
||||||
|
|
||||||
|
movement = rotation * movement;
|
||||||
|
position += movement * world->getLastDelta();
|
||||||
|
|
||||||
|
getCFrame().setPosition(position);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::addProperties(std::vector<ReflectionProperty>& properties)
|
void Camera::addProperties(std::vector<ReflectionProperty>& properties)
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#include <App/V8/DataModel/PartInstance.hpp>
|
#include <App/V8/DataModel/PartInstance.hpp>
|
||||||
#include <App/GUI/SelectionBox.hpp>
|
#include <App/GUI/SelectionBox.hpp>
|
||||||
#include <App/Humanoid/Humanoid.hpp>
|
#include <App/Humanoid/Humanoid.hpp>
|
||||||
|
#include <App/InputManager.hpp>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <pugixml.hpp>
|
#include <pugixml.hpp>
|
||||||
|
|
||||||
|
|
@ -12,6 +13,8 @@ namespace RNR
|
||||||
{
|
{
|
||||||
Instance::setWorld(this);
|
Instance::setWorld(this);
|
||||||
|
|
||||||
|
m_inputManager = 0;
|
||||||
|
|
||||||
m_instanceFactory = new InstanceFactory();
|
m_instanceFactory = new InstanceFactory();
|
||||||
|
|
||||||
m_instanceFactory->registerInstance("Camera", InstanceFactory::instanceBuilder<Camera>);
|
m_instanceFactory->registerInstance("Camera", InstanceFactory::instanceBuilder<Camera>);
|
||||||
|
|
@ -124,7 +127,8 @@ namespace RNR
|
||||||
|
|
||||||
void World::preStep()
|
void World::preStep()
|
||||||
{
|
{
|
||||||
//
|
if(m_inputManager)
|
||||||
|
m_inputManager->frame();
|
||||||
}
|
}
|
||||||
|
|
||||||
double World::step(float timestep)
|
double World::step(float timestep)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue