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