mirror of
https://github.com/opensim/opensim.git
synced 2026-08-09 02:36:00 +08:00
c# things on physics; remove unused file (runprebuild)
This commit is contained in:
@@ -191,7 +191,7 @@ namespace OpenSim.Framework
|
||||
IClientAPI[] localArray;
|
||||
lock (m_syncRoot)
|
||||
{
|
||||
if (m_array == null)
|
||||
if (m_array is null)
|
||||
{
|
||||
if (m_dictbyUUID.Count == 0)
|
||||
return;
|
||||
|
||||
@@ -137,23 +137,22 @@ namespace OpenSim.Region.PhysicsModules.SharedBase
|
||||
|
||||
public void AddCollider(uint localID, ContactPoint contact)
|
||||
{
|
||||
if (m_objCollisionList.TryGetValue(localID, out ContactPoint oldcp))
|
||||
ref ContactPoint curcp = ref CollectionsMarshal.GetValueRefOrAddDefault(m_objCollisionList, localID, out bool ex);
|
||||
if (ex)
|
||||
{
|
||||
float lastVel = oldcp.RelativeSpeed;
|
||||
if (oldcp.PenetrationDepth < contact.PenetrationDepth)
|
||||
if (curcp.PenetrationDepth < contact.PenetrationDepth)
|
||||
{
|
||||
if (Math.Abs(lastVel) > Math.Abs(contact.RelativeSpeed))
|
||||
contact.RelativeSpeed = lastVel;
|
||||
m_objCollisionList[localID] = contact;
|
||||
if (Math.Abs(curcp.PenetrationDepth) > Math.Abs(contact.RelativeSpeed))
|
||||
contact.RelativeSpeed = curcp.PenetrationDepth;
|
||||
curcp = contact;
|
||||
}
|
||||
else if (Math.Abs(lastVel) < Math.Abs(contact.RelativeSpeed))
|
||||
else if (MathF.Abs(curcp.RelativeSpeed) < MathF.Abs(contact.RelativeSpeed))
|
||||
{
|
||||
oldcp.RelativeSpeed = contact.RelativeSpeed;
|
||||
m_objCollisionList[localID] = oldcp;
|
||||
curcp.RelativeSpeed = contact.RelativeSpeed;
|
||||
}
|
||||
}
|
||||
else
|
||||
m_objCollisionList.Add(localID, contact);
|
||||
curcp = contact;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -161,7 +161,7 @@ namespace OpenSim.Region.PhysicsModules.SharedBase
|
||||
{
|
||||
PhysicsActor ret = AddAvatar(avName, position, velocity, size, isFlying);
|
||||
|
||||
if (ret != null)
|
||||
if (ret is not null)
|
||||
ret.LocalID = localID;
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -1,186 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors, http://opensimulator.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSimulator Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace OpenSim.Region.PhysicsModules.SharedBase
|
||||
{
|
||||
/*public class PhysicsVector
|
||||
{
|
||||
public float X;
|
||||
public float Y;
|
||||
public float Z;
|
||||
|
||||
public Vector3()
|
||||
{
|
||||
}
|
||||
|
||||
public Vector3(float x, float y, float z)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
public Vector3(Vector3 pv) : this(pv.X, pv.Y, pv.Z)
|
||||
{
|
||||
}
|
||||
|
||||
public void setValues(float x, float y, float z)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
public static readonly PhysicsVector Zero = new PhysicsVector(0f, 0f, 0f);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "<" + X + "," + Y + "," + Z + ">";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// These routines are the easiest way to store XYZ values in an Vector3 without requiring 3 calls.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
byte[] byteArray = new byte[12];
|
||||
|
||||
Buffer.BlockCopy(BitConverter.GetBytes(X), 0, byteArray, 0, 4);
|
||||
Buffer.BlockCopy(BitConverter.GetBytes(Y), 0, byteArray, 4, 4);
|
||||
Buffer.BlockCopy(BitConverter.GetBytes(Z), 0, byteArray, 8, 4);
|
||||
|
||||
if (!BitConverter.IsLittleEndian)
|
||||
{
|
||||
Array.Reverse(byteArray, 0, 4);
|
||||
Array.Reverse(byteArray, 4, 4);
|
||||
Array.Reverse(byteArray, 8, 4);
|
||||
}
|
||||
|
||||
return byteArray;
|
||||
}
|
||||
|
||||
public void FromBytes(byte[] byteArray, int pos)
|
||||
{
|
||||
byte[] conversionBuffer = null;
|
||||
if (!BitConverter.IsLittleEndian)
|
||||
{
|
||||
// Big endian architecture
|
||||
if (conversionBuffer == null)
|
||||
conversionBuffer = new byte[12];
|
||||
|
||||
Buffer.BlockCopy(byteArray, pos, conversionBuffer, 0, 12);
|
||||
|
||||
Array.Reverse(conversionBuffer, 0, 4);
|
||||
Array.Reverse(conversionBuffer, 4, 4);
|
||||
Array.Reverse(conversionBuffer, 8, 4);
|
||||
|
||||
X = BitConverter.ToSingle(conversionBuffer, 0);
|
||||
Y = BitConverter.ToSingle(conversionBuffer, 4);
|
||||
Z = BitConverter.ToSingle(conversionBuffer, 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Little endian architecture
|
||||
X = BitConverter.ToSingle(byteArray, pos);
|
||||
Y = BitConverter.ToSingle(byteArray, pos + 4);
|
||||
Z = BitConverter.ToSingle(byteArray, pos + 8);
|
||||
}
|
||||
}
|
||||
|
||||
// Operations
|
||||
public static PhysicsVector operator +(Vector3 a, Vector3 b)
|
||||
{
|
||||
return new PhysicsVector(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
|
||||
}
|
||||
|
||||
public static PhysicsVector operator -(Vector3 a, Vector3 b)
|
||||
{
|
||||
return new PhysicsVector(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
|
||||
}
|
||||
|
||||
public static PhysicsVector cross(Vector3 a, Vector3 b)
|
||||
{
|
||||
return new PhysicsVector(a.Y*b.Z - a.Z*b.Y, a.Z*b.X - a.X*b.Z, a.X*b.Y - a.Y*b.X);
|
||||
}
|
||||
|
||||
public float length()
|
||||
{
|
||||
return (float) Math.Sqrt(X*X + Y*Y + Z*Z);
|
||||
}
|
||||
|
||||
public static float GetDistanceTo(Vector3 a, Vector3 b)
|
||||
{
|
||||
float dx = a.X - b.X;
|
||||
float dy = a.Y - b.Y;
|
||||
float dz = a.Z - b.Z;
|
||||
return (float) Math.Sqrt(dx * dx + dy * dy + dz * dz);
|
||||
}
|
||||
|
||||
public static PhysicsVector operator /(Vector3 v, float f)
|
||||
{
|
||||
return new PhysicsVector(v.X/f, v.Y/f, v.Z/f);
|
||||
}
|
||||
|
||||
public static PhysicsVector operator *(Vector3 v, float f)
|
||||
{
|
||||
return new PhysicsVector(v.X*f, v.Y*f, v.Z*f);
|
||||
}
|
||||
|
||||
public static PhysicsVector operator *(float f, Vector3 v)
|
||||
{
|
||||
return v*f;
|
||||
}
|
||||
|
||||
public static bool isFinite(Vector3 v)
|
||||
{
|
||||
if (v == null)
|
||||
return false;
|
||||
if (Single.IsInfinity(v.X) || Single.IsNaN(v.X))
|
||||
return false;
|
||||
if (Single.IsInfinity(v.Y) || Single.IsNaN(v.Y))
|
||||
return false;
|
||||
if (Single.IsInfinity(v.Z) || Single.IsNaN(v.Z))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual bool IsIdentical(Vector3 v, float tolerance)
|
||||
{
|
||||
PhysicsVector diff = this - v;
|
||||
float d = diff.length();
|
||||
if (d <= tolerance)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}*/
|
||||
}
|
||||
@@ -155,7 +155,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
|
||||
public int m_eventsubscription = 0;
|
||||
private int m_cureventsubscription = 0;
|
||||
private readonly CollisionEventUpdate CollisionEventsThisFrame = new CollisionEventUpdate();
|
||||
private readonly CollisionEventUpdate CollisionEventsThisFrame = new();
|
||||
private bool SentEmptyCollisionsEvent;
|
||||
|
||||
public bool bad = false;
|
||||
@@ -602,9 +602,11 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
if (size.Z < 0.01f)
|
||||
size.Z = 0.01f;
|
||||
|
||||
strAvatarSize st = new strAvatarSize();
|
||||
st.size = size;
|
||||
st.offset = feetOffset;
|
||||
strAvatarSize st = new()
|
||||
{
|
||||
size = size,
|
||||
offset = feetOffset
|
||||
};
|
||||
AddChange(changes.AvatarSize, st);
|
||||
}
|
||||
else
|
||||
@@ -1085,7 +1087,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
if (r > 1.0f)
|
||||
return false;
|
||||
|
||||
float dp = 1.0f - (float)Math.Sqrt(r);
|
||||
float dp = 1.0f - MathF.Sqrt(r);
|
||||
if (dp > 0.05f)
|
||||
dp = 0.05f;
|
||||
|
||||
@@ -1147,7 +1149,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
|
||||
float tdp = contact.depth;
|
||||
float t = offset.X;
|
||||
t = Math.Abs(t);
|
||||
t = MathF.Abs(t);
|
||||
if (t > 1e-6)
|
||||
{
|
||||
tdp /= t;
|
||||
@@ -1298,8 +1300,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
float terrainheight = m_parent_scene.GetTerrainHeightAtXY(tmpX, tmpY);
|
||||
if (aabbminz < terrainheight)
|
||||
{
|
||||
if (ctz.Z < 0)
|
||||
ctz.Z = 0;
|
||||
if (ctz.Z < 0f)
|
||||
ctz.Z = 0f;
|
||||
|
||||
if (!m_haveLastFallVel)
|
||||
{
|
||||
@@ -1317,9 +1319,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
vec.Z += -vel.Z * PID_D;
|
||||
if (n.Z < 0.4f)
|
||||
{
|
||||
vec.X = depth * PID_P * 50 - vel.X * PID_D;
|
||||
vec.X = depth * PID_P * 50f - vel.X * PID_D;
|
||||
vec.X *= n.X;
|
||||
vec.Y = depth * PID_P * 50 - vel.Y * PID_D;
|
||||
vec.Y = depth * PID_P * 50f - vel.Y * PID_D;
|
||||
vec.Y *= n.Y;
|
||||
vec.Z *= n.Z;
|
||||
if (n.Z < 0.1f)
|
||||
@@ -1350,14 +1352,14 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
|
||||
m_iscollidingGround = true;
|
||||
|
||||
ContactPoint contact = new ContactPoint();
|
||||
contact.PenetrationDepth = depth;
|
||||
contact.Position.X = _position.X;
|
||||
contact.Position.Y = _position.Y;
|
||||
contact.Position.Z = terrainheight;
|
||||
contact.SurfaceNormal = -n;
|
||||
contact.RelativeSpeed = Vector3.Dot(m_lastFallVel,n);
|
||||
contact.CharacterFeet = true;
|
||||
ContactPoint contact = new()
|
||||
{
|
||||
PenetrationDepth = depth,
|
||||
Position = new( _position.X, _position.Y, terrainheight),
|
||||
SurfaceNormal = -n,
|
||||
RelativeSpeed = Vector3.Dot(m_lastFallVel, n),
|
||||
CharacterFeet = true
|
||||
};
|
||||
AddCollisionEvent(0,contact);
|
||||
m_lastFallVel = vel;
|
||||
|
||||
@@ -1412,7 +1414,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
float fz = (m_targetHoverHeight - _position.Z);
|
||||
|
||||
// if error is zero, use position control; otherwise, velocity control
|
||||
if (Math.Abs(fz) < 0.01f)
|
||||
if (MathF.Abs(fz) < 0.01f)
|
||||
{
|
||||
ctz.Z = 0;
|
||||
}
|
||||
@@ -1421,11 +1423,11 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
_zeroFlag = false;
|
||||
fz /= m_PIDHoverTau;
|
||||
|
||||
float tmp = Math.Abs(fz);
|
||||
if (tmp > 50)
|
||||
fz = 50 * Math.Sign(fz);
|
||||
else if (tmp < 0.1)
|
||||
fz = 0.1f * Math.Sign(fz);
|
||||
float tmp = MathF.Abs(fz);
|
||||
if (tmp > 50f)
|
||||
fz = 50f * MathF.Sign(fz);
|
||||
else if (tmp < 0.1f)
|
||||
fz = 0.1f * MathF.Sign(fz);
|
||||
|
||||
ctz.Z = fz;
|
||||
}
|
||||
@@ -1444,14 +1446,14 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
|
||||
// movement relative to surface if moving on it
|
||||
// dont disturbe vertical movement, ie jumps
|
||||
if (m_iscolliding && !m_flying && ctz.Z == 0 && m_collideNormal.Z > 0.2f && m_collideNormal.Z < 0.94f)
|
||||
if (m_iscolliding && !m_flying && ctz.Z == 0f && m_collideNormal.Z > 0.2f && m_collideNormal.Z < 0.94f)
|
||||
{
|
||||
float p = ctz.X * m_collideNormal.X + ctz.Y * m_collideNormal.Y;
|
||||
ctz.X *= (float)Math.Sqrt(1 - m_collideNormal.X * m_collideNormal.X);
|
||||
ctz.Y *= (float)Math.Sqrt(1 - m_collideNormal.Y * m_collideNormal.Y);
|
||||
ctz.X *= MathF.Sqrt(1 - m_collideNormal.X * m_collideNormal.X);
|
||||
ctz.Y *= MathF.Sqrt(1 - m_collideNormal.Y * m_collideNormal.Y);
|
||||
ctz.Z -= p;
|
||||
if (ctz.Z < 0)
|
||||
ctz.Z *= 2;
|
||||
if (ctz.Z < 0f)
|
||||
ctz.Z *= 2f;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1535,9 +1537,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
{
|
||||
}
|
||||
|
||||
if (Math.Abs(ctz.X) > Math.Abs(vel.X))
|
||||
if (MathF.Abs(ctz.X) > MathF.Abs(vel.X))
|
||||
vec.X += (ctz.X - vel.X) * PID_D;
|
||||
if (Math.Abs(ctz.Y) > Math.Abs(vel.Y))
|
||||
if (MathF.Abs(ctz.Y) > MathF.Abs(vel.Y))
|
||||
vec.Y += (ctz.Y - vel.Y) * PID_D;
|
||||
}
|
||||
}
|
||||
@@ -1642,22 +1644,22 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void round(ref Vector3 v, int digits)
|
||||
{
|
||||
v.X = (float)Math.Round(v.X, digits);
|
||||
v.Y = (float)Math.Round(v.Y, digits);
|
||||
v.Z = (float)Math.Round(v.Z, digits);
|
||||
v.X = MathF.Round(v.X, digits);
|
||||
v.Y = MathF.Round(v.Y, digits);
|
||||
v.Z = MathF.Round(v.Z, digits);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetSmooth(ref Vector3 dst, ref Vector3 value, int rounddigits)
|
||||
{
|
||||
dst.X = 0.4f * dst.X + 0.6f * value.X;
|
||||
dst.X = (float)Math.Round(dst.X, rounddigits);
|
||||
dst.X = MathF.Round(dst.X, rounddigits);
|
||||
|
||||
dst.Y = 0.4f * dst.Y + 0.6f * value.Y;
|
||||
dst.Y = (float)Math.Round(dst.Y, rounddigits);
|
||||
dst.Y = MathF.Round(dst.Y, rounddigits);
|
||||
|
||||
dst.Z = 0.4f * dst.Z + 0.6f * value.Z;
|
||||
dst.Z = (float)Math.Round(dst.Z, rounddigits);
|
||||
dst.Z = MathF.Round(dst.Z, rounddigits);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1998,7 +2000,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
float t = m_orientation2D.W * m_orientation2D.W + m_orientation2D.Z * m_orientation2D.Z;
|
||||
if (t > 0)
|
||||
{
|
||||
t = 1.0f / (float)Math.Sqrt(t);
|
||||
t = 1.0f / MathF.Sqrt(t);
|
||||
m_orientation2D.W *= t;
|
||||
m_orientation2D.Z *= t;
|
||||
}
|
||||
|
||||
@@ -53,8 +53,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
get { return m_type; }
|
||||
}
|
||||
|
||||
private OdePrim rootPrim;
|
||||
private ODEScene _pParentScene;
|
||||
private readonly OdePrim rootPrim;
|
||||
private readonly ODEScene _pParentScene;
|
||||
|
||||
// Vehicle properties
|
||||
// WARNING this are working copies for internel use
|
||||
@@ -77,27 +77,27 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
|
||||
// Linear properties
|
||||
private Vector3 m_linearMotorDirection = Vector3.Zero; // velocity requested by LSL, decayed by time
|
||||
private Vector3 m_linearFrictionTimescale = new Vector3(1000, 1000, 1000);
|
||||
private float m_linearMotorDecayTimescale = 120;
|
||||
private float m_linearMotorTimescale = 1000;
|
||||
private Vector3 m_linearFrictionTimescale = new(1000f, 1000f, 1000f);
|
||||
private float m_linearMotorDecayTimescale = 120f;
|
||||
private float m_linearMotorTimescale = 1000f;
|
||||
private Vector3 m_linearMotorOffset = Vector3.Zero;
|
||||
|
||||
//Angular properties
|
||||
private Vector3 m_angularMotorDirection = Vector3.Zero; // angular velocity requested by LSL motor
|
||||
private float m_angularMotorTimescale = 1000; // motor angular velocity ramp up rate
|
||||
private float m_angularMotorDecayTimescale = 120; // motor angular velocity decay rate
|
||||
private Vector3 m_angularFrictionTimescale = new Vector3(1000, 1000, 1000); // body angular velocity decay rate
|
||||
private float m_angularMotorTimescale = 1000f; // motor angular velocity ramp up rate
|
||||
private float m_angularMotorDecayTimescale = 120f; // motor angular velocity decay rate
|
||||
private Vector3 m_angularFrictionTimescale = new(1000f, 1000f, 1000f); // body angular velocity decay rate
|
||||
|
||||
//Deflection properties
|
||||
private float m_angularDeflectionEfficiency = 0;
|
||||
private float m_angularDeflectionTimescale = 1000;
|
||||
private float m_linearDeflectionEfficiency = 0;
|
||||
private float m_linearDeflectionTimescale = 1000;
|
||||
private float m_angularDeflectionEfficiency = 0f;
|
||||
private float m_angularDeflectionTimescale = 1000f;
|
||||
private float m_linearDeflectionEfficiency = 0f;
|
||||
private float m_linearDeflectionTimescale = 1000f;
|
||||
|
||||
//Banking properties
|
||||
private float m_bankingEfficiency = 0;
|
||||
private float m_bankingMix = 0;
|
||||
private float m_bankingTimescale = 1000;
|
||||
private float m_bankingEfficiency = 0f;
|
||||
private float m_bankingMix = 0f;
|
||||
private float m_bankingTimescale = 1000f;
|
||||
|
||||
//Hover and Buoyancy properties
|
||||
private float m_VhoverHeight = 0f;
|
||||
@@ -122,8 +122,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
|
||||
private float m_ffactor = 1.0f;
|
||||
|
||||
private float m_timestep = 0.02f;
|
||||
private float m_invtimestep = 50;
|
||||
private readonly float m_timestep = 0.02f;
|
||||
private readonly float m_invtimestep = 50;
|
||||
|
||||
|
||||
float m_ampwr;
|
||||
@@ -687,10 +687,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
return vec;
|
||||
}
|
||||
|
||||
private const float pi = (float)Math.PI;
|
||||
private const float halfpi = 0.5f * (float)Math.PI;
|
||||
private const float twopi = 2.0f * pi;
|
||||
|
||||
private const float pi = MathF.PI;
|
||||
private const float halfpi = 0.5f * MathF.PI;
|
||||
|
||||
public static Vector3 ubRot2Euler(Quaternion rot)
|
||||
{
|
||||
// returns roll in X
|
||||
@@ -707,28 +706,28 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
{
|
||||
vec.X = 0;
|
||||
vec.Y = -halfpi;
|
||||
vec.Z = (float)(-2d * Math.Atan(rot.X / rot.W));
|
||||
vec.Z = -2f * MathF.Atan(rot.X / rot.W);
|
||||
}
|
||||
else if (zX > 0.49999f)
|
||||
{
|
||||
vec.X = 0;
|
||||
vec.Y = halfpi;
|
||||
vec.Z = (float)(2d * Math.Atan(rot.X / rot.W));
|
||||
vec.Z = 2f * MathF.Atan(rot.X / rot.W);
|
||||
}
|
||||
else
|
||||
{
|
||||
vec.Y = (float)Math.Asin(2 * zX);
|
||||
vec.Y = MathF.Asin(2 * zX);
|
||||
|
||||
float sqw = rot.W * rot.W;
|
||||
|
||||
float minuszY = rot.X * rot.W - rot.Y * rot.Z;
|
||||
float zZ = rot.Z * rot.Z + sqw - 0.5f;
|
||||
|
||||
vec.X = (float)Math.Atan2(minuszY, zZ);
|
||||
vec.X = MathF.Atan2(minuszY, zZ);
|
||||
|
||||
float yX = rot.Z * rot.W - rot.X * rot.Y; //( have negative ?)
|
||||
float yY = rot.X * rot.X + sqw - 0.5f;
|
||||
vec.Z = (float)Math.Atan2(yX, yY);
|
||||
vec.Z = MathF.Atan2(yX, yY);
|
||||
}
|
||||
return vec;
|
||||
}
|
||||
@@ -752,25 +751,23 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
}
|
||||
else
|
||||
{
|
||||
pitch = (float)Math.Asin(2 * zX);
|
||||
pitch = MathF.Asin(2 * zX);
|
||||
|
||||
float minuszY = rot.X * rot.W - rot.Y * rot.Z;
|
||||
float zZ = rot.Z * rot.Z + rot.W * rot.W - 0.5f;
|
||||
|
||||
roll = (float)Math.Atan2(minuszY, zZ);
|
||||
roll = MathF.Atan2(minuszY, zZ);
|
||||
}
|
||||
return ;
|
||||
}
|
||||
|
||||
internal void Step()
|
||||
{
|
||||
IntPtr Body = rootPrim.Body;
|
||||
|
||||
SafeNativeMethods.Mass dmass;
|
||||
SafeNativeMethods.BodyGetMass(Body, out dmass);
|
||||
SafeNativeMethods.BodyGetMass(Body, out SafeNativeMethods.Mass dmass);
|
||||
|
||||
SafeNativeMethods.Quaternion rot = SafeNativeMethods.BodyGetQuaternion(Body);
|
||||
Quaternion objrotq = new Quaternion(rot.X, rot.Y, rot.Z, rot.W); // rotq = rotation of object
|
||||
Quaternion objrotq = new(rot.X, rot.Y, rot.Z, rot.W); // rotq = rotation of object
|
||||
Quaternion rotq = objrotq; // rotq = rotation of object
|
||||
rotq *= m_referenceFrame; // rotq is now rotation in vehicle reference frame
|
||||
Quaternion irotq = Quaternion.Inverse(rotq);
|
||||
@@ -781,7 +778,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
Vector3 curAngVel; // angular velocity in world
|
||||
Vector3 force = Vector3.Zero; // actually linear aceleration until mult by mass in world frame
|
||||
Vector3 torque = Vector3.Zero;// actually angular aceleration until mult by Inertia in vehicle frame
|
||||
SafeNativeMethods.Vector3 dtorque = new SafeNativeMethods.Vector3();
|
||||
SafeNativeMethods.Vector3 dtorque = new();
|
||||
|
||||
dvtmp = SafeNativeMethods.BodyGetLinearVel(Body);
|
||||
curVel.X = dvtmp.X;
|
||||
@@ -946,7 +943,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
tmpV.Z = -curLocalVel.Z / m_linearFrictionTimescale.Z;
|
||||
tmpV *= rotq; // to world
|
||||
|
||||
if(ldampZ != 0 && Math.Abs(ldampZ) > Math.Abs(tmpV.Z))
|
||||
if(ldampZ != 0 && MathF.Abs(ldampZ) > MathF.Abs(tmpV.Z))
|
||||
tmpV.Z = ldampZ;
|
||||
force.X += tmpV.X;
|
||||
force.Y += tmpV.Y;
|
||||
@@ -956,18 +953,14 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
// vertical atractor
|
||||
if (verticalAttractionTimescale < 300)
|
||||
{
|
||||
float roll;
|
||||
float pitch;
|
||||
|
||||
float ftmp = m_invtimestep / verticalAttractionTimescale / verticalAttractionTimescale;
|
||||
float ftmp2 = 0.5f * m_verticalAttractionEfficiency * m_invtimestep;
|
||||
|
||||
float ftmp2;
|
||||
ftmp2 = 0.5f * m_verticalAttractionEfficiency * m_invtimestep;
|
||||
m_amdampX = ftmp2;
|
||||
|
||||
m_ampwr = 1.0f - 0.8f * m_verticalAttractionEfficiency;
|
||||
|
||||
GetRollPitch(irotq, out roll, out pitch);
|
||||
GetRollPitch(irotq, out float roll, out float pitch);
|
||||
|
||||
if (roll > halfpi)
|
||||
roll = pi - roll;
|
||||
@@ -991,7 +984,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
torque.Y += effpitch * ftmp;
|
||||
}
|
||||
|
||||
if (bankingEfficiency != 0 && Math.Abs(effroll) > 0.01)
|
||||
if (bankingEfficiency != 0 && MathF.Abs(effroll) > 0.01f)
|
||||
{
|
||||
|
||||
float broll = effroll;
|
||||
@@ -1004,7 +997,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
broll *= m_bankingEfficiency;
|
||||
if (m_bankingMix != 0)
|
||||
{
|
||||
float vfact = Math.Abs(curLocalVel.X) / 10.0f;
|
||||
float vfact = MathF.Abs(curLocalVel.X) / 10.0f;
|
||||
if (vfact > 1.0f) vfact = 1.0f;
|
||||
|
||||
if (curLocalVel.X >= 0)
|
||||
@@ -1014,7 +1007,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
}
|
||||
// make z rot be in world Z not local as seems to be in sl
|
||||
|
||||
broll = broll / m_bankingTimescale;
|
||||
broll /= m_bankingTimescale;
|
||||
|
||||
|
||||
tmpV = Zrot(irotq);
|
||||
@@ -1024,7 +1017,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
torque.Y += tmpV.Y;
|
||||
torque.Z += tmpV.Z;
|
||||
|
||||
m_amdampZ = Math.Abs(m_bankingEfficiency) / m_bankingTimescale;
|
||||
m_amdampZ = MathF.Abs(m_bankingEfficiency) / m_bankingTimescale;
|
||||
m_amdampY = m_amdampZ;
|
||||
|
||||
}
|
||||
@@ -1053,12 +1046,12 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
float tmp;
|
||||
|
||||
// get out of x == 0 plane
|
||||
if(Math.Abs(dirv.X) < 0.001f)
|
||||
if(MathF.Abs(dirv.X) < 0.001f)
|
||||
dirv.X = 0.001f;
|
||||
|
||||
if (Math.Abs(dirv.Z) > 0.01)
|
||||
if (MathF.Abs(dirv.Z) > 0.01f)
|
||||
{
|
||||
tmp = -(float)Math.Atan2(dirv.Z, dirv.X) * m_angularMotorDirection.Y;
|
||||
tmp = -MathF.Atan2(dirv.Z, dirv.X) * m_angularMotorDirection.Y;
|
||||
if(tmp < -4f)
|
||||
tmp = -4f;
|
||||
else if(tmp > 4f)
|
||||
@@ -1069,11 +1062,11 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
else
|
||||
torque.Y -= curLocalAngVel.Y * m_invtimestep;
|
||||
|
||||
if (Math.Abs(dirv.Y) > 0.01)
|
||||
if (MathF.Abs(dirv.Y) > 0.01f)
|
||||
{
|
||||
if(mousemodebank)
|
||||
{
|
||||
tmp = -(float)Math.Atan2(dirv.Y, dirv.X) * m_angularMotorDirection.X;
|
||||
tmp = -MathF.Atan2(dirv.Y, dirv.X) * m_angularMotorDirection.X;
|
||||
if(tmp < -4f)
|
||||
tmp = -4f;
|
||||
else if(tmp > 4f)
|
||||
@@ -1082,7 +1075,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = (float)Math.Atan2(dirv.Y, dirv.X) * m_angularMotorDirection.Z;
|
||||
tmp = MathF.Atan2(dirv.Y, dirv.X) * m_angularMotorDirection.Z;
|
||||
tmp *= invamts;
|
||||
if(tmp < -4f)
|
||||
tmp = -4f;
|
||||
@@ -1147,14 +1140,14 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
|
||||
float ftmp = m_angularDeflectionEfficiency / m_angularDeflectionTimescale;
|
||||
|
||||
if (Math.Abs(dirv.Z) > 0.01)
|
||||
if (MathF.Abs(dirv.Z) > 0.01f)
|
||||
{
|
||||
torque.Y += - (float)Math.Atan2(dirv.Z, dirv.X) * ftmp;
|
||||
torque.Y -= MathF.Atan2(dirv.Z, dirv.X) * ftmp;
|
||||
}
|
||||
|
||||
if (Math.Abs(dirv.Y) > 0.01)
|
||||
if (MathF.Abs(dirv.Y) > 0.01f)
|
||||
{
|
||||
torque.Z += (float)Math.Atan2(dirv.Y, dirv.X) * ftmp;
|
||||
torque.Z += MathF.Atan2(dirv.Y, dirv.X) * ftmp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
private float m_targetHoverHeight;
|
||||
private float m_buoyancy; //KF: m_buoyancy should be set by llSetBuoyancy() for non-vehicle.
|
||||
|
||||
private int m_body_autodisable_frames;
|
||||
private readonly int m_body_autodisable_frames;
|
||||
public int m_bodydisablecontrol = 0;
|
||||
private float m_gravmod = 1.0f;
|
||||
|
||||
@@ -117,7 +117,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
public bool m_disabled;
|
||||
|
||||
private IMesh m_mesh;
|
||||
private readonly object m_meshlock = new object();
|
||||
private readonly object m_meshlock = new();
|
||||
private PrimitiveBaseShape m_pbs;
|
||||
|
||||
private UUID? m_assetID;
|
||||
@@ -134,7 +134,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
|
||||
private PhysicsActor _parent;
|
||||
|
||||
private List<OdePrim> childrenPrim = new List<OdePrim>();
|
||||
private readonly List<OdePrim> childrenPrim = new();
|
||||
|
||||
public float m_collisionscore;
|
||||
private int m_colliderfilter = 0;
|
||||
@@ -478,8 +478,10 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
return _parent.GetInertiaData();
|
||||
else
|
||||
{
|
||||
inertia = new PhysicsInertiaData();
|
||||
inertia.TotalMass = -1;
|
||||
inertia = new PhysicsInertiaData
|
||||
{
|
||||
TotalMass = -1
|
||||
};
|
||||
return inertia;
|
||||
}
|
||||
}
|
||||
@@ -489,16 +491,16 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
// double buffering
|
||||
if(m_fakeInertiaOverride != null)
|
||||
{
|
||||
SafeNativeMethods.Mass objdmass = new SafeNativeMethods.Mass();
|
||||
SafeNativeMethods.Mass objdmass = new();
|
||||
objdmass.I.M00 = m_fakeInertiaOverride.Inertia.X;
|
||||
objdmass.I.M11 = m_fakeInertiaOverride.Inertia.Y;
|
||||
objdmass.I.M22 = m_fakeInertiaOverride.Inertia.Z;
|
||||
|
||||
objdmass.mass = m_fakeInertiaOverride.TotalMass;
|
||||
|
||||
if(Math.Abs(m_fakeInertiaOverride.InertiaRotation.W) < 0.999)
|
||||
if(MathF.Abs(m_fakeInertiaOverride.InertiaRotation.W) < 0.999)
|
||||
{
|
||||
SafeNativeMethods.Matrix3 inertiarotmat = new SafeNativeMethods.Matrix3();
|
||||
SafeNativeMethods.Matrix3 inertiarotmat = new();
|
||||
SafeNativeMethods.RfromQ(ref inertiarotmat, ref m_fakeInertiaOverride.InertiaRotation);
|
||||
SafeNativeMethods.MassRotate(ref objdmass, ref inertiarotmat);
|
||||
}
|
||||
@@ -525,7 +527,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
}
|
||||
|
||||
SafeNativeMethods.Vector3 dtmp;
|
||||
SafeNativeMethods.Mass m = new SafeNativeMethods.Mass();
|
||||
SafeNativeMethods.Mass m = new();
|
||||
lock(m_parentScene.OdeLock)
|
||||
{
|
||||
SafeNativeMethods.AllocateODEDataForThread(0);
|
||||
@@ -533,10 +535,10 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
SafeNativeMethods.BodyGetMass(Body, out m);
|
||||
}
|
||||
|
||||
Vector3 cm = new Vector3(-dtmp.X, -dtmp.Y, -dtmp.Z);
|
||||
Vector3 cm = new(-dtmp.X, -dtmp.Y, -dtmp.Z);
|
||||
inertia.CenterOfMass = cm;
|
||||
inertia.Inertia = new Vector3(m.I.M00, m.I.M11, m.I.M22);
|
||||
inertia.InertiaRotation = new Vector4(m.I.M01, m.I.M02 , m.I.M12, 0);
|
||||
inertia.Inertia = new(m.I.M00, m.I.M11, m.I.M22);
|
||||
inertia.InertiaRotation = new(m.I.M01, m.I.M02 , m.I.M12, 0);
|
||||
|
||||
return inertia;
|
||||
}
|
||||
@@ -576,7 +578,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
{
|
||||
Vector3 Ptot = SafeNativeMethods.GeomGetPositionOMV(m_prim_geom);
|
||||
Quaternion q = SafeNativeMethods.GeomGetQuaternionOMV(m_prim_geom);
|
||||
Ptot = Ptot + m_OBBOffset * q;
|
||||
Ptot += m_OBBOffset * q;
|
||||
return Ptot;
|
||||
/*
|
||||
float tmass = _mass;
|
||||
@@ -901,36 +903,44 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override void VehicleFloatParam(int param, float value)
|
||||
{
|
||||
strVehicleFloatParam fp = new strVehicleFloatParam();
|
||||
fp.param = param;
|
||||
fp.value = value;
|
||||
strVehicleFloatParam fp = new()
|
||||
{
|
||||
param = param,
|
||||
value = value
|
||||
};
|
||||
AddChange(changes.VehicleFloatParam, fp);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override void VehicleVectorParam(int param, Vector3 value)
|
||||
{
|
||||
strVehicleVectorParam fp = new strVehicleVectorParam();
|
||||
fp.param = param;
|
||||
fp.value = value;
|
||||
strVehicleVectorParam fp = new()
|
||||
{
|
||||
param = param,
|
||||
value = value
|
||||
};
|
||||
AddChange(changes.VehicleVectorParam, fp);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override void VehicleRotationParam(int param, Quaternion value)
|
||||
{
|
||||
strVehicleQuatParam fp = new strVehicleQuatParam();
|
||||
fp.param = param;
|
||||
fp.value = value;
|
||||
strVehicleQuatParam fp = new()
|
||||
{
|
||||
param = param,
|
||||
value = value
|
||||
};
|
||||
AddChange(changes.VehicleRotationParam, fp);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override void VehicleFlags(int param, bool value)
|
||||
{
|
||||
strVehicleBoolParam bp = new strVehicleBoolParam();
|
||||
bp.param = param;
|
||||
bp.value = value;
|
||||
strVehicleBoolParam bp = new()
|
||||
{
|
||||
param = param,
|
||||
value = value
|
||||
};
|
||||
AddChange(changes.VehicleFlags, bp);
|
||||
}
|
||||
|
||||
@@ -1148,10 +1158,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
{
|
||||
m_eventsubscription = ms;
|
||||
m_cureventsubscription = 0;
|
||||
if (CollisionEvents == null)
|
||||
CollisionEvents = new CollisionEventUpdate();
|
||||
if (CollisionVDTCEvents == null)
|
||||
CollisionVDTCEvents = new CollisionEventUpdate();
|
||||
CollisionEvents ??= new CollisionEventUpdate();
|
||||
CollisionVDTCEvents ??= new CollisionEventUpdate();
|
||||
SentEmptyCollisionsEvent = false;
|
||||
}
|
||||
|
||||
@@ -1175,8 +1183,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override void AddCollisionEvent(uint CollidedWith, ContactPoint contact)
|
||||
{
|
||||
if (CollisionEvents == null)
|
||||
CollisionEvents = new CollisionEventUpdate();
|
||||
CollisionEvents ??= new CollisionEventUpdate();
|
||||
|
||||
CollisionEvents.AddCollider(CollidedWith, contact);
|
||||
m_parentScene.AddCollisionEventReporting(this);
|
||||
@@ -1185,8 +1192,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override void AddVDTCCollisionEvent(uint CollidedWith, ContactPoint contact)
|
||||
{
|
||||
if (CollisionVDTCEvents == null)
|
||||
CollisionVDTCEvents = new CollisionEventUpdate();
|
||||
CollisionVDTCEvents ??= new CollisionEventUpdate();
|
||||
|
||||
CollisionVDTCEvents.AddCollider(CollidedWith, contact);
|
||||
m_parentScene.AddCollisionEventReporting(this);
|
||||
@@ -1324,7 +1330,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
|
||||
m_targetSpace = IntPtr.Zero;
|
||||
|
||||
m_isphysical = pos.Z < Constants.MinSimulationHeight || pos.Z > Constants.MaxSimulationHeight ? false : pisPhysical;
|
||||
m_isphysical = pos.Z >= Constants.MinSimulationHeight && pos.Z <= Constants.MaxSimulationHeight && pisPhysical;
|
||||
m_fakeisphysical = m_isphysical;
|
||||
|
||||
m_isVolumeDetect = false;
|
||||
@@ -1652,17 +1658,12 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
|
||||
private bool GetMeshGeom()
|
||||
{
|
||||
IntPtr vertices, indices;
|
||||
int vertexCount, indexCount;
|
||||
int vertexStride, triStride;
|
||||
|
||||
IMesh mesh = m_mesh;
|
||||
|
||||
if (mesh == null)
|
||||
if (mesh is null)
|
||||
return false;
|
||||
|
||||
mesh.getVertexListAsPtrToFloatArray(out vertices, out vertexStride, out vertexCount);
|
||||
mesh.getIndexListAsPtrToIntArray(out indices, out triStride, out indexCount);
|
||||
mesh.getVertexListAsPtrToFloatArray(out IntPtr vertices, out int vertexStride, out int vertexCount);
|
||||
mesh.getIndexListAsPtrToIntArray(out IntPtr indices, out int triStride, out int indexCount);
|
||||
|
||||
if (vertexCount == 0 || indexCount == 0)
|
||||
{
|
||||
@@ -1756,7 +1757,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
|
||||
if (!hasMesh)
|
||||
{
|
||||
IntPtr geo = IntPtr.Zero;
|
||||
IntPtr geo;
|
||||
|
||||
if (m_pbs.ProfileShape == ProfileShape.HalfCircle && m_pbs.PathCurve == (byte)Extrusion.Curve1
|
||||
&& m_size.X == m_size.Y && m_size.Y == m_size.Z)
|
||||
@@ -1911,11 +1912,11 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
Body = SafeNativeMethods.BodyCreate(m_parentScene.world);
|
||||
|
||||
// set the body rotation
|
||||
SafeNativeMethods.Matrix3 mymat = new SafeNativeMethods.Matrix3();
|
||||
SafeNativeMethods.Matrix3 mymat = new();
|
||||
SafeNativeMethods.RfromQ(ref mymat, ref m_orientation);
|
||||
SafeNativeMethods.BodySetRotation(Body, ref mymat);
|
||||
|
||||
SafeNativeMethods.Mass objdmass = new SafeNativeMethods.Mass { };
|
||||
SafeNativeMethods.Mass objdmass = new();
|
||||
|
||||
|
||||
if (noInertiaOverride)
|
||||
@@ -1927,8 +1928,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
// recompute full object inertia if needed
|
||||
if (childrenPrim.Count > 0)
|
||||
{
|
||||
SafeNativeMethods.Matrix3 mat = new SafeNativeMethods.Matrix3();
|
||||
SafeNativeMethods.Mass tmpdmass = new SafeNativeMethods.Mass { };
|
||||
SafeNativeMethods.Matrix3 mat = new();
|
||||
SafeNativeMethods.Mass tmpdmass;
|
||||
Vector3 rcm;
|
||||
|
||||
rcm = m_position;
|
||||
@@ -2017,9 +2018,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
|
||||
objdmass.mass = m_InertiaOverride.TotalMass;
|
||||
|
||||
if(Math.Abs(m_InertiaOverride.InertiaRotation.W) < 0.999)
|
||||
if(MathF.Abs(m_InertiaOverride.InertiaRotation.W) < 0.999f)
|
||||
{
|
||||
SafeNativeMethods.Matrix3 inertiarotmat = new SafeNativeMethods.Matrix3();
|
||||
SafeNativeMethods.Matrix3 inertiarotmat = new();
|
||||
SafeNativeMethods.RfromQ(ref inertiarotmat, ref m_InertiaOverride.InertiaRotation);
|
||||
SafeNativeMethods.MassRotate(ref objdmass, ref inertiarotmat);
|
||||
}
|
||||
@@ -2233,14 +2234,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
|
||||
private void FixInertia(Vector3 NewPos,Quaternion newrot)
|
||||
{
|
||||
SafeNativeMethods.Matrix3 mat = new SafeNativeMethods.Matrix3();
|
||||
SafeNativeMethods.Quaternion quat = new SafeNativeMethods.Quaternion();
|
||||
|
||||
SafeNativeMethods.Mass tmpdmass = new SafeNativeMethods.Mass { };
|
||||
SafeNativeMethods.Mass objdmass = new SafeNativeMethods.Mass { };
|
||||
|
||||
SafeNativeMethods.BodyGetMass(Body, out tmpdmass);
|
||||
objdmass = tmpdmass;
|
||||
SafeNativeMethods.BodyGetMass(Body, out SafeNativeMethods.Mass tmpdmass);
|
||||
SafeNativeMethods.Mass objdmass = tmpdmass;
|
||||
|
||||
SafeNativeMethods.Vector3 dobjpos;
|
||||
SafeNativeMethods.Vector3 thispos;
|
||||
@@ -2252,7 +2247,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
tmpdmass = primdMass;
|
||||
|
||||
// transform to object frame
|
||||
mat = SafeNativeMethods.GeomGetOffsetRotation(m_prim_geom);
|
||||
SafeNativeMethods.Matrix3 mat = SafeNativeMethods.GeomGetOffsetRotation(m_prim_geom);
|
||||
SafeNativeMethods.MassRotate(ref tmpdmass, ref mat);
|
||||
|
||||
thispos = SafeNativeMethods.GeomGetOffsetPosition(m_prim_geom);
|
||||
@@ -2271,10 +2266,13 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
m_position = NewPos;
|
||||
SafeNativeMethods.GeomSetOffsetWorldPosition(m_prim_geom, NewPos.X, NewPos.Y, NewPos.Z);
|
||||
m_orientation = newrot;
|
||||
quat.X = newrot.X;
|
||||
quat.Y = newrot.Y;
|
||||
quat.Z = newrot.Z;
|
||||
quat.W = newrot.W;
|
||||
SafeNativeMethods.Quaternion quat = new()
|
||||
{
|
||||
X = newrot.X,
|
||||
Y = newrot.Y,
|
||||
Z = newrot.Z,
|
||||
W = newrot.W
|
||||
};
|
||||
SafeNativeMethods.GeomSetOffsetWorldQuaternion(m_prim_geom, ref quat);
|
||||
|
||||
mat = SafeNativeMethods.GeomGetOffsetRotation(m_prim_geom);
|
||||
@@ -2309,15 +2307,14 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
|
||||
private void FixInertia(Vector3 NewPos)
|
||||
{
|
||||
SafeNativeMethods.Matrix3 primmat = new SafeNativeMethods.Matrix3();
|
||||
SafeNativeMethods.Mass tmpdmass = new SafeNativeMethods.Mass { };
|
||||
SafeNativeMethods.Mass objdmass = new SafeNativeMethods.Mass { };
|
||||
SafeNativeMethods.Mass primmass = new SafeNativeMethods.Mass { };
|
||||
SafeNativeMethods.Matrix3 primmat;
|
||||
SafeNativeMethods.Mass tmpdmass;
|
||||
SafeNativeMethods.Mass primmass;
|
||||
|
||||
SafeNativeMethods.Vector3 dobjpos;
|
||||
SafeNativeMethods.Vector3 thispos;
|
||||
|
||||
SafeNativeMethods.BodyGetMass(Body, out objdmass);
|
||||
SafeNativeMethods.BodyGetMass(Body, out SafeNativeMethods.Mass objdmass);
|
||||
|
||||
// get prim own inertia in its local frame
|
||||
primmass = primdMass;
|
||||
@@ -2373,18 +2370,16 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
|
||||
private void FixInertia(Quaternion newrot)
|
||||
{
|
||||
SafeNativeMethods.Matrix3 mat = new SafeNativeMethods.Matrix3();
|
||||
SafeNativeMethods.Quaternion quat = new SafeNativeMethods.Quaternion();
|
||||
SafeNativeMethods.Matrix3 mat;
|
||||
SafeNativeMethods.Quaternion quat = new();
|
||||
|
||||
SafeNativeMethods.Mass tmpdmass = new SafeNativeMethods.Mass { };
|
||||
SafeNativeMethods.Mass objdmass = new SafeNativeMethods.Mass { };
|
||||
SafeNativeMethods.Vector3 dobjpos;
|
||||
SafeNativeMethods.Vector3 thispos;
|
||||
|
||||
SafeNativeMethods.BodyGetMass(Body, out objdmass);
|
||||
SafeNativeMethods.BodyGetMass(Body, out SafeNativeMethods.Mass objdmass);
|
||||
|
||||
// get prim own inertia in its local frame
|
||||
tmpdmass = primdMass;
|
||||
SafeNativeMethods.Mass tmpdmass = primdMass;
|
||||
mat = SafeNativeMethods.GeomGetOffsetRotation(m_prim_geom);
|
||||
SafeNativeMethods.MassRotate(ref tmpdmass, ref mat);
|
||||
// transform to object frame
|
||||
@@ -2957,7 +2952,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
{
|
||||
if (newOri.NotEqual(m_orientation))
|
||||
{
|
||||
SafeNativeMethods.Quaternion myrot = new SafeNativeMethods.Quaternion()
|
||||
SafeNativeMethods.Quaternion myrot = new()
|
||||
{
|
||||
X = newOri.X,
|
||||
Y = newOri.Y,
|
||||
@@ -2987,7 +2982,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
{
|
||||
if (newOri.NotEqual(m_orientation))
|
||||
{
|
||||
SafeNativeMethods.Quaternion myrot = new SafeNativeMethods.Quaternion()
|
||||
SafeNativeMethods.Quaternion myrot = new()
|
||||
{
|
||||
X = newOri.X,
|
||||
Y = newOri.Y,
|
||||
@@ -3020,7 +3015,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
{
|
||||
if (newOri.NotEqual(m_orientation))
|
||||
{
|
||||
SafeNativeMethods.Quaternion myrot = new SafeNativeMethods.Quaternion()
|
||||
SafeNativeMethods.Quaternion myrot = new()
|
||||
{
|
||||
X = newOri.X,
|
||||
Y = newOri.Y,
|
||||
@@ -3054,7 +3049,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
{
|
||||
if (newOri.NotEqual(m_orientation))
|
||||
{
|
||||
SafeNativeMethods.Quaternion myrot = new SafeNativeMethods.Quaternion()
|
||||
SafeNativeMethods.Quaternion myrot = new()
|
||||
{
|
||||
X = newOri.X,
|
||||
Y = newOri.Y,
|
||||
@@ -3157,11 +3152,13 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
if (m_prim_geom != IntPtr.Zero)
|
||||
{
|
||||
SafeNativeMethods.GeomSetPosition(m_prim_geom, m_position.X, m_position.Y, m_position.Z);
|
||||
SafeNativeMethods.Quaternion myrot = new SafeNativeMethods.Quaternion();
|
||||
myrot.X = m_orientation.X;
|
||||
myrot.Y = m_orientation.Y;
|
||||
myrot.Z = m_orientation.Z;
|
||||
myrot.W = m_orientation.W;
|
||||
SafeNativeMethods.Quaternion myrot = new()
|
||||
{
|
||||
X = m_orientation.X,
|
||||
Y = m_orientation.Y,
|
||||
Z = m_orientation.Z,
|
||||
W = m_orientation.W
|
||||
};
|
||||
SafeNativeMethods.GeomSetQuaternion(m_prim_geom, ref myrot);
|
||||
}
|
||||
|
||||
@@ -3234,11 +3231,13 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
if (m_prim_geom != IntPtr.Zero)
|
||||
{
|
||||
SafeNativeMethods.GeomSetPosition(m_prim_geom, m_position.X, m_position.Y, m_position.Z);
|
||||
SafeNativeMethods.Quaternion myrot = new SafeNativeMethods.Quaternion();
|
||||
myrot.X = m_orientation.X;
|
||||
myrot.Y = m_orientation.Y;
|
||||
myrot.Z = m_orientation.Z;
|
||||
myrot.W = m_orientation.W;
|
||||
SafeNativeMethods.Quaternion myrot = new()
|
||||
{
|
||||
X = m_orientation.X,
|
||||
Y = m_orientation.Y,
|
||||
Z = m_orientation.Z,
|
||||
W = m_orientation.W
|
||||
};
|
||||
SafeNativeMethods.GeomSetQuaternion(m_prim_geom, ref myrot);
|
||||
}
|
||||
|
||||
@@ -3367,7 +3366,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
float len = newVel.LengthSquared();
|
||||
if (len > 100000.0f) // limit to 100m/s
|
||||
{
|
||||
len = 100.0f / (float)Math.Sqrt(len);
|
||||
len = 100.0f / MathF.Sqrt(len);
|
||||
newVel *= len;
|
||||
}
|
||||
|
||||
@@ -3395,7 +3394,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
float len = newAngVel.LengthSquared();
|
||||
if (len > m_parentScene.maxAngVelocitySQ)
|
||||
{
|
||||
len = m_parentScene.maximumAngularVelocity / (float)Math.Sqrt(len);
|
||||
len = m_parentScene.maximumAngularVelocity / MathF.Sqrt(len);
|
||||
newAngVel *= len;
|
||||
}
|
||||
|
||||
@@ -3456,8 +3455,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void changeSetVehicle(VehicleData vdata)
|
||||
{
|
||||
if (m_vehicle == null)
|
||||
m_vehicle = new ODEDynamics(this);
|
||||
m_vehicle ??= new ODEDynamics(this);
|
||||
m_vehicle.DoSetVehicle(vdata);
|
||||
}
|
||||
|
||||
@@ -3471,8 +3469,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_vehicle == null)
|
||||
m_vehicle = new ODEDynamics(this);
|
||||
m_vehicle ??= new ODEDynamics(this);
|
||||
|
||||
m_vehicle.ProcessTypeChange((Vehicle)value);
|
||||
}
|
||||
@@ -3742,7 +3739,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
fz = (m_targetHoverHeight - lpos.Z);
|
||||
|
||||
// if error is zero, use position control; otherwise, velocity control
|
||||
if (Math.Abs(fz) < 0.01f)
|
||||
if (MathF.Abs(fz) < 0.01f)
|
||||
{
|
||||
SafeNativeMethods.BodySetPosition(Body, lpos.X, lpos.Y, m_targetHoverHeight);
|
||||
SafeNativeMethods.BodySetLinearVel(Body, vel.X, vel.Y, 0);
|
||||
@@ -3911,13 +3908,13 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
angerror = 0.0005f;
|
||||
}
|
||||
|
||||
if (
|
||||
(Math.Abs(m_position.X - lpos.X) < poserror)
|
||||
&& (Math.Abs(m_position.Y - lpos.Y) < poserror)
|
||||
&& (Math.Abs(m_position.Z - lpos.Z) < poserror)
|
||||
&& (Math.Abs(m_orientation.X - ori.X) < angerror)
|
||||
&& (Math.Abs(m_orientation.Y - ori.Y) < angerror)
|
||||
&& (Math.Abs(m_orientation.Z - ori.Z) < angerror) // ignore W
|
||||
if (
|
||||
(MathF.Abs(m_position.X - lpos.X) < poserror)
|
||||
&& (MathF.Abs(m_position.Y - lpos.Y) < poserror)
|
||||
&& (MathF.Abs(m_position.Z - lpos.Z) < poserror)
|
||||
&& (MathF.Abs(m_orientation.X - ori.X) < angerror)
|
||||
&& (MathF.Abs(m_orientation.Y - ori.Y) < angerror)
|
||||
&& (MathF.Abs(m_orientation.Z - ori.Z) < angerror) // ignore W
|
||||
)
|
||||
_zeroFlag = true;
|
||||
else
|
||||
@@ -3943,14 +3940,11 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
{
|
||||
Vector3 vel = SafeNativeMethods.BodyGetLinearVelOMV(Body);
|
||||
m_acceleration = _velocity;
|
||||
|
||||
if ((Math.Abs(vel.X) < 0.005f) &&
|
||||
(Math.Abs(vel.Y) < 0.005f) &&
|
||||
(Math.Abs(vel.Z) < 0.005f))
|
||||
if (vel.ApproxZero(0.005f))
|
||||
{
|
||||
_velocity = Vector3.Zero;
|
||||
float t = -m_sceneInverseTimeStep;
|
||||
m_acceleration = m_acceleration * t;
|
||||
m_acceleration *= t;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -3958,18 +3952,13 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
m_acceleration = (_velocity - m_acceleration) * m_sceneInverseTimeStep;
|
||||
}
|
||||
|
||||
if ((Math.Abs(m_acceleration.X) < 0.01f) &&
|
||||
(Math.Abs(m_acceleration.Y) < 0.01f) &&
|
||||
(Math.Abs(m_acceleration.Z) < 0.01f))
|
||||
if (m_acceleration.ApproxZero(0.01f))
|
||||
{
|
||||
m_acceleration = Vector3.Zero;
|
||||
}
|
||||
|
||||
vel = SafeNativeMethods.BodyGetAngularVelOMV(Body);
|
||||
if ((Math.Abs(vel.X) < 0.0001) &&
|
||||
(Math.Abs(vel.Y) < 0.0001) &&
|
||||
(Math.Abs(vel.Z) < 0.0001)
|
||||
)
|
||||
if (vel.ApproxZero(0.0001f))
|
||||
{
|
||||
m_rotationalVelocity = Vector3.Zero;
|
||||
}
|
||||
|
||||
@@ -177,8 +177,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
const float commonContactCFM = 0.0001f;
|
||||
const float commomContactSLIP = 0f;
|
||||
|
||||
float TerrainBounce = 0.001f;
|
||||
float TerrainFriction = 0.3f;
|
||||
readonly float TerrainBounce = 0.001f;
|
||||
readonly float TerrainFriction = 0.3f;
|
||||
|
||||
public float AvatarFriction = 0;// 0.9f * 0.5f;
|
||||
|
||||
@@ -223,33 +223,33 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
|
||||
private SafeNativeMethods.NearCallback NearCallback;
|
||||
|
||||
private readonly Dictionary<uint, OdePrim> _prims = new Dictionary<uint, OdePrim>();
|
||||
private readonly HashSet<OdeCharacter> _characters = new HashSet<OdeCharacter>();
|
||||
private readonly HashSet<OdePrim> _activeprims = new HashSet<OdePrim>();
|
||||
private readonly HashSet<OdePrim> _activegroups = new HashSet<OdePrim>();
|
||||
private readonly Dictionary<uint, OdePrim> _prims = new();
|
||||
private readonly HashSet<OdeCharacter> _characters = new();
|
||||
private readonly HashSet<OdePrim> _activeprims = new();
|
||||
private readonly HashSet<OdePrim> _activegroups = new();
|
||||
public List<OdeCharacter> _charactersList;
|
||||
|
||||
public readonly ConcurrentQueue<ODEchangeitem> ChangesQueue = new ConcurrentQueue<ODEchangeitem>();
|
||||
public readonly ConcurrentQueue<ODEchangeitem> ChangesQueue = new();
|
||||
|
||||
/// <summary>
|
||||
/// A list of actors that should receive collision events.
|
||||
/// </summary>
|
||||
private readonly List<PhysicsActor> _collisionEventPrim = new List<PhysicsActor>();
|
||||
private readonly List<PhysicsActor> _collisionEventPrimRemove = new List<PhysicsActor>();
|
||||
private readonly Dictionary<uint, PhysicsActor> _collisionEventPrim = new();
|
||||
private readonly List<PhysicsActor> _collisionEventPrimRemove = new();
|
||||
|
||||
private readonly List<OdeCharacter> _badCharacter = new List<OdeCharacter>();
|
||||
public readonly Dictionary<IntPtr, PhysicsActor> actor_name_map = new Dictionary<IntPtr, PhysicsActor>();
|
||||
private readonly List<OdeCharacter> _badCharacter = new();
|
||||
public readonly Dictionary<IntPtr, PhysicsActor> actor_name_map = new();
|
||||
|
||||
private float contactsurfacelayer = 0.002f;
|
||||
private readonly float contactsurfacelayer = 0.002f;
|
||||
|
||||
private int contactsPerCollision = 80;
|
||||
private readonly int contactsPerCollision = 80;
|
||||
internal IntPtr ContactgeomsArray = IntPtr.Zero;
|
||||
internal SafeNativeMethods.ContactGeom[] m_contacts;
|
||||
internal GCHandle m_contactsHandler;
|
||||
|
||||
private IntPtr GlobalContactsArray;
|
||||
|
||||
private SafeNativeMethods.Contact contactSharedForJoints = new SafeNativeMethods.Contact();
|
||||
private SafeNativeMethods.Contact contactSharedForJoints = new();
|
||||
|
||||
const int maxContactJoints = 6000;
|
||||
private volatile int ContactJointCount = 0;
|
||||
@@ -260,12 +260,12 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
|
||||
public IntPtr TerrainGeom;
|
||||
private float[] m_terrainHeights;
|
||||
private GCHandle m_terrainHeightsHandler = new GCHandle();
|
||||
private GCHandle m_terrainHeightsHandler = new();
|
||||
private IntPtr HeightmapData;
|
||||
private int m_lastRegionWidth;
|
||||
private int m_lastRegionHeight;
|
||||
|
||||
private int m_physicsiterations = 15;
|
||||
private readonly int m_physicsiterations = 15;
|
||||
private const float m_SkipFramesAtms = 0.40f; // Drop frames gracefully at a 400 ms lag
|
||||
//private PhysicsActor PANull = new NullPhysicsActor();
|
||||
private float step_time = 0.0f;
|
||||
@@ -282,13 +282,13 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
public IntPtr ActiveSpace; // space for active prims
|
||||
public IntPtr StaticSpace; // space for the static things around
|
||||
|
||||
public readonly object OdeLock = new object();
|
||||
public static readonly object SimulationLock = new object();
|
||||
public readonly object OdeLock = new();
|
||||
public static readonly object SimulationLock = new();
|
||||
public IMesher mesher;
|
||||
|
||||
public IConfigSource m_config;
|
||||
|
||||
public Vector2 WorldExtents = new Vector2((int)Constants.RegionSize, (int)Constants.RegionSize);
|
||||
public Vector2 WorldExtents = new((int)Constants.RegionSize, (int)Constants.RegionSize);
|
||||
|
||||
private ODERayCastRequestManager m_rayCastManager;
|
||||
public ODEMeshWorker m_meshWorker;
|
||||
@@ -362,7 +362,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
ActiveSpace = SafeNativeMethods.SimpleSpaceCreate(TopSpace);
|
||||
float sx = m_regionWidth + 16;
|
||||
float sy = m_regionHeight + 16;
|
||||
SafeNativeMethods.Vector3 px = new SafeNativeMethods.Vector3(sx * 0.5f, sy * 0.5f, 0);
|
||||
SafeNativeMethods.Vector3 px = new(sx * 0.5f, sy * 0.5f, 0);
|
||||
if (sx < sy)
|
||||
sx = sy;
|
||||
int dp = Util.intLog2((uint)sx);
|
||||
@@ -546,12 +546,12 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
contactSharedForJoints.geom.pos = contactGeom.pos;
|
||||
contactSharedForJoints.geom.normal = contactGeom.normal;
|
||||
|
||||
IntPtr contact = new IntPtr(GlobalContactsArray.ToInt64() + (Int64)(ContactJointCount * SafeNativeMethods.Contact.unmanagedSizeOf));
|
||||
IntPtr contact = new(GlobalContactsArray.ToInt64() + (Int64)(ContactJointCount * SafeNativeMethods.Contact.unmanagedSizeOf));
|
||||
Marshal.StructureToPtr(contactSharedForJoints, contact, false);
|
||||
return SafeNativeMethods.JointCreateContactPtr(world, JointContactGroup, contact);
|
||||
}
|
||||
|
||||
SafeNativeMethods.ContactGeom altWorkContact = new SafeNativeMethods.ContactGeom();
|
||||
SafeNativeMethods.ContactGeom altWorkContact = new();
|
||||
|
||||
/// <summary>
|
||||
/// This is our near callback. A geometry is near a body
|
||||
@@ -635,7 +635,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
// do volume detection case
|
||||
if ((p1.IsVolumeDtc || p2.IsVolumeDtc))
|
||||
{
|
||||
ContactPoint volDepthContact = new ContactPoint(
|
||||
ContactPoint volDepthContact = new(
|
||||
new Vector3(m_contacts[0].pos.X, m_contacts[0].pos.Y, m_contacts[0].pos.Z),
|
||||
new Vector3(m_contacts[0].normal.X, m_contacts[0].normal.Y, m_contacts[0].normal.Z),
|
||||
m_contacts[0].depth, false
|
||||
@@ -650,8 +650,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
float bounce = 0;
|
||||
//bool IgnoreNegSides = false;
|
||||
|
||||
ContactData contactdata1 = new ContactData(0, 0, false);
|
||||
ContactData contactdata2 = new ContactData(0, 0, false);
|
||||
ContactData contactdata1 = new(0, 0, false);
|
||||
ContactData contactdata2 = new(0, 0, false);
|
||||
|
||||
bool dop1ava = false;
|
||||
bool dop2ava = false;
|
||||
@@ -760,7 +760,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
bool FeetCollision = false;
|
||||
int ncontacts = 0;
|
||||
|
||||
ContactPoint maxDepthContact = new ContactPoint();
|
||||
ContactPoint maxDepthContact = new();
|
||||
|
||||
float minDepth = float.MaxValue;
|
||||
float maxDepth = float.MinValue;
|
||||
@@ -879,16 +879,11 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
if (count == 0)
|
||||
return;
|
||||
|
||||
// get first contact
|
||||
|
||||
ContactData contactdata1 = new ContactData(0, 0, false);
|
||||
ContactData contactdata2 = new ContactData(0, 0, false);
|
||||
|
||||
IntPtr Joint;
|
||||
bool FeetCollision = false;
|
||||
int ncontacts = 0;
|
||||
|
||||
ContactPoint maxDepthContact = new ContactPoint();
|
||||
ContactPoint maxDepthContact = new();
|
||||
|
||||
float minDepth = float.MaxValue;
|
||||
float maxDepth = float.MinValue;
|
||||
@@ -946,7 +941,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
|
||||
private void collision_accounting_events(PhysicsActor p1, PhysicsActor p2, ContactPoint contact)
|
||||
{
|
||||
uint obj2LocalID = 0;
|
||||
|
||||
// update actors collision score
|
||||
if (p1.CollisionScore < float.MaxValue)
|
||||
@@ -974,6 +968,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
|
||||
contact.RelativeSpeed = Vector3.Dot(vel, contact.SurfaceNormal);
|
||||
|
||||
uint obj2LocalID;
|
||||
|
||||
switch ((ActorTypes)p1.PhysicsActorType)
|
||||
{
|
||||
case ActorTypes.Agent:
|
||||
@@ -1185,8 +1181,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
/// <param name="obj"></param>
|
||||
public void AddCollisionEventReporting(PhysicsActor obj)
|
||||
{
|
||||
if (!_collisionEventPrim.Contains(obj))
|
||||
_collisionEventPrim.Add(obj);
|
||||
_collisionEventPrim[obj.LocalID] = obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1215,10 +1210,12 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
|
||||
public override PhysicsActor AddAvatar(uint localID, string avName, Vector3 position, Vector3 size, float feetOffset, bool isFlying)
|
||||
{
|
||||
OdeCharacter newAv = new OdeCharacter(localID, avName, this, position,
|
||||
size, feetOffset, avDensity, avMovementDivisorWalk, avMovementDivisorRun);
|
||||
newAv.Flying = isFlying;
|
||||
newAv.MinimumGroundFlightOffset = minimumGroundFlightOffset;
|
||||
OdeCharacter newAv = new(localID, avName, this, position,
|
||||
size, feetOffset, avDensity, avMovementDivisorWalk, avMovementDivisorRun)
|
||||
{
|
||||
Flying = isFlying,
|
||||
MinimumGroundFlightOffset = minimumGroundFlightOffset
|
||||
};
|
||||
|
||||
return newAv;
|
||||
}
|
||||
@@ -1346,9 +1343,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
{
|
||||
// As with all ODE physics operations, we don't remove the prim immediately but signal that it should be
|
||||
// removed in the next physics simulate pass.
|
||||
if (prim is OdePrim)
|
||||
if (prim is OdePrim p)
|
||||
{
|
||||
OdePrim p = (OdePrim)prim;
|
||||
p.setPrimForRemoval();
|
||||
}
|
||||
}
|
||||
@@ -1401,15 +1397,15 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
|
||||
public bool haveActor(PhysicsActor actor)
|
||||
{
|
||||
if (actor is OdePrim)
|
||||
if (actor is OdePrim prim)
|
||||
{
|
||||
lock (_prims)
|
||||
return _prims.ContainsKey(((OdePrim)actor).m_baseLocalID);
|
||||
return _prims.ContainsKey(prim.m_baseLocalID);
|
||||
}
|
||||
else if (actor is OdeCharacter)
|
||||
else if (actor is OdeCharacter ch)
|
||||
{
|
||||
lock (_characters)
|
||||
return _characters.Contains((OdeCharacter)actor);
|
||||
return _characters.Contains(ch);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1496,7 +1492,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
{
|
||||
if (world == IntPtr.Zero)
|
||||
return;
|
||||
ODEchangeitem item = new ODEchangeitem
|
||||
ODEchangeitem item = new()
|
||||
{
|
||||
actor = _actor,
|
||||
what = _what,
|
||||
@@ -1539,8 +1535,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
{
|
||||
lock (SimulationLock)
|
||||
{
|
||||
if (item.actor is OdeCharacter)
|
||||
((OdeCharacter)item.actor).DoAChange(item.what, item.arg);
|
||||
if (item.actor is OdeCharacter character)
|
||||
character.DoAChange(item.what, item.arg);
|
||||
else if (((OdePrim)item.actor).DoAChange(item.what, item.arg))
|
||||
RemovePrimThreadLocked((OdePrim)item.actor);
|
||||
}
|
||||
@@ -1623,8 +1619,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
{
|
||||
lock (SimulationLock)
|
||||
{
|
||||
if (item.actor is OdeCharacter)
|
||||
((OdeCharacter)item.actor).DoAChange(item.what, item.arg);
|
||||
if (item.actor is OdeCharacter ch)
|
||||
ch.DoAChange(item.what, item.arg);
|
||||
else if (((OdePrim)item.actor).DoAChange(item.what, item.arg))
|
||||
RemovePrimThreadLocked((OdePrim)item.actor);
|
||||
}
|
||||
@@ -1685,26 +1681,26 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
lock (_collisionEventPrimRemove)
|
||||
{
|
||||
foreach (PhysicsActor obj in _collisionEventPrimRemove)
|
||||
_collisionEventPrim.Remove(obj);
|
||||
_collisionEventPrim.Remove(obj.LocalID);
|
||||
|
||||
_collisionEventPrimRemove.Clear();
|
||||
}
|
||||
|
||||
List<OdePrim> sleepers = new List<OdePrim>();
|
||||
foreach (PhysicsActor obj in _collisionEventPrim)
|
||||
List<OdePrim> sleepers = new();
|
||||
foreach (PhysicsActor obj in _collisionEventPrim.Values)
|
||||
{
|
||||
switch ((ActorTypes)obj.PhysicsActorType)
|
||||
{
|
||||
case ActorTypes.Agent:
|
||||
OdeCharacter cobj = (OdeCharacter)obj;
|
||||
cobj.SendCollisions((int)(odetimestepMS));
|
||||
cobj.SendCollisions(odetimestepMS);
|
||||
break;
|
||||
|
||||
case ActorTypes.Prim:
|
||||
OdePrim pobj = (OdePrim)obj;
|
||||
if (!pobj.m_outbounds)
|
||||
{
|
||||
pobj.SendCollisions((int)(odetimestepMS));
|
||||
pobj.SendCollisions(odetimestepMS);
|
||||
lock(SimulationLock)
|
||||
{
|
||||
if(pobj.Body != IntPtr.Zero && !pobj.m_isSelected &&
|
||||
@@ -2185,7 +2181,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
foreach (OdePrim prm in _prims.Values)
|
||||
{
|
||||
prm.DoAChange(changes.Remove, null);
|
||||
_collisionEventPrim.Remove(prm);
|
||||
_collisionEventPrim.Remove(prm.LocalID);
|
||||
}
|
||||
_prims.Clear();
|
||||
}
|
||||
@@ -2255,7 +2251,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
{
|
||||
if (retMethod != null)
|
||||
{
|
||||
ODERayRequest req = new ODERayRequest()
|
||||
ODERayRequest req = new()
|
||||
{
|
||||
actor = null,
|
||||
callbackMethod = retMethod,
|
||||
@@ -2273,14 +2269,16 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
{
|
||||
if (retMethod != null)
|
||||
{
|
||||
ODERayRequest req = new ODERayRequest();
|
||||
req.actor = null;
|
||||
req.callbackMethod = retMethod;
|
||||
req.length = length;
|
||||
req.Normal = direction;
|
||||
req.Origin = position;
|
||||
req.Count = Count;
|
||||
req.filter = RayFilterFlags.AllPrims;
|
||||
ODERayRequest req = new()
|
||||
{
|
||||
actor = null,
|
||||
callbackMethod = retMethod,
|
||||
length = length,
|
||||
Normal = direction,
|
||||
Origin = position,
|
||||
Count = Count,
|
||||
filter = RayFilterFlags.AllPrims
|
||||
};
|
||||
|
||||
m_rayCastManager.QueueRequest(req);
|
||||
}
|
||||
@@ -2288,8 +2286,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
|
||||
public override List<ContactResult> RaycastWorld(Vector3 position, Vector3 direction, float length, int Count)
|
||||
{
|
||||
List<ContactResult> ourresults = new List<ContactResult>();
|
||||
object SyncObject = new object();
|
||||
List<ContactResult> ourresults = new();
|
||||
object SyncObject = new();
|
||||
|
||||
RayCallback retMethod = delegate(List<ContactResult> results)
|
||||
{
|
||||
@@ -2300,7 +2298,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
}
|
||||
};
|
||||
|
||||
ODERayRequest req = new ODERayRequest
|
||||
ODERayRequest req = new()
|
||||
{
|
||||
actor = null,
|
||||
callbackMethod = retMethod,
|
||||
@@ -2328,8 +2326,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
|
||||
public override object RaycastWorld(Vector3 position, Vector3 direction, float length, int Count, RayFilterFlags filter)
|
||||
{
|
||||
object SyncObject = new object();
|
||||
List<ContactResult> ourresults = new List<ContactResult>();
|
||||
object SyncObject = new();
|
||||
List<ContactResult> ourresults = new();
|
||||
|
||||
RayCallback retMethod = delegate(List<ContactResult> results)
|
||||
{
|
||||
@@ -2340,7 +2338,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
}
|
||||
};
|
||||
|
||||
ODERayRequest req = new ODERayRequest()
|
||||
ODERayRequest req = new()
|
||||
{
|
||||
actor = null,
|
||||
callbackMethod = retMethod,
|
||||
@@ -2367,10 +2365,10 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
return new List<ContactResult>();
|
||||
|
||||
IntPtr geom;
|
||||
if (actor is OdePrim)
|
||||
geom = ((OdePrim)actor).m_prim_geom;
|
||||
else if (actor is OdeCharacter)
|
||||
geom = ((OdePrim)actor).m_prim_geom;
|
||||
if (actor is OdePrim prim)
|
||||
geom = prim.m_prim_geom;
|
||||
else if (actor is OdeCharacter ch)
|
||||
geom = ch.collider;
|
||||
else
|
||||
return new List<ContactResult>();
|
||||
|
||||
@@ -2378,7 +2376,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
return new List<ContactResult>();
|
||||
|
||||
List<ContactResult> ourResults = null;
|
||||
object SyncObject = new object();
|
||||
object SyncObject = new();
|
||||
|
||||
RayCallback retMethod = delegate(List<ContactResult> results)
|
||||
{
|
||||
@@ -2389,7 +2387,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
}
|
||||
};
|
||||
|
||||
ODERayRequest req = new ODERayRequest
|
||||
ODERayRequest req = new()
|
||||
{
|
||||
actor = actor,
|
||||
callbackMethod = retMethod,
|
||||
@@ -2416,8 +2414,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
{
|
||||
Util.FireAndForget( delegate
|
||||
{
|
||||
ODESitAvatar sitAvatar = new ODESitAvatar(this, m_rayCastManager);
|
||||
if(sitAvatar != null)
|
||||
ODESitAvatar sitAvatar = new(this, m_rayCastManager);
|
||||
if(sitAvatar is not null)
|
||||
sitAvatar.Sit(actor, AbsolutePosition, CameraPosition, offset, AvatarSize, PhysicsSitResponse);
|
||||
});
|
||||
return 1;
|
||||
|
||||
@@ -45,15 +45,14 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
m_raymanager = raymanager;
|
||||
}
|
||||
|
||||
private static readonly Vector3 SitAjust = new Vector3(0, 0, 0.4f);
|
||||
private static readonly Vector3 SitAjust = new(0, 0, 0.4f);
|
||||
private const RayFilterFlags RaySitFlags = RayFilterFlags.AllPrims | RayFilterFlags.ClosestHit;
|
||||
|
||||
private void RotAroundZ(float x, float y, ref Quaternion ori)
|
||||
{
|
||||
double ang = Math.Atan2(y, x);
|
||||
ang *= 0.5d;
|
||||
float s = (float)Math.Sin(ang);
|
||||
float c = (float)Math.Cos(ang);
|
||||
float ang = 0.5f * MathF.Atan2(y, x);
|
||||
float s = MathF.Sin(ang);
|
||||
float c = MathF.Cos(ang);
|
||||
|
||||
ori.X = 0;
|
||||
ori.Y = 0;
|
||||
@@ -64,7 +63,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
|
||||
public void Sit(PhysicsActor actor, Vector3 avPos, Vector3 avCameraPosition, Vector3 offset, Vector3 avOffset, SitAvatarCallback PhysicsSitResponse)
|
||||
{
|
||||
if (!m_scene.haveActor(actor) || !(actor is OdePrim) || ((OdePrim)actor).m_prim_geom == IntPtr.Zero)
|
||||
if (!m_scene.haveActor(actor) || actor is not OdePrim || ((OdePrim)actor).m_prim_geom == IntPtr.Zero)
|
||||
{
|
||||
PhysicsSitResponse(-1, actor.LocalID, offset, Quaternion.Identity);
|
||||
return;
|
||||
@@ -205,7 +204,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
|
||||
if (rayResults.Count == 0)
|
||||
break;
|
||||
|
||||
if (Math.Abs(rayResults[0].Normal.Z) < 0.7f)
|
||||
if (MathF.Abs(rayResults[0].Normal.Z) < 0.7f)
|
||||
{
|
||||
rayDist -= rayResults[0].Depth;
|
||||
if (rayDist < 0f)
|
||||
|
||||
Reference in New Issue
Block a user