1 /**************************************************************************/
2 /*  Copyright 2009 Tim Day                                                */
3 /*                                                                        */
4 /*  This file is part of Fracplanet                                       */
5 /*                                                                        */
6 /*  Fracplanet is free software: you can redistribute it and/or modify    */
7 /*  it under the terms of the GNU General Public License as published by  */
8 /*  the Free Software Foundation, either version 3 of the License, or     */
9 /*  (at your option) any later version.                                   */
10 /*                                                                        */
11 /*  Fracplanet is distributed in the hope that it will be useful,         */
12 /*  but WITHOUT ANY WARRANTY; without even the implied warranty of        */
13 /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         */
14 /*  GNU General Public License for more details.                          */
15 /*                                                                        */
16 /*  You should have received a copy of the GNU General Public License     */
17 /*  along with Fracplanet.  If not, see <http://www.gnu.org/licenses/>.   */
18 /**************************************************************************/
19 
20 /*! \file
21   \brief Interface for class Vertex.
22 */
23 
24 #ifndef _vertex_h_
25 #define _vertex_h_
26 
27 #include "common.h"
28 #include "rgb.h"
29 #include "xyz.h"
30 
31 //! Class to store vertex state information
32 /*! There is no direct access to members.
33   Should probably be a protected member class of TriangleMesh.
34   sizeof(Vertex) should ideally be 3*4+3*4+2*4=32
35  */
36 class Vertex
37 {
38  public:
39 
40   //! Constructor.  NB Almost no default values set.
Vertex()41   Vertex()
42     {}
43 
44   //! Copy constructor.
Vertex(const Vertex & v)45   Vertex(const Vertex& v)
46     :_position(v._position)
47     ,_normal(v._normal)
48     {
49       _colour[0]=v._colour[0];
50       _colour[1]=v._colour[1];
51     }
52 
53   //! Construct from position only.
Vertex(const XYZ & p)54   explicit Vertex(const XYZ& p)
55     :_position(p)
56     ,_normal(0.0,0.0,0.0)
57     {
58       _colour[0]=ByteRGBA(0,0,0,255);
59       _colour[1]=ByteRGBA(0,0,0,255);
60     }
61 
62   //! Accessor.
position()63   const XYZ& position() const
64     {
65       return _position;
66     }
67 
68   //! Accessor.
normal()69   const XYZ& normal() const
70     {
71       return _normal;
72     }
73 
74   //! Accessor.
colour(uint c)75   const ByteRGBA& colour(uint c) const
76     {
77       assert(c<2);
78       return _colour[c];
79     }
80 
81   //! Accessor.
position(const XYZ & p)82   void position(const XYZ& p)
83     {
84       _position=p;
85     }
86 
87   //! Accessor.
normal(const XYZ & n)88   void normal(const XYZ& n)
89     {
90       _normal=n;
91     }
92 
93   //! Accessor.
colour(uint c,const ByteRGBA & col)94   void colour(uint c,const ByteRGBA& col)
95     {
96       assert(c<2);
97       _colour[c]=col;
98     }
99 
100   //! Accessor.
colour(uint c,const FloatRGBA & col)101   void colour(uint c,const FloatRGBA& col)
102     {
103       assert(c<2);
104       _colour[c]=ByteRGBA(col);
105     }
106 
107  private:
108 
109   //! Position of vertex.
110   XYZ _position;
111 
112   //! Normal at vertex (for smooth shading).
113   XYZ _normal;
114 
115   //! Colours at vertex (could be a different colour in different triangles).
116   /*! By convention, in triangle meshes with emissive in use, we overload the alpha
117     channel to indicate emissive (zero indicates emissive) shading is required.
118     Actual alpha or emissive are therefore mutually exclusive (anticipate alpha for clouds, emissive for ground).
119    */
120   ByteRGBA _colour[2];
121 };
122 
123 #endif
124