Subversion Repositories gelsvn

Rev

Rev 299 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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