コード例 #1
0
void mouse(int button, int state, int x, int y)
{
   if (state)
   {
      G.mgr->mouseButtonRelease(button, x, y);
   }
   else
   {
      OSG::Line ray = G.mgr->calcViewRay(x, y);
      OSG::IntersectActionRefPtr ia = OSG::IntersectAction::create();
      ia->setLine(ray);
      ia->apply(G.mgr->getRoot());

      if(ia->didHit())
      {
         G.selectedNode = ia->getHitObject();

         if(OSG::getVoidP(G.selectedNode))
         {
            if(static_cast<BoardGame::Figure*>(OSG::getVoidP(G.selectedNode)))
            {
               std::cout << "Selected figure" << std::endl;
               ia = 0;
               return;
            }
         }
      }
      ia = 0;

      G.mgr->mouseButtonPress(button, x, y);
   }

   glutPostRedisplay();
}
コード例 #2
0
void PlaneMoveManipulator::mouseButtonPress(const UInt16 button,
                                   const Int16  x,
                                   const Int16  y     )
{
    Transform *t = dynamic_cast<Transform *>(getTarget()->getCore());
    
    if (t == NULL)
    {
        SWARNING << "PlaneMoveManipulator::mouseButtonPress() target is not a Transform!" << endLog;
        return;
    }

    SLOG << "PlaneMoveManipulator::mouseButtonPress() button=" << button << " x=" << x << " y=" << y  << std::endl << endLog;

    OSG::Line viewray;
    getViewport()->getCamera()->calcViewRay(viewray, x, y, *getViewport());

    OSG::Node *scene = getTarget();
    while (scene->getParent() != 0)
    {
        scene = scene->getParent();
    }

    OSG::IntersectActionRefPtr act = OSG::IntersectAction::create();
    act->setLine( viewray );
    act->apply( scene );

    SLOG << "PlaneMoveManipulator::mouseButtonPress() viewray=" << viewray << " scene=" << scene << endLog;
 
    if ( act->didHit() )
    {
        SLOG << "PlaneMoveManipulator::mouseButtonPress() hit! at " << act->getHitPoint() << endLog;

        // Get manipulator plane into world space
        OSG::Matrix m = getTarget()->getToWorld();

        Vec3f      translation;       // for matrix decomposition
        Quaternion rotation;
        Vec3f      scaleFactor;
        Quaternion scaleOrientation;

        t->getMatrix().getTransform(translation, rotation, scaleFactor,
                                    scaleOrientation);

        Vec3f rot_axis;
        rotation.multVec(Vec3f(0,1,0), rot_axis);

        Plane pl(rot_axis, act->getHitPoint());

        SLOG << "PlaneMoveManipulator::mouseButtonPress() world plane: " << pl << endLog;
 
        setClickPoint(act->getHitPoint());

        setBaseTranslation(translation);
        setBaseRotation(rotation);
        
        setActive(true);
    }

    act = NULL;
}