コード例 #1
0
ファイル: HaptionDriver.cpp プロジェクト: 151706061/sofa
void HaptionDriver::onKeyPressedEvent(core::objectmodel::KeypressedEvent *kpe)
{
    if(!visuAxes && kpe->getKey()==49)
    {
        sofa::simulation::tree::GNode *parent = dynamic_cast<sofa::simulation::tree::GNode*>(this->getContext());
        parent->getParent()->addChild(nodeAxesVisual);
        nodeAxesVisual->updateContext();
        visuAxes=true;
    }
    else if(visuAxes && kpe->getKey()==49)
    {
        sofa::simulation::tree::GNode *parent = dynamic_cast<sofa::simulation::tree::GNode*>(this->getContext());
        parent->getParent()->removeChild(nodeAxesVisual);
        nodeAxesVisual->updateContext();
        visuAxes=false;
    }

    if(visuAxes  && haptionVisu.getValue())
    {
        double pi = 3.1415926535;
        if ((kpe->getKey()=='X' || kpe->getKey()=='x') && !modX )
        {
            modX=true;
        }
        if ((kpe->getKey()=='Y' || kpe->getKey()=='y') && !modY )
        {
            modY=true;
        }
        if ((kpe->getKey()=='Z' || kpe->getKey()=='z') && !modZ )
        {
            modZ=true;
        }
        if ((kpe->getKey()=='Q' || kpe->getKey()=='q') && !modS )
        {
            modS=true;
        }
        if (kpe->getKey()==18) //left
        {
            if(modX || modY || modZ)
            {
                VecCoord& posB =(*posBase.beginEdit());
                posB[0].getCenter()+=posB[0].getOrientation().rotate(Vec3d(-(int)modX,-(int)modY,-(int)modZ));
                posBase.endEdit();
            }
            else
            {
                scale.setValue(scale.getValue()-5);
                changeScale = true;
            }
        }
        else if (kpe->getKey()==20) //right
        {

            if(modX || modY || modZ)
            {
                VecCoord& posB =(*posBase.beginEdit());
                posB[0].getCenter()+=posB[0].getOrientation().rotate(Vec3d((int)modX,(int)modY,(int)modZ));
                posBase.endEdit();
            }
            else
            {
                scale.setValue(scale.getValue()+5);
                changeScale = true;
            }
        }
        else if ((kpe->getKey()==21) && (modX || modY || modZ)) //down
        {
            VecCoord& posB =(*posBase.beginEdit());
            sofa::helper::Quater<double> quarter_transform(Vec3d((int)modX,(int)modY,(int)modZ),-pi/50);
            posB[0].getOrientation()*=quarter_transform;
            posBase.endEdit();
        }
        else if ((kpe->getKey()==19) && (modX || modY || modZ)) //up
        {
            VecCoord& posB =(*posBase.beginEdit());
            sofa::helper::Quater<double> quarter_transform(Vec3d((int)modX,(int)modY,(int)modZ),+pi/50);
            posB[0].getOrientation()*=quarter_transform;
            posBase.endEdit();
        }
        if ((kpe->getKey()=='E' || kpe->getKey()=='e'))
        {
            VecCoord& posB =(*posBase.beginEdit());
            posB[0].clear();
            posBase.endEdit();
        }

        if(modX || modY || modZ)
        {
            float baseFrame[7] = { (float) posBase.getValue()[0].getCenter()[0]/(float) scale.getValue(),
                    (float) posBase.getValue()[0].getCenter()[1]/(float) scale.getValue(),
                    (float) posBase.getValue()[0].getCenter()[2]/(float) scale.getValue(),
                    (float) posBase.getValue()[0].getOrientation()[0],
                    (float) posBase.getValue()[0].getOrientation()[1],
                    (float) posBase.getValue()[0].getOrientation()[2],
                    (float) posBase.getValue()[0].getOrientation()[3]
                                 };


            cout<<"virtSetBaseFrame return "<<virtSetBaseFrame(myData.m_virtContext, baseFrame)<<endl;
            cout<<"virtGetErrorCode return "<<virtGetErrorCode(myData.m_virtContext)<<endl;

            VecCoord& posH =*(visualHaptionDOF->x.beginEdit());
            posH[0]=posBase.getValue()[0];
            visualHaptionDOF->x.endEdit();

            VecCoord& posA =*(visualAxesDOF->x.beginEdit());
            posA[0]=posBase.getValue()[0];
            posA[1]=posBase.getValue()[0];
            posA[2]=posBase.getValue()[0];
            visualAxesDOF->x.endEdit();
        }
    }

}
コード例 #2
0
ファイル: IHPDriver.cpp プロジェクト: mhdsedighi/SOFA
void IHPDriver::onKeyPressedEvent(core::objectmodel::KeypressedEvent *kpe)
{
    cout<<"kpe"<<endl;
    cout<<initVisu<<endl;
    cout<<int(kpe->getKey())<<" "<<kpe->getKey()<<endl;
    if(!visuAxes && kpe->getKey()==49+deviceIndex.getValue() && initVisu)
    {
        cout<<"axes on"<<endl;
        simulation::Node *parent = dynamic_cast<simulation::Node *>(this->getContext());
        parent->addChild(nodeAxesVisual);
        nodeAxesVisual->updateContext();
        visuAxes=true;
    }
    else if(visuAxes && kpe->getKey()==49+deviceIndex.getValue() && initVisu)
    {
        cout<<"axes off"<<endl;
        simulation::Node *parent = dynamic_cast<simulation::Node *>(this->getContext());
        parent->removeChild(nodeAxesVisual);
        nodeAxesVisual->updateContext();
        visuAxes=false;
    }

    if(visuAxes  && xitactVisu.getValue())
    {
        double pi = 3.1415926535;
        if ((kpe->getKey()=='X' || kpe->getKey()=='x') && !modX )
        {
            modX=true;
        }
        if ((kpe->getKey()=='Y' || kpe->getKey()=='y') && !modY )
        {
            modY=true;
        }
        if ((kpe->getKey()=='Z' || kpe->getKey()=='z') && !modZ )
        {
            modZ=true;
        }
        if ((kpe->getKey()=='Q' || kpe->getKey()=='q') && !modS )
        {
            modS=true;
        }
        if (kpe->getKey()==18) //left
        {
            if(modX || modY || modZ)
            {
                VecCoord& posB =(*positionBase.beginEdit());
                posB[0].getCenter()+=posB[0].getOrientation().rotate(Vec3d(-5*(int)modX,-5*(int)modY,-5*(int)modZ));
                positionBase.endEdit();
            }
            else if(modS)
            {
                Scale.setValue(Scale.getValue()-5);
                changeScale = true;
            }
        }
        else if (kpe->getKey()==20) //right
        {

            if(modX || modY || modZ)
            {
                VecCoord& posB =(*positionBase.beginEdit());
                posB[0].getCenter()+=posB[0].getOrientation().rotate(Vec3d(5*(int)modX,5*(int)modY,5*(int)modZ));
                positionBase.endEdit();
            }
            else if(modS)
            {
                Scale.setValue(Scale.getValue()+5);
                changeScale = true;
            }
        }
        else if ((kpe->getKey()==21) && (modX || modY || modZ)) //down
        {
            VecCoord& posB =(*positionBase.beginEdit());
            sofa::helper::Quater<double> quarter_transform(Vec3d((int)modX,(int)modY,(int)modZ),-pi/50);
            posB[0].getOrientation()*=quarter_transform;
            positionBase.endEdit();
        }
        else if ((kpe->getKey()==19) && (modX || modY || modZ)) //up
        {
            VecCoord& posB =(*positionBase.beginEdit());
            sofa::helper::Quater<double> quarter_transform(Vec3d((int)modX,(int)modY,(int)modZ),+pi/50);
            posB[0].getOrientation()*=quarter_transform;
            positionBase.endEdit();
        }
        if ((kpe->getKey()=='E' || kpe->getKey()=='e'))
        {
            VecCoord& posB =(*positionBase.beginEdit());
            posB[0].clear();
            positionBase.endEdit();
        }

    }

}