📄 face.hh
字号:
/* * Little Green BATS (2006) * * Authors: Martin Klomp (martin@ai.rug.nl) * Mart van de Sanden (vdsanden@ai.rug.nl) * Sander van Dijk (sgdijk@ai.rug.nl) * A. Bram Neijt (bneijt@gmail.com) * Matthijs Platje (mplatje@gmail.com) * * Date: September 14, 2006 * * Website: http://www.littlegreenbats.nl * * Comment: Please feel free to contact us if you have any * problems or questions about the code. * * * License: This program is free software; you can redistribute * it and/or modify it under the terms of the GNU General * Public License as published by the Free Software * Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will * be useful, but WITHOUT ANY WARRANTY; without even the * implied warranty of MERCHANTABILITY or FITNESS FOR A * PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General * Public License along with this program; if not, write * to the Free Software Foundation, Inc., 59 Temple Place - * Suite 330, Boston, MA 02111-1307, USA. * */#ifndef _BATS_FACE_HH_#define _BATS_FACE_HH_namespace bats{ class Face { int d_glMode; std::vector<Vector3D> d_vertices; std::vector<Vector3D> d_normals; std::vector<Vector3D> d_colors; Vector3D d_currentColor; void copy(Face const &other) { d_glMode = other.d_glMode; d_vertices = other.d_vertices; d_normals = other.d_normals; d_colors = other.d_colors; } void destroy() {} public: Face(int glMode, unsigned len) { d_glMode = glMode; d_vertices.resize(len); d_normals.resize(len); d_colors.resize(len); } Face() { d_glMode = 0; } ~Face() { destroy(); } Face(Face const &other) { copy(other); } Face &operator=(Face const &other) { if (this != &other) { destroy(); copy(other); } return *this; } int getGLMode() const { return d_glMode; } unsigned length() const { return d_vertices.size(); } void setVertex(unsigned index, Vector3D const &vect) { assert(index < d_vertices.size()); d_vertices[index] = vect; } void setVertex(unsigned index, double x, double y, double z) { setVertex(index,Vector3D(x,y,z)); } void setNormal(unsigned index, Vector3D const &vect) { assert(index < d_normals.size()); d_vertices[index] = vect; } void setNormal(unsigned index, double x, double y, double z) { setNormal(index,Vector3D(x,y,z)); } void setColors(double r, double g, double b) { Vector3D color(r,g,b); for (std::vector<Vector3D>::iterator i = d_colors.begin(); i != d_colors.end(); ++i) *i = color; } void setColor(unsigned index, double r, double g, double b) { assert(index < d_colors.size()); d_colors[index] = Vector3D(r,g,b); } std::vector<Vector3D> &getVertices() { return d_vertices; } Vector3D const &getVertex(unsigned index) const { assert(index < d_vertices.size()); return d_vertices[index]; } std::vector<Vector3D> &getNormals() { return d_normals; } Vector3D const &getNormal(unsigned index) const { assert(index < d_normals.size()); return d_normals[index]; } std::vector<Vector3D> &getColors() { return d_colors; } Vector3D const &getColor(unsigned index) const { assert(index < d_colors.size()); return d_colors[index]; } void begin(int glMode) { d_glMode = glMode; d_vertices.clear(); d_normals.clear(); d_colors.clear(); } void color(double r, double g, double b) { d_currentColor = Vector3D(r,g,b); } void vertex(Vector3D const &vect, Vector3D const &normal = Vector3D(0,0,0)) { d_vertices.push_back(vect); d_normals.push_back(normal); d_colors.push_back(d_currentColor); } void end() { // nothing? } };};#endif // _BATS_FACE_HH_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -