Add llRotLookat pt1.

avinationmerge
KittoFlora 2009-10-26 00:10:23 +01:00
parent 91084653bd
commit 8428b25939
14 changed files with 296 additions and 31 deletions

View File

@ -1727,6 +1727,45 @@ namespace OpenSim.Region.Framework.Scenes
}
}
public void rotLookAt(Quaternion target, float strength, float damping)
{
SceneObjectPart rootpart = m_rootPart;
if (rootpart != null)
{
if (IsAttachment)
{
/*
ScenePresence avatar = m_scene.GetScenePresence(rootpart.AttachedAvatar);
if (avatar != null)
{
Rotate the Av?
} */
}
else
{
if (rootpart.PhysActor != null)
{
rootpart.PhysActor.APIDTarget = new Quaternion(target.X, target.Y, target.Z, target.W);
rootpart.PhysActor.APIDStrength = strength;
rootpart.PhysActor.APIDDamping = damping;
rootpart.PhysActor.APIDActive = true;
}
}
}
}
public void stopLookAt()
{
SceneObjectPart rootpart = m_rootPart;
if (rootpart != null)
{
if (rootpart.PhysActor != null)
{
rootpart.PhysActor.APIDActive = false;
}
}
}
/// <summary>
/// Uses a PID to attempt to clamp the object on the Z axis at the given height over tau seconds.
/// </summary>

View File

@ -2187,6 +2187,11 @@ if (m_shape != null) {
ParentGroup.HasGroupChanged = true;
ScheduleFullUpdate();
}
public void RotLookAt(Quaternion target, float strength, float damping)
{
m_parentGroup.rotLookAt(target, strength, damping);
}
/// <summary>
/// Schedules this prim for a full update
@ -2662,6 +2667,13 @@ if (m_shape != null) {
SetText(text);
}
public void StopLookAt()
{
m_parentGroup.stopLookAt();
m_parentGroup.ScheduleGroupForTerseUpdate();
}
public void StopMoveToTarget()
{
m_parentGroup.stopMoveToTarget();

View File

@ -307,6 +307,26 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
set { return; }
}
public override Quaternion APIDTarget
{
set { return; }
}
public override bool APIDActive
{
set { return; }
}
public override float APIDStrength
{
set { return; }
}
public override float APIDDamping
{
set { return; }
}
public override void SubscribeEvents(int ms)
{
}

View File

@ -627,6 +627,12 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
{
set { return; }
}
public override Quaternion APIDTarget { set { return; } }
public override bool APIDActive { set { return; } }
public override float APIDStrength { set { return; } }
public override float APIDDamping { set { return; } }
/// <summary>
/// Adds the force supplied to the Target Velocity

View File

@ -566,6 +566,11 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
public override PIDHoverType PIDHoverType { set { m_PIDHoverType = value; } }
public override float PIDHoverTau { set { m_PIDHoverTau = value; } }
public override Quaternion APIDTarget { set { return; } }
public override bool APIDActive { set { return; } }
public override float APIDStrength { set { return; } }
public override float APIDDamping { set { return; } }
public override void AddForce(PhysicsVector force, bool pushforce)
{

View File

@ -1236,6 +1236,26 @@ namespace OpenSim.Region.Physics.BulletXPlugin
public override PIDHoverType PIDHoverType { set { return; } }
public override float PIDHoverTau { set { return; } }
public override OpenMetaverse.Quaternion APIDTarget
{
set { return; }
}
public override bool APIDActive
{
set { return; }
}
public override float APIDStrength
{
set { return; }
}
public override float APIDDamping
{
set { return; }
}
public override void SubscribeEvents(int ms)
{

View File

@ -230,7 +230,12 @@ namespace OpenSim.Region.Physics.Manager
public abstract PIDHoverType PIDHoverType { set;}
public abstract float PIDHoverTau { set;}
// For RotLookAt
public abstract Quaternion APIDTarget { set;}
public abstract bool APIDActive { set;}
public abstract float APIDStrength { set;}
public abstract float APIDDamping { set;}
public abstract void AddForce(PhysicsVector force, bool pushforce);
public abstract void AddAngularForce(PhysicsVector force, bool pushforce);
public abstract void SetMomentum(PhysicsVector momentum);
@ -463,6 +468,12 @@ namespace OpenSim.Region.Physics.Manager
public override bool PIDHoverActive { set { return; } }
public override PIDHoverType PIDHoverType { set { return; } }
public override float PIDHoverTau { set { return; } }
public override Quaternion APIDTarget { set { return; } }
public override bool APIDActive { set { return; } }
public override float APIDStrength { set { return; } }
public override float APIDDamping { set { return; } }
public override void SetMomentum(PhysicsVector momentum)
{

View File

@ -1205,6 +1205,28 @@ namespace OpenSim.Region.Physics.OdePlugin
public override bool PIDHoverActive { set { return; } }
public override PIDHoverType PIDHoverType { set { return; } }
public override float PIDHoverTau { set { return; } }
public override Quaternion APIDTarget
{
set { return; }
}
public override bool APIDActive
{
set { return; }
}
public override float APIDStrength
{
set { return; }
}
public override float APIDDamping
{
set { return; }
}
public override void SubscribeEvents(int ms)
{

View File

@ -119,7 +119,7 @@ namespace OpenSim.Region.Physics.OdePlugin
private float m_VhoverEfficiency = 0f;
private float m_VhoverTimescale = 0f;
private float m_VhoverTargetHeight = -1.0f; // if <0 then no hover, else its the current target height
private float m_VehicleBuoyancy = 0f; //KF: m_VehicleBuoyancy is set by VEHICLE_BUOYANCY for a vehicle.
private float m_VehicleBuoyancy = 0f; // Set by VEHICLE_BUOYANCY, for a vehicle.
// Modifies gravity. Slider between -1 (double-gravity) and 1 (full anti-gravity)
// KF: So far I have found no good method to combine a script-requested .Z velocity and gravity.
// Therefore only m_VehicleBuoyancy=1 (0g) will use the script-requested .Z velocity.
@ -478,7 +478,7 @@ namespace OpenSim.Region.Physics.OdePlugin
Quaternion rotq = new Quaternion(rot.X, rot.Y, rot.Z, rot.W); // rotq = rotation of object
m_dir *= rotq; // apply obj rotation to velocity vector
// add Gravity andBuoyancy
// add Gravity and Buoyancy
// KF: So far I have found no good method to combine a script-requested
// .Z velocity and gravity. Therefore only 0g will used script-requested
// .Z velocity. >0g (m_VehicleBuoyancy < 1) will used modified gravity only.

View File

@ -1,15 +1,4 @@
/*
* Revised August 26 2009 by Kitto Flora. ODEDynamics.cs replaces
* ODEVehicleSettings.cs. It and ODEPrim.cs are re-organised:
* ODEPrim.cs contains methods dealing with Prim editing, Prim
* characteristics and Kinetic motion.
* ODEDynamics.cs contains methods dealing with Prim Physical motion
* (dynamics) and the associated settings. Old Linear and angular
* motors for dynamic motion have been replace with MoveLinear()
* and MoveAngular(); 'Physical' is used only to switch ODE dynamic
* simualtion on/off; VEHICAL_TYPE_NONE/VEHICAL_TYPE_<other> is to
* switch between 'VEHICLE' parameter use and general dynamics
* settings use.
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
@ -34,6 +23,18 @@
* 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.
*
* Revised August 26 2009 by Kitto Flora. ODEDynamics.cs replaces
* ODEVehicleSettings.cs. It and ODEPrim.cs are re-organised:
* ODEPrim.cs contains methods dealing with Prim editing, Prim
* characteristics and Kinetic motion.
* ODEDynamics.cs contains methods dealing with Prim Physical motion
* (dynamics) and the associated settings. Old Linear and angular
* motors for dynamic motion have been replace with MoveLinear()
* and MoveAngular(); 'Physical' is used only to switch ODE dynamic
* simualtion on/off; VEHICAL_TYPE_NONE/VEHICAL_TYPE_<other> is to
* switch between 'VEHICLE' parameter use and general dynamics
* settings use.
*/
using System;
using System.Collections.Generic;
@ -82,6 +83,14 @@ namespace OpenSim.Region.Physics.OdePlugin
private float PID_D = 35f;
private float PID_G = 25f;
private bool m_usePID = false;
private Quaternion m_APIDTarget = new Quaternion();
private float m_APIDStrength = 0.5f;
private float m_APIDDamping = 0.5f;
private float APID_D = 35f;
private float APID_G = 25f;
private bool m_useAPID = false;
// KF: These next 7 params apply to llSetHoverHeight(float height, integer water, float tau),
// and are for non-VEHICLES only.
@ -93,7 +102,7 @@ namespace OpenSim.Region.Physics.OdePlugin
private float m_targetHoverHeight = 0f;
private float m_groundHeight = 0f;
private float m_waterHeight = 0f;
private float m_buoyancy = 0f; //KF: m_buoyancy should be set by llSetBuoyancy() for non-vehicle.
private float m_buoyancy = 0f; //Set by llSetBuoyancy(), for non-vehicles.
// private float m_tensor = 5f;
private int body_autodisable_frames = 20;
@ -1586,21 +1595,18 @@ Console.WriteLine(" JointCreateFixed");
//m_log.Info(m_collisionFlags.ToString());
//KF: m_buoyancy should be set by llSetBuoyancy() for non-vehicle.
// would come from SceneObjectPart.cs, public void SetBuoyancy(float fvalue) , PhysActor.Buoyancy = fvalue; ??
//KF: m_buoyancy is set by llSetBuoyancy() and is for non-vehicle.
// m_buoyancy: (unlimited value) <0=Falls fast; 0=1g; 1=0g; >1 = floats up
// gravityz multiplier = 1 - m_buoyancy
fz = _parent_scene.gravityz * (1.0f - m_buoyancy) * m_mass;
// NB Prims in ODE are no subject to global gravity
fz = _parent_scene.gravityz * (1.0f - m_buoyancy) * m_mass; // force = acceleration * mass
if (m_usePID)
{
//Console.WriteLine("PID " + m_primName);
// KF - this is for object move? eg. llSetPos() ?
// KF - this is for object MoveToTarget.
//if (!d.BodyIsEnabled(Body))
//d.BodySetForce(Body, 0f, 0f, 0f);
// If we're using the PID controller, then we have no gravity
//fz = (-1 * _parent_scene.gravityz) * m_mass; //KF: ?? Prims have no global gravity,so simply...
fz = 0f;
// no lock; for now it's only called from within Simulate()
@ -1744,8 +1750,37 @@ Console.WriteLine(" JointCreateFixed");
// We're flying and colliding with something
fz = fz + ((_target_velocity.Z - vel.Z) * (PID_D) * m_mass);
}
}
} // end m_useHoverPID && !m_usePID
if (m_useAPID)
{
// RotLookAt, apparently overrides all other rotation sources. Inputs:
// Quaternion m_APIDTarget
// float m_APIDStrength // perhaps ratio other forces to lookat force?
// float m_APIDDamping //'seconds to critically damps in'[sic]
// Factors:
// float APID_D
// float APID_G
// get present body rotation
d.Quaternion rot = d.BodyGetQuaternion(Body);
Quaternion rotq = new Quaternion(rot.X, rot.Y, rot.Z, rot.W);
Quaternion rot_diff = Quaternion.Inverse(rotq) * m_APIDTarget;
float diff_angle;
Vector3 diff_axis;
rot_diff.GetAxisAngle(out diff_axis, out diff_angle);
diff_axis.Normalize();
PhysicsVector rotforce = new PhysicsVector(diff_axis.X, diff_axis.Y, diff_axis.Z);
float RLAservo = timestep / m_APIDDamping;
rotforce = rotforce * RLAservo * m_mass;
d.BodyAddTorque(Body, rotforce.X, rotforce.Y, rotforce.Z);
// d.BodySetAngularVel (Body, m_lastAngularVelocity.X, m_lastAngularVelocity.Y, m_lastAngularVelocity.Z);
} // end m_useAPID
fx *= m_mass;
fy *= m_mass;
//fz *= m_mass;
@ -2778,6 +2813,12 @@ Console.WriteLine(" JointCreateFixed");
}
public override bool PIDActive { set { m_usePID = value; } }
public override float PIDTau { set { m_PIDTau = value; } }
// For RotLookAt
public override Quaternion APIDTarget { set { m_APIDTarget = value; } }
public override bool APIDActive { set { m_useAPID = value; } }
public override float APIDStrength { set { m_APIDStrength = value; } }
public override float APIDDamping { set { m_APIDDamping = value; } }
public override float PIDHoverHeight { set { m_PIDHoverHeight = value; ; } }
public override bool PIDHoverActive { set { m_useHoverPID = value; } }

View File

@ -307,6 +307,27 @@ namespace OpenSim.Region.Physics.POSPlugin
{
set { return; }
}
public override Quaternion APIDTarget
{
set { return; }
}
public override bool APIDActive
{
set { return; }
}
public override float APIDStrength
{
set { return; }
}
public override float APIDDamping
{
set { return; }
}
public override void SubscribeEvents(int ms)
{

View File

@ -302,6 +302,26 @@ namespace OpenSim.Region.Physics.POSPlugin
{
set { return; }
}
public override Quaternion APIDTarget
{
set { return; }
}
public override bool APIDActive
{
set { return; }
}
public override float APIDStrength
{
set { return; }
}
public override float APIDDamping
{
set { return; }
}
public override void SubscribeEvents(int ms)
{

View File

@ -500,6 +500,28 @@ namespace OpenSim.Region.Physics.PhysXPlugin
public override bool PIDHoverActive { set { return; } }
public override PIDHoverType PIDHoverType { set { return; } }
public override float PIDHoverTau { set { return; } }
public override Quaternion APIDTarget
{
set { return; }
}
public override bool APIDActive
{
set { return; }
}
public override float APIDStrength
{
set { return; }
}
public override float APIDDamping
{
set { return; }
}
public override void SubscribeEvents(int ms)
{
@ -782,6 +804,28 @@ namespace OpenSim.Region.Physics.PhysXPlugin
public override bool PIDHoverActive { set { return; } }
public override PIDHoverType PIDHoverType { set { return; } }
public override float PIDHoverTau { set { return; } }
public override Quaternion APIDTarget
{
set { return; }
}
public override bool APIDActive
{
set { return; }
}
public override float APIDStrength
{
set { return; }
}
public override float APIDDamping
{
set { return; }
}
public override void SubscribeEvents(int ms)
{

View File

@ -2694,11 +2694,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
// Orient the object to the angle calculated
llSetRot(rot);
}
public void llRotLookAt(LSL_Rotation target, double strength, double damping)
{
m_host.AddScriptLPS(1);
// NotImplemented("llRotLookAt");
m_host.RotLookAt(Rot2Quaternion(target), (float)strength, (float)damping);
}
public void llStopLookAt()
{
m_host.AddScriptLPS(1);
NotImplemented("llStopLookAt");
// NotImplemented("llStopLookAt");
m_host.StopLookAt();
}
public void llSetTimerEvent(double sec)
@ -3042,12 +3052,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
m_host.AddScriptLPS(1);
}
public void llRotLookAt(LSL_Rotation target, double strength, double damping)
{
m_host.AddScriptLPS(1);
NotImplemented("llRotLookAt");
}
public LSL_Integer llStringLength(string str)
{
m_host.AddScriptLPS(1);