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
Go to the documentation of this file.
1 #ifndef _POINT_TO_CAM_H_
2 #define _POINT_TO_CAM_H_
3 
18 #include "gfx/camera.h"
19 
20 inline bool CalculateOrientation( QVector &Pos,
21  Vector &p,
22  Vector &q,
23  Vector &r,
24  float &wid,
25  float &hei,
26  float OffsetByThisPercent,
27  bool moveiftoofar,
28  Matrix *local_transformation = NULL )
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 }
69 
70 #endif
71