Update of /cvsroot/cgkit/cgkit2/wrappers/osg
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5147/wrappers/osg
Modified Files:
osgcore.cpp osgcore.h osgwrap.cpp
Log Message:
keyboard handling
Index: osgwrap.cpp
===================================================================
RCS file: /cvsroot/cgkit/cgkit2/wrappers/osg/osgwrap.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** osgwrap.cpp 7 Feb 2006 08:47:40 -0000 1.2
--- osgwrap.cpp 14 Feb 2006 10:35:38 -0000 1.3
***************
*** 31,34 ****
--- 31,35 ----
.def("renderFrame", &OsgCore::renderFrame)
.def("initStuff", &OsgCore::initStuff)
+ .def("pumpKeyDowns", &OsgCore::pumpKeyDowns)
;
};
Index: osgcore.cpp
===================================================================
RCS file: /cvsroot/cgkit/cgkit2/wrappers/osg/osgcore.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** osgcore.cpp 13 Feb 2006 22:05:49 -0000 1.4
--- osgcore.cpp 14 Feb 2006 10:35:38 -0000 1.5
***************
*** 7,17 ****
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
!
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 library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
--- 7,17 ----
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
!
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 library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***************
*** 33,37 ****
bool normals;
osg::Vec3Array* pMeshVertices = 0;
! osg::Vec3Array* pMeshNormals = 0;
osg::DrawElementsUInt* pElements = 0;
osg::TemplateIndexArray<unsigned int, osg::Array::UIntArrayType,4,4>* pMeshNormalIndices = 0;
--- 33,37 ----
bool normals;
osg::Vec3Array* pMeshVertices = 0;
! osg::Vec3Array* pMeshNormals = 0;
osg::DrawElementsUInt* pElements = 0;
osg::TemplateIndexArray<unsigned int, osg::Array::UIntArrayType,4,4>* pMeshNormalIndices = 0;
***************
*** 40,44 ****
std::cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||" << std::endl;
std::cout << "||||||||||||||| creating OPENSCENEGRAPH mesh ||||||||||" << std::endl;
! std::cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||" << std::endl;
std::cout << std::endl;
--- 40,44 ----
std::cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||" << std::endl;
std::cout << "||||||||||||||| creating OPENSCENEGRAPH mesh ||||||||||" << std::endl;
! std::cout << "|||||||||||||||||||||||||||||||||||||||||||||||||||||||" << std::endl;
std::cout << std::endl;
***************
*** 251,255 ****
void OsgCore::initStuff(support3d::WorldObject& visumRoot)
{
! //////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////
///////////////////////// create a root node
--- 251,255 ----
void OsgCore::initStuff(support3d::WorldObject& visumRoot)
{
! //////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////
///////////////////////// create a root node
***************
*** 271,275 ****
std::cout << "|||||| OSG tree finished ||||||" << std::endl;
std::cout << "|||||||||||||||||||||||||||||||" << std::endl;
!
//////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////
--- 271,275 ----
std::cout << "|||||| OSG tree finished ||||||" << std::endl;
std::cout << "|||||||||||||||||||||||||||||||" << std::endl;
!
//////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////
***************
*** 277,282 ****
theViewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
theViewer.setSceneData( pRoot );
! keyboardEventHandler* keh = new keyboardEventHandler();
! theViewer.getEventHandlerList().push_front(keh);
theViewer.realize();
//////////////////////////////////////////////////////////////////
--- 277,282 ----
theViewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
theViewer.setSceneData( pRoot );
! mpEH = new MyEventHandler();
! theViewer.getEventHandlerList().push_front(mpEH);
theViewer.realize();
//////////////////////////////////////////////////////////////////
***************
*** 284,289 ****
std::cout << "|||||||||||||||||||||||||||||||" << std::endl;
std::cout << "||||||| starting viewer |||||||" << std::endl;
! std::cout << "|||||||||||||||||||||||||||||||" << std::endl;
! std::cout << "|||||||||||||||||||||||||||||||" << std::endl;
}
--- 284,289 ----
std::cout << "|||||||||||||||||||||||||||||||" << std::endl;
std::cout << "||||||| starting viewer |||||||" << std::endl;
! std::cout << "|||||||||||||||||||||||||||||||" << std::endl;
! std::cout << "|||||||||||||||||||||||||||||||" << std::endl;
}
***************
*** 294,297 ****
--- 294,313 ----
//////////////////////////////////////////////////////////////
+ boost::python::list OsgCore::pumpKeyDowns()
+ {
+ boost::python::list eventList;
+ int h = 0;
+ for( h=0; h<mpEH->currentKeyDownIndex; h++)
+ {
+ eventList.append( (char)(mpEH->KeyDownInts[h]) ); // keyChar
+ eventList.append( (mpEH->KeyDownInts[h]) ); // keyInt
+ eventList.append( (mpEH->KeyDownMods[h]) ); // keyMod
+ }
+
+ mpEH->currentKeyDownIndex = 0; // do the reset
+
+ return eventList;
+ }
+
void OsgCore::buildTree(support3d::WorldObject& visumRoot, osg::MatrixTransform *pSnode)
{
Index: osgcore.h
===================================================================
RCS file: /cvsroot/cgkit/cgkit2/wrappers/osg/osgcore.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** osgcore.h 13 Feb 2006 22:05:49 -0000 1.4
--- osgcore.h 14 Feb 2006 10:35:38 -0000 1.5
***************
*** 60,63 ****
--- 60,67 ----
#include <osgGA/GUIEventHandler>
+ // boost
+ #include "boost/python/list.hpp"
+ #include "boost/python/tuple.hpp"
+
// supportlib
#undef max
***************
*** 153,181 ****
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- // The One And Only OscCore Class xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-
- class OsgCore
- {
- public:
- OsgCore();
- ~OsgCore();
- void initStuff(support3d::WorldObject& visumRoot);
- void buildTree(support3d::WorldObject& visumRoot, osg::MatrixTransform *pSnode);
- void fooz();
- void renderFrame();
- private:
- osgProducer::Viewer theViewer;
- osg::StateSet *mpRootStateSet;
- std::vector<support3d::Dependent*> mDependents;
- unsigned int mLights;
- };
-
- // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// The Key Event Handling class xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
! class keyboardEventHandler : public osgGA::GUIEventHandler
{
public:
typedef void (*functionType) ();
enum keyStatusType
--- 157,173 ----
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// The Key Event Handling class xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
! class MyEventHandler : public osgGA::GUIEventHandler
{
public:
+ //boost::python::list keyDowns;
+ //boost::python::list keyUps;
+ #define KEY_LIST_LENGTH 30
+ int KeyDownInts[KEY_LIST_LENGTH];
+ int KeyDownMods[KEY_LIST_LENGTH];
+ int currentKeyDownIndex;
+
typedef void (*functionType) ();
enum keyStatusType
***************
*** 193,196 ****
--- 185,193 ----
typedef std::map<int, functionStatusType > keyFunctionMap;
+ MyEventHandler()
+ {
+ currentKeyDownIndex = 0;
+ }
+
bool addFunction(int whatKey, functionType newFunction)
{
***************
*** 230,233 ****
--- 227,262 ----
virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter&)
{
+
+ if(ea.getButtonMask() & osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON)
+ {
+ std::cout << "left mouse pressed!" << std::endl;
+ std::cout << "mouse X pos: " << ea.getX() << std::endl;
+ std::cout << "mouse Y pos: " << ea.getY() << std::endl;
+ }
+ if(ea.getButtonMask() & osgGA::GUIEventAdapter::RIGHT_MOUSE_BUTTON)
+ {
+ std::cout << "right mouse pressed!" << std::endl;
+ }
+ if(ea.getButtonMask() & osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON)
+ {
+ std::cout << "middle mouse pressed!" << std::endl;
+ }
+ if(ea.getModKeyMask() & osgGA::GUIEventAdapter:: MODKEY_LEFT_SHIFT)
+ {
+ std::cout << "...and left shift pressed" << std::endl;
+ }
+ if(ea.getModKeyMask() & osgGA::GUIEventAdapter:: MODKEY_RIGHT_SHIFT)
+ {
+ std::cout << "...and right shift pressed" << std::endl;
+ }
+ if(ea.getModKeyMask() & osgGA::GUIEventAdapter:: MODKEY_LEFT_CTRL)
+ {
+ std::cout << "...and left ctrl pressed" << std::endl;
+ }
+ if(ea.getModKeyMask() & osgGA::GUIEventAdapter:: MODKEY_RIGHT_CTRL)
+ {
+ std::cout << "...and right ctrl pressed" << std::endl;
+ }
+
bool newKeyDownEvent = false;
bool newKeyUpEvent = false;
***************
*** 238,242 ****
{
// test output
! std::cout << "keydown event" << std::endl;
keyFunctionMap::iterator itr = keyFuncMap.find(ea.getKey());
--- 267,283 ----
{
// test output
! std::cout << "keydown event: " << ea.getKey() << std::endl;
! std::cout << "keydown event: " << (char)ea.getKey() << std::endl;
! std::cout << "keydown index: " << currentKeyDownIndex << std::endl;
!
! //keyDowns.append( (char)ea.getKey() ); // keyChar
! //keyDowns.append( ea.getKey() ); // keyInt
! //keyDowns.append( ea.getModKeyMask() ); // keyMod
! if ( ea.getKey() > 65280 )
! KeyDownInts[currentKeyDownIndex] = ea.getKey() - 65280;
! else
! KeyDownInts[currentKeyDownIndex] = ea.getKey();
! KeyDownMods[currentKeyDownIndex] = ea.getModKeyMask();
! currentKeyDownIndex++;
keyFunctionMap::iterator itr = keyFuncMap.find(ea.getKey());
***************
*** 292,295 ****
--- 333,359 ----
};
+ // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+ // The One And Only OscCore Class xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+
+ class OsgCore
+ {
+ public:
+ OsgCore();
+ ~OsgCore();
+ void initStuff(support3d::WorldObject& visumRoot);
+ void buildTree(support3d::WorldObject& visumRoot, osg::MatrixTransform *pSnode);
+ void fooz();
+ void renderFrame();
+
+ boost::python::list pumpKeyDowns();
+ MyEventHandler *mpEH;
+
+ private:
+ osgProducer::Viewer theViewer;
+ osg::StateSet *mpRootStateSet;
+ std::vector<support3d::Dependent*> mDependents;
+ unsigned int mLights;
+ };
+
#endif
|