00001 #include "disp/ray.H"
00002
00003 using namespace mlib;
00004
00005 RAYhit::RAYhit(
00006 CXYpt &p
00007 ) : _s(false),
00008 _is_surf(0),
00009 _d(-1),
00010 _d_2d(-1),
00011 _g(0),
00012 _visibility(1),
00013 _appear(0),
00014 _tolerance(12),
00015 _from_camera(1)
00016 {
00017 _p = Wpt (p);
00018 _v = Wvec(p);
00019 }
00020
00021 int
00022 RAYhit::test(
00023 double d,
00024 int is_surface,
00025 double d_2d
00026 )
00027 {
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 if ((_s == false && (is_surface || d_2d < _tolerance)) ||
00039 (!is_surface && (d_2d < _tolerance) && (_is_surf || d_2d < _d_2d)) ||
00040 ( is_surface && d < _d && _is_surf))
00041 return 1;
00042 return 0;
00043 }
00044
00045 void
00046 RAYhit::check(
00047 double d,
00048 int is_surface,
00049 double d_2d,
00050 CGELptr &g,
00051 CWvec &n,
00052 CWpt &nearpt,
00053 CWpt &surfl,
00054 APPEAR *app,
00055 CXYpt &tex_coord
00056 )
00057 {
00058 if (test(d, is_surface, d_2d)) {
00059 _s = true;
00060 _d = d;
00061 _d_2d = is_surface ? _d_2d : d_2d;
00062 _is_surf = is_surface;
00063 _n = n;
00064 _nearpt = nearpt;
00065 _g = g;
00066 _surfl = surfl;
00067 _uv = tex_coord;
00068 _appear = app;
00069 }
00070 }
00071
00072 RAYhit
00073 RAYhit::invert(
00074 CWpt &pt
00075 ) const
00076 {
00077 Wvec v((point() - pt).normalized());
00078 return RAYhit(pt + v*1e-5, v);
00079 }
00080
00081
00082
00083 XYpt
00084 RAYhit::screen_point() const
00085 {
00086 return XYpt(_p + _v);
00087 }
00088
00089
00090 void
00091 RAYhit::clear(void)
00092 {
00093 _d = 0;
00094 _d_2d = -1;
00095 _g = 0;
00096 _s = false;
00097 _appear = 0;
00098 }
00099
00100 RAYnear::RAYnear(
00101 CXYpt &p
00102 ) : _s(false), _d_for_geom(-1)
00103 {
00104 _p = Wpt (p);
00105 _v = Wvec(p);
00106 }
00107
00108 void
00109 RAYnear::check(
00110 double d,
00111 CGELptr &g
00112 )
00113 {
00114 if (_s == false ) {
00115 _s = true;
00116 _d = d;
00117 if (_d_for_geom == -1 || d < _d_for_geom)
00118 _g = g;
00119 } else if (d <= _d) {
00120 _d = d;
00121 if (_d_for_geom == -1 || d < _d_for_geom - 1e-7)
00122 _g = g;
00123 }
00124 }
00125
00126 void
00127 RAYnear::check_geom(
00128 double d,
00129 CGELptr &g
00130 )
00131 {
00132 if ((_d_for_geom == -1 && d <= _d+1e-7) ||
00133 (_d_for_geom != -1 && d <= _d_for_geom)) {
00134 _d_for_geom = d;
00135 _g = g;
00136 }
00137 }
00138
00139
00140 void
00141 RAYnear::clear(void)
00142 {
00143 _d_for_geom = -1;
00144 _g = 0;
00145 _s = false;
00146 }