cocos2d-x解析ccb及绑定到lua

cocos2d-x绑定ccb文件 首先,ccb文件是如何生成的,我就不多说了,大家可以搜下cocosbuilder,就能找的相关的教程,而通过cocosbuilder,我们可以省去了很多设计的麻烦,比如设计一个精灵的位置啥的,而通过cocosbuilder,我们可以把我们编码的重点放到具体的控制类上面,而不是在显示页面上下很大的功夫。闲话不多说,要想实现这些好处,首先确定你的Cocos2d-x的版本号,如果是2.0.4,那就用co 阅读详情

cocos2d-x解析ccb及绑定到lua

CCB_SELECTORRESOLVER_CCCONTROL_GLUE  SEL_MenuHandler SEL_CallFuncN SEL_CCControlHandler


onResolveCCBCCMenuItemSelector

CCB_SELECTORRESOLVER_CALLFUNC_GLUE 

分类: cocos2d-x   541人阅读  评论(0)  收藏  举报

要点一:C++解析ccb主要是这几个文件

CCBReader.h/cpp、CCNodeLoaderLibrary.cpp、CCNodeLoader.h/cpp等 

CCBReader文件中的CCBReader::readNodeGraph方法是读取ccbi的节点(该方法应该看懂),该方法做的事有

1.读取该节点类型(自定义类型这里用到了)  
[cpp]  view plain copy
  1. /* Read class name. */  
  2. std::string className = this->readCachedString();  

2.节点名字memberVarAssignmentName

[cpp]  view plain copy
  1. // Read assignment type and name  
  2. int memberVarAssignmentType = this->readInt(false);  
  3. std::string memberVarAssignmentName;  
  4. if(memberVarAssignmentType != kCCBTargetTypeNone) {  
  5.     memberVarAssignmentName = this->readCachedString();  
  6. }  
3.解析节点属性

[cpp]  view plain copy
  1. ...  
  2. CCNodeLoader *ccNodeLoader = this->mCCNodeLoaderLibrary->getCCNodeLoader(className.c_str());  
  3. if (! ccNodeLoader)  
  4. {  
  5.     CCLog("no corresponding node loader for %s", className.c_str());  
  6.     returnNULL;  
  7. }  
  8. CCNode *node = ccNodeLoader->loadCCNode(pParent, this);  
  9. ...  
  10. // Read properties  
  11. ccNodeLoader->parseProperties(node, pParent, this);  
从上面3中可以得知mCCNodeLoaderLibrary为CCNodeLoaderLibrary.cpp类实例对象getCCNodeLoader(className.c_str())为获取对应的节点类型Loader实例对象。

要点二:把CCB原有控件及事件绑定到Lua中(CCControlButton)

在CCNode * CCBReader::readNodeGraph(CCNode * pParent)方法最后加上以下代码

[cpp]  view plain copy
  1. //-------------------binding lua  
  2. if (memberVarAssignmentName != "") {  
  3.     ZGLuaUtils::bindCCBAssign(memberVarAssignmentName.c_str(), className.c_str(), node);  
  4. }  
  5. //-------------------binding lua------end  
我们看下C++中ZGLuaUtils类代码

[cpp]  view plain copy
  1. void ZGLuaUtils::bindCCBAssign(constchar* assignmentName, constchar *className, CCNode* node) {  
  2.      lua_State *L = ((CCLuaEngine*)CCScriptEngineManager::sharedManager()->getScriptEngine())->getLuaStack()->getLuaState();  
  3.      lua_getglobal(L, "GF_setCCBBind");    
  4.      /**//* Push PARAMETERS to STACK */  
  5.      tolua_pushstring(L, assignmentName);  
  6.      tolua_pushusertype(L, node, className);  
  7.      /**//* Call FUNCTION in LUA */   
  8.      int iError;   
  9.      iError = lua_pcall(L,    //VMachine    
  10.                         2,    //Argument Count    
  11.                         LUA_MULTRET,    //Return Value Count    
  12.                         0);    
  13.      if (iError)    
  14.      {    
  15.          constchar* errorInfo = lua_tostring(L, 1);  
  16.          CCLOG("CCBReader::bindCCBAssign pcall FAILED, %s, %d", errorInfo, iError);  
  17.      }    
  18.      /**//* Check Return Value Types */   
  19. }  

