|
14 We need a Compare Node. As in Step 12 CMND+CLICK on a blank part of the Xpresso Editor window and choose New Node > Xpresso > Logic > Compare. Drag this to the right of the Math Node. It has two Input Nodes. We need to send to Input 1 the Output of the Math Node (ie., the distance between the two Objects.) Therefore, Link these two Ports together. 15 Select the Compare Node (click on it) and in the Attribute Manager, press the "Node" Button. In the "Data Type" Field choose "Integer" and in the "Function Field" choose "<" (less than). 16 The other Input Port of the Compare Node needs to be provided with the distance (300) between the Light and the Cube (Step 4). Therefore, Select the Compare Node again (click on it) and open the Attribute Manager. Press the "Parameter" button and in the "Input 2" Field type "300". (This Port has no Link.) The Compare Node will deliver a Boolean "True" value at its Output Port if the X-distance is less than 300 or a "False" value if greater. 17 The light obviously needs to be arranged to switch on and off according to the output of the Compare Node. As in Step 10, from the Object Manager, drag the name of the Light Object into the right side of the Xpresso Editor Window. A Light Node will appear. Click on its Blue Box and from the menu that appears choose "General" > "Brightness". Finally, Link the Output Port of the Compare Node to the Input Port of the Light Node. The Output Port of the Compare Node will therefore switch the brightness of the Light from off (0% brightness) to on (100% brightness). The result should look like this:
18 To test your program, in Cinema's Viewport (preferably in Perspective) position the Cube conveniently near the origin and the Light more than 300 m along the X-axis to the right. Move the Cube (or the Light) along the X-axis until they are less than 300 m apart measured on the X-axis. The light should switch on. To confirm the distance, select each of the objects in turn and subtract the two values for the X-axis readings. (You will notice that if the light is moved more than 300 m to the left of the cube, it stays on. This is most probably because the 300 m setting is being interpreted as "+300". That is, 300 m to the right.) 19 So what can we learn from all this? Xpresso is a method of programming with graphical blocks instead of computer code. As a result it seems much easier for people who find coding baffling and tedious. Its logical structure is much easier to see and the whole thing is much more elegant. But, in complex programs such as those involving Thinking Particles, you need to keep a clear head when debugging, or when trying to choose the correct ports for so many Nodes. The average Node can have several ports, some with several settings each, and a medium-complex Expression would include 10 nodes. That makes a lot of choices. However, I am not a programmer. I designed this program from scratch myself, without the manuals (which were not yet available), and it worked first time! If I can do it you can do it. |
||