1 /* 2 * NodeSuperEllipsoid.h 3 * 4 * Copyright (C) 1999 Stephen F. White, 2004 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 "MeshMorphingNode.h" 25 #include "ProtoMacros.h" 26 #include "Proto.h" 27 #include "SFMFTypes.h" 28 29 class Mesh; 30 31 class SuperEllipsoidData { 32 public: 33 float n1; 34 float n2; 35 float border; 36 float bottomBorder; 37 float size[3]; 38 bool triangulate; 39 }; 40 41 class ProtoSuperEllipsoid : public Proto { 42 public: 43 ProtoSuperEllipsoid(Scene *scene); 44 virtual Node *create(Scene *scene); 45 getType()46 virtual int getType() const { return DUNE_SUPER_ELLIPSOID; } getNodeClass()47 virtual int getNodeClass() const 48 { return PARAMETRIC_GEOMETRY_NODE | GEOMETRY_NODE; } 49 isScriptedExternProto(void)50 virtual bool isScriptedExternProto(void) { return true; } 51 isMesh(void)52 virtual bool isMesh(void) { return true; } 53 54 FieldIndex n1; 55 FieldIndex n2; 56 FieldIndex border; 57 FieldIndex bottom; 58 FieldIndex bottomBorder; 59 FieldIndex ccw; 60 FieldIndex creaseAngle; 61 FieldIndex size; 62 FieldIndex solid; 63 FieldIndex texCoord; 64 FieldIndex top; 65 FieldIndex uTessellation; 66 FieldIndex vTessellation; 67 }; 68 69 class NodeSuperEllipsoid : public MeshMorphingNode { 70 public: 71 NodeSuperEllipsoid(Scene *scene, Proto *proto); 72 ~NodeSuperEllipsoid(); 73 getProfile(void)74 virtual int getProfile(void) const { return PROFILE_IMMERSIVE; } getX3dVersion(void)75 virtual int getX3dVersion(void) const { return -1; } copy()76 virtual Node *copy() const { return new NodeSuperEllipsoid(*this); } 77 hasNumbers4kids(void)78 virtual bool hasNumbers4kids(void) { return true; } 79 draw()80 virtual void draw() { meshDraw(); } 81 virtual void drawHandles(void); 82 virtual Vec3f getHandle(int handle, int *constraint, int *field); 83 virtual void setHandle(int handle, const Vec3f &v); 84 85 virtual void setField(int index, FieldValue *value, int cf = -1); 86 87 virtual void flip(int index); 88 virtual void swap(int fromTo); 89 90 virtual Node *toNurbs(int uTess, int vTess, int uDegree, int vDegree); 91 hasTwoSides(void)92 virtual bool hasTwoSides(void) { return true; } isDoubleSided(void)93 virtual bool isDoubleSided(void) { return !solid()->getValue(); } toggleDoubleSided(void)94 virtual void toggleDoubleSided(void) 95 { solid(new SFBool(!solid()->getValue())); } getSolidField()96 virtual int getSolidField() { return solid_Field(); } flipSide(void)97 virtual void flipSide(void) { ccw(new SFBool(!ccw()->getValue())); } 98 maySetDefault(void)99 virtual bool maySetDefault(void) { return !(TheApp->is4Kids()); } 100 avoidProtoOnPureVrml(void)101 virtual bool avoidProtoOnPureVrml(void) { return true; } 102 int writeProto(int filedes); 103 104 fieldMacros(SFFloat, n1, ProtoSuperEllipsoid) 105 fieldMacros(SFFloat, n2, ProtoSuperEllipsoid) 106 fieldMacros(SFFloat, border, ProtoSuperEllipsoid) 107 fieldMacros(SFBool, bottom, ProtoSuperEllipsoid) 108 fieldMacros(SFFloat, bottomBorder, ProtoSuperEllipsoid) 109 fieldMacros(SFBool, ccw, ProtoSuperEllipsoid) 110 fieldMacros(SFFloat, creaseAngle, ProtoSuperEllipsoid) 111 fieldMacros(SFVec3f, size, ProtoSuperEllipsoid) 112 fieldMacros(SFBool, solid, ProtoSuperEllipsoid) 113 fieldMacros(SFNode, texCoord, ProtoSuperEllipsoid) 114 fieldMacros(SFBool, top, ProtoSuperEllipsoid) 115 fieldMacros(SFInt32, uTessellation, ProtoSuperEllipsoid) 116 fieldMacros(SFInt32, vTessellation, ProtoSuperEllipsoid) 117 protected: 118 void createMesh(bool cleanDoubleVertices = true, 119 bool triangulate = true); 120 void createMesh(SuperEllipsoidData *data, bool cleanVertices); 121 float superellipse1xy(float angle1, float n2); 122 float superellipse1z(float angle1, float n2); 123 float superellipse2x(float angle2, float n1); 124 float superellipse2y(float angle2, float n1); 125 protected: 126 virtual void *initializeData(void); 127 virtual void loadDataFromInterpolators(void *data, Interpolator *inter, 128 int field, float key); 129 virtual void createMeshFromData(void* data, bool optimize); 130 virtual void finalizeData(void* data); 131 }; 132 133 134