[2798] | 1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
[982] | 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 | |
---|
[2822] | 22 | #include "Vector4.h" |
---|
| 23 | #include "Plane.h" |
---|
| 24 | |
---|
[982] | 25 | typedef std::vector<Vector4> VertexVector; |
---|
| 26 | typedef std::vector<Vector4> TexVector; |
---|
| 27 | |
---|
[2822] | 28 | class ConvexPolygon |
---|
| 29 | { |
---|
[982] | 30 | public: |
---|
| 31 | VertexVector vertices; |
---|
| 32 | TexVector texcoords; |
---|
| 33 | int volume_id; //which volume this polygon slice belongs to |
---|
[2822] | 34 | |
---|
| 35 | ConvexPolygon() |
---|
| 36 | {} |
---|
| 37 | |
---|
[982] | 38 | ConvexPolygon(VertexVector vertices); |
---|
[2822] | 39 | |
---|
| 40 | void transform(const Mat4x4& mat); |
---|
| 41 | |
---|
| 42 | void translate(const Vector4& shift); |
---|
| 43 | |
---|
[982] | 44 | // Clips the polygon, retaining the portion where ax + by + cz + d >= 0 |
---|
[2822] | 45 | void clip(Plane& clipPlane, bool copy_to_texcoords); |
---|
| 46 | |
---|
[982] | 47 | void Emit(bool use_texture); |
---|
[2822] | 48 | |
---|
| 49 | void Emit(bool use_texture, const Vector3& shift, const Vector3& scale); |
---|
| 50 | |
---|
[982] | 51 | void copy_vertices_to_texcoords(); |
---|
| 52 | |
---|
[2822] | 53 | void set_id(int v_id) |
---|
| 54 | { |
---|
| 55 | volume_id = v_id; |
---|
[982] | 56 | } |
---|
[2822] | 57 | |
---|
| 58 | void append_vertex(const Vector4& vert) |
---|
| 59 | { |
---|
| 60 | vertices.push_back(vert); |
---|
[982] | 61 | } |
---|
[2822] | 62 | |
---|
| 63 | void insert_vertex(unsigned int index, const Vector4& vert) |
---|
| 64 | { |
---|
| 65 | assert(index<vertices.size()); |
---|
| 66 | vertices.insert(vertices.begin() + index, vert); |
---|
[982] | 67 | } |
---|
[2822] | 68 | |
---|
| 69 | bool is_retained(const Vector4& point, const Vector4& plane) |
---|
| 70 | { |
---|
| 71 | return ((point * plane) >= 0); |
---|
| 72 | } |
---|
[982] | 73 | }; |
---|
| 74 | |
---|
| 75 | #endif |
---|