Cinema 4D / BodyPaint 3D Program Documentation Tutorials XPresso Tutorial
Function available in CINEMA 4D Prime, Visualize, Broadcast, Studio & BodyPaint 3D

Boolean Algebra

In the course of the XPresso tutorial we have run across the occasional term "boole" or "boolean", for example in the section about data types where we explained that a boole value can be either True or False. These states are part of what is called propositional logic, which is a part of many functions. This is why we will take a closer look at this topic in the following.

Imagine you are sitting in the office and someone approaches us and informs us that it’s raining outside. This person has made a statement whose accuracy we want to verify. So we look out of the window and see that it’s raining. The person told the truth so his statement was correct. We can add an action to this verification: If it’s raining we will take an umbrella with us when we go outside. Hence, we added a condition to an action. But what does this have to do with a data type in Cinema 4D? In the case of our weather example we checked the validity of the statement and decided on a course of action (taking an umbrella), depending on the outcome of the statement (true or false).

Exactly these conditions are required for quite a number circumstances in order to make an object behave the way it should or change its properties. Right-click in the XPresso Editor and create a BooleNode (New Node/XPresso/Boole). This Node is designed to process multiple conditions. In the Node’s Node tab in the Attribute Manager you will see a Function parameter, which offers several options from which to choose for defining the condition under which the output Port generates a True value.

Boolean Operations

A condition can be linked to a statement via multiple links. Among these links are AND, OR, NOR as well as several others.

AND

In order for the statement to be correct, all statements must be correct.

Example: If it’s raining outside and I walked to work I will walk home with an umbrella.

OR

The statement is correct if at least one condition is true.

Example: If I have nothing more to drink or if I am hungry I will go to the supermarket.

NOT

The state of a statement will be switched. A false statement will be correct and a correct statement will be false. This operation is also referred to as "negation".

NAND

A NAND link is equal to the behavior of a normal AND condition but the result will be negated. Hence, if both statements of a condition are correct the statement will be false (see NOT).

NOR

A NOR link is an OR condition whose result will be negated (see NOT).

XOR

Here a condition must be correct. If both statements are true or false the result will always be false.

XAND

If statements are linked via a XAND condition the states of all statements must be the same. The statements with a normal AND condition must all be fulfilled.

Example:

In this example we will have a light source turn on when the Light object lies between the values of 200 and 300 on the X axis. Before we start setting up the Expression we must create the objects. First, create a new scene and position a Light object anywhere in the scene. Then add an XPresso tag to this object.

Since our Expression requires the light’s X Position value we will drag the Light object into the XPresso Editor window. Create an Position.X output Port for the Light object, which will output the object’s X position. Our condition will be met if the Light object’s Position.X value is greater than 200 and less than 300. We will be comparing a value to two conditions that are linked with each other. Hence we will also require two comparison Nodes for our Expression (New Node/XPresso/Logic).

The data type in both cases is Real. For the top Compare node, the output must be True if the comparison constant at Input 1 is 300 units larger or equal to the X position; the function required is Larger equal.

Analog to this, the lower node’s Output value must be True if the X position of the light source at Input 1 is equal to the value of the comparison constant 200.

We can now turn our Light object on in accordance with value put out by the Compare Node. We will use the Boole Node to verify whether or not both values are equal, at which point the value True will be output by the output Port. We now have a new Object Node that is connected with the Light object and we will add an Enabled Port, which will activate or deactivate the Light object accordingly. Once the Node has been added, connect the Boole Node’s output port to the newly created Object Node’s input Port.

Check to see if everything works correctly by moving the Light object along its X axis. The light will be deactivated in the Object Manager if the light lies within the appropriate region.