上面调用 了Lua中的全局函数也即C++调用Lua拉,查看ZGCCBSupport.lua文件

[plain]  view plain copy
  1. GV_CCBVars = nil  
  2. function GF_setCCBBind(nodeKey, node)  
  3.      CCBLOG ("binding.."..nodeKey)  
  4.      GV_CCBVars[nodeKey] = node  
  5. end  

lua中具体实现调用节点控件见LuaLayer.lua文件

[plain]  view plain copy
  1. function LuaLayer:createLayer()  
  2.      self:initForVars()  
  3.      self.layer = CCBReader:nodeGraphFromFile(self.ccbiName)  
  4.      self.ccbReader = GV_CCBReader  
  5.      self.ccbReader:retain()  
  6.      self:initUI()  
  7.      local function sceneEventHandler( eventType )  
  8.            if eventType == "enter" then  
  9.               self:onPreEnter()  
  10.            else  
  11.               self:onPreExit()  
  12.            end  
  13.      end  
  14.      self.layer:registerScriptHandler(sceneEventHandler)  
  15.      return self.layer  
  16. end  
  17. -- init ccb vars  
  18. function LuaLayer:initForVars( )   
  19.      self.ccbVars = {}  
  20.      self:initVarsForCCB()  
  21.      GV_CCBVars = self.ccbVars  
  22. end  
经过以上操作Lua中就能操作该节点拉!下面实现绑定控件的事件,也即注册控件事件 (如CCControlButton)
1)修改CCNodeLoader.h中的BlockCCControlData加上std::string mSelectorName;

[cpp]  view plain copy
  1. struct BlockCCControlData {  
  2.        SEL_CCControlHandler mSELCCControlHandler;  
  3.        CCObject * mTarget;  
  4.        std::string mSelectorName;  
  5.        int mControlEvents;  
  6. };  
2)修改CCNodeLoader.cpp函数parsePropTypeBlockCCControl

[cpp]  view plain copy
  1. BlockCCControlData * CCNodeLoader::parsePropTypeBlockCCControl(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader) {  
  2.       //-----直接传出带selectorName的BlockData  
  3.       std::string selectorName = pCCBReader->readCachedString();  
  4.       // 在返回之前,要把下面这个玩意读出来,否则的话会造成读取数据的错位  
  5.       pCCBReader->readInt(false);        // for int selectorTarget  
  6.       pCCBReader->readInt(false);         // for int controlEvents  
  7.       if(selectorName.length() > 0) {  
  8.            BlockCCControlData *blockData = newBlockCCControlData();  
  9.            blockData->mSelectorName = selectorName;  
  10.            return blockData;  
  11.       }  
  12.       //-----直接传出带selectorName的BlockData---end  
  13.       return NULL;  
  14. }  
3)修改CCControlLoader.cpp中的事件函数onHandlePropTypeBlockCCControl

[cpp]  view plain copy
  1. #include "CCControlLoader.h"  
  2. #include "ZGLuaUtils.h"  
  3. void CCControlLoader::onHandlePropTypeBlockCCControl(CCNode * pNode, CCNode * pParent, constchar * pPropertyName, BlockCCControlData * pBlockCCControlData, CCBReader * pCCBReader) {  
  4.      ZGLuaUtils::bindCCBFunctionForCCControl(pBlockCCControlData->mSelectorName.c_str(), "CCControlButton", pNode, false);  
  5. }  
我们看下C++中ZGLuaUtils类代码

