Notifications
Clear all

[Closed] Math Incorrect for Parameter Wiring?

Hey fellas,

I've been working on a script that makes a light's color dependant on it's location.
However, I've narrowed down a problem to a single location; the parameter wiring!
Check this out:

    o = omniLight()
    position = o.pos = [1,1,1]
    temp = position.z / sqrt(position.x^2 + position.y^2 + position.z^2)
    o.color = temp * [120,120,120] as color
    
This creates an Omnilight with 69,69,69 as the color.  Seems straight forward...

Now try this:
Go into the wire-params editor.  Rig up a parameter relationship FROM Position TO Color- like in the image attached.  Include the same equation in the Expression box as shown below:

    (position.z / sqrt(position.x^2 + position.y^2 + position.z^2))* [120,120,120] as color
    
THIS method of calculating it, however, results in the color
[b](color 17666.9 17666.9 17666.9)[/b]

Am I to understand that math is different in Max depending on where you use it?
Any thoughts on what might be causing this?  I've been bashing my head against the monitor for 4 hours trying to figure this one out!
1 Reply

While MAXScript typically expresses color values as RGBA from 0 to 255, CONTROLLERS do not – they store color data in the range from 0 to 1.0.
So instead of multiplying by [120,120,120], you have to multiply by [120,120,120]/255 and the resulting color will be (color 69.282 69.282 69.282):

(position.z / sqrt(position.x^2 + position.y^2 + position.z^2))* [120,120,120]/255

or shorter

position.z / length position * [120,120,120]/255

or even shorter

position.z / length position * [0.470588,0.470588,0.470588]