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.

Dark GDK / C++ equivalent for "OR"

Author
Message
Core2uu
16
Years of Service
User Offline
Joined: 15th Mar 2008
Location: Saskatoon, SK, Canada
Posted: 23rd Apr 2008 03:49
How do you say OR in C++? If I wanted to say "if ((this) OR (that)) {dothis;}" then how would I say it?

~~Core2uu~~
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 23rd Apr 2008 03:54 Edited at: 23rd Apr 2008 03:55
The logical or (the one you've asked about) is ||, the bitwise or is |
Logical and is &&, bitwise and is &
Not is !
xor (exclusive or) is ^

e.g. if (a == 0 || b == 0)
Core2uu
16
Years of Service
User Offline
Joined: 15th Mar 2008
Location: Saskatoon, SK, Canada
Posted: 23rd Apr 2008 04:18
What's the difference between logical and bitwise?

~~Core2uu~~
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 23rd Apr 2008 04:35 Edited at: 23rd Apr 2008 04:38
Logical checks the value of the expression, so it is either true (1), or false (0). Bitwise actually changes the variable when used with an assignment. Bitwise operations are used to create flag variables, for example.

Let's say that you have a DWORD (32-bit) variable, designed to carry 32 on/off conditions, one for each bit. Let's go a step further and define what the flags are for two of those bits.

#define FLAG_1 0x00000001
#define FLAG_2 0x00000002

I can turn on both of them like this:

DWORD myflag = FLAG_1 | FLAG_2;

To check myflag, I can use:

if (myflag & FLAG_1) // Means if FLAG_1 bit is set, or ON.

Otherwise, I would have to set flags using literal values, like:
myflag = 3;

You will eventually use both in a single expression:
if (myflag & FLAG_1 || myflag & FLAG_2)

That means, if either FLAG_1 OR FLAG_2 is set...
Let's say FLAG_2 is set, but FLAG_1 is not,

myflag & FLAG_1 == 0
myflag & FLAG_2 == 1

In this case, the myflag variable is not changed in any way.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 23rd Apr 2008 04:43 Edited at: 23rd Apr 2008 04:43
Assume that a logical operation can only return a single true or false. That's what happens when you do a comparison test for example.

A < B

as an expression returns a true or false based on the values of A and B. You'd do a logical and or or when testing whether two or more of these comparisons are true or not.

if (A < B && C > D) {....}

This means that for the statements in the braces to happen A must be less than B AND C must be greater than D) If you used ||

if (A < B || C > D) {....}

then either A can be less and B or C can be greater than D and the statement will be executed. For it to fail, both must be false.

A bitwise AND or OR matches up the bit position of larger bit patterns. Often an integer or other numeric type is used to store a collection of single bits that aren't intended to necessarily be related.

Let's say you have two true/false on/off conditions you want to track. I'll use an 8 bit variable for this for brevity.

UINT8 MachineStatus = 0;

and it would look like this initially.

00000000

Let's say you want to track if the machine is on or of and if there's a warning condition. We'll use the least significant bit tell us if the machine is on or off and the next LSB to tell us if there's a warning condition. For now we'll assume that some other part of the program sets these and all we want to do is test them.

#define MACHINE_ON 1;
#define MACHINE_WARNING 2;

These represent bit positions 00000001 and 00000010 respectively.

To test if the machine is on we can do

if (MachineStatus & MACHINE_ON) {....}

what this does is matches up the bit position of the two numbers

00000001 MachineStatus
00000001 MACHINE_ON (mask)
--------
00000001 result of anding
by anding these together we're saying if both bit positions are 1 (true) the result for that bit position is true. If either zero then the result for that bit position is zero.

if we bitwise or them then either bit position can be 1 and the matching result bit is 1. Both of them have to be zero (false) for that position to be zero in the result. That's how we set bits in a result by making the bit position in the mask equal to zero.

MachineStatus = MachineStatus | MACHINE_ON;

sets the first bit on. We can also short hand this with

MachineStatus |= MACHINE_ON.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Core2uu
16
Years of Service
User Offline
Joined: 15th Mar 2008
Location: Saskatoon, SK, Canada
Posted: 23rd Apr 2008 04:46 Edited at: 23rd Apr 2008 04:50
OK... Why did I ask that question? I already knew the answer... Well I guess the word bitwise confused me but I know what you mean... Although this flag thing is new to me so thanks for introducing that to me...

OK, while I have your attention and since my last thread was ignored I'll ask you...

