FreeCAD-VR: Positional light and fix in camera positioning
This commit is contained in:
parent
4c7fb2d0f0
commit
9a19baa8f5
|
@ -95,7 +95,24 @@ CoinRiftWidget::CoinRiftWidget() : QGLWidget()
|
|||
std::max(recommenedTex1Size.h, recommenedTex1Size.h)));
|
||||
m_sceneManager->setBackgroundColor(SbColor(.0f, .0f, .8f));
|
||||
#endif
|
||||
basePosition = SbVec3f(0.0f, 0.0f, 5.0f);
|
||||
basePosition = SbVec3f(0.0f, 0.0f, -2.0f);
|
||||
// light handling
|
||||
SoGroup *lightGroup = new SoGroup;
|
||||
|
||||
SoTranslation *lightTranslation1 = new SoTranslation;
|
||||
lightTranslation1->translation.setValue(0,1,1);
|
||||
lightGroup->addChild (lightTranslation1);
|
||||
|
||||
SoDirectionalLight *light = new SoDirectionalLight();
|
||||
lightGroup->addChild (light);
|
||||
|
||||
SoTranslation *lightTranslation2 = new SoTranslation;
|
||||
lightTranslation2->translation.setValue(0,-1,-1);
|
||||
lightGroup->addChild (lightTranslation2);
|
||||
|
||||
|
||||
//translation->translation.setValue(0,-1,0);
|
||||
//workplace->addChild(translation);
|
||||
|
||||
scene = new SoSeparator(0); // Placeholder.
|
||||
for (int eye = 0; eye < 2; eye++) {
|
||||
|
@ -106,7 +123,7 @@ CoinRiftWidget::CoinRiftWidget() : QGLWidget()
|
|||
camera[eye]->focalDistance.setValue(5.0f);
|
||||
camera[eye]->viewportMapping.setValue(SoCamera::LEAVE_ALONE);
|
||||
rootScene[eye]->addChild(camera[eye]);
|
||||
rootScene[eye]->addChild(new SoDirectionalLight()); // TODO Connect direction to camera.
|
||||
rootScene[eye]->addChild(lightGroup); // TODO Connect direction to camera.
|
||||
rootScene[eye]->addChild(scene);
|
||||
}
|
||||
|
||||
|
@ -159,16 +176,17 @@ CoinRiftWidget::CoinRiftWidget() : QGLWidget()
|
|||
qDebug() << "Could not configure OVR rendering.";
|
||||
throw;
|
||||
}
|
||||
static const float nearPlane = 0.01;
|
||||
|
||||
for (int eye = 0; eye < 2; eye++) {
|
||||
camera[eye]->aspectRatio.setValue((eyeRenderDesc[eye].Fov.LeftTan + eyeRenderDesc[eye].Fov.RightTan) /
|
||||
(eyeRenderDesc[eye].Fov.UpTan + eyeRenderDesc[eye].Fov.DownTan));
|
||||
camera[eye]->nearDistance.setValue(1.0f);
|
||||
camera[eye]->farDistance.setValue(100.0f);
|
||||
camera[eye]->left.setValue(-eyeRenderDesc[eye].Fov.LeftTan);
|
||||
camera[eye]->right.setValue(eyeRenderDesc[eye].Fov.RightTan);
|
||||
camera[eye]->top.setValue(eyeRenderDesc[eye].Fov.UpTan);
|
||||
camera[eye]->bottom.setValue(-eyeRenderDesc[eye].Fov.DownTan);
|
||||
camera[eye]->nearDistance.setValue(nearPlane);
|
||||
camera[eye]->farDistance.setValue(10000.0f);
|
||||
camera[eye]->left.setValue(-eyeRenderDesc[eye].Fov.LeftTan * nearPlane);
|
||||
camera[eye]->right.setValue(eyeRenderDesc[eye].Fov.RightTan * nearPlane);
|
||||
camera[eye]->top.setValue(eyeRenderDesc[eye].Fov.UpTan * nearPlane);
|
||||
camera[eye]->bottom.setValue(-eyeRenderDesc[eye].Fov.DownTan * nearPlane);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -202,6 +220,13 @@ CoinRiftWidget::~CoinRiftWidget()
|
|||
}
|
||||
|
||||
|
||||
void CoinRiftWidget::setBackgroundColor(const SbColor &Col)
|
||||
{
|
||||
BackgroundColor = Col;
|
||||
renderer->setBackgroundColor(BackgroundColor);
|
||||
}
|
||||
|
||||
|
||||
void CoinRiftWidget::setSceneGraph(SoNode *sceneGraph)
|
||||
{
|
||||
rootScene[0]->replaceChild(scene, sceneGraph);
|
||||
|
@ -324,15 +349,23 @@ void CoinRiftWidget::paintGL()
|
|||
eyePose[eye].Position.y,
|
||||
eyePose[eye].Position.z);
|
||||
|
||||
//Base::Console().Log("Pos: (%d) %f, %f, %f \n",eye, eyePose[eye].Position.x,
|
||||
// eyePose[eye].Position.y,
|
||||
// eyePose[eye].Position.z);
|
||||
|
||||
//SbVec3f originalPosition(camera[eye]->position.getValue());
|
||||
SbVec3f viewAdjust(eyeRenderDesc[eye].ViewAdjust.x,
|
||||
eyeRenderDesc[eye].ViewAdjust.y,
|
||||
eyeRenderDesc[eye].ViewAdjust.z);
|
||||
|
||||
camera[eye]->position.setValue(basePosition - SbVec3f(eyeRenderDesc[eye].ViewAdjust.x,
|
||||
eyeRenderDesc[eye].ViewAdjust.y,
|
||||
eyeRenderDesc[eye].ViewAdjust.z) + riftPosition);
|
||||
riftOrientation.multVec(viewAdjust,viewAdjust);
|
||||
|
||||
camera[eye]->position.setValue(basePosition - viewAdjust + riftPosition);
|
||||
//camera[eye]->position.setValue(basePosition - riftPosition);
|
||||
|
||||
//Base::Console().Log("Eye(%d) Pos: %f, %f, %f ViewAdjust: %f, %f, %f \n",eye, eyePose[eye].Position.x,
|
||||
// eyePose[eye].Position.y,
|
||||
// eyePose[eye].Position.z,
|
||||
// eyeRenderDesc[eye].ViewAdjust.x,
|
||||
// eyeRenderDesc[eye].ViewAdjust.y,
|
||||
// eyeRenderDesc[eye].ViewAdjust.z);
|
||||
|
||||
#ifdef USE_SO_OFFSCREEN_RENDERER
|
||||
ovrGLTextureData *texData = reinterpret_cast<ovrGLTextureData*>(&eyeTexture[eye]);
|
||||
|
|
|
@ -97,7 +97,7 @@ public:
|
|||
~CoinRiftWidget();
|
||||
virtual void setSceneGraph(SoNode *sceneGraph);
|
||||
void setBase(const SbVec3f &pos){basePosition=pos;}
|
||||
void setBackgoundColor(const SbColor &Col){BackgroundColor = Col;}
|
||||
void setBackgroundColor(const SbColor &Col);
|
||||
|
||||
SbVec3f basePosition;
|
||||
SbRotation baseOrientation;
|
||||
|
@ -109,6 +109,7 @@ protected:
|
|||
void resizeGL(int width, int height);
|
||||
|
||||
SbColor BackgroundColor;
|
||||
SoTranslation *lightTranslation;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -37,15 +37,24 @@ using namespace Gui;
|
|||
View3DInventorRiftViewer::View3DInventorRiftViewer() : CoinRiftWidget()
|
||||
{
|
||||
workplace = new SoGroup();
|
||||
translation = new SoTranslation ;
|
||||
rotation = new SoRotationXYZ ;
|
||||
rotation->axis.setValue(SoRotationXYZ::X);
|
||||
rotation->angle.setValue(M_PI/4);
|
||||
workplace->addChild(rotation);
|
||||
|
||||
//translation = new SoTranslation ;
|
||||
//translation->translation.setValue(0,-1,0);
|
||||
//workplace->addChild(translation);
|
||||
|
||||
rotation1 = new SoRotationXYZ ;
|
||||
rotation1->axis.setValue(SoRotationXYZ::X);
|
||||
rotation1->angle.setValue(M_PI/2);
|
||||
workplace->addChild(rotation1);
|
||||
|
||||
rotation2 = new SoRotationXYZ ;
|
||||
rotation2->axis.setValue(SoRotationXYZ::Z);
|
||||
rotation2->angle.setValue(0);
|
||||
workplace->addChild(rotation2);
|
||||
|
||||
|
||||
scale = new SoScale ;
|
||||
scale->scaleFactor.setValue(0.01f,0.01f,0.01f); // scale from mm to m as neede by the Rift
|
||||
scale->scaleFactor.setValue(0.001f,0.001f,0.001f); // scale from mm to m as neede by the Rift
|
||||
workplace->addChild(scale);
|
||||
|
||||
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Oculus");
|
||||
|
@ -56,7 +65,9 @@ View3DInventorRiftViewer::View3DInventorRiftViewer() : CoinRiftWidget()
|
|||
hGrp->GetInt("RenderWindowSizeH",1080)
|
||||
);
|
||||
|
||||
|
||||
|
||||
setBackgroundColor(SbColor(51,51,101));
|
||||
basePosition = SbVec3f(0.0f, 0.5f, 0.5f);
|
||||
}
|
||||
|
||||
//void saveWinPostion(void)
|
||||
|
@ -93,10 +104,32 @@ void View3DInventorRiftViewer::setSceneGraph(SoNode *sceneGraph)
|
|||
|
||||
void View3DInventorRiftViewer::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if ((event->key() == Qt::Key_Delete
|
||||
|| event->key() == Qt::Key_Backspace)) {
|
||||
; // TODO
|
||||
static const float increment = 0.02; // move two centimeter per key
|
||||
static const float rotIncrement = M_PI/4; // move two 90° per key
|
||||
|
||||
|
||||
if (event->key() == Qt::Key_Plus) {
|
||||
scale->scaleFactor.setValue(scale->scaleFactor.getValue() * 2.0f) ;
|
||||
} else if (event->key() == Qt::Key_Minus) {
|
||||
scale->scaleFactor.setValue(scale->scaleFactor.getValue() * 0.2f) ;
|
||||
} else if (event->key() == Qt::Key_S) {
|
||||
basePosition += SbVec3f(0,0,increment) ;
|
||||
} else if (event->key() == Qt::Key_W) {
|
||||
basePosition += SbVec3f(0,0,-increment) ;
|
||||
} else if (event->key() == Qt::Key_Up) {
|
||||
basePosition += SbVec3f(0,-increment,0) ;
|
||||
} else if (event->key() == Qt::Key_Down) {
|
||||
basePosition += SbVec3f(0,increment,0) ;
|
||||
} else if (event->key() == Qt::Key_Left) {
|
||||
rotation2->angle.setValue( rotation2->angle.getValue() + rotIncrement);
|
||||
} else if (event->key() == Qt::Key_Right) {
|
||||
rotation2->angle.setValue( rotation2->angle.getValue() - rotIncrement);
|
||||
} else if (event->key() == Qt::Key_A) {
|
||||
basePosition += SbVec3f(-increment,0,0) ;
|
||||
} else if (event->key() == Qt::Key_D) {
|
||||
basePosition += SbVec3f(increment,0,0) ;
|
||||
} else {
|
||||
|
||||
CoinRiftWidget::keyPressEvent(event);
|
||||
}
|
||||
}
|
||||
|
@ -156,9 +189,9 @@ void oculusStop()
|
|||
if(window){
|
||||
delete window;
|
||||
window = 0;
|
||||
ovr_Shutdown();
|
||||
}
|
||||
|
||||
ovr_Shutdown();
|
||||
}
|
||||
|
||||
bool oculusUp(void)
|
||||
|
|
|
@ -40,7 +40,8 @@ public:
|
|||
protected:
|
||||
SoGroup *workplace;
|
||||
SoTranslation *translation;
|
||||
SoRotationXYZ *rotation;
|
||||
SoRotationXYZ *rotation1;
|
||||
SoRotationXYZ *rotation2;
|
||||
SoScale *scale;
|
||||
|
||||
protected:
|
||||
|
|
Loading…
Reference in New Issue
Block a user