my broken version of vehicle mouse steer on ubOde (no bank,needs better damp)

LSLKeyTest
UbitUmarov 2016-08-28 03:51:20 +01:00
parent e7b0963db8
commit 804d4971e2
5 changed files with 146 additions and 48 deletions

View File

@ -406,6 +406,16 @@ namespace OpenSim.Region.Framework.Scenes
ph.SetVehicle(vd); ph.SetVehicle(vd);
} }
public bool CameraDecoupled
{
get
{
if((vd.m_flags & VehicleFlag.CAMERA_DECOUPLED) != 0)
return true;
return false;
}
}
private XmlTextWriter writer; private XmlTextWriter writer;
private void XWint(string name, int i) private void XWint(string name, int i)

View File

@ -5431,7 +5431,6 @@ Label_GroupsDone:
} }
} }
} }
} }
public void DeleteFromStorage(UUID uuid) public void DeleteFromStorage(UUID uuid)

View File

@ -2162,9 +2162,19 @@ namespace OpenSim.Region.Framework.Scenes
{ {
AddToPhysics(isPhysical, isPhantom, building, isPhysical); AddToPhysics(isPhysical, isPhantom, building, isPhysical);
UpdatePhysicsSubscribedEvents(); // not sure if appliable here UpdatePhysicsSubscribedEvents(); // not sure if appliable here
if(!_VolumeDetectActive &&
m_vehicleParams != null &&
m_vehicleParams.CameraDecoupled &&
m_localId == ParentGroup.RootPart.LocalId)
AddFlag(PrimFlags.CameraDecoupled);
else
RemFlag(PrimFlags.CameraDecoupled);
} }
else else
{
PhysActor = null; // just to be sure PhysActor = null; // just to be sure
RemFlag(PrimFlags.CameraDecoupled);
}
} }
} }
@ -3539,6 +3549,7 @@ SendFullUpdateToClient(remoteClient, Position) ignores position parameter
set set
{ {
m_vehicleParams = value; m_vehicleParams = value;
} }
} }
@ -3583,7 +3594,7 @@ SendFullUpdateToClient(remoteClient, Position) ignores position parameter
m_vehicleParams.ProcessVehicleFlags(param, remove); m_vehicleParams.ProcessVehicleFlags(param, remove);
if (_parentID ==0 && PhysActor != null) if (_parentID == 0 && PhysActor != null)
{ {
PhysActor.VehicleFlags(param, remove); PhysActor.VehicleFlags(param, remove);
} }
@ -4662,6 +4673,11 @@ SendFullUpdateToClient(remoteClient, Position) ignores position parameter
if (ParentGroup != null) if (ParentGroup != null)
{ {
if(UsePhysics && !SetPhantom && m_localId == ParentGroup.RootPart.LocalId &&
m_vehicleParams != null && m_vehicleParams.CameraDecoupled)
AddFlag(PrimFlags.CameraDecoupled);
else
RemFlag(PrimFlags.CameraDecoupled);
ParentGroup.HasGroupChanged = true; ParentGroup.HasGroupChanged = true;
ScheduleFullUpdate(); ScheduleFullUpdate();
} }
@ -4722,9 +4738,16 @@ SendFullUpdateToClient(remoteClient, Position) ignores position parameter
if (VolumeDetectActive) // change if not the default only if (VolumeDetectActive) // change if not the default only
pa.SetVolumeDetect(1); pa.SetVolumeDetect(1);
if (m_vehicleParams != null && LocalId == ParentGroup.RootPart.LocalId) if (m_vehicleParams != null && m_localId == ParentGroup.RootPart.LocalId)
{
m_vehicleParams.SetVehicle(pa); m_vehicleParams.SetVehicle(pa);
if(isPhysical && !isPhantom && m_vehicleParams.CameraDecoupled)
AddFlag(PrimFlags.CameraDecoupled);
else
RemFlag(PrimFlags.CameraDecoupled);
}
else
RemFlag(PrimFlags.CameraDecoupled);
// we are going to tell rest of code about physics so better have this here // we are going to tell rest of code about physics so better have this here
PhysActor = pa; PhysActor = pa;
@ -4800,6 +4823,7 @@ SendFullUpdateToClient(remoteClient, Position) ignores position parameter
ParentGroup.Scene.EventManager.TriggerObjectRemovedFromPhysicalScene(this); ParentGroup.Scene.EventManager.TriggerObjectRemovedFromPhysicalScene(this);
} }
RemFlag(PrimFlags.CameraDecoupled);
PhysActor = null; PhysActor = null;
} }

View File

@ -5442,6 +5442,7 @@ namespace OpenSim.Region.Framework.Scenes
Valid = true, Valid = true,
MouseLook = this.m_mouseLook, MouseLook = this.m_mouseLook,
CameraRotation = this.CameraRotation, CameraRotation = this.CameraRotation,
CameraAtAxis = this.CameraAtAxis
}; };
} }

View File

@ -648,6 +648,10 @@ namespace OpenSim.Region.PhysicsModule.ubOde
break; break;
} }
// disable mouse steering
m_flags &= ~(VehicleFlag.MOUSELOOK_STEER |
VehicleFlag.MOUSELOOK_BANK |
VehicleFlag.CAMERA_DECOUPLED);
m_lmDecay = (1.0f - 1.0f / m_linearMotorDecayTimescale); m_lmDecay = (1.0f - 1.0f / m_linearMotorDecayTimescale);
m_amDecay = 1.0f - 1.0f / m_angularMotorDecayTimescale; m_amDecay = 1.0f - 1.0f / m_angularMotorDecayTimescale;
@ -794,6 +798,16 @@ namespace OpenSim.Region.PhysicsModule.ubOde
float ldampZ = 0; float ldampZ = 0;
bool mousemode = false;
if((m_flags & (VehicleFlag.MOUSELOOK_STEER |VehicleFlag.MOUSELOOK_BANK)) != 0 )
mousemode = true;
float bankingEfficiency;
if(mousemode)
bankingEfficiency = 0;
else
bankingEfficiency = m_bankingEfficiency;
// linear motor // linear motor
if (m_lmEfect > 0.01 && m_linearMotorTimescale < 1000) if (m_lmEfect > 0.01 && m_linearMotorTimescale < 1000)
{ {
@ -967,7 +981,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
torque.Y += effpitch * ftmp; torque.Y += effpitch * ftmp;
} }
if (m_bankingEfficiency != 0 && Math.Abs(effroll) > 0.01) if (bankingEfficiency != 0 && Math.Abs(effroll) > 0.01)
{ {
float broll = effroll; float broll = effroll;
@ -1018,57 +1032,107 @@ namespace OpenSim.Region.PhysicsModule.ubOde
m_amdampZ = 1 / m_angularFrictionTimescale.Z; m_amdampZ = 1 / m_angularFrictionTimescale.Z;
} }
// angular motor if(mousemode)
if (m_amEfect > 0.01 && m_angularMotorTimescale < 1000)
{ {
tmpV = m_angularMotorDirection - curLocalAngVel; // velocity error CameraData cam = rootPrim.TryGetCameraData();
tmpV *= m_amEfect / m_angularMotorTimescale; // error to correct in this timestep if(cam.Valid && cam.MouseLook)
torque.X += tmpV.X * m_ampwr; {
torque.Y += tmpV.Y * m_ampwr; Vector3 dirv = cam.CameraAtAxis * irotq;
torque.Z += tmpV.Z;
m_amEfect *= m_amDecay; float tmp;
} if(Math.Abs(dirv.X) > 0.01f)
else {
m_amEfect = 0; if (Math.Abs(dirv.Z) > 0.01)
{
tmp = -(float)Math.Atan2(dirv.Z, dirv.X) * m_angularMotorDirection.Y;
if(tmp < -4f)
tmp = -4f;
else if(tmp > 4f)
tmp = 4f;
torque.Y += (tmp - curLocalAngVel.Y) / m_angularMotorTimescale;
}
// angular deflection if (Math.Abs(dirv.Y) > 0.01)
if (m_angularDeflectionEfficiency > 0) {
{ tmp = (float)Math.Atan2(dirv.Y, dirv.X) * m_angularMotorDirection.Z;
Vector3 dirv; if(tmp < -4f)
tmp = -4f;
if (curLocalVel.X > 0.01f) else if(tmp > 4f)
dirv = curLocalVel; tmp = 4f;
else if (curLocalVel.X < -0.01f) torque.Z += (tmp - curLocalAngVel.Z) / m_angularMotorTimescale;
// use oposite }
dirv = -curLocalVel; }
// angular friction
if (curLocalAngVel.X != 0 || curLocalAngVel.Y != 0 || curLocalAngVel.Z != 0)
{
torque.X -= curLocalAngVel.X * m_amdampX;
torque.Y -= curLocalAngVel.Y * m_amdampY;
torque.Z -= curLocalAngVel.Z * m_amdampZ;
}
}
else else
{ {
// make it fall into small positive x case if (curLocalAngVel.X != 0 || curLocalAngVel.Y != 0 || curLocalAngVel.Z != 0)
dirv.X = 0.01f; {
dirv.Y = curLocalVel.Y; torque.X -= curLocalAngVel.X * 10f;
dirv.Z = curLocalVel.Z; torque.Y -= curLocalAngVel.Y * 10f;
} torque.Z -= curLocalAngVel.Z * 10f;
}
float ftmp = m_angularDeflectionEfficiency / m_angularDeflectionTimescale;
if (Math.Abs(dirv.Z) > 0.01)
{
torque.Y += - (float)Math.Atan2(dirv.Z, dirv.X) * ftmp;
}
if (Math.Abs(dirv.Y) > 0.01)
{
torque.Z += (float)Math.Atan2(dirv.Y, dirv.X) * ftmp;
} }
} }
else
// angular friction
if (curLocalAngVel.X != 0 || curLocalAngVel.Y != 0 || curLocalAngVel.Z != 0)
{ {
torque.X -= curLocalAngVel.X * m_amdampX; // angular motor
torque.Y -= curLocalAngVel.Y * m_amdampY; if (m_amEfect > 0.01 && m_angularMotorTimescale < 1000)
torque.Z -= curLocalAngVel.Z * m_amdampZ; {
tmpV = m_angularMotorDirection - curLocalAngVel; // velocity error
tmpV *= m_amEfect / m_angularMotorTimescale; // error to correct in this timestep
torque.X += tmpV.X * m_ampwr;
torque.Y += tmpV.Y * m_ampwr;
torque.Z += tmpV.Z;
m_amEfect *= m_amDecay;
}
else
m_amEfect = 0;
// angular deflection
if (m_angularDeflectionEfficiency > 0)
{
Vector3 dirv;
if (curLocalVel.X > 0.01f)
dirv = curLocalVel;
else if (curLocalVel.X < -0.01f)
// use oposite
dirv = -curLocalVel;
else
{
// make it fall into small positive x case
dirv.X = 0.01f;
dirv.Y = curLocalVel.Y;
dirv.Z = curLocalVel.Z;
}
float ftmp = m_angularDeflectionEfficiency / m_angularDeflectionTimescale;
if (Math.Abs(dirv.Z) > 0.01)
{
torque.Y += - (float)Math.Atan2(dirv.Z, dirv.X) * ftmp;
}
if (Math.Abs(dirv.Y) > 0.01)
{
torque.Z += (float)Math.Atan2(dirv.Y, dirv.X) * ftmp;
}
}
if (curLocalAngVel.X != 0 || curLocalAngVel.Y != 0 || curLocalAngVel.Z != 0)
{
torque.X -= curLocalAngVel.X * m_amdampX;
torque.Y -= curLocalAngVel.Y * m_amdampY;
torque.Z -= curLocalAngVel.Z * m_amdampZ;
}
} }
force *= dmass.mass; force *= dmass.mass;