Modifications for prim movement. For now only in Mod. BulletX, but i think it can be easy to add to ODE. Enjoy kick the prims and be careful with the falling ones ;D
parent
dabbdec2cd
commit
fbf3c6a768
|
@ -55,6 +55,9 @@ namespace OpenSim.Region.Environment.Scenes
|
|||
|
||||
public bool HasChanged = false;
|
||||
|
||||
private LLVector3 lastPhysGroupPos;
|
||||
private LLQuaternion lastPhysGroupRot;
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
|
@ -490,6 +493,25 @@ namespace OpenSim.Region.Environment.Scenes
|
|||
/// </summary>
|
||||
public override void Update()
|
||||
{
|
||||
if (lastPhysGroupPos.GetDistanceTo(AbsolutePosition) > 0.02)
|
||||
{
|
||||
foreach (SceneObjectPart part in m_parts.Values)
|
||||
{
|
||||
if (part.UpdateFlag == 0) part.UpdateFlag = 1;
|
||||
}
|
||||
lastPhysGroupPos = AbsolutePosition;
|
||||
}
|
||||
if ((Math.Abs(lastPhysGroupRot.W - GroupRotation.W) > 0.1)
|
||||
|| (Math.Abs(lastPhysGroupRot.X - GroupRotation.X) > 0.1)
|
||||
|| (Math.Abs(lastPhysGroupRot.Y - GroupRotation.Y) > 0.1)
|
||||
|| (Math.Abs(lastPhysGroupRot.Z - GroupRotation.Z) > 0.1))
|
||||
{
|
||||
foreach (SceneObjectPart part in m_parts.Values)
|
||||
{
|
||||
if (part.UpdateFlag == 0) part.UpdateFlag = 1;
|
||||
}
|
||||
lastPhysGroupRot = GroupRotation;
|
||||
}
|
||||
foreach (SceneObjectPart part in m_parts.Values)
|
||||
{
|
||||
part.SendScheduledUpdates();
|
||||
|
|
|
@ -148,8 +148,34 @@ namespace OpenSim.Region.Environment.Scenes
|
|||
|
||||
public LLVector3 GroupPosition
|
||||
{
|
||||
get { return m_groupPosition; }
|
||||
set { m_groupPosition = value; }
|
||||
get
|
||||
{
|
||||
if (PhysActor != null)
|
||||
{
|
||||
m_groupPosition.X = PhysActor.Position.X;
|
||||
m_groupPosition.Y = PhysActor.Position.Y;
|
||||
m_groupPosition.Z = PhysActor.Position.Z;
|
||||
}
|
||||
return m_groupPosition;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (PhysActor != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
//lock (m_scene.SyncRoot)
|
||||
//{
|
||||
PhysActor.Position = new PhysicsVector(value.X, value.Y, value.Z);
|
||||
//}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
}
|
||||
m_groupPosition = value;
|
||||
}
|
||||
}
|
||||
|
||||
protected LLVector3 m_offsetPosition;
|
||||
|
@ -169,8 +195,35 @@ namespace OpenSim.Region.Environment.Scenes
|
|||
|
||||
public LLQuaternion RotationOffset
|
||||
{
|
||||
get { return m_rotationOffset; }
|
||||
set { m_rotationOffset = value; }
|
||||
get
|
||||
{
|
||||
if (PhysActor != null)
|
||||
{
|
||||
m_rotationOffset.X = PhysActor.Orientation.x;
|
||||
m_rotationOffset.Y = PhysActor.Orientation.y;
|
||||
m_rotationOffset.Z = PhysActor.Orientation.z;
|
||||
m_rotationOffset.W = PhysActor.Orientation.w;
|
||||
}
|
||||
return m_rotationOffset;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (PhysActor != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
//lock (m_scene.SyncRoot)
|
||||
//{
|
||||
PhysActor.Orientation = new Quaternion(value.W, value.X, value.Y, value.Z);
|
||||
//}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
m_rotationOffset = value;
|
||||
}
|
||||
}
|
||||
|
||||
protected LLVector3 m_velocity;
|
||||
|
@ -260,7 +313,12 @@ namespace OpenSim.Region.Environment.Scenes
|
|||
public SceneObjectGroup ParentGroup
|
||||
{
|
||||
get { return m_parentGroup; }
|
||||
}
|
||||
|
||||
public byte UpdateFlag
|
||||
{
|
||||
get { return m_updateFlag; }
|
||||
set { m_updateFlag = value; }
|
||||
}
|
||||
|
||||
#region Constructors
|
||||
|
@ -502,6 +560,7 @@ namespace OpenSim.Region.Environment.Scenes
|
|||
{
|
||||
AddTerseUpdateToAllAvatars();
|
||||
ClearUpdateSchedule();
|
||||
ScheduleTerseUpdate();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -706,6 +765,10 @@ namespace OpenSim.Region.Environment.Scenes
|
|||
new Quaternion(RotationOffset.W, RotationOffset.X,
|
||||
RotationOffset.Y, RotationOffset.Z), UsePhysics);
|
||||
}
|
||||
else
|
||||
{
|
||||
PhysActor.IsPhysical = UsePhysics;
|
||||
}
|
||||
}
|
||||
|
||||
if (IsTemporary)
|
||||
|
|
|
@ -400,35 +400,30 @@ namespace OpenSim.Region.Physics.BulletXPlugin
|
|||
/// support simple box & hollow box now; later, more shapes
|
||||
if (pbs.ProfileHollow == 0)
|
||||
{
|
||||
result = AddPrim(primName, position, size, rotation, null, null);
|
||||
result = AddPrim(primName, position, size, rotation, null, null, isPhysical);
|
||||
}
|
||||
else
|
||||
{
|
||||
Mesh mesh = null;
|
||||
result = AddPrim(primName, position, size, rotation, mesh, pbs);
|
||||
result = AddPrim(primName, position, size, rotation, mesh, pbs, isPhysical);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
result = AddPrim(primName, position, size, rotation, null, null);
|
||||
result = AddPrim(primName, position, size, rotation, null, null, isPhysical);
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, AxiomQuaternion rotation)
|
||||
{
|
||||
return AddPrim("", position, size, rotation, null, null);
|
||||
}
|
||||
|
||||
public PhysicsActor AddPrim(String name, PhysicsVector position, PhysicsVector size, AxiomQuaternion rotation,
|
||||
Mesh mesh, PrimitiveBaseShape pbs)
|
||||
Mesh mesh, PrimitiveBaseShape pbs, bool isPhysical)
|
||||
{
|
||||
BulletXPrim newPrim = null;
|
||||
lock (BulletXLock)
|
||||
{
|
||||
newPrim = new BulletXPrim(name, this, position, size, rotation, mesh, pbs);
|
||||
newPrim = new BulletXPrim(name, this, position, size, rotation, mesh, pbs, isPhysical);
|
||||
_prims.Add(newPrim);
|
||||
}
|
||||
return newPrim;
|
||||
|
@ -641,7 +636,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin
|
|||
public class BulletXActor : PhysicsActor
|
||||
{
|
||||
protected bool flying = false;
|
||||
protected bool _physical = true;
|
||||
protected bool _physical = false;
|
||||
protected PhysicsVector _position;
|
||||
protected PhysicsVector _velocity;
|
||||
protected PhysicsVector _size;
|
||||
|
@ -722,8 +717,8 @@ namespace OpenSim.Region.Physics.BulletXPlugin
|
|||
|
||||
public override bool IsPhysical
|
||||
{
|
||||
get { return false; }
|
||||
set { return; }
|
||||
get { return _physical; }
|
||||
set { _physical = value; }
|
||||
}
|
||||
|
||||
public override bool Flying
|
||||
|
@ -736,17 +731,6 @@ namespace OpenSim.Region.Physics.BulletXPlugin
|
|||
get { return iscolliding; }
|
||||
set { iscolliding = value; }
|
||||
}
|
||||
/*public override bool Physical
|
||||
{
|
||||
get
|
||||
{
|
||||
return _physical;
|
||||
}
|
||||
set
|
||||
{
|
||||
_physical = value;
|
||||
}
|
||||
}*/
|
||||
public virtual void SetAcceleration(PhysicsVector accel)
|
||||
{
|
||||
lock (BulletXScene.BulletXLock)
|
||||
|
@ -854,6 +838,8 @@ namespace OpenSim.Region.Physics.BulletXPlugin
|
|||
//.
|
||||
_acceleration = acceleration;
|
||||
_orientation = orientation;
|
||||
_physical = true;
|
||||
|
||||
float _mass = 50.0f; //This depends of avatar's dimensions
|
||||
//For RigidBody Constructor. The next values might change
|
||||
float _linearDamping = 0.0f;
|
||||
|
@ -1003,25 +989,23 @@ namespace OpenSim.Region.Physics.BulletXPlugin
|
|||
private BulletXScene _parent_scene;
|
||||
|
||||
public BulletXPrim(String primName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector size,
|
||||
AxiomQuaternion rotation, Mesh mesh, PrimitiveBaseShape pbs)
|
||||
: this(primName, parent_scene, pos, new PhysicsVector(), size, new PhysicsVector(), rotation, mesh, pbs)
|
||||
AxiomQuaternion rotation, Mesh mesh, PrimitiveBaseShape pbs, bool isPhysical)
|
||||
: this(primName, parent_scene, pos, new PhysicsVector(), size, new PhysicsVector(), rotation, mesh, pbs, isPhysical)
|
||||
{
|
||||
}
|
||||
public BulletXPrim(String primName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector velocity,
|
||||
PhysicsVector size,
|
||||
PhysicsVector aceleration, AxiomQuaternion rotation, Mesh mesh, PrimitiveBaseShape pbs)
|
||||
PhysicsVector acceleration, AxiomQuaternion rotation, Mesh mesh, PrimitiveBaseShape pbs,
|
||||
bool isPhysical)
|
||||
{
|
||||
if ((size.X == 0) || (size.Y == 0) || (size.Z == 0)) throw new Exception("Size 0");
|
||||
if (rotation.Norm == 0f) rotation = AxiomQuaternion.Identity;
|
||||
|
||||
_position = pos;
|
||||
//ZZZ
|
||||
_physical = false;
|
||||
//zzz
|
||||
if (_physical) _velocity = velocity;
|
||||
else _velocity = new PhysicsVector();
|
||||
_physical = isPhysical;
|
||||
_velocity = _physical ? velocity : new PhysicsVector();
|
||||
_size = size;
|
||||
_acceleration = aceleration;
|
||||
_acceleration = acceleration;
|
||||
_orientation = rotation;
|
||||
|
||||
_parent_scene = parent_scene;
|
||||
|
@ -1068,26 +1052,18 @@ namespace OpenSim.Region.Physics.BulletXPlugin
|
|||
get
|
||||
{
|
||||
//For now all prims are boxes
|
||||
//ZZZ
|
||||
return _density * _size.X * _size.Y * _size.Z;
|
||||
//return (_physical ? 1 : 0) * _density * _size.X * _size.Y * _size.Z;
|
||||
//zzz
|
||||
return (_physical ? 1 : 0) * _density * _size.X * _size.Y * _size.Z;
|
||||
}
|
||||
}
|
||||
public Boolean Physical
|
||||
{
|
||||
get { return _physical; }
|
||||
set { _physical = value; }
|
||||
}
|
||||
/*public override bool Physical
|
||||
public override bool IsPhysical
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.Physical;
|
||||
return base.IsPhysical;
|
||||
}
|
||||
set
|
||||
{
|
||||
base.Physical = value;
|
||||
base.IsPhysical = value;
|
||||
if (value)
|
||||
{
|
||||
//---
|
||||
|
@ -1100,10 +1076,10 @@ namespace OpenSim.Region.Physics.BulletXPlugin
|
|||
//---
|
||||
PhysicsPluginManager.PhysicsPluginMessage("Physical - SetMassProps", true);
|
||||
//---
|
||||
this.rigidBody.SetMassProps(Mass, new MonoXnaCompactMaths.Vector3());
|
||||
this.rigidBody.SetMassProps(Mass, new Vector3());
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
public override bool Flying
|
||||
{
|
||||
get { return base.Flying; }
|
||||
|
@ -1184,10 +1160,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin
|
|||
CollisionShape _collisionShape = new XnaDevRu.BulletX.BoxShape(BulletXMaths.PhysicsVectorToXnaVector3(size) / 2.0f);
|
||||
DefaultMotionState _motionState = new DefaultMotionState(_startTransform, _centerOfMassOffset);
|
||||
Vector3 _localInertia = new Vector3();
|
||||
//ZZZ
|
||||
if (Mass > 0) _collisionShape.CalculateLocalInertia(Mass, out _localInertia); //Always when mass > 0
|
||||
//if (_physical) _collisionShape.CalculateLocalInertia(Mass, out _localInertia); //Always when mass > 0
|
||||
//zzz
|
||||
if (_physical) _collisionShape.CalculateLocalInertia(Mass, out _localInertia); //Always when mass > 0
|
||||
rigidBody = new RigidBody(Mass, _motionState, _collisionShape, _localInertia, _linearDamping, _angularDamping, _friction, _restitution);
|
||||
//rigidBody.ActivationState = ActivationState.DisableDeactivation;
|
||||
//It's seems that there are a bug with rigidBody constructor and its CenterOfMassPosition
|
||||
|
|
Loading…
Reference in New Issue