Subversion Repositories gelsvn

Rev

Rev 299 | Rev 443 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 299 Rev 304
Line 1... Line 1...
1
#ifndef __BBOX_H__
1
#ifndef __BBOX_H__
2
#define __BBOX_H__
2
#define __BBOX_H__
3
 
3
 
4
#include "CGLA/Vec3f.h"
4
#include "CGLA/Vec3f.h"
5
 
5
 
6
#include "Ray.h"
6
#include "Ray.h"
7
 
7
 
8
namespace Geometry 
8
namespace Geometry 
9
{
9
{
10
  struct ISectTri 
10
  struct ISectTri 
11
  {
11
  {
12
    CGLA::Vec3f point0;
12
    CGLA::Vec3f point0;
13
    CGLA::Vec3f point1;
13
    CGLA::Vec3f point1;
14
    CGLA::Vec3f point2;
14
    CGLA::Vec3f point2;
15
    
15
    
16
    CGLA::Vec3f edge0; // Optimization
16
    CGLA::Vec3f edge0; // Optimization
17
    CGLA::Vec3f edge1; // Optimization
17
    CGLA::Vec3f edge1; // Optimization
18
    unsigned int mesh_id;
18
    unsigned int mesh_id;
19
    unsigned int tri_id; // pad to 48 bytes for cache alignment purposes
19
    unsigned int tri_id; // pad to 48 bytes for cache alignment purposes
20
  };
20
  };
21
 
21
 
22
  struct TriAccel
22
  struct TriAccel
23
  {
23
  {
24
    // first 16 byte half cache line
24
    // first 16 byte half cache line
25
    // plane:
25
    // plane:
26
    double n_u;  //!< == normal.u / normal.k
26
    double n_u;  //!< == normal.u / normal.k
27
    double n_v;  //!< == normal.v / normal.k
27
    double n_v;  //!< == normal.v / normal.k
28
    double n_d;  //!< constant of plane equation
28
    double n_d;  //!< constant of plane equation
29
    int k;       // projection dimension
29
    int k;       // projection dimension
30
 
30
 
31
    // second 16 byte half cache line
31
    // second 16 byte half cache line
32
    // line equation for line ac
32
    // line equation for line ac
33
    double b_nu;
33
    double b_nu;
34
    double b_nv;
34
    double b_nv;
35
    double b_d;
35
    double b_d;
36
    unsigned int mesh_id;
36
    unsigned int mesh_id;
37
 
37
 
38
    // third 16 byte half cache line
38
    // third 16 byte half cache line
39
    // line equation for line ab
39
    // line equation for line ab
40
    double c_nu;
40
    double c_nu;
41
    double c_nv;
41
    double c_nv;
42
    double c_d;
42
    double c_d;
43
 
43
 
44
    unsigned int tri_id; // pad to 48 bytes for cache alignment purposes
44
    unsigned int tri_id; // pad to 48 bytes for cache alignment purposes
45
  };
45
  };
46
 
46
 
47
  struct BBox 
47
  struct BBox 
48
  {
48
  {
49
    CGLA::Vec3f min_corner;
49
    CGLA::Vec3f min_corner;
50
    CGLA::Vec3f max_corner;
50
    CGLA::Vec3f max_corner;
51
 
51
 
52
    void intersect_min_max(Ray &ray, double &t_min, double &t_max) const ;
52
    void intersect_min_max(Ray &ray, double &t_min, double &t_max) const ;
53
    bool intersect(Ray &ray);
53
    bool intersect(Ray &ray);
54
    bool ray_triangle(CGLA::Vec3f &ray_start, CGLA::Vec3f &ray_end, ISectTri &tri);
54
    bool ray_triangle(CGLA::Vec3f &ray_start, CGLA::Vec3f &ray_end, ISectTri &tri);
55
    bool intersect_edge_box(CGLA::Vec3f &ray_start, CGLA::Vec3f &ray_end);
55
    bool intersect_edge_box(CGLA::Vec3f &ray_start, CGLA::Vec3f &ray_end);
56
    bool intersect_triangle(ISectTri &tri);
56
    bool intersect_triangle(ISectTri &tri);
57
    bool in_interval(double min_limit, double test_value, double max_limit);
57
    bool in_interval(double min_limit, double test_value, double max_limit);
58
    void compute_bbox(std::vector<ISectTri> &isectmesh);
58
    void compute_bbox(std::vector<ISectTri> &isectmesh);
59
    bool intersect_triangle_left(ISectTri &tri, double plane, int axis);
59
    bool intersect_triangle_left(ISectTri &tri, double plane, int axis);
60
    bool intersect_triangle_right(ISectTri &tri, double plane, int axis);
60
    bool intersect_triangle_right(ISectTri &tri, double plane, int axis);
61
    double area();
61
    double area();
62
  };
62
  };
63
}
63
}
64
 
64
 
65
#endif
65
#endif