diff --git a/OpenRoadEd/Osg/OSGCameraControls.h b/OpenRoadEd/Osg/OSGCameraControls.h index 9cdcb930b5a24174448e1ec423116784aa568dc4..4a689ef98edb4a3358b3560b69bf2e599d6ea1eb 100644 --- a/OpenRoadEd/Osg/OSGCameraControls.h +++ b/OpenRoadEd/Osg/OSGCameraControls.h @@ -59,4 +59,4 @@ -#endif \ No newline at end of file +#endif diff --git a/OpenRoadEd/Osg/OSGCameraControls2.cpp b/OpenRoadEd/Osg/OSGCameraControls2.cpp index 4ccd4a438511c7cfe979714128e26f463778b4df..2587eb0f1ef3d2ba70d4efe56e83f8f63dcbc5c4 100644 --- a/OpenRoadEd/Osg/OSGCameraControls2.cpp +++ b/OpenRoadEd/Osg/OSGCameraControls2.cpp @@ -5,6 +5,8 @@ OSGCameraControls2::OSGCameraControls2() { mSpaceIsPressed=false; + mNode=NULL; + mParkingNode=NULL; } OSGCameraControls2::~OSGCameraControls2() {} @@ -23,6 +25,10 @@ void OSGCameraControls2::setNode(osg::Node* node) } if (getAutoComputeHomePosition()) computeHomePosition(); } +void OSGCameraControls2::setParkingNode(osg::Node* node) +{ + mParkingNode = node; +} const osg::Node* OSGCameraControls2::getNode() const { return mNode.get(); @@ -31,7 +37,10 @@ osg::Node* OSGCameraControls2::getNode() { return mNode.get(); } - +osg::Node* OSGCameraControls2::getParkingNode() +{ + return mParkingNode.get(); +} /** * Home methods (inherited from the matrix manipulator) */ @@ -50,11 +59,12 @@ void OSGCameraControls2::computeHomePosition() { double x,y,z,width,height; - if(getNode()) + if(getNode() && getParkingNode()) { osg::ref_ptr<osg::ComputeBoundsVisitor> cbv = new osg::ComputeBoundsVisitor(); //attach the compute bounds visitor to the node getNode()->accept(*cbv); + getParkingNode()->accept(*cbv); osg::BoundingBox bb(cbv->getBoundingBox()); x=(bb.xMax()+bb.xMin())/2.0; y=(bb.yMax()+bb.yMin())/2.0; diff --git a/OpenRoadEd/Osg/OSGCameraControls2.h b/OpenRoadEd/Osg/OSGCameraControls2.h index 063098017ef6c70c0390397a202e764b94fb2604..02c1085456a55222238fe2dd5ac3eb492ff70489 100644 --- a/OpenRoadEd/Osg/OSGCameraControls2.h +++ b/OpenRoadEd/Osg/OSGCameraControls2.h @@ -25,8 +25,10 @@ public: * Usually the root node */ virtual void setNode(osg::Node* node); + void setParkingNode(osg::Node* node); virtual const osg::Node* getNode() const; virtual osg::Node* getNode(); + osg::Node* getParkingNode(); /** * Home methods (inherited from the matrix manipulator) @@ -88,6 +90,7 @@ protected: * Node reference */ osg::ref_ptr<osg::Node> mNode; + osg::ref_ptr<osg::Node> mParkingNode; /** * Camera position, rotation diff --git a/OpenRoadEd/Osg/OSGMain.cpp b/OpenRoadEd/Osg/OSGMain.cpp index ec693b14b1c5c3d08c3449eb10f6f5b6e0b2570b..c06cb4b16dd224f5f479a6824b1d8d0b821076e4 100644 --- a/OpenRoadEd/Osg/OSGMain.cpp +++ b/OpenRoadEd/Osg/OSGMain.cpp @@ -109,6 +109,7 @@ void OSGMain::initViewer(QOSGWidget *viewer) // lala viewer->getCameraManipulator()->setNode(mRoadsGroup); +// ((OSGCameraControls2 *)viewer->getCameraManipulator())->setParkingNode(mRecordsHelpersGroup); } /** @@ -963,6 +964,7 @@ void OSGMain::GetBoundingBox(double &x,double &y,double &width,double &height) osg::ref_ptr<osg::ComputeBoundsVisitor> cbv = new osg::ComputeBoundsVisitor(); //attach the compute bounds visitor to the node this->mRoadsGroup->accept(*cbv); + this->mRecordsHelpersGroup->accept(*cbv); osg::BoundingBox bb(cbv->getBoundingBox()); x=(bb.xMax()+bb.xMin())/2.0; diff --git a/OpenRoadEd/Osg/OSGRecordsHelpers.cpp b/OpenRoadEd/Osg/OSGRecordsHelpers.cpp index dc8cc6fcceb187916f63ce2a0616174d815d849e..59f200421bee25871577d51c85a85cd40179b3df 100644 --- a/OpenRoadEd/Osg/OSGRecordsHelpers.cpp +++ b/OpenRoadEd/Osg/OSGRecordsHelpers.cpp @@ -564,6 +564,7 @@ osg::ref_ptr<osg::MatrixTransform> OSGRecordsHelpers::AddParkingHelper(Object *o x-=object->GetT()*sin(hdg); y+=object->GetT()*cos(hdg); + std::cout << "Z: " << elevation+object->GetZOffset() << std::endl; matrix->setMatrix(osg::Matrix::rotate(osg::inRadians(hdg+object->GetHeading()), osg::Vec3(0.0, 0.0, 1.0)) * osg::Matrix::translate(osg::Vec3(x,y,elevation+object->GetZOffset())) ); matrix->addChild(parkingGeode); diff --git a/OpenRoadEd/Qt/QOSGWidget.cpp b/OpenRoadEd/Qt/QOSGWidget.cpp index facf5d2378f05a85d439cf176afcf73767f8cf35..3bf8cab1d5a1de92885106d509f0ab05de4ddc52 100644 --- a/OpenRoadEd/Qt/QOSGWidget.cpp +++ b/OpenRoadEd/Qt/QOSGWidget.cpp @@ -1,6 +1,5 @@ #include "QOSGWidget.h" #include "moc_QOSGWidget.cpp" -#include "OSGCameraControls2.h" #include <osgGA/KeySwitchMatrixManipulator> #define SCREENSHOT_WIDTH 7000 @@ -24,6 +23,8 @@ QOSGWidget::QOSGWidget(OSGMain *osgMain, QWidget * parent, const char * name, Qt this->setThreadingModel(osgViewer::Viewer::SingleThreaded); this->setKeyEventSetsDone(0); + camera_controls=new OSGCameraControls2(); + display=addViewWidget(this->createGraphicsWindow(0,0,100,100)); QHBoxLayout* layout=new QHBoxLayout; layout->addWidget(display); @@ -60,6 +61,7 @@ QOSGWidget::QOSGWidget(OSGMain *osgMain, QWidget * parent, const char * name, Qt _timer.start(10); mOsgMain=osgMain; + camera_controls->setParkingNode(mOsgMain->mRecordsHelpersGroup); } QWidget* QOSGWidget::addViewWidget(osgQt::GraphicsWindowQt* gw) @@ -83,7 +85,7 @@ QWidget* QOSGWidget::addViewWidget(osgQt::GraphicsWindowQt* gw) this->addEventHandler(new osgViewer::ThreadingHandler); osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator=new osgGA::KeySwitchMatrixManipulator; - keyswitchManipulator->addMatrixManipulator('6',"Own2",new OSGCameraControls2()); + keyswitchManipulator->addMatrixManipulator('6',"Own2",camera_controls); this->setCameraManipulator(keyswitchManipulator.get()); //gw->setTouchEventsEnabled( true ); return gw->getGLWidget(); diff --git a/OpenRoadEd/Qt/QOSGWidget.h b/OpenRoadEd/Qt/QOSGWidget.h index 5c19574534a0a31a637d40cbdbbbd7c4bbba889f..d8405d71d08e1df5a375004bdff0c8d4886204fe 100644 --- a/OpenRoadEd/Qt/QOSGWidget.h +++ b/OpenRoadEd/Qt/QOSGWidget.h @@ -12,6 +12,7 @@ #include <osgGA/MultiTouchTrackballManipulator> #include <osgDB/ReadFile> #include <osgQt/GraphicsWindowQt> +#include "OSGCameraControls2.h" #include <sys/stat.h> #include <sys/types.h> @@ -85,6 +86,8 @@ private: */ OSGMain *mOsgMain; + OSGCameraControls2 *camera_controls; + //Class with methods needed to take the screenshots osg::ref_ptr<OSGScreenshotRequest> mScreenshotRequest; diff --git a/Samples/sample.xodr b/Samples/sample.xodr index 9c73d95e41f970daf7024e29c4a5c61fac22cb7d..f062543148b4838e3971e82faea3f5ae7c5f30f0 100644 --- a/Samples/sample.xodr +++ b/Samples/sample.xodr @@ -411,7 +411,7 @@ </lanes> <objects> <object s="3.0000000000000000e+01" t="-1.2000000000000000e+01" id="perimeter3" name="perimeter3" dynamic="no" orientation="none" zOffset="2.5000000000000000e+00" validLength="0.0000000000000000e+00" type="none" hdg="0.0000000000000000e+00" pitch="0.0000000000000000e+00" roll="0.0000000000000000e+00" length="5.0000000000000000e+00" width="1.0000000000000000e+02" height="5.0000000000000000e+00" /> - <object s="3.0000000000000000e+01" t="-6.0000000000000000e+00" id="2" name="parkingslot2" dynamic="no" orientation="none" zOffset="2.5000000000000000e+00" validLength="0.0000000000000000e+00" type="parkingSpace" hdg="0.0000000000000000e+00" pitch="0.0000000000000000e+00" roll="0.0000000000000000e+00" length="1.0000000000000000e+01" width="4.2000000000000002e+00" height="5.0000000000000000e+00"> + <object s="3.0000000000000000e+01" t="-6.5000000000000000e+00" id="2" name="parkingslot2" dynamic="no" orientation="none" zOffset="0.0000000000000000e+00" validLength="0.0000000000000000e+00" type="parkingSpace" hdg="0.0000000000000000e+00" pitch="0.0000000000000000e+00" roll="0.0000000000000000e+00" length="1.0000000000000000e+01" width="4.2000000000000002e+00" height="5.0000000000000000e+00"> <parkingSpace access="all" restrictions="none"> <marking side="front" type="solid" width="1.4999999999999999e-01" color="standard" /> </parkingSpace>