XArd Zond
Registered User
Join date: 10 Jun 2009
Posts: 7
|
10-13-2009 15:53
I'm trying to find out a way on how to get a value between 1.0 and 0.0 based on the distance between two points. The value needs to be on a gradual increase, like in a Tangent form.
I tried getting the Up vector on one of the points (PointB) giving me the third point (PointC) to make a triangle and used that to get the angle between PointB and PointC on PointA. Hoping that would give me a Tangent like increase.
I have tried using llTan also, however with disappointing results.
I honestly don't know what I'm doing any more.
|
Haravikk Mistral
Registered User
Join date: 8 Oct 2005
Posts: 2,482
|
10-13-2009 16:23
Can't you just normalise the value to be within some useful range?
For example, if you don't care for (or won't ever encounter) points more than 96.0 metres apart then just do:
float dist = llVecDist(pointA, pointB) / 96.0; if (dist > 1.0) dist = 1.0;
If you want it to increase on a kind of curve, then just square or cube the result.
It may help to know more about what you want the value for?
_____________________
Computer (Mac Pro): 2 x Quad Core 3.2ghz Xeon 10gb DDR2 800mhz FB-DIMMS 4 x 750gb, 32mb cache hard-drives (RAID-0/striped) NVidia GeForce 8800GT (512mb)
|
XArd Zond
Registered User
Join date: 10 Jun 2009
Posts: 7
|
10-13-2009 17:07
I was planning on scaling an object based on this distance value.
I have a HUD that I want to have its scale set to the ObjectA's Scale times by a value between 1.0 and 0.0 so that it scales to ObjectA's exact scale or something smaller.
In a more practical use, the HUD should scale into proportion based on the distance away the camera is from the object. Like those "Black Bars" you get when covering one's genitals.
Positioning of the HUD is in no need for concern.
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
10-14-2009 08:54
How about.... float exp(float x) { return llPow(2.718281828, x); } float tanh(float x) { float epx = exp(x); float enx = exp(-x); return (epx-enx)/(epx+enx); }
With an input domain from zero to positive infinity (e.g. distance), tanh() will evaluate to values between zero and one. See http://mathworld.wolfram.com/HyperbolicTangent.htmlIf it approaches one too quickly for you, you can always scale the distance down: 'tanh(x/factor)' Another possibility is '1.0-exp(-x)', which looks quite similar to 'tanh(x)' for positive x but is a little less expensive to compute.
|