%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
![]() |
![]() |
||
|
creating your own waveform controller Hey folks. Welcome to the first math tutorial. In this tutorial, I'll teach you how to 'program' your very own waveform controller. We'll use max expressions to create a quite simple waveform controller. It doesn't have the control the native waveform controller provides, but it has a major advantage over the waveform controller. Since you're creating the variables to be used, nothing is hard-coded. You can use any values you see fit. We'll be hard-coding values into it, but you can change that to referencing-variables, so you can use any available track in your scene (an object's custom attributes, global tracks, etc) to change these values. This will also allow you to animate them! So, let's get to it!! PREPARING THE SCENE This
will be quite simple. Just create an object of your liking to test the
controller on. I used the good ol' teapot. So, create it and move it to
[0,0,0]. sin(F) F is a system-only variable, which means you MAY NEVER use it and assign values to it. F means frames. We want our controller to be time-dependant, which means its value will be changing over time. So, that's why we're using F here. If you click play, you'll see the teapot (or whatever you chose to create) going up and down over time. The movement, however, is very slow, and very small. The default values used by this expression provide an amplitude of 1 (which means the object will go from -1 to 1 units), and a period of 270 frames (which means it'll take 270 frames for the controller to complete a cycle). Therefore, we have a slow, subtle movement. We need a way of controlling the amplitude and period of the waveform in order to have a useful controller. Let's start with the period. We don't want to hard code the values into the expression, so we'll use variables instead. These variables will have hard-coded values, but this way, it's very easy to change them into referencing varaibles afterwards. So, create a scalar variable named period. Once created, assign a constant value of 9 to it. Now, change the expression to read... sin(F*period) Hit the evaluate button. I recommend having the function curve editor open displaying this expression's track fcurve, so you can see the changes in the animation's fcurve. You'll notice the movement is quicker now, but still subtle. Lower values in the period variable will change the animation into a slower movement, whereas higher values will shorten the resulting sine wave amplitude, creating faster movements. The default value of 9 used above will result in a waveform period of 30 frames. A value of 3 will create a waveform period of 90 frames. A value of 9 will stretch the period to 270 frames. And so on... Now, let's take care of the amplitude of the waveform. Create a scalar variable named amplitude, and assign a constant value of 100 to it. Change the expression to read... (sin(F*period)*amplitude) You'll notice immediately a drastic difference. This is a very straightforward value. The value you assign to this variable will be the amplitude of the resulting waveform. In our case, a value of 100 yields a movement that goes from -100 to 100 world units. Therefore, changing this value will change the amplitude of the resulting waveform in a quite direct fashion. So, we have now a quite nice little waveform controller. It is still, however, missing some important features in order for it to be usable. Let's add offseting of the curve to it. What I mean by this, is the ability to offset the curve in time and space. This means you should be able to move the fcurve in both space (make the movement start higher or lower in Z) and time (offset the fcurve so the waveform starts lower or higher in the curve). Let's add first vertical offset. Create a scalar variable named yOffset and assign a constant value of 0 to it. Change the expression to read... (sin(F*period)*amplitude)+yOffset As you can see, nothing has changed. That's because the variable has a value of 0. Change that to 50. Evaluate the expression... You'll see your object move 50 units in Z. Now, the movement goes from -50 to 150. This value is very straight forward. It'll move the curve in Z in the number of units you specify. Let's take a look at horizontal (temporal) offset... Create a new scalar variable named xOffset, and assign a constant value of 90 to it. Change the expression to read... (sin(F*period+xOffset)*amplitude)+yOffset As you can see, the fcurve changed to begin the movement at the peak of the resulting waveform, instead of the center. A value of 90 will move you to the highest peak. A value of -90 to the lowest. A value of 0 will re-center the resulting waveform. Hey!! Congratulations!! You now have a quite functional waveform controller there! You may use it as you see fit. As I mentioned, you can change these variables to reference other tracks, so you may animate them and have a dynamic waveform controller (something you CAN'T do with the waveform controller!! HA!!). ;) So, there you are. I hope you understood the principals behind all this. Don't hesitate to email me if you have any questions. But please, before you do, take out those high-school math books and start going through the pages... you'll find invaluable info there! Till the next time!! Take care!! Sergio Muciño. Copyright 2003. |
|||