[cpp]  view plain copy
  1. void ZGLuaUtils::bindCCBFunctionForCCControl(constchar *selectorName, constchar *className, cocos2d::CCNode *node, bool isRegistForTouch) {  
  2.      lua_State *L = getLuaState();  
  3.      lua_getglobal(L, "GF_setCCBCallback");  
  4.      /**//* Push PARAMETERS to STACK */  
  5.      tolua_pushusertype(L, node, className);  
  6.      tolua_pushstring(L, selectorName);  
  7.      tolua_pushboolean(L, isRegistForTouch);  
  8.      /**//* Call FUNCTION in LUA */  
  9.      int iError;  
  10.      iError = lua_pcall(L,    //VMachine  
  11.                         3,    //Argument Count  
  12.                         LUA_MULTRET,    //Return Value Count  
  13.                         0);  
  14.      if (iError)  
  15.      {  
  16.           constchar* errorInfo = lua_tostring(L, 1);  
  17.           CCLOG("CCBReader::bindCCBFunctionForCCControl pcall FAILED, %s, %d", errorInfo, iError);  
  18.      }  
  19.      /**//* Check Return Value Types */  
  20. }  
上面调用 了Lua中的全局函数也即C++调用Lua拉,查看ZGCCBSupport.lua文件
[plain]  view plain copy
  1. function GF_setCCBCallback(node, callbackKey, isRegistForTouch)  
  2.      CCBLOG ("binding callback.."..callbackKey)  
  3.      local value = GV_CCBVars[callbackKey]  
  4.      if isRegistForTouch then  
  5.      -- registe for CCControlButton and others  
  6.           node:registerScriptTouchHandler(GV_CCBVars[callbackKey])  
  7.      else  
  8.      -- registe for CCMenuItems  
  9.           GF_dump(node, "node")  
  10.           GF_dump(callbackKey, "callbackKey")  
  11.           node:registerScriptTapHandler(GV_CCBVars[callbackKey])  
  12.      end  
  13. end  
上面取得了CCBI中事件名称对应到Lua中相同名称的方法再注册节点脚本事件,但是上面貌似完美但是CCControlButton默认没有registerScriptTapHandler 方法,所以node:registerScriptTapHandler(GV_CCBVars[callbackKey])还是有问题所以还要第4步
4)修改CCControlButton.h文件增加以下代码
[cpp]  view plain copy
  1. // add lua touch support  
  2. protected:  
  3.     int m_nScriptTapHandler;  
  4. public:  
  5.     virtualvoid registerScriptTapHandler(int nHandler);  
  6.     virtualvoid unregisterScriptTapHandler(void);  
  7.     int getScriptTapHandler() { returnm_nScriptTapHandler; };  
  8. / add lua touch support  
修改CCControlButton.cpp文件,增加以下代码
[cpp]  view plain copy
  1. #include "script_support/CCScriptSupport.h"  
  2. #include "ZGLuaUtils.h"  
  3. voidCCControlButton::registerScriptTapHandler(int nHandler)  
  4. {       
  5.      unregisterScriptTapHandler();  
  6.      m_nScriptTapHandler = nHandler;  
  7.      LUALOG("[LUA] Add CCMenuItem script handler: %d", m_nScriptTapHandler);  
  8. }  
  9.   
  10. voidCCControlButton::unregisterScriptTapHandler(void)  
  11. {  
  12.      if (m_nScriptTapHandler)  
  13.      {  
  14.          CCScriptEngineManager::sharedManager()->getScriptEngine()->removeScriptHandler(m_nScriptTapHandler);  
  15.          LUALOG("[LUA] Remove CCMenuItem script handler: %d", m_nScriptTapHandler);  
  16.          m_nScriptTapHandler = 0;  
  17.      }  
  18. }   
