Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
unit_collide.cpp File Reference
#include "vegastrike.h"
#include "beam.h"
#include "bolt.h"
#include "gfx/mesh.h"
#include "unit_collide.h"
#include "physics.h"
#include "collide2/CSopcodecollider.h"
#include "collide2/csgeom2/optransfrm.h"
#include "collide2/basecollider.h"
#include "hashtable.h"
#include <string>
#include "vs_globals.h"
#include "configxml.h"
#include "collide.h"

Go to the source code of this file.

Functions

static bool operator== (const Collidable &a, const Collidable &b)
 
Vector Vabs (const Vector &in)
 
Matrix WarpMatrixForCollisions (Unit *un, const Matrix &ctm)
 
float mysqr (float a)
 
float globQueryShell (QVector st, QVector dir, float radius)
 
float globQuerySphere (QVector start, QVector end, QVector pos, float radius)
 

Function Documentation

float globQueryShell ( QVector  st,
QVector  dir,
float  radius 
)

Definition at line 308 of file unit_collide.cpp.

References a, b, c, and UniverseUtil::sqrt().

Referenced by Unit::AutoPilotToErrorMessage(), and globQuerySphere().

309 {
310  float temp1 = radius;
311  float a, b, c;
312  c = st.Dot( st );
313  c = c-temp1*temp1;
314  b = 2.0f*( dir.Dot( st ) );
315  a = dir.Dot( dir );
316  //b^2-4ac
317  c = b*b-4.0f*a*c;
318  if (c < 0 || a == 0)
319  return 0.0f;
320  a *= 2.0f;
321 
322  float tmp = ( -b+sqrt( c ) )/a;
323  c = ( -b-sqrt( c ) )/a;
324  if (tmp > 0 && tmp <= 1)
325  return (c > 0 && c < tmp) ? c : tmp;
326  else if (c > 0 && c <= 1)
327  return c;
328  return 0.0f;
329 }
float globQuerySphere ( QVector  start,
QVector  end,
QVector  pos,
float  radius 
)

Definition at line 331 of file unit_collide.cpp.

References e, f, globQueryShell(), and QVector.

Referenced by Unit::rayCollide().

332 {
333  QVector st = start-pos;
334  if (st.MagnitudeSquared() < radius*radius)
335  return 1.0e-6f;
336  return globQueryShell( st, end-start, radius );
337 }
float mysqr ( float  a)
inline

Definition at line 241 of file unit_collide.cpp.

References a.

Referenced by Unit::Collide().

242 {
243  return a*a;
244 }
static bool operator== ( const Collidable a,
const Collidable b 
)
static

Unit mesh collision detection Provides various functions for collision detection

Definition at line 22 of file unit_collide.cpp.

23 {
24  return memcmp( &a, &b, sizeof (Collidable) ) == 0;
25 }
Vector Vabs ( const Vector in)

Definition at line 106 of file unit_collide.cpp.

References Vector.

Referenced by WarpMatrixForCollisions().

107 {
108  return Vector( in.i >= 0 ? in.i : -in.i,
109  in.j >= 0 ? in.j : -in.j,
110  in.k >= 0 ? in.k : -in.k );
111 }
Matrix WarpMatrixForCollisions ( Unit un,
const Matrix ctm 
)

Definition at line 114 of file unit_collide.cpp.

References Matrix::getR(), Unit::GetWarpVelocity(), k, Matrix::r, Unit::rSize(), SIMULATION_ATOM, v, Vabs(), and Vector.

115 {
116  if ( un->GetWarpVelocity().MagnitudeSquared()*SIMULATION_ATOM*SIMULATION_ATOM < un->rSize()*un->rSize() ) {
117  return ctm;
118  } else {
119  Matrix k( ctm );
120  const Vector v( Vector( 1, 1, 1 )+Vabs( ctm.getR()*ctm.getR().Dot( un->GetWarpVelocity().Scale(
121  100*SIMULATION_ATOM/un->rSize() ) ) ) );
122  k.r[0] *= v.i;
123  k.r[1] *= v.j;
124  k.r[2] *= v.k;
125 
126  k.r[3] *= v.i;
127  k.r[4] *= v.j;
128  k.r[5] *= v.k;
129 
130  k.r[6] *= v.i;
131  k.r[7] *= v.j;
132  k.r[8] *= v.k;
133  return k;
134  }
135 }