[Orxonox-commit 1592] r6310 - in code/branches/presentation2/src/orxonox: controllers overlays
wirthmi at orxonox.net
wirthmi at orxonox.net
Wed Dec 9 22:58:26 CET 2009
Author: wirthmi
Date: 2009-12-09 22:58:26 +0100 (Wed, 09 Dec 2009)
New Revision: 6310
Modified:
code/branches/presentation2/src/orxonox/controllers/NewHumanController.cc
code/branches/presentation2/src/orxonox/controllers/NewHumanController.h
code/branches/presentation2/src/orxonox/overlays/OrxonoxOverlay.cc
code/branches/presentation2/src/orxonox/overlays/OrxonoxOverlay.h
Log:
Added damage overlays
Modified: code/branches/presentation2/src/orxonox/controllers/NewHumanController.cc
===================================================================
--- code/branches/presentation2/src/orxonox/controllers/NewHumanController.cc 2009-12-09 21:57:59 UTC (rev 6309)
+++ code/branches/presentation2/src/orxonox/controllers/NewHumanController.cc 2009-12-09 21:58:26 UTC (rev 6310)
@@ -66,12 +66,17 @@
overlaySize_ = 0.08;
arrowsSize_ = 0.4;
+
+ damageOverlayTime_ = 0.6;
+
controlMode_ = 0;
acceleration_ = 0;
accelerating_ = false;
firemode_ = -1;
+
showArrows_ = true;
showOverlays_ = false;
+ showDamageOverlay_ = true;
//currentPitch_ = 1;
//currentYaw_ = 1;
@@ -90,8 +95,35 @@
centerOverlay_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0));\
centerOverlay_->hide();
- if (showArrows_)
+ if ( showDamageOverlay_ )
{
+ damageOverlayTop_ = new OrxonoxOverlay(this);
+ damageOverlayTop_->setBackgroundMaterial("Orxonox/DamageOverlayTop");
+ damageOverlayTop_->setSize(Vector2(overlaySize_ * 2.5, overlaySize_ * 2.5));
+ damageOverlayTop_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0));\
+ damageOverlayTop_->hide();
+
+ damageOverlayRight_ = new OrxonoxOverlay(this);
+ damageOverlayRight_->setBackgroundMaterial("Orxonox/DamageOverlayRight");
+ damageOverlayRight_->setSize(Vector2(overlaySize_ * 2.5, overlaySize_ * 2.5));
+ damageOverlayRight_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0));\
+ damageOverlayRight_->hide();
+
+ damageOverlayBottom_ = new OrxonoxOverlay(this);
+ damageOverlayBottom_->setBackgroundMaterial("Orxonox/DamageOverlayBottom");
+ damageOverlayBottom_->setSize(Vector2(overlaySize_ * 2.5, overlaySize_ * 2.5));
+ damageOverlayBottom_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0));\
+ damageOverlayBottom_->hide();
+
+ damageOverlayLeft_ = new OrxonoxOverlay(this);
+ damageOverlayLeft_->setBackgroundMaterial("Orxonox/DamageOverlayLeft");
+ damageOverlayLeft_->setSize(Vector2(overlaySize_ * 2.5, overlaySize_ * 2.5));
+ damageOverlayLeft_->setPosition(Vector2(0.5 - overlaySize_*2.5/2.0, 0.5 - overlaySize_*2.5/2.0));\
+ damageOverlayLeft_->hide();
+ }
+
+ if ( showArrows_ )
+ {
arrowsOverlay1_ = new OrxonoxOverlay(this);
arrowsOverlay1_->setBackgroundMaterial("Orxonox/DirectionArrows1");
arrowsOverlay1_->setSize(Vector2(0.02727, 0.36 * arrowsSize_));
@@ -167,7 +199,7 @@
this->updateTarget();
if ( !controlPaused_ ) {
- if (this->getControllableEntity() && this->getControllableEntity()->getIdentifier()->getName() == "SpaceShip")
+ if (this->getControllableEntity() && (this->getControllableEntity()->getIdentifier()->getName() == "SpaceShip" || this->getControllableEntity()->getIdentifier()->getName() == "Rocket"))
this->showOverlays();
this->crossHairOverlay_->setPosition(Vector2(static_cast<float>(this->currentYaw_)/2*-1+.5-overlaySize_/2, static_cast<float>(this->currentPitch_)/2*-1+.5-overlaySize_/2));
@@ -179,6 +211,21 @@
}
else
hideArrows();
+
+ if ( this->showDamageOverlay_ && ( this->damageOverlayTT_ > 0 || this->damageOverlayTR_ > 0 || this->damageOverlayTB_ > 0 || this->damageOverlayTL_ > 0 ) ) {
+ this->damageOverlayTT_ -= dt;
+ this->damageOverlayTR_ -= dt;
+ this->damageOverlayTB_ -= dt;
+ this->damageOverlayTL_ -= dt;
+ if ( this->damageOverlayTT_ <= 0 )
+ this->damageOverlayTop_->hide();
+ if ( this->damageOverlayTR_ <= 0 )
+ this->damageOverlayRight_->hide();
+ if ( this->damageOverlayTB_ <= 0 )
+ this->damageOverlayBottom_->hide();
+ if ( this->damageOverlayTL_ <= 0 )
+ this->damageOverlayLeft_->hide();
+ }
}
}
else
@@ -250,14 +297,51 @@
}
void NewHumanController::hit(Pawn* originator, btManifoldPoint& contactpoint, float damage) {
- Vector3 posA = multi_cast<Vector3>(contactpoint.getPositionWorldOnA());
- //Vector3 posB = multi_cast<Vector3>(contactpoint.getPositionWorldOnB());
- //posA and posB are almost identical
+ if ( showDamageOverlay_ ) {
+ Vector3 posA;
+ if ( originator )
+ posA = originator->getWorldPosition();
+ else
+ posA = multi_cast<Vector3>(contactpoint.getPositionWorldOnA());
+ //Vector3 posB = multi_cast<Vector3>(contactpoint.getPositionWorldOnB());
+ //posA and posB are almost identical
- Vector3 relativeHit = this->getControllableEntity()->getWorldOrientation() * (posA - this->getControllableEntity()->getPosition());
+ Vector3 relativeHit = this->getControllableEntity()->getWorldOrientation().UnitInverse() * (this->getControllableEntity()->getWorldPosition() - posA);
- COUT(0) << relativeHit << endl;
- //COUT(0) << "Damage: " << damage << " Point A: " << posA << " Point B: " << posB << endl;
+ //back is z positive
+ //x is left positive
+ //y is down positive
+ relativeHit.normalise();
+ COUT(0) << relativeHit << endl;
+
+ float threshold = 0.3;
+ // && abs(relativeHit.y) < 0.5
+ if ( relativeHit.x > threshold) // Left
+ {
+ this->damageOverlayLeft_->show();
+ this->damageOverlayTL_ = this->damageOverlayTime_;
+ //this->damageOverlayLeft_->setBackgroundAlpha(0.3);
+ }
+ if ( relativeHit.x < -threshold) //Right
+ {
+ this->damageOverlayRight_->show();
+ this->damageOverlayTR_ = this->damageOverlayTime_;
+ //this->damageOverlayRight_->setBackgroundAlpha(0.3);
+ }
+ if ( relativeHit.y > threshold) //Top
+ {
+ this->damageOverlayTop_->show();
+ this->damageOverlayTT_ = this->damageOverlayTime_;
+ //this->damageOverlayTop_->setBackgroundAlpha(0.3);
+ }
+ if ( relativeHit.y < -threshold) //Bottom
+ {
+ this->damageOverlayBottom_->show();
+ this->damageOverlayTB_ = this->damageOverlayTime_;
+ //this->damageOverlayBottom_->setBackgroundAlpha(0.3);
+ }
+
+ }
}
void NewHumanController::unfire()
@@ -484,6 +568,13 @@
this->crossHairOverlay_->hide();
this->centerOverlay_->hide();
+ if ( showDamageOverlay_ ) {
+ this->damageOverlayTop_->hide();
+ this->damageOverlayRight_->hide();
+ this->damageOverlayBottom_->hide();
+ this->damageOverlayLeft_->hide();
+ }
+
this->hideArrows();
}
Modified: code/branches/presentation2/src/orxonox/controllers/NewHumanController.h
===================================================================
--- code/branches/presentation2/src/orxonox/controllers/NewHumanController.h 2009-12-09 21:57:59 UTC (rev 6309)
+++ code/branches/presentation2/src/orxonox/controllers/NewHumanController.h 2009-12-09 21:58:26 UTC (rev 6310)
@@ -80,16 +80,29 @@
float currentPitch_;
OrxonoxOverlay* crossHairOverlay_;
OrxonoxOverlay* centerOverlay_;
+
+ OrxonoxOverlay* damageOverlayTop_;
+ OrxonoxOverlay* damageOverlayRight_;
+ OrxonoxOverlay* damageOverlayBottom_;
+ OrxonoxOverlay* damageOverlayLeft_;
+ float damageOverlayTime_;
+ float damageOverlayTT_;
+ float damageOverlayTR_;
+ float damageOverlayTB_;
+ float damageOverlayTL_;
+
OrxonoxOverlay* arrowsOverlay1_;
OrxonoxOverlay* arrowsOverlay2_;
OrxonoxOverlay* arrowsOverlay3_;
OrxonoxOverlay* arrowsOverlay4_;
+
float overlaySize_;
float arrowsSize_;
bool accelerating_;
float acceleration_;
int firemode_;
bool showArrows_;
+ bool showDamageOverlay_;
bool showOverlays_;
ClassTreeMask targetMask_;
};
Modified: code/branches/presentation2/src/orxonox/overlays/OrxonoxOverlay.cc
===================================================================
--- code/branches/presentation2/src/orxonox/overlays/OrxonoxOverlay.cc 2009-12-09 21:57:59 UTC (rev 6309)
+++ code/branches/presentation2/src/orxonox/overlays/OrxonoxOverlay.cc 2009-12-09 21:58:26 UTC (rev 6310)
@@ -38,6 +38,9 @@
#include <OgreOverlayManager.h>
#include <OgrePanelOverlayElement.h>
#include <OgreRenderWindow.h>
+#include <OgreMaterialManager.h>
+#include <OgreTechnique.h>
+#include <OgrePass.h>
#include "util/Convert.h"
#include "util/Exception.h"
@@ -369,4 +372,10 @@
this->changedOverlayGroup();
}
}
+
+ void OrxonoxOverlay::setBackgroundAlpha(float alpha) {
+ Ogre::MaterialPtr ptr = this->background_->getMaterial();
+ Ogre::TextureUnitState* tempTx = ptr->getTechnique(0)->getPass(0)->getTextureUnitState(0);
+ tempTx->setAlphaOperation(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, alpha);
+ }
}
Modified: code/branches/presentation2/src/orxonox/overlays/OrxonoxOverlay.h
===================================================================
--- code/branches/presentation2/src/orxonox/overlays/OrxonoxOverlay.h 2009-12-09 21:57:59 UTC (rev 6309)
+++ code/branches/presentation2/src/orxonox/overlays/OrxonoxOverlay.h 2009-12-09 21:58:26 UTC (rev 6310)
@@ -157,6 +157,8 @@
void setBackgroundMaterial(const std::string& material);
const std::string& getBackgroundMaterial() const;
+ void setBackgroundAlpha(float alpha);
+
virtual void changedVisibility();
inline void setOwner(BaseObject* owner)
@@ -204,6 +206,7 @@
static std::map<std::string, OrxonoxOverlay*> overlays_s;
BaseObject* owner_;
OverlayGroup* group_;
+ Ogre::Pass* backgroundAlphaPass_;
};
SUPER_FUNCTION(6, OrxonoxOverlay, changedOwner, false);
More information about the Orxonox-commit
mailing list