1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
2 | /* |
---|
3 | * ---------------------------------------------------------------------- |
---|
4 | * ConvexPolygon.h: convex polygon class |
---|
5 | * |
---|
6 | * ====================================================================== |
---|
7 | * AUTHOR: Wei Qiao <qiaow@purdue.edu> |
---|
8 | * Purdue Rendering and Perceptualization Lab (PURPL) |
---|
9 | * |
---|
10 | * Copyright (c) 2004-2006 Purdue Research Foundation |
---|
11 | * |
---|
12 | * See the file "license.terms" for information on usage and |
---|
13 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
14 | * ====================================================================== |
---|
15 | */ |
---|
16 | #ifndef _CONVEX_POLYGON_H_ |
---|
17 | #define _CONVEX_POLYGON_H_ |
---|
18 | |
---|
19 | #include <assert.h> |
---|
20 | #include <vector> |
---|
21 | |
---|
22 | #include "Vector4.h" |
---|
23 | #include "Plane.h" |
---|
24 | |
---|
25 | typedef std::vector<Vector4> VertexVector; |
---|
26 | typedef std::vector<Vector4> TexVector; |
---|
27 | |
---|
28 | class ConvexPolygon |
---|
29 | { |
---|
30 | public: |
---|
31 | VertexVector vertices; |
---|
32 | TexVector texcoords; |
---|
33 | int volume_id; //which volume this polygon slice belongs to |
---|
34 | |
---|
35 | ConvexPolygon() |
---|
36 | {} |
---|
37 | |
---|
38 | ConvexPolygon(VertexVector vertices); |
---|
39 | |
---|
40 | void transform(const Mat4x4& mat); |
---|
41 | |
---|
42 | void translate(const Vector4& shift); |
---|
43 | |
---|
44 | // Clips the polygon, retaining the portion where ax + by + cz + d >= 0 |
---|
45 | void clip(Plane& clipPlane, bool copy_to_texcoords); |
---|
46 | |
---|
47 | void Emit(bool use_texture); |
---|
48 | |
---|
49 | void Emit(bool use_texture, const Vector3& shift, const Vector3& scale); |
---|
50 | |
---|
51 | void copy_vertices_to_texcoords(); |
---|
52 | |
---|
53 | void set_id(int v_id) |
---|
54 | { |
---|
55 | volume_id = v_id; |
---|
56 | } |
---|
57 | |
---|
58 | void append_vertex(const Vector4& vert) |
---|
59 | { |
---|
60 | vertices.push_back(vert); |
---|
61 | } |
---|
62 | |
---|
63 | void insert_vertex(unsigned int index, const Vector4& vert) |
---|
64 | { |
---|
65 | assert(index<vertices.size()); |
---|
66 | vertices.insert(vertices.begin() + index, vert); |
---|
67 | } |
---|
68 | |
---|
69 | bool is_retained(const Vector4& point, const Vector4& plane) |
---|
70 | { |
---|
71 | return ((point * plane) >= 0); |
---|
72 | } |
---|
73 | }; |
---|
74 | |
---|
75 | #endif |
---|