5)修改ZGToLua 加上以上二个方法以便在Lua中能访问(不能是tolua工具生成,参数是句柄而不是真正意义上的int)
说明:如果Lua在C++中注册回调函数。也即向C++的函数传的参是Lua函数,但C++函数形参却是int型(Lua函数的标号即句柄),在这里程序启动后,每注册一个回调则回调的函数标识是加1的,即句柄是自增长的int型 
上面已经实现在Lua中绑定事件即Lua中注册事件但还要在Lua中实现响应事件
6)修改CCControlButton.cpp文件
[cpp]  view plain copy
  1.    /**(i)在 CCControlButton::~CCControlButton()方法体内加上unregisterScriptTapHandler(); 
  2.     **(ii)在 ccTouchEnded方法实现调用注册的事件即加上以下代码 
  3.     **if (m_nScriptTapHandler != 0) { 
  4.     **     ZGLuaUtils::getLuaEngine()->executeControlButtonEvent(this); 
  5.     **} 
  6.     **/   
  7.    
  8.     void CCControlButton::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent)  
  9.     {  
  10.          m_isPushed = false;  
  11.          setHighlighted(false);  
  12.       
  13.       
  14.          if (isTouchInside(pTouch))  
  15.          {  
  16.              sendActionsForControlEvents(CCControlEventTouchUpInside);  
  17.              if (m_nScriptTapHandler != 0) {  
  18.                  ZGLuaUtils::getLuaEngine()->executeControlButtonEvent(this);  
  19.              }  
  20.          }  
  21.          else  
  22.          {  
  23.              sendActionsForControlEvents(CCControlEventTouchUpOutside);          
  24.          }  
  25.     }  
7)修改CCLuaEngin.h/ccp 
[cpp]  view plain copy
  1. //修改.h文件增加以下代码  
  2. #include "cocos-ext.h"  
  3. virtual int executeControlButtonEvent(cocos2d::extension::CCControlButton *controlButton);  
  4.    
  5. //修改.cpp文件增加以下代码  
  6. int CCLuaEngine::executeControlButtonEvent(cocos2d::extension::CCControlButton *controlButton) {  
  7.     int nHandler = controlButton->getScriptTapHandler();  
  8.     if (!nHandler) return0;  
  9.   
  10.     m_stack->pushInt(controlButton->getTag());  
  11.     m_stack->pushCCObject(controlButton, "CCControlButton");  
  12.     returnm_stack->executeFunctionByHandler(nHandler, 2);  
  13. }  
要点三:把CCB自定义控件及事件绑定到Lua中(CCScrollLayerButton)
 1)CCLuaEngin.h/ccp 其它一些控件类会调用CCLuaEngin中的一些方法,而本类又是C++调用Lua堆栈,用处是处理控件和控件的事件响应
[cpp]  view plain copy
  1. //修改.h文件,加上以下代码  
  2. #include "CCScrollLayerButton.h"  
  3. virtual int executeScrollLayerButtonEvent(CCScrollLayerButton *scrollLayerButton);  
[cpp]  view plain copy
  1. //修改.cpp文件,加上以下代码  
  2. int CCLuaEngine::executeScrollLayerButtonEvent(CCScrollLayerButton *scrollLayerButton) {  
  3.     int nHandle = scrollLayerButton->getScriptTapHandler();  
  4.     if (!nHandle) return 0;  
  5.     m_stack->pushInt(scrollLayerButton->getTag());  
  6.     m_stack->pushCCObject(scrollLayerButton, "CCScrollLayerButton");  
  7.     return m_stack->executeFunctionByHandler(nHandle, 2);  
  8. }  
