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.
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...
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.
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?Originally Posted by roberto_h25
It won't let me do it that way...
The error says: expected constructor, destructor or type conversion before '.' token.
Can you show the struct/class definition for Vertex ?
Ok:
typedef struct {
unsigned int color;
float x, y, z;
} Vertex;
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.
Can you show the entire function of where you are getting that 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;
}
I wasn't declaring it inside the main function!
Thanks a lot! It works now...
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks