Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 18, 2009, 4:39:56 PM (14 years ago)
Author:
wirthmi
Message:

The weapon is firing where the mouse is pointing. Uncoupling of the mouse with TAB-key.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/steering/src/orxonox/controllers/NewHumanController.cc

    r6058 r6091  
    4545namespace orxonox
    4646{
     47    SetConsoleCommand(NewHumanController, changeMode,          false).keybindMode(KeybindMode::OnPress);
     48
    4749    CreateUnloadableFactory(NewHumanController);
     50
     51    NewHumanController* NewHumanController::localController_s = 0;
    4852
    4953    NewHumanController::NewHumanController(BaseObject* creator) : HumanController(creator)
     
    6367        this->targetMask_.include(ClassByString("WorldEntity"));
    6468        this->targetMask_.exclude(ClassByString("Projectile"));
     69
     70        NewHumanController::localController_s = this;
    6571    }
    6672
     
    119125        Ogre::RaySceneQuery * rsq = HumanController::localController_s->getControllableEntity()->getScene()->getSceneManager()->createRayQuery(Ogre::Ray());
    120126
    121         //std::cout << "X: " << static_cast<float>(this->currentYaw_)/2*-1+.5 << "  Y: " << static_cast<float>(this->currentPitch_)/2*-1+.5 << endl;
    122 
    123127        Ogre::Ray mouseRay = HumanController::localController_s->getControllableEntity()->getCamera()->getOgreCamera()->getCameraToViewportRay(static_cast<float>(this->currentYaw_)/2*-1+.5, static_cast<float>(this->currentPitch_)/2*-1+.5);
    124128
     
    140144        for (itr = result.begin(); itr != result.end(); ++itr)
    141145        {
    142             //std::cout << "distance: " << itr->distance << "  name: " << itr->movable->getName() << " type: " << itr->movable->getMovableType();
    143146            if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity" && itr->distance > 500)
    144147            {
     
    151154                        continue;
    152155                }
    153                 //std::cout << "  TAGGED";
     156
    154157                itr->movable->getParentSceneNode()->showBoundingBox(true);
    155                 std::cout << itr->movable->getParentSceneNode()->_getDerivedPosition() << endl;
    156                 return itr->movable->getParentSceneNode()->_getDerivedPosition();
     158                //std::cout << itr->movable->getParentSceneNode()->_getDerivedPosition() << endl;
     159                return mouseRay.getOrigin() + mouseRay.getDirection() * itr->distance; //or itr->movable->getParentSceneNode()->_getDerivedPosition()
    157160            }
    158             //std::cout << endl;
     161
    159162        }
    160163
    161         //if (result.front().movable->isInScene()) std::cout << "in scene" << endl;
    162         // && result.front().movable->getParentSceneNode() != NULL) result.front().movable->getParentSceneNode()->showBoundingBox(true);
    163         //result.front().movable->setVisible(false);
     164        return mouseRay.getOrigin() + mouseRay.getDirection() * 1200;
    164165
    165         //std::cout << endl;
    166 /*
    167         if (!result.empty()) {
    168             Ogre::RaySceneQueryResultEntry obj = result.front();
    169             std::cout << "distance: " << obj.distance << "  name: " << obj.movable->getName() << endl;
    170         }
    171 */
    172         return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getWorldOrientation() * Vector3::NEGATIVE_UNIT_Z * 800);
     166        //return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getWorldOrientation() * Vector3::NEGATIVE_UNIT_Z * 2000);
    173167        //return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getCamera()->getOgreCamera()->getOrientation() * Vector3::NEGATIVE_UNIT_Z);
    174168    }
     
    177171    {
    178172//         SUPER(NewHumanController, yaw, value);
    179         HumanController::yaw(value);
     173        if (this->controlMode_ == 0)
     174            HumanController::yaw(value);
    180175       
    181176        this->currentYaw_ = value.x;
     
    186181    {
    187182//         SUPER(NewHumanController, pitch, value);
    188         HumanController::pitch(value);
    189        
     183        if (this->controlMode_ == 0)
     184            HumanController::pitch(value);
     185
    190186        this->currentPitch_ = value.x;
    191187        //std::cout << "Y: " << static_cast<float>(this->currentPitch_) << " X: " << static_cast<float>(this->currentYaw_) << endl;
    192188    }
     189
     190    void NewHumanController::changeMode() {
     191        if (NewHumanController::localController_s->controlMode_ == 0)
     192            NewHumanController::localController_s->controlMode_ = 1;
     193        else
     194            NewHumanController::localController_s->controlMode_ = 0;
     195    }
    193196}
Note: See TracChangeset for help on using the changeset viewer.