2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2005-04-23 11:36:44 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-04-16 22:40:48 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2005-04-23 11:36:44 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-04-23 11:36:44 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2005-04-23 11:36:44 +00:00
|
|
|
*/
|
|
|
|
|
2011-02-25 13:35:59 +00:00
|
|
|
/** \file gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.cpp
|
|
|
|
* \ingroup ketsji
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2005-04-23 11:36:44 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "KX_SG_BoneParentNodeRelationship.h"
|
|
|
|
|
|
|
|
#include "MT_Matrix4x4.h"
|
|
|
|
#include "BL_ArmatureObject.h"
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of classes defined in KX_SG_BoneParentNodeRelationship.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* first of all KX_SG_BoneParentRelation
|
|
|
|
*/
|
|
|
|
|
|
|
|
KX_BoneParentRelation *
|
|
|
|
KX_BoneParentRelation::
|
|
|
|
New(Bone* bone
|
|
|
|
) {
|
|
|
|
return new KX_BoneParentRelation(bone);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
KX_BoneParentRelation::
|
|
|
|
UpdateChildCoordinates(
|
|
|
|
SG_Spatial * child,
|
2009-04-07 22:14:06 +00:00
|
|
|
const SG_Spatial * parent,
|
|
|
|
bool& parentUpdated
|
2005-04-23 11:36:44 +00:00
|
|
|
){
|
|
|
|
MT_assert(child != NULL);
|
|
|
|
|
|
|
|
// This way of accessing child coordinates is a bit cumbersome
|
|
|
|
// be nice to have non constant reference access to these values.
|
|
|
|
|
|
|
|
const MT_Vector3 & child_scale = child->GetLocalScale();
|
|
|
|
const MT_Point3 & child_pos = child->GetLocalPosition();
|
|
|
|
const MT_Matrix3x3 & child_rotation = child->GetLocalOrientation();
|
2009-04-07 22:14:06 +00:00
|
|
|
// we don't know if the armature has been updated or not, assume yes
|
|
|
|
parentUpdated = true;
|
2005-04-23 11:36:44 +00:00
|
|
|
|
|
|
|
// the childs world locations which we will update.
|
|
|
|
|
|
|
|
MT_Vector3 child_w_scale;
|
|
|
|
MT_Point3 child_w_pos;
|
|
|
|
MT_Matrix3x3 child_w_rotation;
|
|
|
|
|
|
|
|
bool valid_parent_transform = false;
|
|
|
|
|
|
|
|
if (parent)
|
|
|
|
{
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 20:51:28 +00:00
|
|
|
BL_ArmatureObject *armature = (BL_ArmatureObject*)(parent->GetSGClientObject());
|
2005-04-23 11:36:44 +00:00
|
|
|
if (armature)
|
|
|
|
{
|
|
|
|
MT_Matrix4x4 parent_matrix;
|
|
|
|
if (armature->GetBoneMatrix(m_bone, parent_matrix))
|
|
|
|
{
|
|
|
|
// Get the child's transform, and the bone matrix.
|
|
|
|
MT_Matrix4x4 child_transform (
|
|
|
|
MT_Transform(child_pos + MT_Vector3(0.0, armature->GetBoneLength(m_bone), 0.0),
|
|
|
|
child_rotation.scaled(
|
|
|
|
child_scale[0],
|
|
|
|
child_scale[1],
|
|
|
|
child_scale[2])));
|
|
|
|
|
|
|
|
// The child's world transform is parent * child
|
|
|
|
parent_matrix = parent->GetWorldTransform() * parent_matrix;
|
|
|
|
child_transform = parent_matrix * child_transform;
|
|
|
|
|
|
|
|
// Recompute the child transform components from the transform.
|
2009-02-25 06:43:03 +00:00
|
|
|
child_w_scale.setValue(
|
2005-04-23 11:36:44 +00:00
|
|
|
MT_Vector3(child_transform[0][0], child_transform[0][1], child_transform[0][2]).length(),
|
|
|
|
MT_Vector3(child_transform[1][0], child_transform[1][1], child_transform[1][2]).length(),
|
|
|
|
MT_Vector3(child_transform[2][0], child_transform[2][1], child_transform[2][2]).length());
|
2009-02-25 06:43:03 +00:00
|
|
|
child_w_rotation.setValue(child_transform[0][0], child_transform[0][1], child_transform[0][2],
|
2005-04-23 11:36:44 +00:00
|
|
|
child_transform[1][0], child_transform[1][1], child_transform[1][2],
|
|
|
|
child_transform[2][0], child_transform[2][1], child_transform[2][2]);
|
|
|
|
child_w_rotation.scale(1.0/child_w_scale[0], 1.0/child_w_scale[1], 1.0/child_w_scale[2]);
|
|
|
|
|
|
|
|
child_w_pos = MT_Point3(child_transform[0][3], child_transform[1][3], child_transform[2][3]);
|
|
|
|
|
|
|
|
valid_parent_transform = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-25 06:43:03 +00:00
|
|
|
if (valid_parent_transform)
|
2005-04-23 11:36:44 +00:00
|
|
|
{
|
2009-02-25 06:43:03 +00:00
|
|
|
child->SetWorldScale(child_w_scale);
|
|
|
|
child->SetWorldPosition(child_w_pos);
|
|
|
|
child->SetWorldOrientation(child_w_rotation);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
child->SetWorldFromLocalTransform();
|
2005-04-23 11:36:44 +00:00
|
|
|
}
|
2009-05-03 22:29:00 +00:00
|
|
|
child->ClearModified();
|
|
|
|
// this node must always be updated, so reschedule it for next time
|
|
|
|
child->ActivateRecheduleUpdateCallback();
|
2005-04-23 11:36:44 +00:00
|
|
|
return valid_parent_transform;
|
|
|
|
}
|
|
|
|
|
|
|
|
SG_ParentRelation *
|
|
|
|
KX_BoneParentRelation::
|
|
|
|
NewCopy(
|
|
|
|
){
|
|
|
|
KX_BoneParentRelation* bone_parent = new KX_BoneParentRelation(m_bone);
|
|
|
|
return bone_parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
KX_BoneParentRelation::
|
|
|
|
~KX_BoneParentRelation(
|
|
|
|
){
|
|
|
|
//nothing to do
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
KX_BoneParentRelation::
|
|
|
|
KX_BoneParentRelation(Bone* bone
|
|
|
|
)
|
|
|
|
: m_bone(bone)
|
|
|
|
{
|
|
|
|
// nothing to do
|
|
|
|
}
|