views:

168

answers:

3

Ok,

I'm trying to save some time creating some generic classes to draw objects in the 3D space.

I created a Object3D class with the properties x, y, and z.

The thumbnail3D is a "son" of Object3D using inheritance. Vertex3D is a struct with a GLfloat for every coord.

The problem is when I try to compile the method initWithPosition:( Vertex3D *)vertex, and the error is:

Request for member 'x' in something not structure or union. Request for member 'y' in something not structure or union. Request for member 'z' in something not structure or union.

But, the structure is on the import...

#import <UIKit/UIKit.h>
#import <OpenGLES/ES2/gl.h>

@interface Object3D : NSObject 
{
    GLfloat x;
    GLfloat y;
    GLfloat z;
}

@property  GLfloat x;
@property  GLfloat y;
@property  GLfloat z;

-(void) render;

@end

The render is still hardcoded

#import "Thumbnail3D.h"
#import "ConstantsAndMacros.h"
#import "OpenGLCommon.h"

@implementation Thumbnail3D

@synthesize width;
@synthesize height;

-(void)render
{
    Triangle3D  triangle[2];
    triangle[0].v1 = Vertex3DMake(0.0, 1.0, -3.0);
    triangle[0].v2 = Vertex3DMake(1.0, 0.0, -3.0);
    triangle[0].v3 = Vertex3DMake(-1.0, 0.0, -3.0);
    triangle[1].v1 = Vertex3DMake(-1.0, 0.0, -3.0);
    triangle[1].v2 = Vertex3DMake(1.0, 0.0, -3.0);
    triangle[1].v3 = Vertex3DMake(0.0, -1.0, -3.0);

    glLoadIdentity();
    glClearColor(0.7, 0.7, 0.7, 1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnableClientState(GL_VERTEX_ARRAY);
    glColor4f(1.0, 0.0, 0.0, 1.0);
    glVertexPointer(3, GL_FLOAT, 0, &triangle);
    glDrawArrays(GL_TRIANGLES, 0, 18);
    glDisableClientState(GL_VERTEX_ARRAY);
}

-(void)initWithPosition:(Vertex3D *)vertex
{
    x = vertex.x;
    y = vertex.y;
    z = vertex.z;
}

@end
+1  A: 

Do you mean to pass Object3D into the init function?

I dont know what Vertex3D is..

Or, is that supposed to be the implementation for Object3D? In which case you need to have

@implementation Object3D

at the start.

And you should probably

@synthesize x
@synthesize y
@synthesize z

instead of width, height..

Mongus Pong
A: 

The error...

Request for member 'x' in something not structure or union.

... means that something has gone wrong in the definition of a structure, union or class. Either, (1) the Vertex3D struct was not defined properly or (2) the definition was not included properly in the Thumbnail3D class.

TechZen
+3  A: 

When I read this part

Vertex3D is a struct with a GLfloat for every coord.

I think you should write

-(void)initWithPosition:(Vertex3D *)vertex
{
  x = vertex->x;
  y = vertex->y;
  z = vertex->z;
}

...as vertex then is a plain-old pointer to a C struct

epatel
Yep, a `Vertex3d*` is in fact not a structure or a union — it's a pointer.
Chuck