diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/entity/model/DrawLineInfo.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/entity/model/DrawLineInfo.java index 0033028dd1..c0272da780 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/entity/model/DrawLineInfo.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/entity/model/DrawLineInfo.java @@ -27,7 +27,7 @@ public class DrawLineInfo { private float width; - private int direction; + private boolean hasStopLines; public String getType() { return type; @@ -69,12 +69,12 @@ public class DrawLineInfo { this.width = width; } - public int getDirection() { - return direction; + public boolean isHasStopLines() { + return hasStopLines; } - public void setDirection(int direction) { - this.direction = direction; + public void setHasStopLines(boolean hasStopLines) { + this.hasStopLines = hasStopLines; } public List getLocations() { diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/manager/impl/MoGoWarnPolylineManager.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/manager/impl/MoGoWarnPolylineManager.java index 11d7d63f79..ad315d9d67 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/manager/impl/MoGoWarnPolylineManager.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/manager/impl/MoGoWarnPolylineManager.java @@ -44,7 +44,7 @@ public class MoGoWarnPolylineManager implements IMoGoWarnPolylineManager { .setGps(false); List colors = new ArrayList<>(); - if (info.getDirection() == ALERT_THE_FRONT_CRASH_WARNING_TOP) { + if (info.isHasStopLines() == true) { colors.add(0x0D3036FF); colors.add(0xD93036FF); colors.add(0x0D3036FF); @@ -75,6 +75,8 @@ public class MoGoWarnPolylineManager implements IMoGoWarnPolylineManager { if (mMogoPolyline != null) { mMogoPolyline.remove(); mMogoPolyline = null; + } else { + Log.d("V2XWarningMarker", "mMogoPolyline==null"); } } diff --git a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/warning/V2XWarningMarker.java b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/warning/V2XWarningMarker.java index a095289f43..9ae538dd9a 100644 --- a/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/warning/V2XWarningMarker.java +++ b/modules/mogo-module-v2x/src/main/java/com/mogo/module/v2x/scenario/scene/warning/V2XWarningMarker.java @@ -62,6 +62,7 @@ public class V2XWarningMarker implements IV2XMarker { private MogoLatLng middleLocationInStopLine = new MogoLatLng(0, 0); private static long showTime = 6000; private float bearing; + private boolean hasStopLines = false; @Override public void drawPOI(Object entity) { @@ -80,14 +81,12 @@ public class V2XWarningMarker implements IV2XMarker { fillPointOnStopLine(); bearing = V2XLocationListener.getInstance().getLastCarLocation().getBearing(); + hasStopLines = mCloundWarningInfo.getStopLines().size() > 0; isSelfLineClear = false; isFirstLocation = false; if (fillPoints.size() > 0) { //存在停止线的情况 自车与停止线之间绘制蓝色安全线 停止线向前50m绘制红色预警线 middleLocationInStopLine = getMiddleLocationInStopLine(); - //获取停止线前方50m坐标点 - MogoLatLng warningLocation = Trigonometric.getNewLocation(middleLocationInStopLine, - 50, mCloundWarningInfo.getAngle()); //停止线前方画线 WorkThreadHandler.getInstance().postDelayed(() -> { if (carLocation.lat != 0 && carLocation.lon != 0) { @@ -98,6 +97,9 @@ public class V2XWarningMarker implements IV2XMarker { } //二轮车和行人的渲染和移动 V2XServiceManager.getMarkerManager().removeMarkers(TYPE_MARKER_CLOUD_WARN_DATA); + //获取停止线前方50m坐标点 + MogoLatLng warningLocation = Trigonometric.getNewLocation(middleLocationInStopLine, + 50, angleForCarMoveDirection()); //停止线向前方50m绘制红色预警线 drawRedWarningLineFrontOfStopLine(mCloundWarningInfo, middleLocationInStopLine, warningLocation); @@ -115,7 +117,6 @@ public class V2XWarningMarker implements IV2XMarker { drawOtherObjectLine(mCloundWarningInfo); //二轮车和行人的渲染和移动 V2XServiceManager.getMarkerManager().removeMarkers(TYPE_MARKER_CLOUD_WARN_DATA); - //车辆静止的时候 if (carLocation.lat != 0 && carLocation.lon != 0) { drawSelfCarLine(carLocation.lon, carLocation.lat, bearing); } else { @@ -132,6 +133,18 @@ public class V2XWarningMarker implements IV2XMarker { (mCloundWarningInfo.getDirection(), MogoReceiver.ACTION_V2X_FRONT_WARNING); } + /* + * + * */ + public double angleForCarMoveDirection() { + MogoLatLng startLatLng = new MogoLatLng(carLocation.lat, carLocation.lon); + MogoLatLng endLatLng = new MogoLatLng(middleLocationInStopLine.lat, middleLocationInStopLine.lon); + double angle = Trigonometric.getAngle(startLatLng.lon, startLatLng.lat, endLatLng.lon, endLatLng.lat); + Log.d(TAG, "angle==" + String.valueOf(angle)); + return angle; + } + + /*绘制停止线前方50m的红色预警线 * startLatLng: 划线起点=停止线上的坐标点 * mogoLatLng: 停止线前方50m坐标点 @@ -139,14 +152,13 @@ public class V2XWarningMarker implements IV2XMarker { private void drawRedWarningLineFrontOfStopLine(V2XWarningEntity info, MogoLatLng startLatLng, MogoLatLng mogoLatLng) { if (info != null) { + double angle = Trigonometric.getAngle(startLatLng.lon, startLatLng.lat, mogoLatLng.lon, mogoLatLng.lat); + Log.d(TAG, "angle==drawRedWarningLineFrontOfStopLine:" + String.valueOf(angle)); IMogoPolyline polyLine = V2XServiceManager.getMoGoStopPolylineManager().getMogoStopPolyline(); MogoLatLng endLatlng = new MogoLatLng(mogoLatLng.lat, mogoLatLng.lon); - float distance = CoordinateUtils.calculateLineDistance(startLatLng.lon, startLatLng.lat, - endLatlng.lon, endLatlng.lat); - MogoLatLng addMiddleLoc = Trigonometric.getNewLocation(startLatLng, distance / 2, - mCloundWarningInfo.getAngle()); + MogoLatLng addMiddleLoc = Trigonometric.getNewLocation(startLatLng, 25, angle); if (polyLine != null) { - Log.d(V2XConst.LOG_NAME_WARN, "drawStopLine polyLine != null"); + Log.d(TAG, "drawStopLine polyLine != null"); polyLine.setPoints(Arrays.asList(startLatLng, addMiddleLoc, endLatlng)); polyLine.setTransparency(0.5f); } else { @@ -157,7 +169,7 @@ public class V2XWarningMarker implements IV2XMarker { locations.add(endLatlng); lineInfo.setLocations(locations); lineInfo.setHeading(info.heading); - Log.d(V2XConst.LOG_NAME_WARN, "drawStopLine width = " + info.getRoadwidth()); + Log.d(TAG, "drawStopLine width = " + info.getRoadwidth()); lineInfo.setWidth(info.getRoadwidth() * 14 + 5); V2XServiceManager.getMoGoStopPolylineManager().drawStopPolyline(getContext(), lineInfo); } @@ -174,7 +186,7 @@ public class V2XWarningMarker implements IV2XMarker { Log.d(TAG, "清除所有预警线的时间是:" + String.valueOf(showTime)); //清除识别物到碰撞点预警线 V2XServiceManager.getMoGoPersonWarnPolylineManager().clearLine(); - //清除车到碰撞点预警线 + //清除车前方第一条预警线 V2XServiceManager.getMoGoWarnPolylineManager().clearLine(); //清除停止线 V2XServiceManager.getMoGoStopPolylineManager().clearLine(); @@ -227,7 +239,6 @@ public class V2XWarningMarker implements IV2XMarker { entity.setLat(latLng.lat); entity.setLon(latLng.lon); entity.heading = mCloundWarningInfo.heading; - Log.d(TAG, "绘制停止线+time=" + String.valueOf(System.currentTimeMillis())); V2XWarnDataDrawer.getInstance().renderStopLineData(entity); } } @@ -249,22 +260,29 @@ public class V2XWarningMarker implements IV2XMarker { if (carLocation.lat == 0 || carLocation.lon == 0) { Log.d(TAG, "获取不到车的位置"); } - MogoLatLng newLocation = Trigonometric.getNewLocation(carLocation, mCloundWarningInfo.getStopLineDistance(), - mCloundWarningInfo.getAngle()); - Log.d(TAG, "计算停止线上的某个点" + String.valueOf(carLocation.lat + "," + - String.valueOf(carLocation.lon))); + MogoLatLng newLocation = new MogoLatLng(0, 0); + if (mCloundWarningInfo.getStopLines().size() > 1) { + MogoLatLng x = mCloundWarningInfo.getStopLines().get(0); + MogoLatLng y = mCloundWarningInfo.getStopLines().get(1); + float distance = CoordinateUtils.calculateLineDistance(x.lon, x.lat, y.lon, y.lat); + double angle = Trigonometric.getAngle(x.lon, x.lat, y.lon, y.lat); + newLocation = Trigonometric.getNewLocation(x, distance * 0.5, angle); + } else { + Log.d(TAG, "停止线返回坐标点数量不正确" + String.valueOf(mCloundWarningInfo.getStopLines().size())); + } return newLocation; } /** - * 自车与停止线之间为蓝色预警 + * 存在停止线时自车与停止线之间为蓝色预警 + * 不存在停止线,自车与预碰撞点之间为红色预警 * lon 自车经度 * lat 自车纬度 */ public void drawSelfCarLine(double lon, double lat, float bearing) { if (!isSelfLineClear) { - IMogoPolyline mogoPolyline = V2XServiceManager.getMoGoWarnPolylineManager().getMogoWarnPolyline(); if (mCloundWarningInfo != null) { + IMogoPolyline mogoPolyline = V2XServiceManager.getMoGoWarnPolylineManager().getMogoWarnPolyline(); MogoLatLng startLatlng = new MogoLatLng(0, 0); MogoLatLng endLatlng = new MogoLatLng(0, 0); MogoLatLng addMiddleLoc = new MogoLatLng(0, 0); @@ -274,17 +292,17 @@ public class V2XWarningMarker implements IV2XMarker { isFirstLocation = true; } //绘制线的终点(在停止线上或者预碰撞点上) - endLatlng = new MogoLatLng(mCloundWarningInfo.getStopLines().size() > 0 ? - middleLocationInStopLine.lat : mCloundWarningInfo.getCollisionLat(), - mCloundWarningInfo.getDirection() == ALERT_THE_FRONT_CRASH_WARNING_TOP ? - middleLocationInStopLine.lon : mCloundWarningInfo.getCollisionLon()); - //自车位置 + endLatlng = new MogoLatLng(hasStopLines ? + middleLocationInStopLine.lat : mCloundWarningInfo.getCollisionLat(), hasStopLines ? + middleLocationInStopLine.lon : mCloundWarningInfo.getCollisionLon()); + startLatlng = new MogoLatLng(lat, lon); float distance = CoordinateUtils.calculateLineDistance(startLatlng.lon, startLatlng.lat, endLatlng.lon, endLatlng.lat); //扩展点为了渐变色添加 addMiddleLoc = Trigonometric.getNewLocation(startLatlng, distance / 2, Trigonometric.getAngle(startLatlng.lon, startLatlng.lat, endLatlng.lon, endLatlng.lat)); - + Log.d(TAG, "angle==扩展点为了渐变色添加:" + + String.valueOf(Trigonometric.getAngle(startLatlng.lon, startLatlng.lat, endLatlng.lon, endLatlng.lat))); if (mogoPolyline != null) { mogoPolyline.setPoints(Arrays.asList(startLatlng, addMiddleLoc, endLatlng)); mogoPolyline.setTransparency(0.5f); @@ -297,10 +315,9 @@ public class V2XWarningMarker implements IV2XMarker { info.setLocations(locations); info.setHeading(bearing); info.setWidth(mCloundWarningInfo.getRoadwidth() * 14 + 5); - info.setDirection(mCloundWarningInfo.getDirection()); + info.setHasStopLines(mCloundWarningInfo.getStopLines().size() > 0); V2XServiceManager.getMoGoWarnPolylineManager().drawWarnPolyline(getContext(), info); - Log.d(TAG, "安全区域蓝色预警线" + "起点:" + startLatlng + "中间点:" + addMiddleLoc + "终点:" + endLatlng); - Log.d(TAG, "绘制自车与碰撞点之间的预警线+time=" + String.valueOf(System.currentTimeMillis())); + Log.d(TAG, "自车前方第一条线" + "起点:" + startLatlng + "中间点:" + addMiddleLoc + "终点:" + endLatlng); } Log.d(TAG, "自车为起点绘制 自车;" + startLatlng.lon + "," + startLatlng.lat + "中间扩展点" + addMiddleLoc.lon + "," + addMiddleLoc.lat + "终点:" + endLatlng.lon + "," + endLatlng.lat); @@ -337,7 +354,6 @@ public class V2XWarningMarker implements IV2XMarker { lineInfo.setHeading(info.heading); lineInfo.setWidth(info.getRoadwidth() * 14 + 5); V2XServiceManager.getMoGoPersonWarnPolylineManager().drawPersonWarnPolyline(getContext(), lineInfo); - Log.d(TAG, "道路宽度为" + info.getRoadwidth()); Log.d(TAG, "目标物与预碰撞点画线点为" + "起点:" + startLatlng + "中间点:" + addMiddleLoc + "终点:" + endLatlng); } } else {