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