Commit 2b7751f9 authored by cutealien's avatar cutealien

Allow moving the camera around with the mouse in the MaterialViewer.


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4961 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 21eeb81b
......@@ -5,6 +5,7 @@ Only the default non-shader materials are used in here.
You have a node with a mesh, one dynamic light and global ambient light to play around with.
You can move the light with cursor-keys and +/-.
You can move the camera while left-mouse button is clicked.
*/
// TODO: Should be possible to set all material values by the GUI.
......@@ -629,6 +630,23 @@ bool CApp::OnEvent(const SEvent &event)
{
KeysPressed[event.KeyInput.Key] = event.KeyInput.PressedDown;
}
else if (event.EventType == EET_MOUSE_INPUT_EVENT)
{
if (!MousePressed && event.MouseInput.isLeftPressed())
{
gui::IGUIEnvironment* guiEnv = Device->getGUIEnvironment();
if ( guiEnv->getHovered() == guiEnv->getRootGUIElement() ) // Click on background
{
MousePressed = true;
MouseStart.X = event.MouseInput.X;
MouseStart.Y = event.MouseInput.Y;
}
}
else if (MousePressed && !event.MouseInput.isLeftPressed())
{
MousePressed = false;
}
}
return false;
}
......@@ -800,6 +818,16 @@ bool CApp::update()
if ( KeysPressed[KEY_DOWN])
RotateAroundAxis(NodeLight, -rotationSpeed, LightRotationAxis);
// Let the user move the camera around
if (MousePressed)
{
gui::ICursorControl* cursorControl = Device->getCursorControl();
const core::position2d<s32>& mousePos = cursorControl->getPosition ();
RotateHorizontal(Camera, rotationSpeed * (MouseStart.X - mousePos.X));
RotateAroundAxis(Camera, rotationSpeed * (mousePos.Y - MouseStart.Y), CameraRotationAxis);
MouseStart = mousePos;
}
// draw everything
video::SColor bkColor( skin->getColor(gui::EGDC_APP_WORKSPACE) );
videoDriver->beginScene(true, true, bkColor);
......
......@@ -236,9 +236,11 @@ public:
, MeshManipulator(0)
, Camera(0)
, SceneNode(0), SceneNode2T(0), SceneNodeTangents(0), NodeLight(0)
, CameraRotationAxis(irr::core::vector3df(1,0,0))
, LightRotationAxis(irr::core::vector3df(1,0,0))
, ControlVertexColors(0)
, GlobalAmbient(0)
, MousePressed(false)
{
memset(KeysPressed, 0, sizeof KeysPressed);
}
......@@ -299,12 +301,15 @@ private:
irr::scene::IMeshSceneNode* SceneNode2T;
irr::scene::IMeshSceneNode* SceneNodeTangents;
irr::scene::ILightSceneNode* NodeLight;
irr::core::vector3df CameraRotationAxis;
irr::core::vector3df LightRotationAxis;
SMaterialControl MeshMaterialControl;
SLightNodeControl LightControl;
CColorControl* ControlVertexColors;
CColorControl* GlobalAmbient;
bool KeysPressed[irr::KEY_KEY_CODES_COUNT];
bool MousePressed;
irr::core::position2d<irr::s32> MouseStart;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment