English 中文(简体)
目标C阵列和类别变量
原标题:Objective-C arrays and class variables

我正在把安乐素一带上台,并陷入与辛奈(我想)有关的问题。

I m basing the project off of the example from http://iphonedevelopment.blogspot.com/2009/04/opengl-es-from-ground-up-part-2-look-at.html

I would like to pull out the geometry from the rendering process to keep the code modular but I can t seem to get it to work. I ve created a class called Icosahedron (comments are my understanding of what s going on) Icosahedron.h

#import <Foundation/Foundation.h>
#import "OpenGLCommon.h"



@interface Icosahedron : NSObject {
 Vertex3D *vertices[12]; //allocate a group of 12 Vertex3D pointers
 Vertex3D *normals[12]; // ditto
 GLubyte *faces[60]; // ditto but with 60 face values
}

// Declare methods
-(Vertex3D *) vertices; 
-(void) setVertices:(Vector3D *)setVerts; 

-(Vertex3D *) normals;
-(void) setNormals:(Vector3D *)setNorms;

-(GLubyte *) faces;
-(void) setFaces:(GLubyte *)setFaces;

@end

Icosahedron。 页: 1

#import "Icosahedron.h"


@implementation Icosahedron

// Returns the pointer to the vertices instance variable
-(Vector3D *) vertices{
 return *vertices;
}

-(void) setVertices:(Vector3D *)setVerts
{
 //vertices=setVerts[0];
}

-(Vector3D *) normals{
 return *normals;
}

-(void) setNormals:(Vector3D *)setNorms
{
 //normals=setNorms;
}

-(GLubyte *) faces{
 return *faces;
}

-(void) setFaces:(GLubyte *)setFaces
{
 //faces=setFaces;
}
/**/
-(id)init
{
 // super method
 self=[super init];

    // create 12 Vector3D objects and populate them...
 Vector3D tempVert[12]={
        {0, -0.525731, 0.850651},             // vertices[0]
        {0.850651, 0, 0.525731},              // vertices[1]
        {0.850651, 0, -0.525731},             // vertices[2]
        {-0.850651, 0, -0.525731},            // vertices[3]
        {-0.850651, 0, 0.525731},             // vertices[4]
        {-0.525731, 0.850651, 0},             // vertices[5]
        {0.525731, 0.850651, 0},              // vertices[6]
        {0.525731, -0.850651, 0},             // vertices[7]
        {-0.525731, -0.850651, 0},            // vertices[8]
        {0, -0.525731, -0.850651},            // vertices[9]
        {0, 0.525731, -0.850651},             // vertices[10]
        {0, 0.525731, 0.850651}               // vertices[11]
    };
    // same...
 Vector3D tempNorm[12]={
        {0.000000, -0.417775, 0.675974},
        {0.675973, 0.000000, 0.417775},
        {0.675973, -0.000000, -0.417775},
        {-0.675973, 0.000000, -0.417775},
        {-0.675973, -0.000000, 0.417775},
        {-0.417775, 0.675974, 0.000000},
        {0.417775, 0.675973, -0.000000},
        {0.417775, -0.675974, 0.000000},
        {-0.417775, -0.675974, 0.000000},
        {0.000000, -0.417775, -0.675973},
        {0.000000, 0.417775, -0.675974},
        {0.000000, 0.417775, 0.675973},
    };


 // face values
 GLubyte tempFaces[60]={
        1, 2, 6,
        1, 7, 2,
        3, 4, 5,
        4, 3, 8,
        6, 5, 11,
        5, 6, 10,
        9, 10, 2,
        10, 9, 3,
        7, 8, 9,
        8, 7, 0,
        11, 0, 1,
        0, 11, 4,
        6, 2, 10,
        1, 6, 11,
        3, 5, 10,
        5, 4, 11,
        2, 7, 9,
        7, 1, 0,
        3, 9, 8,
        4, 8, 0,
    };

   // set the instance pointers to the temp values
 *vertices=tempVert;
 *normals=tempNorm;
 *faces=tempFaces;

此时,这些数值是NOT的适当人口,只有第一个数值正确。

 return self;

}

@end

我所要做的是,能够说像什么这样的东西。

...
ico=[[Icosahedron alloc] init];
glVertexPointer(3, GL_FLOAT, 0, [ico vertices]);
...

在送文科,但最远的I ve却能够在Icosahedron语中确定最高3D人的第一价值,而Icosahedron语中任何一个Icosahedron的数值,我从夸大。

我怀疑,这只是我学习目标——C的qui子,但我几天来尝试了许多不同的做法,似乎在任何地方找不到我。

请帮助我超负荷工作,你只想回想。

最佳回答

你们把点和阵列混在一起。 你们想要的是:

Vertex3D vertices[12];

- (void) setVertices: (Vertex3D *)newVertices;
{
    memcpy( vertices, newVertices, 12 * sizeof( Vertex3D ) );
}

- (Vertex3D *) vertices;
{
    return vertices;
}

若要复制C的阵列,你必须使用肉类(或手工艺品)来复制,你不能与转让经营人一道这样做。

问题回答

首先,你似乎互换地使用了“Vertex3D”和“Vector3D”。 我不知道这是否确实是一个问题。

我认为,应当宣布这些阵列为各种价值观,而不是各种点。 因此

Vertex3D vertices[12]; //allocate a group of 12 Vertex3D pointers
Vertex3D normals[12]; // ditto
GLubyte faces[60]; // ditto but with 60 face values

这样,你们就具备了所有价值观的空间,而不仅仅是指向其他病媒(你们已经分配了这些病媒)。

除此以外,典型的顺序是:

-(id)init
{
    if (self = [super init])
    {
         //do initialization stuff
    }
    return self;
}

它对错误的处理更为宽松。

www.un.org/chinese/ga/president 似乎像你真的想要的是有一系列的构件/价值。 因此,你的接口应当说:

Vertex3D vertices[12];
Vertex3D normals[12];
GLubyte faces[60];

之后,您的物体将拥有包含12个vert、12个平常和60个面孔的记忆库(无论这些).是什么——GLubyte值,不管怎么说。

点数和阵列如下:sort of interchangeable in C/Objective-C. Soverticesnormals。 也可视为<代码>Vertex3D* Value,和faces,作为GLubyte*,并可将这些数值作为此类职能予以通过。

为了说明什么内容,最好把初始数值作为单一的<代码>static const阵列在您的执行档案的顶级,然后在初始阶段将这些数值复制到物体所有阵列。 你可以采取这些几种方式,但最简单的可能使用<条码>mcpy,载于





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签