2)修改CCScrollLayerButton.h/cpp 。跟CCControlButton一样加上注册事件及删除事件及取得回调句柄
3)修改CCBReader.cpp  CCNode * CCBReader::readNodeGraph(CCNode * pParent)方法最后加上以下代码
[cpp]  view plain copy
  1. //-------------------binding lua  
  2. if (memberVarAssignmentName != "") {  
  3.      //CCScrollLayerButton特殊处理  
  4.      if (strcmp(className.c_str(), "CCScrollLayerButton") == 0) {  
  5.           vector<string> stringVec;  
  6.           ZGStringUtils::splitString(memberVarAssignmentName, "@", stringVec);  
  7.           string member = stringVec[0];  
  8.           string function = stringVec[1];  
  9.           //bind var name  
  10.           ZGLuaUtils::bindCCBAssign(member.c_str(), "CCScrollLayerButton", node);  
  11.           //bind function  
  12.           ZGLuaUtils::bindCCBFunctionForCCControl(function.c_str(), "CCScrollLayerButton", node, false);  
  13.      }else{  
  14.           ZGLuaUtils::bindCCBAssign(memberVarAssignmentName.c_str(), className.c_str(), node);  
  15.      }  
  16. }  
  17. //-------------------binding lua------end  
3)修改ZGToLua.cpp

bindCCBFunctionForCCControl方法调用lua中的方法ZGCCBSupport.lua 文件中的GF_setCCBCallback方法,而方法又调用了节点的node:registerScriptTapHandler(GV_CCBVars[callbackKey]), 因为Lua调用c++代码且是自定义控件所以ZGToLua中加入CCScrollLayerButton的registerScriptTapHandler方法
4)但是由上面要点一第3小点可得CCBReader还会解析控件的属性所以必须加上以下代码,当然也要在项目上加上CCScrollLayerButtonLoader.h文件

[cpp]  view plain copy
  1. #include "CCScrollLayerButtonLoader.h"  
  2.   
  3.  voidCCNodeLoaderLibrary::registerDefaultCCNodeLoaders() {  
  4.      this->registerCCNodeLoader("CCScrollLayerButton", CCScrollLayerButtonLoader::loader());  
  5.  }
自己毕设的Cocos Creator小介绍 Google开发专家带你学 AI:入门到实战(Keras/Tensorflow)(附源码) 小介绍软件小介绍Cocos Creator技术特征物理引擎技术使用的语言 参考部分文章 软件小介绍 Cocos Creator是用于开发和存储Cocos2d-x引擎的且用JavaScript实现以及快速游戏开发所需的各种图形界面和工具的完美游戏开发解决方案。Cocos Creator的编辑器是一个... 阅读详情

相关推荐

CocosBuilder与Lua结合:高效构建Cocos2d-x游戏UI的完整指南

在游戏开发中,UI(用户界面)的构建与逻辑分离是提升开发效率的关键。其核心原理在于将视觉表现与程序逻辑解耦,通过数据驱动的方式实现界面动态更新。这项技术的价值在于大幅降低美术与程序间的沟通成本,支持快速迭代和热更新,尤其适合UI复杂、交互频繁的移动游戏项目。具体到Cocos2d-x引擎,结合Lua脚本语言与CocosBuilder可视化编辑器,形成了一套成熟的解决方案:CocosBuilder负责编辑场景布局并生成.ccbi资源文件,定义了节点的层级、属性和动画时间线;Lua则通过CCBReader加载该文

diandingyin9417的博客 410

cocos2d 解密ccbi_cocosBuilder使用总结

原创,转载请注明出处!基本流程>=-. 准备工作#. 把一个项目场景相关的,相对独立(别的场景用不到)的碎图,用TexturePack拼接成大的png图片文件及plist数据字处理文件#. 多场景公用的图,可以以单图的形式存在。但上传资源的时候,注意他们只能出现一次>=-. 新建工程#. 删除新工程时,自带着ccb文件,及相关资源文件, (在Finder下删除 cocosBuilder...

weixin_39857792的博客 561

cocos2d-x绑定ccb文件个人实现的例子

cocos2d-x绑定ccb文件个人实现的例子,在博客中有相关的描述

cocos2dx 读取ccb时崩溃的问题

在工作当中,总是会出现莫名奇妙的问题,读取一个ccb就崩溃了,常常让人很

superxsw的专栏 993

通过ccb(CocosBuilder)文件生成cocos2dx代码

