Changeset 9792 for code/branches/radarDreiD/src/libraries
- Timestamp:
- Nov 18, 2013, 4:22:09 PM (11 years ago)
- Location:
- code/branches/radarDreiD/src/libraries/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/radarDreiD/src/libraries/util/Math.cc
r9787 r9792 204 204 Examples: 205 205 - 206 206 */ 207 207 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) 208 208 { … … 222 222 } 223 223 224 224 // perform a coordinate transformation to get distance in relation of the position of the ship 225 orxonox::Vector3 distanceShip = getTransformedVector(distance, mydirection, myorthonormal, myside); 226 227 // calculate 2D vector on the map (with angle between x/z - plain and line of sight) 228 float xcoordinate = distanceShip.z; // z; cause x direction on screen is to the right side 229 float ycoordinate = distanceShip.x*sin(mapangle)+distanceShip.y*cos(mapangle); 230 return orxonox::Vector2(xcoordinate , ycoordinate); 231 } 232 233 /** 234 @brief Gets if a object is over the x/z - plain on map 235 @param myposition My position 236 @param mydirection My viewing direction 237 @param myorthonormal My orthonormalvector (pointing upwards through my head) 238 @param otherposition The position of the other object 239 @param mapangle The angle you look on the 3Dmap 240 @return If distancevector to the other object has a positive y-coordinate 241 242 Examples: 243 Returns true if object is over x/z - plain 244 Returns false if object is below x/z -plain 245 */ 246 bool isObjectHigherThanShipOnMap(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition, const float mapangle) 247 { 248 // Orxonox Vectors: x_direction you are looking, y_direction points up, z_direction points to the right 249 orxonox::Vector3 distance = otherposition - myposition; 250 251 // new coordinate system: x_axsis: mydirection (points front) 252 // y_axsis: myorthonormal (points up) 253 // z_axsis: myside (points right) 254 255 orxonox::Vector3 myside = mydirection.crossProduct(myorthonormal); // get vector from Ship to object 256 257 258 // perform a coordinate transformation to get distance in relation of the position of the ship 259 orxonox::Vector3 distanceShip = getTransformedVector(distance, mydirection, myorthonormal, myside); 260 261 if(distanceShip.y >= 0) 262 return true; 263 else 264 return false; 265 } 266 267 268 /** 269 @brief Gets the new vector after a coordinate transformation 270 @param distance Vector which will be transformed 271 @param mydirection New x basevector 272 @param myorthonormal New y basevector 273 @param otherposition New z basevector 274 @return direction in the new coordinates 275 276 x is vector in old coordinates 277 y is vector in old coordinates 278 T is transform matrix with: 279 T = (t1 , t2 , t3) 280 t1 = mydirection 281 t2 = myorthonormal 282 t3 = myside 283 284 y = T^(-1)*x 285 */ 286 orxonox::Vector3 getTransformedVector(const orxonox::Vector3& distance, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& myside) 287 { 225 288 // inverse of the transform matrix 226 289 float determinant = +mydirection.x * (myorthonormal.y*myside.z - myside.y*myorthonormal.z) … … 250 313 distanceShip.z = xinvtransform.z * distance.x + yinvtransform.z * distance.y + zinvtransform.z * distance.z; 251 314 252 // cap vector for map if its to long 253 //distance.x = clamp<float>(distance.x, -detectionlimit/5, detectionlimit/5); 254 //distance.y = clamp<float>(distance.y, -detectionlimit/5, detectionlimit/5); 255 //distance.z = clamp<float>(distance.z, -detectionlimit/5, detectionlimit/5); 256 //float distancelength = distance.length(); 257 258 259 // project vector for the rotated 3DMap on screen 260 //float xcoordinate = distance.z; 261 //float ycoordinate = distance.y; 262 263 float xcoordinate = distanceShip.z; // z; cause z direction is to the side 264 float ycoordinate = distanceShip.x*sin(mapangle)+distanceShip.y*cos(mapangle);// -; cause on screen y coordinate points down 265 return orxonox::Vector2(xcoordinate , ycoordinate); 266 } 267 315 return distanceShip; 316 } 268 317 269 318 /** -
code/branches/radarDreiD/src/libraries/util/Math.h
r9740 r9792 93 93 _UtilExport orxonox::Vector2 get2DViewcoordinates(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition); 94 94 _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); 95 _UtilExport bool isObjectHigherThanShipOnMap(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition, const float mapangle); 96 _UtilExport orxonox::Vector3 getTransformedVector(const orxonox::Vector3& distance, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& myside); 95 97 _UtilExport orxonox::Vector3 getPredictedPosition(const orxonox::Vector3& myposition, float projectilespeed, const orxonox::Vector3& targetposition, const orxonox::Vector3& targetvelocity); 96 98
Note: See TracChangeset
for help on using the changeset viewer.