First cut and a demo which uses Open Producer for windowing.
This commit is contained in:
17
src/Demos/osgproducer/Makefile
Normal file
17
src/Demos/osgproducer/Makefile
Normal file
@@ -0,0 +1,17 @@
|
||||
TOPDIR = ../../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
ProducerEventAdapter.cpp\
|
||||
osgproducer.cpp\
|
||||
|
||||
LIBS += -lProducer $(OSG_LIBS) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
|
||||
|
||||
INSTFILES = \
|
||||
$(CXXFILES)\
|
||||
Makefile.inst=Makefile
|
||||
|
||||
EXEC = osgproducer
|
||||
|
||||
include $(TOPDIR)/Make/makerules
|
||||
|
||||
13
src/Demos/osgproducer/Makefile.inst
Normal file
13
src/Demos/osgproducer/Makefile.inst
Normal file
@@ -0,0 +1,13 @@
|
||||
TOPDIR = ../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES =\
|
||||
ProducerEventAdapter.cpp\
|
||||
osgproducer.cpp\
|
||||
|
||||
LIBS += -lProducer $(OSG_LIBS) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
|
||||
|
||||
EXEC = osgproducer
|
||||
|
||||
|
||||
include $(TOPDIR)/Make/makerules
|
||||
69
src/Demos/osgproducer/MyKeyboardMouseCallback
Normal file
69
src/Demos/osgproducer/MyKeyboardMouseCallback
Normal file
@@ -0,0 +1,69 @@
|
||||
#ifndef PRODUCER_EXAMPLES_MYKEYBOARD_MOUSE_CALLBACK
|
||||
#define PRODUCER_EXAMPLES_MYKEYBOARD_MOUSE_CALLBACK
|
||||
#include <stdio.h>
|
||||
#include <Producer/RenderSurface> // For definition of KeySymbol
|
||||
#include <Producer/KeyboardMouse>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <X11/keysym.h>
|
||||
#endif
|
||||
|
||||
class MyKeyboardMouseCallback : public Producer::KeyboardMouseCallback
|
||||
{
|
||||
public:
|
||||
MyKeyboardMouseCallback(bool &done) :
|
||||
Producer::KeyboardMouseCallback(),
|
||||
_mx(0.0f),_my(0.0f),_mbutton(0),
|
||||
_done(done)
|
||||
{}
|
||||
|
||||
virtual void keyPress( Producer::KeySymbol key )
|
||||
{
|
||||
switch( key )
|
||||
{
|
||||
#ifdef XK_MISCELLANY // XWindows keydefs
|
||||
case XK_Escape:
|
||||
_done = true;
|
||||
break;
|
||||
#endif
|
||||
#ifdef WIN32
|
||||
case VK_ESCAPE:
|
||||
_done = true;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
virtual void mouseMotion( float mx, float my)
|
||||
{
|
||||
_mx = mx;
|
||||
_my = my;
|
||||
}
|
||||
virtual void buttonPress( float mx, float my, unsigned int mbutton )
|
||||
{
|
||||
_mx = mx;
|
||||
_my = my;
|
||||
_mbutton |= (1<<(mbutton-1));
|
||||
}
|
||||
virtual void buttonRelease( float mx, float my, unsigned int mbutton )
|
||||
{
|
||||
_mx = mx;
|
||||
_my = my;
|
||||
_mbutton &= ~(1<<(mbutton-1));
|
||||
}
|
||||
|
||||
|
||||
//virtual bool idle( void ) {static c = 0; printf( "IDLE %4d\n", c++ ); return true; }
|
||||
|
||||
|
||||
bool done() { return _done; }
|
||||
float mx() { return _mx; }
|
||||
float my() { return _my; }
|
||||
unsigned int mbutton() { return _mbutton; }
|
||||
private:
|
||||
float _mx, _my;
|
||||
unsigned int _mbutton;
|
||||
bool &_done;
|
||||
};
|
||||
#endif
|
||||
169
src/Demos/osgproducer/ProducerEventAdapter.cpp
Normal file
169
src/Demos/osgproducer/ProducerEventAdapter.cpp
Normal file
@@ -0,0 +1,169 @@
|
||||
#include "ProducerEventAdapter.h"
|
||||
|
||||
// default to no mouse buttons being pressed.
|
||||
unsigned int ProducerEventAdapter::_s_accumulatedButtonMask = 0;
|
||||
|
||||
int ProducerEventAdapter::_s_button = 0;
|
||||
int ProducerEventAdapter::_s_Xmin = 0;
|
||||
int ProducerEventAdapter::_s_Xmax = 1280;
|
||||
int ProducerEventAdapter::_s_Ymin = 0;
|
||||
int ProducerEventAdapter::_s_Ymax = 1024;
|
||||
int ProducerEventAdapter::_s_mx = 0;
|
||||
int ProducerEventAdapter::_s_my = 0;
|
||||
|
||||
ProducerEventAdapter::ProducerEventAdapter()
|
||||
{
|
||||
_eventType = NONE; // adaptor does not encapsulate any events.
|
||||
_key = -1; // set to 'invalid' key value.
|
||||
_button = -1; // set to 'invalid' button value.
|
||||
_mx = -1; // set to 'invalid' position value.
|
||||
_my = -1; // set to 'invalid' position value.
|
||||
_buttonMask = 0; // default to no mouse buttons being pressed.
|
||||
_time = 0.0f; // default to no time has been set.
|
||||
|
||||
copyStaticVariables();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ProducerEventAdapter::copyStaticVariables()
|
||||
{
|
||||
_buttonMask = _s_accumulatedButtonMask;
|
||||
_button = _s_button;
|
||||
_Xmin = _s_Xmin;
|
||||
_Xmax = _s_Xmax;
|
||||
_Ymin = _s_Ymin;
|
||||
_Ymax = _s_Ymax;
|
||||
_mx = _s_mx;
|
||||
_my = _s_my;
|
||||
}
|
||||
|
||||
|
||||
void ProducerEventAdapter::setWindowSize(int Xmin, int Ymin, int Xmax, int Ymax)
|
||||
{
|
||||
_s_Xmin = Xmin;
|
||||
_s_Xmax = Xmax;
|
||||
_s_Ymin = Ymin;
|
||||
_s_Ymax = Ymax;
|
||||
}
|
||||
|
||||
|
||||
void ProducerEventAdapter::setButtonMask(unsigned int buttonMask)
|
||||
{
|
||||
_s_accumulatedButtonMask = buttonMask;
|
||||
}
|
||||
|
||||
|
||||
void ProducerEventAdapter::adaptResize(double time, int Xmin, int Ymin, int Xmax, int Ymax)
|
||||
{
|
||||
setWindowSize(Xmin,Ymin,Xmax,Ymax);
|
||||
_eventType = RESIZE;
|
||||
_time = time;
|
||||
copyStaticVariables();
|
||||
}
|
||||
|
||||
void ProducerEventAdapter::adaptButtonPress(double time,float x, float y, unsigned int button)
|
||||
{
|
||||
_time = time;
|
||||
|
||||
_eventType = PUSH;
|
||||
_button = button;
|
||||
|
||||
switch(button)
|
||||
{
|
||||
case(0):
|
||||
_s_accumulatedButtonMask =
|
||||
_s_accumulatedButtonMask | LEFT_MOUSE_BUTTON;
|
||||
_s_button = LEFT_MOUSE_BUTTON;
|
||||
break;
|
||||
case(1):
|
||||
_s_accumulatedButtonMask =
|
||||
_s_accumulatedButtonMask | MIDDLE_MOUSE_BUTTON;
|
||||
_s_button = MIDDLE_MOUSE_BUTTON;
|
||||
break;
|
||||
case(2):
|
||||
_s_accumulatedButtonMask =
|
||||
_s_accumulatedButtonMask | RIGHT_MOUSE_BUTTON;
|
||||
_s_button = RIGHT_MOUSE_BUTTON;
|
||||
break;
|
||||
}
|
||||
|
||||
_s_mx = (int)(x*(float)(_s_Xmax-_s_Xmin))+_s_Xmin;
|
||||
_s_my = (int)(y*(float)(_s_Ymax-_s_Ymin))+_s_Ymin;
|
||||
|
||||
copyStaticVariables();
|
||||
}
|
||||
|
||||
void ProducerEventAdapter::adaptButtonRelease(double time,float x, float y, unsigned int button)
|
||||
{
|
||||
_time = time;
|
||||
|
||||
_eventType = RELEASE;
|
||||
_button = button;
|
||||
|
||||
switch(button)
|
||||
{
|
||||
case(0):
|
||||
_s_accumulatedButtonMask =
|
||||
_s_accumulatedButtonMask & ~LEFT_MOUSE_BUTTON;
|
||||
_s_button = LEFT_MOUSE_BUTTON;
|
||||
break;
|
||||
case(1):
|
||||
_s_accumulatedButtonMask =
|
||||
_s_accumulatedButtonMask & ~MIDDLE_MOUSE_BUTTON;
|
||||
_s_button = MIDDLE_MOUSE_BUTTON;
|
||||
break;
|
||||
case(2):
|
||||
_s_accumulatedButtonMask =
|
||||
_s_accumulatedButtonMask & ~RIGHT_MOUSE_BUTTON;
|
||||
_s_button = RIGHT_MOUSE_BUTTON;
|
||||
break;
|
||||
}
|
||||
|
||||
_s_mx = (int)(x*(float)(_s_Xmax-_s_Xmin))+_s_Xmin;
|
||||
_s_my = (int)(y*(float)(_s_Ymax-_s_Ymin))+_s_Ymin;
|
||||
|
||||
copyStaticVariables();
|
||||
}
|
||||
|
||||
/** method for adapting mouse motion events whilst mouse buttons are pressed.*/
|
||||
void ProducerEventAdapter::adaptMouseMotion(double time, float x, float y)
|
||||
{
|
||||
_eventType = DRAG;
|
||||
_time = time;
|
||||
_s_mx = (int)(x*(float)(_s_Xmax-_s_Xmin))+_s_Xmin;
|
||||
_s_my = (int)(y*(float)(_s_Ymax-_s_Ymin))+_s_Ymin;
|
||||
copyStaticVariables();
|
||||
}
|
||||
|
||||
|
||||
/** method for adapting keyboard events.*/
|
||||
void ProducerEventAdapter::adaptKeyPess( double time, Producer::KeySymbol key)
|
||||
{
|
||||
_eventType = KEYDOWN;
|
||||
_time = time;
|
||||
_key = key;
|
||||
|
||||
copyStaticVariables();
|
||||
}
|
||||
|
||||
void ProducerEventAdapter::adaptKeyRelease( double time, Producer::KeySymbol key)
|
||||
{
|
||||
// we won't handle this correctly right now.. GUIEventAdapter isn't up to it
|
||||
_eventType = KEYUP;
|
||||
_time = time;
|
||||
_key = key;
|
||||
|
||||
copyStaticVariables();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** method for adapting frame events, i.e. iddle/display callback.*/
|
||||
void ProducerEventAdapter::adaptFrame(double time)
|
||||
{
|
||||
_eventType = FRAME;
|
||||
_time = time;
|
||||
|
||||
copyStaticVariables();
|
||||
}
|
||||
113
src/Demos/osgproducer/ProducerEventAdapter.h
Normal file
113
src/Demos/osgproducer/ProducerEventAdapter.h
Normal file
@@ -0,0 +1,113 @@
|
||||
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
|
||||
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
||||
//as published by the Free Software Foundation.
|
||||
|
||||
#ifndef OSGGLUT_ProducerEventAdapter
|
||||
#define OSGGLUT_ProducerEventAdapter 1
|
||||
|
||||
#include <osgGA/GUIEventAdapter>
|
||||
#include <Producer/KeyboardMouse>
|
||||
|
||||
/** Class for adapting GLUT events so that they can be used as input to osgGA::CameraManipulators.*/
|
||||
class ProducerEventAdapter : public osgGA::GUIEventAdapter
|
||||
{
|
||||
|
||||
public:
|
||||
ProducerEventAdapter();
|
||||
virtual ~ProducerEventAdapter() {}
|
||||
|
||||
/** Get the EventType of the GUI event.*/
|
||||
virtual EventType getEventType() const { return _eventType; }
|
||||
|
||||
/** key pressed, return -1 if inappropriate for this event. */
|
||||
virtual int getKey() const { return _key; }
|
||||
|
||||
/** button pressed/released, return -1 if inappropriate for this event.*/
|
||||
virtual int getButton() const { return _button; }
|
||||
|
||||
/** window minimum x. */
|
||||
virtual int getXmin() const { return _Xmin; }
|
||||
|
||||
/** window maximum x. */
|
||||
virtual int getXmax() const { return _Xmax; }
|
||||
|
||||
/** window minimum y. */
|
||||
virtual int getYmin() const { return _Ymin; }
|
||||
|
||||
/** window maximum y. */
|
||||
virtual int getYmax() const { return _Ymax; }
|
||||
|
||||
/** current mouse x position.*/
|
||||
virtual int getX() const { return _mx; }
|
||||
|
||||
/** current mouse y position.*/
|
||||
virtual int getY() const { return _my; }
|
||||
|
||||
/** current mouse button state */
|
||||
virtual unsigned int getButtonMask() const { return _buttonMask; }
|
||||
|
||||
/** time in seconds of event. */
|
||||
virtual double time() const { return _time; }
|
||||
|
||||
|
||||
/** static method for setting window dimensions.*/
|
||||
static void setWindowSize(int Xmin, int Ymin, int Xmax, int Ymax);
|
||||
|
||||
/** static method for setting button state.*/
|
||||
static void setButtonMask(unsigned int buttonMask);
|
||||
|
||||
/** method for adapting resize events. */
|
||||
void adaptResize(double t, int Xmin, int Ymin, int Xmax, int Ymax);
|
||||
|
||||
|
||||
/** method for adapting mouse motion events whilst mouse buttons are pressed.*/
|
||||
void adaptMouseMotion(double t, float x, float y);
|
||||
|
||||
void adaptButtonPress(double t,float x, float y, unsigned int button);
|
||||
|
||||
void adaptButtonRelease(double t,float x, float y, unsigned int button);
|
||||
|
||||
/** method for adapting keyboard events.*/
|
||||
void adaptKeyPess( double t, Producer::KeySymbol key);
|
||||
|
||||
void adaptKeyRelease( double t, Producer::KeySymbol key);
|
||||
|
||||
/** method for adapting frame events, i.e. idle/display callback.*/
|
||||
void adaptFrame(double t);
|
||||
|
||||
void copyStaticVariables();
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
EventType _eventType;
|
||||
int _key;
|
||||
int _button;
|
||||
int _Xmin,_Xmax;
|
||||
int _Ymin,_Ymax;
|
||||
int _mx;
|
||||
int _my;
|
||||
unsigned int _buttonMask;
|
||||
double _time;
|
||||
|
||||
// used to accumulate the button mask state, it represents
|
||||
// the current button mask state, which is modified by the
|
||||
// adaptMouse() method which then copies it to value _buttonMask
|
||||
// which required the mouse buttons state at the time of the event.
|
||||
static unsigned int _s_accumulatedButtonMask;
|
||||
|
||||
// used to store current button value
|
||||
static int _s_button;
|
||||
|
||||
// used to store window min and max values.
|
||||
static int _s_Xmin;
|
||||
static int _s_Xmax;
|
||||
static int _s_Ymin;
|
||||
static int _s_Ymax;
|
||||
static int _s_mx;
|
||||
static int _s_my;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
84
src/Demos/osgproducer/osgproducer.cpp
Normal file
84
src/Demos/osgproducer/osgproducer.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
#include <stdio.h>
|
||||
//C++ source file - Open Producer - Copyright (C) 2002 Don Burns
|
||||
//Distributed under the terms of the GNU LIBRARY GENERAL PUBLIC LICENSE (LGPL)
|
||||
//as published by the Free Software Foundation.
|
||||
|
||||
// Simple example of use of Producer::RenderSurface
|
||||
// The myGraphics class is a simple sample of how one would implement
|
||||
// graphics drawing with Producer::RenderSurface
|
||||
|
||||
#include <Producer/Camera>
|
||||
#include <Producer/OsgCameraGroup>
|
||||
#include <Producer/OsgSceneHandler>
|
||||
#include <Producer/InputArea>
|
||||
#include <Producer/KeyboardMouse>
|
||||
#include <Producer/Trackball>
|
||||
|
||||
#include <osgUtil/Optimizer>
|
||||
|
||||
#include <osgDB/ReadFile>
|
||||
|
||||
#include "MyKeyboardMouseCallback"
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
|
||||
std::string filename;
|
||||
if (argc>1) filename = argv[1];
|
||||
else filename = "cow.osg";
|
||||
|
||||
osg::ref_ptr<osg::Node> scene = osgDB::readNodeFile(filename.c_str());
|
||||
if (!scene) return 1;
|
||||
|
||||
osgUtil::Optimizer optimizer;
|
||||
optimizer.optimize(scene.get());
|
||||
|
||||
|
||||
Producer::Camera camera1;
|
||||
Producer::RenderSurface *rs1 = camera1.getRenderSurface();
|
||||
rs1->setWindowRect(10,10,620,480);
|
||||
camera1.setOffset( 1.0, 0.0 );
|
||||
camera1.setSceneHandler(new Producer::OsgSceneHandler);
|
||||
|
||||
Producer::Camera camera2;
|
||||
Producer::RenderSurface *rs2 = camera2.getRenderSurface();
|
||||
rs2->setWindowRect(650,10,620,480);
|
||||
camera2.setOffset( -1.0, 0.0 );
|
||||
camera2.setSceneHandler(new Producer::OsgSceneHandler);
|
||||
|
||||
Producer::InputArea *ia = new Producer::InputArea;
|
||||
ia->addInputRectangle( rs1, Producer::InputRectangle(0.0,0.5,0.0,1.0));
|
||||
ia->addInputRectangle( rs2, Producer::InputRectangle(0.5,1.0,0.0,1.0));
|
||||
|
||||
Producer::CameraConfig cfg;
|
||||
cfg.addCamera("Camera 1", &camera1);
|
||||
cfg.addCamera("Camera 2", &camera2);
|
||||
|
||||
Producer::OsgCameraGroup cg(&cfg);
|
||||
|
||||
cg.setSceneData(scene.get());
|
||||
|
||||
Producer::KeyboardMouse kbm(ia);
|
||||
|
||||
bool done = false;
|
||||
MyKeyboardMouseCallback kbmcb(done);
|
||||
kbm.setCallback( &kbmcb );
|
||||
kbm.startThread();
|
||||
|
||||
Producer::Trackball tb;
|
||||
tb.setOrientation( Producer::Trackball::Y_UP );
|
||||
|
||||
// cg.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
cg.realize(Producer::CameraGroup::SingleThreaded);
|
||||
|
||||
while( !done )
|
||||
{
|
||||
tb.input( kbmcb.mx(), kbmcb.my(), kbmcb.mbutton() );
|
||||
|
||||
cg.setView(tb.getMatrix().ptr());
|
||||
|
||||
cg.frame();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user