PDA

View Full Version : i wonder if this is right.

11-08-2002, 12:14 PM
i wonder if this is right: glVertex3fv(&Tris[i].A.x); i mean, is the parameter for glVertex3fv right one? anybody can help? the context is like the following:

class TriModel
{
public:

Tri *Tris;
...
}

struct Tri
{
Vec3f A,B,C,N;
unsigned char Color[3]; // r,g,b
};

class Vec3f
{
public:
float x, y, z;

Vec3f (void)
{};
...
}

nexusone
11-08-2002, 01:16 PM
No, vertex needs three values
You are only passing one with Tris[i].A.x.

You could do it like this:
glVertex3f(Tris[i].A.x,Tris[i].A.y,Tris[i].A.z);

or

which I am not sure but you may could do it with:
glVertex3fv(Tris[i].A); // A = x, y, z
the v means a pointer to the starting location of the three variables.

I do it like this:

GLfloat vec[number of vertex][3];

glVertex3fv(&vec[i]);

Originally posted by ffd:
i wonder if this is right: glVertex3fv(&Tris[i].A.x); i mean, is the parameter for glVertex3fv right one? anybody can help? the context is like the following:

class TriModel
{
public:

Tri *Tris;
...
}

struct Tri
{
Vec3f A,B,C,N;
unsigned char Color[3]; // r,g,b
};

class Vec3f
{
public:
float x, y, z;

Vec3f (void)
{};
...
}

mm_freak
11-08-2002, 03:52 PM
nexusone: Should be working on most systems, but it's not defined. All compilers add, for example, an identification value for abstract classes. If this is at the beginning of the structure, that wouldn't work anymore, since the structure would start with that value instead of the x-value.

You should get a C/C++ tutorial first, I think, you didn't understand pointers and stuff.

nexusone
11-08-2002, 04:33 PM
I have not worked with all types of pointers, other then the basic C type.
I understand what you are saying, I know that x will point to the start of the three floats.
but my thought was with A.x the computer may only expect a pointer to a single float.

I guess that both A and A.x will give you the same pointer to the begining of the three floats, just in how the compiler handles it. and which would work best with glVertex3fv.

Originally posted by mm_freak:
nexusone: Should be working on most systems, but it's not defined. All compilers add, for example, an identification value for abstract classes. If this is at the beginning of the structure, that wouldn't work anymore, since the structure would start with that value instead of the x-value.

You should get a C/C++ tutorial first, I think, you didn't understand pointers and stuff.

11-08-2002, 05:13 PM
Something like that will either work, or not work. Both of those won't work. If you store the coordinates in three fields of a structure, you have to use glVertex3f. If you are using an array, you can use glVertex3fv (faster).

glVertex3fv(&A.x); might work on your system, but it won't work on most. Compilers may add padding bytes or put the fields in a weird order.

-- Thomas

mm_freak
11-08-2002, 06:16 PM
That's what I ment.