Implemented LinMap and LinInterpolate to cerberus.math?

Holzchopf

Moderator
3rd Party Module Dev
Tutorial Author
Joined
Jul 31, 2017
Messages
496
Hi there

I'm suggesting adding the two functions to cerberus.math:

LinMap : Float ( dt:Float, t0:Float, t1:Float ) - returns percentage of where about dt is in the range of t0 to t1. No clamping performed.

LinInterpolate : Float ( t0:Float, t1:Float, dt:Float ) - interpolates between t0 and t1 at dt. No clamping performed.

If there are not enough concerns mentioned to stop me from this, I will implement and document them by the end of the week or so and bother Mike with a pull request on GitHub ;)

Cheers
 

MikeHart

Administrator
Joined
Jun 19, 2017
Messages
3,167
That is basically a tweening method, right? How about implementing other methods too.
 

Holzchopf

Moderator
3rd Party Module Dev
Tutorial Author
Joined
Jul 31, 2017
Messages
496
Tweening, exactly! Well except for LinMap. You're right about even more. My suggestions so far:


TweenLinear

Linear interpolation between two values. Useful for all kinds of stuff.

tween-linear.png



TweenIntermediate

2nd degree polynomial interpolation between two values with one support point at x=0.5. For accelerating or decelerating transitions. Also for pulses.

tween-intermediate.png



TweenSinusoidal

Sinusoidal interpolation between two values. Useful when start and end shall be smooth.

tween-sinusoidal.png



TweenFit

Interpolation between two values with their derivatives. Useful when start and end shall have specific slopes / fit in seamlessly between two adjacent curves.

tween-fitting.png



TweenFlats

Interpolation between two values with slope=0 each and one support point at x=0.5. Useful for smooth transitions and pulses.

tween-flats.png



Additionally, I would make CubicBezierEase a cerberus.math function too.


I'm very open for suggestions about the naming ;-)
 

Holzchopf

Moderator
3rd Party Module Dev
Tutorial Author
Joined
Jul 31, 2017
Messages
496
I'm struggling finding clever names. Tween as prefix is short, but as far as I've learned the term tween is not very well known outside the industry of computer graphics. So newcomers might not find the functions they're looking for as they're mislead by the term tween. For linear interpolation I often hear lerp (contraction of linear interpolation). But the same principle won't be applicable to the other interpolation methods...

Interpolate as prefix on the other hand is quite long and makes the function names look odd, IMHO: InterpolateLinear...

I guess I'm going for Tween and those names:

TweenLin
TweenCurve
TweenSin
TweenFit
TweenFlats
TweenCubicBezier


What do you think?
 

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Messages
644
I am not sure, if these functions should be placed in a math library. The main use case is for tweening/transition of objects. So I would like to see it in a framework together with all the mathematics for collisions, reflections etc. Maybe implement them into Mike's fantom engine.
If they go into the math library I would speak for a mathematical name like InterpolateLin, InterpolateCurve, ... so someone, who wants to use it for math curves, statistics etc can find it properly.

BTW I really think there should be a standard games framework shipped with cerberusX. You are free to use it or not, but it is there for quicker development.
At the moment I am using IgnitionX (mojo1) but it would be nice to have something alive and ready to use.
 

Holzchopf

Moderator
3rd Party Module Dev
Tutorial Author
Joined
Jul 31, 2017
Messages
496
I am not sure, if these functions should be placed in a math library. The main use case is for tweening/transition of objects. So I would like to see it in a framework together with all the mathematics for collisions, reflections etc. Maybe implement them into Mike's fantom engine

So anyone who's not using fantom then - for whatever reason - shall not have access to those functions? o_O I think I disagree.

On a second thought, naming them InterpolateLin etc. seems to be the cleverest solution. "Interpolate" is somewhat the most common term you would group this functionality in. AND everyone knows that term. No jargon used in industry to hide stuff from "uneducated" hobby coders :D
 

MikeHart

Administrator
Joined
Jun 19, 2017
Messages
3,167
I think CX should have a separate tweening functionality. A framework then can utilize it. Go ahead @Holzchopf .
 

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Messages
644
I am definitely not against those functionalities available for all, but I am a bit concerned about the risk of having a big math module with too many special functions in it. Some kind of grouping would be necessary. Just think about functions for intersections like line_line, line_circle, .rectangle_rectangle, polygons, ...
To me and I guess to a lot of new folks it would be useful to keep basic math functions easy to find. Just remember those a-z lists of functions we had in the docs before as a bad example.
 

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Messages
644
I have been pondering about this, because it is still part of math somehow. Maybe it is possible to put these functions inside a class inside the module math. So you would call them like the constants in class Image: Image.Midhandle
Then you could call the functions Interpolate.Curve(), but without any instances of the class.
This way we could have basic math functions without class and special functions are kind of grouped together: Collide.RectRect()
The only thing I am not sure about is, if this has any downsides technically like overhead or something else.
 

Holzchopf

Moderator
3rd Party Module Dev
Tutorial Author
Joined
Jul 31, 2017
Messages
496
I really see your point, it would be possible and I think static functions have no additional overhead. But still - it would not fit the current scheme of standard Cerberus X modules and I'd rather stick to that. Isn't there a language out there that does that, what you described, strictly? I mean consequently use static class functions like Math.sin, StdOut.printf and so on? What's it called again? Ah yeah: ugly.

Edit
Just to be clear: I made a joke. And I don't think static functions are ugly per se. I just think that since cerberus. and brl. modules rarely use them it would just fit very well into it not using them for basic functionality. Advanced framework stuff (I consider mojo already an advanced framework) is different. Especially when you have functions that depend on certain other constraints that are only given within that framework (the PremultiplyArgb2Abgr for example only makes sense in the mojo2 environment, because only there I've seen premultiplied ABGR colour format used). Static function do help keeping your code clean and minimize the risk of naming clashes, but I don't think interpolation is too advanced for a base module that uses 'global' functions.
 
Last edited:

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Messages
644
You are right, structure can be a burden on its own and I definitely don't want to get into some javaish names chaos. So maybe a practical route could be appropriate:
I looked into the purebasic docs (with which I am quite familiar) at what size of grouped functions (libraries there) I feel uncomfortable or maybe overwhelmed.
To me at about 7 it makes sense to have a new group. Above 30 it gets uncomfortable for me and above 50 I'm quite overwhelmed when trying to get an overview of functionality.
I am completely aware, that this is just subjective, but I read about studies that show that most of the people have a similar range of perception.

To put it short: I would like to keep the amount of functions in a group below 30 (40 max)
In this case we could just keep your interpolate functions in math library (currently 30) and have them somehow grouped with a new caption in the docs to keep a better overview.
 

Holzchopf

Moderator
3rd Party Module Dev
Tutorial Author
Joined
Jul 31, 2017
Messages
496
Well I would simply put them into a new module (called cerberus.interpolate). That way, the
somehow grouped with a new caption in the docs to keep a better overview.
is also directly addressed.
 
Top Bottom