Morrowind Mod talk:Math Functions

The UESPWiki – Your source for The Elder Scrolls since 1995
Jump to: navigation, search

Rather Spammy Additions by Yacoby[edit]

Modulo gives you the remainder of division operation. One common use would be to get the rotation of an object within the range of 0 to 360 degrees. (Remembering maths classes: if angle, x, is greater than 360 degrees, it is the same angle as the remainder of x/360)

Working with the example above, the simple way to do it would be to keep removing 360 from the angle, until the angle is < 360

while ( x > 360 )
    set x to x - 360

While this works fine, it is horribly inefficient.

(Switching to a more maths like notation) We know that the angle, x is made up of n 360s and a remainder

x = n*360 + r

For example, 520 = 1*360 + 160

We also know that the remainder is always less than 360 (otherwise n would go up by 1). So with that information we can derive:

n = floor(x/360)

(floor is a function to round down to an integer)

If we subsitute everything back into the original equation

x = n*360 + r
  = floor(x/360)*360 + r

r = x - floor(x/360)*360

Morrowind doesn't have a floor function, but you can achieve the same result by converting a floating point number to an integer (i.e converting a float to a short).

Putting it all together gives:

float x ;the angle
short n ;the number of times 360 goes into x
float r ;the remainder

;calculate n
set n to ( x / 360 )

set r to (x - n*360)


I'm just going to revert this to a usable form. I mean, sure, only me and a few others actually use this page... but the point is to provide functions... and this really doesn't improve the function rather than explain the need for it (again, only a single example involving angles).

All in all, He took the time to write it so I'll leave it here... but it does not belong in the article when it does not improve it in any fashion or form