- Charlie fixed some bugs related to copying armature-constraint data (these are...
[blender.git] / source / gameengine / Converter / BL_ActionActuator.cpp
1 /**
2 * $Id$
3 *
4  * ***** BEGIN GPL/BL DUAL 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. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31 */
32
33 #if defined (__sgi)
34 #include <math.h>
35 #else
36 #include <cmath>
37 #endif
38
39 #include "SCA_LogicManager.h"
40 #include "BL_ActionActuator.h"
41 #include "BL_ArmatureObject.h"
42 #include "BL_SkinDeformer.h"
43 #include "KX_GameObject.h"
44 #include "STR_HashedString.h"
45 #include "DNA_action_types.h"
46 #include "DNA_actuator_types.h"
47 #include "BKE_action.h"
48 #include "DNA_armature_types.h"
49 #include "MEM_guardedalloc.h"
50 #include "BLI_blenlib.h"
51 #include "BLI_arithb.h"
52 #include "MT_Matrix4x4.h"
53 #include "BKE_utildefines.h"
54
55 #ifdef HAVE_CONFIG_H
56 #include <config.h>
57 #endif
58
59 BL_ActionActuator::~BL_ActionActuator()
60 {
61
62         if (m_pose) {
63                 free_pose_channels(m_pose);
64                 MEM_freeN(m_pose);
65                 m_pose = NULL;
66         };
67         
68         if (m_userpose){
69                 free_pose_channels(m_userpose);
70                 MEM_freeN(m_userpose);
71                 m_userpose=NULL;
72         }
73         if (m_blendpose) {
74                 free_pose_channels(m_blendpose);
75                 MEM_freeN(m_blendpose);
76                 m_blendpose = NULL;
77         };
78         
79 }
80
81 void BL_ActionActuator::ProcessReplica(){
82 //      bPose *oldpose = m_pose;
83 //      bPose *oldbpose = m_blendpose;
84         
85         m_pose = NULL;
86         m_blendpose = NULL;
87         m_localtime=m_startframe;
88         m_lastUpdate=-1;
89         
90 }
91
92 void BL_ActionActuator::SetBlendTime (float newtime){
93         m_blendframe = newtime;
94 }
95
96 CValue* BL_ActionActuator::GetReplica() {
97         BL_ActionActuator* replica = new BL_ActionActuator(*this);//m_float,GetName());
98         replica->ProcessReplica();
99         
100         // this will copy properties and so on...
101         CValue::AddDataToReplica(replica);
102         return replica;
103 }
104
105 bool BL_ActionActuator::ClampLocalTime()
106 {
107         if (m_startframe < m_endframe)
108         {
109                 if (m_localtime < m_startframe)
110                 {
111                         m_localtime = m_startframe;
112                         return true;
113                 } 
114                 else if (m_localtime > m_endframe)
115                 {
116                         m_localtime = m_endframe;
117                         return true;
118                 }
119         } else {
120                 if (m_localtime > m_startframe)
121                 {
122                         m_localtime = m_startframe;
123                         return true;
124                 }
125                 else if (m_localtime < m_endframe)
126                 {
127                         m_localtime = m_endframe;
128                         return true;
129                 }
130         }
131         return false;
132 }
133
134 void BL_ActionActuator::SetStartTime(float curtime)
135 {
136         float direction = m_startframe < m_endframe ? 1.0 : -1.0;
137         
138         if (!(m_flag & ACT_FLAG_REVERSE))
139                 m_starttime = curtime - direction*(m_localtime - m_startframe)/KX_FIXED_FRAME_PER_SEC;
140         else
141                 m_starttime = curtime - direction*(m_endframe - m_localtime)/KX_FIXED_FRAME_PER_SEC;
142 }
143
144 void BL_ActionActuator::SetLocalTime(float curtime)
145 {
146         float delta_time = (curtime - m_starttime)*KX_FIXED_FRAME_PER_SEC;
147         
148         if (m_endframe < m_startframe)
149                 delta_time = -delta_time;
150
151         if (!(m_flag & ACT_FLAG_REVERSE))
152                 m_localtime = m_startframe + delta_time;
153         else
154                 m_localtime = m_endframe - delta_time;
155 }
156
157
158 bool BL_ActionActuator::Update(double curtime, bool frame)
159 {
160         bool bNegativeEvent = false;
161         bool bPositiveEvent = false;
162         bool keepgoing = true;
163         bool wrap = false;
164         bool apply=true;
165         int     priority;
166         float newweight;
167         
168         // result = true if animation has to be continued, false if animation stops
169         // maybe there are events for us in the queue !
170         if (frame)
171         {
172                 for (vector<CValue*>::iterator i=m_events.begin(); !(i==m_events.end());i++)
173                 {
174                         if ((*i)->GetNumber() == 0.0f)
175                                 bNegativeEvent = true;
176                         else
177                                 bPositiveEvent= true;
178                         (*i)->Release();
179                 
180                 }
181                 m_events.clear();
182                 
183                 if (bPositiveEvent)
184                         m_flag |= ACT_FLAG_ACTIVE;
185                 
186                 if (bNegativeEvent)
187                 {
188                         if (!(m_flag & ACT_FLAG_ACTIVE))
189                                 return false;
190                         m_flag &= ~ACT_FLAG_ACTIVE;
191                 }
192         }
193         
194         /*      We know that action actuators have been discarded from all non armature objects:
195         if we're being called, we're attached to a BL_ArmatureObject */
196         BL_ArmatureObject *obj = (BL_ArmatureObject*)GetParent();
197         float length = m_endframe - m_startframe;
198         
199         priority = m_priority;
200         
201         /* Determine pre-incrementation behaviour and set appropriate flags */
202         switch (m_playtype){
203         case ACT_ACTION_MOTION:
204                 if (bNegativeEvent){
205                         keepgoing=false;
206                         apply=false;
207                 };
208                 break;
209         case ACT_ACTION_FROM_PROP:
210                 if (bNegativeEvent){
211                         apply=false;
212                         keepgoing=false;
213                 }
214                 break;
215         case ACT_ACTION_LOOP_END:
216                 if (bPositiveEvent){
217                         if (!(m_flag & ACT_FLAG_LOCKINPUT)){
218                                 m_flag &= ~ACT_FLAG_KEYUP;
219                                 m_flag &= ~ACT_FLAG_REVERSE;
220                                 m_flag |= ACT_FLAG_LOCKINPUT;
221                                 m_localtime = m_startframe;
222                                 m_starttime = curtime;
223                         }
224                 }
225                 if (bNegativeEvent){
226                         m_flag |= ACT_FLAG_KEYUP;
227                 }
228                 break;
229         case ACT_ACTION_LOOP_STOP:
230                 if (bPositiveEvent){
231                         if (!(m_flag & ACT_FLAG_LOCKINPUT)){
232                                 m_flag &= ~ACT_FLAG_REVERSE;
233                                 m_flag &= ~ACT_FLAG_KEYUP;
234                                 m_flag |= ACT_FLAG_LOCKINPUT;
235                                 SetStartTime(curtime);
236                         }
237                 }
238                 if (bNegativeEvent){
239                         m_flag |= ACT_FLAG_KEYUP;
240                         m_flag &= ~ACT_FLAG_LOCKINPUT;
241                         keepgoing=false;
242                         apply=false;
243                 }
244                 break;
245         case ACT_ACTION_FLIPPER:
246                 if (bPositiveEvent){
247                         if (!(m_flag & ACT_FLAG_LOCKINPUT)){
248                                 m_flag &= ~ACT_FLAG_REVERSE;
249                                 m_flag |= ACT_FLAG_LOCKINPUT;
250                                 SetStartTime(curtime);
251                         }
252                 }
253                 else if (bNegativeEvent){
254                         m_flag |= ACT_FLAG_REVERSE;
255                         m_flag &= ~ACT_FLAG_LOCKINPUT;
256                         SetStartTime(curtime);
257                 }
258                 break;
259         case ACT_ACTION_PLAY:
260                 if (bPositiveEvent){
261                         if (!(m_flag & ACT_FLAG_LOCKINPUT)){
262                                 m_flag &= ~ACT_FLAG_REVERSE;
263                                 m_localtime = m_starttime;
264                                 m_starttime = curtime;
265                                 m_flag |= ACT_FLAG_LOCKINPUT;
266                         }
267                 }
268                 break;
269         default:
270                 break;
271         }
272         
273         /* Perform increment */
274         if (keepgoing){
275                 if (m_playtype == ACT_ACTION_MOTION){
276                         MT_Point3       newpos;
277                         MT_Point3       deltapos;
278                         
279                         newpos = obj->NodeGetWorldPosition();
280                         
281                         /* Find displacement */
282                         deltapos = newpos-m_lastpos;
283                         m_localtime += (length/m_stridelength) * deltapos.length();
284                         m_lastpos = newpos;
285                 }
286                 else{
287                         SetLocalTime(curtime);
288                 }
289         }
290         
291         /* Check if a wrapping response is needed */
292         if (length){
293                 if (m_localtime < m_startframe || m_localtime > m_endframe)
294                 {
295                         m_localtime = m_startframe + fmod(m_localtime, length);
296                         wrap = true;
297                 }
298         }
299         else
300                 m_localtime = m_startframe;
301         
302         /* Perform post-increment tasks */
303         switch (m_playtype){
304         case ACT_ACTION_FROM_PROP:
305                 {
306                         CValue* propval = GetParent()->GetProperty(m_propname);
307                         if (propval)
308                                 m_localtime = propval->GetNumber();
309                         
310                         if (bNegativeEvent){
311                                 keepgoing=false;
312                         }
313                 }
314                 break;
315         case ACT_ACTION_MOTION:
316                 break;
317         case ACT_ACTION_LOOP_STOP:
318                 break;
319         case ACT_ACTION_FLIPPER:
320                 if (wrap){
321                         if (!(m_flag & ACT_FLAG_REVERSE)){
322                                 m_localtime=m_endframe;
323                                 //keepgoing = false;
324                         }
325                         else {
326                                 m_localtime=m_startframe;
327                                 keepgoing = false;
328                         }
329                 }
330                 break;
331         case ACT_ACTION_LOOP_END:
332                 if (wrap){
333                         if (m_flag & ACT_FLAG_KEYUP){
334                                 keepgoing = false;
335                                 m_localtime = m_endframe;
336                                 m_flag &= ~ACT_FLAG_LOCKINPUT;
337                         }
338                         SetStartTime(curtime);
339                 }
340                 break;
341         case ACT_ACTION_PLAY:
342                 if (wrap){
343                         m_localtime = m_endframe;
344                         keepgoing = false;
345                         m_flag &= ~ACT_FLAG_LOCKINPUT;
346                 }
347                 break;
348         default:
349                 keepgoing = false;
350                 break;
351         }
352         
353         
354         if (bNegativeEvent)
355                 m_blendframe=0.0;
356         
357         /* Apply the pose if necessary*/
358         if (apply){
359
360                 /* Priority test */
361                 if (obj->SetActiveAction(this, priority, curtime)){
362                         
363                         /* Get the underlying pose from the armature */
364                         obj->GetPose(&m_pose);
365                         
366                         /* Override the necessary channels with ones from the action */
367                         extract_pose_from_action(m_pose, m_action, m_localtime);
368
369                         /* Perform the user override (if any) */
370                         if (m_userpose){
371                                 extract_pose_from_pose(m_pose, m_userpose);
372 //                              clear_pose(m_userpose);
373                                 MEM_freeN(m_userpose);
374                                 m_userpose = NULL;
375                         }
376 #if 1
377                         /* Handle blending */
378                         if (m_blendin && (m_blendframe<m_blendin)){
379                                 /* If this is the start of a blending sequence... */
380                                 if ((m_blendframe==0.0) || (!m_blendpose)){
381                                         obj->GetMRDPose(&m_blendpose);
382                                         m_blendstart = curtime;
383                                 }
384                                 
385                                 /* Find percentages */
386                                 newweight = (m_blendframe/(float)m_blendin);
387                                 blend_poses(m_pose, m_blendpose, 1.0 - newweight, POSE_BLEND);
388
389                                 /* Increment current blending percentage */
390                                 m_blendframe = (curtime - m_blendstart)*KX_FIXED_FRAME_PER_SEC;
391                                 if (m_blendframe>m_blendin)
392                                         m_blendframe = m_blendin;
393                                 
394                         }
395 #endif
396                         m_lastUpdate = m_localtime;
397                         obj->SetPose (m_pose);
398                 }
399                 else{
400                         m_blendframe = 0.0;
401                 }
402         }
403         
404         if (!keepgoing){
405                 m_blendframe = 0.0;
406         }
407         return keepgoing;
408 };
409
410 /* ------------------------------------------------------------------------- */
411 /* Python functions                                                          */
412 /* ------------------------------------------------------------------------- */
413
414 /* Integration hooks ------------------------------------------------------- */
415
416 PyTypeObject BL_ActionActuator::Type = {
417         PyObject_HEAD_INIT(&PyType_Type)
418                 0,
419                 "BL_ActionActuator",
420                 sizeof(BL_ActionActuator),
421                 0,
422                 PyDestructor,
423                 0,
424                 __getattr,
425                 __setattr,
426                 0, //&MyPyCompare,
427                 __repr,
428                 0, //&cvalue_as_number,
429                 0,
430                 0,
431                 0,
432                 0
433 };
434
435 PyParentObject BL_ActionActuator::Parents[] = {
436         &BL_ActionActuator::Type,
437                 &SCA_IActuator::Type,
438                 &SCA_ILogicBrick::Type,
439                 &CValue::Type,
440                 NULL
441 };
442
443 PyMethodDef BL_ActionActuator::Methods[] = {
444         {"setAction", (PyCFunction) BL_ActionActuator::sPySetAction, METH_VARARGS, SetAction_doc},
445         {"setStart", (PyCFunction) BL_ActionActuator::sPySetStart, METH_VARARGS, SetStart_doc},
446         {"setEnd", (PyCFunction) BL_ActionActuator::sPySetEnd, METH_VARARGS, SetEnd_doc},
447         {"setBlendin", (PyCFunction) BL_ActionActuator::sPySetBlendin, METH_VARARGS, SetBlendin_doc},
448         {"setPriority", (PyCFunction) BL_ActionActuator::sPySetPriority, METH_VARARGS, SetPriority_doc},
449         {"setFrame", (PyCFunction) BL_ActionActuator::sPySetFrame, METH_VARARGS, SetFrame_doc},
450         {"setProperty", (PyCFunction) BL_ActionActuator::sPySetProperty, METH_VARARGS, SetProperty_doc},
451         {"setBlendtime", (PyCFunction) BL_ActionActuator::sPySetBlendtime, METH_VARARGS, SetBlendtime_doc},
452
453         {"getAction", (PyCFunction) BL_ActionActuator::sPyGetAction, METH_VARARGS, GetAction_doc},
454         {"getStart", (PyCFunction) BL_ActionActuator::sPyGetStart, METH_VARARGS, GetStart_doc},
455         {"getEnd", (PyCFunction) BL_ActionActuator::sPyGetEnd, METH_VARARGS, GetEnd_doc},
456         {"getBlendin", (PyCFunction) BL_ActionActuator::sPyGetBlendin, METH_VARARGS, GetBlendin_doc},
457         {"getPriority", (PyCFunction) BL_ActionActuator::sPyGetPriority, METH_VARARGS, GetPriority_doc},
458         {"getFrame", (PyCFunction) BL_ActionActuator::sPyGetFrame, METH_VARARGS, GetFrame_doc},
459         {"getProperty", (PyCFunction) BL_ActionActuator::sPyGetProperty, METH_VARARGS, GetProperty_doc},
460         {"setChannel", (PyCFunction) BL_ActionActuator::sPySetChannel, METH_VARARGS, SetChannel_doc},
461 //      {"getChannel", (PyCFunction) BL_ActionActuator::sPyGetChannel, METH_VARARGS},
462         {"getType", (PyCFunction) BL_ActionActuator::sPyGetType, METH_VARARGS, GetType_doc},    
463         {"setType", (PyCFunction) BL_ActionActuator::sPySetType, METH_VARARGS, SetType_doc},
464         {NULL,NULL} //Sentinel
465 };
466
467 PyObject* BL_ActionActuator::_getattr(const STR_String& attr) {
468         _getattr_up(SCA_IActuator);
469 }
470
471 /*     setStart                                                              */
472 char BL_ActionActuator::GetAction_doc[] = 
473 "getAction()\n"
474 "\tReturns a string containing the name of the current action.\n";
475
476 PyObject* BL_ActionActuator::PyGetAction(PyObject* self, 
477                                                                                  PyObject* args, 
478                                                                                  PyObject* kwds) {
479         PyObject *result;
480         
481         if (m_action){
482                 result = Py_BuildValue("s", m_action->id.name+2);
483         }
484         else{
485                 Py_INCREF(Py_None);
486                 result = Py_None;
487         }
488         
489         return result;
490 }
491
492 /*     getProperty                                                             */
493 char BL_ActionActuator::GetProperty_doc[] = 
494 "getProperty()\n"
495 "\tReturns the name of the property to be used in FromProp mode.\n";
496
497 PyObject* BL_ActionActuator::PyGetProperty(PyObject* self, 
498                                                                                    PyObject* args, 
499                                                                                    PyObject* kwds) {
500         PyObject *result;
501         
502         result = Py_BuildValue("s", (const char *)m_propname);
503         
504         return result;
505 }
506
507 /*     getFrame                                                              */
508 char BL_ActionActuator::GetFrame_doc[] = 
509 "getFrame()\n"
510 "\tReturns the current frame number.\n";
511
512 PyObject* BL_ActionActuator::PyGetFrame(PyObject* self, 
513                                                                                 PyObject* args, 
514                                                                                 PyObject* kwds) {
515         PyObject *result;
516         
517         result = Py_BuildValue("f", m_localtime);
518         
519         return result;
520 }
521
522 /*     getEnd                                                                */
523 char BL_ActionActuator::GetEnd_doc[] = 
524 "getEnd()\n"
525 "\tReturns the last frame of the action.\n";
526
527 PyObject* BL_ActionActuator::PyGetEnd(PyObject* self, 
528                                                                           PyObject* args, 
529                                                                           PyObject* kwds) {
530         PyObject *result;
531         
532         result = Py_BuildValue("f", m_endframe);
533         
534         return result;
535 }
536
537 /*     getStart                                                              */
538 char BL_ActionActuator::GetStart_doc[] = 
539 "getStart()\n"
540 "\tReturns the starting frame of the action.\n";
541
542 PyObject* BL_ActionActuator::PyGetStart(PyObject* self, 
543                                                                                 PyObject* args, 
544                                                                                 PyObject* kwds) {
545         PyObject *result;
546         
547         result = Py_BuildValue("f", m_startframe);
548         
549         return result;
550 }
551
552 /*     getBlendin                                                            */
553 char BL_ActionActuator::GetBlendin_doc[] = 
554 "getBlendin()\n"
555 "\tReturns the number of interpolation animation frames to be\n"
556 "\tgenerated when this actuator is triggered.\n";
557
558 PyObject* BL_ActionActuator::PyGetBlendin(PyObject* self, 
559                                                                                   PyObject* args, 
560                                                                                   PyObject* kwds) {
561         PyObject *result;
562         
563         result = Py_BuildValue("f", m_blendin);
564         
565         return result;
566 }
567
568 /*     getPriority                                                           */
569 char BL_ActionActuator::GetPriority_doc[] = 
570 "getPriority()\n"
571 "\tReturns the priority for this actuator.  Actuators with lower\n"
572 "\tPriority numbers will override actuators with higher numbers.\n";
573
574 PyObject* BL_ActionActuator::PyGetPriority(PyObject* self, 
575                                                                                    PyObject* args, 
576                                                                                    PyObject* kwds) {
577         PyObject *result;
578         
579         result = Py_BuildValue("i", m_priority);
580         
581         return result;
582 }
583
584 /*     setAction                                                             */
585 char BL_ActionActuator::SetAction_doc[] = 
586 "setAction(action, (reset))\n"
587 "\t - action    : The name of the action to set as the current action.\n"
588 "\t - reset     : Optional parameter indicating whether to reset the\n"
589 "\t               blend timer or not.  A value of 1 indicates that the\n"
590 "\t               timer should be reset.  A value of 0 will leave it\n"
591 "\t               unchanged.  If reset is not specified, the timer will"
592 "\t                   be reset.\n";
593
594 PyObject* BL_ActionActuator::PySetAction(PyObject* self, 
595                                                                                  PyObject* args, 
596                                                                                  PyObject* kwds) {
597         char *string;
598         int     reset = 1;
599
600         if (PyArg_ParseTuple(args,"s|i",&string, &reset))
601         {
602                 bAction *action;
603                 
604                 action = (bAction*)SCA_ILogicBrick::m_sCurrentLogicManager->GetActionByName(STR_String(string));
605                 
606                 if (!action){
607                         /* NOTE!  Throw an exception or something */
608                         //                      printf ("setAction failed: Action not found\n", string);
609                 }
610                 else{
611                         m_action=action;
612                         if (reset)
613                                 m_blendframe = 0;
614                 }
615         }
616         
617         Py_INCREF(Py_None);
618         return Py_None;
619 }
620
621 /*     setStart                                                              */
622 char BL_ActionActuator::SetStart_doc[] = 
623 "setStart(start)\n"
624 "\t - start     : Specifies the starting frame of the animation.\n";
625
626 PyObject* BL_ActionActuator::PySetStart(PyObject* self, 
627                                                                                 PyObject* args, 
628                                                                                 PyObject* kwds) {
629         float start;
630         
631         if (PyArg_ParseTuple(args,"f",&start))
632         {
633                 m_startframe = start;
634         }
635         
636         Py_INCREF(Py_None);
637         return Py_None;
638 }
639
640 /*     setEnd                                                                */
641 char BL_ActionActuator::SetEnd_doc[] = 
642 "setEnd(end)\n"
643 "\t - end       : Specifies the ending frame of the animation.\n";
644
645 PyObject* BL_ActionActuator::PySetEnd(PyObject* self, 
646                                                                           PyObject* args, 
647                                                                           PyObject* kwds) {
648         float end;
649         
650         if (PyArg_ParseTuple(args,"f",&end))
651         {
652                 m_endframe = end;
653         }
654         
655         Py_INCREF(Py_None);
656         return Py_None;
657 }
658
659 /*     setBlendin                                                            */
660 char BL_ActionActuator::SetBlendin_doc[] = 
661 "setBlendin(blendin)\n"
662 "\t - blendin   : Specifies the number of frames of animation to generate\n"
663 "\t               when making transitions between actions.\n";
664
665 PyObject* BL_ActionActuator::PySetBlendin(PyObject* self, 
666                                                                                   PyObject* args, 
667                                                                                   PyObject* kwds) {
668         float blendin;
669         
670         if (PyArg_ParseTuple(args,"f",&blendin))
671         {
672                 m_blendin = blendin;
673         }
674         
675         Py_INCREF(Py_None);
676         return Py_None;
677 }
678
679 /*     setBlendtime                                                          */
680 char BL_ActionActuator::SetBlendtime_doc[] = 
681 "setBlendtime(blendtime)\n"
682 "\t - blendtime : Allows the script to directly modify the internal timer\n"
683 "\t               used when generating transitions between actions.  This\n"
684 "\t               parameter must be in the range from 0.0 to 1.0.\n";
685
686 PyObject* BL_ActionActuator::PySetBlendtime(PyObject* self, 
687                                                                                   PyObject* args, 
688                                                                                   PyObject* kwds) {
689         float blendframe;
690         
691         if (PyArg_ParseTuple(args,"f",&blendframe))
692         {
693                 m_blendframe = blendframe * m_blendin;
694                 if (m_blendframe<0)
695                         m_blendframe = 0;
696                 if (m_blendframe>m_blendin)
697                         m_blendframe = m_blendin;
698         }
699         
700         Py_INCREF(Py_None);
701         return Py_None;
702 }
703
704 /*     setPriority                                                           */
705 char BL_ActionActuator::SetPriority_doc[] = 
706 "setPriority(priority)\n"
707 "\t - priority  : Specifies the new priority.  Actuators will lower\n"
708 "\t               priority numbers will override actuators with higher\n"
709 "\t               numbers.\n";
710
711 PyObject* BL_ActionActuator::PySetPriority(PyObject* self, 
712                                                                                    PyObject* args, 
713                                                                                    PyObject* kwds) {
714         int priority;
715         
716         if (PyArg_ParseTuple(args,"i",&priority))
717         {
718                 m_priority = priority;
719         }
720         
721         Py_INCREF(Py_None);
722         return Py_None;
723 }
724
725 /*     setFrame                                                              */
726 char BL_ActionActuator::SetFrame_doc[] = 
727 "setFrame(frame)\n"
728 "\t - frame     : Specifies the new current frame for the animation\n";
729
730 PyObject* BL_ActionActuator::PySetFrame(PyObject* self, 
731                                                                                 PyObject* args, 
732                                                                                 PyObject* kwds) {
733         float frame;
734         
735         if (PyArg_ParseTuple(args,"f",&frame))
736         {
737                 m_localtime = frame;
738                 if (m_localtime<m_startframe)
739                         m_localtime=m_startframe;
740                 else if (m_localtime>m_endframe)
741                         m_localtime=m_endframe;
742         }
743         
744         Py_INCREF(Py_None);
745         return Py_None;
746 }
747
748 /*     setProperty                                                           */
749 char BL_ActionActuator::SetProperty_doc[] = 
750 "setProperty(prop)\n"
751 "\t - prop      : A string specifying the property name to be used in\n"
752 "\t               FromProp playback mode.\n";
753
754 PyObject* BL_ActionActuator::PySetProperty(PyObject* self, 
755                                                                                    PyObject* args, 
756                                                                                    PyObject* kwds) {
757         char *string;
758         
759         if (PyArg_ParseTuple(args,"s",&string))
760         {
761                 m_propname = string;
762         }
763         
764         Py_INCREF(Py_None);
765         return Py_None;
766 }
767
768 /*
769 PyObject* BL_ActionActuator::PyGetChannel(PyObject* self, 
770                                                                                    PyObject* args, 
771                                                                                    PyObject* kwds) {
772         char *string;
773         
774         if (PyArg_ParseTuple(args,"s",&string))
775         {
776                 m_propname = string;
777         }
778         
779         Py_INCREF(Py_None);
780         return Py_None;
781 }
782 */
783
784 /*     setChannel                                                            */
785 char BL_ActionActuator::SetChannel_doc[] = 
786 "setChannel(channel, matrix)\n"
787 "\t - channel   : A string specifying the name of the bone channel.\n"
788 "\t - matrix    : A 4x4 matrix specifying the overriding transformation\n"
789 "\t               as an offset from the bone's rest position.\n";
790
791 PyObject* BL_ActionActuator::PySetChannel(PyObject* self, 
792                                                                                    PyObject* args, 
793                                                                                    PyObject* kwds) 
794 {
795         float matrix[4][4];
796         char *string;
797         PyObject* pylist;
798         bool    error = false;
799         int row,col;
800         int     mode = 0;       /* 0 for bone space, 1 for armature/world space */
801         
802         PyArg_ParseTuple(args,"sO|i", &string, &pylist, &mode);
803         
804         if (pylist->ob_type == &CListValue::Type)
805         {
806                 CListValue* listval = (CListValue*) pylist;
807                 if (listval->GetCount() == 4)
808                 {
809                         for (row=0;row<4;row++) // each row has a 4-vector [x,y,z, w]
810                         {
811                                 CListValue* vecval = (CListValue*)listval->GetValue(row);
812                                 for (col=0;col<4;col++)
813                                 {
814                                         matrix[row][col] = vecval->GetValue(col)->GetNumber();
815                                         
816                                 }
817                         }
818                 }
819                 else
820                 {
821                         error = true;
822                 }
823         }
824         else
825         {
826                 // assert the list is long enough...
827                 int numitems = PyList_Size(pylist);
828                 if (numitems == 4)
829                 {
830                         for (row=0;row<4;row++) // each row has a 4-vector [x,y,z, w]
831                         {
832                                 
833                                 PyObject* veclist = PyList_GetItem(pylist,row); // here we have a vector4 list
834                                 for (col=0;col<4;col++)
835                                 {
836                                         matrix[row][col] =  PyFloat_AsDouble(PyList_GetItem(veclist,col));
837                                         
838                                 }
839                         }
840                 }
841                 else
842                 {
843                         error = true;
844                 }
845         }
846         
847         if (!error)
848         {
849
850 /*      DO IT HERE */
851                 bPoseChannel *pchan= verify_pose_channel(m_userpose, string);
852
853                 Mat4ToQuat(matrix, pchan->quat);
854                 Mat4ToSize(matrix, pchan->size);
855                 VECCOPY (pchan->loc, matrix[3]);
856                 
857                 pchan->flag |= POSE_ROT|POSE_LOC|POSE_SIZE;
858
859                 if (!m_userpose){
860                         m_userpose = (bPose*)MEM_callocN(sizeof(bPose), "userPose");
861                 }
862         }
863         
864         Py_INCREF(Py_None);
865         return Py_None;
866 }
867
868 /* getType */
869 char BL_ActionActuator::GetType_doc[] =
870 "getType()\n"
871 "\tReturns the operation mode of the actuator.\n";
872 PyObject* BL_ActionActuator::PyGetType(PyObject* self,
873                                        PyObject* args, 
874                                        PyObject* kwds) {
875     return Py_BuildValue("h", m_playtype);
876 }
877
878 /* setType */
879 char BL_ActionActuator::SetType_doc[] =
880 "setType(mode)\n"
881 "\t - mode: Play (0), Flipper (2), LoopStop (3), LoopEnd (4) or Property (6)\n"
882 "\tSet the operation mode of the actuator.\n";
883 PyObject* BL_ActionActuator::PySetType(PyObject* self,
884                                        PyObject* args,
885                                        PyObject* kwds) {
886         short typeArg;
887                                                                                                              
888     if (!PyArg_ParseTuple(args, "h", &typeArg)) {
889         return NULL;
890     }
891
892         switch (typeArg) {
893         case KX_ACT_ACTION_PLAY:
894         case KX_ACT_ACTION_FLIPPER:
895         case KX_ACT_ACTION_LOOPSTOP:
896         case KX_ACT_ACTION_LOOPEND:
897         case KX_ACT_ACTION_PROPERTY:
898                 m_playtype = typeArg;
899                 break;
900         default:
901                 printf("Invalid type for action actuator: %d\n", typeArg); /* error */
902     }
903         
904     Py_Return;
905 }
906