Results 1 to 9 of 9

Thread: How to define the model dynamically?

                  
   
  1. #1

    Default How to define the model dynamically?

    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...

  2. #2
    GP2X Coder/Moderator
    Join Date
    Jan 2006
    Posts
    1,678
    Rep Power
    84

    Default

    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.

  3. #3

    Default

    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.

  4. #4
    GP2X Coder/Moderator
    Join Date
    Jan 2006
    Posts
    1,678
    Rep Power
    84

    Default

    Quote Originally Posted by roberto_h25
    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?

  5. #5

    Default

    It won't let me do it that way...

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

  6. #6
    GP2X Coder/Moderator
    Join Date
    Jan 2006
    Posts
    1,678
    Rep Power
    84

    Default

    Can you show the struct/class definition for Vertex ?

  7. #7

    Default

    Ok:

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

  8. #8
    GP2X Coder/Moderator
    Join Date
    Jan 2006
    Posts
    1,678
    Rep Power
    84

    Default

    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?

  9. #9

    Default

    I wasn't declaring it inside the main function!

    Thanks a lot! It works now...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •