remove config.h references, was added for automake build system rev around 124-126...
[blender-staging.git] / source / gameengine / Expressions / VectorValue.cpp
1 // VectorValue.cpp: implementation of the CVectorValue class.
2 /*
3  * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
4  *
5  * Permission to use, copy, modify, distribute and sell this software
6  * and its documentation for any purpose is hereby granted without fee,
7  * provided that the above copyright notice appear in all copies and
8  * that both that copyright notice and this permission notice appear
9  * in supporting documentation.  Erwin Coumans makes no
10  * representations about the suitability of this software for any
11  * purpose.  It is provided "as is" without express or implied warranty.
12  *
13  */
14
15 #ifdef WIN32
16 #pragma warning (disable:4786)
17 #endif
18
19 #include "Value.h"
20 #include "VectorValue.h"
21 #include "ErrorValue.h"
22 //#include "MatrixValue.h"
23 #include "VoidValue.h"
24 #include "StringValue.h"
25 //#include "FactoryManager.h"
26
27
28
29 //////////////////////////////////////////////////////////////////////
30 // Construction/Destruction
31 //////////////////////////////////////////////////////////////////////
32
33 CVectorValue::CVectorValue(float x,float y,float z, AllocationTYPE alloctype)
34 {
35         SetCustomFlag1(false);//FancyOutput=false;
36         
37         if (alloctype == STACKVALUE)
38         {
39                 CValue::DisableRefCount();
40         };
41         
42         m_vec[KX_X] = m_transformedvec[KX_X] = x;
43         m_vec[KX_Y] = m_transformedvec[KX_Y] = y;
44         m_vec[KX_Z] = m_transformedvec[KX_Z] = z;
45         
46 }
47 CVectorValue::CVectorValue(double vec[],const char *name,AllocationTYPE alloctype) {
48         
49         SetCustomFlag1(false);//FancyOutput=false;
50         
51         m_vec[KX_X] = m_transformedvec[KX_X] = vec[KX_X];
52         m_vec[KX_Y] = m_transformedvec[KX_Y] = vec[KX_Y];
53         m_vec[KX_Z] = m_transformedvec[KX_Z] = vec[KX_Z];
54                 
55         if (alloctype == STACKVALUE)
56         {
57                 CValue::DisableRefCount();
58                 
59         }
60         
61         SetName(name);
62 }
63
64 CVectorValue::CVectorValue(double vec[],AllocationTYPE alloctype) {
65         
66         SetCustomFlag1(false);//FancyOutput=false;
67         
68         m_vec[KX_X] = m_transformedvec[KX_X] = vec[KX_X];
69         m_vec[KX_Y] = m_transformedvec[KX_Y] = vec[KX_Y];
70         m_vec[KX_Z] = m_transformedvec[KX_Z] = vec[KX_Z];
71         
72         if (alloctype == STACKVALUE)
73         {
74                 CValue::DisableRefCount();
75                 
76         }
77         
78         
79 }
80 CVectorValue::~CVectorValue()
81 {
82
83 }
84
85 CValue* CVectorValue::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val)
86 /*
87 pre: the type of val is dtype
88 ret: a new object containing the result of applying operator op to val and
89 this object
90 */
91 {
92         CValue *ret = NULL;
93         
94         switch(op)
95         { 
96         case VALUE_ADD_OPERATOR: 
97                 {
98                         switch (dtype)
99                         {
100                         case VALUE_EMPTY_TYPE:
101                         case VALUE_VECTOR_TYPE: 
102                                 {
103                                         ret = new CVectorValue(
104                                                 val->GetVector3()[KX_X] + GetVector3()[KX_X],
105                                                 val->GetVector3()[KX_Y] + GetVector3()[KX_Y],
106                                                 val->GetVector3()[KX_Z] + GetVector3()[KX_Z],
107                                                 CValue::HEAPVALUE);
108                                         ret->SetName(GetName());
109                                         break;
110                                 }
111                         
112                         default: 
113                                 ret = new CErrorValue(val->GetText() + op2str(op) +     GetText());
114                         }
115                         break;
116                 }
117         case VALUE_MUL_OPERATOR:
118                 {
119                         switch (dtype)
120                         {
121                                 
122                         case VALUE_EMPTY_TYPE:
123                         case VALUE_VECTOR_TYPE: 
124                                 {
125                                         //MT_Vector3 supports 'scaling' by another vector, instead of using general transform, Gino?
126                                         //ret = new CVectorValue(val->GetVector3().Scaled(GetVector3()),GetName());
127                                         break;
128                                 }
129                         case VALUE_FLOAT_TYPE: 
130                                 {
131                                         ret = new CVectorValue(
132                                                 val->GetVector3()[KX_X] * GetVector3()[KX_X],
133                                                 val->GetVector3()[KX_Y] * GetVector3()[KX_Y],
134                                                 val->GetVector3()[KX_Z] * GetVector3()[KX_Z],
135                                                 CValue::HEAPVALUE);
136                                         ret->SetName(GetName());
137                                         break;
138                                 }
139                         
140                         default: 
141                                 ret = new CErrorValue(val->GetText() + op2str(op) +     GetText());
142                         }
143                         break;
144
145                 }
146         
147         default:
148                 ret = new CErrorValue(val->GetText() + op2str(op) +     GetText());
149         }
150
151         
152         return ret;
153 }
154
155 double CVectorValue::GetNumber()
156 {
157         return m_vec[KX_X];
158 }
159
160
161 double* CVectorValue::GetVector3(bool bGetTransformedVec)
162 {
163         if (bGetTransformedVec)
164                 return m_transformedvec;
165         // else 
166         return m_vec;
167 }
168
169
170
171
172
173 void CVectorValue::SetVector(double newvec[])
174 {
175         m_vec[KX_X] = m_transformedvec[KX_X] = newvec[KX_X];
176         m_vec[KX_Y] = m_transformedvec[KX_Y] = newvec[KX_Y];
177         m_vec[KX_Z] = m_transformedvec[KX_Z] = newvec[KX_Z];
178         
179         SetModified(true);
180 }
181
182
183 void CVectorValue::SetValue(CValue *newval)
184 {
185         
186         double* newvec = ((CVectorValue*)newval)->GetVector3();
187         m_vec[KX_X] = m_transformedvec[KX_X] = newvec[KX_X];
188         m_vec[KX_Y] = m_transformedvec[KX_Y] = newvec[KX_Y];
189         m_vec[KX_Z] = m_transformedvec[KX_Z] = newvec[KX_Z];
190         
191         SetModified(true);
192 }
193
194 static const STR_String gstrVectorStr=STR_String();
195 const STR_String & CVectorValue::GetText()
196 {
197         assertd(false);
198         return gstrVectorStr;
199 }
200
201 CValue* CVectorValue::GetReplica() { 
202         CVectorValue* replica = new CVectorValue(*this);
203         replica->ProcessReplica();
204         return replica;
205 };
206
207 /*void CVectorValue::Transform(rcMatrix4x4 mat)
208 {
209         m_transformedvec = mat*m_vec;
210 }
211 */
212
213