Merge of itasc branch. Project files, scons and cmake should be working. Makefile...
[blender.git] / source / gameengine / Converter / BL_ArmatureConstraint.h
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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 #ifndef __BL_ARMATURECONSTRAINT
30 #define __BL_ARMATURECONSTRAINT
31
32 #include "DNA_constraint_types.h"
33 #include "GEN_HashedPtr.h"
34 #include "GEN_Map.h"
35 #include "PyObjectPlus.h"
36
37 class SCA_IObject;
38 class KX_GameObject;
39 class BL_ArmatureObject;
40 struct bConstraint;
41 struct bPoseChannel;
42 struct Object;
43 struct bPose;
44
45 /**
46  * SG_DList : element of controlled constraint list 
47  *            head = BL_ArmatureObject::m_controlledConstraints
48  * SG_QList : not used
49  */
50 class BL_ArmatureConstraint     : public PyObjectPlus
51 {
52         Py_Header;
53
54 private:
55         struct bConstraint* m_constraint;
56         struct bPoseChannel* m_posechannel;
57         class BL_ArmatureObject* m_armature;
58         char m_name[64];
59         KX_GameObject*  m_target;
60         KX_GameObject*  m_subtarget;
61         struct Object*  m_blendtarget;
62         struct Object*  m_blendsubtarget;
63         float           m_blendmat[4][4];
64         float           m_blendsubmat[4][4];
65         struct bPose*   m_pose;
66         struct bPose*   m_subpose;
67
68 public:
69         BL_ArmatureConstraint(class BL_ArmatureObject *armature, 
70                                                 struct bPoseChannel *posechannel, 
71                                                 struct bConstraint *constraint, 
72                                                 KX_GameObject* target,
73                                                 KX_GameObject* subtarget);
74         virtual ~BL_ArmatureConstraint();
75
76
77         virtual PyObject* py_repr(void);
78
79         BL_ArmatureConstraint* GetReplica() const;
80         void ReParent(BL_ArmatureObject* armature);
81         void Relink(GEN_Map<GEN_HashedPtr, void*> *map);
82         bool UnlinkObject(SCA_IObject* clientobj);
83
84         void UpdateTarget();
85         void RestoreTarget();
86
87         bool Match(const char* posechannel, const char* constraint);
88         const char* GetName() { return m_name; }
89
90         void SetConstraintFlag(int flag)
91         {
92                 if (m_constraint)
93                         m_constraint->flag |= flag;
94         }
95         void ClrConstraintFlag(int flag)
96         {
97                 if (m_constraint)
98                         m_constraint->flag &= ~flag;
99         }
100         void SetWeight(float weight)
101         {
102                 if (m_constraint && m_constraint->type == CONSTRAINT_TYPE_KINEMATIC && m_constraint->data) {
103                         bKinematicConstraint* con = (bKinematicConstraint*)m_constraint->data;
104                         con->weight = weight;
105                 }
106         }
107         void SetTarget(KX_GameObject* target);
108         void SetSubtarget(KX_GameObject* subtarget);
109
110         // Python access
111         static PyObject* py_attr_getattr(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
112         static int py_attr_setattr(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
113
114 };
115
116 #endif //__BL_ARMATURECONSTRAINT
117