想了解Scene,了解其数据结构是必不可少的。Scene中有种对象,一个种是Node,它以一种树形结构保存场景中所有节点的当前状态(有位置缩放等数据指标)。另一种是Entity,它挂接在Node上,采用这种方式使得场景的内容的设计变的灵活。
Node:
1.构造
Node::Node(const String& name)
:
mParent(0), // 父
mNeedParentUpdate(false), // 如果为true,则模型的转换继承与父
mNeedChildUpdate(false), // 如果为true,所有的孩子需要更新(怀疑)
mParentNotified(false), // true表示父通知更改
mQueuedForUpdate(false), // true表示节点在排队等待更新
mName(name),
mOrientation(Quaternion::IDENTITY), // 这是一个四元数,存储它与父的相对位置
mPosition(Vector3::ZERO), // 相对于父节点的位置
mScale(Vector3::UNIT_SCALE), // 缩放比例
mInheritOrientation(true), // true 方向继承与父
mInheritScale(true), // 缩放继承与父
mDerivedOrientation(Quaternion::IDENTITY), // Derived 前缀的这三个参数表示的是增量
mDerivedPosition(Vector3::ZERO), // ,这个增量受到父亲和自己累加的影响
mDerivedScale(Vector3::UNIT_SCALE),
mInitialPosition(Vector3::ZERO), // Initial为前缀的三个参数,是为关键帧动画服务的。
mInitialOrientation(Quaternion::IDENTITY),
mInitialScale(Vector3::UNIT_SCALE),
mCachedTransformOutOfDate(true), // 暂时不明白
mListener(0),
mDebug(0)
{
needUpdate();
}
2.createChild:创建了孩纸,自己就是父亲了,父子关系也建立了。
Node* Node::createChild(const String& name, const Vector3& inTranslate, const Quaternion& inRotate)
{
Node* newNode = createChildImpl(name);
newNode->translate(inTranslate);
newNode->rotate(inRotate);
this->addChild(newNode);
return newNode;
}
createChildImpl是虚函数,子类里面研究它。translate这名字取的有点蛋疼啊,明明是确定位置。rotate旋转和缩放。
translate :
void Node::translate(const Vector3& d, TransformSpace relativeTo)
{
switch(relativeTo)
{
case TS_LOCAL:
// position is relative to parent so transform downwards
mPosition += mOrientation * d;
break;
case TS_WORLD:
// position is relative to parent so transform upwards
if (mParent)
{
mPosition += (mParent->_getDerivedOrientation().Inverse() * d)
/ mParent->_getDerivedScale();
}
else
{
mPosition += d;
}
break;
case TS_PARENT:
mPosition += d;
break;
}
needUpdate();
}
从头到尾只看到了对位置的改变mPosition
rotate:
rotate(Vector3::UNIT_Y, angle, relativeTo); //调用
v