[brlcad-commits] SF.net SVN: brlcad:[31916]
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: <ma...@us...> - 2008-07-23 14:03:09
|
Revision: 31916 http://brlcad.svn.sourceforge.net/brlcad/?rev=31916&view=rev Author: mafm Date: 2008-07-23 14:03:16 +0000 (Wed, 23 Jul 2008) Log Message: ----------- Initial commit for my work on MGED mode. At the moment only scaling works, and not very well... Modified Paths: -------------- rt^3/trunk/src/g3d/CameraManager.cxx Added Paths: ----------- rt^3/trunk/src/g3d/CameraModeMGED.cxx rt^3/trunk/src/g3d/CameraModeMGED.h Modified: rt^3/trunk/src/g3d/CameraManager.cxx =================================================================== --- rt^3/trunk/src/g3d/CameraManager.cxx 2008-07-23 13:20:02 UTC (rev 31915) +++ rt^3/trunk/src/g3d/CameraManager.cxx 2008-07-23 14:03:16 UTC (rev 31916) @@ -32,7 +32,7 @@ #include "Logger.h" #include "CameraMode.h" #include "CameraModeBlender.h" -//#include "CameraModeMGED.h" +#include "CameraModeMGED.h" #include "CameraModeOrbital.h" #include <OGRE/OgreSceneNode.h> @@ -54,8 +54,8 @@ { // create camera modes that we'll use (default is the first one, it // will get in the front of the list) + _cameraModeList.push_back(new CameraModeMGED()); _cameraModeList.push_back(new CameraModeBlender()); - //_cameraModeList.push_back(new CameraModeMGED()); _cameraModeList.push_back(new CameraModeOrbital()); const char* cameraModeName = _cameraModeList.front()->getName(); Added: rt^3/trunk/src/g3d/CameraModeMGED.cxx =================================================================== --- rt^3/trunk/src/g3d/CameraModeMGED.cxx (rev 0) +++ rt^3/trunk/src/g3d/CameraModeMGED.cxx 2008-07-23 14:03:16 UTC (rev 31916) @@ -0,0 +1,291 @@ +/* C A M E R A M O D E M G E D . C X X + * BRL-CAD + * + * Copyright (c) 2008 United States Government as represented by the + * U.S. Army Research Laboratory. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this file; see the file named COPYING for more + * information. + */ + +/** @file CameraModeMGED.cxx + * + * @author Manuel A. Fernandez Montecelo <ma...@us...> + * + * @brief + * Implementation of the Camera mode "MGED" of 3D Geometry Editor + * (g3d). + */ + +#include "CameraModeMGED.h" + +#include "Logger.h" + + +/******************************************************************************* + * CameraModeMGED + ******************************************************************************/ +const float CameraModeMGED::ROTATION_STEP = PI_NUMBER/12.0f; // 15 degrees, in radians +const float CameraModeMGED::PAN_STEP = 50.0f; // m +const float CameraModeMGED::ZOOM_STEP = 1.25f; // ratio +const float CameraModeMGED::ZOOM_SCALE = 4.0f; // ratio + +CameraModeMGED::CameraModeMGED() : + CameraMode("MGED"), + _keyControlPressed(false), + _keyAltPressed(false), + _keyShiftPressed(false), + _translationModeEnabled(false), + _rotationModeEnabled(false), + _scaleModeEnabled(false), + _constrainedSubmodeEnabled(false), + _constrainedToAxis(NOTSET), + _mouseButtonsPressed(0), + _dragOriginX(0), + _dragOriginY(0), + _dragOriginalRadius(0.0f) +{ +} + +bool CameraModeMGED::injectKeyPressed(OIS::KeyCode keyCode) +{ + switch (keyCode) { + case OIS::KC_LCONTROL: + case OIS::KC_RCONTROL: + _keyControlPressed = true; + setMode(); + return true; + case OIS::KC_LMENU: + case OIS::KC_RMENU: + _keyAltPressed = true; + setMode(); + return true; + case OIS::KC_LSHIFT: + case OIS::KC_RSHIFT: + _keyShiftPressed = true; + setMode(); + return true; + default: + return false; + } +} + +bool CameraModeMGED::injectKeyReleased(OIS::KeyCode keyCode) +{ + switch (keyCode) { + case OIS::KC_LCONTROL: + case OIS::KC_RCONTROL: + _keyControlPressed = false; + setMode(); + return true; + case OIS::KC_LMENU: + case OIS::KC_RMENU: + _keyAltPressed = false; + setMode(); + return true; + case OIS::KC_LSHIFT: + case OIS::KC_RSHIFT: + _keyShiftPressed = false; + setMode(); + return true; + default: + return false; + } +} + +bool CameraModeMGED::injectMouseMotion(int x, int y) +{ + /// \todo mafm: there are some glitches, depending on the position + /// when it starts and so on, it's worth investigating when more + /// complex scenes are in place and it can be diagnosed more easily + + if (_scaleModeEnabled && _mouseButtonsPressed > 0) { + // calculate the x position normalized between 0.0 and 1.0 + // w.r.t. screen coordinates + float horizDiffNorm = 1.0f/ZOOM_SCALE + + (x - _dragOriginX/(_windowWidth/2.0f) * (ZOOM_SCALE - 1.0f/ZOOM_SCALE)); + Logger::logDEBUG("x diff: %0.1f", horizDiffNorm); + + // zoom freely, left zooms out and right zooms in + doZoomScale(horizDiffNorm); + + return true; + } else { + return false; + } +} + +bool CameraModeMGED::injectMousePressed(OIS::MouseButtonID buttonId, int x, int y) +{ + // increase the count of mouse buttons pressed, for all purposes + ++(_mouseButtonsPressed); + + if (_translationModeEnabled || _rotationModeEnabled || _scaleModeEnabled) { + switch (buttonId) { + case OIS::MB_Left: + _constrainedToAxis = X; + _dragOriginX = x; + _dragOriginY = y; + _dragOriginalRadius = _radius; + break; + case OIS::MB_Middle: + _constrainedToAxis = Y; + _dragOriginX = x; + _dragOriginY = y; + _dragOriginalRadius = _radius; + break; + case OIS::MB_Right: + _constrainedToAxis = Z; + _dragOriginX = x; + _dragOriginY = y; + _dragOriginalRadius = _radius; + break; + default: + // nothing + break; + } + } else { + switch (buttonId) { + case OIS::MB_Left: + doZoomOut(); + break; + case OIS::MB_Middle: + /// \todo mafm: pan same distance as from point clicked to + /// center, but in opposite direction + break; + case OIS::MB_Right: + doZoomIn(); + break; + default: + // nothing + break; + } + } + + return true; +} + +bool CameraModeMGED::injectMouseReleased(OIS::MouseButtonID buttonId, int x, int y) +{ + // decrease the count of mouse buttons pressed, for all purposes + --(_mouseButtonsPressed); + + if (_translationModeEnabled || _rotationModeEnabled) { + _constrainedSubmodeEnabled = false; + switch (buttonId) { + case OIS::MB_Left: + _constrainedToAxis = NOTSET; + break; + case OIS::MB_Middle: + _constrainedToAxis = NOTSET; + break; + case OIS::MB_Right: + _constrainedToAxis = NOTSET; + break; + default: + // nothing + break; + } + } + + return true; +} + +void CameraModeMGED::setMode() +{ + if (_keyControlPressed + && _keyAltPressed + && _keyShiftPressed) { + // all keys active at once: scale mode + _scaleModeEnabled = true; + // ...and disable the rest + _translationModeEnabled = false; + _rotationModeEnabled = false; + _constrainedSubmodeEnabled = false; + //Logger::logDEBUG("set scale mode"); + } else { + // submode "constrained"? + if (_keyAltPressed) { + _constrainedSubmodeEnabled = true; + } else { + _constrainedSubmodeEnabled = false; + } + + // control key: rotation mode + if (_keyControlPressed) { + _rotationModeEnabled = true; + // ...and disable the rest + _scaleModeEnabled = false; + _translationModeEnabled = false; + + //Logger::logDEBUG("set rotate mode, constrained=%d", _constrainedSubmodeEnabled); + } else { + if (_rotationModeEnabled) { + //Logger::logDEBUG("unset rotate mode"); + _rotationModeEnabled = false; + } + } + + // shift key: translation mode + if (_keyShiftPressed ) { + _translationModeEnabled = true; + // ...and disable the rest + _scaleModeEnabled = false; + _rotationModeEnabled = false; + + //Logger::logDEBUG("set translate mode, constrained=%d", _constrainedSubmodeEnabled); + } else { + if (_translationModeEnabled) { + //Logger::logDEBUG("unset translate mode"); + _translationModeEnabled = false; + } + } + } +} + +void CameraModeMGED::doZoomScale(float modifier) +{ + float newRadius = _dragOriginalRadius; + Logger::logDEBUG("_dragOriginalRadius: %0.1f", _dragOriginalRadius); + divideVarWithLimit(newRadius, modifier*ZOOM_STEP, RADIUS_MIN_DISTANCE); + _radius = newRadius; + Logger::logDEBUG("scaled to radius: %0.1f (modifier: %g)", _radius, modifier); +/* + return; + + if (modifier > 1.0f) { + divideVarWithLimit(_radius, modifier*ZOOM_STEP, RADIUS_MIN_DISTANCE); + } else { + multiplyVarWithLimit(_radius, -modifier*ZOOM_STEP, RADIUS_MAX_DISTANCE); + } +*/ +} + +void CameraModeMGED::doZoomIn() +{ + divideVarWithLimit(_radius, ZOOM_STEP, RADIUS_MIN_DISTANCE); +} + +void CameraModeMGED::doZoomOut() +{ + multiplyVarWithLimit(_radius, ZOOM_STEP, RADIUS_MAX_DISTANCE); +} + + +// Local Variables: *** +// mode: C++ *** +// tab-width: 8 *** +// c-basic-offset: 2 *** +// indent-tabs-mode: t *** +// End: *** +// ex: shiftwidth=2 tabstop=8 Property changes on: rt^3/trunk/src/g3d/CameraModeMGED.cxx ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: rt^3/trunk/src/g3d/CameraModeMGED.h =================================================================== --- rt^3/trunk/src/g3d/CameraModeMGED.h (rev 0) +++ rt^3/trunk/src/g3d/CameraModeMGED.h 2008-07-23 14:03:16 UTC (rev 31916) @@ -0,0 +1,120 @@ +/* C A M E R A M O D E M G E D . H + * BRL-CAD + * + * Copyright (c) 2008 United States Government as represented by the + * U.S. Army Research Laboratory. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * version 2.1 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this file; see the file named COPYING for more + * information. + */ + +/** @file CameraModeMGED.h + * + * @author Manuel A. Fernandez Montecelo <ma...@us...> + * + * @brief + * Declaration of the Camera mode "MGED" of 3D Geometry Editor + * (g3d). + */ + +#ifndef __G3D_CAMERAMODEMGED_H__ +#define __G3D_CAMERAMODEMGED_H__ + + +#include "CameraMode.h" + + +/** @brief MGED camera mode + * + * @author Manuel A. Fernandez Montecelo <ma...@us...> + * + * The behavior of this camera tries to mimic the behaviour of + * traditional BRL-CAD program MGED. The shift-grips bindings are + * described in: + * http://brlcad.org/w/images/8/8c/Shift_Grips_Quick_Reference_Guide.pdf + */ +class CameraModeMGED : public CameraMode +{ +public: + /** Default constructor */ + CameraModeMGED(); + + /** @see CameraMode::injectKeyPressed */ + virtual bool injectKeyPressed(OIS::KeyCode keyCode); + /** @see CameraMode::injectKeyReleased */ + virtual bool injectKeyReleased(OIS::KeyCode keyCode); + /** @see CameraMode::injectMouseMotion */ + virtual bool injectMouseMotion(int x, int y); + /** @see CameraMode::injectMousePressed */ + virtual bool injectMousePressed(OIS::MouseButtonID buttonId, int x, int y); + /** @see CameraMode::injectMouseReleased */ + virtual bool injectMouseReleased(OIS::MouseButtonID buttonId, int x, int y); + +private: + /** Default rotation step */ + static const float ROTATION_STEP; // radians + /** Default pan distance */ + static const float PAN_STEP; // m + /** Default zoom step ratio */ + static const float ZOOM_STEP; // ratio + /** Default zoom scale ratio */ + static const float ZOOM_SCALE; // ratio + + /** Key state */ + bool _keyControlPressed; + /** Key state */ + bool _keyAltPressed; + /** Key state */ + bool _keyShiftPressed; + + /** Mode */ + bool _translationModeEnabled; + /** Mode */ + bool _rotationModeEnabled; + /** Mode */ + bool _scaleModeEnabled; + /** Submode */ + bool _constrainedSubmodeEnabled; + /** Mode helper */ + Axis _constrainedToAxis; + /** Mode helper */ + int _mouseButtonsPressed; + /** Mode helper */ + int _dragOriginX; + /** Mode helper */ + int _dragOriginY; + /** Mode helper */ + float _dragOriginalRadius; + + + /** Common functionality for all places needing it */ + void setMode(); + /** Common functionality for all places needing it */ + void doZoomScale(float modifier); + /** Common functionality for all places needing it */ + void doZoomIn(); + /** Common functionality for all places needing it */ + void doZoomOut(); +}; + + +#endif + + +// Local Variables: *** +// mode: C++ *** +// tab-width: 8 *** +// c-basic-offset: 2 *** +// indent-tabs-mode: t *** +// End: *** +// ex: shiftwidth=2 tabstop=8 Property changes on: rt^3/trunk/src/g3d/CameraModeMGED.h ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |