simplemap.cpp
Go to the documentation of this file.
1 #include "raytracer.h"
2 
3 namespace RayTracer {
4  using namespace std;
5 
6 
7  bool Segment::ray_tracing(const double p[2], const double direction,
8  double& range, double &alpha) const {
9 
10  int found = segment_ray_tracing(this->p0, this->p1, p, direction, &range);
11 
12  if(found) {
13  alpha = segment_alpha(this->p0, this->p1);
14 
15  /* alpha and direction should have versors with negative dot product */
16  if( cos(alpha)*cos(direction) + sin(alpha)*sin(direction) > 0 )
17  alpha = alpha + M_PI;
18 
19  alpha = normalize_0_2PI(alpha);
20 
21  return true;
22  } else {
23  alpha = NAN;
24  return false;
25  }
26  };
27 
28  bool Environment::ray_tracing(const double p[2], const double direction, double& out_distance, double &out_alpha, int*stuff_id) const {
29 
30  int champion = -1;
31  double champion_range, champion_alpha;
32  for(size_t i=0;i<stuff.size();i++) {
33  Stuff * s = stuff.at(i);
34 
35  double range, alpha;
36  if(s->ray_tracing(p,direction,range,alpha)){
37  if(champion==-1 || range<champion_range) {
38  champion = i;
39  champion_range = range;
40  champion_alpha = alpha;
41  }
42  }
43 
44  }
45 
46  if(champion != -1) {
47  *stuff_id = champion;
48  out_distance = champion_range;
49  out_alpha = champion_alpha;
50 
51  return true;
52  } else {
53  return false;
54  }
55  }
56 } // namespace SimpleMap
bool ray_tracing(const double p[2], const double direction, double &out_distance, double &out_alpha, int *stuff_id) const
Definition: simplemap.cpp:28
#define NAN
Definition: math_utils.h:11
double normalize_0_2PI(double t)
Definition: math_utils.c:198
#define M_PI
Definition: math_utils.h:7
struct @0 p
double segment_alpha(const double p0[2], const double p1[2])
Definition: math_utils.c:257
bool ray_tracing(const double p[2], const double direction, double &out_distance, double &out_alpha) const
Definition: simplemap.cpp:7
int segment_ray_tracing(const double p0[2], const double p1[2], const double eye[2], double direction, double *range)
Definition: math_utils.c:218
virtual bool ray_tracing(const double p[2], const double direction, double &out_distance, double &out_alpha) const =0


csm
Author(s): Andrea Censi
autogenerated on Tue May 11 2021 02:18:23