Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 使用OpenGL识别调用draw()方法的对象_Objective C_Opengl Es_Opengl Es 2.0 - Fatal编程技术网

Objective c 使用OpenGL识别调用draw()方法的对象

Objective c 使用OpenGL识别调用draw()方法的对象,objective-c,opengl-es,opengl-es-2.0,Objective C,Opengl Es,Opengl Es 2.0,是否有一种方法可以识别哪个对象正在调用draw方法 创建: joint.model = [[Box alloc] init]; 呼叫代码: [joint.model draw]; 绘制方法(在Box类中): 如何在绘图方法中接收关节对象 如果需要更多的类信息,我可以附加,但我没有假设,因为没有更多。模型对象需要有一个指向关节的指针,以便在-draw方法中使用它。因此,您需要修改Box类,使其具有指向任何类型joint的指针,或者如果Box是由您正在使用的框架定义的,则需要对其进行子类

是否有一种方法可以识别哪个对象正在调用draw方法

创建:

joint.model = [[Box alloc] init];
呼叫代码:

    [joint.model draw];
绘制方法(在Box类中):

如何在绘图方法中接收
关节
对象


如果需要更多的类信息,我可以附加,但我没有假设,因为没有更多。

模型对象需要有一个指向关节的指针,以便在
-draw
方法中使用它。因此,您需要修改
Box
类,使其具有指向任何类型
joint
的指针,或者如果
Box
是由您正在使用的框架定义的,则需要对其进行子类化。因此,您可以选择:

@class Box {
   Model* model; // Or whatever type model is.
}
或者,如果这不是一个选项,您可以这样做:

@class BetterBox : Box {
    Model* model; // Or whatever type model is.
}
并确保创建的
model.joint
如下所示:

model.joint = [[BetterBox alloc] init]; // or [[Box alloc] init] if you modified the Box class
[model.joint setModel:model];
- (void)draw
{
    [model someMethod];
    //... etc. ...
}
然后,在绘制方法中,您可以简单地访问
模型
,如下所示:

model.joint = [[BetterBox alloc] init]; // or [[Box alloc] init] if you modified the Box class
[model.joint setModel:model];
- (void)draw
{
    [model someMethod];
    //... etc. ...
}

模型
对象需要有一个指向
关节
的指针,才能在
-draw
方法中使用它。因此,您需要修改
Box
类,使其具有指向任何类型
joint
的指针,或者如果
Box
是由您正在使用的框架定义的,则需要对其进行子类化。因此,您可以选择:

@class Box {
   Model* model; // Or whatever type model is.
}
或者,如果这不是一个选项,您可以这样做:

@class BetterBox : Box {
    Model* model; // Or whatever type model is.
}
并确保创建的
model.joint
如下所示:

model.joint = [[BetterBox alloc] init]; // or [[Box alloc] init] if you modified the Box class
[model.joint setModel:model];
- (void)draw
{
    [model someMethod];
    //... etc. ...
}
然后,在绘制方法中,您可以简单地访问
模型
,如下所示:

model.joint = [[BetterBox alloc] init]; // or [[Box alloc] init] if you modified the Box class
[model.joint setModel:model];
- (void)draw
{
    [model someMethod];
    //... etc. ...
}

我需要此功能的原因是为了使用命名常量。但是在这种情况下,我如何使用
self
?我如何访问我可以识别对象的
joint.jointName
属性?啊,我误解了你上面写的内容。我以为
-draw
是一种
联合的方法,但它是一种
模型的方法。在这种情况下,self是
model
,而
model
需要有一个指向
joint
的指针。然后,您只需调用
[self.model doWhatever]。当然,我忘记了澄清这一点的部分。请等待更新。请立即查看我的编辑
joint.model
Box类的对象,在该类中调用
draw
方法。这有意义吗?我已经有了
@property(非原子,保留)Box*模型在my
Joint.h
中。但正如我所见,它不会有太大的好处。我之所以需要这个功能是为了使用命名常量。但是在这种情况下,我如何使用
self
?我如何访问我可以识别对象的
joint.jointName
属性?啊,我误解了你上面写的内容。我以为
-draw
是一种
联合的方法,但它是一种
模型的方法。在这种情况下,self是
model
,而
model
需要有一个指向
joint
的指针。然后,您只需调用
[self.model doWhatever]。当然,我忘记了澄清这一点的部分。请等待更新。请立即查看我的编辑
joint.model
Box类的对象,在该类中调用
draw
方法。这有意义吗?我已经有了
@property(非原子,保留)Box*模型在my
Joint.h
中。但正如我所看到的,这不会有多大好处。。