Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

KX_IpoConvert.cpp

Go to the documentation of this file.
00001 #include "BL_BlenderOrientation.h"
00002 #include "KX_GameObject.h"
00003 #include "KX_IpoConvert.h"
00004 #include "BL_BlenderIPO.h"
00005 #include "KX_IInterpolator.h"
00006 #include "KX_ScalarInterpolator.h"
00007 #include "blender.h"
00008 #include "ipo.h"
00009 #include "KX_IPO_SGController.h"
00010 #include "SG_Node.h"
00011 
00012 extern BL_IpoMap g_ipoMap;
00013 
00014 void BL_ConvertIpos(struct Object* blenderobject,KX_GameObject* gameobj)

00015 {
00016 
00017         if (blenderobject->ipo) {
00018 
00019                 KX_IpoSGController* ipocontr = new KX_IpoSGController();
00020                 gameobj->GetSGNode()->AddSGController(ipocontr);
00021                 ipocontr->SetObject(gameobj->GetSGNode());
00022                 
00023                 
00024                 ipocontr->GetIPOTransform().SetPosition(BL_GetBlenderPosition(blenderobject));
00025                 ipocontr->GetIPOTransform().SetEulerAngles(BL_GetBlenderRotation(blenderobject));
00026                 ipocontr->GetIPOTransform().SetScaling(BL_GetBlenderScaling(blenderobject));
00027 
00028                 BL_InterpolatorList *ipoList;
00029 
00030                 // Get the ipoList from the global map if it already
00031                 // exists. If not, then create one and add it to the
00032                 // global map. BL_ClearConvert gets rid of it.
00033                 
00034                 BL_IpoMap::iterator i = g_ipoMap.find(blenderobject->ipo);
00035                 
00036                 if (i == g_ipoMap.end()) {
00037                         ipoList = new BL_InterpolatorList(blenderobject->ipo);
00038                         g_ipoMap[blenderobject->ipo] = ipoList;
00039                 }
00040                 else {
00041                         ipoList = (*i).second;
00042                 }
00043                 // For each active channel in the ipoList add an
00044                 // interpolator to the game object.
00045                 
00046                 KX_IScalarInterpolator *ipo;
00047                 
00048                 ipo = ipoList->GetScalarInterpolator(OB_LOC_X);
00049                 if (ipo) {
00050                         KX_IInterpolator *interpolator =
00051                                 new KX_ScalarInterpolator(
00052                                         &(ipocontr->GetIPOTransform().GetPosition()[0]),
00053                                         ipo);
00054                         ipocontr->AddInterpolator(interpolator);
00055                         ipocontr->SetModifyPosition(true);
00056         
00057                 }
00058                 
00059                 ipo = ipoList->GetScalarInterpolator(OB_LOC_Y);
00060                 if (ipo) {
00061                         KX_IInterpolator *interpolator =
00062                                 new KX_ScalarInterpolator(
00063                                         &(ipocontr->GetIPOTransform().GetPosition()[1]),
00064                                         ipo);
00065                         ipocontr->AddInterpolator(interpolator);
00066                         ipocontr->SetModifyPosition(true);
00067                 }
00068                 
00069                 ipo = ipoList->GetScalarInterpolator(OB_LOC_Z);
00070                 if (ipo) {
00071                         KX_IInterpolator *interpolator =
00072                                 new KX_ScalarInterpolator(
00073                                         &(ipocontr->GetIPOTransform().GetPosition()[2]),
00074                                         ipo);
00075                         ipocontr->AddInterpolator(interpolator);
00076                         ipocontr->SetModifyPosition(true);
00077                 }
00078                 
00079                 // Master the art of cut & paste programming...
00080                 
00081                 ipo = ipoList->GetScalarInterpolator(OB_DLOC_X);
00082                 if (ipo) {
00083                         KX_IInterpolator *interpolator =
00084                                 new KX_ScalarInterpolator(
00085                                         &(ipocontr->GetIPOTransform().GetDeltaPosition()[0]),
00086                                         ipo);
00087                         ipocontr->AddInterpolator(interpolator);
00088                         ipocontr->SetModifyPosition(true);
00089                 }
00090                 
00091                 ipo = ipoList->GetScalarInterpolator(OB_DLOC_Y);
00092                 if (ipo) {
00093                         KX_IInterpolator *interpolator =
00094                                 new KX_ScalarInterpolator(
00095                                         &(ipocontr->GetIPOTransform().GetDeltaPosition()[1]),
00096                                         ipo);
00097                         ipocontr->AddInterpolator(interpolator);
00098                         ipocontr->SetModifyPosition(true);
00099                 }
00100                 
00101                 ipo = ipoList->GetScalarInterpolator(OB_DLOC_Z);
00102                 if (ipo) {
00103                         KX_IInterpolator *interpolator =
00104                                 new KX_ScalarInterpolator(
00105                                         &(ipocontr->GetIPOTransform().GetDeltaPosition()[2]),
00106                                         ipo);
00107                         ipocontr->AddInterpolator(interpolator);
00108                         ipocontr->SetModifyPosition(true);
00109                 }
00110                 
00111                 // Explore the finesse of reuse and slight modification
00112                 
00113                 ipo = ipoList->GetScalarInterpolator(OB_ROT_X);
00114                 if (ipo) {
00115                         KX_IInterpolator *interpolator =
00116                                 new KX_ScalarInterpolator(
00117                                         &(ipocontr->GetIPOTransform().GetEulerAngles()[0]),
00118                                         ipo);
00119                         ipocontr->AddInterpolator(interpolator);
00120                         ipocontr->SetModifyOrientation(true);
00121                 }
00122                 ipo = ipoList->GetScalarInterpolator(OB_ROT_Y);
00123                 if (ipo) {
00124                         KX_IInterpolator *interpolator =
00125                                 new KX_ScalarInterpolator(
00126                                         &(ipocontr->GetIPOTransform().GetEulerAngles()[1]),
00127                                         ipo);
00128                         ipocontr->AddInterpolator(interpolator);
00129                         ipocontr->SetModifyOrientation(true);
00130                 }
00131                 ipo = ipoList->GetScalarInterpolator(OB_ROT_Z);
00132                 if (ipo) {
00133                         KX_IInterpolator *interpolator =
00134                                 new KX_ScalarInterpolator(
00135                                         &(ipocontr->GetIPOTransform().GetEulerAngles()[2]),
00136                                         ipo);
00137                         ipocontr->AddInterpolator(interpolator);
00138                         ipocontr->SetModifyOrientation(true);
00139                 }
00140 
00141                 // Hmmm, the need for a macro comes to mind... 
00142                 
00143                 ipo = ipoList->GetScalarInterpolator(OB_DROT_X);
00144                 if (ipo) {
00145                         KX_IInterpolator *interpolator =
00146                                 new KX_ScalarInterpolator(
00147                                         &(ipocontr->GetIPOTransform().GetDeltaEulerAngles()[0]),
00148                                         ipo);
00149                         ipocontr->AddInterpolator(interpolator);
00150                         ipocontr->SetModifyOrientation(true);
00151                 }
00152                 ipo = ipoList->GetScalarInterpolator(OB_DROT_Y);
00153                 if (ipo) {
00154                         KX_IInterpolator *interpolator =
00155                                 new KX_ScalarInterpolator(
00156                                         &(ipocontr->GetIPOTransform().GetDeltaEulerAngles()[1]),
00157                                         ipo);
00158                         ipocontr->AddInterpolator(interpolator);
00159                         ipocontr->SetModifyOrientation(true);
00160                 }
00161                 ipo = ipoList->GetScalarInterpolator(OB_DROT_Z);
00162                 if (ipo) {
00163                         KX_IInterpolator *interpolator =
00164                                 new KX_ScalarInterpolator(
00165                                         &(ipocontr->GetIPOTransform().GetDeltaEulerAngles()[2]),
00166                                         ipo);
00167                         ipocontr->AddInterpolator(interpolator);
00168                         ipocontr->SetModifyOrientation(true);
00169                 }
00170 
00171                 // Hang on, almost there... 
00172                 
00173                 ipo = ipoList->GetScalarInterpolator(OB_SIZE_X);
00174                 if (ipo) {
00175                         KX_IInterpolator *interpolator =
00176                                 new KX_ScalarInterpolator(
00177                                         &(ipocontr->GetIPOTransform().GetScaling()[0]),
00178                                         ipo);
00179                         ipocontr->AddInterpolator(interpolator);
00180                         ipocontr->SetModifyScaling(true);
00181                 }
00182                 ipo = ipoList->GetScalarInterpolator(OB_SIZE_Y);
00183                 if (ipo) {
00184                         KX_IInterpolator *interpolator =
00185                                 new KX_ScalarInterpolator(
00186                                         &(ipocontr->GetIPOTransform().GetScaling()[1]),
00187                                         ipo);
00188                         ipocontr->AddInterpolator(interpolator);
00189                         ipocontr->SetModifyScaling(true);
00190                 }
00191                 ipo = ipoList->GetScalarInterpolator(OB_SIZE_Z);
00192                 if (ipo) {
00193                         KX_IInterpolator *interpolator =
00194                                 new KX_ScalarInterpolator(
00195                                         &(ipocontr->GetIPOTransform().GetScaling()[2]),
00196                                         ipo);
00197                         ipocontr->AddInterpolator(interpolator);
00198                         ipocontr->SetModifyScaling(true);
00199                 }
00200 
00201                 // The last few... 
00202                 
00203                 ipo = ipoList->GetScalarInterpolator(OB_DSIZE_X);
00204                 if (ipo) {
00205                         KX_IInterpolator *interpolator =
00206                                 new KX_ScalarInterpolator(
00207                                         &(ipocontr->GetIPOTransform().GetDeltaScaling()[0]),
00208                                         ipo);
00209                         ipocontr->AddInterpolator(interpolator);
00210                         ipocontr->SetModifyScaling(true);
00211                 }
00212                 ipo = ipoList->GetScalarInterpolator(OB_DSIZE_Y);
00213                 if (ipo) {
00214                         KX_IInterpolator *interpolator =
00215                                 new KX_ScalarInterpolator(
00216                                         &(ipocontr->GetIPOTransform().GetDeltaScaling()[1]),
00217                                         ipo);
00218                         ipocontr->AddInterpolator(interpolator);
00219                         ipocontr->SetModifyScaling(true);
00220                 }
00221                 ipo = ipoList->GetScalarInterpolator(OB_DSIZE_Z);
00222                 if (ipo) {
00223                         KX_IInterpolator *interpolator =
00224                                 new KX_ScalarInterpolator(
00225                                         &(ipocontr->GetIPOTransform().GetDeltaScaling()[2]),
00226                                         ipo);
00227                         ipocontr->AddInterpolator(interpolator);
00228                         ipocontr->SetModifyScaling(true);
00229                 }
00230         }
00231 
00232 
00233 }

Generated at Thu Feb 1 13:03:05 2001 for Ketsji Game Engine by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000