source: GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.cpp @ 1692

Revision 1692, 1.8 KB checked in by mattausch, 18 years ago (diff)
Line 
1#include "IntersectableWrapper.h"
2#include "Mesh.h"
3#include "Triangle3.h"
4
5
6namespace GtpVisibilityPreprocessor {
7
8
9AxisAlignedBox3 TriangleIntersectable::GetBox() const
10{       
11        return mItem.GetBoundingBox();
12}
13
14
15int TriangleIntersectable::CastRay(Ray &ray)
16{       
17        float nearestT = MAX_FLOAT;
18        float t;
19        Vector3 nearestNormal;
20
21        if (ray.GetType() == Ray::LOCAL_RAY && !ray.intersections.empty())
22                nearestT = ray.intersections[0].mT;
23
24        const int hitCode = mItem.CastRay(ray, t, nearestT, nearestNormal);
25
26        nearestT = t;
27
28        if ((hitCode == Ray::INTERSECTION) && (ray.GetType() == Ray::LOCAL_RAY))
29        {
30                if (!ray.intersections.empty())
31                {
32                        ray.intersections[0] = Ray::Intersection(nearestT, nearestNormal, this, 0);
33                }
34                else
35                {
36                        ray.intersections.push_back(Ray::Intersection(nearestT, nearestNormal, this, 0));
37                }
38               
39                return 1;
40        }
41
42        return 0;
43}
44       
45
46int TriangleIntersectable::NumberOfFaces() const
47{
48        return 1;
49}
50
51
52Vector3 TriangleIntersectable::GetNormal(const int idx) const
53{
54        return mItem.GetNormal();
55}
56
57int
58TriangleIntersectable::GetRandomSurfacePoint(Vector3 &point, Vector3 &normal)
59{
60        // random barycentric coordinates
61        float a = RandomValue(0,1);
62        float b = RandomValue(0,1);
63        float c = RandomValue(0,1);
64       
65        const float sum = a + b + c;
66
67        // scale so we get vaccumated value of 1
68        if (sum)
69        {
70                a /= sum;
71                b /= sum;
72                c /= sum;
73        }
74
75        //cout << "a: " << a << " b: " << b << " c: " << c << " sum: " << sum << endl;
76        point = mItem.mVertices[0] * a + mItem.mVertices[1] * b + mItem.mVertices[2] * c;
77        normal = mItem.GetNormal();
78
79        return 0;
80}
81
82
83int TriangleIntersectable::GetRandomVisibleSurfacePoint(Vector3 &point,
84                                                                                                                Vector3 &normal,
85                                                                                                                const Vector3 &viewpoint,
86                                                                                                                const int maxTries)
87{
88        return GetRandomSurfacePoint(point, normal);
89}
90 
91}
Note: See TracBrowser for help on using the repository browser.