Back to old rotation calculation.

This commit is contained in:
Sardelka
2022-06-03 14:40:41 +08:00
parent 88a51cc154
commit 11d178498f
6 changed files with 21 additions and 21 deletions

View File

@ -358,7 +358,7 @@ namespace RageCoop.Client
if (v.IsMine) { return; } if (v.IsMine) { return; }
v.ID= packet.ID; v.ID= packet.ID;
v.Position=packet.Position; v.Position=packet.Position;
v.Rotation=packet.Rotation; v.Quaternion=packet.Quaternion;
v.SteeringAngle=packet.SteeringAngle; v.SteeringAngle=packet.SteeringAngle;
v.ThrottlePower=packet.ThrottlePower; v.ThrottlePower=packet.ThrottlePower;
v.BrakePower=packet.BrakePower; v.BrakePower=packet.BrakePower;

View File

@ -77,7 +77,8 @@ namespace RageCoop.Client
ID =v.ID, ID =v.ID,
SteeringAngle = veh.SteeringAngle, SteeringAngle = veh.SteeringAngle,
Position = veh.PredictPosition(), Position = veh.PredictPosition(),
Rotation = veh.Rotation, Quaternion=veh.Quaternion,
// Rotation = veh.Rotation,
Velocity = veh.Velocity, Velocity = veh.Velocity,
RotationVelocity=veh.RotationVelocity, RotationVelocity=veh.RotationVelocity,
ThrottlePower = veh.ThrottlePower, ThrottlePower = veh.ThrottlePower,

View File

@ -56,6 +56,7 @@ namespace RageCoop.Client
public Vector3 Position { get; set; } public Vector3 Position { get; set; }
public Vector3 Rotation { get; set; } public Vector3 Rotation { get; set; }
public Quaternion Quaternion { get; set; }
public Vector3 Velocity { get; set; } public Vector3 Velocity { get; set; }
public abstract void Update(); public abstract void Update();
public void PauseUpdate(ulong frames) public void PauseUpdate(ulong frames)

View File

@ -52,7 +52,6 @@ namespace RageCoop.Client
#region LAST STATE STORE #region LAST STATE STORE
private ulong _vehicleStopTime { get; set; }
private byte[] _lastVehicleColors = new byte[] { 0, 0 }; private byte[] _lastVehicleColors = new byte[] { 0, 0 };
private Dictionary<int, int> _lastVehicleMods = new Dictionary<int, int>(); private Dictionary<int, int> _lastVehicleMods = new Dictionary<int, int>();
private byte _lastRadioIndex=255; private byte _lastRadioIndex=255;
@ -63,6 +62,7 @@ namespace RageCoop.Client
public float SteeringAngle { get; set; } public float SteeringAngle { get; set; }
public float ThrottlePower { get; set; } public float ThrottlePower { get; set; }
public float BrakePower { get; set; } public float BrakePower { get; set; }
public float DeluxoWingRatio { get; set; } = -1;
#endregion #endregion
#region -- VEHICLE STATE -- #region -- VEHICLE STATE --
@ -89,7 +89,6 @@ namespace RageCoop.Client
/// VehicleSeat,PedID /// VehicleSeat,PedID
/// </summary> /// </summary>
public Dictionary<VehicleSeat, SyncedPed> Passengers { get; set; } public Dictionary<VehicleSeat, SyncedPed> Passengers { get; set; }
public float DeluxoWingRatio { get; set; } = -1;
public byte RadioStation = 255; public byte RadioStation = 255;
private long _lastPositionCalibrated { get; set; } private long _lastPositionCalibrated { get; set; }
@ -137,16 +136,9 @@ namespace RageCoop.Client
MainVehicle.Position=Position; MainVehicle.Position=Position;
MainVehicle.Velocity=Velocity; MainVehicle.Velocity=Velocity;
} }
Vector3 r = GetCalibrationRotation(); // Vector3 r = GetCalibrationRotation();
if (r.Length() < 20f) MainVehicle.Quaternion=Quaternion.Slerp(MainVehicle.Quaternion, Quaternion, 0.35f);
{
MainVehicle.RotationVelocity = r * 0.15f + RotationVelocity;
}
else
{
MainVehicle.Rotation = Rotation;
MainVehicle.RotationVelocity = RotationVelocity; MainVehicle.RotationVelocity = RotationVelocity;
}
if (DeluxoWingRatio!=-1) if (DeluxoWingRatio!=-1)
{ {
MainVehicle.SetDeluxoWingRatio(DeluxoWingRatio); MainVehicle.SetDeluxoWingRatio(DeluxoWingRatio);
@ -330,6 +322,8 @@ namespace RageCoop.Client
} }
private Vector3 GetCalibrationRotation() private Vector3 GetCalibrationRotation()
{ {
return (Quaternion-MainVehicle.Quaternion).ToEulerAngles().ToDegree();
/*
var r = Rotation-MainVehicle.Rotation; var r = Rotation-MainVehicle.Rotation;
if (r.X>180) { r.X=r.X-360; } if (r.X>180) { r.X=r.X-360; }
else if(r.X<-180) { r.X=360+r.X; } else if(r.X<-180) { r.X=360+r.X; }
@ -340,6 +334,7 @@ namespace RageCoop.Client
if (r.Z>180) { r.Z=r.Z-360; } if (r.Z>180) { r.Z=r.Z-360; }
else if (r.Z<-180) { r.Z=360+r.Z; } else if (r.Z<-180) { r.Z=360+r.Z; }
return r; return r;
*/
} }
private void CreateVehicle() private void CreateVehicle()
{ {
@ -355,7 +350,7 @@ namespace RageCoop.Client
{ {
EntityPool.Add( this); EntityPool.Add( this);
} }
MainVehicle.Rotation = Rotation; MainVehicle.Quaternion = Quaternion;
if (MainVehicle.HasRoof) if (MainVehicle.HasRoof)
{ {

View File

@ -113,7 +113,7 @@ namespace RageCoop.Core
Z = ReadFloat() Z = ReadFloat()
}; };
} }
public Quaternion ReadLQuaternion() public Quaternion ReadQuaternion()
{ {
return new Quaternion() return new Quaternion()
{ {

View File

@ -217,7 +217,8 @@ namespace RageCoop.Core
public Vector3 Position { get; set; } public Vector3 Position { get; set; }
public Vector3 Rotation { get; set; } public Quaternion Quaternion { get; set; }
// public Vector3 Rotation { get; set; }
public Vector3 Velocity { get; set; } public Vector3 Velocity { get; set; }
@ -242,8 +243,9 @@ namespace RageCoop.Core
byteArray.AddVector3(Position); byteArray.AddVector3(Position);
// Write rotation // Write quaternion
byteArray.AddVector3(Rotation); //byteArray.AddVector3(Rotation);
byteArray.AddQuaternion(Quaternion);
// Write velocity // Write velocity
byteArray.AddVector3(Velocity); byteArray.AddVector3(Velocity);
@ -283,8 +285,9 @@ namespace RageCoop.Core
// Read position // Read position
Position = reader.ReadVector3(); Position = reader.ReadVector3();
// Read rotation // Read quaternion
Rotation = reader.ReadVector3(); // Rotation = reader.ReadVector3();
Quaternion=reader.ReadQuaternion();
// Read velocity // Read velocity
Velocity =reader.ReadVector3(); Velocity =reader.ReadVector3();