Created
November 12, 2015 05:40
-
-
Save Sgeo/dc140b32c082ae38fd15 to your computer and use it in GitHub Desktop.
Measures the impact of floating point numbers on low velocities
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float estimated_min_attempt_vel(float fps) | |
{ | |
vector pos = llGetPos(); | |
float alt = pos.z; | |
integer shell = llFloor(llLog(alt)/llLog(2.0)); | |
return fps * llPow(2.0, (float)shell - 24.0); | |
} | |
show(float attempting, float getvel, float actual, float fps, float dilation) | |
{ | |
string text = "Attempting: " + (string)attempting + "\n" + | |
"-llGetVel().z: " + (string)getvel + "\n" + | |
"Actual: " + (string)actual + "\n" + | |
"FPS: " + (string)fps + "\n" + | |
"Dilation: " + (string)dilation; | |
llSetText(text, ZERO_VECTOR, 1.0); | |
} | |
default | |
{ | |
state_entry() | |
{ | |
llListen(300, "", NULL_KEY, ""); | |
} | |
listen(integer channel, string name, key id, string msg) | |
{ | |
if(id != llGetOwner()) return; | |
float attempt_factor = (float)msg; | |
vector curPos = llGetPos(); | |
llSetStatus(STATUS_PHYSICS, TRUE); | |
llSetBuoyancy(1.0); | |
llResetTime(); | |
while(TRUE) | |
{ | |
float time = llGetAndResetTime(); | |
vector newPos = llGetPos(); | |
float fps = llGetRegionFPS(); | |
float dilation = llGetRegionTimeDilation(); | |
vector getvel_vec = llGetVel(); | |
float min_vel = estimated_min_attempt_vel(fps); | |
float attempting = attempt_factor * min_vel; | |
float actual = 0.0; | |
if(time != 0.0) | |
{ | |
actual = (newPos.z - curPos.z)/time; | |
} | |
curPos = newPos; | |
show(attempting, | |
-getvel_vec.z, | |
-actual, | |
fps, | |
dilation); | |
llSetVelocity(<0.0, 0.0, -attempting>, FALSE); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment