![]() |
||||||
|
PISTON Walkthrough No. E1 |
||||||
|
OBJECTIVE: to write a program in Cinema 4d R8 in Xpresso to cause a piston, driven by a crank, to move realistically, and in a straight line (as might be inside the cylinder of a steam or petrol engine). (See also Walkthrough E1A-Piston 2). The first step in any computer programming task is to be clear about the objective that is to be achieved, (see above), followed by a statement of the logic that the program is to follow to achieve that objective. Skipping these steps leads to muddle, frustration and waste of time. LOGIC 1. Create the Crank, connecting rod (Conrod) and Piston. 2. Join the Conrod to the upper end of the Crank and animate both to rotate around the other end of the Crank. 3. Make the Conrod always point towards the Piston. 4. Make the Piston move left and right in a straight line (as it would slide in and out of an engine cylinder) in a way as in a real engine (that is, slowing down at each end of its movement). Walkthrough E1A shows another way of doing this. Creation of the Scene Download the above Project file and load into Cinema. The file is already complete. Choose Front view of the Viewport and run the animation to get an idea of how it works. This Walkthrough assumes that you know the basics of creating Objects and how to set up a simple animation. Therefore examine the Object Manager and the Timeline to familiarise yourself. The Crank and the Conrod are simply thin Primitive Cubes. However, they have been made Editable (Main Menu Bar > Structure > Make Editable) because both must have their Object Axes moved to their ends to make the Crank rotate about its end and to make the end of the Conrod connect to the Crank. The Piston is a Primitive Cylinder (not made Editable). The Conrod has a Target Expression attached to it (Object Manager) and when double-clicked the Attribute Manager : Tag button shows that the target of its affections is the Piston. A target Expression makes the object to which it is attached always point at its target. Two more Objects have been added - the Crank Shaft and the Crank Joint. These are simple spheres to represent the moving joints, but Crank Joint has an important job to do (see below). So far, this is conventional modelling with no Xpresso involved. The Xpresso Expression To see the Xpresso Expression, open the Object Manager and locate the Null Object. Double-click its Xpresso Tag: Driving the Piston We need to have a system to drive the piston right and left in a realistic way, which means that it must slow down at both ends of its movement. (Not much in the world stops or starts instantly and 3d modelling must allow for gradual slowdowns or startups nearly everywhere.) To get that, we must generate a Suitable Sequence of Numbers which will be used as the Piston's X-Coordinates. Those numbers must start at a certain middle value (the middle position of the Piston) increase as the Piston moves to the right but that increase must slow down until the numbers stop increasing. Then the numbers must start reducing, slowly at first, than faster, past the middle value, still reducing but more slowly until the numbers stop reducing. Then they must start increasing again, slowly then faster until the middle value is reached again, at the end of the cycle. How can we generate such a sequence of numbers? That is where the Crank Joint Node comes in. |
||||||