export function sys_draw(game: Game, delta: number) {
game.ForegroundContext.resetTransform();
game.ForegroundContext.clearRect(0, 0, game.ViewportWidth, game.ViewportHeight);
let position = <Vec3>[0, 0, 0];
let camera_entity = game.Cameras[0];
let main_camera = game.World.Camera[camera_entity];
if (!main_camera || main_camera.Kind === CameraKind.Xr) {
return;
}
for (let i = 0; i < game.World.Signature.length; i++) {
if ((game.World.Signature[i] & QUERY) == QUERY) {
mat4_get_translation(position, game.World.Transform[i].World);
vec3_transform_position(position, position, main_camera.Pv);
if (position[2] < -1 || position[2] > 1) {
continue;
}
game.ForegroundContext.setTransform(
1,
0,
0,
1,
0.5 * (position[0] + 1) * game.ViewportWidth,
0.5 * (-position[1] + 1) * game.ViewportHeight
);
let draw = game.World.Draw[i];
switch (draw.Kind) {
case DrawKind.Text:
draw_text(game, draw);
break;
case DrawKind.Selection:
draw_selection(game, draw);
break;
}
}
}
}