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
point_to_cam.h File Reference
#include "gfx/camera.h"

Go to the source code of this file.

Functions

bool CalculateOrientation (QVector &Pos, Vector &p, Vector &q, Vector &r, float &wid, float &hei, float OffsetByThisPercent, bool moveiftoofar, Matrix *local_transformation=NULL)
 

Function Documentation

bool CalculateOrientation ( QVector Pos,
Vector p,
Vector q,
Vector r,
float wid,
float hei,
float  OffsetByThisPercent,
bool  moveiftoofar,
Matrix local_transformation = NULL 
)
inline

Calculates the way a point-like sphere should be oriented, with a given input position. Pos will be tweaked, and p,q,r to be used will be returned. true will be returned if it is close enough to be rendered Uses current camera orientation If local_transformation is used, the object will attempt to use that to keep Its own up alignment, otherwise it will match the camera up If offsetbyradius is used the animation will appear closer than it is If moveiftoofar is true and also offset by radius is true then the item will be moved closer to the cam if it is too far and shrunken appropriately Fixed 052402 to have floating -> double for important values

Definition at line 20 of file point_to_cam.h.

References _Universe, Universe::AccessCamera(), g_game, Camera::GetPosition(), Camera::GetPQR(), QVector, Vector, game_data_t::zfar, and game_data_t::znear.

Referenced by Halo::Draw(), GameUnit< UnitType >::Draw(), and GameUnit< UnitType >::DrawNow().

29 {
30  const float kkkk = 3; //this seems to work for no good reason
31  _Universe->AccessCamera()->GetPQR( p, q, r );
32  QVector OLDR( r.i, r.j, r.k );
33  QVector offset( _Universe->AccessCamera()->GetPosition()-Pos );
34  double offz = -OLDR.Dot( offset );
35  if (OffsetByThisPercent != 0) {
36  double offmag = offset.Magnitude();
37  double rad = wid > hei ? wid : hei;
38  offset *= 1./offmag;
39  if ( (!moveiftoofar) || offz < rad+.4*g_game.zfar ) {
40  if (offz-OffsetByThisPercent*rad < 2*g_game.znear)
41  rad = (offz-2*g_game.znear)/OffsetByThisPercent;
42  offset *= OffsetByThisPercent*rad;
43  } else {
44  offset *= (offmag/offz)*(offz-2*g_game.znear); //-rad-.4*g_game.zfar);
45  wid /= ( (offz)/(kkkk*g_game.znear) ); //it's 1 time away from znear
46  hei /= ( (offz)/(kkkk*g_game.znear) );
47  }
48  Pos += offset;
49  offz += OLDR.Dot( offset ); //coming closer so this means that offz is less
50  }
51  if (local_transformation) {
52  Vector q1( local_transformation->r[1], local_transformation->r[4], local_transformation->r[7] );
53  Vector p1( ( q1.Dot( q ) )*q );
54  q = ( q1.Dot( p ) )*p+p1;
56 
57  posit = posit-local_transformation->p;
58 
59  Normalize( posit );
60  r.i = posit.i;
61  r.j = posit.j;
62  r.k = posit.k;
63  ScaledCrossProduct( q, r, p );
64  ScaledCrossProduct( r, p, q );
65  //if the vectors are linearly dependant we're phucked :) fun fun fun
66  }
67  return offz < .4*g_game.zfar;
68 }