Q: Array Help



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 03/01/2008 at 10:21, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   10.506 
    Platform:   Windows  ;   
    Language(s) :     C++  ;

    ---------
    Hey Guys,
    This is more of a general programming question than a question for the Cinema SDK. But, I need to setup an array that contains each frame of the scene as an element and then have those elements hold an array of vectors. This way I can access a number of positions for each frame. For instance; frame 0 would hold an array of 5 vectors, frame 1 would hold an array of 3 vectors, and so on.

    The question is: how would I define this array? Does this make sense? As always, thanks in advance for any help.
    Josh



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 03/01/2008 at 11:38, xxxxxxxx wrote:

    Define a class for the top-level array:

    class FrameItem
    {
    private:
    LONG numVectors;
    Vector* vecArray;
    public:
    FrameItem()
    {
    numVectors = 0L;
    vecArray = NULL;
    }
    ~FrameItem()
    {
    bDelete(vecArray);
    }
    };

    Allocate an array of numFrames FrameItems:

    FrameItem* fi = bNew FrameItem[numFrames];
    if (!fi) //error
    FrameItem* lfi = fi+numFrames;
    for (FrameItem* f = fi; f != lfi; ++f)
    {
    f->numVectors = ?;
    f->vecArray = bNew Vector[?];
    if (!f->vecArray) // error
    }

    As can be seen by the question marks, you'll have to determine the number of Vectors for each Frame's Vector array in whatever manner you intend.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 03/01/2008 at 14:37, xxxxxxxx wrote:

    Thanks for the quick reply Robert. I can see how this will work for what I am trying to achieve, but there is one problem: I find out each frame how many vectors will be in the vector array in a for statement.

    > _
    > class cacheFrame
    > {
    > LONG numVectors;
    > Vector *vecArray;
    > };
    >
    > cacheFrame *cf = bNew cacheFrame[numFrames];
    >
    >
    > for(LONG f=startFrame; f <=endFrame; f++)
    > {
    > //get number of vectors to create on this frame
    > counter = GetNumVectors();
    >
    > //construct the array of vectors for the given frame
    > cf->vecArray = bNew Vector[counter];
    > if(!cf->vecArray) return;
    >
    > //increment the pointer
    > ++cf;
    > }//end for statement
    >
    > _

    So I need to incorporate this class into my existing for statement. Would I want to go through the allocation of the FrameItem class each frame? I know there is definitely something wrong with the provided code, but I can't get the vecArray to allocate properly.

    Thanks in advance,
    Josh



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 03/01/2008 at 15:34, xxxxxxxx wrote:

    Would I want to go through the allocation of the FrameItem class each frame?

    No. You either allocate an array or you'll never be able to track all of the individual FrameItem class instances.

    First problem with the code is that you allocate the array to 'cf' and proceed to increment the pointer. Where do you think the original pointer goes when you try to access the array later or delete it? Make a new pointer and increment it:

    cacheFrame* cf = bNew cacheFrame[numFrames];
    cacheFrame* tcf = cf;

    // in the loop
    ...
    tcf- >vecArray = bNew Vector[counter];
    if (!tcf->vecArray) return;
    ++tcf;

    In this way, the original allocator pointer doesn't get lost. The vecArray is still added to the current class instance of cf.


Log in to reply