PageRenderTime 19ms CodeModel.GetById 12ms app.highlight 5ms RepoModel.GetById 0ms app.codeStats 0ms

/Irrlicht/CBoneSceneNode.cpp

http://myjeh.googlecode.com/
C++ | 129 lines | 76 code | 32 blank | 21 comment | 7 complexity | 5d3939417df7dd340601d4879073c917 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-2.0
  1// Copyright (C) 2002-2010 Nikolaus Gebhardt
  2// This file is part of the "Irrlicht Engine".
  3// For conditions of distribution and use, see copyright notice in irrlicht.h
  4
  5#include "IrrCompileConfig.h"
  6#ifdef _IRR_COMPILE_WITH_SKINNED_MESH_SUPPORT_
  7
  8#include "CBoneSceneNode.h"
  9
 10namespace irr
 11{
 12namespace scene
 13{
 14
 15//! constructor
 16CBoneSceneNode::CBoneSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id,
 17	u32 boneIndex, const c8* boneName)
 18: IBoneSceneNode(parent, mgr, id), BoneIndex(boneIndex),
 19	AnimationMode(EBAM_AUTOMATIC), SkinningSpace(EBSS_LOCAL)
 20{
 21	#ifdef _DEBUG
 22	setDebugName("CBoneSceneNode");
 23	#endif
 24	setName(boneName);
 25}
 26
 27
 28//! Returns the index of the bone
 29u32 CBoneSceneNode::getBoneIndex() const
 30{
 31	return BoneIndex;
 32}
 33
 34
 35//! Sets the animation mode of the bone. Returns true if successful.
 36bool CBoneSceneNode::setAnimationMode(E_BONE_ANIMATION_MODE mode)
 37{
 38	AnimationMode = mode;
 39	return true;
 40}
 41
 42
 43//! Gets the current animation mode of the bone
 44E_BONE_ANIMATION_MODE CBoneSceneNode::getAnimationMode() const
 45{
 46	return AnimationMode;
 47}
 48
 49
 50//! returns the axis aligned bounding box of this node
 51const core::aabbox3d<f32>& CBoneSceneNode::getBoundingBox() const
 52{
 53	return Box;
 54}
 55
 56
 57/*
 58//! Returns the relative transformation of the scene node.
 59core::matrix4 CBoneSceneNode::getRelativeTransformation() const
 60{
 61	return core::matrix4(); // RelativeTransformation;
 62}
 63*/
 64
 65
 66void CBoneSceneNode::OnAnimate(u32 timeMs)
 67{
 68	if (IsVisible)
 69	{
 70		// animate this node with all animators
 71
 72		ISceneNodeAnimatorList::Iterator ait = Animators.begin();
 73		for (; ait != Animators.end(); ++ait)
 74			(*ait)->animateNode(this, timeMs);
 75
 76		// update absolute position
 77		//updateAbsolutePosition();
 78
 79		// perform the post render process on all children
 80		ISceneNodeList::Iterator it = Children.begin();
 81		for (; it != Children.end(); ++it)
 82			(*it)->OnAnimate(timeMs);
 83	}
 84}
 85
 86
 87void CBoneSceneNode::helper_updateAbsolutePositionOfAllChildren(ISceneNode *Node)
 88{
 89	Node->updateAbsolutePosition();
 90
 91	ISceneNodeList::ConstIterator it = Node->getChildren().begin();
 92	for (; it != Node->getChildren().end(); ++it)
 93	{
 94		helper_updateAbsolutePositionOfAllChildren( (*it) );
 95	}
 96}
 97
 98
 99void CBoneSceneNode::updateAbsolutePositionOfAllChildren()
100{
101	helper_updateAbsolutePositionOfAllChildren( this );
102}
103
104
105void CBoneSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
106{
107	IBoneSceneNode::serializeAttributes(out, options);
108	out->addInt("BoneIndex", BoneIndex);
109	out->addEnum("AnimationMode", AnimationMode, BoneAnimationModeNames);
110}
111
112
113void CBoneSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
114{
115	BoneIndex = in->getAttributeAsInt("BoneIndex");
116	AnimationMode = (E_BONE_ANIMATION_MODE)in->getAttributeAsEnumeration("AnimationMode", BoneAnimationModeNames);
117	// for legacy files (before 1.5)
118	const core::stringc boneName = in->getAttributeAsString("BoneName");
119	setName(boneName);
120	IBoneSceneNode::deserializeAttributes(in, options);
121	// TODO: add/replace bone in parent with bone from mesh
122}
123
124
125} // namespace scene
126} // namespace irr
127
128#endif
129