PDA

View Full Version : How to define the model dynamically?



roberto_h25
August 26th, 2006, 22:16
I know the normal way...


Vertex __attribute__((aligned(16))) pyramid[3*1] =
{
{ 0x000000ff, -0.811853955937f, 0.445342652067f, 0.445342652067f},
{ 0x000000ff, -0.523709643896f, 0.307797283808f, 0.0f },
{ 0x000000ff, -0.811853955937f, 0.890685304134f, 0.0f }
};

But I would like to use fill the values of my variable pyramid dynamically. Something like:


Vertex __attribute__((aligned(16))) pyramid[3*1];

pyramid[0].color = VariableA;
pyramid[0].x = VariableB;
pyramid[0].y = VariableC;
pyramid[0].z = VariableD;

pyramid[1].color = VariableE;
pyramid[1].x = VariableF;
pyramid[1].y = VariableG;
pyramid[1].z = VariableH;

pyramid[2].color = VariableI;
pyramid[2].x = VariableJ;
pyramid[2].y = VariableK;
pyramid[2].z = VariableL;


Thanks...

yaustar
August 26th, 2006, 22:19
What do you mean by 'dynamically'? Both pieces of the code you posted do exactly the same thing. The only difference is one is 'filled' at construction time.

roberto_h25
August 26th, 2006, 22:24
This is a better example of what I want...

for (i = 0; i < 10; i++) {
pyramid[i].color = ColorArray[i];
pyramid[i].x = XArray[i];
pyramid[i].y = YArray[i];
pyramid[i].z = ZArray[i];
}

...being able to use the values in some array to fill the values of my pyramid variable.

yaustar
August 26th, 2006, 22:30
This is a better example of what I want...

for (i = 0; i < 10; i++) {
pyramid[i].color = ColorArray[i];
pyramid[i].x = XArray[i];
pyramid[i].y = YArray[i];
pyramid[i].z = ZArray[i];
}

...being able to use the values in some array to fill the values of my pyramid variable.

Okay, what is wrong with the code here? It looks fine to me. Do you want a function definition?

roberto_h25
August 26th, 2006, 22:39
It won't let me do it that way...

The error says: expected constructor, destructor or type conversion before '.' token.

yaustar
August 26th, 2006, 22:40
Can you show the struct/class definition for Vertex ?

roberto_h25
August 26th, 2006, 22:42
Ok:

typedef struct {
unsigned int color;
float x, y, z;
} Vertex;

yaustar
August 26th, 2006, 23:00
Assuming all the ColorArray, XArray,etc are valid arrays, then I don't see the error. That for loop is completely valid.

This works fine without error.

typedef struct {
unsigned int color;
float x, y, z;
} Vertex;

int main()
{
Vertex __attribute__((aligned(16))) A[2];

A[0].color = 0;
A[0].x = 0;
A[0].y = 0;
A[0].z = 0;

A[1].color = 0;
A[1].x = 0;
A[1].y = 0;
A[1].z = 0;
}

Can you show the entire function of where you are getting that error?

roberto_h25
August 26th, 2006, 23:16
I wasn't declaring it inside the main function!

Thanks a lot! It works now...