2
* $Id: KX_SG_BoneParentNodeRelationship.cpp,v 1.1 2005/04/23 11:36:44 kester Exp $
3
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version. The Blender
9
* Foundation also sells licenses for use in proprietary software under
10
* the Blender License. See http://www.blender.org/BL/ for information
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software Foundation,
20
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
23
* All rights reserved.
25
* The Original Code is: all of this file.
27
* Contributor(s): none yet.
29
* ***** END GPL/BL DUAL LICENSE BLOCK *****
34
#include "KX_SG_BoneParentNodeRelationship.h"
36
#include "MT_Matrix4x4.h"
37
#include "BL_ArmatureObject.h"
45
* Implementation of classes defined in KX_SG_BoneParentNodeRelationship.h
49
* first of all KX_SG_BoneParentRelation
52
KX_BoneParentRelation *
53
KX_BoneParentRelation::
56
return new KX_BoneParentRelation(bone);
60
KX_BoneParentRelation::
61
UpdateChildCoordinates(
63
const SG_Spatial * parent
65
MT_assert(child != NULL);
67
// This way of accessing child coordinates is a bit cumbersome
68
// be nice to have non constant reference access to these values.
70
const MT_Vector3 & child_scale = child->GetLocalScale();
71
const MT_Point3 & child_pos = child->GetLocalPosition();
72
const MT_Matrix3x3 & child_rotation = child->GetLocalOrientation();
74
// the childs world locations which we will update.
76
MT_Vector3 child_w_scale;
77
MT_Point3 child_w_pos;
78
MT_Matrix3x3 child_w_rotation;
80
bool valid_parent_transform = false;
84
const BL_ArmatureObject *armature = (const BL_ArmatureObject*)(parent->GetSGClientObject());
87
MT_Matrix4x4 parent_matrix;
88
if (armature->GetBoneMatrix(m_bone, parent_matrix))
90
// Get the child's transform, and the bone matrix.
91
MT_Matrix4x4 child_transform (
92
MT_Transform(child_pos + MT_Vector3(0.0, armature->GetBoneLength(m_bone), 0.0),
93
child_rotation.scaled(
98
// The child's world transform is parent * child
99
parent_matrix = parent->GetWorldTransform() * parent_matrix;
100
child_transform = parent_matrix * child_transform;
102
// Recompute the child transform components from the transform.
103
child_w_scale = MT_Vector3(
104
MT_Vector3(child_transform[0][0], child_transform[0][1], child_transform[0][2]).length(),
105
MT_Vector3(child_transform[1][0], child_transform[1][1], child_transform[1][2]).length(),
106
MT_Vector3(child_transform[2][0], child_transform[2][1], child_transform[2][2]).length());
107
child_w_rotation = MT_Matrix3x3(child_transform[0][0], child_transform[0][1], child_transform[0][2],
108
child_transform[1][0], child_transform[1][1], child_transform[1][2],
109
child_transform[2][0], child_transform[2][1], child_transform[2][2]);
110
child_w_rotation.scale(1.0/child_w_scale[0], 1.0/child_w_scale[1], 1.0/child_w_scale[2]);
112
child_w_pos = MT_Point3(child_transform[0][3], child_transform[1][3], child_transform[2][3]);
114
valid_parent_transform = true;
119
if (!valid_parent_transform)
121
child_w_scale = child_scale;
122
child_w_pos = child_pos;
123
child_w_rotation = child_rotation;
126
child->SetWorldScale(child_w_scale);
127
child->SetWorldPosition(child_w_pos);
128
child->SetWorldOrientation(child_w_rotation);
130
return valid_parent_transform;
134
KX_BoneParentRelation::
137
KX_BoneParentRelation* bone_parent = new KX_BoneParentRelation(m_bone);
141
KX_BoneParentRelation::
142
~KX_BoneParentRelation(
148
KX_BoneParentRelation::
149
KX_BoneParentRelation(Bone* bone