在C++下使用ccb,绑定调用,成员变量,让人头疼又容易犯错。 自己用pythong写了个小程序,通过ccb文件直接生成C++代码 详细见我的blog http://blog.youkuaiyun.com/listlike

cocos2dx中lua扩展(ccb执行完回调函数扩展)

cocos2dx-3.7在lua中ccb动画完成回调setAnimationCompletedCallback修改

(三)cocos2d-x中通过lua脚本使用ccbi

(三)cocos2d-x中通过lua脚本使用ccbi  2013-11-04 10:25:04|  分类: cocos2d-x |  标签:cocos2d-x  lua  ccbi  |字号大中小订阅 1>修改bool AppDelegate::applicationDidFinishLaunching()文件。 增加头文件 #incl

我的 1267

LVDS信号调试必备:5分钟搞懂Xilinx IDELAYE3的TIME模式校准

本文深入解析了在Xilinx Ultrascale系列FPGA中调试LVDS信号时,如何正确使用IDELAYE3的TIME模式进行精密延迟校准。文章重点阐述了IDELAYCTRL、EN_VTC管脚与校准状态机的协同工作机制,揭秘了内置自校准(BISC)中Align_Delay的影响,并提供了从抽头值计算到实际眼图优化的完整实战方案,帮助工程师快速解决高速接口的时序问题。

joy55的博客 216

如何在cocos2d c++代码中调用lua以及探究

如何在cocos2d c++代码中调用lua   在AppDelegate 中加入了 #include"Lua_extensions_CCB.h" #include"CCLuaEngine.h" #include"Lua_web_socket.h"   查到代码加载lua脚步引擎 官方原话注册引擎 CCLuaEngine*pEngine=CCLuaEngine::defaul

u012840010的专栏 2618

zynq 7010/020 AMP双核通信-Vitis2023/2024

在platform cpu1设置中添加;注意value中使用空格分开程序思路:比较简单。

weixin_43310175的博客 916

物理机centos7系统重启后直接进入dracut

Warning: /dev/centos/root does not exist Warning: /dev/mapper/centos-root does not exist 在shell命令行执行以下: dracut:/# lvm vgscan dracut:/# lvm vgchange -ay dracut:/# exit 之后可以正常进入系统(测试正常)。 但是重启之后依然会进入dracut模式,永久解决如下: 查看kernel文件 [root@ecs ~]# ls -ltrh /boot

魏志标的博客 1万+

cocosBuilder + cocos2d-x-LuaProxy 解决在CCB编辑器中的label的多国语言文本替换

cocosBuilder + cocos2d-x-LuaProxy 解决在CCB编辑器中的label的多国语言文本替换 我们使用cocos2d-x + lua来开发游戏,同时使用cocosBuilder作为UI编辑器。在UI中需要放置label,例如CCLabelTTF,但是在编辑器中我们无法给他设定不同语言的文本。由于我们使用的是Lua,使用cocos2d-x-LuaProxy这个库来

聚焦游戏和图形引擎开发技术 6489

Doris存储层设计介绍2——数据写入及删除流程

Doris存储层设计介绍2——数据写入及删除流程

爱吃辣条的博客 4585

cocos2dx-3.7 lua绑定部分学习记录

cocos2dx-3.7 lua绑定部分学习笔记

芈少的专栏 1435

Vivado里LDPC IP核怎么配?手把手教你从6144bit数据到完整参数设置

本文详细介绍了在Vivado中配置LDPC IP核的完整流程,从6144bit数据的参数计算到实际IP核设置。通过分析基本图选择、扩展因子计算和移位参数确定等关键步骤,帮助工程师高效完成LDPC编译码的硬件实现,并提供了时序控制、仿真验证和性能优化的实用技巧。

weixin_30352645的博客 517

【机器学习入门】1.4 吃透这些基本术语,才算真正入门

