1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
2 | /* |
---|
3 | * Copyright (c) 2004-2013 HUBzero Foundation, LLC |
---|
4 | * |
---|
5 | * Authors: |
---|
6 | * Wei Qiao <qiaow@purdue.edu> |
---|
7 | */ |
---|
8 | #ifndef NV_CONVEX_POLYGON_H |
---|
9 | #define NV_CONVEX_POLYGON_H |
---|
10 | |
---|
11 | #include <assert.h> |
---|
12 | #include <vector> |
---|
13 | |
---|
14 | #include <vrmath/Vector3f.h> |
---|
15 | #include <vrmath/Vector4f.h> |
---|
16 | #include <vrmath/Matrix4x4d.h> |
---|
17 | |
---|
18 | #include "Plane.h" |
---|
19 | |
---|
20 | namespace nv { |
---|
21 | |
---|
22 | typedef std::vector<vrmath::Vector4f> VertexVector; |
---|
23 | typedef std::vector<vrmath::Vector4f> TexVector; |
---|
24 | |
---|
25 | class ConvexPolygon |
---|
26 | { |
---|
27 | public: |
---|
28 | ConvexPolygon() |
---|
29 | {} |
---|
30 | |
---|
31 | ConvexPolygon(VertexVector vertices); |
---|
32 | |
---|
33 | void transform(const vrmath::Matrix4x4d& mat); |
---|
34 | |
---|
35 | void translate(const vrmath::Vector4f& shift); |
---|
36 | |
---|
37 | // Clips the polygon, retaining the portion where ax + by + cz + d >= 0 |
---|
38 | bool clip(nv::Plane& clipPlane, bool copyToTexcoords); |
---|
39 | |
---|
40 | void emit(bool useTexture); |
---|
41 | |
---|
42 | void emit(bool useTexture, const vrmath::Vector3f& shift, const vrmath::Vector3f& scale); |
---|
43 | |
---|
44 | void copyVerticesToTexcoords(); |
---|
45 | |
---|
46 | void setId(int id) |
---|
47 | { |
---|
48 | volumeId = id; |
---|
49 | } |
---|
50 | |
---|
51 | void appendVertex(const vrmath::Vector4f& vert) |
---|
52 | { |
---|
53 | vertices.push_back(vert); |
---|
54 | } |
---|
55 | |
---|
56 | void insertVertex(unsigned int index, const vrmath::Vector4f& vert) |
---|
57 | { |
---|
58 | assert(index < vertices.size()); |
---|
59 | vertices.insert(vertices.begin() + index, vert); |
---|
60 | } |
---|
61 | |
---|
62 | VertexVector vertices; |
---|
63 | TexVector texcoords; |
---|
64 | int volumeId; //which volume this polygon slice belongs to |
---|
65 | }; |
---|
66 | |
---|
67 | } |
---|
68 | |
---|
69 | #endif |
---|