Blender V2.61 - r43446

VectorValue.cpp

Go to the documentation of this file.
00001 
00004 // VectorValue.cpp: implementation of the CVectorValue class.
00005 /*
00006  * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
00007  *
00008  * Permission to use, copy, modify, distribute and sell this software
00009  * and its documentation for any purpose is hereby granted without fee,
00010  * provided that the above copyright notice appear in all copies and
00011  * that both that copyright notice and this permission notice appear
00012  * in supporting documentation.  Erwin Coumans makes no
00013  * representations about the suitability of this software for any
00014  * purpose.  It is provided "as is" without express or implied warranty.
00015  *
00016  */
00017 
00018 #if defined(WIN32) && !defined(FREE_WINDOWS)
00019 #pragma warning (disable:4786)
00020 #endif
00021 
00022 #include "Value.h"
00023 #include "VectorValue.h"
00024 #include "ErrorValue.h"
00025 //#include "MatrixValue.h"
00026 #include "VoidValue.h"
00027 #include "StringValue.h"
00028 //#include "FactoryManager.h"
00029 
00030 
00031 
00033 // Construction/Destruction
00035 
00036 CVectorValue::CVectorValue(float x,float y,float z, AllocationTYPE alloctype)
00037 {
00038     SetCustomFlag1(false);//FancyOutput=false;
00039     
00040     if (alloctype == STACKVALUE)
00041     {
00042         CValue::DisableRefCount();
00043     };
00044     
00045     m_vec[KX_X] = m_transformedvec[KX_X] = x;
00046     m_vec[KX_Y] = m_transformedvec[KX_Y] = y;
00047     m_vec[KX_Z] = m_transformedvec[KX_Z] = z;
00048     
00049 }
00050 CVectorValue::CVectorValue(double vec[],const char *name,AllocationTYPE alloctype) {
00051     
00052     SetCustomFlag1(false);//FancyOutput=false;
00053     
00054     m_vec[KX_X] = m_transformedvec[KX_X] = vec[KX_X];
00055     m_vec[KX_Y] = m_transformedvec[KX_Y] = vec[KX_Y];
00056     m_vec[KX_Z] = m_transformedvec[KX_Z] = vec[KX_Z];
00057         
00058     if (alloctype == STACKVALUE)
00059     {
00060         CValue::DisableRefCount();
00061         
00062     }
00063     
00064     SetName(name);
00065 }
00066 
00067 CVectorValue::CVectorValue(double vec[],AllocationTYPE alloctype) {
00068     
00069     SetCustomFlag1(false);//FancyOutput=false;
00070     
00071     m_vec[KX_X] = m_transformedvec[KX_X] = vec[KX_X];
00072     m_vec[KX_Y] = m_transformedvec[KX_Y] = vec[KX_Y];
00073     m_vec[KX_Z] = m_transformedvec[KX_Z] = vec[KX_Z];
00074     
00075     if (alloctype == STACKVALUE)
00076     {
00077         CValue::DisableRefCount();
00078         
00079     }
00080     
00081     
00082 }
00083 CVectorValue::~CVectorValue()
00084 {
00085 
00086 }
00087 
00088 CValue* CVectorValue::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val)
00089 /*
00090 pre: the type of val is dtype
00091 ret: a new object containing the result of applying operator op to val and
00092 this object
00093 */
00094 {
00095     CValue *ret = NULL;
00096     
00097     switch(op)
00098     { 
00099     case VALUE_ADD_OPERATOR: 
00100         {
00101             switch (dtype)
00102             {
00103             case VALUE_EMPTY_TYPE:
00104             case VALUE_VECTOR_TYPE: 
00105                 {
00106                     ret = new CVectorValue(
00107                         val->GetVector3()[KX_X] + GetVector3()[KX_X],
00108                         val->GetVector3()[KX_Y] + GetVector3()[KX_Y],
00109                         val->GetVector3()[KX_Z] + GetVector3()[KX_Z],
00110                         CValue::HEAPVALUE);
00111                     ret->SetName(GetName());
00112                     break;
00113                 }
00114             
00115             default: 
00116                 ret = new CErrorValue(val->GetText() + op2str(op) + GetText());
00117             }
00118             break;
00119         }
00120     case VALUE_MUL_OPERATOR:
00121         {
00122             switch (dtype)
00123             {
00124                 
00125             case VALUE_EMPTY_TYPE:
00126             case VALUE_VECTOR_TYPE: 
00127                 {
00128                     //MT_Vector3 supports 'scaling' by another vector, instead of using general transform, Gino?
00129                     //ret = new CVectorValue(val->GetVector3().Scaled(GetVector3()),GetName());
00130                     break;
00131                 }
00132             case VALUE_FLOAT_TYPE: 
00133                 {
00134                     ret = new CVectorValue(
00135                         val->GetVector3()[KX_X] * GetVector3()[KX_X],
00136                         val->GetVector3()[KX_Y] * GetVector3()[KX_Y],
00137                         val->GetVector3()[KX_Z] * GetVector3()[KX_Z],
00138                         CValue::HEAPVALUE);
00139                     ret->SetName(GetName());
00140                     break;
00141                 }
00142             
00143             default: 
00144                 ret = new CErrorValue(val->GetText() + op2str(op) + GetText());
00145             }
00146             break;
00147 
00148         }
00149     
00150     default:
00151         ret = new CErrorValue(val->GetText() + op2str(op) + GetText());
00152     }
00153 
00154     
00155     return ret;
00156 }
00157 
00158 double CVectorValue::GetNumber()
00159 {
00160     return m_vec[KX_X];
00161 }
00162 
00163 
00164 double* CVectorValue::GetVector3(bool bGetTransformedVec)
00165 {
00166     if (bGetTransformedVec)
00167         return m_transformedvec;
00168     // else 
00169     return m_vec;
00170 }
00171 
00172 
00173 
00174 
00175 
00176 void CVectorValue::SetVector(double newvec[])
00177 {
00178     m_vec[KX_X] = m_transformedvec[KX_X] = newvec[KX_X];
00179     m_vec[KX_Y] = m_transformedvec[KX_Y] = newvec[KX_Y];
00180     m_vec[KX_Z] = m_transformedvec[KX_Z] = newvec[KX_Z];
00181     
00182     SetModified(true);
00183 }
00184 
00185 
00186 void CVectorValue::SetValue(CValue *newval)
00187 {
00188     
00189     double* newvec = ((CVectorValue*)newval)->GetVector3();
00190     m_vec[KX_X] = m_transformedvec[KX_X] = newvec[KX_X];
00191     m_vec[KX_Y] = m_transformedvec[KX_Y] = newvec[KX_Y];
00192     m_vec[KX_Z] = m_transformedvec[KX_Z] = newvec[KX_Z];
00193     
00194     SetModified(true);
00195 }
00196 
00197 static const STR_String gstrVectorStr=STR_String();
00198 const STR_String & CVectorValue::GetText()
00199 {
00200     assertd(false);
00201     return gstrVectorStr;
00202 }
00203 
00204 CValue* CVectorValue::GetReplica() { 
00205     CVectorValue* replica = new CVectorValue(*this);
00206     replica->ProcessReplica();
00207     return replica;
00208 };
00209 
00210 /*void CVectorValue::Transform(rcMatrix4x4 mat)
00211 {
00212     m_transformedvec = mat*m_vec;
00213 }
00214 */
00215 
00216