Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 4, 2009, 5:47:31 PM (15 years ago)
Author:
wirthmi
Message:

Added the ability to raytrace on fire to find the object to user wants to aim at.

File:
1 edited

Legend:

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

    r6001 r6033  
    2929#include "NewHumanController.h"
    3030
    31 #include "core/input/InputManager.h"
    32 #include "core/input/InputState.h"
     31#include <OgreRay.h>
     32#include <OgreSceneQuery.h>
     33#include <OgreCamera.h>
     34#include <OgreSceneManager.h>
    3335
    3436#include "core/CoreIncludes.h"
     
    5355        RegisterObject(NewHumanController);
    5456
     57        overlaySize = 0.08;
     58
    5559        CrossHairOverlay = new OrxonoxOverlay(this);
    5660        CrossHairOverlay->setBackgroundMaterial("Orxonox/Crosshair3");
    57         CrossHairOverlay->setSize(Vector2(0.08,0.08));
     61        CrossHairOverlay->setSize(Vector2(overlaySize,overlaySize));
    5862        CrossHairOverlay->show();
    5963    }
     
    6771
    6872    void NewHumanController::tick(float dt) {
    69         CrossHairOverlay->setPosition(Vector2(static_cast<float>(this->currentYaw_), static_cast<float>(this->currentPitch_)));
     73        CrossHairOverlay->setPosition(Vector2(static_cast<float>(this->currentYaw_)/2*-1+.5-overlaySize/2, static_cast<float>(this->currentPitch_)/2*-1+.5-overlaySize/2));
    7074
    7175        HumanController::tick(dt);
     
    8892    }*/
    8993   
     94    void NewHumanController::doFire(unsigned int firemode)
     95    {
     96        //if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) {
     97
     98/*
     99
     100 // Get results, create a node/entity on the position
     101 for ( itr = result.begin(); itr != result.end(); itr++ )
     102 {
     103     if (itr->movable && itr->movable->getName() == "Head")
     104     {
     105         soundMgr->StopSound( &jaguarSoundChannel );
     106         soundMgr->PlaySound( jaguarSound, headNode, &jaguarSoundChannel );
     107         break;
     108     } // if
     109 }
     110*/
     111
     112            Ogre::RaySceneQuery * rsq = HumanController::localController_s->getControllableEntity()->getScene()->getSceneManager()->createRayQuery(Ogre::Ray());
     113
     114std::cout << "X: " << static_cast<float>(this->currentYaw_)/2*-1+.5 << "  Y: " << static_cast<float>(this->currentPitch_)/2*-1+.5 << endl;
     115
     116            Ogre::Ray mouseRay = HumanController::localController_s->getControllableEntity()->getCamera()->getCamera()->getCameraToViewportRay(static_cast<float>(this->currentYaw_)/2*-1+.5, static_cast<float>(this->currentPitch_)/2*-1+.5);
     117
     118            rsq->setRay(mouseRay);
     119            rsq->setSortByDistance(true);
     120
     121
     122            Ogre::RaySceneQueryResult &result = rsq->execute();
     123
     124            Ogre::RaySceneQueryResult::iterator itr;
     125for ( itr = result.begin(); itr != result.end(); itr++ )
     126 {
     127     std::cout << "distance: " << itr->distance << "  name: " << itr->movable->getName() << " type: " << itr->movable->getMovableType() << endl;
     128if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity") {
     129std::cout << " in scene" << endl;
     130        itr->movable->getParentSceneNode()->showBoundingBox(true);
     131}
     132 }
     133
     134//if (result.front().movable->isInScene()) std::cout << "in scene" << endl;
     135// && result.front().movable->getParentSceneNode() != NULL) result.front().movable->getParentSceneNode()->showBoundingBox(true);
     136//result.front().movable->setVisible(false);
     137
     138std::cout << endl;
     139/*
     140            if (!result.empty()) {
     141                Ogre::RaySceneQueryResultEntry obj = result.front();
     142                std::cout << "distance: " << obj.distance << "  name: " << obj.movable->getName() << endl;
     143            }
     144*/
     145
     146
     147            HumanController::localController_s->getControllableEntity()->fire(firemode);
     148        //}
     149//}
     150    }
     151
    90152    void NewHumanController::yaw(const Vector2& value)
    91153    {
     
    94156       
    95157        this->currentYaw_ = value.x;
    96         std::cout << "Y: " << static_cast<float>(this->currentPitch_) << " X: " << static_cast<float>(this->currentYaw_) << endl;
     158        //std::cout << "Y: " << static_cast<float>(this->currentPitch_) << " X: " << static_cast<float>(this->currentYaw_) << endl;
    97159    }
    98160    void NewHumanController::pitch(const Vector2& value)
     
    102164       
    103165        this->currentPitch_ = value.x;
    104         std::cout << "Y: " << static_cast<float>(this->currentPitch_) << " X: " << static_cast<float>(this->currentYaw_) << endl;
     166        //std::cout << "Y: " << static_cast<float>(this->currentPitch_) << " X: " << static_cast<float>(this->currentYaw_) << endl;
    105167    }
    106168
Note: See TracChangeset for help on using the changeset viewer.