1 /* 2 * SFVec3d.h 3 * 4 * Copyright (C) 1999 Stephen F. White, 2006 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 #ifndef _SFVEC3D_H 23 #define _SFVEC3D_H 24 25 #ifndef _SFVEC3X_H 26 # include "SfVec3x.h" 27 #endif 28 #ifndef _VEC3D_H 29 # include "Vec3d.h" 30 #endif 31 #ifndef _SFSTRING_H 32 # include "SFString.h" 33 #endif 34 35 class SFVec3d : public SfVec3x<double> { 36 public: SFVec3d(const Vec3d & v)37 SFVec3d(const Vec3d &v) 38 { 39 m_value[0] = v.x; 40 m_value[1] = v.y; 41 m_value[2] = v.z; 42 } SFVec3d(double x,double y,double z)43 SFVec3d(double x, double y, double z) 44 { 45 m_value[0] = x; 46 m_value[1] = y; 47 m_value[2] = z; 48 } SFVec3d(const double * value)49 SFVec3d(const double* value) 50 { 51 m_value[0] = value[0]; 52 m_value[1] = value[1]; 53 m_value[2] = value[2]; 54 } SFVec3d(const float * value)55 SFVec3d(const float* value) 56 { 57 m_value[0] = value[0]; 58 m_value[1] = value[1]; 59 m_value[2] = value[2]; 60 } SFVec3d(const char * value)61 SFVec3d(const char* value) 62 { 63 setValue(value); 64 } SFVec3d(void)65 SFVec3d(void) // silly default 66 { 67 m_value[0] = m_value[1] = m_value[2] = 0.0; 68 } 69 SFVec3d(SFString *value); 70 getType()71 virtual int getType() const { return SFVEC3D; } getTypeName()72 virtual const char *getTypeName() const { return "SFVec3d"; } getStride()73 virtual int getStride() const { return 3; } 74 virtual MyString getString(int index, int stride) const; copy()75 virtual FieldValue *copy() { return new SFVec3d(*this); } 76 virtual bool equals(const FieldValue *value) const; 77 virtual void clamp(const FieldValue *min, const FieldValue *max); supportAnimation(bool x3d)78 virtual bool supportAnimation(bool x3d) const { return false; } supportInteraction(void)79 virtual bool supportInteraction(void) const { return false; } 80 MyString getEcmaScriptComment(MyString name, int flags) const; 81 82 virtual int writeData(int filedes, int i) const; 83 84 virtual int writeC(int filedes, const char* variableName, 85 int languageFlag) const; getTypeC(int languageFlag)86 virtual const char *getTypeC(int languageFlag) const { return "double"; } isArrayInC(void)87 virtual bool isArrayInC(void) const { return true; } 88 89 virtual bool readLine(int index, char *line); setValue(int index,double value)90 virtual void setValue(int index, double value) 91 { 92 assert(index >= 0 && index < 3); 93 m_value[index] = value; 94 } setValue(const char * value)95 void setValue(const char *value) 96 { 97 sscanf(value, "%lf %lf %lf", 98 &m_value[0], &m_value[1], &m_value[2]); 99 } isX3DType()100 virtual bool isX3DType() { return true; } 101 getRandom(Scene * scene,int nodeType)102 FieldValue *getRandom(Scene *scene, int nodeType) 103 { return new SFVec3d(FLOAT_RAND(), FLOAT_RAND(), 104 FLOAT_RAND()); } 105 }; 106 107 #endif // _SFVEC3D_H 108