Go to the documentation of this file.00001 #include "raytracer.h"
00002
00003 namespace RayTracer {
00004 using namespace std;
00005
00006
00007 bool Segment::ray_tracing(const double p[2], const double direction,
00008 double& range, double &alpha) const {
00009
00010 int found = segment_ray_tracing(this->p0, this->p1, p, direction, &range);
00011
00012 if(found) {
00013 alpha = segment_alpha(this->p0, this->p1);
00014
00015
00016 if( cos(alpha)*cos(direction) + sin(alpha)*sin(direction) > 0 )
00017 alpha = alpha + M_PI;
00018
00019 alpha = normalize_0_2PI(alpha);
00020
00021 return true;
00022 } else {
00023 alpha = NAN;
00024 return false;
00025 }
00026 };
00027
00028 bool Environment::ray_tracing(const double p[2], const double direction, double& out_distance, double &out_alpha, int*stuff_id) const {
00029
00030 int champion = -1;
00031 double champion_range, champion_alpha;
00032 for(size_t i=0;i<stuff.size();i++) {
00033 Stuff * s = stuff.at(i);
00034
00035 double range, alpha;
00036 if(s->ray_tracing(p,direction,range,alpha)){
00037 if(champion==-1 || range<champion_range) {
00038 champion = i;
00039 champion_range = range;
00040 champion_alpha = alpha;
00041 }
00042 }
00043
00044 }
00045
00046 if(champion != -1) {
00047 *stuff_id = champion;
00048 out_distance = champion_range;
00049 out_alpha = champion_alpha;
00050
00051 return true;
00052 } else {
00053 return false;
00054 }
00055 }
00056 }