Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

vectors and rotations as data structures

Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
05-04-2005 22:19
I want to share a little trick I used on a recent project. I needed to store a lot of data and work with it easily, and I really wanted to be able to treat several properties as one coherent unit in my code. My data was represented by a group of four small integers, so I used rotations. It turns out that rotations aren't treated specially unless you actually pass them to rotation functions, but of course I wasn't going to do that. I just wanted to be able to store my "structures" in lists.

One thing this let me do was to compare two rotations to see if they represented the same object by just using the == operator. Sure, rotations have floats in them, and you're never supposed to use == with floats because they're inaccurate. But in this case, because I was always using small integers in the four parts of my rotations, they were always exact. Comparing with == always works in that case.

Also, rotations can be addressed with dot notation to get at the four parts, and I would assume this is an O(1) operation. It could be a pain that you can't address them by a number, but you could get around this with a little accessor function. It's not like it's any worse than using list functions.

You can do this with rotations or vectors. I used vectors to store 2d coordinates, with the Z value always 0. It's just a convenience thing.
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
05-05-2005 13:28
Yep - I've done this before for an earlier project. Fun, isn't it? :)
_____________________
---