void coTouchIntersection::intersect(const osg::Matrix &handMat, bool mouseHit) { cerr << "coTouchIntersection::intersect info: called" << endl; Vec3 q0, q1, q2, q3, q4, q5; // 3 line segments for interscetion test hand-object // of course this test can fail q0.set(0.0f, -0.5f * handSize, 0.0f); q1.set(0.0f, 0.5f * handSize, 0.0f); q2.set(-0.5f * handSize, 0.0f, 0.0f); q3.set(0.5f * handSize, 0.0f, 0.0f); q4.set(0.0f, 0.0f, -0.5f * handSize); q5.set(0.0f, 0.0f, 0.5f * handSize); // xform the intersection line segment q0 = handMat.preMult(q0); q1 = handMat.preMult(q1); q2 = handMat.preMult(q2); q3 = handMat.preMult(q3); q4 = handMat.preMult(q4); q5 = handMat.preMult(q5); ref_ptr<LineSegment> ray1 = new LineSegment(); ref_ptr<LineSegment> ray2 = new LineSegment(); ref_ptr<LineSegment> ray3 = new LineSegment(); ray1->set(q0, q1); ray2->set(q2, q3); ray3->set(q4, q5); IntersectVisitor visitor; visitor.addLineSegment(ray1.get()); visitor.addLineSegment(ray2.get()); visitor.addLineSegment(ray3.get()); cover->getScene()->traverse(visitor); ref_ptr<LineSegment> hitRay = 0; if (visitor.getNumHits(ray1.get())) hitRay = ray1; else if (visitor.getNumHits(ray2.get())) hitRay = ray2; else if (visitor.getNumHits(ray3.get())) hitRay = ray3; if (visitor.getNumHits(hitRay.get())) { Hit hitInformation = visitor.getHitList(hitRay.get()).front(); cover->intersectionHitPointWorld = hitInformation.getWorldIntersectPoint(); cover->intersectionHitPointLocal = hitInformation.getLocalIntersectPoint(); cover->intersectionMatrix = hitInformation._matrix; cover->intersectedNode = hitInformation._geode; // walk up to the root and call all coActions OSGVruiHit hit(hitInformation, mouseHit); OSGVruiNode node(cover->intersectedNode.get()); callActions(&node, &hit); } }
bool GeoTransform::ComputeMatrixCallback::computeLocalToWorldMatrix(const GeoTransform* xform, osg::Matrix& m, osg::NodeVisitor* nv) const { if (xform->getReferenceFrame() == xform->RELATIVE_RF) m.preMult(xform->getMatrix()); else m = xform->getMatrix(); return true; }
//src/Viewer/SkyBox.cpp:111: Is this a non-const reference? If so, make const or use a pointer: osg::Matrix& matrix [runtime/references] [2] virtual bool computeLocalToWorldMatrix( osg::Matrix& matrix,osg::NodeVisitor* nv ) const { osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>( nv ); if ( cv ) { osg::Vec3 eyePointLocal = cv->getEyeLocal(); matrix.preMult( osg::Matrix::translate( eyePointLocal ) ); } return true; }
bool SkyBox::computeLocalToWorldMatrix( osg::Matrix& matrix, osg::NodeVisitor* nv ) const { if ( nv && nv->getVisitorType()==osg::NodeVisitor::CULL_VISITOR ) { osgUtil::CullVisitor* cv = static_cast<osgUtil::CullVisitor*>( nv ); matrix.preMult( osg::Matrix::translate(cv->getEyeLocal()) ); return true; } else return osg::Transform::computeLocalToWorldMatrix( matrix, nv ); }
virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor*) const { if (_referenceFrame==RELATIVE_RF) { matrix.preMult(getMatrix()); } else // absolute { matrix = getMatrix(); } return true; }
bool AntiSquish::computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const { osg::Matrix unsquishedMatrix; if ( !computeUnSquishedMatrix( nv, unsquishedMatrix ) ) return Transform::computeLocalToWorldMatrix( matrix, nv ); if (_referenceFrame==RELATIVE_RF) { matrix.preMult(unsquishedMatrix); } else // absolute { matrix = unsquishedMatrix; } return true; }
bool AntiSquish::computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor* /*nv*/) const { osg::Matrix unsquishedMatrix; if ( !computeUnSquishedMatrix( unsquishedMatrix ) ) { return false; } if (_referenceFrame==RELATIVE_RF) { matrix.preMult(unsquishedMatrix); } else // absolute { matrix = unsquishedMatrix; } return true; }
bool AbsoluteModelTransform::computeLocalToWorldMatrix( osg::Matrix& matrix, osg::NodeVisitor* nv ) const { if( getReferenceFrame() == osg::Transform::ABSOLUTE_RF ) { osg::Matrix view; if( !nv ) osg::notify( osg::INFO ) << "AbsoluteModelTransform: NULL NodeVisitor; can't get view." << std::endl; else if( nv->getVisitorType() != osg::NodeVisitor::CULL_VISITOR ) osg::notify( osg::INFO ) << "AbsoluteModelTransform: NodeVisitor is not CullVisitor; can't get view." << std::endl; else { osgUtil::CullVisitor* cv = dynamic_cast< osgUtil::CullVisitor* >( nv ); #ifdef SCENEVIEW_ANAGLYPHIC_STEREO_SUPPORT // If OSG_STEREO=ON is in the environment, SceneView hides the view matrix // in a stack rather than placing it in a Camera node. Enable this code // (using CMake) to use a less-efficient way to compute the view matrix that // is compatible with SceneView's usage. osg::NodePath np = nv->getNodePath(); np.pop_back(); osg::Matrix l2w = osg::computeLocalToWorld( np ); osg::Matrix invL2w = osg::Matrix::inverse( l2w ); view = invL2w * *( cv->getModelViewMatrix() ); #else // Faster way to determine the view matrix, but not compatible with // SceneView anaglyphic stereo. osg::Camera* cam = cv->getCurrentCamera(); cam->computeLocalToWorldMatrix( view, cv ); #endif } matrix = ( _matrix * view ); } else // RELATIVE_RF matrix.preMult(_matrix); return( true ); }
bool DOFTransform::computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor*) const { //put the PUT matrix first: osg::Matrix l2w(getPutMatrix()); //now the current matrix: osg::Matrix current; current.makeTranslate(getCurrentTranslate()); //now create the local rotation: if(_multOrder == PRH) { current.preMult(osg::Matrix::rotate(getCurrentHPR()[1], 1.0, 0.0, 0.0));//pitch current.preMult(osg::Matrix::rotate(getCurrentHPR()[2], 0.0, 1.0, 0.0));//roll current.preMult(osg::Matrix::rotate(getCurrentHPR()[0], 0.0, 0.0, 1.0));//heading } else if(_multOrder == PHR) { current.preMult(osg::Matrix::rotate(getCurrentHPR()[1], 1.0, 0.0, 0.0));//pitch current.preMult(osg::Matrix::rotate(getCurrentHPR()[0], 0.0, 0.0, 1.0));//heading current.preMult(osg::Matrix::rotate(getCurrentHPR()[2], 0.0, 1.0, 0.0));//roll } else if(_multOrder == HPR) { current.preMult(osg::Matrix::rotate(getCurrentHPR()[0], 0.0, 0.0, 1.0));//heading current.preMult(osg::Matrix::rotate(getCurrentHPR()[1], 1.0, 0.0, 0.0));//pitch current.preMult(osg::Matrix::rotate(getCurrentHPR()[2], 0.0, 1.0, 0.0));//roll } else if(_multOrder == HRP) { current.preMult(osg::Matrix::rotate(getCurrentHPR()[0], 0.0, 0.0, 1.0));//heading current.preMult(osg::Matrix::rotate(getCurrentHPR()[2], 0.0, 1.0, 0.0));//roll current.preMult(osg::Matrix::rotate(getCurrentHPR()[1], 1.0, 0.0, 0.0));//pitch } else if(_multOrder == RHP) { current.preMult(osg::Matrix::rotate(getCurrentHPR()[2], 0.0, 1.0, 0.0));//roll current.preMult(osg::Matrix::rotate(getCurrentHPR()[0], 0.0, 0.0, 1.0));//heading current.preMult(osg::Matrix::rotate(getCurrentHPR()[1], 1.0, 0.0, 0.0));//pitch } else // _multOrder == RPH { current.preMult(osg::Matrix::rotate(getCurrentHPR()[2], 0.0, 1.0, 0.0));//roll current.preMult(osg::Matrix::rotate(getCurrentHPR()[1], 1.0, 0.0, 0.0));//pitch current.preMult(osg::Matrix::rotate(getCurrentHPR()[0], 0.0, 0.0, 1.0));//heading } //and scale: current.preMultScale(getCurrentScale()); l2w.postMult(current); //and impose inverse put: l2w.postMult(getInversePutMatrix()); // finally. if (_referenceFrame==RELATIVE_RF) { matrix.preMult(l2w); } else { matrix = l2w; } return true; }
// ================================================ // convertRotMtxToEuler // vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv void convertRotMtxToEuler( const osg::Matrix &m, osg::Vec3 &euler ) { osg::Vec3 yaxis( 0., 1., 0. ), zaxis( 0., 0., 1. ); float heading, pitch, roll; osg::Vec3 headingv, pitchv, hpnormalv, v; pitchv = m.preMult( yaxis ); headingv = pitchv; // zero-out the z component headingv[2] = 0.; // normalize headingv.normalize(); ///////////////////////////////////////////////////////////////// // HEADING ///////////////////////////////////////////////////////////////// // the dot product of the two vectors will get us the cosine of the // angle between them float cosH = headingv * yaxis; // dot product ARCCOS_SANITY( cosH ) heading = acos(cosH); // the cross product of the two vectors will get us the vector normal // to them v = headingv ^ yaxis; // cross product if( v[2] > 0. ) { heading *= -1.; } ///////////////////////////////////////////////////////////////// // PITCH ///////////////////////////////////////////////////////////////// float cosP = pitchv * headingv; // dot product ARCCOS_SANITY( cosP ) pitch = acos(cosP); if( pitchv[2] < 0. ) { pitch *= -1.; } ///////////////////////////////////////////////////////////////// // ROLL ///////////////////////////////////////////////////////////////// hpnormalv = pitchv ^ headingv; hpnormalv.normalize(); // If pitch is negative, hpnormalv will point in the "wrong" direction. // In this situation, we'll negate hpnormalv. If we didn't do this, // we'd get roll values that change sign as pitch changes from positive to // negative or vice versa (yuck). if( pitch < 0. ) hpnormalv *= -1.; osg::Vec3 zm; zm = m.preMult( zaxis ); /* cout << "vv color " << "zm" << " 0.5 0.5 1.0\n"; cout << "vv set zm " << zm << endl; cout << "vv color pitchv 1 0 1\n"; cout << "vv set pitchv " << pitchv << endl; cout << "vv color headingv 1 .5 1\n"; cout << "vv set headingv " << headingv << endl; cout << "vv color " << "hpnormalv" << " 1. 1. 1.\n"; cout << "vv set hpnormalv " << hpnormalv << endl; */ float cosR = zm * hpnormalv; ARCCOS_SANITY( cosR ) roll = acos(cosR); // if the normal is roughly coincident with pitchv, then we need // to negate the sign of the roll angle osg::Vec3 rollplanenormalv = zm ^ hpnormalv; rollplanenormalv.normalize(); //cout << "vv color " << "rollplanenormalv" << " .3 .3 .3\n"; //cout << "vv set rollplanenormalv " << rollplanenormalv << endl; if( pitchv * rollplanenormalv > 0. ) { roll *= -1.; } euler.set( roll, pitch, heading ); //cout << "r p h " << euler << endl; }
/*______________________________________________________________________*/ void VRSpacePointer::update(osg::Matrix &mat, unsigned int *button) { (void)mat; if (cover->debugLevel(5)) fprintf(stderr, "\nVRSpacePointer::update\n"); //float mx, my; //,smooth,tmp_float; //pfCoord coord; //float j1,j2,j3=0; //matrix wird staendig ueberschrieben =:-) if ((coVRTrackingUtil::instance()->getTrackingSystem() == coVRTrackingUtil::T_COVER_FLYBOX) || (trackingType == coVRTrackingUtil::T_COVER_BEEBOX)) { #ifdef BG_LIB if (coVRTrackingUtil::instance()->getTrackingSystem() == coVRTrackingUtil::T_COVER_BEEBOX) { r_bg(&bb); /* ** inbuf[0] - horizontal joy ** inbuf[1] - vertical joy ** inbuf[3] - bee_slider1 */ tmp_float = bb.inbuf[3]; tmp_float *= 1.25; if (tmp_float < -1.0) { tmp_float = -1.0; } else if (tmp_float > 1.0) { tmp_float = 1.0; } tmp_float += 1.0; tmp_float /= 2.0; if (tmp_float < 0.0) { tmp_float = 0.0; } else if (tmp_float > 1.0) { tmp_float = 1.0; } j3 = tmp_float - zero3; if ((j3 > -0.1) && (j3 < 0.1)) j3 = 0; //printf( "bee slider = %f\n", tmp_float ); tmp_float = bb.inbuf[0] - zero1; if (tmp_float < 0.0) { if (tmp_float < -1.0) { tmp_float = -1.0; } } else { if (tmp_float > 1.0) { tmp_float = 1.0; } } j1 = tmp_float; tmp_float = bb.inbuf[1] - zero2; if (tmp_float < 0.0) { if (tmp_float < -1.0) { tmp_float = -1.0; } } else { if (tmp_float > 1.0) { tmp_float = 1.0; } } j2 = tmp_float; if (bb.dio & LEFT_MOMENTARY_MASK) *button = 1; else *button = 0; st = w_bg(bb.mode, &bb); } if (coVRTrackingUtil::instance()->getTrackingSystem() == coVRTrackingUtil::T_COVER_FLYBOX) { r_bg(&fb); tmp_float = fb.inbuf[0]; if (tmp_float < 0.0) { if (tmp_float < -1.0) { tmp_float = -1.0; } } else { if (tmp_float > 1.0) { tmp_float = 1.0; } } j1 = tmp_float - zero1; tmp_float = fb.inbuf[1]; if (tmp_float < 0.0) { if (tmp_float < -1.0) { tmp_float = -1.0; } } else { if (tmp_float > 1.0) { tmp_float = 1.0; } } j2 = tmp_float - zero2; tmp_float = fb.inbuf[2]; if (tmp_float < 0.0) { if (tmp_float < -1.0) { tmp_float = -1.0; } } else { if (tmp_float > 1.0) { tmp_float = 1.0; } } tmp_float = fb.inbuf[4]; if (tmp_float < 0.0) { if (tmp_float < -1.0) { tmp_float = -1.0; } } else { if (tmp_float > 1.0) { tmp_float = 1.0; } } j3 = tmp_float - zero3; if ((j3 > -0.1) && (j3 < 0.1)) j3 = 0; /* ** Smooth and set slider 1 value in shared memory. */ fb.inbuf[3] *= 1.25; if (fb.inbuf[3] < -1.0) { fb.inbuf[3] = -1.0; } else if (fb.inbuf[3] > 1.0) { fb.inbuf[3] = 1.0; } fb.inbuf[3] += 1.0; fb.inbuf[3] /= 2.0; if (fb.inbuf[3] < 0.0) { fb.inbuf[3] = 0.0; } else if (fb.inbuf[3] > 1.0) { fb.inbuf[3] = 1.0; } smooth = fb.inbuf[3]; /* ** Smooth and set slider 2 value in shared memory. */ fb.inbuf[4] *= 1.25; if (fb.inbuf[4] < -1.0) { fb.inbuf[4] = -1.0; } else if (fb.inbuf[4] > 1.0) { fb.inbuf[4] = 1.0; } smooth = fb.inbuf[4]; /* ** Smooth and set pedal 1 value in shared memory. */ /*if( !cons4[0] ){ smooth = fb.inbuf[2] * fb.inbuf[2]; mused_smooth_pedal( PEDAL1, &smooth ); f[0] = smooth; } else { fb.inbuf[5] = -fb.inbuf[5]; fb.inbuf[5] += 1.0; fb.inbuf[5] /= 2.0; if( fb.inbuf[5] < 0.0 ){ fb.inbuf[5] = 0.0; } else if ( fb.inbuf[5] > 1.0 ){ fb.inbuf[5] = 1.0; } smooth = fb.inbuf[5] * fb.inbuf[5]; mused_smooth_pedal( PEDAL1, &smooth ); f[0] = 1.0 - smooth; }*/ /* ** Get the joystick lever... hooked into analog #8 input */ #define THUMB_PIN 7 if (fb.inbuf[THUMB_PIN] < 0.0) { smooth = -fb.inbuf[THUMB_PIN] * fb.inbuf[THUMB_PIN]; } else { smooth = fb.inbuf[THUMB_PIN] * fb.inbuf[THUMB_PIN]; } //f[0] = smooth; /* ** Set momentary button values in shared memory. */ //if( fb.dio & LEFT_MOMENTARY_MASK ) //if( fb.dio & RIGHT_MOMENTARY_MASK ) joy_trigger_value = fb.dio & 0x0100; if (joy_trigger_value == JOYSTICK_TRIGGER_MASK) *button = 0x04; else *button = 0; /* ** Set toggle button values in shared memory. */ /* if( fb.dio & LEFT_UPPER_TOGGLE_MASK ) if( fb.dio & RIGHT_UPPER_TOGGLE_MASK ) if( fb.dio & LEFT_MIDDLE_TOGGLE_MASK ) if( fb.dio & RIGHT_MIDDLE_TOGGLE_MASK ) if( fb.dio & LEFT_LOWER_TOGGLE_MASK ) if( fb.dio & RIGHT_LOWER_TOGGLE_MASK )*/ w_bg(fb.mode, &fb); } if ((j1 > -0.05) && (j1 < 0.05)) j1 = 0; if ((j2 > -0.05) && (j2 < 0.05)) j2 = 0; if ((j3 > -0.05) && (j3 < 0.05)) j3 = 0; //printf( "j1 = %f\n", j1 ); //printf( "j2 = %f\n", j2 ); //printf( "j3 = %f\n", j3 ); pfGetOrthoMatCoord(matrix, &coord0); coord.hpr[0] = coord0.hpr[0] - j1 * speed / 20; coord.hpr[1] = coord0.hpr[1] - j2 * speed / 20; coord.hpr[2] = 0.0; /*if (coord.hpr[1] >= 90.0) { coord.hpr[0]= -180 + coord.hpr[0]; coord.hpr[1]= 180.0 - coord.hpr[1]; coord.hpr[2]= 180.0; }*/ pfMakeCoordMat(matrix, &coord); osg::Vec3 v; v[0] = 0.0; v[1] = j3 * speed / 100; v[2] = 0.0; pfFullXformPt3(v, v, matrix); coord.xyz[0] = coord0.xyz[0] + v[0]; coord.xyz[1] = coord0.xyz[1] + v[1]; coord.xyz[2] = coord0.xyz[2] + v[2]; pfMakeCoordMat(matrix, &coord); pfCopyMat(mat, matrix); #endif } else if (coVRTrackingUtil::instance()->getTrackingSystem() == coVRTrackingUtil::T_PHANTOM) { #ifdef PHANTOM_TRACKER static int oldTime; int currTime; update_phantom(phid); currTime = time(NULL); if (get_stylus_switch(phid)) *button = 1; else { *button = 0; oldTime = currTime; } if (currTime - oldTime > 3) { oldTime = currTime; phantom_reset(gPhantomID); } get_stylus_matrix(phid, mat.mat); mat[3][0] *= 0.2; mat[3][1] *= 0.2; mat[3][2] *= 0.2; osg::Matrix rmat; rmat.makeEuler(0.0, -90.0, 0.0); mat.preMult(rmat); #endif } else if (coVRTrackingUtil::instance()->getTrackingSystem() == coVRTrackingUtil::T_SPACEBALL) { /* mat.copy(sh->spaceball_mat); //fprintf(stderr,"spaceball pos: %f %f %f", mat[3][0], mat[3][1], mat[3][2]); *button=0; if(sh->button&SPACEBALL_B1) *button=1; if(sh->button&SPACEBALL_B2) *button=DRIVE_BUTTON; if(sh->button&SPACEBALL_B3) *button=XFORM_BUTTON; if(sh->button&SPACEBALL_B5) *button=1; if(sh->button&SPACEBALL_B6) *button=DRIVE_BUTTON; if(sh->button&SPACEBALL_B7) *button=XFORM_BUTTON; if(sh->button&SPACEBALL_BPICK) { buttonSpecCell spec; strcpy(spec.name,"view all"); sh->button &= ~SPACEBALL_BPICK; VRSceneGraph::sg->manipulate(&spec); }*/ } else { //oldflags= mouse.flags; // bugfix dr: coGetMouse wurde in VRRenderer schon aufgerufen //coGetMouse(&mouse); /* mx= (float)mouse.xpos; my= (float)mouse.ypos; if (cover->debugLevel(6)) fprintf(stderr,"mouse x=%f y=%f\n", mx, my); matrix.getOrthoCoord(&coord); if (mouse.flags & CO_MOUSE_LEFT_DOWN) *button= 1; else *button= 0; // clear left mouse button flag mouse.flags= mouse.flags & (CO_MOUSE_LEFT_DOWN ^ -1); // xy translation if ( (mouse.flags & CO_MOUSE_MIDDLE_DOWN) && (mouse.flags & CO_MOUSE_RIGHT_DOWN) ) { if ( ! ((oldflags & CO_MOUSE_MIDDLE_DOWN) && (oldflags & CO_MOUSE_RIGHT_DOWN)) ) { mx0= (float)mouse.xpos; my0= (float)mouse.ypos; matrix.getOrthoCoord(&coord0); } coord.xyz[0]= coord0.xyz[0] + (mx-mx0)*speed/1024.0; coord.xyz[1]= coord0.xyz[1] + (my-my0)*speed/1024.0; } // xz translation else if (mouse.flags & CO_MOUSE_MIDDLE_DOWN) { if ( ! ( (oldflags & CO_MOUSE_MIDDLE_DOWN) && !(oldflags & CO_MOUSE_RIGHT_DOWN) && !(oldflags & CO_MOUSE_LEFT_DOWN)) ) { mx0= (float)mouse.xpos; my0= (float)mouse.ypos; matrix.getOrthoCoord(&coord0); } coord.xyz[0]= coord0.xyz[0] + (mx-mx0)*speed/1024.0; coord.xyz[2]= coord0.xyz[2] + (my-my0)*speed/1024.0; } //rotation else if (mouse.flags & CO_MOUSE_RIGHT_DOWN) { if ( ! (!(oldflags & CO_MOUSE_MIDDLE_DOWN) && (oldflags & CO_MOUSE_RIGHT_DOWN) && !(oldflags & CO_MOUSE_LEFT_DOWN)) ) { mx0= (float)mouse.xpos; my0= (float)mouse.ypos; matrix.getOrthoCoord(&coord0); } coord.hpr[0]= coord0.hpr[0] - (mx-mx0)*speed/256.0; coord.hpr[1]= coord0.hpr[1] + (my-my0)*speed/256.0; coord.hpr[2]= 0.0; if (coord.hpr[1] >= 90.0) { coord.hpr[0]= -180 + coord.hpr[0]; coord.hpr[1]= 180.0 - coord.hpr[1]; coord.hpr[2]= 180.0; } } matrix.makeCoord(&coord); mat = matrix;*/ } //oldflags= mouse.flags; if (cover->debugLevel(6)) { //mat.print(1,1,"spacepointer mat ",stderr); fprintf(stderr, "spacepointer button: %d\n", *button); } }