BulletSim: Add ForcePosition and ForceOrientation to BSPhysObject and to its children of BSPrim and BSCharacter.

connector_plugin
Robert Adams 2012-10-02 11:06:07 -07:00
parent d8a786870b
commit ce47d0c454
3 changed files with 64 additions and 5 deletions

View File

@ -218,6 +218,18 @@ public class BSCharacter : BSPhysObject
}); });
} }
} }
public override OMV.Vector3 ForcePosition {
get {
_position = BulletSimAPI.GetPosition2(BSBody.ptr);
return _position;
}
set {
_position = value;
PositionSanityCheck();
BulletSimAPI.SetTranslation2(BSBody.ptr, _position, _orientation);
}
}
// Check that the current position is sane and, if not, modify the position to make it so. // Check that the current position is sane and, if not, modify the position to make it so.
// Check for being below terrain and being out of bounds. // Check for being below terrain and being out of bounds.
@ -346,6 +358,20 @@ public class BSCharacter : BSPhysObject
}); });
} }
} }
// Go directly to Bullet to get/set the value.
public override OMV.Quaternion ForceOrientation
{
get
{
_orientation = BulletSimAPI.GetOrientation2(BSBody.ptr);
return _orientation;
}
set
{
_orientation = value;
BulletSimAPI.SetTranslation2(BSBody.ptr, _position, _orientation);
}
}
public override int PhysicsActorType { public override int PhysicsActorType {
get { return _physicsActorType; } get { return _physicsActorType; }
set { _physicsActorType = value; set { _physicsActorType = value;

View File

@ -81,6 +81,10 @@ public abstract class BSPhysObject : PhysicsActor
// Tell the object to clean up. // Tell the object to clean up.
public abstract void Destroy(); public abstract void Destroy();
public abstract OMV.Vector3 ForcePosition { get; set; }
public abstract OMV.Quaternion ForceOrientation { get; set; }
#region Collisions #region Collisions
// Requested number of milliseconds between collision events. Zero means disabled. // Requested number of milliseconds between collision events. Zero means disabled.

View File

@ -275,6 +275,17 @@ public sealed class BSPrim : BSPhysObject
}); });
} }
} }
public override OMV.Vector3 ForcePosition {
get {
_position = BulletSimAPI.GetPosition2(BSBody.ptr);
return _position;
}
set {
_position = value;
PositionSanityCheck();
BulletSimAPI.SetTranslation2(BSBody.ptr, _position, _orientation);
}
}
// Check that the current position is sane and, if not, modify the position to make it so. // Check that the current position is sane and, if not, modify the position to make it so.
// Check for being below terrain and being out of bounds. // Check for being below terrain and being out of bounds.
@ -377,14 +388,15 @@ public sealed class BSPrim : BSPhysObject
} }
set { set {
Vehicle type = (Vehicle)value; Vehicle type = (Vehicle)value;
BSPrim vehiclePrim = this;
// Tell the scene about the vehicle so it will get processing each frame.
PhysicsScene.VehicleInSceneTypeChanged(this, type);
PhysicsScene.TaintedObject("setVehicleType", delegate() PhysicsScene.TaintedObject("setVehicleType", delegate()
{ {
// Done at taint time so we're sure the physics engine is not using the variables // Done at taint time so we're sure the physics engine is not using the variables
// Vehicle code changes the parameters for this vehicle type. // Vehicle code changes the parameters for this vehicle type.
_vehicle.ProcessTypeChange(type); this._vehicle.ProcessTypeChange(type);
// Tell the scene about the vehicle so it will get processing each frame.
PhysicsScene.VehicleInSceneTypeChanged(this, type);
}); });
} }
} }
@ -422,8 +434,10 @@ public sealed class BSPrim : BSPhysObject
public override void StepVehicle(float timeStep) public override void StepVehicle(float timeStep)
{ {
if (IsPhysical) if (IsPhysical)
{
_vehicle.Step(timeStep); _vehicle.Step(timeStep);
} }
}
// Allows the detection of collisions with inherently non-physical prims. see llVolumeDetect for more // Allows the detection of collisions with inherently non-physical prims. see llVolumeDetect for more
public override void SetVolumeDetect(int param) { public override void SetVolumeDetect(int param) {
@ -486,6 +500,20 @@ public sealed class BSPrim : BSPhysObject
}); });
} }
} }
// Go directly to Bullet to get/set the value.
public override OMV.Quaternion ForceOrientation
{
get
{
_orientation = BulletSimAPI.GetOrientation2(BSBody.ptr);
return _orientation;
}
set
{
_orientation = value;
BulletSimAPI.SetTranslation2(BSBody.ptr, _position, _orientation);
}
}
public override int PhysicsActorType { public override int PhysicsActorType {
get { return _physicsActorType; } get { return _physicsActorType; }
set { _physicsActorType = value; } set { _physicsActorType = value; }
@ -1170,7 +1198,8 @@ public sealed class BSPrim : BSPhysObject
// Create the correct physical representation for this type of object. // Create the correct physical representation for this type of object.
// Updates BSBody and BSShape with the new information. // Updates BSBody and BSShape with the new information.
PhysicsScene.Shapes.GetBodyAndShape(forceRebuild, PhysicsScene.World, this, shapeData, _pbs, // Ignore 'forceRebuild'. This routine makes the right choices and changes of necessary.
PhysicsScene.Shapes.GetBodyAndShape(false, PhysicsScene.World, this, shapeData, _pbs,
null, delegate(BulletBody dBody) null, delegate(BulletBody dBody)
{ {
// Called if the current prim body is about to be destroyed. // Called if the current prim body is about to be destroyed.