1 /*
2  * SFVec4f.h
3  *
4  * Copyright (C) 1999 Stephen F. White, 2009 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 _SFVEC4F_H
23 #define _SFVEC4F_H
24 
25 #ifndef _VEC4F_H
26 # include "Vec4f.h"
27 #endif
28 #include "FieldValue.h"
29 
30 class SFVec4f : public FieldValue {
31 public:
SFVec4f(const Vec4f & v)32                         SFVec4f(const Vec4f &v)
33                           {
34                           m_value[0] = v.x;
35                           m_value[1] = v.y;
36                           m_value[2] = v.z;
37                           m_value[3] = v.w;
38                           }
SFVec4f(float x,float y,float z,float w)39                         SFVec4f(float x, float y, float z, float w)
40                            {
41                            m_value[0] = x;
42                            m_value[1] = y;
43                            m_value[2] = z;
44                            m_value[3] = w;
45                            }
SFVec4f(const float * value)46                         SFVec4f(const float* value)
47                            {
48                            m_value[0] = value[0];
49                            m_value[1] = value[1];
50                            m_value[2] = value[2];
51                            m_value[3] = value[3];
52                            }
SFVec4f(void)53                         SFVec4f(void)  // silly default
54                            {
55                            m_value[0] = m_value[1] = m_value[2] = m_value[3] = 0.0;
56                            }
57 
getType()58     virtual int         getType() const { return SFVEC4F; }
getTypeName()59     virtual const char *getTypeName() const { return "SFVec4f"; }
getStride()60     virtual int         getStride() const { return 4; }
61     virtual MyString    getString(int index, int stride) const;
copy()62     virtual FieldValue *copy() { return new SFVec4f(*this); }
63     virtual bool        equals(const FieldValue *value) const;
64     virtual void        clamp(const FieldValue *min, const FieldValue *max);
supportAnimation(bool x3d)65     virtual bool        supportAnimation(bool x3d) const { return true; }
supportInteraction(void)66     virtual bool        supportInteraction(void) const { return true; }
67     MyString            getEcmaScriptComment(MyString name, int flags) const;
68 
69     virtual int         writeData(int filedes, int i) const;
70 
71     virtual int         writeC(int filedes, const char* variableName,
72                                int languageFlag) const;
getTypeC(int languageFlag)73     virtual const char *getTypeC(int languageFlag) const { return "float"; }
isArrayInC(void)74     virtual bool        isArrayInC(void) const { return true; }
75 
76     virtual int         writeAc3d(int filedes, int indent) const;
77 
78     virtual bool        readLine(int index, char *line);
79 
getNumbersPerType(void)80     virtual int         getNumbersPerType(void) const { return 4; }
needCheckFloat(void)81     virtual bool        needCheckFloat(void) const { return true; }
82 
getValue()83     const float        *getValue() const { return m_value; }
getValue(int pos)84     float               getValue(int pos) const { return m_value[pos]; }
setValue(int index,float value)85     void                setValue(int index, float value)
86                            {
87                            assert(index >= 0 && index < 4);
88                            m_value[index] = value;
89                            }
setValue(float v1,float v2,float v3,float v4)90     void                setValue(float v1, float v2, float v3, float v4)
91                            {
92                            m_value[0] = v1;
93                            m_value[1] = v2;
94                            m_value[2] = v3;
95                            m_value[3] = v4;
96                            }
97 
flip(int index)98     void                flip(int index) { m_value[index] *= -1.0; }
swap(int fromTo)99     void                swap(int fromTo)
100                            {
101                            switch(fromTo) {
102                              case SWAP_XY:
103                                ::myswap(m_value[0], m_value[1]);
104                                break;
105                             case SWAP_XZ:
106                                ::myswap(m_value[0], m_value[2]);
107                                break;
108                             case SWAP_YZ:
109                                ::myswap(m_value[1], m_value[2]);
110                                break;
111                            }
112                            }
113 
getRandom(Scene * scene,int nodeType)114     FieldValue         *getRandom(Scene *scene, int nodeType)
115                            { return new SFVec4f(FLOAT_RAND(), FLOAT_RAND(),
116                                                 FLOAT_RAND(), FLOAT_RAND()); }
117 protected:
118     float               m_value[4];
119 };
120 
121 #endif // _SFVEC4F_H
122