save a few ns
parent
ad0b736405
commit
037e5d8031
|
@ -392,8 +392,8 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
||||||
#region Methods
|
#region Methods
|
||||||
public Quaternion Normalize()
|
public Quaternion Normalize()
|
||||||
{
|
{
|
||||||
double length = Math.Sqrt(x * x + y * y + z * z + s * s);
|
double lengthsq = x * x + y * y + z * z + s * s;
|
||||||
if (length < float.Epsilon)
|
if (lengthsq < float.Epsilon)
|
||||||
{
|
{
|
||||||
x = 0;
|
x = 0;
|
||||||
y = 0;
|
y = 0;
|
||||||
|
@ -403,7 +403,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
double invLength = 1.0 / length;
|
double invLength = 1.0 / Math.Sqrt(lengthsq);
|
||||||
x *= invLength;
|
x *= invLength;
|
||||||
y *= invLength;
|
y *= invLength;
|
||||||
z *= invLength;
|
z *= invLength;
|
||||||
|
@ -474,7 +474,8 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
||||||
{
|
{
|
||||||
// LSL quaternions can normalize to 0, normal Quaternions can't.
|
// LSL quaternions can normalize to 0, normal Quaternions can't.
|
||||||
if (rot.s == 0 && rot.x == 0 && rot.y == 0 && rot.z == 0)
|
if (rot.s == 0 && rot.x == 0 && rot.y == 0 && rot.z == 0)
|
||||||
rot.z = 1; // ZERO_ROTATION = 0,0,0,1
|
return OMV_Quaternion.Identity; // ZERO_ROTATION = 0,0,0,1
|
||||||
|
|
||||||
OMV_Quaternion omvrot = new OMV_Quaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s);
|
OMV_Quaternion omvrot = new OMV_Quaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s);
|
||||||
omvrot.Normalize();
|
omvrot.Normalize();
|
||||||
return omvrot;
|
return omvrot;
|
||||||
|
@ -510,6 +511,7 @@ namespace OpenSim.Region.ScriptEngine.Shared
|
||||||
|
|
||||||
public static Quaternion operator /(Quaternion a, Quaternion b)
|
public static Quaternion operator /(Quaternion a, Quaternion b)
|
||||||
{
|
{
|
||||||
|
// assuming normalized
|
||||||
b.s = -b.s;
|
b.s = -b.s;
|
||||||
return a * b;
|
return a * b;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue