Skip to content

Commit

Permalink
clerp2
Browse files Browse the repository at this point in the history
  • Loading branch information
omicronrex committed Dec 19, 2024
1 parent 385eed9 commit 979e20a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
37 changes: 26 additions & 11 deletions gm82core.gej
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,21 @@
],
"returntype": 2
},
{
"name": "clerp2",
"extname": "",
"calltype": 12,
"helpline": "clerp2(fromA,fromB,toA,toB,value)",
"hidden": false,
"argtypes": [
2,
2,
2,
2,
2
],
"returntype": 2
},
{
"name": "color_inverse",
"extname": "",
Expand Down Expand Up @@ -308,6 +323,17 @@
],
"returntype": 1
},
{
"name": "file_create",
"extname": "",
"calltype": 12,
"helpline": "file_create(filename)",
"hidden": false,
"argtypes": [
1
],
"returntype": 2
},
{
"name": "file_get_timestamp",
"extname": "",
Expand Down Expand Up @@ -1179,17 +1205,6 @@
2
],
"returntype": 2
},
{
"name": "file_create",
"extname": "",
"calltype": 12,
"helpline": "file_create(filename)",
"hidden": false,
"argtypes": [
1
],
"returntype": 2
}
],
"constants": []
Expand Down
13 changes: 13 additions & 0 deletions source/math.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ GMREAL lerp2(double fromA, double fromB, double toA, double toB, double value) {
return ((value-fromA)/(fromB-fromA))*(toB-toA)+toA;
}

GMREAL clerp2(double fromA, double fromB, double toA, double toB, double value) {
///clerp2(fromA,fromB,toA,toB,value)
//fromA: start value from
//fromB: end value from
//toA: start value to
//toB: end value to
//value: value to project
//returns: projected value, clamped to the 'to' values
//Projects 'value' from line segment 'from' to segment 'to'.

return max(toA,min(toB,((value-fromA)/(fromB-fromA))*(toB-toA)+toA));
}

GMREAL unlerp(double a, double b, double val) {
///unlerp(a,b,val)
//a: start value
Expand Down

0 comments on commit 979e20a

Please sign in to comment.