[Orxonox-commit 5127] r9792 - in code/branches/radarDreiD: data/levels src/libraries/util src/modules/overlays/hud

wroennin at orxonox.net wroennin at orxonox.net
Mon Nov 18 16:22:10 CET 2013


Author: wroennin
Date: 2013-11-18 16:22:09 +0100 (Mon, 18 Nov 2013)
New Revision: 9792

Modified:
   code/branches/radarDreiD/data/levels/radar3D_test.oxw
   code/branches/radarDreiD/src/libraries/util/Math.cc
   code/branches/radarDreiD/src/libraries/util/Math.h
   code/branches/radarDreiD/src/modules/overlays/hud/HUDRadar.cc
Log:
Math.cc: new function isObjectHigherThanShipOnMap, separated coordinatetransformation into a seperate function; Math.h: updated with new functions; HUDRadar.cc: added zOrder for rendering on screen; radar3D_test.oxw: canged spawn direction to 0,0,0

Modified: code/branches/radarDreiD/data/levels/radar3D_test.oxw
===================================================================
--- code/branches/radarDreiD/data/levels/radar3D_test.oxw	2013-11-18 15:10:21 UTC (rev 9791)
+++ code/branches/radarDreiD/data/levels/radar3D_test.oxw	2013-11-18 15:22:09 UTC (rev 9792)
@@ -31,7 +31,7 @@
   >
 
     <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/>
-    <SpawnPoint team=0 position="-500,0,0" lookat="-500,0,1" spawnclass=SpaceShip pawndesign=spaceshipescort />
+    <SpawnPoint team=0 position="-500,0,0" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipescort />
     
 
 

Modified: code/branches/radarDreiD/src/libraries/util/Math.cc
===================================================================
--- code/branches/radarDreiD/src/libraries/util/Math.cc	2013-11-18 15:10:21 UTC (rev 9791)
+++ code/branches/radarDreiD/src/libraries/util/Math.cc	2013-11-18 15:22:09 UTC (rev 9792)
@@ -203,7 +203,7 @@
 
             Examples:
              -
-        */
+    */
     orxonox::Vector2 get3DProjection(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition, const float mapangle, const float detectionlimit)
     {
     	// Orxonox Vectors: x_direction you are looking, y_direction points up, z_direction points to the right
@@ -221,7 +221,70 @@
     	    	distance = distance / distance.length();
     	   		}
 
+    	// perform a coordinate transformation to get distance in relation of the position of the ship
+    	orxonox::Vector3 distanceShip = getTransformedVector(distance, mydirection, myorthonormal, myside);
 
+    	// calculate 2D vector on the map (with angle between x/z - plain and line of sight)
+    	float xcoordinate = distanceShip.z; // z; cause x direction on screen is to the right side
+    	float ycoordinate = distanceShip.x*sin(mapangle)+distanceShip.y*cos(mapangle);
+    	return orxonox::Vector2(xcoordinate , ycoordinate);
+    }
+
+    /**
+               @brief Gets if a object is over the x/z - plain on map
+               @param myposition My position
+               @param mydirection My viewing direction
+               @param myorthonormal My orthonormalvector (pointing upwards through my head)
+               @param otherposition The position of the other object
+               @param mapangle The angle you look on the 3Dmap
+               @return If distancevector to the other object has a positive y-coordinate
+
+               Examples:
+                Returns true if object is over x/z - plain
+                Returns false if object is below x/z -plain
+    */
+    bool isObjectHigherThanShipOnMap(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition, const float mapangle)
+    {
+    	// Orxonox Vectors: x_direction you are looking, y_direction points up, z_direction points to the right
+    	orxonox::Vector3 distance = otherposition - myposition;
+
+    	// new coordinate system:	x_axsis:	mydirection		(points front)
+    	//							y_axsis:	myorthonormal	(points up)
+       	//							z_axsis:	myside			(points right)
+
+       	orxonox::Vector3 myside = mydirection.crossProduct(myorthonormal); // get vector from Ship to object
+
+
+       	// perform a coordinate transformation to get distance in relation of the position of the ship
+       	orxonox::Vector3 distanceShip = getTransformedVector(distance, mydirection, myorthonormal, myside);
+
+       	if(distanceShip.y >= 0)
+       		return true;
+       	else
+       		return false;
+    }
+
+
+    /**
+                @brief Gets the new vector after a coordinate transformation
+                @param distance Vector which will be transformed
+                @param mydirection New x basevector
+                @param myorthonormal New y basevector
+                @param otherposition New z basevector
+                @return direction in the new coordinates
+
+                x is vector in old coordinates
+                y is vector in old coordinates
+                T is transform matrix with:
+                	T = (t1 , t2 , t3)
+                	t1 = mydirection
+                	t2 = myorthonormal
+                	t3 = myside
+
+                y = T^(-1)*x
+            */
+    orxonox::Vector3 getTransformedVector(const orxonox::Vector3& distance, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& myside)
+    {
     	// inverse of the transform matrix
     	float determinant = +mydirection.x * (myorthonormal.y*myside.z - myside.y*myorthonormal.z)
     						-mydirection.y * (myorthonormal.x*myside.z - myorthonormal.z*myside.x)
@@ -249,23 +312,9 @@
     	distanceShip.y = xinvtransform.y * distance.x + yinvtransform.y * distance.y + zinvtransform.y * distance.z;
     	distanceShip.z = xinvtransform.z * distance.x + yinvtransform.z * distance.y + zinvtransform.z * distance.z;
 
-    	// cap vector for map if its to long
-    	//distance.x = clamp<float>(distance.x, -detectionlimit/5, detectionlimit/5);
-    	//distance.y = clamp<float>(distance.y, -detectionlimit/5, detectionlimit/5);
-    	//distance.z = clamp<float>(distance.z, -detectionlimit/5, detectionlimit/5);
-    	//float distancelength = distance.length();
-
-
-    	// project vector for the rotated 3DMap on screen
-    	//float xcoordinate = distance.z;
-    	//float ycoordinate = distance.y;
-
-    	float xcoordinate = distanceShip.z; // z; cause z direction is to the side
-    	float ycoordinate = distanceShip.x*sin(mapangle)+distanceShip.y*cos(mapangle);// -; cause on screen y coordinate points down
-    	return orxonox::Vector2(xcoordinate , ycoordinate);
+    	return distanceShip;
     }
 
-
     /**
         @brief Returns the predicted position I have to aim at, if I want to hit a moving target with a moving projectile.
         @param myposition My position

Modified: code/branches/radarDreiD/src/libraries/util/Math.h
===================================================================
--- code/branches/radarDreiD/src/libraries/util/Math.h	2013-11-18 15:10:21 UTC (rev 9791)
+++ code/branches/radarDreiD/src/libraries/util/Math.h	2013-11-18 15:22:09 UTC (rev 9792)
@@ -92,6 +92,8 @@
     _UtilExport orxonox::Vector2 get2DViewdirection(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition);
     _UtilExport orxonox::Vector2 get2DViewcoordinates(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition);
     _UtilExport orxonox::Vector2 get3DProjection(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition, const float mapangle, const float detectionlimit);
+    _UtilExport bool isObjectHigherThanShipOnMap(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition, const float mapangle);
+    _UtilExport orxonox::Vector3 getTransformedVector(const orxonox::Vector3& distance, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& myside);
     _UtilExport orxonox::Vector3 getPredictedPosition(const orxonox::Vector3& myposition, float projectilespeed, const orxonox::Vector3& targetposition, const orxonox::Vector3& targetvelocity);
 
     /**

Modified: code/branches/radarDreiD/src/modules/overlays/hud/HUDRadar.cc
===================================================================
--- code/branches/radarDreiD/src/modules/overlays/hud/HUDRadar.cc	2013-11-18 15:10:21 UTC (rev 9791)
+++ code/branches/radarDreiD/src/modules/overlays/hud/HUDRadar.cc	2013-11-18 15:22:09 UTC (rev 9792)
@@ -165,18 +165,24 @@
             float distance = (wePointer->getWorldPosition() - this->owner_->getPosition()).length();
             // calculate the size with 1/distance dependency for simplicity (instead of exp(-distance * lambda)
             float size = maximumDotSize_ * halfDotSizeDistance_ / (halfDotSizeDistance_ + distance) * it->first->getRadarObjectScale();
+
+
             it->second->setDimensions(size, size);
 
             // calc position on radar...
             //Vector2 coord = get2DViewcoordinates(this->owner_->getPosition(), this->owner_->getOrientation() * WorldEntity::FRONT, this->owner_->getOrientation() * WorldEntity::UP, wePointer->getWorldPosition());
             Vector2 coord = get3DProjection(this->owner_->getPosition(), this->owner_->getOrientation() * WorldEntity::FRONT, this->owner_->getOrientation() * WorldEntity::UP, wePointer->getWorldPosition(), 0.6435011, detectionLimit_);
-            if(coord.y < 0)
-            	{
-            	orxonox::ColourValue color = it->second->getColour();
-            	color.a = 0.5f;
-            	it->second->setColour(color);
-            	}
 
+            // set zOrder on screen
+            bool overXZPlain = isObjectHigherThanShipOnMap(this->owner_->getPosition(), this->owner_->getOrientation() * WorldEntity::FRONT, this->owner_->getOrientation() * WorldEntity::UP, wePointer->getWorldPosition(), 0.6435011);
+
+            if(overXZPlain == false && (it->second->getZOrder() >  100 * this->overlay_->getZOrder())) // it appears that zOrder of attached Overlayelements is 100 times the zOrder of the Overlay
+            	it->second->_notifyZOrder(this->overlay_->getZOrder() * 100 - 1);
+            if(overXZPlain == true && (it->second->getZOrder() <= 100 * this->overlay_->getZOrder()))
+            	it->second->_notifyZOrder(this->overlay_->getZOrder() * 100 + 1);
+
+
+
             coord *= math::pi / 3.5f; // small adjustment to make it fit the texture
             it->second->setPosition((1.0f + coord.x - size) * 0.5f, (1.0f - coord.y - size) * 0.5f);
 




More information about the Orxonox-commit mailing list