문제

I'm sitting here and trying to resolve an issue I have, with alternating between 0 and 1 of a variable.

Basicly, I want to do something like this:

float distance = 32f;
float maxDistance = 32f;
float clampedDistance = Math.ClampPresentableValue(distance, maxDistance);

The variable "clampedDistance", would receive the clamped value from the math method. "ClampPresentableValue" should in this case, be able to take the "distance" value, and calculate, where it is in the "0 to 1" timeline, in comparison to the maxDistance.

In this case, since "distance" is the same as "maxDistance", the clamped value would be 1.0f. But if we cut "distance" down to 16f, the clamped value would present 0.5f, in the "clampedDistance" variable.

What is something like this called? Does it have a name, or is it just an algorithm that i'd have to build myself?

도움이 되었습니까?

해결책

It should probably be called 'normalize' or something like that. If I understood you correctly, you should simply do this:

float normalizedDistance = distance / maxDistance;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top