Moved old osgPresentation source files to osgPresentation/deprecated subdirectory.
This commit is contained in:
236
src/osgPresentation/deprecated/AnimationMaterial.cpp
Normal file
236
src/osgPresentation/deprecated/AnimationMaterial.cpp
Normal file
@@ -0,0 +1,236 @@
|
||||
/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
|
||||
*
|
||||
* This software is open source and may be redistributed and/or modified under
|
||||
* the terms of the GNU General Public License (GPL) version 2.0.
|
||||
* The full license is in LICENSE.txt file included with this distribution,.
|
||||
*
|
||||
* This software 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
|
||||
* include LICENSE.txt for more details.
|
||||
*/
|
||||
|
||||
#include <osgPresentation/deprecated/AnimationMaterial>
|
||||
|
||||
#include <osg/MatrixTransform>
|
||||
#include <osg/PositionAttitudeTransform>
|
||||
#include <osg/Notify>
|
||||
#include <osg/io_utils>
|
||||
|
||||
using namespace osgPresentation;
|
||||
|
||||
void AnimationMaterial::insert(double time,osg::Material* material)
|
||||
{
|
||||
_timeControlPointMap[time] = material;
|
||||
}
|
||||
|
||||
bool AnimationMaterial::getMaterial(double time,osg::Material& material) const
|
||||
{
|
||||
if (_timeControlPointMap.empty()) return false;
|
||||
|
||||
switch(_loopMode)
|
||||
{
|
||||
case(SWING):
|
||||
{
|
||||
double modulated_time = (time - getFirstTime())/(getPeriod()*2.0);
|
||||
double fraction_part = modulated_time - floor(modulated_time);
|
||||
if (fraction_part>0.5) fraction_part = 1.0-fraction_part;
|
||||
|
||||
time = getFirstTime()+(fraction_part*2.0) * getPeriod();
|
||||
break;
|
||||
}
|
||||
case(LOOP):
|
||||
{
|
||||
double modulated_time = (time - getFirstTime())/getPeriod();
|
||||
double fraction_part = modulated_time - floor(modulated_time);
|
||||
time = getFirstTime()+fraction_part * getPeriod();
|
||||
break;
|
||||
}
|
||||
case(NO_LOOPING):
|
||||
// no need to modulate the time.
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
TimeControlPointMap::const_iterator second = _timeControlPointMap.lower_bound(time);
|
||||
if (second==_timeControlPointMap.begin())
|
||||
{
|
||||
material = *(second->second);
|
||||
}
|
||||
else if (second!=_timeControlPointMap.end())
|
||||
{
|
||||
TimeControlPointMap::const_iterator first = second;
|
||||
--first;
|
||||
|
||||
// we have both a lower bound and the next item.
|
||||
|
||||
// deta_time = second.time - first.time
|
||||
double delta_time = second->first - first->first;
|
||||
|
||||
if (delta_time==0.0)
|
||||
material = *(first->second);
|
||||
else
|
||||
{
|
||||
interpolate(material,(time - first->first)/delta_time, *first->second, *second->second);
|
||||
}
|
||||
}
|
||||
else // (second==_timeControlPointMap.end())
|
||||
{
|
||||
material = *(_timeControlPointMap.rbegin()->second);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T interp(float r, const T& lhs, const T& rhs)
|
||||
{
|
||||
return lhs*(1.0f-r)+rhs*r;
|
||||
}
|
||||
|
||||
|
||||
void AnimationMaterial::interpolate(osg::Material& material, float r, const osg::Material& lhs,const osg::Material& rhs) const
|
||||
{
|
||||
material.setColorMode(lhs.getColorMode());
|
||||
|
||||
material.setAmbient(osg::Material::FRONT_AND_BACK,interp(r, lhs.getAmbient(osg::Material::FRONT),rhs.getAmbient(osg::Material::FRONT)));
|
||||
if (!material.getAmbientFrontAndBack())
|
||||
material.setAmbient(osg::Material::BACK,interp(r, lhs.getAmbient(osg::Material::BACK),rhs.getAmbient(osg::Material::BACK)));
|
||||
|
||||
material.setDiffuse(osg::Material::FRONT_AND_BACK,interp(r, lhs.getDiffuse(osg::Material::FRONT),rhs.getDiffuse(osg::Material::FRONT)));
|
||||
if (!material.getDiffuseFrontAndBack())
|
||||
material.setDiffuse(osg::Material::BACK,interp(r, lhs.getDiffuse(osg::Material::BACK),rhs.getDiffuse(osg::Material::BACK)));
|
||||
|
||||
material.setSpecular(osg::Material::FRONT_AND_BACK,interp(r, lhs.getSpecular(osg::Material::FRONT),rhs.getSpecular(osg::Material::FRONT)));
|
||||
if (!material.getSpecularFrontAndBack())
|
||||
material.setSpecular(osg::Material::BACK,interp(r, lhs.getSpecular(osg::Material::BACK),rhs.getSpecular(osg::Material::BACK)));
|
||||
|
||||
material.setEmission(osg::Material::FRONT_AND_BACK,interp(r, lhs.getEmission(osg::Material::FRONT),rhs.getEmission(osg::Material::FRONT)));
|
||||
if (!material.getEmissionFrontAndBack())
|
||||
material.setEmission(osg::Material::BACK,interp(r, lhs.getEmission(osg::Material::BACK),rhs.getEmission(osg::Material::BACK)));
|
||||
|
||||
material.setShininess(osg::Material::FRONT_AND_BACK,interp(r, lhs.getShininess(osg::Material::FRONT),rhs.getShininess(osg::Material::FRONT)));
|
||||
if (!material.getShininessFrontAndBack())
|
||||
material.setShininess(osg::Material::BACK,interp(r, lhs.getShininess(osg::Material::BACK),rhs.getShininess(osg::Material::BACK)));
|
||||
}
|
||||
|
||||
void AnimationMaterial::read(std::istream& in)
|
||||
{
|
||||
while (!in.eof())
|
||||
{
|
||||
double time;
|
||||
osg::Vec4 color;
|
||||
in >> time >> color[0] >> color[1] >> color[2] >> color[3];
|
||||
if(!in.eof())
|
||||
{
|
||||
osg::Material* material = new osg::Material;
|
||||
material->setAmbient(osg::Material::FRONT_AND_BACK,color);
|
||||
material->setDiffuse(osg::Material::FRONT_AND_BACK,color);
|
||||
insert(time,material);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationMaterial::write(std::ostream& fout) const
|
||||
{
|
||||
const TimeControlPointMap& tcpm = getTimeControlPointMap();
|
||||
for(TimeControlPointMap::const_iterator tcpmitr=tcpm.begin();
|
||||
tcpmitr!=tcpm.end();
|
||||
++tcpmitr)
|
||||
{
|
||||
fout<<tcpmitr->first<<" "<<tcpmitr->second->getDiffuse(osg::Material::FRONT)<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
bool AnimationMaterial::requiresBlending() const
|
||||
{
|
||||
const TimeControlPointMap& tcpm = getTimeControlPointMap();
|
||||
for(TimeControlPointMap::const_iterator tcpmitr=tcpm.begin();
|
||||
tcpmitr!=tcpm.end();
|
||||
++tcpmitr)
|
||||
{
|
||||
if ((tcpmitr->second->getDiffuse(osg::Material::FRONT))[3]!=1.0f) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void AnimationMaterialCallback::operator()(osg::Node* node, osg::NodeVisitor* nv)
|
||||
{
|
||||
if (_animationMaterial.valid() &&
|
||||
nv->getVisitorType()==osg::NodeVisitor::UPDATE_VISITOR &&
|
||||
nv->getFrameStamp())
|
||||
{
|
||||
double time = nv->getFrameStamp()->getReferenceTime();
|
||||
_latestTime = time;
|
||||
|
||||
if (!_pause)
|
||||
{
|
||||
// Only update _firstTime the first time, when its value is still DBL_MAX
|
||||
if (_firstTime==DBL_MAX)
|
||||
{
|
||||
OSG_INFO<<"AnimationMaterialCallback::operator() resetting _firstTime to "<<time<<std::endl;
|
||||
_firstTime = time;
|
||||
}
|
||||
update(*node);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// must call any nested node callbacks and continue subgraph traversal.
|
||||
NodeCallback::traverse(node,nv);
|
||||
}
|
||||
|
||||
double AnimationMaterialCallback::getAnimationTime() const
|
||||
{
|
||||
if (_firstTime==DBL_MAX) return 0.0f;
|
||||
else return ((_latestTime-_firstTime)-_timeOffset)*_timeMultiplier;
|
||||
}
|
||||
|
||||
void AnimationMaterialCallback::update(osg::Node& node)
|
||||
{
|
||||
osg::StateSet* stateset = node.getOrCreateStateSet();
|
||||
osg::Material* material =
|
||||
dynamic_cast<osg::Material*>(stateset->getAttribute(osg::StateAttribute::MATERIAL));
|
||||
|
||||
if (!material)
|
||||
{
|
||||
material = new osg::Material;
|
||||
stateset->setAttribute(material,osg::StateAttribute::OVERRIDE);
|
||||
}
|
||||
|
||||
_animationMaterial->getMaterial(getAnimationTime(),*material);
|
||||
}
|
||||
|
||||
|
||||
void AnimationMaterialCallback::reset()
|
||||
{
|
||||
#if 1
|
||||
_firstTime = DBL_MAX;
|
||||
_pauseTime = DBL_MAX;
|
||||
#else
|
||||
_firstTime = _latestTime;
|
||||
_pauseTime = _latestTime;
|
||||
#endif
|
||||
}
|
||||
|
||||
void AnimationMaterialCallback::setPause(bool pause)
|
||||
{
|
||||
if (_pause==pause)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_pause = pause;
|
||||
|
||||
if (_firstTime==DBL_MAX) return;
|
||||
|
||||
if (_pause)
|
||||
{
|
||||
_pauseTime = _latestTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
_firstTime += (_latestTime-_pauseTime);
|
||||
}
|
||||
}
|
||||
48
src/osgPresentation/deprecated/CompileSlideCallback.cpp
Normal file
48
src/osgPresentation/deprecated/CompileSlideCallback.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
|
||||
*
|
||||
* This software is open source and may be redistributed and/or modified under
|
||||
* the terms of the GNU General Public License (GPL) version 2.0.
|
||||
* The full license is in LICENSE.txt file included with this distribution,.
|
||||
*
|
||||
* This software 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
|
||||
* include LICENSE.txt for more details.
|
||||
*/
|
||||
|
||||
#include <osgPresentation/deprecated/CompileSlideCallback>
|
||||
|
||||
#include <osgUtil/GLObjectsVisitor>
|
||||
|
||||
using namespace osgPresentation;
|
||||
|
||||
void CompileSlideCallback::operator()(const osg::Camera & camera) const
|
||||
{
|
||||
osg::GraphicsContext* context = const_cast<osg::GraphicsContext*>(camera.getGraphicsContext());
|
||||
if (!context) return;
|
||||
|
||||
osg::State* state = context->getState();
|
||||
if (!state) return;
|
||||
|
||||
const osg::FrameStamp* fs = state->getFrameStamp();
|
||||
if (!fs) return;
|
||||
|
||||
if (_needCompile)
|
||||
{
|
||||
_frameNumber = fs->getFrameNumber();
|
||||
_needCompile = false;
|
||||
}
|
||||
|
||||
if (_frameNumber!=fs->getFrameNumber()) return;
|
||||
|
||||
osgUtil::GLObjectsVisitor globjVisitor(osgUtil::GLObjectsVisitor::COMPILE_DISPLAY_LISTS|
|
||||
osgUtil::GLObjectsVisitor::COMPILE_STATE_ATTRIBUTES);
|
||||
|
||||
globjVisitor.setTraversalMode(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN);
|
||||
|
||||
globjVisitor.setNodeMaskOverride(0xffffffff);
|
||||
|
||||
globjVisitor.setState(state);
|
||||
|
||||
_sceneToCompile->accept(globjVisitor);
|
||||
}
|
||||
171
src/osgPresentation/deprecated/KeyEventHandler.cpp
Normal file
171
src/osgPresentation/deprecated/KeyEventHandler.cpp
Normal file
@@ -0,0 +1,171 @@
|
||||
/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
|
||||
*
|
||||
* This software is open source and may be redistributed and/or modified under
|
||||
* the terms of the GNU General Public License (GPL) version 2.0.
|
||||
* The full license is in LICENSE.txt file included with this distribution,.
|
||||
*
|
||||
* This software 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
|
||||
* include LICENSE.txt for more details.
|
||||
*/
|
||||
|
||||
#include <osgPresentation/deprecated/KeyEventHandler>
|
||||
#include <osgPresentation/deprecated/SlideEventHandler>
|
||||
|
||||
#include <osgViewer/Viewer>
|
||||
#include <osg/Notify>
|
||||
#include <osgDB/FileUtils>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
using namespace osgPresentation;
|
||||
|
||||
KeyEventHandler::KeyEventHandler(int key, osgPresentation::Operation operation, const JumpData& jumpData):
|
||||
_key(key),
|
||||
_operation(operation),
|
||||
_jumpData(jumpData)
|
||||
{
|
||||
}
|
||||
|
||||
KeyEventHandler::KeyEventHandler(int key, const std::string& str, osgPresentation::Operation operation, const JumpData& jumpData):
|
||||
_key(key),
|
||||
_command(str),
|
||||
_operation(operation),
|
||||
_jumpData(jumpData)
|
||||
{
|
||||
}
|
||||
|
||||
KeyEventHandler::KeyEventHandler(int key, const osgPresentation::KeyPosition& keyPos, const JumpData& jumpData):
|
||||
_key(key),
|
||||
_keyPos(keyPos),
|
||||
_operation(osgPresentation::EVENT),
|
||||
_jumpData(jumpData)
|
||||
{
|
||||
}
|
||||
|
||||
bool KeyEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& /*aa*/, osg::Object*, osg::NodeVisitor* /*nv*/)
|
||||
{
|
||||
if (ea.getHandled()) return false;
|
||||
|
||||
switch(ea.getEventType())
|
||||
{
|
||||
case(osgGA::GUIEventAdapter::KEYDOWN):
|
||||
{
|
||||
if (ea.getKey()==_key)
|
||||
{
|
||||
doOperation();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void KeyEventHandler::accept(osgGA::GUIEventHandlerVisitor& v)
|
||||
{
|
||||
v.visit(*this);
|
||||
}
|
||||
|
||||
void KeyEventHandler::getUsage(osg::ApplicationUsage& /*usage*/) const
|
||||
{
|
||||
}
|
||||
|
||||
void KeyEventHandler::doOperation()
|
||||
{
|
||||
switch(_operation)
|
||||
{
|
||||
case(osgPresentation::RUN):
|
||||
{
|
||||
OSG_NOTICE<<"Run "<<_command<<std::endl;
|
||||
|
||||
#if 0
|
||||
osgDB::FilePathList& paths = osgDB::getDataFilePathList();
|
||||
if (!paths.empty())
|
||||
{
|
||||
#ifdef _WIN32
|
||||
std::string delimintor(";");
|
||||
#else
|
||||
std::string delimintor(":");
|
||||
#endif
|
||||
std::string filepath("OSG_FILE_PATH=");
|
||||
|
||||
bool needDeliminator = false;
|
||||
for(osgDB::FilePathList::iterator itr = paths.begin();
|
||||
itr != paths.end();
|
||||
++itr)
|
||||
{
|
||||
if (needDeliminator) filepath += delimintor;
|
||||
filepath += *itr;
|
||||
needDeliminator = true;
|
||||
}
|
||||
putenv( (char*) filepath.c_str());
|
||||
|
||||
std::string binpath("PATH=");
|
||||
char* path = getenv("PATH");
|
||||
if (path) binpath += path;
|
||||
|
||||
needDeliminator = true;
|
||||
for(osgDB::FilePathList::iterator itr = paths.begin();
|
||||
itr != paths.end();
|
||||
++itr)
|
||||
{
|
||||
if (needDeliminator) binpath += delimintor;
|
||||
binpath += *itr;
|
||||
needDeliminator = true;
|
||||
}
|
||||
putenv( (char*) binpath.c_str());
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
bool commandRunsInBackground = (_command.find("&")!=std::string::npos);
|
||||
|
||||
int result = system(_command.c_str());
|
||||
|
||||
OSG_INFO<<"system("<<_command<<") result "<<result<<std::endl;
|
||||
|
||||
if (commandRunsInBackground)
|
||||
{
|
||||
// Sleep breifly while command runs in background to give it a chance to open
|
||||
// a window and obscure this present3D's window avoiding this present3D from
|
||||
// rendering anything new before the new window opens.
|
||||
OpenThreads::Thread::microSleep(500000); // half second sleep.
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case(osgPresentation::LOAD):
|
||||
{
|
||||
OSG_NOTICE<<"Load "<<_command<<std::endl;
|
||||
break;
|
||||
}
|
||||
case(osgPresentation::EVENT):
|
||||
{
|
||||
OSG_INFO<<"Event "<<_keyPos._key<<" "<<_keyPos._x<<" "<<_keyPos._y<<std::endl;
|
||||
if (SlideEventHandler::instance()) SlideEventHandler::instance()->dispatchEvent(_keyPos);
|
||||
break;
|
||||
}
|
||||
case(osgPresentation::JUMP):
|
||||
{
|
||||
OSG_NOTICE<<"Requires jump "<<std::endl;
|
||||
break;
|
||||
}
|
||||
case(osgPresentation::FORWARD_EVENT):
|
||||
break;
|
||||
}
|
||||
|
||||
if (_jumpData.requiresJump())
|
||||
{
|
||||
_jumpData.jump(SlideEventHandler::instance());
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_NOTICE<<"No jump required."<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
237
src/osgPresentation/deprecated/PickEventHandler.cpp
Normal file
237
src/osgPresentation/deprecated/PickEventHandler.cpp
Normal file
@@ -0,0 +1,237 @@
|
||||
/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
|
||||
*
|
||||
* This software is open source and may be redistributed and/or modified under
|
||||
* the terms of the GNU General Public License (GPL) version 2.0.
|
||||
* The full license is in LICENSE.txt file included with this distribution,.
|
||||
*
|
||||
* This software 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
|
||||
* include LICENSE.txt for more details.
|
||||
*/
|
||||
|
||||
#include <osgPresentation/deprecated/PickEventHandler>
|
||||
#include <osgPresentation/deprecated/SlideEventHandler>
|
||||
|
||||
#include <osgViewer/Viewer>
|
||||
#include <osg/Notify>
|
||||
#include <osgDB/FileUtils>
|
||||
#include <osg/io_utils>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
using namespace osgPresentation;
|
||||
|
||||
PickEventHandler::PickEventHandler(osgPresentation::Operation operation, const JumpData& jumpData):
|
||||
_operation(operation),
|
||||
_jumpData(jumpData),
|
||||
_drawablesOnPush()
|
||||
{
|
||||
OSG_INFO<<"PickEventHandler::PickEventHandler(operation="<<operation<<", jumpData.relativeJump="<<jumpData.relativeJump<<", jumpData.="<<jumpData.slideNum<<", jumpData.layerNum="<<jumpData.layerNum<<std::endl;
|
||||
}
|
||||
|
||||
PickEventHandler::PickEventHandler(const std::string& str, osgPresentation::Operation operation, const JumpData& jumpData):
|
||||
_command(str),
|
||||
_operation(operation),
|
||||
_jumpData(jumpData),
|
||||
_drawablesOnPush()
|
||||
{
|
||||
OSG_INFO<<"PickEventHandler::PickEventHandler(str="<<str<<", operation="<<operation<<", jumpData.relativeJump="<<jumpData.relativeJump<<", jumpData.="<<jumpData.slideNum<<", jumpData.layerNum="<<jumpData.layerNum<<std::endl;
|
||||
}
|
||||
|
||||
PickEventHandler::PickEventHandler(const osgPresentation::KeyPosition& keyPos, const JumpData& jumpData):
|
||||
_keyPos(keyPos),
|
||||
_operation(osgPresentation::EVENT),
|
||||
_jumpData(jumpData),
|
||||
_drawablesOnPush()
|
||||
{
|
||||
OSG_INFO<<"PickEventHandler::PickEventHandler(keyPos="<<keyPos._key<<", jumpData.relativeJump="<<jumpData.relativeJump<<", jumpData.="<<jumpData.slideNum<<", jumpData.layerNum="<<jumpData.layerNum<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
bool PickEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor* nv)
|
||||
{
|
||||
if (ea.getHandled()) return false;
|
||||
|
||||
switch(ea.getEventType())
|
||||
{
|
||||
case(osgGA::GUIEventAdapter::MOVE):
|
||||
case(osgGA::GUIEventAdapter::PUSH):
|
||||
case(osgGA::GUIEventAdapter::DRAG):
|
||||
case(osgGA::GUIEventAdapter::RELEASE):
|
||||
{
|
||||
if(ea.getEventType() == osgGA::GUIEventAdapter::PUSH)
|
||||
{
|
||||
_drawablesOnPush.clear();
|
||||
}
|
||||
osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa);
|
||||
osgUtil::LineSegmentIntersector::Intersections intersections;
|
||||
if (viewer->computeIntersections(ea, nv->getNodePath(), intersections))
|
||||
{
|
||||
for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr=intersections.begin();
|
||||
hitr!=intersections.end();
|
||||
++hitr)
|
||||
{
|
||||
if (_operation == FORWARD_EVENT)
|
||||
{
|
||||
osg::ref_ptr<osgGA::GUIEventAdapter> cloned_ea = osg::clone(&ea);
|
||||
const osg::BoundingBox bb(hitr->drawable->getBound());
|
||||
const osg::Vec3& p(hitr->localIntersectionPoint);
|
||||
|
||||
float transformed_x = (p.x() - bb.xMin()) / (bb.xMax() - bb.xMin());
|
||||
float transformed_y = (p.z() - bb.zMin()) / (bb.zMax() - bb.zMin());
|
||||
|
||||
cloned_ea->setX(ea.getXmin() + transformed_x * (ea.getXmax() - ea.getXmin()));
|
||||
cloned_ea->setY(ea.getYmin() + transformed_y * (ea.getYmax() - ea.getYmin()));
|
||||
cloned_ea->setMouseYOrientation(osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS);
|
||||
|
||||
// std::cout << transformed_x << "/" << transformed_x << " -> " << cloned_ea->getX() << "/" <<cloned_ea->getY() << std::endl;
|
||||
|
||||
|
||||
// dispatch cloned event to devices
|
||||
osgViewer::View::Devices& devices = viewer->getDevices();
|
||||
for(osgViewer::View::Devices::iterator i = devices.begin(); i != devices.end(); ++i)
|
||||
{
|
||||
if((*i)->getCapabilities() & osgGA::Device::SEND_EVENTS)
|
||||
{
|
||||
(*i)->sendEvent(*cloned_ea);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ea.getEventType()==osgGA::GUIEventAdapter::PUSH)
|
||||
{
|
||||
_drawablesOnPush.insert( hitr->drawable.get() );
|
||||
}
|
||||
else if (ea.getEventType()==osgGA::GUIEventAdapter::MOVE)
|
||||
{
|
||||
OSG_INFO<<"Tooltip..."<<std::endl;
|
||||
}
|
||||
else if (ea.getEventType()==osgGA::GUIEventAdapter::RELEASE)
|
||||
{
|
||||
if (_drawablesOnPush.find(hitr->drawable.get()) != _drawablesOnPush.end())
|
||||
doOperation();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case(osgGA::GUIEventAdapter::KEYDOWN):
|
||||
{
|
||||
//OSG_NOTICE<<"PickEventHandler KEYDOWN "<<(char)ea.getKey()<<std::endl;
|
||||
//if (object) OSG_NOTICE<<" "<<object->className()<<std::endl;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void PickEventHandler::accept(osgGA::GUIEventHandlerVisitor& v)
|
||||
{
|
||||
v.visit(*this);
|
||||
}
|
||||
|
||||
void PickEventHandler::getUsage(osg::ApplicationUsage& /*usage*/) const
|
||||
{
|
||||
}
|
||||
|
||||
void PickEventHandler::doOperation()
|
||||
{
|
||||
switch(_operation)
|
||||
{
|
||||
case(osgPresentation::RUN):
|
||||
{
|
||||
OSG_NOTICE<<"Run "<<_command<<std::endl;
|
||||
|
||||
#if 0
|
||||
osgDB::FilePathList& paths = osgDB::getDataFilePathList();
|
||||
if (!paths.empty())
|
||||
{
|
||||
#ifdef _WIN32
|
||||
std::string delimintor(";");
|
||||
#else
|
||||
std::string delimintor(":");
|
||||
#endif
|
||||
std::string filepath("OSG_FILE_PATH=");
|
||||
|
||||
bool needDeliminator = false;
|
||||
for(osgDB::FilePathList::iterator itr = paths.begin();
|
||||
itr != paths.end();
|
||||
++itr)
|
||||
{
|
||||
if (needDeliminator) filepath += delimintor;
|
||||
filepath += *itr;
|
||||
needDeliminator = true;
|
||||
}
|
||||
putenv( (char*) filepath.c_str());
|
||||
|
||||
std::string binpath("PATH=");
|
||||
char* path = getenv("PATH");
|
||||
if (path) binpath += path;
|
||||
|
||||
needDeliminator = true;
|
||||
for(osgDB::FilePathList::iterator itr = paths.begin();
|
||||
itr != paths.end();
|
||||
++itr)
|
||||
{
|
||||
if (needDeliminator) binpath += delimintor;
|
||||
binpath += *itr;
|
||||
needDeliminator = true;
|
||||
}
|
||||
putenv( (char*) binpath.c_str());
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
bool commandRunsInBackground = (_command.find("&")!=std::string::npos);
|
||||
|
||||
int result = system(_command.c_str());
|
||||
|
||||
OSG_INFO<<"system("<<_command<<") result "<<result<<std::endl;
|
||||
|
||||
if (commandRunsInBackground)
|
||||
{
|
||||
// Sleep breifly while command runs in background to give it a chance to open
|
||||
// a window and obscure this present3D's window avoiding this present3D from
|
||||
// rendering anything new before the new window opens.
|
||||
OpenThreads::Thread::microSleep(500000); // half second sleep.
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case(osgPresentation::LOAD):
|
||||
{
|
||||
OSG_NOTICE<<"Load "<<_command<<std::endl;
|
||||
break;
|
||||
}
|
||||
case(osgPresentation::EVENT):
|
||||
{
|
||||
OSG_NOTICE<<"Event "<<_keyPos._key<<" "<<_keyPos._x<<" "<<_keyPos._y<<std::endl;
|
||||
if (SlideEventHandler::instance()) SlideEventHandler::instance()->dispatchEvent(_keyPos);
|
||||
break;
|
||||
}
|
||||
case(osgPresentation::JUMP):
|
||||
{
|
||||
OSG_INFO<<"Requires jump "<<std::endl;
|
||||
break;
|
||||
}
|
||||
case(osgPresentation::FORWARD_EVENT):
|
||||
break;
|
||||
}
|
||||
|
||||
if (_jumpData.requiresJump())
|
||||
{
|
||||
_jumpData.jump(SlideEventHandler::instance());
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_INFO<<"No jump required."<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
346
src/osgPresentation/deprecated/PropertyManager.cpp
Normal file
346
src/osgPresentation/deprecated/PropertyManager.cpp
Normal file
@@ -0,0 +1,346 @@
|
||||
/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
|
||||
*
|
||||
* This software is open source and may be redistributed and/or modified under
|
||||
* the terms of the GNU General Public License (GPL) version 2.0.
|
||||
* The full license is in LICENSE.txt file included with this distribution,.
|
||||
*
|
||||
* This software 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
|
||||
* include LICENSE.txt for more details.
|
||||
*/
|
||||
|
||||
#include <osgPresentation/deprecated/PropertyManager>
|
||||
#include <osg/io_utils>
|
||||
|
||||
using namespace osgPresentation;
|
||||
|
||||
const osg::Object* osgPresentation::getUserObject(const osg::NodePath& nodepath, const std::string& name)
|
||||
{
|
||||
for(osg::NodePath::const_reverse_iterator itr = nodepath.rbegin();
|
||||
itr != nodepath.rend();
|
||||
++itr)
|
||||
{
|
||||
const osg::UserDataContainer* udc = (*itr)->getUserDataContainer();
|
||||
const osg::Object* object = udc ? udc->getUserObject(name) : 0;
|
||||
if (object) return object;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool osgPresentation::containsPropertyReference(const std::string& str)
|
||||
{
|
||||
return (str.find('$')!=std::string::npos);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PropertyAnimation::reset()
|
||||
{
|
||||
_firstTime = DBL_MAX;
|
||||
_pauseTime = DBL_MAX;
|
||||
|
||||
OSG_NOTICE<<"PropertyAnimation::reset()"<<std::endl;
|
||||
}
|
||||
|
||||
void PropertyAnimation::setPause(bool pause)
|
||||
{
|
||||
OSG_NOTICE<<"PropertyAnimation::setPause("<<pause<<")"<<std::endl;
|
||||
|
||||
if (_pause==pause)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_pause = pause;
|
||||
|
||||
if (_firstTime==DBL_MAX) return;
|
||||
|
||||
if (_pause)
|
||||
{
|
||||
_pauseTime = _latestTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
_firstTime += (_latestTime-_pauseTime);
|
||||
}
|
||||
}
|
||||
|
||||
double PropertyAnimation::getAnimationTime() const
|
||||
{
|
||||
return _latestTime-_firstTime;
|
||||
}
|
||||
|
||||
|
||||
void PropertyAnimation::operator()(osg::Node* node, osg::NodeVisitor* nv)
|
||||
{
|
||||
if (nv->getVisitorType()==osg::NodeVisitor::UPDATE_VISITOR &&
|
||||
nv->getFrameStamp())
|
||||
{
|
||||
double time = nv->getFrameStamp()->getSimulationTime();
|
||||
_latestTime = time;
|
||||
|
||||
if (!_pause)
|
||||
{
|
||||
// Only update _firstTime the first time, when its value is still DBL_MAX
|
||||
if (_firstTime==DBL_MAX) _firstTime = time;
|
||||
update(*node);
|
||||
}
|
||||
}
|
||||
|
||||
traverse(node, nv);
|
||||
}
|
||||
|
||||
class MySetValueVisitor : public osg::ValueObject::SetValueVisitor
|
||||
{
|
||||
public:
|
||||
|
||||
MySetValueVisitor(double in_r1, double in_r2, osg::ValueObject* in_object2):
|
||||
_r1(in_r1), _r2(in_r2), _object2(in_object2)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void combineRealUserValue(T& value) const
|
||||
{
|
||||
typedef osg::TemplateValueObject<T> UserValueObject;
|
||||
const UserValueObject* uvo = _object2 ? dynamic_cast<const UserValueObject*>(_object2) : 0;
|
||||
if (uvo)
|
||||
{
|
||||
value = value*_r1 + uvo->getValue()*_r2;
|
||||
}
|
||||
OSG_NOTICE<<"combineRealUserValue r1="<<_r1<<", r2="<<_r2<<", value="<<value<<std::endl;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void combineIntegerUserValue(T& value) const
|
||||
{
|
||||
typedef osg::TemplateValueObject<T> UserValueObject;
|
||||
const UserValueObject* uvo = _object2 ? dynamic_cast<const UserValueObject*>(_object2) : 0;
|
||||
if (uvo)
|
||||
{
|
||||
value = static_cast<T>(static_cast<double>(value)*_r1 + static_cast<double>(uvo->getValue())*_r2);
|
||||
}
|
||||
OSG_NOTICE<<"combineIntegerUserValue "<<value<<std::endl;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void combineDiscretUserValue(T& value) const
|
||||
{
|
||||
if (_r1<_r2) // choose value2 if possible
|
||||
{
|
||||
typedef osg::TemplateValueObject<T> UserValueObject;
|
||||
const UserValueObject* uvo = _object2 ? dynamic_cast<const UserValueObject*>(_object2) : 0;
|
||||
if (uvo)
|
||||
{
|
||||
value = uvo->getValue();
|
||||
}
|
||||
}
|
||||
OSG_NOTICE<<"combineDiscretUserValue "<<value<<std::endl;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void combineRotationUserValue(T& /*value*/) const
|
||||
{
|
||||
OSG_NOTICE<<"combineRotationUserValue TODO - do slerp"<<std::endl;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void combinePlaneUserValue(T& /*value*/) const
|
||||
{
|
||||
OSG_NOTICE<<"combinePlaneUserValue TODO"<<std::endl;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void combineMatrixUserValue(T& /*value*/) const
|
||||
{
|
||||
OSG_NOTICE<<"combineMatrixUserValue TODO - decomposs into translate, rotation and scale and then interpolate."<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
virtual void apply(bool& value) { combineDiscretUserValue(value); }
|
||||
virtual void apply(char& value) { combineDiscretUserValue(value); }
|
||||
virtual void apply(unsigned char& value) { combineDiscretUserValue(value); }
|
||||
virtual void apply(short& value) { combineIntegerUserValue(value); }
|
||||
virtual void apply(unsigned short& value) { combineIntegerUserValue(value); }
|
||||
virtual void apply(int& value) { combineIntegerUserValue(value); }
|
||||
virtual void apply(unsigned int& value) { combineIntegerUserValue(value); }
|
||||
virtual void apply(float& value) { combineRealUserValue(value); }
|
||||
virtual void apply(double& value) { combineRealUserValue(value); }
|
||||
virtual void apply(std::string& value) { combineDiscretUserValue(value); }
|
||||
virtual void apply(osg::Vec2f& value) { combineRealUserValue(value); }
|
||||
virtual void apply(osg::Vec3f& value) { combineRealUserValue(value); }
|
||||
virtual void apply(osg::Vec4f& value) { combineRealUserValue(value); }
|
||||
virtual void apply(osg::Vec2d& value) { combineRealUserValue(value); }
|
||||
virtual void apply(osg::Vec3d& value) { combineRealUserValue(value); }
|
||||
virtual void apply(osg::Vec4d& value) { combineRealUserValue(value); }
|
||||
virtual void apply(osg::Quat& value) { combineRotationUserValue(value); }
|
||||
virtual void apply(osg::Plane& value) { combinePlaneUserValue(value); }
|
||||
virtual void apply(osg::Matrixf& value) { combineMatrixUserValue(value); }
|
||||
virtual void apply(osg::Matrixd& value) { combineMatrixUserValue(value); }
|
||||
|
||||
double _r1, _r2;
|
||||
osg::ValueObject* _object2;
|
||||
};
|
||||
|
||||
void PropertyAnimation::update(osg::Node& node)
|
||||
{
|
||||
OSG_NOTICE<<"PropertyAnimation::update()"<<this<<std::endl;
|
||||
|
||||
double time = getAnimationTime();
|
||||
|
||||
if (_keyFrameMap.empty()) return;
|
||||
|
||||
KeyFrameMap::const_iterator itr = _keyFrameMap.lower_bound(time);
|
||||
if (itr==_keyFrameMap.begin())
|
||||
{
|
||||
// need to copy first UserDataContainer
|
||||
OSG_NOTICE<<"PropertyAnimation::update() : copy first UserDataContainer"<<std::endl;
|
||||
assign(node.getOrCreateUserDataContainer(), itr->second.get());
|
||||
}
|
||||
else if (itr!=_keyFrameMap.end())
|
||||
{
|
||||
KeyFrameMap::const_iterator itr_1 = itr; --itr_1;
|
||||
KeyFrameMap::const_iterator itr_2 = itr;
|
||||
|
||||
// delta_time = second.time - first.time
|
||||
double delta_time = itr_2->first - itr_1->first;
|
||||
double r1, r2;
|
||||
if (delta_time==0.0)
|
||||
{
|
||||
r1 = 0.5;
|
||||
r2 = 0.5;
|
||||
}
|
||||
else
|
||||
{
|
||||
r2 = (time - itr_1->first)/delta_time;
|
||||
r1 = 1.0-r2;
|
||||
}
|
||||
|
||||
osg::UserDataContainer* p1 = itr_1->second.get();
|
||||
osg::UserDataContainer* p2 = itr_2->second.get();
|
||||
|
||||
// clone all the properties from p1;
|
||||
|
||||
osg::ref_ptr<osg::UserDataContainer> destination = node.getOrCreateUserDataContainer();
|
||||
|
||||
assign(destination.get(), p1);
|
||||
|
||||
for(unsigned int i2=0; i2<p2->getNumUserObjects(); ++i2)
|
||||
{
|
||||
osg::Object* obj_2 = p2->getUserObject(i2);
|
||||
unsigned int i1 = p1->getUserObjectIndex(obj_2->getName());
|
||||
if (i1<p1->getNumUserObjects())
|
||||
{
|
||||
osg::Object* obj_1 = p1->getUserObject(i1);
|
||||
osg::ValueObject* valueobject_1 = dynamic_cast<osg::ValueObject*>(obj_1);
|
||||
osg::ValueObject* valueobject_2 = dynamic_cast<osg::ValueObject*>(obj_2);
|
||||
if (valueobject_1 && valueobject_2)
|
||||
{
|
||||
osg::ref_ptr<osg::ValueObject> vo = osg::clone(valueobject_1);
|
||||
MySetValueVisitor mySetValue(r1, r2, valueobject_2);
|
||||
vo->set(mySetValue);
|
||||
assign(destination.get(), vo.get());
|
||||
}
|
||||
else if (obj_1)
|
||||
{
|
||||
assign(destination.get(), obj_1);
|
||||
}
|
||||
else if (obj_2)
|
||||
{
|
||||
assign(destination.get(), obj_2);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// need to insert property;
|
||||
assign(destination.get(), obj_2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else // (itr==_keyFrameMap.end())
|
||||
{
|
||||
OSG_NOTICE<<"PropertyAnimation::update() : copy last UserDataContainer"<<std::endl;
|
||||
assign(node.getOrCreateUserDataContainer(), _keyFrameMap.rbegin()->second.get());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PropertyAnimation::assign(osg::UserDataContainer* destination, osg::UserDataContainer* source)
|
||||
{
|
||||
if (!destination) return;
|
||||
if (!source) return;
|
||||
|
||||
for(unsigned int i=0; i<source->getNumUserObjects(); ++i)
|
||||
{
|
||||
assign(destination, source->getUserObject(i));
|
||||
}
|
||||
}
|
||||
|
||||
void PropertyAnimation::assign(osg::UserDataContainer* udc, osg::Object* obj)
|
||||
{
|
||||
if (!obj) return;
|
||||
|
||||
unsigned int index = udc->getUserObjectIndex(obj);
|
||||
if (index != udc->getNumUserObjects())
|
||||
{
|
||||
OSG_NOTICE<<"Object already assigned to UserDataContainer"<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
index = udc->getUserObjectIndex(obj->getName());
|
||||
if (index != udc->getNumUserObjects())
|
||||
{
|
||||
OSG_NOTICE<<"Replacing object in UserDataContainer"<<std::endl;
|
||||
udc->setUserObject(index, obj);
|
||||
return;
|
||||
}
|
||||
|
||||
OSG_NOTICE<<"Assigned object to UserDataContainer"<<std::endl;
|
||||
udc->addUserObject(obj);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ImageSequenceUpdateCallback::operator()(osg::Node* node, osg::NodeVisitor* nv)
|
||||
{
|
||||
float x;
|
||||
if (_propertyManager->getProperty(_propertyName,x))
|
||||
{
|
||||
double xMin = -1.0;
|
||||
double xMax = 1.0;
|
||||
double position = ((double)x-xMin)/(xMax-xMin)*_imageSequence->getLength();
|
||||
|
||||
_imageSequence->seek(position);
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_INFO<<"ImageSequenceUpdateCallback::operator() Could not find property : "<<_propertyName<<std::endl;
|
||||
}
|
||||
|
||||
// note, callback is responsible for scenegraph traversal so
|
||||
// they must call traverse(node,nv) to ensure that the
|
||||
// scene graph subtree (and associated callbacks) are traversed.
|
||||
traverse(node,nv);
|
||||
}
|
||||
|
||||
|
||||
bool PropertyEventCallback::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&)
|
||||
{
|
||||
|
||||
bool mouseEvent = (ea.getEventType()==osgGA::GUIEventAdapter::MOVE ||
|
||||
ea.getEventType()==osgGA::GUIEventAdapter::DRAG ||
|
||||
ea.getEventType()==osgGA::GUIEventAdapter::PUSH ||
|
||||
ea.getEventType()==osgGA::GUIEventAdapter::RELEASE);
|
||||
if(mouseEvent)
|
||||
{
|
||||
_propertyManager->setProperty("mouse.x",ea.getX());
|
||||
_propertyManager->setProperty("mouse.x_normalized",ea.getXnormalized());
|
||||
_propertyManager->setProperty("mouse.y",ea.getX());
|
||||
_propertyManager->setProperty("mouse.y_normalized",ea.getYnormalized());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
1603
src/osgPresentation/deprecated/SlideEventHandler.cpp
Normal file
1603
src/osgPresentation/deprecated/SlideEventHandler.cpp
Normal file
File diff suppressed because it is too large
Load Diff
2894
src/osgPresentation/deprecated/SlideShowConstructor.cpp
Normal file
2894
src/osgPresentation/deprecated/SlideShowConstructor.cpp
Normal file
File diff suppressed because it is too large
Load Diff
394
src/osgPresentation/deprecated/Timeout.cpp
Normal file
394
src/osgPresentation/deprecated/Timeout.cpp
Normal file
@@ -0,0 +1,394 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* 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
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#include <osgPresentation/deprecated/Timeout>
|
||||
#include <osgUtil/CullVisitor>
|
||||
#include <osgGA/EventVisitor>
|
||||
|
||||
using namespace osgPresentation;
|
||||
|
||||
|
||||
class OperationVisitor : public osg::NodeVisitor
|
||||
{
|
||||
public:
|
||||
|
||||
enum Operation
|
||||
{
|
||||
ENTER,
|
||||
LEAVE,
|
||||
RESET
|
||||
};
|
||||
|
||||
OperationVisitor(Operation op) : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), _operation(op), _sleepTime(0.0) {}
|
||||
|
||||
void apply(osg::Node& node)
|
||||
{
|
||||
if (node.getStateSet()) process(node.getStateSet());
|
||||
traverse(node);
|
||||
}
|
||||
|
||||
void apply(osg::Geode& geode)
|
||||
{
|
||||
apply(static_cast<osg::Node&>(geode));
|
||||
|
||||
for(unsigned int i=0;i<geode.getNumDrawables();++i)
|
||||
{
|
||||
osg::Drawable* drawable = geode.getDrawable(i);
|
||||
if (drawable->getStateSet()) process(drawable->getStateSet());
|
||||
}
|
||||
}
|
||||
|
||||
virtual void process(osg::StateSet* ss)
|
||||
{
|
||||
for(unsigned int i=0;i<ss->getTextureAttributeList().size();++i)
|
||||
{
|
||||
osg::Texture* texture = dynamic_cast<osg::Texture*>(ss->getTextureAttribute(i,osg::StateAttribute::TEXTURE));
|
||||
osg::Image* image = texture ? texture->getImage(0) : 0;
|
||||
osg::ImageStream* imageStream = dynamic_cast<osg::ImageStream*>(image);
|
||||
if (imageStream) process(imageStream);
|
||||
}
|
||||
}
|
||||
|
||||
void process(osg::ImageStream* video)
|
||||
{
|
||||
if (_operation==ENTER)
|
||||
{
|
||||
video->rewind();
|
||||
video->play();
|
||||
|
||||
_sleepTime = 0.2;
|
||||
}
|
||||
else if (_operation==LEAVE)
|
||||
{
|
||||
video->pause();
|
||||
}
|
||||
else if (_operation==RESET)
|
||||
{
|
||||
video->rewind();
|
||||
|
||||
_sleepTime = 0.2;
|
||||
}
|
||||
}
|
||||
|
||||
double sleepTime() const { return _sleepTime; }
|
||||
|
||||
Operation _operation;
|
||||
double _sleepTime;
|
||||
};
|
||||
|
||||
|
||||
HUDSettings::HUDSettings(double slideDistance, float eyeOffset, unsigned int leftMask, unsigned int rightMask):
|
||||
_slideDistance(slideDistance),
|
||||
_eyeOffset(eyeOffset),
|
||||
_leftMask(leftMask),
|
||||
_rightMask(rightMask)
|
||||
{
|
||||
}
|
||||
|
||||
HUDSettings::~HUDSettings()
|
||||
{
|
||||
}
|
||||
|
||||
bool HUDSettings::getModelViewMatrix(osg::Matrix& matrix, osg::NodeVisitor* nv) const
|
||||
{
|
||||
matrix.makeLookAt(osg::Vec3d(0.0,0.0,0.0),osg::Vec3d(0.0,_slideDistance,0.0),osg::Vec3d(0.0,0.0,1.0));
|
||||
|
||||
if (nv)
|
||||
{
|
||||
if (nv->getTraversalMask()==_leftMask)
|
||||
{
|
||||
matrix.postMultTranslate(osg::Vec3(_eyeOffset,0.0,0.0));
|
||||
}
|
||||
else if (nv->getTraversalMask()==_rightMask)
|
||||
{
|
||||
matrix.postMultTranslate(osg::Vec3(-_eyeOffset,0.0,0.0));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HUDSettings::getInverseModelViewMatrix(osg::Matrix& matrix, osg::NodeVisitor* nv) const
|
||||
{
|
||||
osg::Matrix modelView;
|
||||
getModelViewMatrix(modelView,nv);
|
||||
matrix.invert(modelView);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Timeout::Timeout(HUDSettings* hudSettings):
|
||||
_previousFrameNumber(-1),
|
||||
_timeOfLastEvent(0.0),
|
||||
_displayTimeout(false),
|
||||
_idleDurationBeforeTimeoutDisplay(DBL_MAX),
|
||||
_idleDurationBeforeTimeoutAction(DBL_MAX),
|
||||
_keyStartsTimoutDisplay(0),
|
||||
_keyDismissTimoutDisplay(0),
|
||||
_keyRunTimeoutAction(0)
|
||||
{
|
||||
_hudSettings = hudSettings;
|
||||
setCullingActive(false);
|
||||
setNumChildrenRequiringEventTraversal(1);
|
||||
}
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
Timeout::Timeout(const Timeout& timeout,const osg::CopyOp& copyop):
|
||||
osg::Transform(timeout, copyop),
|
||||
_hudSettings(timeout._hudSettings)
|
||||
{
|
||||
setDataVariance(osg::Object::DYNAMIC);
|
||||
setReferenceFrame(osg::Transform::ABSOLUTE_RF);
|
||||
}
|
||||
|
||||
Timeout::~Timeout()
|
||||
{
|
||||
}
|
||||
|
||||
bool Timeout::computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const
|
||||
{
|
||||
if (_hudSettings.valid()) return _hudSettings->getModelViewMatrix(matrix,nv);
|
||||
else return false;
|
||||
}
|
||||
|
||||
bool Timeout::computeWorldToLocalMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const
|
||||
{
|
||||
if (_hudSettings.valid()) return _hudSettings->getInverseModelViewMatrix(matrix,nv);
|
||||
else return false;
|
||||
}
|
||||
|
||||
void Timeout::broadcastEvent(osgViewer::Viewer* viewer, const osgPresentation::KeyPosition& keyPos)
|
||||
{
|
||||
osg::ref_ptr<osgGA::GUIEventAdapter> event = new osgGA::GUIEventAdapter;
|
||||
|
||||
if (keyPos._key!=0) event->setEventType(osgGA::GUIEventAdapter::KEYDOWN);
|
||||
else event->setEventType(osgGA::GUIEventAdapter::MOVE);
|
||||
|
||||
if (keyPos._key!=0) event->setKey(keyPos._key);
|
||||
if (keyPos._x!=FLT_MAX) event->setX(keyPos._x);
|
||||
if (keyPos._y!=FLT_MAX) event->setY(keyPos._y);
|
||||
|
||||
event->setMouseYOrientation(osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS);
|
||||
|
||||
// dispatch cloned event to devices
|
||||
osgViewer::View::Devices& devices = viewer->getDevices();
|
||||
for(osgViewer::View::Devices::iterator i = devices.begin(); i != devices.end(); ++i)
|
||||
{
|
||||
if((*i)->getCapabilities() & osgGA::Device::SEND_EVENTS)
|
||||
{
|
||||
(*i)->sendEvent(*event);
|
||||
}
|
||||
}
|
||||
}
|
||||
void Timeout::traverse(osg::NodeVisitor& nv)
|
||||
{
|
||||
if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR)
|
||||
{
|
||||
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv);
|
||||
if (_displayTimeout && cv)
|
||||
{
|
||||
osgUtil::RenderStage* previous_stage = cv->getCurrentRenderBin()->getStage();
|
||||
|
||||
osg::ref_ptr<osgUtil::RenderStage> rs = new osgUtil::RenderStage;
|
||||
|
||||
osg::ColorMask* colorMask = previous_stage->getColorMask();
|
||||
rs->setColorMask(colorMask);
|
||||
|
||||
// set up the viewport.
|
||||
osg::Viewport* viewport = previous_stage->getViewport();
|
||||
rs->setViewport( viewport );
|
||||
|
||||
rs->setClearMask(GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// record the render bin, to be restored after creation
|
||||
// of the render to text
|
||||
osgUtil::RenderBin* previousRenderBin = cv->getCurrentRenderBin();
|
||||
|
||||
// set the current renderbin to be the newly created stage.
|
||||
cv->setCurrentRenderBin(rs.get());
|
||||
|
||||
// traverse the subgraph
|
||||
{
|
||||
Transform::traverse(nv);
|
||||
}
|
||||
|
||||
// restore the previous renderbin.
|
||||
cv->setCurrentRenderBin(previousRenderBin);
|
||||
|
||||
// and the render to texture stage to the current stages
|
||||
// dependancy list.
|
||||
cv->getCurrentRenderBin()->getStage()->addPostRenderStage(rs.get(),0);
|
||||
}
|
||||
}
|
||||
else if (nv.getVisitorType()==osg::NodeVisitor::EVENT_VISITOR)
|
||||
{
|
||||
int deltaFrameNumber = (nv.getFrameStamp()->getFrameNumber()-_previousFrameNumber);
|
||||
_previousFrameNumber = nv.getFrameStamp()->getFrameNumber();
|
||||
|
||||
bool needToRecordEventTime = false;
|
||||
bool needToAction = false;
|
||||
|
||||
if (deltaFrameNumber>1)
|
||||
{
|
||||
needToRecordEventTime = true;
|
||||
}
|
||||
|
||||
bool previous_displayTimeout = _displayTimeout;
|
||||
bool needToDismiss = false;
|
||||
|
||||
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(&nv);
|
||||
osgViewer::Viewer* viewer = ev ? dynamic_cast<osgViewer::Viewer*>(ev->getActionAdapter()) : 0;
|
||||
if (ev)
|
||||
{
|
||||
osgGA::EventQueue::Events& events = ev->getEvents();
|
||||
for(osgGA::EventQueue::Events::iterator itr = events.begin();
|
||||
itr != events.end();
|
||||
++itr)
|
||||
{
|
||||
osgGA::GUIEventAdapter* event = itr->get();
|
||||
|
||||
bool keyEvent = event->getEventType()==osgGA::GUIEventAdapter::KEYDOWN || event->getEventType()==osgGA::GUIEventAdapter::KEYUP;
|
||||
|
||||
if (keyEvent && event->getKey()==_keyStartsTimoutDisplay)
|
||||
{
|
||||
OSG_NOTICE<<"_keyStartsTimoutDisplay pressed"<<std::endl;
|
||||
_displayTimeout = true;
|
||||
}
|
||||
else if (keyEvent && event->getKey()==_keyDismissTimoutDisplay)
|
||||
{
|
||||
OSG_NOTICE<<"_keyDismissTimoutDisplay pressed"<<std::endl;
|
||||
needToRecordEventTime = true;
|
||||
needToDismiss = _displayTimeout;
|
||||
_displayTimeout = false;
|
||||
}
|
||||
else if (keyEvent && event->getKey()==_keyRunTimeoutAction)
|
||||
{
|
||||
OSG_NOTICE<<"_keyRunTimeoutAction pressed"<<std::endl;
|
||||
_displayTimeout = false;
|
||||
needToRecordEventTime = true;
|
||||
needToAction = true;
|
||||
}
|
||||
else if (event->getEventType()!=osgGA::GUIEventAdapter::FRAME)
|
||||
{
|
||||
needToRecordEventTime = true;
|
||||
needToDismiss = _displayTimeout;
|
||||
_displayTimeout = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (needToRecordEventTime)
|
||||
{
|
||||
_timeOfLastEvent = nv.getFrameStamp()->getReferenceTime();
|
||||
}
|
||||
|
||||
double timeSinceLastEvent = nv.getFrameStamp() ? nv.getFrameStamp()->getReferenceTime()-_timeOfLastEvent : 0.0;
|
||||
|
||||
if (timeSinceLastEvent>_idleDurationBeforeTimeoutDisplay)
|
||||
{
|
||||
_displayTimeout = true;
|
||||
}
|
||||
|
||||
if (timeSinceLastEvent>_idleDurationBeforeTimeoutAction)
|
||||
{
|
||||
_displayTimeout = false;
|
||||
needToAction = true;
|
||||
needToDismiss = false;
|
||||
}
|
||||
|
||||
if (!previous_displayTimeout && _displayTimeout)
|
||||
{
|
||||
if (viewer && (_displayBroadcastKeyPos._key!=0 || _displayBroadcastKeyPos._x!=FLT_MAX || _displayBroadcastKeyPos._y!=FLT_MAX))
|
||||
{
|
||||
OSG_NOTICE<<"Doing display broadcast key event"<<_displayBroadcastKeyPos._key<<std::endl;
|
||||
broadcastEvent(viewer, _displayBroadcastKeyPos);
|
||||
}
|
||||
|
||||
OperationVisitor leave(OperationVisitor::ENTER);
|
||||
accept(leave);
|
||||
|
||||
if (leave.sleepTime()!=0.0)
|
||||
{
|
||||
OSG_NOTICE<<"Pausing for "<<leave.sleepTime()<<std::endl;
|
||||
OpenThreads::Thread::microSleep(static_cast<unsigned int>(1000000.0*leave.sleepTime()));
|
||||
OSG_NOTICE<<"Finished Pause "<<std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (needToDismiss)
|
||||
{
|
||||
if (viewer && (_dismissBroadcastKeyPos._key!=0 || _dismissBroadcastKeyPos._x!=FLT_MAX || _dismissBroadcastKeyPos._y!=FLT_MAX))
|
||||
{
|
||||
OSG_NOTICE<<"Doing dismiss broadcast key event"<<_dismissBroadcastKeyPos._key<<std::endl;
|
||||
broadcastEvent(viewer, _dismissBroadcastKeyPos);
|
||||
}
|
||||
|
||||
OperationVisitor leave(OperationVisitor::LEAVE);
|
||||
accept(leave);
|
||||
}
|
||||
|
||||
Transform::traverse(nv);
|
||||
|
||||
|
||||
if (needToAction)
|
||||
{
|
||||
OSG_NOTICE<<"Do timeout action"<<std::endl;
|
||||
_previousFrameNumber = -1;
|
||||
_timeOfLastEvent = nv.getFrameStamp()->getReferenceTime();
|
||||
|
||||
|
||||
if (_actionJumpData.requiresJump())
|
||||
{
|
||||
OSG_NOTICE<<"Doing timeout jump"<<std::endl;
|
||||
_actionJumpData.jump(SlideEventHandler::instance());
|
||||
}
|
||||
|
||||
if (_actionKeyPos._key!=0 || _actionKeyPos._x!=FLT_MAX || _actionKeyPos._y!=FLT_MAX)
|
||||
{
|
||||
OSG_NOTICE<<"Doing timeout key event"<<_actionKeyPos._key<<std::endl;
|
||||
if (SlideEventHandler::instance()) SlideEventHandler::instance()->dispatchEvent(_actionKeyPos);
|
||||
}
|
||||
|
||||
if (viewer && (_actionBroadcastKeyPos._key!=0 || _actionBroadcastKeyPos._x!=FLT_MAX || _actionBroadcastKeyPos._y!=FLT_MAX))
|
||||
{
|
||||
OSG_NOTICE<<"Doing timeout broadcast key event"<<_actionBroadcastKeyPos._key<<std::endl;
|
||||
broadcastEvent(viewer, _actionBroadcastKeyPos);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else if (nv.getVisitorType()==osg::NodeVisitor::UPDATE_VISITOR)
|
||||
{
|
||||
if (_displayTimeout) Transform::traverse(nv);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strcmp(nv.className(),"FindOperatorsVisitor")==0)
|
||||
{
|
||||
OSG_NOTICE<<"Timout::traverse() "<<nv.className()<<", ignoring traversal"<<std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
Transform::traverse(nv);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user