Skip to content

Commit 6873cfb

Browse files
authored
fix: out of bounding box issue (#118)
1 parent ade792c commit 6873cfb

1 file changed

Lines changed: 17 additions & 14 deletions

File tree

src/lightstates/index.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { CubePrimitive, Vector3, type Color } from "@foxglove/schemas";
22
import {
33
MovingObject,
44
MovingObject_VehicleClassification_LightState_IndicatorState,
5+
Dimension3d,
56
} from "@lichtblick/asam-osi-types";
67
import { eulerToQuaternion, pointRotationByQuaternion } from "@utils/geometry";
78
import { objectToCubePrimitive } from "@utils/marker";
@@ -21,14 +22,16 @@ export enum IndicatorLightSide {
2122
RearRight,
2223
}
2324

24-
const BRAKE_LIGHT_DIMENSIONS: Vector3 = { x: 0.5, y: 0.25, z: 0.25 };
25-
const BRAKE_LIGHT_POSITION_Y_OFFSET = 0.25;
25+
const BRAKE_LIGHT_DIMENSIONS: Dimension3d = { width: 0.5, length: 0.25, height: 0.25 };
26+
const BRAKE_LIGHT_POSITION_X_OFFSET = BRAKE_LIGHT_DIMENSIONS.length! / 2;
27+
const BRAKE_LIGHT_POSITION_Y_OFFSET = BRAKE_LIGHT_DIMENSIONS.width! / 2;
2628

2729
const INDICATOR_ON_COLOR: Color = { r: 1.0, g: 0.8, b: 0.0, a: 0.7 };
2830
const INDICATOR_OFF_COLOR: Color = { r: 0.5, g: 0.5, b: 0.0, a: 0.7 };
29-
const INDICATOR_LIGHT_DIMENSIONS: Vector3 = { x: 0.25, y: 0.25, z: 0.25 };
30-
const INDICATOR_LIGHT_POSITION_Y_OFFSET = 0.125;
31-
const INDICATOR_LIGHT_POSITION_Z_OFFSET = 0.25;
31+
const INDICATOR_LIGHT_DIMENSIONS: Dimension3d = { width: 0.25, length: 0.25, height: 0.25 };
32+
const INDICATOR_LIGHT_POSITION_X_OFFSET = INDICATOR_LIGHT_DIMENSIONS.length! / 2;
33+
const INDICATOR_LIGHT_POSITION_Y_OFFSET = INDICATOR_LIGHT_DIMENSIONS.width! / 2;
34+
const INDICATOR_LIGHT_POSITION_Z_OFFSET = BRAKE_LIGHT_DIMENSIONS.height!;
3235

3336
export const buildBrakeLight = (
3437
moving_obj: DeepRequired<MovingObject>,
@@ -39,7 +42,7 @@ export const buildBrakeLight = (
3942

4043
const directionMultiplier = side === BrakeLightSide.Left ? 1 : -1;
4144
const localAxisOffset: Vector3 = {
42-
x: -(moving_obj.base.dimension.length / 2),
45+
x: -(moving_obj.base.dimension.length / 2) + BRAKE_LIGHT_POSITION_X_OFFSET,
4346
y:
4447
directionMultiplier * (moving_obj.base.dimension.width / 2) -
4548
BRAKE_LIGHT_POSITION_Y_OFFSET * directionMultiplier,
@@ -59,9 +62,9 @@ export const buildBrakeLight = (
5962
moving_obj.base.orientation.roll,
6063
moving_obj.base.orientation.pitch,
6164
moving_obj.base.orientation.yaw,
62-
BRAKE_LIGHT_DIMENSIONS.x,
63-
BRAKE_LIGHT_DIMENSIONS.y,
64-
BRAKE_LIGHT_DIMENSIONS.z,
65+
BRAKE_LIGHT_DIMENSIONS.width!,
66+
BRAKE_LIGHT_DIMENSIONS.length!,
67+
BRAKE_LIGHT_DIMENSIONS.height!,
6568
brakeLightColor,
6669
);
6770
};
@@ -97,8 +100,8 @@ export const buildIndicatorLight = (
97100
const localAxisOffset: Vector3 = {
98101
x:
99102
side === IndicatorLightSide.FrontLeft || side === IndicatorLightSide.FrontRight
100-
? moving_obj.base.dimension.length / 2
101-
: -(moving_obj.base.dimension.length / 2),
103+
? moving_obj.base.dimension.length / 2 - INDICATOR_LIGHT_POSITION_X_OFFSET
104+
: -(moving_obj.base.dimension.length / 2) + INDICATOR_LIGHT_POSITION_X_OFFSET,
102105
y:
103106
side === IndicatorLightSide.FrontLeft || side === IndicatorLightSide.RearLeft
104107
? moving_obj.base.dimension.width / 2 - INDICATOR_LIGHT_POSITION_Y_OFFSET
@@ -119,9 +122,9 @@ export const buildIndicatorLight = (
119122
moving_obj.base.orientation.roll,
120123
moving_obj.base.orientation.pitch,
121124
moving_obj.base.orientation.yaw,
122-
INDICATOR_LIGHT_DIMENSIONS.x,
123-
INDICATOR_LIGHT_DIMENSIONS.y,
124-
INDICATOR_LIGHT_DIMENSIONS.z,
125+
INDICATOR_LIGHT_DIMENSIONS.width!,
126+
INDICATOR_LIGHT_DIMENSIONS.length!,
127+
INDICATOR_LIGHT_DIMENSIONS.height!,
125128
lightOn ? INDICATOR_ON_COLOR : INDICATOR_OFF_COLOR,
126129
);
127130
};

0 commit comments

Comments
 (0)