Subversion Repositories gelsvn

Rev

Rev 417 | Rev 422 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 417 Rev 420
Line 2... Line 2...
2
#define __RAY_H__
2
#define __RAY_H__
3
 
3
 
4
#include "../CGLA/Vec3i.h"
4
#include "../CGLA/Vec3i.h"
5
#include "../CGLA/Vec3f.h"
5
#include "../CGLA/Vec3f.h"
6
#include "TriMesh.h"
6
#include "TriMesh.h"
-
 
7
#include "Material.h"
7
 
8
 
8
namespace Geometry 
9
namespace Geometry 
9
{
10
{
10
		const double d_eps = 1.0e-12;
11
    const double d_eps = 1.0e-12;
11
		const float f_eps = 1.0e-6f;
12
    const float f_eps = 1.0e-6f;
Line 14... Line 15...
14
		{
15
    {
15
				// Constructor
16
        // Constructor
16
				Ray() 
17
        Ray() 
17
						: origin(0.0f), direction(0.0f), hit_pos(0.0f), hit_normal(0.0f), 
18
          : origin(0.0f), direction(0.0f), hit_pos(0.0f), hit_normal(0.0f), 
18
        has_hit(false), dist(CGLA::BIG), ior(1.0f), u(0.0f), v(0.0f), 
19
            has_hit(false), dist(CGLA::BIG), ior(1.0f), u(0.0f), v(0.0f), 
19
				hit_object(0)
20
            hit_object(0), trace_depth(0)
20
						{ }
21
        { }
21
 
22
 
22
				Ray(const CGLA::Vec3f& _origin, const CGLA::Vec3f& _direction) 
23
        Ray(const CGLA::Vec3f& _origin, const CGLA::Vec3f& _direction) 
23
						: origin(_origin), direction(_direction), hit_pos(0.0f), hit_normal(0.0f), 
24
          : origin(_origin), direction(_direction), hit_pos(0.0f), hit_normal(0.0f), 
24
        has_hit(false), dist(CGLA::BIG), ior(1.0f), u(0.0f), v(0.0f), 
25
            has_hit(false), dist(CGLA::BIG), ior(1.0f), u(0.0f), v(0.0f), 
25
				hit_object(0)
26
            hit_object(0), trace_depth(0)
26
						{ }
27
        { }
27
 
28
 
28
				CGLA::Vec3f origin;
29
        CGLA::Vec3f origin;
29
				CGLA::Vec3f direction;
30
        CGLA::Vec3f direction;
30
				CGLA::Vec3f hit_pos;
31
        CGLA::Vec3f hit_pos;
Line 40... Line 41...
40
 
41
 
41
				int trace_depth;  // Current recursion number
42
        int trace_depth;  // Current recursion number
42
				size_t hit_face_id;
43
        size_t hit_face_id;
43
				int id;
44
        int id;
44
 
45
 
45
				const Geometry::TriMesh* hit_object;
46
        const TriMesh* hit_object;
-
 
47
 
-
 
48
        const Material* get_hit_material() const
-
 
49
        {
-
 
50
          if(!hit_object)
-
 
51
            return 0;
-
 
52
          return &hit_object->materials[hit_object->mat_idx[hit_face_id]];
-
 
53
        }
46
 
54
 
47
				void reset()
55
        void reset()
48
						{
56
        {
49
								dist = CGLA::BIG; 
57
            dist = CGLA::BIG; 
50
								hit_object = 0;
58
            hit_object = 0;
Line 96... Line 104...
96
								else 
104
            else 
97
										// Total internal reflection.
105
                // Total internal reflection.
98
										reflect(normal);
106
                reflect(normal);
99
						}
107
        }
100
 
108
 
101
				bool cond_set_parameter(float t, float _u, float _v, 
109
        bool cond_set_parameter(float t, float _u, float _v, Geometry::TriMesh* mesh, size_t idx)
102
																Geometry::TriMesh* mesh, size_t idx)
-
 
103
						{
110
        {
104
								if(t < dist)
111
            if(t < dist)
105
								{
112
            {
106
										dist = t;
113
                dist = t;
107
										u = _u;
114
                u = _u;