在cocos2dx中,rmature的骨骼上能够绑定另外的armature,在我的项目中使用了该功能来完毕骑乘功能,可是在使用过程发现了例如以下的bug,特写在这里做一下记录。

</span>

首先说说cocos2dx的代码。在cocos2dx的骨骼的update函数中有例如以下代码用于骨骼的矩阵更新。

    if (_boneTransformDirty)
{
if (_dataVersion >= VERSION_COMBINED)
{
TransformHelp::nodeConcat(*_tweenData, *_boneData);
_tweenData->scaleX -= 1;
_tweenData->scaleY -= 1;
}
<span style="white-space:pre"> </span>//(1)
_worldInfo->copy(_tweenData); _worldInfo->x = _tweenData->x + _position.x;
_worldInfo->y = _tweenData->y + _position.y;
_worldInfo->scaleX = _tweenData->scaleX * _scaleX;
_worldInfo->scaleY = _tweenData->scaleY * _scaleY;
_worldInfo->skewX = _tweenData->skewX + _skewX + CC_DEGREES_TO_RADIANS(_rotationZ_X);
_worldInfo->skewY = _tweenData->skewY + _skewY - CC_DEGREES_TO_RADIANS(_rotationZ_Y);
<span style="white-space:pre"> </span>//(2)
if(_parentBone)
{
applyParentTransform(_parentBone);
}
else
{
if (_armatureParentBone) //(3)
{
applyParentTransform(_armatureParentBone);
}
}
<span style="white-space:pre"> </span>//(4)
TransformHelp::nodeToMatrix(*_worldInfo, _worldTransform);
<span style="white-space:pre"> </span>//(5)
if (_armatureParentBone)
{
_worldTransform = TransformConcat(_worldTransform, _armature->getNodeToParentTransform());
}
}

在上面的代码中,

1、程序首先计算了bone本身的变换信息,

2、然后在第二步。假设骨骼有父骨骼,则乘以父骨骼的变换信息。假设没有父骨骼可是该骨骼所在的armature有父骨骼(即armayure被作为了其它armature的bone的display。这时就先乘以armature的父骨骼的变换信息。

3、第四步将worldinfo转换为矩阵。

4、第五步计算再将bone所在的armature的变换信息应用于变换矩阵上,得到终于的骨骼的矩阵信息。

问题就出在上面代码标号为3的地方,我们都知道矩阵变换是不满足交换定律的(当然少数情况除外)。

可是骨骼矩阵之间的关系应该例如以下:

parentArmature-------armatureParentBone------------armature------------bone

或者是armature-----------。。。。------parentBone-----bone  中间省略一些parentBone。

因此在上面的代码中。假设不包括armatureParentBone,那么矩阵变换关系是bone * parentBone *...*parentBone,结果正确。即没有armature作为bone的render。

可是假设有armature作为bone的render,那么关系是bone*armatureParentBone*armature,那么在矩阵变换的顺序上就出现了问题。

因此我将代码做了一些改动例如以下:

  //if it is a armature display render node, apply transform to armature.
BaseData worldInfo;
if (!_parentBone && _armatureParentBone)
{ //bone * armature
TransformHelp::nodeToMatrix(*_worldInfo, _worldTransform);
_worldTransform = TransformConcat( _armature->getNodeToParentTransform(), _worldTransform);
TransformHelp::matrixToNode(_worldTransform, worldInfo);
} else {
worldInfo = *_worldInfo;
} BaseData cache = *_worldInfo;
*_worldInfo = worldInfo;
//apply to parent bone.
if(_parentBone) //bone * parentbone
{
applyParentTransform(_parentBone);
} else { // * armatureParentBone
if (_armatureParentBone)
{
applyParentTransform(_armatureParentBone);
}
}
TransformHelp::nodeToMatrix(*_worldInfo, _worldTransform);

上面的代码中,假设bone没有parentBone而且有armatureParentBone。则先乘以armature的矩阵。

假设没有 则直接乘以parentBone的变换。

最后假设有armatureparentBone。还的乘以parenBone的变换。

cocos2d的armature绑定到其它armature骨骼上的bug的更多相关文章

  1. 把多个JavaScript函数绑定到onload事件处理函数上

    为了让函数只在页面加载完毕后才得到执行,我们会把函数绑定到onload事件上: window.onload = userFunction 但如果有两个函数:firstFunction() 和 seco ...

  2. 使用MethodType函数将方法绑定到类或实例上

    在开始正文之前,需要了解下Python的绑定方法(bound method)和非绑定方法. 简单做个测试: 定义一个类,类中由实例方法.静态方法和类方法. class ClassA: def inst ...

  3. linux 将进程或者线程绑定到指定的cpu上

    基本概念 cpu亲和性(affinity) CPU的亲和性, 就是进程要在指定的 CPU 上尽量长时间地运行而不被迁移到其他处理器,也称为CPU关联性:再简单的点的描述就将指定的进程或线程绑定到相应的 ...

  4. jQ给下拉框绑定事件,为什么要绑定在框(select标签)上,而不是绑定在选项(option标签)上

    这是我在学习锋利的 jquery 书中 5.1.4 的代码时遇到的一个小问题,源代码如下: <head> <style type="text/css"> * ...

  5. 外部配置属性值是如何被绑定到XxxProperties类属性上的?--SpringBoot源码(五)

    注:该源码分析对应SpringBoot版本为2.1.0.RELEASE 1 前言 本篇接 SpringBoot是如何实现自动配置的?--SpringBoot源码(四) 温故而知新,我们来简单回顾一下上 ...

  6. 利刃 MVVMLight 5:绑定在表单验证上的应用

    表单验证是MVVM体系中的重要一块.而绑定除了推动 Model-View-ViewModel (MVVM) 模式松散耦合 逻辑.数据 和 UI定义 的关系之外,还为业务数据验证方案提供强大而灵活的支持 ...

  7. asp.net core mvc中如何把二级域名绑定到特定的控制器上

    由于公司的工作安排,一直在研究其他技术,所以一直没时间更新博客,今天终于可以停下手头的事情,写一些新内容了. 应用场景:企业门户网站会根据内容不同,设置不同的板块,如新浪有体育,娱乐频道,等等.有的情 ...

  8. 获得touch事件,jquery绑定事件监听器,ios设备上打开touch状态以响应focus,active等伪类

    2. 默认的监听方式 document.addEventListener('touchstart', function(){ alert('hello'); }, false); 使用jquery时 ...

  9. 如何在双向绑定的Image控件上绘制自定义标记(wpf)

    我们的需求是什么? 答:需要在图片上增加一些自定义标记,例如:2个图片对比时,对相同区域进行高亮. 先上效果图: 设计思路 1.概述 1.通过TargeUpdated事件,重新绘制图片进行替换. 2. ...

随机推荐

  1. java设计模式之代理模式模式总结

    定义:代理模式这种设计模式是一种使用代理对象来执行目标对象的方法并在代理对象中增强目标对象方法的一种设计模式. 解读定义: 1.代理对象和目标对象有共同的接口: 2.使用代理对象执行目标对象中的方法: ...

  2. MySQL 8.*版本 修改root密码

    MySQL .*版本 修改root密码 查看版本:select version() from dual; 1.6. 登录mysql: 登录mysql:(因为之前没设置密码,所以密码为空,不用输入密码, ...

  3. 系统异常 NSException.h

    FOUNDATION_EXPORT NSExceptionName const NSGenericException; FOUNDATION_EXPORT NSExceptionName const ...

  4. C# 字符串每隔两个 提取

    private void button3_Click(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); str ...

  5. 并发编程学习笔记(11)----FutureTask的使用及实现

    1. Future的使用 Future模式解决的问题是.在实际的运用场景中,可能某一个任务执行起来非常耗时,如果我们线程一直等着该任务执行完成再去执行其他的代码,就会损耗很大的性能,而Future接口 ...

  6. jquery onclick 问题

    var str = ''; for(var i = 0;i<data.list.length;i++){ str += "<tr><td>" + (i ...

  7. Linux---文件目录管理

    1. Linux文件目录架构 Linux的目录结构与win的目录有很大不同,首先,没有盘符的概念:然后Linux使用斜杠/标识目录,Linux首先建立一个根目录,然后将其他文件系统挂载到这个目录下. ...

  8. java导出word的6种方式(转发)

    来自: http://www.cnblogs.com/lcngu/p/5247179.html 最近做的项目,需要将一些信息导出到word中.在网上找了好多解决方案,现在将这几天的总结分享一下. 目前 ...

  9. 如何用纯 CSS 创作一个按钮文字滑动特效

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. 在线预览 https://codepen.io/zhang-ou/pen/GdpPLE 可交互视频教 ...

  10. 利用 Python 批量修改文件名

    开发的第一步,首先得熟悉脚本中使用的模块函数,废话不多说,开干! 1 函数介绍 1.1 os 模块 (1)os.lisdir() >>> import os >>> ...