-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathconvex.hpp
More file actions
90 lines (73 loc) · 2.15 KB
/
Copy pathconvex.hpp
File metadata and controls
90 lines (73 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef VPYTHON_PYTHON_CONVEX_HPP
#define VPYTHON_PYTHON_CONVEX_HPP
// Copyright (c) 2000, 2001, 2002, 2003 by David Scherer and others.
// Copyright (c) 2004 by Jonathan Brandmeyer and others.
// See the file license.txt for complete license terms.
// See the file authors.txt for a complete list of contributors.
#include "renderable.hpp"
#include "util/sorted_model.hpp"
#include "python/arrayprim.hpp"
#include <vector>
namespace cvisual { namespace python {
class convex : public arrayprim
{
private:
struct face : triangle
{
double d;
inline face( const vector& v1, const vector& v2, const vector& v3)
: triangle( v1, v2, v3), d( normal.dot(corner[0]))
{
}
inline bool visible_from( const vector& p)
{ return normal.dot(p) > d; }
};
struct edge
{
vector v[2];
inline edge( vector a, vector b)
{ v[0]=a; v[1]=b; }
inline bool
operator==( const edge& b) const
{
// There are two cases where a pair of edges are equal, the first is
// occurs when the endpoints are both the same, while the other occurs
// when the edge have the same endpoints in opposite directions.
// Since the first case never happens when we construct the hull, we
// only test for the second case here.
return (v[0] == b.v[1] && v[1] == b.v[0]);
}
};
struct jitter_table
{
enum { mask = 1023 };
enum { count = mask+1 };
double v[count];
jitter_table()
{
for(int i=0; i<count; i++)
v[i] = (static_cast<double>(rand()) / RAND_MAX - 0.5) * 2 * 1e-6;
}
};
static jitter_table jitter; // Use default construction for initialization.
long last_checksum;
long checksum() const;
bool degenerate() const;
// Hull construction routines.
void recalc();
void add_point( size_t, vector);
std::vector<face> hull;
vector min_extent, max_extent;
public:
convex();
void set_color( const rgb&);
rgb get_color();
protected:
virtual void gl_render( const view&);
virtual vector get_center() const;
virtual void gl_pick_render( const view&);
virtual void grow_extent( extent&);
virtual void get_material_matrix( const view&, tmatrix& out );
};
} } // !namespace cvisual::python
#endif // !defined VPYTHON_PYTHON_CONVEX_HPP