- 浏览: 643924 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
lizaochengwen:
网络请求碰到的中文乱码使用encodeURL吧- (NSStr ...
iPhone开发/iPad开发 中文乱码问题 -
hhb19900618:
还是没弄懂怎么解决了中文乱码? 正确代码能重写贴出吗
iPhone开发/iPad开发 中文乱码问题 -
zhengjj_2009:
我的理解是讲ipa文件解压缩之后再重新打包,已经破坏了签名,所 ...
xcodebuild和xcrun实现自动打包iOS应用程序 -
zhengjj_2009:
我参考你的“ 从ipa格式的母包生成其它渠道包的shell脚本 ...
xcodebuild和xcrun实现自动打包iOS应用程序 -
同一片天空:
问题果然解决了
iOS 搭建 XMPP实现环境
如果你想要在iOS程序中使用3D模型,一般来说你有3个选择:使用OpenGL ES,或者使用其他的游戏引擎:如Unity 3D,最后就是我认为最好的方法:使用Cocos3D。
为什么我觉得Cocos3D是iOS上最好的使用3D模型的方法呢?首先是因为Cocos3D是cocos2D的拓展集,完全嵌入在Xcode中,更加好控制并且可以和iOS应用结合。其次还因为Cocos3D较OpenGL ES来说比较简单,使用的方法也比较高级。
这篇教程我们主要讲解Cocos3D的一些基础的内容,比如说如何设置灯光摄像机,如何绘制物体,如何设置物体运动,还有如何进行用户交互。
如何安装使用
首先你要先下载哦,要用mac的还用我说嘛亲?下载地址在这里。
如果你感兴趣,在下载站点的旁边有一个引擎作者写的详细说明,有兴趣也可以看看,还有翻译的哦亲:
作者说明 —— 翻译
至于安装,你可以看看Readme,很简单的,首先把cocos2d放在cocos3d的目录里,之后输入命令cd,进入cocos3d的文件夹,运行命令:
安装程序会搞定一切。
构建3D世界
首先打开Xcode,新建一个Cocos3d的项目,打开直接看class文件夹里的内容吧,其他的基本上都是资源文件。
一个新建的cocos3d项目本身就带有一个3d的自旋转的Hello,World模型,我们要知道它是如何构建的,只需要查看其代码就可以,找到下面的代码:
其实如果看过我之前的教程并且有一些编程基础的人都可以很容易的看懂这些代码,不过我还是要稍微讲解一下:
这段代码在创建一个摄像机,了解3D游戏编程的人一定了解这个概念,新手可以理解为用户的视角。
这段代码增加了一段灯光,请注意在最后设置为了摄像机的子物体,也就是说随着摄像机的移动,灯光也会移动的意思。
真正加载3D模型的语句就是这么一句,如果你在Resource文件夹中寻找的话,你就会发现有一个hello-world.pod文件,这个就是我们会显示的3D模型了。
更新方法
Cocos3d的模板中还提供了一系列的更新方法,注释中有很多的解释,我们来看看:
这段代码中主要就是4个方法:
如果你曾经使用过Unity3D的话,你就会熟悉它的Update函数,这个函数和他差不多,简单地说,就是每帧运行一次这里面的代码,或者用户设置的每一段时间。
这个函数和上面的很像,不赘述了
顾名思义,这个就是onStart函数,在开始的时候运行一次的。
同上,在结束的时候运行一次。
交互方法
cocos3D模板中提供的最后一个方法就是检测交互的方法,我们来看看:
很明显这个函数是根据用户点击的点进行交互的
而这个函数则不仅根据用户点击的点,还根据用户点击的类型进行排定并作出反应。
之后看些什么?
好了到这里我就把cocos3d模板文件的代码讲解完了,你可以自己拍动代码看看效果,我们接下来会推出一系列的具体cocos3d教程,有些还会配上视频,敬请关注:
《Cocos3D教程:如何将3D文件导入进Cocos3D工程中》
《Cocos3D教程:如何制作一个嵌入3D模型的iOS应用》
《Cocos3D教程:如何制作一个简单的3D小游戏》
欢迎关注我的围脖: @Oratis
在知乎和豆瓣上,我的名字也是Oratis
我会把之后发表的教程分享到这些社交网络中。
如果你有任何问题,欢迎在底下留言,也欢迎写信给我,我的邮箱地址是: oratis@appkon.com
为什么我觉得Cocos3D是iOS上最好的使用3D模型的方法呢?首先是因为Cocos3D是cocos2D的拓展集,完全嵌入在Xcode中,更加好控制并且可以和iOS应用结合。其次还因为Cocos3D较OpenGL ES来说比较简单,使用的方法也比较高级。
这篇教程我们主要讲解Cocos3D的一些基础的内容,比如说如何设置灯光摄像机,如何绘制物体,如何设置物体运动,还有如何进行用户交互。
如何安装使用
首先你要先下载哦,要用mac的还用我说嘛亲?下载地址在这里。
如果你感兴趣,在下载站点的旁边有一个引擎作者写的详细说明,有兴趣也可以看看,还有翻译的哦亲:
作者说明 —— 翻译
至于安装,你可以看看Readme,很简单的,首先把cocos2d放在cocos3d的目录里,之后输入命令cd,进入cocos3d的文件夹,运行命令:
./install-cocos3d.sh -f -2 “../../cocos2d/cocos2d-iphone-1.0.1″
安装程序会搞定一切。
构建3D世界
首先打开Xcode,新建一个Cocos3d的项目,打开直接看class文件夹里的内容吧,其他的基本上都是资源文件。
一个新建的cocos3d项目本身就带有一个3d的自旋转的Hello,World模型,我们要知道它是如何构建的,只需要查看其代码就可以,找到下面的代码:
-(void) initializeScene { // Create the camera, place it back a bit, and add it to the scene CC3Camera* cam = [CC3Camera nodeWithName: @"Camera"]; cam.location = cc3v( 0.0, 0.0, 6.0 ); [self addChild: cam]; // Create a light, place it back and to the left at a specific // position (not just directional lighting), and add it to the scene CC3Light* lamp = [CC3Light nodeWithName: @"Lamp"]; lamp.location = cc3v( -2.0, 0.0, 0.0 ); lamp.isDirectionalOnly = NO; [cam addChild: lamp]; // This is the simplest way to load a POD resource file and add the // nodes to the CC3Scene, if no customized resource subclass is needed. [self addContentFromPODFile: @"hello-world.pod"]; // Create OpenGL ES buffers for the vertex arrays to keep things fast and efficient, // and to save memory, release the vertex data in main memory because it is now redundant. [self createGLBuffers]; [self releaseRedundantData]; // That's it! The scene is now constructed and is good to go. // If you encounter problems displaying your models, you can uncomment one or // more of the following lines to help you troubleshoot. You can also use these // features on a single node, or a structure of nodes. See the CC3Node notes. // Displays short descriptive text for each node (including class, node name & tag). // The text is displayed centered on the pivot point (origin) of the node. // self.shouldDrawAllDescriptors = YES; // Displays bounding boxes around those nodes with local content (eg- meshes). // self.shouldDrawAllLocalContentWireframeBoxes = YES; // Displays bounding boxes around all nodes. The bounding box for each node // will encompass its child nodes. // self.shouldDrawAllWireframeBoxes = YES; // Moves the camera so that it will display the entire scene. // [self.activeCamera moveWithDuration: 3.0 toShowAllOf: self]; // If you encounter issues creating and adding nodes, or loading models from // files, the following line is used to log the full structure of the scene. LogCleanDebug(@"The structure of this scene is: %@", [self structureDescription]); // ------------------------------------------ // But to add some dynamism, we'll animate the 'hello, world' message // using a couple of cocos2d actions... // Fetch the 'hello, world' 3D text object that was loaded from the // POD file and start it rotating CC3MeshNode* helloTxt = (CC3MeshNode*)[self getNodeNamed: @"Hello"]; CCActionInterval* partialRot = [CC3RotateBy actionWithDuration: 1.0 rotateBy: cc3v(0.0, 30.0, 0.0)]; [helloTxt runAction: [CCRepeatForever actionWithAction: partialRot]]; // To make things a bit more appealing, set up a repeating up/down cycle to // change the color of the text from the original red to blue, and back again. GLfloat tintTime = 8.0f; ccColor3B startColor = helloTxt.color; ccColor3B endColor = { 50, 0, 200 }; CCActionInterval* tintDown = [CCTintTo actionWithDuration: tintTime red: endColor.r green: endColor.g blue: endColor.b]; CCActionInterval* tintUp = [CCTintTo actionWithDuration: tintTime red: startColor.r green: startColor.g blue: startColor.b]; CCActionInterval* tintCycle = [CCSequence actionOne: tintDown two: tintUp]; [helloTxt runAction: [CCRepeatForever actionWithAction: tintCycle]]; }
其实如果看过我之前的教程并且有一些编程基础的人都可以很容易的看懂这些代码,不过我还是要稍微讲解一下:
// Create the camera, place it back a bit, and add it to the scene CC3Camera* cam = [CC3Camera nodeWithName: @"Camera"]; cam.location = cc3v( 0.0, 0.0, 6.0 ); [self addChild: cam];
这段代码在创建一个摄像机,了解3D游戏编程的人一定了解这个概念,新手可以理解为用户的视角。
// Create a light, place it back and to the left at a specific // position (not just directional lighting), and add it to the scene CC3Light* lamp = [CC3Light nodeWithName: @"Lamp"]; lamp.location = cc3v( -2.0, 0.0, 0.0 ); lamp.isDirectionalOnly = NO; [cam addChild: lamp];
这段代码增加了一段灯光,请注意在最后设置为了摄像机的子物体,也就是说随着摄像机的移动,灯光也会移动的意思。
[self addContentFromPODFile: @"hello-world.pod"];
真正加载3D模型的语句就是这么一句,如果你在Resource文件夹中寻找的话,你就会发现有一个hello-world.pod文件,这个就是我们会显示的3D模型了。
更新方法
Cocos3d的模板中还提供了一系列的更新方法,注释中有很多的解释,我们来看看:
-(void) updateBeforeTransform: (CC3NodeUpdatingVisitor*) visitor {} /** * This template method is invoked periodically whenever the 3D nodes are to be updated. * * This method provides your app with an opportunity to perform update activities after * the transformMatrix of the 3D nodes in the scen have been recalculated. * * For more info, read the notes of this method on CC3Node. */ -(void) updateAfterTransform: (CC3NodeUpdatingVisitor*) visitor {} #pragma mark Scene opening and closing /** * Callback template method that is invoked automatically when the CC3Layer that * holds this scene is first displayed. * * This method is a good place to invoke one of CC3Camera moveToShowAllOf:... family * of methods, used to cause the camera to automatically focus on and frame a particular * node, or the entire scene. * * For more info, read the notes of this method on CC3Scene. */ -(void) onOpen { // Uncomment this line to have the camera move to show the entire scene. // This must be done after the CC3Layer has been attached to the view, // because this makes use of the camera frustum and projection. // [self.activeCamera moveWithDuration: 3.0 toShowAllOf: self]; // Uncomment this line to draw the bounding box of the scene. // self.shouldDrawWireframeBox = YES; } /** * Callback template method that is invoked automatically when the CC3Layer that * holds this scene has been removed from display. * * For more info, read the notes of this method on CC3Scene. */ -(void) onClose {} #pragma mark Handling touch events /** * This method is invoked from the CC3Layer whenever a touch event occurs, if that layer * has indicated that it is interested in receiving touch events, and is handling them. * * Override this method to handle touch events, or remove this method to make use of * the superclass behaviour of selecting 3D nodes on each touch-down event. * * This method is not invoked when gestures are used for user interaction. Your custom * CC3Layer processes gestures and invokes higher-level application-defined behaviour * on this customized CC3Scene subclass. * * For more info, read the notes of this method on CC3Scene. */
这段代码中主要就是4个方法:
-(void) updateBeforeTransform: (CC3NodeUpdatingVisitor*) visitor {}
如果你曾经使用过Unity3D的话,你就会熟悉它的Update函数,这个函数和他差不多,简单地说,就是每帧运行一次这里面的代码,或者用户设置的每一段时间。
-(void) updateAfterTransform: (CC3NodeUpdatingVisitor*) visitor {}
这个函数和上面的很像,不赘述了
-(void) onOpen {}
顾名思义,这个就是onStart函数,在开始的时候运行一次的。
-(void) onClose {}
同上,在结束的时候运行一次。
交互方法
cocos3D模板中提供的最后一个方法就是检测交互的方法,我们来看看:
-(void) touchEvent: (uint) touchType at: (CGPoint) touchPoint {} /** * This callback template method is invoked automatically when a node has been picked * by the invocation of the pickNodeFromTapAt: or pickNodeFromTouchEvent:at: methods, * as a result of a touch event or tap gesture. * * Override this method to perform activities on 3D nodes that have been picked by the user. * * For more info, read the notes of this method on CC3Scene. */ -(void) nodeSelected: (CC3Node*) aNode byTouchEvent: (uint) touchType at: (CGPoint) touchPoint {} -(void) touchEvent: (uint) touchType at: (CGPoint) touchPoint {}
很明显这个函数是根据用户点击的点进行交互的
-(void) nodeSelected: (CC3Node*) aNode byTouchEvent: (uint) touchType at: (CGPoint) touchPoint {}
而这个函数则不仅根据用户点击的点,还根据用户点击的类型进行排定并作出反应。
之后看些什么?
好了到这里我就把cocos3d模板文件的代码讲解完了,你可以自己拍动代码看看效果,我们接下来会推出一系列的具体cocos3d教程,有些还会配上视频,敬请关注:
《Cocos3D教程:如何将3D文件导入进Cocos3D工程中》
《Cocos3D教程:如何制作一个嵌入3D模型的iOS应用》
《Cocos3D教程:如何制作一个简单的3D小游戏》
欢迎关注我的围脖: @Oratis
在知乎和豆瓣上,我的名字也是Oratis
我会把之后发表的教程分享到这些社交网络中。
如果你有任何问题,欢迎在底下留言,也欢迎写信给我,我的邮箱地址是: oratis@appkon.com
发表评论
-
cocos2d-x触摸事件优先级的探究与实践
2013-10-26 17:24 2417如何让自定义Layer触发触摸事件? bool Layer ... -
cocos2d-x添加触摸层阻止后端事件
2013-10-26 17:15 1255由于cocos2d-x中的优先级小的,先响应触摸事件 ... -
IOS游戏引擎列表
2013-09-13 10:35 2484常用iOS游戏开发工具与SDK 2D游戏开发框架 co ... -
手机游戏引擎 Cocos2d-x
2013-09-13 10:31 1263Cocos2D-X是全球知名的开源跨平台手机游戏引擎,易学易用 ... -
cocos3d教程:Hello,World
2013-09-11 19:21 1455这是cocos3d的主页,一个复杂的,但直观且易于使用的,3D ... -
总结阐述Cocos2d-X与Cocos2d-iphone区别
2013-09-11 19:20 787引用摘要: 最近开始学习cocos2d, 查阅资料发现有个Co ... -
网上论坛讨论问题
2013-09-11 19:18 874=================问题1=========== ... -
16大跨平台游戏引擎
2013-09-11 19:06 12351. Edgelib:2D及3D中间件 ... -
八款开源 Android 游戏引擎
2013-09-10 13:33 1030引用感谢西部的投递 新 ... -
【Cocos3d 入门教程之---配置cocos3d环境】
2013-09-10 10:39 1267本文适合于初步了解coco ... -
cocos2d学习资料
2013-09-10 15:42 5571,cocos2d-x 系列学习资料:http://blog. ... -
Cocos2d-X与Cocos2d区别
2013-09-09 16:12 863引用不得不说要说总结 ... -
Unity3D与cocos2d-x有什么区别和差异?
2013-09-09 14:47 1240Unity3D是收费的3D游戏引擎(当然也可开发2D游戏),c ... -
cocos2d-x与cocos2d-iphone+objc的区别
2013-09-09 14:45 529cocos2d-x是由国内一个团队,将objc语言的cocos ... -
1.3 Cocos2D-x与Cocos2D-iPhone的比较
2013-09-09 14:41 403Cocos2D-x与Cocos2D的其他版本和Cocos2D- ... -
《中国手机游戏四月流水榜》出炉 超过半数基于Cocos2D-X引擎
2013-09-09 14:29 969进入2013年,手机游戏市 ...
相关推荐
该资源主要用于cocos2d-x中Value与json字符串的相互转换,提供从json文件读取为cocos2d::Value,cocos2d::Value写入到文件,cocos2d::Value转换为json字符串,json字符串转换为cocos2d::Value。json字符串转换成cocos...
Cocos2d-iphone之HelloWorld
cocos2dx_helloworld_+jsoncpp
CocosCreater入门教程:登录界面.txt
c++ cocos2d的helloworld程序
自己最近一个星期搭好环境,主要是模仿helloworld来实现的。例子中虽然给了helloworld,但要是新手来搭的话,可能有些困难。免费的资源,希望对大家好帮助了。
cocos3d 小例子源代码,喜欢cocos3D的朋友关注偶的微博 http://weibo.com/cocos3d
cocos3D游戏引擎
主要是根据HelloWorld代码画出主要类图及时序图。结合http://blog.csdn.net/l695863436/article/details/10028323这篇文章一起看。
(译)cocos2d精灵教程:第一部分.pdf (译)cocos2d精灵教程:第三部分.pdf (译)cocos2d精灵教程:第二部分.pdf (译)cocos2d菜单教程:第一部分.pdf (译)cocos2d菜单教程:第三部分(完).pdf (译)...
cocos2d-x初探学习笔记(1)--HelloWorld
1. 基于cocos creator 2.1.3 开发 2. 主要功能: 2.1 开始菜单界面 2.2 主游戏界面 2.3 历史排行榜 2.4 结算弹窗 3. 支持微信等各平台小游戏发布 4. 亲测有效
cocos3d包Cocos3d是cocos2d的扩展集,cocos2d深入人心网上下的不知道有不有用
用cocos3d加载3Dmax模型的Demo. 详细可以看博客:http://fengmm521.blog.163.com/blog/static/25091358201210173463909/
NULL 博文链接:https://o0o0o0o.iteye.com/blog/805541
本资源是本在网上下的,原地址已失效,现在上传方便大家,在3d游戏开发
由知名Cocos技术专家火云红孩儿开发的Cocos3D模型工具,帮助Cocos3D程序进行模型处理与观看。
cocos3d已经发布了,跟cocos2d一样,都是开源的框架,该资源包为zip安装包,欢迎ios开发者下载。Cocos3d框架是iOS平台高度提炼的3D应用开发框架。 Cocos3d是cocos2d的扩展集,cocos2d深入人心,广泛使用在iOS 2d游戏...
NULL 博文链接:https://o0o0o0o.iteye.com/blog/805601
只有基本功能:注册事件,监听事件;点击按钮移动节点,以及点击按钮提交文本框中的操作,根据文本框的内容操作。