bool CSymbol::Compare(CSymbol* pSymbol) { double epsilon=30.+((m_nDirection>15)?(15.):(0.)); if(m_nDirection<=0)return false; int a=0,b=0; double r1=0,r2=0,r3; bool succes=false; while(1) { // a+1 if(a+1<m_nDirection) r1=(m_Direction[a+1]==pSymbol->m_Direction[b]); else r1=777; // b+1 if(b+1<pSymbol->m_nDirection) r2=(m_Direction[a]==pSymbol->m_Direction[b+1]); else r2=777; // a+1, b+1 if((b+1<pSymbol->m_nDirection)&&(a+1<m_nDirection)) r3=(m_Direction[a+1]==pSymbol->m_Direction[b+1]); else r3=777; if((r1==777)&&(r2==777)) { succes=true; break; } if(min(r1,r2)>epsilon) if(r3>epsilon*1.8) { succes=false; break; } switch(nMin(r1,r2,r3)) { case 0:a++;break; case 1:b++;break; case 2:a++;b++;break; default: ASSERT(1); } } // while return succes; }
// Function called after tracker update but before start of drawing. Do // calculations and state modifications here. // In the glove application, this function does the logic for picking the // objects. void gloveApp::postFrame() { //: we need to keep track of the wand, and the user. UserInfo user_info; TrackedInfo wand_info, head_info; gmtl::Vec3f glove_pos; gmtl::Matrix44f finger_matrix; gmtl::Matrix44f inv_nav; gmtl::invert(inv_nav, mNavigation); ///////////////////////////////////////////////////////// //: Debug stuff std::cout << mPinchLeftThumb->getData() << mPinchLeftIndex->getData() << mPinchLeftMiddle->getData() << mPinchLeftRing->getData() << mPinchLeftPinky->getData() << mPinchRightThumb->getData() << mPinchRightIndex->getData() << mPinchRightMiddle->getData() << mPinchRightRing->getData() << mPinchRightPinky->getData() << std::endl; if (LeftPointing() == true) { std::cout << "Left Pointing" << std::flush; } else if (LeftOpen() == true) { std::cout << "Left Open" << std::flush; } else if (LeftFist() == true) { std::cout << "Left Fist" << std::flush; } if (RightPointing() == true) { std::cout << ", Right Pointing" << std::flush; } else if (RightOpen() == true) { std::cout << ", Right Open" << std::flush; } else if (RightFist() == true) { std::cout << ", Right Fist" << std::flush; } std::cout << "\n" << std::flush; ///////////////////////////////////////////////////////// //: Handle navigation //mNavigation.accelerate( LeftPointing() == true ); //mNavigation.rotate( LeftPointing() == false && LeftOpen() == false ); //mNavigation.setMatrix( mGlove->getTipTransform(vrj::GloveData::INDEX) ); //mNavigation.update( time ); //: Get the position of the index finger: finger_matrix = mGlove->getTipTransform(gadget::GloveData::INDEX); gmtl::setTrans(glove_pos, finger_matrix); gmtl::xform(glove_pos, inv_nav, glove_pos); //////////////////////// // NAVIGATION // //////////////////////////////////////////////////////// static float userVelocity(0.0f); if (LeftPointing() == true) { userVelocity += 0.0001f; } else if (LeftFist() == true) { userVelocity = 0.0f; } user_info.setVelocity(userVelocity); user_info.setAngularVelocity(0.01f); gmtl::Matrix44f tttt = mGlove->getTipTransform(gadget::GloveData::INDEX); wand_info.updateWithMatrix(tttt); user_info.update(wand_info, gmtl::Vec3f(0.0f, 0.0f, 0.0f)); user_info.getSceneTransform(mNavigation); //////////////////////////////////////////////////////// //////////////////////////////////////////////////////// //: pick up the object if you're grabbing. // set the object position equal to the glove position. if ( this->RightFist() == true ) { if (mConeSelected) { mConePos = glove_pos; } else if (mSphereSelected) { mSpherePos = glove_pos; } else if (mCubeSelected) { mCubePos = glove_pos; } } float cube_distance = gmtl::length(gmtl::Vec3f(glove_pos - mCubePos)); float sphere_distance = gmtl::length(gmtl::Vec3f(glove_pos - mSpherePos)); float cone_distance = gmtl::length(gmtl::Vec3f(glove_pos - mConePos)); float min = nMin(cube_distance, sphere_distance, cone_distance); //: If the distance between hand and object is too far // don't highlight any of them. if (min > 1.0f) { mCubeSelected = false; mSphereSelected = false; mConeSelected = false; } // ...otherwise, // If glove is not grabbing, or // we don't already have a selected one, then... else if ( this->RightOpen() == true || (mCubeSelected == false && mSphereSelected == false && mConeSelected == false) ) { // ... highlight the closest one to the glove. if (min == cone_distance) { mCubeSelected = false; mSphereSelected = false; mConeSelected = true; } else if (min == sphere_distance) { mCubeSelected = false; mSphereSelected = true; mConeSelected = false; } else if (min == cube_distance) { mCubeSelected = true; mSphereSelected = false; mConeSelected = false; } } }