BGE: Some various changes to make moving the character physics type easier:
[blender.git] / source / gameengine / Converter / KX_BlenderScalarInterpolator.cpp
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /** \file gameengine/Converter/KX_BlenderScalarInterpolator.cpp
29  *  \ingroup bgeconv
30  */
31
32
33 #include "KX_BlenderScalarInterpolator.h"
34
35 #include <cstring>
36
37 extern "C" {
38 #include "DNA_ipo_types.h"
39 #include "DNA_action_types.h"
40 #include "DNA_anim_types.h"
41 #include "BKE_fcurve.h"
42 }
43
44 float BL_ScalarInterpolator::GetValue(float currentTime) const
45 {
46         // XXX 2.4x IPO_GetFloatValue(m_blender_adt, m_channel, currentTime);
47         return evaluate_fcurve(m_fcu, currentTime);
48 }
49
50 BL_InterpolatorList::BL_InterpolatorList(bAction *action)
51 {
52         if (action==NULL)
53                 return;
54         
55         for (FCurve *fcu = (FCurve *)action->curves.first; fcu; fcu = fcu->next) {
56                 if (fcu->rna_path) {
57                         BL_ScalarInterpolator *new_ipo = new BL_ScalarInterpolator(fcu); 
58                         //assert(new_ipo);
59                         push_back(new_ipo);
60                 }
61         }
62 }
63
64 BL_InterpolatorList::~BL_InterpolatorList()
65 {
66         BL_InterpolatorList::iterator i;
67         for (i = begin(); !(i == end()); ++i) {
68                 delete *i;
69         }
70 }
71
72 KX_IScalarInterpolator *BL_InterpolatorList::GetScalarInterpolator(const char *rna_path, int array_index)
73 {
74         for (BL_InterpolatorList::iterator i = begin(); (i != end()) ; i++ )
75         {
76                 FCurve *fcu= (static_cast<BL_ScalarInterpolator *>(*i))->GetFCurve();
77                 if (array_index==fcu->array_index && strcmp(rna_path, fcu->rna_path)==0)
78                         return *i;
79         }
80         return NULL;
81 }
82