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
IceRay.h
Go to the documentation of this file.
1 
8 
11 // Include Guard
12 #ifndef __ICERAY_H__
13 #define __ICERAY_H__
14 
16  {
17  public:
19  inline_ Ray() {}
21  inline_ Ray(const Point& orig, const Point& dir) : mOrig(orig), mDir(dir) {}
23  inline_ Ray(const Ray& ray) : mOrig(ray.mOrig), mDir(ray.mDir) {}
26 
27  float SquareDistance(const Point& point, float* t=null) const;
28  inline_ float Distance(const Point& point, float* t=null) const { return sqrtf(SquareDistance(point, t)); }
29 
32  };
33 
34  inline_ void ComputeReflexionVector(Point& reflected, const Point& incoming_dir, const Point& outward_normal)
35  {
36  reflected = incoming_dir - outward_normal * 2.0f * (incoming_dir|outward_normal);
37  }
38 
39  inline_ void ComputeReflexionVector(Point& reflected, const Point& source, const Point& impact, const Point& normal)
40  {
41  Point V = impact - source;
42  reflected = V - normal * 2.0f * (V|normal);
43  }
44 
45  inline_ void DecomposeVector(Point& normal_compo, Point& tangent_compo, const Point& outward_dir, const Point& outward_normal)
46  {
47  normal_compo = outward_normal * (outward_dir|outward_normal);
48  tangent_compo = outward_dir - normal_compo;
49  }
50 
52 
58  inline_ void ComputeLocalDirection(Point& local_dir, const Point& world_dir, const Matrix4x4& world)
60  {
61  // Get world direction back in local space
62 // Matrix3x3 InvWorld = world;
63 // local_dir = InvWorld * world_dir;
64  local_dir = Matrix3x3(world) * world_dir;
65  }
66 
68 
74  inline_ void ComputeLocalPoint(Point& local_pt, const Point& world_pt, const Matrix4x4& world)
76  {
77  // Get world vertex back in local space
78  Matrix4x4 InvWorld = world;
79  InvWorld.Invert();
80  local_pt = world_pt * InvWorld;
81  }
82 
84 
90  inline_ void ComputeLocalRay(Ray& local_ray, const Ray& world_ray, const Matrix4x4& world)
92  {
93  // Get world ray back in local space
94  ComputeLocalDirection(local_ray.mDir, world_ray.mDir, world);
95  ComputeLocalPoint(local_ray.mOrig, world_ray.mOrig, world);
96  }
97 
98 #endif // __ICERAY_H__