1 /*
2  * NodeElevationGrid.h
3  *
4  * Copyright (C) 1999 Stephen F. White
5  *
6  * This program 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 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program 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 this program (see the file "COPYING" for details); if
18  * not, write to the Free Software Foundation, Inc., 675 Mass Ave,
19  * Cambridge, MA 02139, USA.
20  */
21 
22 #pragma once
23 
24 #include "MeshBasedNode.h"
25 #include "ProtoMacros.h"
26 #include "Proto.h"
27 #include "SFMFTypes.h"
28 
29 class ProtoElevationGrid : public GeometryProto {
30 public:
31                     ProtoElevationGrid(Scene *scene);
32     virtual Node   *create(Scene *scene);
33 
getType()34     virtual int     getType() const { return VRML_ELEVATION_GRID; }
getNodeClass()35     virtual int     getNodeClass() const { return GEOMETRY_NODE; }
36 
isMesh(void)37     virtual bool    isMesh(void) { return true; }
38 
39     FieldIndex attrib;
40     FieldIndex color;
41     FieldIndex fogCoord;
42     FieldIndex normal;
43     FieldIndex texCoord;
44     FieldIndex ccw;
45     FieldIndex colorPerVertex;
46     FieldIndex creaseAngle;
47     FieldIndex height;
48     FieldIndex normalPerVertex;
49     FieldIndex solid;
50     FieldIndex xDimension;
51     FieldIndex xSpacing;
52     FieldIndex zDimension;
53     FieldIndex zSpacing;
54     x3domGeometryCommonFieldIndex()
55 };
56 
57 class MFVec2f;
58 
59 class NodeElevationGrid : public MeshBasedNode {
60 public:
61                     NodeElevationGrid(Scene *scene, Proto *proto);
62 
63 protected:
64     virtual        ~NodeElevationGrid();
65 
66 public:
67     virtual int     getProfile(void) const;
getX3dVersion(void)68     virtual int     getX3dVersion(void) const { return 0; }
copy()69     virtual Node   *copy() const { return new NodeElevationGrid(*this); }
70 
71     virtual void    setField(int index, FieldValue *value, int cf = -1);
72 
73     virtual Vec3f   getHandle(int handle, int *constraint, int *field);
74     virtual void    setHandle(int handle, const Vec3f &v);
75 
draw()76     virtual void    draw() { meshDraw(); }
77     virtual void    drawHandles(void);
78 
79     virtual bool    validHandle(int handle);
80     virtual bool    checkHandle(int handle);
81     virtual int     getMaxHandle(void);
82 
getNormalField()83     virtual int     getNormalField() { return normal_Field(); }
getTexCoordField()84     virtual int     getTexCoordField() { return texCoord_Field(); }
85 
86     virtual void    setNormalFromMesh(Node *nnormal);
87     virtual void    setTexCoordFromMesh(Node *ntexCoord);
88 
hasTwoSides(void)89     virtual bool    hasTwoSides(void) { return true; }
isDoubleSided(void)90     virtual bool    isDoubleSided(void) { return !solid()->getValue(); }
toggleDoubleSided(void)91     virtual void    toggleDoubleSided(void)
92                        { solid(new SFBool(!solid()->getValue())); }
getSolidField()93     virtual int     getSolidField() { return solid_Field(); }
flipSide(void)94     virtual void    flipSide(void) { ccw(new SFBool(!ccw()->getValue())); }
95 
getColorNode()96     virtual NodeColor *getColorNode()
97                     { return (NodeColor *)color()->getValue(); }
getColorRGBANode()98     virtual NodeColorRGBA *getColorRGBANode()
99                     { return (NodeColorRGBA *)color()->getValue(); }
100 
shouldConvertToIndexedFaceSet(void)101     virtual bool    shouldConvertToIndexedFaceSet(void) { return false; }
102 
103     fieldMacros(MFNode,  attrib,          ProtoElevationGrid)
104     fieldMacros(SFNode,  color,           ProtoElevationGrid)
105     fieldMacros(SFNode,  fogCoord,        ProtoElevationGrid)
106     fieldMacros(SFNode,  normal,          ProtoElevationGrid)
107     fieldMacros(SFNode,  texCoord,        ProtoElevationGrid)
108     fieldMacros(MFFloat, height,          ProtoElevationGrid)
109     fieldMacros(SFBool,  ccw,             ProtoElevationGrid)
110     fieldMacros(SFBool,  colorPerVertex,  ProtoElevationGrid)
111     fieldMacros(SFFloat, creaseAngle,     ProtoElevationGrid)
112     fieldMacros(SFBool,  normalPerVertex, ProtoElevationGrid)
113     fieldMacros(SFBool,  solid,           ProtoElevationGrid)
114     fieldMacros(SFInt32, xDimension,      ProtoElevationGrid)
115     fieldMacros(SFFloat, xSpacing,        ProtoElevationGrid)
116     fieldMacros(SFInt32, zDimension,      ProtoElevationGrid)
117     fieldMacros(SFFloat, zSpacing,        ProtoElevationGrid)
118     x3domGeometryCommonFieldMacros(ProtoElevationGrid)
119 
120 protected:
121     void            createMesh(bool cleanDoubleVertices = true,
122                                bool triangulate = true);
123     MFVec2f        *accountTexCoord(void);
124 
125 };
126 
127