Get rid of c++ in blenkernel and modifiers
[blender.git] / source / gameengine / Converter / BL_DeformableGameObject.cpp
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (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; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30 /** \file gameengine/Converter/BL_DeformableGameObject.cpp
31  *  \ingroup bgeconv
32  */
33
34
35 #include "BL_DeformableGameObject.h"
36 #include "BL_ShapeDeformer.h"
37 #include "BL_ShapeActionActuator.h"
38 #include "RAS_MaterialBucket.h"
39
40
41 BL_DeformableGameObject::~BL_DeformableGameObject()
42 {
43         if (m_pDeformer)
44                 delete m_pDeformer;             //      __NLA : Temporary until we decide where to put this
45 }
46
47 void BL_DeformableGameObject::ProcessReplica()
48 {
49         KX_GameObject::ProcessReplica();
50
51         if (m_pDeformer)
52                 m_pDeformer= (BL_MeshDeformer*)m_pDeformer->GetReplica();
53 }
54
55 CValue*         BL_DeformableGameObject::GetReplica()
56 {
57
58         BL_DeformableGameObject* replica = new BL_DeformableGameObject(*this);//m_float,GetName());
59         replica->ProcessReplica();
60         return replica;
61 }
62
63 bool BL_DeformableGameObject::SetActiveAction(BL_ShapeActionActuator *act, short priority, double curtime)
64 {
65         if (curtime != m_lastframe){
66                 m_activePriority = 9999;
67                 m_lastframe= curtime;
68                 m_activeAct = NULL;
69         }
70
71         if (priority<=m_activePriority)
72         {
73                 if (m_activeAct && (m_activeAct!=act))
74                         m_activeAct->SetBlendTime(0.0f);        /* Reset the blend timer */
75                 m_activeAct = act;
76                 m_activePriority = priority;
77                 m_lastframe = curtime;
78         
79                 return true;
80         }
81         else{
82                 act->SetBlendTime(0.0f);
83                 return false;
84         }
85 }
86
87 bool BL_DeformableGameObject::GetShape(vector<float> &shape)
88 {
89         shape.clear();
90         BL_ShapeDeformer* shape_deformer = dynamic_cast<BL_ShapeDeformer*>(m_pDeformer);
91         if (shape_deformer)
92         {
93                 // this check is normally superfluous: a shape deformer can only be created if the mesh
94                 // has relative keys
95                 Key* key = shape_deformer->GetKey();
96                 if (key && key->type==KEY_RELATIVE) 
97                 {
98                         KeyBlock *kb;
99                         for (kb = (KeyBlock*)key->block.first; kb; kb = (KeyBlock*)kb->next)
100                         {
101                                 shape.push_back(kb->curval);
102                         }
103                 }
104         }
105         return !shape.empty();
106 }
107
108 void BL_DeformableGameObject::SetDeformer(class RAS_Deformer* deformer)
109 {
110         m_pDeformer = deformer;
111
112         SG_QList::iterator<RAS_MeshSlot> mit(m_meshSlots);
113         for(mit.begin(); !mit.end(); ++mit)
114         {
115                 (*mit)->SetDeformer(deformer);
116         }
117 }
118