IRdNumArray

About Truespace Archives

These pages are a copy of the official truespace forums prior to their removal somewhere around 2011.

They are retained here for archive purposes only.

IRdNumArray // SDK, Plug-in & 3rd Party Area

1  |  

Post by Paul_Martinsen // Mar 6, 2009, 8:00pm

Paul_Martinsen
Total Posts: 5
Hello,


I used the cable object as the basis for a tentacle animation recently and converted it to C++ to make it run faster (I had a lot of tentacles). I've been trying to make it easier to use so I can share it with everyone but have run into a problem.


I store the position of the tentacle in a 3D "Common Data Package/Number Array Data" object. This comes across as an IRdNumArray object in C++. The array is 120 x 20 x 3 (key frames x segments x <x,y,z>).


To access the data in the array, I package the matrix index into a safe array (VT_I4) then call GetAt as follows:

if (FAILED(SetIndicies(psaIndex, nKey1, nStep, nAxis)) ||

FAILED(hr = pData->GetAt(psaIndex, &vResult)) ||

FAILED(vResult.ChangeType(VT_R4)))

{ SafeArrayDestroy(psaIndex);

return;

}

When nKey1 == nStep == nAxis == 0, this works fine. But if I set nAxis to 1, I get an E_INVALIDARG from GetAt(...). I've used GetDim() & GetSize() earlier in the code to check that the size of the array is as expected & the access works from a TS JScript object.


I'd be grateful if anyone can suggest a solution or has an example for accessing multidimensional TrueSpace arrays. The only alternative I can think of is putting the data in a text file, tying the project to the file system.


Thanks

Paul.

Post by frootee // Mar 7, 2009, 3:51am

frootee
Total Posts: 2667
pic
Hello,


To access the data in the array, I package the matrix index into a safe array (VT_I4) then call GetAt as follows:

if (FAILED(SetIndicies(psaIndex, nKey1, nStep, nAxis)) ||

FAILED(hr = pData->GetAt(psaIndex, &vResult)) ||

FAILED(vResult.ChangeType(VT_R4)))

{ SafeArrayDestroy(psaIndex);

return;

}

When nKey1 == nStep == nAxis == 0, this works fine. But if I set nAxis to 1, I get an E_INVALIDARG from GetAt(...). I've used GetDim() & GetSize() earlier in the code to check that the size of the array is as expected & the access works from a TS JScript object.


Thanks

Paul.


Hi Paul.


You have a 3 dimensional array, but are trying to access its contents using a single index.


While with 'classic' array structures you can get away with it, like this:


int x[5][10];

printf("%d", x[35]);


with the GetAt function, you have to use an index for each dimension.


Here's some sample jscript code to demonstrate what I mean:




// Execute

// Called to execute the command

function Execute(params)

{


arr = System.CreateDO('Common Data Package/Number Array Data');

arr.SetDim(3);

arr.SetSize(5, 10, 15);

arr.SetAt(4, 9, 14, 100);

arr.SetAt(0, 9, 0, 10);


// This works

val = arr.GetAt(4, 9, 14);


// This does not work

val2 = arr.GetAt(10);


System.Alert(val2);


}


Try that and please let us know how it goes. Thanks! :)


Froo

Post by Paul_Martinsen // Mar 7, 2009, 11:24am

Paul_Martinsen
Total Posts: 5
Thanks Froo.


I should have pointed out the code example was in C++. C++ doesn't support variable arguments for COM calls so instead of specifying the indicies as separate arguments, they are packed into a "safe array". In other words, psaIndex is a 3 element array that contains the 3 indicies for the matrix.


What I can't understand is why vResult = array.GetAt(0,0,1) works in TS, but array->GetAt({0,0,1},&vResult) fails in C++. :-(


paul.

Post by jamesmc // Mar 8, 2009, 5:56am

jamesmc
Total Posts: 2566
Just a S.W.A.G. and pardon me for butting in, but if the positions are non-linear (negative or values outside of a known matrix) the dimensioning might fail if consideration was not given how to handle negative position values.

i.e. pointers to something outside of an array not defined by a Class that handles 'out of range' actions or where the definition doesn't consider that some positive element tries to be smaller than a negative number, which it can not be.

As I said, a S.W.A.G. from programming skills not used in 20 years. :D
Awportals.com is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2024. All Rights Reserved.
Awportals.com   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn