Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6033


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

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

Location:
code/branches/steering/src/orxonox
Files:
5 edited

Legend:

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

    r5993 r6033  
    143143    }
    144144
    145     void HumanController::fire(unsigned int firemode)
     145    void HumanController::doFire(unsigned int firemode)
    146146    {
    147147        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
  • code/branches/steering/src/orxonox/controllers/HumanController.h

    r5993 r6033  
    5656            virtual void pitch(const Vector2& value);
    5757
    58             static void fire(unsigned int firemode);
     58            static void fire(unsigned int firemode) { HumanController::localController_s->doFire(firemode); }
     59            virtual void doFire(unsigned int firemode);
    5960            static void reload();
    6061
     
    7980            friend class Map;
    8081
    81         private:
     82        protected:
    8283            static HumanController* localController_s;
    8384    };
  • 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
  • code/branches/steering/src/orxonox/controllers/NewHumanController.h

    r6001 r6033  
    3434#include "HumanController.h"
    3535#include "overlays/OrxonoxOverlay.h"
     36#include "util/OgreForwardRefs.h"
    3637
    3738namespace orxonox
     
    4849            virtual void pitch(const Vector2& value);
    4950
     51            virtual void doFire(unsigned int firemode);
     52
    5053        private:
    5154            float                       currentYaw_;
    5255            float                       currentPitch_;
    5356            OrxonoxOverlay              *CrossHairOverlay;
     57            float                       overlaySize;
    5458    };
    5559}
  • code/branches/steering/src/orxonox/graphics/Camera.h

    r5781 r6033  
    5252            void releaseFocus();
    5353
     54            inline Ogre::Camera* getCamera()
     55               { return this->camera_; }
     56
    5457            inline bool hasFocus()
    5558                { return this->bHasFocus_; }
Note: See TracChangeset for help on using the changeset viewer.