1 /* 2 * NodeRectangle2D.h 3 * 4 * Copyright (C) 1999 Stephen F. White, 2007 J. "MUFTI" Scheurich 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 "Vec3f.h" 28 #include "SFMFTypes.h" 29 30 class ProtoRectangle2D : public Proto { 31 public: 32 ProtoRectangle2D(Scene *scene); 33 virtual Node *create(Scene *scene); 34 getType()35 virtual int getType() const { return X3D_RECTANGLE_2D; } getNodeClass()36 virtual int getNodeClass() const 37 { return PARAMETRIC_GEOMETRY_NODE | GEOMETRY_NODE; } 38 isX3dInternalProto(void)39 virtual bool isX3dInternalProto(void) { return true; } 40 isMesh(void)41 virtual bool isMesh(void) { return true; } 42 43 FieldIndex size; 44 FieldIndex solid; 45 x3domGeometryCommonFieldIndex() 46 FieldIndex ccw; 47 }; 48 49 class NodeRectangle2D : public MeshBasedNode { 50 public: 51 NodeRectangle2D(Scene *scene, Proto *proto); 52 getComponentName(void)53 virtual const char* getComponentName(void) const 54 { return "Geometry2D"; } getComponentLevel(void)55 virtual int getComponentLevel(void) const { return 1; } getX3dVersion(void)56 virtual int getX3dVersion(void) const { return 0; } copy()57 virtual Node *copy() const { return new NodeRectangle2D(*this); } 58 draw()59 virtual void draw() { meshDraw(); } 60 hasTwoSides(void)61 virtual bool hasTwoSides(void) { return true; } isDoubleSided(void)62 virtual bool isDoubleSided(void) { return !solid()->getValue(); } toggleDoubleSided(void)63 virtual void toggleDoubleSided(void) 64 { solid(new SFBool(!solid()->getValue())); } getSolidField()65 virtual int getSolidField() { return solid_Field(); } 66 countPrimitives(void)67 virtual int countPrimitives(void) {return 1;} countPolygons(void)68 virtual int countPolygons(void) { return 0; } 69 writeProto(int f)70 virtual int writeProto(int f) { return writeX3dProto(f); } 71 72 fieldMacros(SFVec2f, size, ProtoRectangle2D) 73 fieldMacros(SFBool, solid, ProtoRectangle2D) 74 x3domGeometryCommonFieldMacros(ProtoRectangle2D) 75 fieldMacros(SFBool, ccw, ProtoRectangle2D) 76 77 protected: 78 void createMesh(bool cleanDoubleVertices = true, 79 bool triangulate = true); 80 81 }; 82 83