@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
44 lines (37 loc) • 957 B
JavaScript
/**
*
* @param {Vector2} mapSize
* @param camera
* @param {number} x0
* @param {number} y0
* @param {number} z0
* @param {number} x1
* @param {number} y1
* @param {number} z1
*/
export function setShadowCameraDimensionsDiscrete(
mapSize,
camera,
x0,
y0,
z0,
x1,
y1,
z1
) {
const dX = x1 - x0;
const dY = y1 - y0;
const shadow_map_width = mapSize.x;
const shadow_map_height = mapSize.y;
const rX = dX / shadow_map_width;
const rY = dY / shadow_map_height;
//set start coordinate to pixel-snapped position
const x0_d = x0 - x0 % rX - rX / 2;
const y0_d = y0 - y0 % rY - rY / 2;
const x1_d = x0_d + (dX) * ((shadow_map_width + 1) / shadow_map_width);
const y1_d = y0_d + (dY) * ((shadow_map_height + 1) / shadow_map_height);
camera.left = x0_d;
camera.right = x1_d;
camera.bottom = y0_d;
camera.top = y1_d;
}