将 C 结构转换为 Objective C 对象 - iPhone - OpenGL Es

发布于 2025-01-06 16:57:38 字数 459 浏览 3 评论 0原文

我将通过一个示例来说明如何将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

终难愈 2025-01-13 16:57:39

我不太了解 openGL ES,但你可以声明一个类:

@interface YourClass : NSObject
{
   float value1;
   float value2;
   float value3;
}

@end

保存你的变量。如果您愿意,您可以将这些对象存储在 NSArray 中。

I don't know much openGL ES, but you could declare a class like:

@interface YourClass : NSObject
{
   float value1;
   float value2;
   float value3;
}

@end

To hold your variables. You could store those objects in a NSArray if you want to.

匿名。 2025-01-13 16:57:39

在这种情况下,我建议您重新考虑用 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).

笙痞 2025-01-13 16:57:39

NSValue是目标 c 类,被设计为 c 数据的容器。

查看这个答案

NSValue is the objective c class which is designed to be a container for c data.

check out this answer

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文