+ code refactoring of View3DInventorPy::viewDefaultOrientation

This commit is contained in:
wmayer
2021-12-27 16:32:31 +01:00
parent cbede02dc5
commit 0bc96dfedd
3 changed files with 29 additions and 17 deletions

View File

@@ -361,7 +361,7 @@ Turntable: the part will be rotated around the z-axis.</string>
<item row="4" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>New document scale</string>
<string>Camera zoom</string>
</property>
</widget>
</item>

View File

@@ -738,22 +738,8 @@ Py::Object View3DInventorPy::viewDefaultOrientation(const Py::Tuple& args)
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View");
scale = hGrp->GetFloat("NewDocumentCameraScale",100.0);
}
if (scale > 1e-7) {
double f = 0.0; //focal dist
if (cam->isOfType(SoOrthographicCamera::getClassTypeId())){
static_cast<SoOrthographicCamera*>(cam)->height = scale;
f = scale;
} else if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())){
//nothing to do
double ang = static_cast<SoPerspectiveCamera*>(cam)->heightAngle.getValue();
f = 0.5 * scale / sin(ang * 0.5);
}
SbVec3f lookDir;
rot.multVec(SbVec3f(0,0,-1), lookDir);
SbVec3f pos = lookDir * -f;
cam->focalDistance = f;
cam->position = pos;
}
setDefaultCameraHeight(scale);
}
catch (const Base::Exception& e) {
throw Py::RuntimeError(e.what());
@@ -768,6 +754,31 @@ Py::Object View3DInventorPy::viewDefaultOrientation(const Py::Tuple& args)
return Py::None();
}
void View3DInventorPy::setDefaultCameraHeight(float scale)
{
if (scale > 1e-7) {
SoCamera* cam = getView3DIventorPtr()->getViewer()->getCamera();
SbRotation rot = cam->orientation.getValue();
double f = 0.0; //focal dist
if (cam->isOfType(SoOrthographicCamera::getClassTypeId())){
static_cast<SoOrthographicCamera*>(cam)->height = scale;
f = scale;
}
else if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())){
//nothing to do
double ang = static_cast<SoPerspectiveCamera*>(cam)->heightAngle.getValue();
f = 0.5 * scale / sin(ang * 0.5);
}
SbVec3f lookDir;
rot.multVec(SbVec3f(0,0,-1), lookDir);
SbVec3f pos = lookDir * -f;
cam->focalDistance = f;
cam->position = pos;
}
}
Py::Object View3DInventorPy::viewRotateLeft(const Py::Tuple& args)
{
if (!PyArg_ParseTuple(args.ptr(), ""))

View File

@@ -146,6 +146,7 @@ public:
Py::Object getCornerCrossSize(const Py::Tuple& args);
private:
void setDefaultCameraHeight(float);
static void eventCallback(void * ud, SoEventCallback * n);
static void eventCallbackPivy(void * ud, SoEventCallback * n);
static void eventCallbackPivyEx(void * ud, SoEventCallback * n);