本文通过"挑西瓜"的生活案例,形象解释了机器学习的基本术语。样本对应单个西瓜,特征如色泽、根蒂等是观察维度,特征值是其具体表现,标签是西瓜的好坏判断。数据集是样本集合,特征向量是样本的数学表达,特征空间是所有可能的样本组合。文章强调数据集需划分为训练集、验证集和测试集,以评估模型的泛化能力。最后整理了术语对照表,并解答了常见问题。这些基础概念是理解机器学习的关键,建议读者重点掌握。

国科大硕士在读,分享Python/GEE/Matlab/R专业代码实践,涵盖数据分析、算法开发与应用技巧等,以代码会友。 654

cocos2d 解密ccbi_cocos2d-x lua分支加载ccbi文件

cocos2d-x lua的分支竟然没有提供扩展包里面的类,苦大了我们啊,经过各种尝试摸索,终于OK不完美处就是留下一些使用的潜规则:1、所有的控件名字不得重复(要根据控件名字注册lua的回调方法)2、如果是成员变量名字格式为 空间名-空间类型 比如:second_text-CCLabelTTF3、点击事件的lua回调方法名为 控件名_onClicked 比如:button_onClicked4、...

weixin_39925413的博客 268

Linux系统安全学习手册

Linux反弹shell Linux系统应急响应 Linux服务器安全加固 Linux下的用户、组和权限 Linux中的gcc Linux中su和sudo的用法和区别 Linux系统python2与python3共存 Linux中grep工具的使用 Linux中环境变量的设置 Linux中常见的150个命令(干货) Linux中编写Shell脚本 LNMP环境搭建Wordpress博客 LAMP环境搭建一个Discuz论坛 Linux运维比较常用的一些脚本 Linux系统中安装软

谢公子的博客 7532

cocos2d-x+lua+cocosbuilder+luaproxy开发中遇到的读取子node以及事件绑定问题

转自:http://blog.youkuaiyun.com/zhuangyou123/article/details/8954758 1,在用luaproxy开发时,会操作node里的menuItem,controlbutton,并实现在lua里实现其对应的selector。遇到的问题如下 一,通过node名字读取子node的问题 建立一个cocos2d-x工程,把luaproxy源码加进去,在lua里

mergerly的专栏 2453

13、7自由度机械臂混合逆运动学算法解析

本文介绍了一种针对7自由度机械臂的混合逆运动学算法,通过引入额外参数Φ解决冗余自由度问题,并实现了避障、避免关节超限和扩大工作空间。该方法采用解析逆运动学求解策略,克服了机械臂在奇异位姿时的配置不连续性问题。通过对比实验验证了该算法在腕部关节角度连续性和位姿可达性方面的优越性,同时结合躯干逆运动学显著扩展了机械臂的工作空间。

rgv23456789的博客 236

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

cocos2d-x lua分支加载ccbi文件

cocos2d-x lua的分支竟然没有提供扩展包里面的类,苦大了我们啊,经过各种尝试摸索,终于OKlua分支加载ccbi文件" alt="cocos2d-x lua分支加载ccbi文件" src="http://www.sinaimg.cn/uc/myshow/blog/misc/gif/E___6715EN00SIGG.gif" type="face"> 不完美处就是留下一些使用的潜

孙少磊的专栏 2510

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

cocosbulider与cocos2d-x项目的绑定问题

从昨天折腾到今天,也看了好多网上的材料,但是好像都不成功。总是提示没有实现接口的纯虚函数。。。但是确实都继承了。最终参照cocos2d-x的样例工程发现,是函数的参数类型有问题,cocos2d-x的版本里是const char* 而我看的教程里是CCstring- -然后不报错可以运行了,发现读不到ccbi文件,检查文件添加没有问题,看log发现是cocosbuilder的版...

weixin_33696106的博客 109

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

上一篇: cocos2d函数
下一篇: Visual Assist X 10.6.1837.0 Cracked
linuxheik
博客等级 码龄15年 865粉丝 135原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值