Skip to content

Commit

Permalink
camera mount, i dont get it
Browse files Browse the repository at this point in the history
  • Loading branch information
vwaurich committed Aug 14, 2017
1 parent f43fad0 commit d66adad
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 4 deletions.
84 changes: 84 additions & 0 deletions OMEdit/OMEditGUI/Animation/AbstractAnimationWindow.cpp
Expand Up @@ -535,6 +535,8 @@ void AbstractAnimationWindow::openFMUSettingsDialog(VisualizerFMU* pVisualizerFM
*/
void AbstractAnimationWindow::updateScene()
{
std::cout<<"updateScene"<<std::endl;

if (!(mpVisualizer == NULL)) {
//set time label
if (!mpVisualizer->getTimeManager()->isPaused()) {
Expand All @@ -547,9 +549,91 @@ void AbstractAnimationWindow::updateScene()
mpAnimationSlider->blockSignals(state);
}
}
std::cout<<"updateScene2"<<std::endl;

//update the scene
mpVisualizer->sceneUpdate();
mpViewerWidget->update();
std::cout<<"updateScene3"<<std::endl;


if (mpVisualizer->getCamMountShape()==nullptr)
{
std::cout<<"NULL"<<std::endl;
}
else
{
std::cout<<"NOT NULL"<<std::endl;
}

if (mpVisualizer->getCamMountShape())
{
osg::Matrixd matObj = mpVisualizer->getCamMountShape()->_mat;
std::cout << "obj" << matObj(0, 0) << ", " << matObj(0, 1) << ", " << matObj(0, 2) << ", " << matObj(0, 3) << std::endl;
std::cout << " " << matObj(1, 0) << ", " << matObj(1, 1) << ", " << matObj(1, 2) << ", " << matObj(1, 3) << std::endl;
std::cout << " " << matObj(2, 0) << ", " << matObj(2, 1) << ", " << matObj(2, 2) << ", " << matObj(2, 3) << std::endl;
std::cout << " " << matObj(3, 0) << ", " << matObj(3, 1) << ", " << matObj(3, 2) << ", " << matObj(3, 3) << std::endl;
std::cout<<"DONE"<<std::endl;

osg::Matrixd maniMat = mpViewerWidget->getSceneView()->getCameraManipulator()->getMatrix();
std::cout << "mani" << maniMat(0, 0) << ", " << maniMat(0, 1) << ", " << maniMat(0, 2) << ", " << maniMat(0, 3) << std::endl;
std::cout << " " << maniMat(1, 0) << ", " << maniMat(1, 1) << ", " << maniMat(1, 2) << ", " << maniMat(1, 3) << std::endl;
std::cout << " " << maniMat(2, 0) << ", " << maniMat(2, 1) << ", " << maniMat(2, 2) << ", " << maniMat(2, 3) << std::endl;
std::cout << " " << maniMat(3, 0) << ", " << maniMat(3, 1) << ", " << maniMat(3, 2) << ", " << maniMat(3, 3) << std::endl;
std::cout<<"DONE"<<std::endl;

osg::Matrixd matCam = mpViewerWidget->getUmountedCamMatrix();
std::cout << "cam " << matCam(0, 0) << ", " << matCam(0, 1) << ", " << matCam(0, 2) << ", " << matCam(0, 3) << std::endl;
std::cout << " " << matCam(1, 0) << ", " << matCam(1, 1) << ", " << matCam(1, 2) << ", " << matCam(1, 3) << std::endl;
std::cout << " " << matCam(2, 0) << ", " << matCam(2, 1) << ", " << matCam(2, 2) << ", " << matCam(2, 3) << std::endl;
std::cout << " " << matCam(3, 0) << ", " << matCam(3, 1) << ", " << matCam(3, 2) << ", " << matCam(3, 3) << std::endl;
std::cout<<"DONE"<<std::endl;

osg::Vec3 center = matObj.getTrans();
osg::Vec3 eye = matCam.getTrans();
std::cout << "objgPos " << center[0] << ", " << center[1] << ", " << center[2] << std::endl;
std::cout << "camgPos " << eye[0] << ", " << eye[1] << ", " << eye[2] << std::endl;
osg::Vec3 up;
double dist = osg::Vec3((center-eye)).length();

std::cout<<"dist "<<dist<<std::endl;
matCam.getLookAt(eye,center,up,dist);
std::cout << "eye " << eye[0] << ", " << eye[1] << ", " << eye[2] << std::endl;
std::cout << "center " << center[0] << ", " << center[1] << ", " << center[2] << std::endl;
std::cout << "up " << up[0] << ", " << up[1] << ", " << up[2] << std::endl;

//center = center-matObj.getTrans();
//eye = eye-matObj.getTrans();
/*
center[0] = center[0]-matObj(3,0)+mpVisualizer->getCamMountMat0()(3,0);
center[1] = center[1]-matObj(3,1)+mpVisualizer->getCamMountMat0()(3,1);
center[2] = center[2]-matObj(3,2)+mpVisualizer->getCamMountMat0()(3,2);
eye[0] = eye[0]-matObj(3,0)+mpVisualizer->getCamMountMat0()(3,0);
eye[1] = eye[1]-matObj(3,1)+mpVisualizer->getCamMountMat0()(3,1);
eye[2] = eye[2]-matObj(3,2)+mpVisualizer->getCamMountMat0()(3,2);
*/
std::cout << "center2 " << center[0] << ", " << center[1] << ", " << center[2] << std::endl;
std::cout << "eye2 " << eye[0] << ", " << eye[1] << ", " << eye[2] << std::endl;

//osg::Matrixd mat3 = camManipulatorMat.lookAt(eye, center, osg::Vec3(0,1,0));
osg::Matrixd mat4 = matCam;
osg::Matrixd mat3 = maniMat;
mat3.makeLookAt(eye, center, up);
mat3 = mat3.translate(matObj.getTrans()+mat3.getTrans());

osg::Matrixd _mat = mat3;
std::cout << "mat " << _mat(0, 0) << ", " << _mat(0, 1) << ", " << _mat(0, 2) << ", " << _mat(0, 3) << std::endl;
std::cout << " " << _mat(1, 0) << ", " << _mat(1, 1) << ", " << _mat(1, 2) << ", " << _mat(1, 3) << std::endl;
std::cout << " " << _mat(2, 0) << ", " << _mat(2, 1) << ", " << _mat(2, 2) << ", " << _mat(2, 3) << std::endl;
std::cout << " " << _mat(3, 0) << ", " << _mat(3, 1) << ", " << _mat(3, 2) << ", " << _mat(3, 3) << std::endl;
std::cout<<"DONE"<<std::endl;

mpViewerWidget->getSceneView()->getCameraManipulator()->setByMatrix(mat3);
}
else{
std::cout<<"too bad"<<std::endl;
}
updateControlPanelValues();
}
}
Expand Down
48 changes: 45 additions & 3 deletions OMEdit/OMEditGUI/Animation/ViewerWidget.cpp
Expand Up @@ -68,7 +68,8 @@ void Viewer::setUpThreading()
* \param flags
*/
ViewerWidget::ViewerWidget(QWidget* parent, Qt::WindowFlags flags)
: GLWidget(parent, flags)
: GLWidget(parent, flags),
mCamIsMounted(false)
{
// Set the number of samples used for multisampling
#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
Expand Down Expand Up @@ -236,10 +237,10 @@ void ViewerWidget::pickShape(int x, int y)

if (!hitr->nodePath.empty() && !(hitr->nodePath.back()->getName().empty())) {
mSelectedShape = hitr->nodePath.back()->getName();
//std::cout<<"Object identified by name "<<mSelectedShape<<std::endl;
std::cout<<"Object identified by name "<<mSelectedShape<<std::endl;
} else if (hitr->drawable.valid()) {
mSelectedShape = hitr->drawable->className();
//std::cout<<"Object identified by its drawable "<<mSelectedShape<<std::endl;
std::cout<<"Object identified by its drawable "<<mSelectedShape<<std::endl;
}
}
}
Expand All @@ -263,6 +264,7 @@ void ViewerWidget::showShapePickContextMenu(const QPoint& pos)
QAction action4(QIcon(":/Resources/icons/checkered.svg"), tr("Apply Check Texture"), this);
QAction action5(QIcon(":/Resources/icons/texture.svg"), tr("Apply Custom Texture"), this);
QAction action6(QIcon(":/Resources/icons/undo.svg"), tr("Remove Texture"), this);
QAction action7(QIcon(":/Resources/icons/cam.svg"), tr("Mount/Unmount Camera"), this);

