James Kuszmaul | 92ba0e5 | 2019-03-29 17:19:30 -0700 | [diff] [blame] | 1 | import {CAMERA_POSES} from './camera_constants'; |
Alex Perry | 5b89562 | 2019-04-06 14:27:55 -0700 | [diff] [blame^] | 2 | import {FT_TO_M, IN_TO_M} from './constants'; |
Alex Perry | 554cec0 | 2019-03-23 20:15:12 -0700 | [diff] [blame] | 3 | |
| 4 | const ROBOT_WIDTH = 25 * IN_TO_M; |
| 5 | const ROBOT_LENGTH = 31 * IN_TO_M; |
James Kuszmaul | 92ba0e5 | 2019-03-29 17:19:30 -0700 | [diff] [blame] | 6 | const CAMERA_SCALE = 0.3; |
Alex Perry | 554cec0 | 2019-03-23 20:15:12 -0700 | [diff] [blame] | 7 | |
Alex Perry | 5b89562 | 2019-04-06 14:27:55 -0700 | [diff] [blame^] | 8 | function drawCamera( |
| 9 | ctx: CanvasRenderingContext2D, |
| 10 | pose: {x: number, y: number, theta: number}): void { |
James Kuszmaul | 92ba0e5 | 2019-03-29 17:19:30 -0700 | [diff] [blame] | 11 | ctx.beginPath(); |
| 12 | ctx.moveTo(pose.x, pose.y); |
Alex Perry | 5b89562 | 2019-04-06 14:27:55 -0700 | [diff] [blame^] | 13 | ctx.lineTo( |
| 14 | pose.x + CAMERA_SCALE * Math.cos(pose.theta + Math.PI / 4.0), |
| 15 | pose.y + CAMERA_SCALE * Math.sin(pose.theta + Math.PI / 4.0)); |
| 16 | ctx.lineTo( |
| 17 | pose.x + CAMERA_SCALE * Math.cos(pose.theta - Math.PI / 4.0), |
| 18 | pose.y + CAMERA_SCALE * Math.sin(pose.theta - Math.PI / 4.0)); |
James Kuszmaul | 92ba0e5 | 2019-03-29 17:19:30 -0700 | [diff] [blame] | 19 | ctx.closePath(); |
| 20 | ctx.stroke(); |
| 21 | } |
| 22 | |
Alex Perry | 5b89562 | 2019-04-06 14:27:55 -0700 | [diff] [blame^] | 23 | export function drawRobot( |
| 24 | ctx: CanvasRenderingContext2D, x: number, y: number, theta: number, |
| 25 | camera_colors: string[]): void { |
Alex Perry | 554cec0 | 2019-03-23 20:15:12 -0700 | [diff] [blame] | 26 | ctx.save(); |
| 27 | ctx.translate(x, y); |
| 28 | ctx.rotate(theta); |
| 29 | |
| 30 | ctx.fillStyle = 'blue'; |
| 31 | ctx.fillRect(-ROBOT_LENGTH / 2, -ROBOT_WIDTH / 2, ROBOT_LENGTH, ROBOT_WIDTH); |
| 32 | |
James Kuszmaul | 92ba0e5 | 2019-03-29 17:19:30 -0700 | [diff] [blame] | 33 | ctx.beginPath(); |
| 34 | ctx.strokeStyle = 'black'; |
Alex Perry | 5b89562 | 2019-04-06 14:27:55 -0700 | [diff] [blame^] | 35 | ctx.moveTo(ROBOT_LENGTH / 2, -ROBOT_WIDTH / 2); |
Alex Perry | 554cec0 | 2019-03-23 20:15:12 -0700 | [diff] [blame] | 36 | ctx.lineTo(ROBOT_LENGTH / 2 + 0.1, 0); |
Alex Perry | 5b89562 | 2019-04-06 14:27:55 -0700 | [diff] [blame^] | 37 | ctx.lineTo(ROBOT_LENGTH / 2, ROBOT_WIDTH / 2); |
Alex Perry | 554cec0 | 2019-03-23 20:15:12 -0700 | [diff] [blame] | 38 | ctx.closePath(); |
| 39 | ctx.stroke(); |
James Kuszmaul | 92ba0e5 | 2019-03-29 17:19:30 -0700 | [diff] [blame] | 40 | ctx.lineWidth = 3.0 * ctx.lineWidth; |
| 41 | for (let ii of [0, 1, 2, 3, 4]) { |
| 42 | ctx.strokeStyle = camera_colors[ii]; |
| 43 | drawCamera(ctx, CAMERA_POSES[ii]); |
| 44 | } |
Alex Perry | 554cec0 | 2019-03-23 20:15:12 -0700 | [diff] [blame] | 45 | |
| 46 | ctx.restore(); |
| 47 | } |