I'm making a fighter... dbObjectCollision is OK but I don't entirely like it because if its not polygon detection it's not really realistic... What I want to ask you is how fast is dbIntersectObject and would it be better for me to use that or a third-party collision detection like Sparky's etc. And during animation the character does move but the coll. detection sphere is still in the same place... If the object moves in animations will the polygon detection detect its original position or the seen one?

EDIT: You beat me to posting Lilith... Thanks for the in detail explanation of anding, now bitwise makes even more sense...

~~It's not who you are underneath, but what you do that defines you.~~
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 23rd Apr 2008 04:51
I'll have to leave that to jinzai. I haven't jumped into 3D at this point.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 23rd Apr 2008 05:43
Do you know the answer already?

Sparky's I hear doesn't do Animation Collision. For me it seemed to work with rotated limbs though.

Intersect Object and tobi has his own he made - that I guess is slower than Sparky, but faster than intersect object, and handles Animation.

Intersect Object handles Animation - if set to poly collision.

anyone correct me if I'm wrong here.

Core2uu
16
Years of Service
User Offline
Joined: 15th Mar 2008
Location: Saskatoon, SK, Canada
Posted: 23rd Apr 2008 05:58
I recently checked out Toby's version and it indeed is MUCH faster than intersect object... It's a compromise between speed and anim. detection and that absolutely works for me... The only thing is I'm sorta scared of the larger amount of code and replacement of the existing, but hey, if you want the best you have to work for it...

And no Jason I did not already know the answer... I wanted to know if any of these handled animation but I did not know previously... So a sincere thanks to you and all other forum members for providing a helping hand(s).

~~It's not who you are underneath, but what you do that defines you.~~
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 23rd Apr 2008 06:12
(I was just being coy because I saw two people write BOOKS to explain something you then claimed you knew the answer for. I personally would have just said thank you so they didn't feel like they wasted their time LOL )

Toby is a very good coder. You see his StarWars Game? Its Grrreeeat! (Like frosted Flakes Cereal)

I just learned about his collision code and the nice thing about it he gives ya the source. Something you won't get from TGC naturally, and MAYBE someday we'll see Sparky's but - regardless... All these systems have their pros and cons. Everything has its pros and cons.

I'm glad to hear Toby's is faster than intersect. He said it was - but its great to hear positive feed back from others.. just reenforces it YAY TOBY!

Have a great night Bro!

Core2uu
16
Years of Service
User Offline
Joined: 15th Mar 2008
Location: Saskatoon, SK, Canada
Posted: 23rd Apr 2008 06:26
Just for your information I knew the difference between == and = BUT I did not know the concept of polybit (if that's even a word) variables which was what Lilith and Jinzai discussed at length in their posts and I'm very glad they did...

Once again thanks and YAY TOBY!

P.S. You don't have to reply to this post because I know you're time will be better spent elsewhere helping someone else...

~~It's not who you are underneath, but what you do that defines you.~~
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 23rd Apr 2008 13:36
Bah... I just told you what it looked like when I read it... Lighten up

jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 23rd Apr 2008 14:12
My Wife said I sounded snippy and read your post wrong. (I asked her about it... yup) I wasn't trying to sound snippy... And I myself have done things not knowing what they were technially called ... and then found out some phrases people were throwing around - I thought "were beyond me" I was already doing.

So.. I wasn't meaning to sound snippy... and then when you seemed upset - something I didn't want you to be - I said lighten up.. because I wasn't even feeling hostile at all - in both post.

so I'm Sorry.

Core2uu
16
Years of Service
User Offline
Joined: 15th Mar 2008
Location: Saskatoon, SK, Canada
Posted: 24th Apr 2008 01:07 Edited at: 24th Apr 2008 01:09
I should make better use of emoticons... I was at no point angry with you or anybody here... And why would I be? You never said anything to anger me... You were helping me and I'm very thankful to you... So there is no need for any apologies at all from anybody... Anyways now that we're all cool... it's good...

~~It's not who you are underneath, but what you do that defines you.~~
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 24th Apr 2008 03:56
tobi453
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location:
Posted: 24th Apr 2008 19:45
hi,

In my opinion the reason it is slower than sparky is not that it does work with animated objects.

I think there is still a lot of potential for optimization. The faces of a limb are grouped in groups and if you optimize the grouping process and add subgroups and subsubgroups etc.. you might be able to double the speed or more.
So it's up to you. I'm busy with grass, AI and other things.

FINAL VERSION RELEASED!!!!

Login to post a reply

Server time is: 2024-09-29 19:14:19
Your offset time is: 2024-09-29 19:14:19