将 C 结构转换为 Objective C 对象 - iPhone - OpenGL Es
我将通过一个示例来说明如何将 DAE 文件解析为 OpenGL ES (http://www.everita.com/lightwave-collada-and-opengles-on-the-iphone)。
在此示例中,有以下代码:
const Vertex3D tigerBottomNormals[] = {
{-0.425880, -0.327633, 0.350967},
{-0.480159, -0.592888, 0.042138},
{-0.113803, -0.991356, 0.065283},
};
这里使用 C 结构体来存储 3 个数组,每个数组包含三个浮点值。
我的问题是如何将此数据结构转换为目标 C 对象。我想我会在更大的容器 NSArray 中创建 NSArray,但不确定应该如何连接三个单独的浮点值,以便它们可以作为一项添加到数组中。
提前致谢。
I am following through an example of how to parse a DAE file to OpenGL ES (http://www.everita.com/lightwave-collada-and-opengles-on-the-iphone).
In this example there is the following code :
const Vertex3D tigerBottomNormals[] = {
{-0.425880, -0.327633, 0.350967},
{-0.480159, -0.592888, 0.042138},
{-0.113803, -0.991356, 0.065283},
};
Here a C struct is used to store 3 arrays each containing three float values.
My question is how would I convert this data structure to objective C objects. I am thinking I would create NSArrays within a larger container NSArray, but am unsure how I should join the three separate float values so that they can be added as one item to the array.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不太了解 openGL ES,但你可以声明一个类:
保存你的变量。如果您愿意,您可以将这些对象存储在 NSArray 中。
I don't know much openGL ES, but you could declare a class like:
To hold your variables. You could store those objects in a NSArray if you want to.
在这种情况下,我建议您重新考虑用 Objective-C 类替换普通 C 结构的决定。 Objective-C 是 C 的子集,因此它可以与普通的 C 结构一起使用,没有任何问题,并且上面的代码应该可以编译。我有很多用 C/C++ 实现的低级数学结构的项目,这使得代码对于这个特定任务来说变得简单且可读。
但是,如果您严格需要 Obj-C 包装器,请检查 CIVector 类 - 您必须创建类似的东西(或者甚至可能直接使用 CIVector,因为 CoreImage 是 iOS 5 的一部分)。
I'd recommend you to reconsider your decision to replace the plain C-structs with Objective-C classes in this case. Objective-C is a subset of the C, so it works with plain C structs without any problems and the code above should compile. I have a bunch of projects with low-level math structs implemented in C/C++ which makes the code simple and readable for this particular task.
However, if you strictly need an Obj-C wrapper, check the CIVector class - you must create something like that (or maybe even use CIVector directly since CoreImage is a part of the iOS 5).
NSValue是目标 c 类,被设计为 c 数据的容器。
查看这个答案
NSValue is the objective c class which is designed to be a container for c data.
check out this answer