//if a shape is picked, we can set it transparent
if (0 != QString::compare(name,QString(""))) {
Expand All @@ -275,12 +277,15 @@ void ViewerWidget::showShapePickContextMenu(const QPoint& pos)
shapeMenu.addAction( &action4);
shapeMenu.addAction( &action5);
shapeMenu.addAction( &action6);
shapeMenu.addSeparator();
shapeMenu.addAction( &action7);
connect(&action1, SIGNAL(triggered()), this, SLOT(changeShapeTransparency()));
connect(&action2, SIGNAL(triggered()), this, SLOT(makeShapeInvisible()));
connect(&action3, SIGNAL(triggered()), this, SLOT(changeShapeColor()));
connect(&action4, SIGNAL(triggered()), this, SLOT(applyCheckTexture()));
connect(&action5, SIGNAL(triggered()), this, SLOT(applyCustomTexture()));
connect(&action6, SIGNAL(triggered()), this, SLOT(removeTexture()));
connect(&action7, SIGNAL(triggered()), this, SLOT(mountCamera()));
}
contextMenu.addAction(&action0);
connect(&action0, SIGNAL(triggered()), this, SLOT(removeTransparencyForAllShapes()));
Expand Down Expand Up @@ -335,6 +340,43 @@ void ViewerWidget::removeTexture()
}
}

