svn merge ^/trunk/blender -r43124:43160
[blender.git] / source / gameengine / Converter / BL_ArmatureConstraint.h
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 BL_ArmatureConstraint.h
29  *  \ingroup bgeconv
30  */
31
32 #ifndef __BL_ARMATURECONSTRAINT
33 #define __BL_ARMATURECONSTRAINT
34
35 #include "DNA_constraint_types.h"
36 #include "CTR_HashedPtr.h"
37 #include "CTR_Map.h"
38 #include "PyObjectPlus.h"
39
40 class SCA_IObject;
41 class KX_GameObject;
42 class BL_ArmatureObject;
43 struct bConstraint;
44 struct bPoseChannel;
45 struct Object;
46 struct bPose;
47
48 /**
49  * SG_DList : element of controlled constraint list 
50  *            head = BL_ArmatureObject::m_controlledConstraints
51  * SG_QList : not used
52  */
53 class BL_ArmatureConstraint     : public PyObjectPlus
54 {
55         Py_Header
56
57 private:
58         struct bConstraint* m_constraint;
59         struct bPoseChannel* m_posechannel;
60         class BL_ArmatureObject* m_armature;
61         char m_name[64];
62         KX_GameObject*  m_target;
63         KX_GameObject*  m_subtarget;
64         struct Object*  m_blendtarget;
65         struct Object*  m_blendsubtarget;
66         float           m_blendmat[4][4];
67         float           m_blendsubmat[4][4];
68         struct bPose*   m_pose;
69         struct bPose*   m_subpose;
70
71 public:
72         BL_ArmatureConstraint(class BL_ArmatureObject *armature, 
73                                                 struct bPoseChannel *posechannel, 
74                                                 struct bConstraint *constraint, 
75                                                 KX_GameObject* target,
76                                                 KX_GameObject* subtarget);
77         virtual ~BL_ArmatureConstraint();
78
79         BL_ArmatureConstraint* GetReplica() const;
80         void ReParent(BL_ArmatureObject* armature);
81         void Relink(CTR_Map<CTR_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 #ifdef WITH_PYTHON
111
112         // Python access
113         virtual PyObject* py_repr(void);
114
115         static PyObject* py_attr_getattr(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
116         static int py_attr_setattr(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
117 #endif // WITH_PYTHON
118 };
119
120 #endif //__BL_ARMATURECONSTRAINT
121