Game Development Community

Bit()?

by John Vanderbeck · in Torque Game Builder · 03/29/2005 (6:37 am) · 3 replies

Ok i'm goign to admit it right here and now and beg for help.

I've been a programmer for going on 20 years now. Worked on games in one way or another for probably nearly half that, yet bitwise operations have always confused the living heck out of me.

I typically stumble my way through, read some domb tutorial that never fully explains it but manages to answer my problem of the moment, then move one.

And here I am runnign into it yet again. Obviously it seems to me that the setCollisionMasks() function is doign some for of packign bits or whatever you call it and i'm lost.

Is anyone here capablae of providing a good english easy to understand lesson on how to actually UNDERSTAND this stuff? I have 3 seperate layers right now and more on the way and I really need to udnerstand how to specify which layers/groups collide with what but it just makes my head spin.

#1
03/29/2005 (6:47 am)
I don't really get it either, but so you can continue programming, the answer to your question regarding setting up colllision masks:

.setCollisionMask( BIT(groupNum) | BIT(groupNum)... , BIT(layerNum) | BIT(layerNum)... );

Some links to people discussing it:
www.garagegames.com/mg/forums/result.thread.php?qt=26749
www.garagegames.com/mg/forums/result.thread.php?qt=26880

I dunno if that helps, but it helped me in getting going.
#2
03/29/2005 (7:00 am)
Thanks Matt that keeps me moving hehe.
#3
03/30/2005 (3:24 am)
An integer has 32 bits, that is, its a string on 32 1s or 0s. You probably knew that.
Im assuming BIT(number) gives a number that has bit "number" set to 1. So BIT(2) would give
00000000000000000000000000000100 (assuming the rightmost bit is bit# 0). You probably knew this as well.

Bitwise Or ( the | ) will look at each bit of a number and do an or on these. An or operation is true if either of the bits is true (on/one).

So 0001 | 1000 = 1001 as 0 | 1 = 1, 0 | 0 = 0, 0 | 0 = 0 and 1 | 0 = 1 (left to right evaluation).

Thats pretty much it... & works similarly, but ony returns true of both bits are set (one). So 1010 & 0011 = 0010.

Theres also stuff for not (inversion), xor etc. Pretty fun stuff :D