/*!
* \brief ViewerWidget::mountCamera
*/
void ViewerWidget::mountCamera()
{
ShapeObject* shape = nullptr;
if ((shape = mpAnimationWidget->getVisualizer()->getBaseData()->getShapeObjectByID(mSelectedShape)))
{
//mUnmountedCam = getSceneView()->getCamera()->getViewMatrix();
mUnmountedCam = getSceneView()->getCameraManipulator()->getMatrix();

std::cout<<"when mounting mpUnmountedCam "<<mUnmountedCam.getTrans()[0]<<"-"<<mUnmountedCam.getTrans()[1]<<"-"<<mUnmountedCam.getTrans()[2]<<std::endl;
mCamIsMounted = true;
mpAnimationWidget->getVisualizer()->setCamMountShape(shape);
std::cout<<"when mounting set "<<mpAnimationWidget->getVisualizer()->getCamMountShape()->_id<<std::endl;
}
}

/*!
* \brief ViewerWidget::mountCamera
*/
void ViewerWidget::unmountCamera()
{
std::cout<<"unmount camera"<<std::endl;
mpAnimationWidget->getVisualizer()->setCamMountShape(nullptr);
mUnmountedCam = osg::Matrix::identity();
}

/*!
* \brief ViewerWidget::getUmountedCamMatrix
*/
osg::Matrixd ViewerWidget::getUmountedCamMatrix()
{
return mUnmountedCam;
}


