Goal of this tutorial
This is a further tutorial on functional objects. We want to animate a part of a diggers arm containing of a joint and a hydraulic cylinder. In detail we want to work rotations to animate the arms movement and make use of pointing joints to animate the hydraulic cylinder.
Assumptions
All previous tutorial are finished. PADrend is opened and the scene tut5_scene.minsg (see [tut5scene](/Tutorials/Tutorials/User_Guide/5_Functional_Objects_Pointing_Joint/scene/tut5_scene.minsg)) is loaded. Infinite ground and dynamic sky are enabled. The _ObjectFactories plugin is activated.
Adding rotation to the main joint
We start this tutorial by animating the rotation of the arm around the main joints axis. Open the object placer and drag out a Functional/RotationAxis. Place it somewhere on the ground not too far away from the arm. Give it some name like mainJointRotationAxis. Rotate it by 90 degrees around the x-axis.
Next up we need to align the rotation axis with the main joints axis. Thankfully PADrend provides us with a functionality that can do the job. To use this functionality it is very important to select the node that should be aligned and the node that is used for the alignment in the correct order. Select first the node that should be aligned. In our case this is the rotation axis. Afterwards select the second node. We want to align the rotation axis to the main joints axis. First select the rotation axis. Than hold down the [shift] key and select node midJointAxis. Now both nodes should be selected.
Right click to open the context menu. Select Node Tools and than Alignment. You will find some menu points and a combobox. You can use the combobox to choose an alignment position within the second node. Make sure that BB center is selected.
Click on common position and the rotation axis will be aligned to the joint axis.
Next up create a link between the rotation axis and the node upperArm.
Use transformSnapOffset as role name.
Test if the rotation works correctly by rotating the rotation axis.
Animating the hydraulic cylinder
For the animation of the hydraulic cylinder we use the Animation/PointingJoint object trait. The trait can be used to align a node between two anchor points. One of the anchor points is the mount anchor point. The nodes top will snap to it. The second anchor point is the target anchor point. The nodes bottom will align to it. When one of the anchor points gets moved by some transformation the node will also move to keep its alignment to the two anchor points.
Creating the anchors
First we need to create the anchor points. Select the anchor tool from the toolbar. Select the node named TieRod. Open the context menu by a right click. Select New Anchor, name it lowerMountPoint and click Create.
Next up the anchor needs a position. Open the context menu again and locate [lowerMountPoint]. Search for Positon (relative to bb) to position it relative to the nodes bounding box. Type in [0.5, 0, 0.5] and press return.
We do not need the anchor point at the TieRod but we need it at the lowerArm. However we created it at the TieRod since it makes the positioning much easier. In the next step we copy the anchor from the TieRod to the lowerArm. In order to copy the anchor we need to select both nodes. Since the nodes are stored on different levels of the scene graph it is useful to store each selection individually.
Using the selection store tool
You may have already noticed that there are numbers form one to nine in the toolbar. This numbers can be used to store selections. If you have selected one or more nodes and you know that you need the same selection later on, you can store your selection. Select a node. To store your selection simply click on the number you want to use. You can also press [ctrl] followed by one of the keys [0] … [9]. The numbers that store a selection will be highlighted. To overwrite a stored selection you can either use the keyboard method the keyboard like before or you right click onto a number and hit Store Selection. If you want to use your stored selection click on the number you have stored it or hit the number on your keyboard. Hitting the number twice will focus the node.
Coping the anchor
Make sure the anchor tool is still active. Store the selection of each node. To use the copy tool it is again important to select the nodes in the correct order. Use your stored selection and select first lowerArm then hold down shift and select TieRod. Open the context menu by a right click and select Copy Anchor.
A window will appear. Use the combobox Source Anchor to select the anchor you want to copy. With use of the textfield Target Anchor you can change the name of the anchor that will be created at the target node. Hit copy and the anchor will be copied.
In the same manner create an anchor for the node piston. Name it upperMountPoint and position it at [0.5, 1, 0.5] relative to the bounding box. Copy it to node upperArm.
Creating the pointing joint animation
To ensure the animation to work correctly, we use position proxies to build up the pointing joint animation.
The hydraulic cylinder itself will be connected to them later in a later step.
Drag out two position proxies and name one upperMount and the other one lowerMount.
Let us start with the upperMount proxy.
Select it in the object explorer and add an Animation/PointingJoint object trait to it.
The trait provides you with two comboboxes which you can use to choose the mount and target anchor point. The trait also provides two link roles to connect the nodes that contain the both anchor points. Connect node upperArm via link role mountAnchor to the proxy. Next up connect node lowerArm to the proxy by using the link role targetAnchor.
You should now find the anchor point upperMountPoint in the combobox mountAnchorId and the anchor point lowerMountPoint in the combobox targetAnchorId. The position proxy should now be snapped to the anchor point uppermount. Select both anchors via the comboboxes.
Do the same for the lowerMount position proxy, but change the order of the links.
Link role mountAnchor is now connected to lowerArm and targetAnchor to upperArm.
Next up we connect the hydraulic cylinder to the position proxies.
Connect the upperMount proxy to the nodes Piston and pistonJointAxis and the lowertMount proxy to the nodes TieRod and tieRodJointAxis.
Use transformSnapOffset as link role.
Try out if every thing works correctly. Pick the mainJointRotationAxis and rotate it. The hydraulic cylinder should align to both mount points and move like a real hydraulic cylinder. The arm should rotate around its joint axis. Undo your rotation after trying.
Adding an animator
To get the animation running we need to add an animator. Open the object placer and drag out a Functional/ConstraindeMotor object. Restrict the maximum time of the motor to 2. Open the mainJointRotationAxis in the object explorer and connect it to the motor via a link. Set the rotation to 30 degrees per second. Start the motor to try out if everything works correctly. If the arm rotates in the wrong direction set the rotation to -30 degrees per second