修改坡度计算逻辑,骑行界面大部分完成

This commit is contained in:
lishuo committed 2021-03-31 20:46:57 +08:00
1 parent b0f6c39118
commit eb93577d68
131 files changed
+4314 -75444

No files matched your search

+34 -23
View File
@@ -16,6 +16,8 @@ using System.Globalization;
using Assets.Scenes.Ride.Scripts.Model;
using static CyclingController;
using System.IO;
using Assets.Scenes.Ride.Scripts.Model.CyclingModels;
using System.Threading.Tasks;
namespace Assets.Scenes.Ride.Scripts
{
@@ -44,10 +46,10 @@ namespace Assets.Scenes.Ride.Scripts
int userId;
int routeId;
DateTime startTime;//开始骑行时间
BaseCycling baseCycling;
double speed;
double power;
double gradev;
double elevation;
double cadance;
int heartRate;
@@ -56,6 +58,7 @@ namespace Assets.Scenes.Ride.Scripts
double currentSlope;
double nextSlope;
double nextSlopeDistance;
double currentSlopeDistance;
double distance;
public int UserId { get => userId; }
@@ -66,10 +69,11 @@ namespace Assets.Scenes.Ride.Scripts
public double HeartRate { get => heartRate; }
public int TotalTicks { get => ticks; }
public double TotalDistance { get => totalDistance; }
public double Distance { get => distance; }
public double CurrentSlope { get => currentSlope; }
public double NextSlope { get => nextSlope;}
public double NextSlopeDistance { get => nextSlopeDistance; }
public double Gradev { get => gradev; }
public double CurrentSlopeDistance { get => currentSlopeDistance; }
public double Elevation { get => elevation; }
#endregion
@@ -81,6 +85,7 @@ namespace Assets.Scenes.Ride.Scripts
mapData = mainController.GetMapData();//获取路书信息
routeId = mainController.RouteId;//路数id
Initialize(mainController.GetCenterCoordinate());//初始人物
baseCycling = mainController.cyclingController;
}
void Update()
@@ -134,12 +139,12 @@ namespace Assets.Scenes.Ride.Scripts
//骑行中
void Run()
{
ComputeMapData();//计算海拔&坡度&下一个点信息
if (IsStart)
{
//CamControl();
ComputeMapData();//计算海拔&坡度&下一个点信息
power = 2000;//功率
speed = Helper.CalculateSpeed(elevation, 0, power, 65, 7);
speed = Helper.CalculateSpeed(elevation, currentSlope, power, 65, 7);
distance = Math.Round(speed / 3600, 6);
totalDistance += distance;
@@ -149,6 +154,7 @@ namespace Assets.Scenes.Ride.Scripts
//数据处理
ticks++;
nextlatlong = Along(totalDistance);//下一个坐标
nextPos = map.GeoToWorldPosition(nextlatlong);//下一个点
nextPos.y += 0.3f;
prePos = transform.localPosition;//当前点
@@ -179,23 +185,27 @@ namespace Assets.Scenes.Ride.Scripts
else
{
totalDistance = mapData.TotalDistance;
//记录骑行数据
var recordText = string.Format($"{ ticks },{ power.ToString(CultureInfo.InvariantCulture) },{ speed.ToString(CultureInfo.InvariantCulture) },{ Math.Round(totalDistance, 6).ToString(CultureInfo.InvariantCulture) },{ cadance.ToString(CultureInfo.InvariantCulture) },{ heartRate.ToString(CultureInfo.InvariantCulture) },{ Math.Round(nextlatlong.x, 6).ToString(CultureInfo.InvariantCulture) },{ Math.Round(nextlatlong.y, 6).ToString(CultureInfo.InvariantCulture) }");
Debug.Log(recordText);
RiderDatas.Add(new TargetData
{
Ticks = ticks,
_Power = power,
_Speed = speed,
_Distance = totalDistance,
_Cadence = cadance,
_HeartRate = heartRate,
_Lat = nextlatlong.x,
_Lon = nextlatlong.y
});
Complete();
isStart = false;
characterAnimator.SetBool("ReachEnd", true);
////记录骑行数据
//var recordText = string.Format($"{ ticks },{ power.ToString(CultureInfo.InvariantCulture) },{ speed.ToString(CultureInfo.InvariantCulture) },{ Math.Round(totalDistance, 6).ToString(CultureInfo.InvariantCulture) },{ cadance.ToString(CultureInfo.InvariantCulture) },{ heartRate.ToString(CultureInfo.InvariantCulture) },{ Math.Round(nextlatlong.x, 6).ToString(CultureInfo.InvariantCulture) },{ Math.Round(nextlatlong.y, 6).ToString(CultureInfo.InvariantCulture) }");
//Debug.Log(recordText);
//RiderDatas.Add(new TargetData
//{
// Ticks = ticks,
// _Power = power,
// _Speed = speed,
// _Distance = totalDistance,
// _Cadence = cadance,
// _HeartRate = heartRate,
// _Lat = nextlatlong.x,
// _Lon = nextlatlong.y
//});
Task.Run(() =>
{
Complete();
});
isStart = false;
}
}
else
@@ -313,7 +323,7 @@ namespace Assets.Scenes.Ride.Scripts
for (int i = 0; i < pointList.Count; i++)
{
sumDistance += pointList[i].Distance;
if (totalDistance <= sumDistance)
if (totalDistance * 1000 <= sumDistance)
{
index = i;
break;
@@ -321,12 +331,13 @@ namespace Assets.Scenes.Ride.Scripts
}
//计算当前海拔和坡度
elevation = pointList[index].Elevation;
gradev = pointList[index].Grade;
currentSlope = pointList[index].Grade;
//计算下一个点的坡度和距离
int nextIndex = index == pointList.Count - 1 ? index : index + 1;
CurrentIndex = nextIndex;
nextSlope = pointList[nextIndex].Grade;
nextSlopeDistance = sumDistance + pointList[nextIndex].Distance - totalDistance;
nextSlopeDistance = sumDistance - totalDistance*1000;
currentSlopeDistance = totalDistance * 1000 - (sumDistance- pointList[index].Distance);
}
//根据距离计算坐标
Vector2d Along(double endDistance)