/*!
* \brief ViewerWidget::applyCustomTexture
* adds a user-defiend texture to the shape
Expand Down
5 changes: 5 additions & 0 deletions OMEdit/OMEditGUI/Animation/ViewerWidget.h
Expand Up @@ -76,6 +76,7 @@ class ViewerWidget : public GLWidget
std::string getSelectedShape() {return mSelectedShape;}
void setSelectedShape(std::string shape) {mSelectedShape = shape;}
void pickShape(int x, int y);
osg::Matrixd getUmountedCamMatrix();
protected:
virtual void paintEvent(QPaintEvent *paintEvent);
virtual void paintGL();
Expand All @@ -95,6 +96,8 @@ class ViewerWidget : public GLWidget
osgViewer::View* mpSceneView;
std::string mSelectedShape;
AbstractAnimationWindow *mpAnimationWidget;
osg::Matrixd mUnmountedCam;
bool mCamIsMounted;
public slots:
void changeShapeTransparency();
void removeTransparencyForAllShapes();
Expand All @@ -103,6 +106,8 @@ public slots:
void applyCustomTexture();
void removeTexture();
void changeShapeColor();
void mountCamera();
void unmountCamera();

};

Expand Down
19 changes: 18 additions & 1 deletion OMEdit/OMEditGUI/Animation/Visualizer.cpp
Expand Up @@ -271,7 +271,8 @@ VisualizerAbstract::VisualizerAbstract()
: _visType(VisType::NONE),
mpOMVisualBase(nullptr),
mpOMVisScene(nullptr),
mpUpdateVisitor(nullptr)
mpUpdateVisitor(nullptr),
mpCamMountShape(nullptr)
{
mpTimeManager = new TimeManager(0.0, 0.0, 1.0, 0.0, 0.1, 0.0, 1.0);
}
Expand Down Expand Up @@ -385,7 +386,23 @@ void VisualizerAbstract::pauseVisualization()
mpTimeManager->setPause(true);
}

void VisualizerAbstract::setCamMountShape(ShapeObject* shape)
{
mpCamMountShape = shape;
mCamMountMat0 = shape->_mat;
std::cout<<"mounted shape "<<mpCamMountShape->_id<<std::endl;
}

ShapeObject* VisualizerAbstract::getCamMountShape()
{
return mpCamMountShape;
}


osg::Matrix VisualizerAbstract::getCamMountMat0()
{
return mCamMountMat0;
}


OMVisScene::OMVisScene()
Expand Down
8 changes: 8 additions & 0 deletions OMEdit/OMEditGUI/Animation/Visualizer.h
Expand Up @@ -170,6 +170,11 @@ class VisualizerAbstract
VisType getVisType() const;
OMVisScene* getOMVisScene() const;
std::string getModelFile() const;

void setCamMountShape(ShapeObject* shape);
ShapeObject* getCamMountShape();
osg::Matrix getCamMountMat0();

//virtual void setSimulationSettings(const UserSimSettingsFMU& simSetFMU) { };
//virtual void simulate(TimeManager& omvm) = 0;
virtual void startVisualization();
Expand All @@ -180,8 +185,11 @@ class VisualizerAbstract
OMVisScene* mpOMVisScene;
UpdateVisitor* mpUpdateVisitor;
TimeManager* mpTimeManager;
ShapeObject* mpCamMountShape;
osg::Matrix mCamMountMat0;
};


osg::Vec3f Mat3mulV3(osg::Matrix3 M, osg::Vec3f V);
osg::Vec3f V3mulMat3(osg::Vec3f V, osg::Matrix3 M);
osg::Matrix3 Mat3mulMat3(osg::Matrix3 M1, osg::Matrix3 M2);
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/resource_omedit.qrc
Expand Up @@ -183,5 +183,6 @@
<file>Resources/icons/completerCodeSnippets.svg</file>
<file>Resources/icons/array-parametric-plot-window.svg</file>
<file>Resources/icons/update.svg</file>
<file>Resources/icons/cam.svg</file>
</qresource>
</RCC>

0 comments on commit d66adad

Please sign in to comment.