[Orxonox-commit 1337] r6055 - in code/branches/steering/src: modules/weapons/weaponmodes orxonox/controllers orxonox/infos orxonox/weaponsystem orxonox/worldentities
rgrieder at orxonox.net
rgrieder at orxonox.net
Fri Nov 13 11:21:40 CET 2009
Author: rgrieder
Date: 2009-11-13 11:21:40 +0100 (Fri, 13 Nov 2009)
New Revision: 6055
Modified:
code/branches/steering/src/modules/weapons/weaponmodes/HsW01.cc
code/branches/steering/src/orxonox/controllers/Controller.cc
code/branches/steering/src/orxonox/controllers/Controller.h
code/branches/steering/src/orxonox/controllers/NewHumanController.cc
code/branches/steering/src/orxonox/controllers/NewHumanController.h
code/branches/steering/src/orxonox/infos/PlayerInfo.cc
code/branches/steering/src/orxonox/weaponsystem/WeaponMode.cc
code/branches/steering/src/orxonox/weaponsystem/WeaponMode.h
code/branches/steering/src/orxonox/worldentities/ControllableEntity.h
code/branches/steering/src/orxonox/worldentities/WorldEntity.cc
Log:
Resolved projectile targeting problem by introducing a ClassTreeMask. It's a bit hacky but currently I don't see another quick way.
There is a problem though: The weapons aim into other directions while rolling the space ship...
I just couldn't figure it out.
Modified: code/branches/steering/src/modules/weapons/weaponmodes/HsW01.cc
===================================================================
--- code/branches/steering/src/modules/weapons/weaponmodes/HsW01.cc 2009-11-13 10:12:31 UTC (rev 6054)
+++ code/branches/steering/src/modules/weapons/weaponmodes/HsW01.cc 2009-11-13 10:21:40 UTC (rev 6055)
@@ -110,11 +110,10 @@
projectile->attach(model);
model->setScale(5);
- //projectile->setOrientation(this->getMuzzleOrientation());
- projectile->lookAt(this->getTarget(), WorldEntity::World);
+ this->computeMuzzleParameters();
+ projectile->setOrientation(this->getMuzzleOrientation());
projectile->setPosition(this->getMuzzlePosition());
- projectile->setVelocity((projectile->getOrientation() * Vector3::UNIT_Z) * this->speed_); //getWorldOrientation??
- //projectile->setVelocity(this->getMuzzleDirection() * this->speed_);
+ projectile->setVelocity(this->getMuzzleDirection() * this->speed_);
projectile->setOwner(this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn());
projectile->setDamage(this->getDamage());
Modified: code/branches/steering/src/orxonox/controllers/Controller.cc
===================================================================
--- code/branches/steering/src/orxonox/controllers/Controller.cc 2009-11-13 10:12:31 UTC (rev 6054)
+++ code/branches/steering/src/orxonox/controllers/Controller.cc 2009-11-13 10:21:40 UTC (rev 6055)
@@ -45,8 +45,4 @@
Controller::~Controller()
{
}
-
- Vector3 Controller::getTarget() {
- return this->controllableEntity_->getPosition() + (this->controllableEntity_->getOrientation() * Vector3::UNIT_Z);
- }
}
Modified: code/branches/steering/src/orxonox/controllers/Controller.h
===================================================================
--- code/branches/steering/src/orxonox/controllers/Controller.h 2009-11-13 10:12:31 UTC (rev 6054)
+++ code/branches/steering/src/orxonox/controllers/Controller.h 2009-11-13 10:21:40 UTC (rev 6055)
@@ -57,7 +57,10 @@
{ return this->controllableEntity_; }
virtual void changedControllableEntity() {}
- virtual Vector3 getTarget();
+ virtual bool canFindTarget()
+ { return false; }
+ virtual Vector3 getTarget()
+ { return Vector3::ZERO; }
protected:
PlayerInfo* player_;
Modified: code/branches/steering/src/orxonox/controllers/NewHumanController.cc
===================================================================
--- code/branches/steering/src/orxonox/controllers/NewHumanController.cc 2009-11-13 10:12:31 UTC (rev 6054)
+++ code/branches/steering/src/orxonox/controllers/NewHumanController.cc 2009-11-13 10:21:40 UTC (rev 6055)
@@ -36,43 +36,44 @@
#include "core/CoreIncludes.h"
#include "core/ConsoleCommand.h"
#include "worldentities/ControllableEntity.h"
-#include "worldentities/pawns/Pawn.h"
-#include "gametypes/Gametype.h"
#include "infos/PlayerInfo.h"
-#include "overlays/Map.h"
+#include "overlays/OrxonoxOverlay.h"
#include "graphics/Camera.h"
#include "sound/SoundManager.h"
-#include "Radar.h"
#include "Scene.h"
namespace orxonox
{
-
CreateUnloadableFactory(NewHumanController);
NewHumanController::NewHumanController(BaseObject* creator) : HumanController(creator)
{
RegisterObject(NewHumanController);
- overlaySize = 0.08;
+ overlaySize_ = 0.08;
+ controlMode_ = 0;
- controlMode = 0;
+ crossHairOverlay_ = new OrxonoxOverlay(this);
+ crossHairOverlay_->setBackgroundMaterial("Orxonox/Crosshair3");
+ crossHairOverlay_->setSize(Vector2(overlaySize_, overlaySize_));
+ crossHairOverlay_->show();
- CrossHairOverlay = new OrxonoxOverlay(this);
- CrossHairOverlay->setBackgroundMaterial("Orxonox/Crosshair3");
- CrossHairOverlay->setSize(Vector2(overlaySize,overlaySize));
- CrossHairOverlay->show();
+ // HACK: Define which objects are targettable when considering the creator of an orxonox::Model
+ this->targetMask_.exclude(ClassByString("BaseObject"));
+ this->targetMask_.include(ClassByString("WorldEntity"));
+ this->targetMask_.exclude(ClassByString("Projectile"));
}
NewHumanController::~NewHumanController()
{
- if( this->isInitialized() )
+ if (this->isInitialized())
{
}
}
- void NewHumanController::tick(float dt) {
- CrossHairOverlay->setPosition(Vector2(static_cast<float>(this->currentYaw_)/2*-1+.5-overlaySize/2, static_cast<float>(this->currentPitch_)/2*-1+.5-overlaySize/2));
+ void NewHumanController::tick(float dt)
+ {
+ crossHairOverlay_->setPosition(Vector2(static_cast<float>(this->currentYaw_)/2*-1+.5-overlaySize_/2, static_cast<float>(this->currentPitch_)/2*-1+.5-overlaySize_/2));
HumanController::tick(dt);
}
@@ -98,71 +99,78 @@
//if (HumanController::localController_s && HumanController::localController_s->controllableEntity_) {
/*
-
- // Get results, create a node/entity on the position
- for ( itr = result.begin(); itr != result.end(); itr++ )
- {
- if (itr->movable && itr->movable->getName() == "Head")
- {
- soundMgr->StopSound( &jaguarSoundChannel );
- soundMgr->PlaySound( jaguarSound, headNode, &jaguarSoundChannel );
- break;
- } // if
- }
+ // Get results, create a node/entity on the position
+ for ( itr = result.begin(); itr != result.end(); itr++ )
+ {
+ if (itr->movable && itr->movable->getName() == "Head")
+ {
+ soundMgr->StopSound( &jaguarSoundChannel );
+ soundMgr->PlaySound( jaguarSound, headNode, &jaguarSoundChannel );
+ break;
+ } // if
+ }
*/
- HumanController::localController_s->getControllableEntity()->fire(firemode);
- //}
-//}
+ HumanController::localController_s->getControllableEntity()->fire(firemode);
}
- Vector3 NewHumanController::getTarget() {
- Ogre::RaySceneQuery * rsq = HumanController::localController_s->getControllableEntity()->getScene()->getSceneManager()->createRayQuery(Ogre::Ray());
+ Vector3 NewHumanController::getTarget()
+ {
+ Ogre::RaySceneQuery * rsq = HumanController::localController_s->getControllableEntity()->getScene()->getSceneManager()->createRayQuery(Ogre::Ray());
-//std::cout << "X: " << static_cast<float>(this->currentYaw_)/2*-1+.5 << " Y: " << static_cast<float>(this->currentPitch_)/2*-1+.5 << endl;
+ //std::cout << "X: " << static_cast<float>(this->currentYaw_)/2*-1+.5 << " Y: " << static_cast<float>(this->currentPitch_)/2*-1+.5 << endl;
- 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);
+ 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);
- rsq->setRay(mouseRay);
- rsq->setSortByDistance(true);
+ rsq->setRay(mouseRay);
+ rsq->setSortByDistance(true);
-/*
-Distance of objects:
-ignore everything under 200 maybe even take 1000 as min distance to shoot at
+ /*
+ Distance of objects:
+ ignore everything under 200 maybe even take 1000 as min distance to shoot at
-shots are regularly traced and are entities!!!!!!!!! this is the biggest problem
-they vanish only after a distance of 10'000
-*/
+ shots are regularly traced and are entities!!!!!!!!! this is the biggest problem
+ they vanish only after a distance of 10'000
+ */
- Ogre::RaySceneQueryResult &result = rsq->execute();
+ Ogre::RaySceneQueryResult& result = rsq->execute();
- Ogre::RaySceneQueryResult::iterator itr;
- for ( itr = result.begin(); itr != result.end(); itr++ )
+ Ogre::RaySceneQueryResult::iterator itr;
+ for (itr = result.begin(); itr != result.end(); ++itr)
+ {
+ //std::cout << "distance: " << itr->distance << " name: " << itr->movable->getName() << " type: " << itr->movable->getMovableType();
+ if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity" && itr->distance > 500)
{
- //std::cout << "distance: " << itr->distance << " name: " << itr->movable->getName() << " type: " << itr->movable->getMovableType();
- if (itr->movable->isInScene() && itr->movable->getMovableType() == "Entity" && itr->distance > 500) {
- //std::cout << " TAGGED";
- itr->movable->getParentSceneNode()->showBoundingBox(true);
-std::cout << itr->movable->getParentSceneNode()->_getDerivedPosition() << endl;
-return itr->movable->getParentSceneNode()->_getDerivedPosition();
+ // Try to cast the user pointer
+ WorldEntity* wePtr = dynamic_cast<WorldEntity*>(itr->movable->getUserObject());
+ if (wePtr)
+ {
+ BaseObject* creator = wePtr->getCreator();
+ if (this->targetMask_.isExcluded(creator->getIdentifier()))
+ continue;
}
- //std::cout << endl;
+ //std::cout << " TAGGED";
+ itr->movable->getParentSceneNode()->showBoundingBox(true);
+ std::cout << itr->movable->getParentSceneNode()->_getDerivedPosition() << endl;
+ return itr->movable->getParentSceneNode()->_getDerivedPosition();
}
+ //std::cout << endl;
+ }
-//if (result.front().movable->isInScene()) std::cout << "in scene" << endl;
-// && result.front().movable->getParentSceneNode() != NULL) result.front().movable->getParentSceneNode()->showBoundingBox(true);
-//result.front().movable->setVisible(false);
+ //if (result.front().movable->isInScene()) std::cout << "in scene" << endl;
+ // && result.front().movable->getParentSceneNode() != NULL) result.front().movable->getParentSceneNode()->showBoundingBox(true);
+ //result.front().movable->setVisible(false);
- //std::cout << endl;
+ //std::cout << endl;
/*
- if (!result.empty()) {
- Ogre::RaySceneQueryResultEntry obj = result.front();
- std::cout << "distance: " << obj.distance << " name: " << obj.movable->getName() << endl;
- }
+ if (!result.empty()) {
+ Ogre::RaySceneQueryResultEntry obj = result.front();
+ std::cout << "distance: " << obj.distance << " name: " << obj.movable->getName() << endl;
+ }
*/
- return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getWorldOrientation() * Vector3::NEGATIVE_UNIT_Z);
-//return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getCamera()->getCamera()->getOrientation() * Vector3::NEGATIVE_UNIT_Z);
+ return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getWorldOrientation() * Vector3::NEGATIVE_UNIT_Z * 100);
+ //return this->controllableEntity_->getWorldPosition() + (this->controllableEntity_->getCamera()->getCamera()->getOrientation() * Vector3::NEGATIVE_UNIT_Z);
}
void NewHumanController::yaw(const Vector2& value)
@@ -173,6 +181,7 @@
this->currentYaw_ = value.x;
//std::cout << "Y: " << static_cast<float>(this->currentPitch_) << " X: " << static_cast<float>(this->currentYaw_) << endl;
}
+
void NewHumanController::pitch(const Vector2& value)
{
// SUPER(NewHumanController, pitch, value);
@@ -181,5 +190,4 @@
this->currentPitch_ = value.x;
//std::cout << "Y: " << static_cast<float>(this->currentPitch_) << " X: " << static_cast<float>(this->currentYaw_) << endl;
}
-
}
Modified: code/branches/steering/src/orxonox/controllers/NewHumanController.h
===================================================================
--- code/branches/steering/src/orxonox/controllers/NewHumanController.h 2009-11-13 10:12:31 UTC (rev 6054)
+++ code/branches/steering/src/orxonox/controllers/NewHumanController.h 2009-11-13 10:21:40 UTC (rev 6055)
@@ -31,9 +31,8 @@
#include "OrxonoxPrereqs.h"
+#include "core/ClassTreeMask.h"
#include "HumanController.h"
-#include "overlays/OrxonoxOverlay.h"
-#include "util/OgreForwardRefs.h"
namespace orxonox
{
@@ -52,14 +51,16 @@
void changeMode(unsigned int controleMode);
+ virtual bool canFindTarget() { return true; }
virtual Vector3 getTarget();
private:
float currentYaw_;
float currentPitch_;
- OrxonoxOverlay *CrossHairOverlay;
- float overlaySize;
- unsigned int controlMode;
+ OrxonoxOverlay* crossHairOverlay_;
+ float overlaySize_;
+ unsigned int controlMode_;
+ ClassTreeMask targetMask_;
};
}
Modified: code/branches/steering/src/orxonox/infos/PlayerInfo.cc
===================================================================
--- code/branches/steering/src/orxonox/infos/PlayerInfo.cc 2009-11-13 10:12:31 UTC (rev 6054)
+++ code/branches/steering/src/orxonox/infos/PlayerInfo.cc 2009-11-13 10:21:40 UTC (rev 6055)
@@ -137,7 +137,8 @@
this->controller_ = this->defaultController_.fabricate(this);
assert(this->controller_);
this->controller_->setPlayer(this);
- if (this->controllableEntity_) {
+ if (this->controllableEntity_)
+ {
this->controller_->setControllableEntity(this->controllableEntity_);
this->controllableEntity_->setController(this->controller_);
}
@@ -159,7 +160,8 @@
this->bReadyToSpawn_ &= (!this->bSetUnreadyAfterSpawn_);
- if (this->controller_) {
+ if (this->controller_)
+ {
this->controller_->setControllableEntity(entity);
this->controllableEntity_->setController(this->controller_);
}
Modified: code/branches/steering/src/orxonox/weaponsystem/WeaponMode.cc
===================================================================
--- code/branches/steering/src/orxonox/weaponsystem/WeaponMode.cc 2009-11-13 10:12:31 UTC (rev 6054)
+++ code/branches/steering/src/orxonox/weaponsystem/WeaponMode.cc 2009-11-13 10:21:40 UTC (rev 6055)
@@ -31,6 +31,8 @@
#include "core/CoreIncludes.h"
#include "core/XMLPort.h"
+#include "controllers/Controller.h"
+#include "worldentities/pawns/Pawn.h"
#include "Munition.h"
#include "Weapon.h"
@@ -193,26 +195,32 @@
this->bReloading_ = false;
}
- Vector3 WeaponMode::getMuzzlePosition() const
+ void WeaponMode::computeMuzzleParameters()
{
if (this->weapon_)
- return (this->weapon_->getWorldPosition() + this->weapon_->getWorldOrientation() * this->muzzleOffset_);
- else
- return this->muzzleOffset_;
- }
+ {
+ this->muzzlePosition_ = this->weapon_->getWorldPosition() + this->weapon_->getWorldOrientation() * this->muzzleOffset_;
- const Quaternion& WeaponMode::getMuzzleOrientation() const
- {
- if (this->weapon_)
- return this->weapon_->getWorldOrientation();
+ Controller* controller = this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()->getController();
+ if (controller->canFindTarget())
+ {
+ Vector3 muzzleDirection(controller->getTarget() - this->muzzlePosition_);
+ this->muzzleOrientation_ = this->weapon_->getWorldOrientation() * (this->weapon_->getWorldOrientation() * WorldEntity::FRONT).getRotationTo(muzzleDirection);
+ }
+ else
+ this->muzzleOrientation_ = this->weapon_->getWorldOrientation();
+ }
else
- return Quaternion::IDENTITY;
+ {
+ this->muzzlePosition_ = this->muzzleOffset_;
+ this->muzzleOrientation_ = Quaternion::IDENTITY;
+ }
}
Vector3 WeaponMode::getMuzzleDirection() const
{
if (this->weapon_)
- return (this->weapon_->getWorldOrientation() * WorldEntity::FRONT);
+ return (this->getMuzzleOrientation() * WorldEntity::FRONT);
else
return WorldEntity::FRONT;
}
Modified: code/branches/steering/src/orxonox/weaponsystem/WeaponMode.h
===================================================================
--- code/branches/steering/src/orxonox/weaponsystem/WeaponMode.h 2009-11-13 10:12:31 UTC (rev 6054)
+++ code/branches/steering/src/orxonox/weaponsystem/WeaponMode.h 2009-11-13 10:21:40 UTC (rev 6055)
@@ -38,12 +38,6 @@
#include "core/SubclassIdentifier.h"
#include "tools/Timer.h"
-#include "weaponsystem/Weapon.h"
-#include "weaponsystem/WeaponPack.h"
-#include "weaponsystem/WeaponSystem.h"
-#include "worldentities/pawns/Pawn.h"
-#include "controllers/Controller.h"
-
namespace orxonox
{
class _OrxonoxExport WeaponMode : public BaseObject
@@ -114,8 +108,11 @@
inline const Vector3& getMuzzleOffset() const
{ return this->muzzleOffset_; }
- Vector3 getMuzzlePosition() const;
- const Quaternion& getMuzzleOrientation() const;
+ void computeMuzzleParameters();
+ const Vector3& getMuzzlePosition() const
+ { return this->muzzlePosition_; }
+ const Quaternion& getMuzzleOrientation() const
+ { return this->muzzleOrientation_; }
Vector3 getMuzzleDirection() const;
@@ -130,8 +127,7 @@
inline unsigned int getMode() const
{ return this->mode_; }
- inline Vector3 getTarget()
- { return this->getWeapon()->getWeaponPack()->getWeaponSystem()->getPawn()->getController()->getTarget(); }
+ Vector3 getTarget();
protected:
virtual void fire() = 0;
@@ -160,6 +156,9 @@
Timer reloadTimer_;
bool bReloading_;
+
+ Vector3 muzzlePosition_;
+ Quaternion muzzleOrientation_;
};
}
Modified: code/branches/steering/src/orxonox/worldentities/ControllableEntity.h
===================================================================
--- code/branches/steering/src/orxonox/worldentities/ControllableEntity.h 2009-11-13 10:12:31 UTC (rev 6054)
+++ code/branches/steering/src/orxonox/worldentities/ControllableEntity.h 2009-11-13 10:21:40 UTC (rev 6055)
@@ -141,8 +141,8 @@
inline Controller* getController() const
{ return this->controller_; }
- inline void setController(Controller* c)
- { this->controller_ = c; }
+ inline void setController(Controller* val)
+ { this->controller_ = val; }
protected:
virtual void setPlayer(PlayerInfo* player); // don't call this directly, use friend class PlayerInfo instead
Modified: code/branches/steering/src/orxonox/worldentities/WorldEntity.cc
===================================================================
--- code/branches/steering/src/orxonox/worldentities/WorldEntity.cc 2009-11-13 10:12:31 UTC (rev 6054)
+++ code/branches/steering/src/orxonox/worldentities/WorldEntity.cc 2009-11-13 10:21:40 UTC (rev 6055)
@@ -653,7 +653,7 @@
/**
@brief
- Makes this WorldEntity look a specific target location.
+ Makes this WorldEntity look at a specific target location.
@param relativeTo
@see WorldEntity::TransformSpace
@param localDirectionVector
More information about the Orxonox-commit
mailing list