static void copyCameraSettings(SoCamera* cam1, SbRotation& rot_cam1, SbVec3f& pos_cam1, SoCamera* cam2, SbRotation& rot_cam2, SbVec3f& pos_cam2) { // recompute the diff we have applied to the camera's orientation SbRotation rot = cam1->orientation.getValue(); SbRotation dif = rot * rot_cam1.inverse(); rot_cam1 = rot; // copy the values cam2->enableNotify(false); cam2->nearDistance = cam1->nearDistance; cam2->farDistance = cam1->farDistance; cam2->focalDistance = cam1->focalDistance; reorientCamera(cam2,dif); rot_cam2 = cam2->orientation.getValue(); // reverse engineer the translation part in wc SbVec3f pos = cam1->position.getValue(); SbVec3f difpos = pos - pos_cam1; pos_cam1 = pos; // the translation in pixel coords cam1->orientation.getValue().inverse().multVec(difpos,difpos); // the translation again in wc for the second camera cam2->orientation.getValue().multVec(difpos,difpos); cam2->position.setValue(cam2->position.getValue()+difpos); if (cam1->getTypeId() == cam2->getTypeId()) { if (cam1->getTypeId() == SoOrthographicCamera::getClassTypeId()) static_cast<SoOrthographicCamera*>(cam2)->height = static_cast<SoOrthographicCamera*>(cam1)->height; } cam2->enableNotify(true); }
/*! Should be called after motion matrix has been updated by a child dragger. */ void SoCenterballDragger::transferCenterDraggerMotion(SoDragger * childdragger) { if (coin_assert_cast<SoNode *>(childdragger) == XCenterChanger.getValue() || coin_assert_cast<SoNode *>(childdragger) == YCenterChanger.getValue() || coin_assert_cast<SoNode *>(childdragger) == ZCenterChanger.getValue()) { // translate part of matrix should not change. Move motion // into center instead. SbVec3f transl; SbMatrix matrix = this->getMotionMatrix(); transl[0] = matrix[3][0]; transl[1] = matrix[3][1]; transl[2] = matrix[3][2]; SbVec3f difftransl = transl - this->savedtransl; { // consider rotation before translating SbRotation rot = this->rotation.getValue(); SbMatrix tmp; tmp.setRotate(rot.inverse()); tmp.multVecMatrix(difftransl, difftransl); } this->centerFieldSensor->detach(); this->center = difftransl + this->savedcenter; this->centerFieldSensor->attach(&this->center); matrix[3][0] = this->savedtransl[0]; matrix[3][1] = this->savedtransl[1]; matrix[3][2] = this->savedtransl[2]; SbBool oldval = this->enableValueChangedCallbacks(FALSE); this->setMotionMatrix(matrix); this->enableValueChangedCallbacks(oldval); SoMatrixTransform *mt = SO_GET_ANY_PART(this, "translateToCenter", SoMatrixTransform); matrix.setTranslate(this->center.getValue()); mt->matrix = matrix; } }