Page 190
Quick Nav Bar
<<   Previous Contents
Selection
Op Index
Parent User Notes
Index
Glossary
Next   >>


Mathematical Expressions & Keys

Animating a ray trace requires some mathematical background. This animation will be simple in its movements so as not to be over-complicated. The below image was used in the image map on the rectangle. This image gave the rectangle a "felt table" look.

The script would look like:
Note that all keys are set for 30 frames.

<libpath "c:\w3\">
<lib "textures.w3d">

    <normalize>

<seed 10>

Keys let you set "trends" for any effect in the ray trace operator. The Keys operator works as follows:

Keys "keyname" frame1 value frame2 value… etc

<keys "cuemovex" 1 -12 15 -2 30 -5>

This is saying "From frame 1 to frame 15, I want the value of 'cuemovex' to go from -12 to -2. Then, from frame 15 to 30, I want the value of 'cuemovex' to go from -2 to -5."

This value is going to be used in the x-position of the cueball. That means that the cueball is going to move forward, and bounce back abruptly.

<keys "cuemovez" 1 0 15 0 30 3>
"From frame 1 to 15, 'cuemovez' will remain 0. From frame 15 to 30, the value of 'cuemovez' will go from 0 to 3."

This value will be used in the z-position of the cueball, that means that it's also going to move farther away, "into the screen."

<keys "cuerotz" 1 0 15 360 30 180>
This is going to be used in the z-rotation of the cueball, now it makes one complete rotation between frame 1 and 15, then rotates back half a turn.

<keys "cuerotx" 1 0 15 0 30 -5>
This is going to be used in the z rotation of the cueball. It will rotate just a bit about x when the abrupt bounce happens.

<keys "fourmove" 1 4 15 4 30 12>
This is going to be used as the x-position of the fourball, so it stays in place until frame 15, then shoots forward on x.
<keys "fourrotz" 1 0 15 0 30 180>
<keys "fourrotx" 1 0 15 0 30 5>

Pool ball:
    <position fourmove 0 0> <radius 3>
    This sets the x-position to where it gets its value for each frame from the key 'fourmove.' Now the pool ball will move.

    <apply "glossy">
    <reflectivity 0.1>
    <color 1 0 0>
    <rotate fourrotx 0 fourrotz>
    Now the fourball will rotate according to the key as well.

    <imagemap "c:\imagemaps\raytrace_imagemap_1.jpg">
    
<object sphere "My Sphere">
    <normalize>

Cue Ball:
    <position cuemovex 0 cuemovez> <radius 3>
    The cueball will move according to the keys.

    <apply "glossy">
    <rotate cuerotx 0 cuerotz>
    Now the cueball will rotate according to the key.

    <reflectivity 0.1>

    <specular 0>
    <roughness 0>

    <color 1 1 1>
    <color 0 0.5 1>
    <texturemap "marble" 0.01 30>

    
<object sphere "My Sphere">
    <normalize>

Felt:
The felt surface is going to be a arbitrarily large rectangle, to simulate a pool table surface, it will also be imagemapped with a tiling image of real felt.

<structure>
Rectangles have to be bound within a structure.
     <apply "matte">
     <ambient 0.5>
     <vtx0 10000 -3 10000>
     <vtx1 10000 -3 -10000>
     <vtx2 -10000 -3 10000>
     These are the vertices of the rectangle.
     <color 0 0.5 0>
     <tile 10000 10000>
     Tile the imagemap 10000 times on each axis, so it's a 10000x10000 square.
     <imagemap "c:\imagemaps\felttile.jpg">
<object rect "felt">
<normalize>
</structure>
This marks the end of the structure.

<object bound>

Light:
    <position 50 500 -750>
    The light was moved simply because it looked better there
    <color 1 1 1>
<object light "light_1">

<viewlocation 0 2 14>
The viewlocation was moved for the very same reason.
<viewtarget 0 0 0>
Now that the objects are centered around 0,0,0 instead of the pool ball being centered there, we can look straight at 0,0,0 again.


This is the end product of the script.

Some notes and tips for adding mathematical expressions to your ray traces:

Always remember that you must prefix an expression with '!' (an exclamation point). No whitespace is allowed inside the expression either, whitespace is the signal to the evaluator that the expression is complete.

Tip:

...a little something from the propeller-heads at Black Belt Systems
A simple boilerplate way to make circles is to add the following expressions:

!cos(loopv(cframe(0))*6.281835)*radius
!sin(loopv(cframe(0))*6.281835)*radius

Now it treats the frame number as a fractional part of one whole rotation. Now you just determine the raduis you want, and you have a circle.

You can also set a variable for the radius so it lives in one easy to find place by adding a key:

<keys "radius" 1 10>
Now "radius" will remain constant, and can be changed for all instances with little effort.

You can also model an oval by giving unequal radii for the sin and cos function.

Spinning the camera would be:

<viewlocation !cos(loopv(cframe(0))*6.281835)*radius 0 !sin(loopv(cframe(0))*6.281835)*radius>

This will move in a circle in/out and left/right, not up/down

Here is a list of valid expressions for the ray tracer's SceneScript.

Other examples


Quick Nav Bar
<<   Previous Contents
Selection
Op Index
Parent User Notes
Index
Glossary
Next   >>
Page 190

WinImages F/x, WinImages Morph and all associated documentation
Copyright © 1992-2007 Black Belt Systems ALL RIGHTS RESERVED Under the Pan-American Conventions

WinImages F/x Manual Version 7, Revision 5, Level B

HTML Documentation Management System © 1992-2007 Black Belt Systems