mirror of
https://github.com/opensim/opensim.git
synced 2026-08-11 20:05:33 +08:00
a little use of MathF
This commit is contained in:
@@ -54,10 +54,10 @@ namespace OpenSim.Framework
|
||||
Vector3 dir = Vector3.Normalize(offset);
|
||||
|
||||
// Get the bearing (yaw)
|
||||
Yaw = (float)Math.Atan2(dir.Y, dir.X);
|
||||
Yaw = MathF.Atan2(dir.Y, dir.X);
|
||||
|
||||
// Get the elevation (pitch)
|
||||
Pitch = (float)-Math.Atan2(dir.Z, Math.Sqrt(dir.X * dir.X + dir.Y * dir.Y));
|
||||
Pitch = -MathF.Atan2(dir.Z, MathF.Sqrt(dir.X * dir.X + dir.Y * dir.Y));
|
||||
}
|
||||
|
||||
public Vector3 GetLocation(Vector3 pos, Quaternion rot)
|
||||
|
||||
@@ -519,7 +519,7 @@ namespace OpenSim.Framework
|
||||
for (int xx = 0; xx < SizeX; xx++)
|
||||
{
|
||||
// reduce to 1mm resolution
|
||||
float val = (float)Math.Round(m_heightmap[xx, yy],3,MidpointRounding.AwayFromZero);
|
||||
float val = MathF.Round(m_heightmap[xx, yy],3,MidpointRounding.AwayFromZero);
|
||||
bw.Write(val);
|
||||
}
|
||||
}
|
||||
@@ -549,7 +549,7 @@ namespace OpenSim.Framework
|
||||
for (int xx = 0; xx < SizeX; xx++)
|
||||
{
|
||||
//bw.Write((float)m_heightmap[xx, yy]);
|
||||
bw.Write((float)Math.Round(m_heightmap[xx, yy], 3, MidpointRounding.AwayFromZero));
|
||||
bw.Write(MathF.Round(m_heightmap[xx, yy], 3, MidpointRounding.AwayFromZero));
|
||||
}
|
||||
|
||||
bw.Flush();
|
||||
|
||||
@@ -115,21 +115,21 @@ namespace OpenSim.Framework
|
||||
if (Utils.ApproxEqual(al, 0, 1e-3f) || Utils.ApproxEqual(Math.Abs(al), Utils.TWO_PI, 1e-3f))
|
||||
{
|
||||
az *= 0.5f;
|
||||
return new Quaternion(0, 0, (float)Math.Sin(az), (float)Math.Cos(az));
|
||||
return new Quaternion(0, 0, MathF.Sin(az), MathF.Cos(az));
|
||||
}
|
||||
|
||||
if (Utils.ApproxEqual(az, 0, 1e-3f) || Utils.ApproxEqual(Math.Abs(az), Utils.TWO_PI, 1e-3f))
|
||||
{
|
||||
al *= 0.5f;
|
||||
return new Quaternion(0, -(float)Math.Sin(al), 0, (float)Math.Cos(al));
|
||||
return new Quaternion(0, -MathF.Sin(al), 0, MathF.Cos(al));
|
||||
}
|
||||
|
||||
az *= 0.5f;
|
||||
float sz = (float)Math.Sin(az);
|
||||
float cz = (float)Math.Cos(az);
|
||||
float sz = MathF.Sin(az);
|
||||
float cz = MathF.Cos(az);
|
||||
al *= 0.5f;
|
||||
float sl = (float)Math.Sin(al);
|
||||
float cl = (float)Math.Cos(al);
|
||||
float sl = MathF.Sin(al);
|
||||
float cl = MathF.Cos(al);
|
||||
|
||||
Quaternion rot = new Quaternion(sl * sz, -sl * cz, cl * sz, cl * cz);
|
||||
rot.Normalize();
|
||||
@@ -142,7 +142,7 @@ namespace OpenSim.Framework
|
||||
float al = sun_angle;
|
||||
|
||||
sky.sun_rotation = AzAlToRot(az, al);
|
||||
sky.moon_rotation = AzAlToRot(az, al + (float)Math.PI);
|
||||
sky.moon_rotation = AzAlToRot(az, al + MathF.PI);
|
||||
}
|
||||
|
||||
public static Vector3 Xrot(Quaternion rot)
|
||||
@@ -162,17 +162,16 @@ namespace OpenSim.Framework
|
||||
else if (v.Z > -0.12)
|
||||
{
|
||||
float m = v.Y * v.Y + v.Z * v.Z;
|
||||
m = 1/(float)Math.Sqrt(m);
|
||||
m = 1.0f / MathF.Sqrt(m);
|
||||
lightnorm = new Vector4(v.Y * m, 0, v.X * m, 1);
|
||||
}
|
||||
else
|
||||
lightnorm = new Vector4(-v.Y, -v.Z, -v.X, 1);
|
||||
|
||||
sun_angle = (float)Math.Asin(v.Z);
|
||||
east_angle = -(float)Math.Atan2(v.Y, v.X);
|
||||
sun_angle = MathF.Asin(v.Z);
|
||||
east_angle = -MathF.Atan2(v.Y, v.X);
|
||||
|
||||
|
||||
if (Math.Abs(east_angle) < 1e-6)
|
||||
if (MathF.Abs(east_angle) < 1e-6f)
|
||||
east_angle = 0;
|
||||
else if (east_angle < 0)
|
||||
east_angle = Utils.TWO_PI + east_angle;
|
||||
@@ -185,7 +184,7 @@ namespace OpenSim.Framework
|
||||
sun_angle = Utils.PI - sun_angle;
|
||||
}
|
||||
*/
|
||||
if (Math.Abs(sun_angle) < 1e-6)
|
||||
if (MathF.Abs(sun_angle) < 1e-6f)
|
||||
sun_angle = 0;
|
||||
else if (sun_angle < 0)
|
||||
sun_angle = Utils.TWO_PI + sun_angle;
|
||||
@@ -197,7 +196,7 @@ namespace OpenSim.Framework
|
||||
WaterData water = new WaterData();
|
||||
|
||||
water.waterFogColor = ls.waterColor / 256f;
|
||||
water.waterFogDensity = (float)Math.Pow(2.0f, ls.waterFogDensityExponent);
|
||||
water.waterFogDensity = MathF.Pow(2.0f, ls.waterFogDensityExponent);
|
||||
//water.waterFogDensity = ls.waterFogDensityExponent;
|
||||
water.underWaterFogMod = ls.underwaterFogModifier;
|
||||
water.normScale = ls.reflectionWaveletScale;
|
||||
@@ -212,7 +211,7 @@ namespace OpenSim.Framework
|
||||
water.Name = "LightshareWater";
|
||||
|
||||
SkyData sky = new SkyData();
|
||||
convertFromAngles(sky, 2.0f * (float)Math.PI * ls.sunMoonPosition, 2.0f * (float)Math.PI * ls.eastAngle);
|
||||
convertFromAngles(sky, Utils.TWO_PI * ls.sunMoonPosition, Utils.TWO_PI * ls.eastAngle);
|
||||
sky.sunlight_color = ls.sunMoonColor * 3.0f;
|
||||
sky.ambient = new Vector3(ls.ambient.X * 3.0f, ls.ambient.Y * 3.0f, ls.ambient.Z * 3.0f);
|
||||
sky.blue_horizon = new Vector3(ls.horizon.X * 2.0f, ls.horizon.Y * 2.0f, ls.horizon.Z * 2.0f);
|
||||
@@ -261,7 +260,7 @@ namespace OpenSim.Framework
|
||||
if (Cycle.waterframes.TryGetValue(te.frameName, out WaterData water))
|
||||
{
|
||||
ls.waterColor = water.waterFogColor * 256f;
|
||||
ls.waterFogDensityExponent = (float)Math.Sqrt(water.waterFogDensity);
|
||||
ls.waterFogDensityExponent = MathF.Sqrt(water.waterFogDensity);
|
||||
//ls.waterFogDensityExponent = water.waterFogDensity;
|
||||
ls.underwaterFogModifier = water.underWaterFogMod;
|
||||
ls.reflectionWaveletScale = water.normScale;
|
||||
@@ -283,8 +282,8 @@ namespace OpenSim.Framework
|
||||
{
|
||||
Vector4 lightnorm;
|
||||
convertToAngles(sky, out ls.sunMoonPosition, out ls.eastAngle, out lightnorm);
|
||||
ls.sunMoonPosition *= 0.5f / (float)Math.PI;
|
||||
ls.eastAngle *= 0.5f / (float)Math.PI;
|
||||
ls.sunMoonPosition *= 0.5f / MathF.PI;
|
||||
ls.eastAngle *= 0.5f / MathF.PI;
|
||||
ls.sunMoonColor = sky.sunlight_color / 3f;
|
||||
ls.ambient = new Vector4(sky.ambient.X / 3.0f, sky.ambient.Y / 3.0f, sky.ambient.Z / 3.0f, 1);
|
||||
ls.horizon = new Vector4(sky.blue_horizon.X / 2.0f, sky.blue_horizon.Y / 2.0f, sky.blue_horizon.Z / 2.0f, 1);
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace OpenSim.Framework
|
||||
map["underWaterFogMod"] = underWaterFogMod;
|
||||
map["waterFogColor"] = new Vector4(waterFogColor.X, waterFogColor.Y, waterFogColor.Z, 1);
|
||||
map["waterFogDensity"] = waterFogDensity;
|
||||
//map["waterFogDensity"] = (float)Math.Pow(2.0f, waterFogDensity);
|
||||
//map["waterFogDensity"] = MathF.Pow(2.0f, waterFogDensity);
|
||||
map["wave1Dir"] = wave1Dir;
|
||||
map["wave2Dir"] = wave2Dir;
|
||||
|
||||
|
||||
@@ -611,7 +611,7 @@ namespace OpenSim
|
||||
return;
|
||||
}
|
||||
|
||||
float angle = (float)(Convert.ToSingle(args[2]) / 180.0 * Math.PI);
|
||||
float angle = Convert.ToSingle(args[2]) / 180.0f * MathF.PI;
|
||||
OpenMetaverse.Quaternion rot = OpenMetaverse.Quaternion.CreateFromAxisAngle(0, 0, 1, angle);
|
||||
|
||||
if (args.Length > 4)
|
||||
|
||||
@@ -6757,11 +6757,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
{
|
||||
float a, b;
|
||||
|
||||
a = Math.Abs(v.X);
|
||||
b = Math.Abs(v.Y);
|
||||
a = MathF.Abs(v.X);
|
||||
b = MathF.Abs(v.Y);
|
||||
if (b > a)
|
||||
a = b;
|
||||
b = Math.Abs(v.Z);
|
||||
b = MathF.Abs(v.Z);
|
||||
if (b > a)
|
||||
a = b;
|
||||
|
||||
@@ -7073,7 +7073,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
}
|
||||
else
|
||||
{
|
||||
a = 1.0f / (float)Math.Sqrt(a);
|
||||
a = 1.0f / MathF.Sqrt(a);
|
||||
Utils.FloatToUInt16Bytes(rz * a, 1.0f, data, pos); pos += 2;
|
||||
Utils.FloatToUInt16Bytes(rw * a, 1.0f, data, pos); pos += 2;
|
||||
}
|
||||
@@ -7138,7 +7138,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
}
|
||||
else
|
||||
{
|
||||
a = 1.0f / (float)Math.Sqrt(a);
|
||||
a = 1.0f / MathF.Sqrt(a);
|
||||
Utils.UInt16ToBytes(Utils.FloatToUnitUInt16(rz * a), data); data += 2;
|
||||
Utils.UInt16ToBytes(Utils.FloatToUnitUInt16(rw * a), data); data += 2;
|
||||
}
|
||||
@@ -8500,11 +8500,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
|| (x.ControlFlags & ~(uint)AgentManager.ControlFlags.AGENT_CONTROL_FINISH_ANIM) != (uint)AgentManager.ControlFlags.NONE
|
||||
|| (x.Flags != m_thisAgentUpdateArgs.Flags) // significant if Flags changed
|
||||
|| (x.State != m_thisAgentUpdateArgs.State) // significant if Stats changed
|
||||
|| (Math.Abs(x.Far - m_thisAgentUpdateArgs.Far) >= 32) // significant if far distance changed
|
||||
|| (MathF.Abs(x.Far - m_thisAgentUpdateArgs.Far) >= 32f) // significant if far distance changed
|
||||
)
|
||||
return true;
|
||||
|
||||
float qdelta = Math.Abs(x.BodyRotation.Dot(m_thisAgentUpdateArgs.BodyRotation));
|
||||
float qdelta = MathF.Abs(x.BodyRotation.Dot(m_thisAgentUpdateArgs.BodyRotation));
|
||||
return qdelta < QDELTABody; // significant if body rotation above(below cos) threshold
|
||||
}
|
||||
|
||||
@@ -8516,15 +8516,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
/// <param name='x'></param>
|
||||
private bool CheckAgentCameraUpdateSignificance(AgentUpdatePacket.AgentDataBlock x)
|
||||
{
|
||||
return (Math.Abs(x.CameraCenter.X - m_thisAgentUpdateArgs.CameraCenter.X) > VDELTA ||
|
||||
Math.Abs(x.CameraCenter.Y - m_thisAgentUpdateArgs.CameraCenter.Y) > VDELTA ||
|
||||
Math.Abs(x.CameraCenter.Z - m_thisAgentUpdateArgs.CameraCenter.Z) > VDELTA ||
|
||||
return (MathF.Abs(x.CameraCenter.X - m_thisAgentUpdateArgs.CameraCenter.X) > VDELTA ||
|
||||
MathF.Abs(x.CameraCenter.Y - m_thisAgentUpdateArgs.CameraCenter.Y) > VDELTA ||
|
||||
MathF.Abs(x.CameraCenter.Z - m_thisAgentUpdateArgs.CameraCenter.Z) > VDELTA ||
|
||||
|
||||
Math.Abs(x.CameraAtAxis.X - m_thisAgentUpdateArgs.CameraAtAxis.X) > VDELTA ||
|
||||
Math.Abs(x.CameraAtAxis.Y - m_thisAgentUpdateArgs.CameraAtAxis.Y) > VDELTA ||
|
||||
MathF.Abs(x.CameraAtAxis.X - m_thisAgentUpdateArgs.CameraAtAxis.X) > VDELTA ||
|
||||
MathF.Abs(x.CameraAtAxis.Y - m_thisAgentUpdateArgs.CameraAtAxis.Y) > VDELTA ||
|
||||
|
||||
Math.Abs(x.CameraUpAxis.X - m_thisAgentUpdateArgs.CameraUpAxis.X) > VDELTA ||
|
||||
Math.Abs(x.CameraUpAxis.Y - m_thisAgentUpdateArgs.CameraUpAxis.Y) > VDELTA
|
||||
MathF.Abs(x.CameraUpAxis.X - m_thisAgentUpdateArgs.CameraUpAxis.X) > VDELTA ||
|
||||
MathF.Abs(x.CameraUpAxis.Y - m_thisAgentUpdateArgs.CameraUpAxis.Y) > VDELTA
|
||||
);
|
||||
}
|
||||
|
||||
@@ -10884,8 +10884,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
return;
|
||||
|
||||
ParcelPropertiesRequestPacket.ParcelDataBlock pdb = propertiesRequest.ParcelData;
|
||||
OnParcelPropertiesRequest?.Invoke((int)Math.Round(pdb.West), (int)Math.Round(pdb.South),
|
||||
(int)Math.Round(pdb.East), (int)Math.Round(pdb.North),
|
||||
OnParcelPropertiesRequest?.Invoke((int)MathF.Round(pdb.West), (int)MathF.Round(pdb.South),
|
||||
(int)MathF.Round(pdb.East), (int)MathF.Round(pdb.North),
|
||||
pdb.SequenceID, pdb.SnapSelection, this);
|
||||
}
|
||||
|
||||
@@ -10895,10 +10895,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
if (landDivide.AgentData.SessionID.NotEqual(m_sessionId) || landDivide.AgentData.AgentID.NotEqual(m_agentId))
|
||||
return;
|
||||
|
||||
OnParcelDivideRequest?.Invoke((int)Math.Round(landDivide.ParcelData.West),
|
||||
(int)Math.Round(landDivide.ParcelData.South),
|
||||
OnParcelDivideRequest?.Invoke((int)MathF.Round(landDivide.ParcelData.West),
|
||||
(int)MathF.Round(landDivide.ParcelData.South),
|
||||
(int)Math.Round(landDivide.ParcelData.East),
|
||||
(int)Math.Round(landDivide.ParcelData.North), this);
|
||||
(int)MathF.Round(landDivide.ParcelData.North), this);
|
||||
}
|
||||
|
||||
private void HandleParcelJoin(Packet Pack)
|
||||
@@ -10907,10 +10907,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||
if (landJoin.AgentData.SessionID.NotEqual(m_sessionId) || landJoin.AgentData.AgentID.NotEqual(m_agentId))
|
||||
return;
|
||||
|
||||
OnParcelJoinRequest?.Invoke((int)Math.Round(landJoin.ParcelData.West),
|
||||
(int)Math.Round(landJoin.ParcelData.South),
|
||||
(int)Math.Round(landJoin.ParcelData.East),
|
||||
(int)Math.Round(landJoin.ParcelData.North), this);
|
||||
OnParcelJoinRequest?.Invoke((int)MathF.Round(landJoin.ParcelData.West),
|
||||
(int)MathF.Round(landJoin.ParcelData.South),
|
||||
(int)MathF.Round(landJoin.ParcelData.East),
|
||||
(int)MathF.Round(landJoin.ParcelData.North), this);
|
||||
}
|
||||
|
||||
private void HandleParcelPropertiesUpdate(Packet Pack)
|
||||
|
||||
Reference in New Issue
Block a user