// -------------------------------------------------------------------------
void OgreBulletListener::button1Pressed()
{

    // small unique impulse under cursor.
    Ogre::Vector3 pickPos;
    Ogre::Ray rayTo;
    OgreBulletDynamics::RigidBody * body = 
        getBodyUnderCursorUsingBullet(pickPos, rayTo);
        //getBodyUnderCursorUsingOgre(pickPos, rayTo);
    if (body)
    {  
        if (!(body->isStaticObject() 
            || body->isKinematicObject()
            ))
        {

            body->enableActiveState ();

            const Ogre::Vector3 relPos (pickPos - body->getCenterOfMassPosition());
            const Ogre::Vector3 impulse (rayTo.getDirection ());

            body->applyImpulse (impulse * mImpulseForce, relPos);		

        }

        getDebugLines();
        mDebugRayLine->addLine (rayTo.getOrigin(), pickPos);
        mDebugRayLine->draw();	
    }  
}
Esempio n. 2
0
int PlayState::interpretConsoleCommand(const MyGUI::UString & command)
{
    /* This method must be redone in a different way */

    std::string sCommand = (std::string)command;
    Ogre::StringVector splitStrings = Ogre::StringUtil::split(sCommand, " ", 4);
    std::string s = splitStrings.front();
    if(s.compare("close")==0) {
        notifyWindowButtonPressed(mConsoleWindow, s);
    } else if(s.compare("pause")==0) {
        pauseGame();
    } else if(s.compare("quit")==0) {
        mContinue = false;
    } else if(s.compare("push")==0 && splitStrings.size()>=5 ) {

        if(mActors.find(splitStrings[1]) != mActors.end()) {
            OgreBulletDynamics::RigidBody* body = mActors[splitStrings[1]]->getBody();
            if(body) {
                Vector3 dir = Vector3(atof(splitStrings[2].c_str()),atof(splitStrings[3].c_str()),atof(splitStrings[4].c_str()));
                body->getBulletObject()->activate();
                body->applyImpulse(dir*50,Vector3(0, 0.05, 0));
            } else {
                return 0;
            }
        }
    } else if(s.compare("move")==0 && splitStrings.size()>=5) {
        Actor *actor = mActors[splitStrings[1]];
        if (actor) {

            btTransform transform;
            transform.setIdentity();
            transform.setOrigin(OgreBulletCollisions::OgreBtConverter::to(Vector3(atof(splitStrings[2].c_str()),atof(splitStrings[3].c_str()),atof(splitStrings[4].c_str()))));
            actor->getBody()->getBulletRigidBody()->clearForces();
            actor->getBody()->getBulletRigidBody()->setLinearVelocity(btVector3(0,0,0));
            actor->getBody()->getBulletRigidBody()->setAngularVelocity(btVector3(0,0,0));
            actor->getBody()->getBulletRigidBody()->setWorldTransform(transform);
        } else {
            return 0;
        }
    } else if(s.compare("debug")==0) {
        if(splitStrings.size()<2) {
            alterPlayState(DEBUG);
        } else if(splitStrings[1].compare("off")==0) {
            alterPlayState(NORMAL);
        }
    } else if(s.compare("win")==0) {
        GameManager::getSingletonPtr()->changeState(WinState::getInstance());
        return -1;
    } else {
        return 0;
    }
    return 1;
}