Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Sorting multi-dimensional arrays... Help...

Author
Message
Robert The Robot
18
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 7th Nov 2007 20:11 Edited at: 7th Nov 2007 20:12
I'm working on a limb based animator, where you can switch between the objects you're working on. Unfortunately, when it comes to setting and deleting keyframes my arrays get rather messed up and I'm struggling to get them sorted. Here's one of them:

ObjectLimbOffset#(Object, KeyFrame, Limb, 3)

For each object there can be up to 1000 keyframes, and for each keyframe there can be up to 1000 limbs with an X, Y and Z offset.

When I set keyframe 10, I say: ObjectLimbOffset#(1, 1) = 10 and then follow it with all the limb offset numbers. Then if I want to set Keyframe 5, I say ObjectLimbOffset#(1, 2) = 5 instead. But in the arrays, Keyframe 5 now follows Keyframe 10, and I want to swap them over. I've tried Bubble sorting, but it doesn't seem to do anything at all.

Could someone take a look at my code and give me a hand please?




Another problem I've got is that whenever I delete a keyframe, I get a gap in the array and I can't shuffle the other data around to fill it.

On our way 'ome, on our way 'ome...
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 8th Nov 2007 00:51 Edited at: 8th Nov 2007 00:53
Quote: "I've tried Bubble sorting, but it doesn't seem to do anything at all."


Your array:

ObjectLimbOffset#(Object, KeyFrame, Limb, 3)

has 4 subscripts.

Quote: "When I set keyframe 10, I say: ObjectLimbOffset#(1, 1) = 10"


Here you are only using 2. I've never misused arrays like that before so I don't actually know if DB accepts it or not, but even if it does, it might be the reason your bubble sort isn't working.

You also don't have to enclose If..Endif conditions in parenthesis either (like you do in Delphi) - but that won't have anything to do with your sorting problem.

Finally, do you have to use float arrays? Integer arrays are much, much faster if you can get away with using them instead. When you do get the sort working, with the number of sub-elements you have as a maximum, a float sort would take forever! Maybe...

TDK_Man

Robert The Robot
18
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 12th Nov 2007 12:14
I've got it working!!

I hadn't realised that you weren't supposed to do this kind of thing with arrays - but DB seems to handle it fine.

Quote: "Do you have to use float arrays?"


Yes - the knight model is just 25 units tall, and limb offsets will run into many decimal places. But your advice about integer arrays did set me thinking. I can't do anything with my main float arrays, so I created a separate indexing integer array:

Keyframes(ObjectLimit, KeyframeLimit, 2)

For each object, there are 1000 keyframes and two pieces of data on each one - the Keyframe number, and the position in the main arrays of that particular keyframe. I can bubble sort this array quickly and easily (that's the only sorting type I know, I must remember to look up some others), and always get the objects limbs in the correct positions for editing!

Many thanks, RTR

On our way 'ome, on our way 'ome...

Login to post a reply

Server time is: 2025-05-31 21:04:44
Your offset time is: 2025-05-31 21:04:44