Scalevar: Difference between revisions

From EDukeWiki
Jump to navigation Jump to search
Fox (talk | contribs)
No edit summary
NY00123 (talk | contribs)
mNo edit summary
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
'''mulscale''' <Result> <Factor 1> <Factor 2> <Divisor>
'''scalevar''' <Result> <Factor 1> <Factor 2> <Divisor>


In C terms, this command performs roughly the expression <code><Result> = (<Factor 1> * <Factor 2>) / <Divisor></code>.
In C terms, this command performs roughly the expression <code><Result> = (<Factor 1> * <Factor 2>) / <Divisor></code>.
Line 16: Line 16:


Note that the equation above is very likely to surpass 31 bits. Using 16 bits of precision for rotatesprite, the maximum screen coordinate would be 327. So '''scalevar''' is required.
Note that the equation above is very likely to surpass 31 bits. Using 16 bits of precision for rotatesprite, the maximum screen coordinate would be 327. So '''scalevar''' is required.
See also [[mulscale]] and [[divscale]].


[[Category:EDuke32 specific commands]]
[[Category:EDuke32 specific commands]]
[[Category:Gamevar manipulation]]
[[Category:Gamevar manipulation]]

Latest revision as of 02:33, 13 May 2023

scalevar <Result> <Factor 1> <Factor 2> <Divisor>

In C terms, this command performs roughly the expression <Result> = (<Factor 1> * <Factor 2>) / <Divisor>.

In CON terms, it is very similar to the following series of commands:

set <Result> <Factor 1>
mul <Result> <Factor 2>
div <Result> <Divisor>

The main difference is that the calculation uses 64 bits to prevent overflow, while using gamevars for intermediate values would limit it to 31 bits.

For example, statusbarscale use a scaling factor of 100. If you wanted to scale the screen coordinates of a sprite, you would do:

 scalevar Result Coordinate userdef[].statusbarscale 100

Note that the equation above is very likely to surpass 31 bits. Using 16 bits of precision for rotatesprite, the maximum screen coordinate would be 327. So scalevar is required.

See also mulscale and divscale.