1 /* 2 * NodeCurveAnimation.h 3 * 4 * Copyright (C) 1999 Stephen F. White, 2011 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 "ProtoMacros.h" 25 #include "Proto.h" 26 #include "NodeNurbsCurve.h" 27 #include "NodePositionInterpolator.h" 28 #include "NodeOrientationInterpolator.h" 29 30 #include "SFMFTypes.h" 31 class Interpolator; 32 33 class ProtoCurveAnimation : public ProtoNurbsCurve { 34 public: 35 ProtoCurveAnimation(Scene *scene); 36 virtual Node *create(Scene *scene); 37 getType()38 virtual int getType() const { return DUNE_CURVE_ANIMATION; } getNodeClass()39 virtual int getNodeClass() const { return CHILD_NODE; } 40 isScriptedExternProto(void)41 virtual bool isScriptedExternProto(void) { return true; } 42 43 FieldIndex rotationAxis; 44 FieldIndex enableRotation; 45 FieldIndex hover; 46 }; 47 48 class NodeCurveAnimation : public NodeNurbsCurve { 49 public: 50 NodeCurveAnimation(Scene *scene, Proto *proto); 51 ~NodeCurveAnimation(); 52 getProfile(void)53 virtual int getProfile(void) const { return PROFILE_IMMERSIVE; } 54 getComponentName(void)55 virtual const char* getComponentName(void) const { return ""; } getComponentLevel(void)56 virtual int getComponentLevel(void) const { return -1; } 57 copy()58 virtual Node *copy() const { return new NodeCurveAnimation(*this); } 59 60 void createNurbsCurve(void); 61 62 virtual void drawHandles(void); 63 64 virtual Vec3f getHandle(int handle, int *constraint, int *field); 65 virtual void setHandle(int handle, const Vec3f &v); 66 67 virtual void setField(int index, FieldValue *value, int cf = -1); 68 hasBoundingBox(void)69 virtual bool hasBoundingBox(void) { return true; } 70 virtual Vec3f getMinBoundingBox(void); 71 virtual Vec3f getMaxBoundingBox(void); 72 73 virtual void flip(int index); 74 virtual void swap(int fromTo); 75 76 Node *toNurbsCurve(void); 77 Node *copyFromNurbsCurve(Node *nurbsCurve); 78 79 void receiveEvent(int eventIn, double timestamp, 80 FieldValue *value); 81 maySetDefault(void)82 virtual bool maySetDefault(void) { return false; } 83 avoidProtoOnPureVrml(void)84 virtual bool avoidProtoOnPureVrml(void) { return true; } 85 virtual int writeProto(int filedes); 86 canConvertToPositionAndOrientationInterpolators(void)87 virtual bool canConvertToPositionAndOrientationInterpolators(void) 88 { return true; } 89 virtual void toPositionAndOrientationInterpolators(NodeList *nodes); 90 91 virtual Node *degreeElevate(int newDegree); 92 93 virtual int write(int filedes, int indent, bool avoidUse = false); 94 virtual int writeXml(int filedes, int indent, int containerField = -1, 95 bool avoidUse = false) 96 { 97 return write(filedes, indent, avoidUse); 98 } 99 100 virtual int writeC(int filedes, int languageFlag); 101 virtual int writeCDeclaration(int filedes, int languageFlag); 102 103 virtual void addToConvertedNodes(int writeFlags); 104 getPositionInterpolator()105 Node *getPositionInterpolator() 106 { return m_positionInterpolator; } getOrientationInterpolator()107 Node *getOrientationInterpolator() 108 { return m_orientationInterpolator; } 109 getFraction_Field()110 int getFraction_Field() { return m_set_fractionField; } getPosition_Field()111 FieldIndex getPosition_Field() { return m_position_changedField; } getOrientation_Field()112 FieldIndex getOrientation_Field() { return m_orientation_changedField; } 113 114 virtual void addInput(int eventIn, Node *src, int eventOut); 115 virtual void addOutput(int eventOut, Node *dst, int eventIn); 116 virtual void removeInput(int eventIn, Node *src, int eventOut); 117 virtual void removeOutput(int eventOut, Node *dst, int eventIn); 118 119 void createRoutes(Interpolator *node, bool appendToScene); 120 121 float setNewFraction(float fraction); 122 update(void)123 void update(void) { m_curveDirty = true; } 124 void reInit(void); 125 126 fieldMacros(SFVec3f, rotationAxis, ProtoCurveAnimation) 127 fieldMacros(SFBool, enableRotation, ProtoCurveAnimation) 128 fieldMacros(SFBool, hover, ProtoCurveAnimation) 129 130 protected: 131 void sendPosition(double timestamp, float fraction); 132 void sendOrientation(double timestamp, float fraction); 133 protected: 134 FieldIndex m_set_fractionField; 135 FieldIndex m_position_changedField; 136 FieldIndex m_orientation_changedField; 137 NodePositionInterpolator *m_positionInterpolator; 138 NodeOrientationInterpolator *m_orientationInterpolator; 139 bool m_curveDirty; 140 MyArray<float> m_chain; 141 }; 142 143 144