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