|
|
|
@ -193,6 +193,7 @@ function geometry_start_prestroke(state, player_id) {
@@ -193,6 +193,7 @@ function geometry_start_prestroke(state, player_id) {
|
|
|
|
|
player.strokes.push({ |
|
|
|
|
'empty': false, |
|
|
|
|
'points': [], |
|
|
|
|
'raw_points': [], |
|
|
|
|
'head': null, |
|
|
|
|
'color': player.color, |
|
|
|
|
'width': player.width, |
|
|
|
@ -208,6 +209,97 @@ function geometry_end_prestroke(state, player_id) {
@@ -208,6 +209,97 @@ function geometry_end_prestroke(state, player_id) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function geometry_add_prepoint(state, context, player_id, point, is_pen, raw = false) { |
|
|
|
|
if (config.p === 'demetri') { |
|
|
|
|
return geometry_add_prepoint_demetri(state, context, player_id, point, is_pen, raw); |
|
|
|
|
} else if (config.p == 'raw') { |
|
|
|
|
return geometry_add_prepoint_raw(state, context, player_id, point, is_pen, raw); |
|
|
|
|
} else if (config.p == 'avg') { |
|
|
|
|
return geometry_add_prepoint_new(state, context, player_id, point, is_pen, raw); |
|
|
|
|
} else if (config.p == 'perf') { |
|
|
|
|
return geometry_add_prepoint_old(state, context, player_id, point, is_pen, raw); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function geometry_add_prepoint_demetri(state, context, player_id, point, is_pen, raw = false) { |
|
|
|
|
if (!state.online) return; |
|
|
|
|
|
|
|
|
|
const player = state.players[player_id]; |
|
|
|
|
const stroke = player.strokes[player.strokes.length - 1]; |
|
|
|
|
|
|
|
|
|
stroke.raw_points.push(point); |
|
|
|
|
stroke.points = smooth_curve(stroke.raw_points); |
|
|
|
|
|
|
|
|
|
if (point.pressure < config.min_pressure) { |
|
|
|
|
point.pressure = config.min_pressure; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
recompute_dynamic_data(state, context); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function geometry_add_prepoint_raw(state, context, player_id, point, is_pen, raw = false) { |
|
|
|
|
if (!state.online) return; |
|
|
|
|
|
|
|
|
|
const player = state.players[player_id]; |
|
|
|
|
const stroke = player.strokes[player.strokes.length - 1]; |
|
|
|
|
const points = stroke.points; |
|
|
|
|
|
|
|
|
|
if (point.pressure < config.min_pressure) { |
|
|
|
|
point.pressure = config.min_pressure; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
points.push(point); |
|
|
|
|
|
|
|
|
|
recompute_dynamic_data(state, context); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function geometry_add_prepoint_new(state, context, player_id, point, is_pen, raw = false) { |
|
|
|
|
if (!state.online) return; |
|
|
|
|
|
|
|
|
|
const player = state.players[player_id]; |
|
|
|
|
const stroke = player.strokes[player.strokes.length - 1]; |
|
|
|
|
const points = stroke.points; |
|
|
|
|
|
|
|
|
|
if (point.pressure < config.min_pressure) { |
|
|
|
|
point.pressure = config.min_pressure; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const exp_window = 3; |
|
|
|
|
|
|
|
|
|
if (points.length > exp_window) { |
|
|
|
|
let xsum = 0; |
|
|
|
|
let ysum = 0; |
|
|
|
|
|
|
|
|
|
const screen_last = canvas_to_screen(state, points[points.length - 1]); |
|
|
|
|
const screen_this = canvas_to_screen(state, point); |
|
|
|
|
|
|
|
|
|
const screen_dx = screen_this.x - screen_last.x; |
|
|
|
|
const screen_dy = screen_this.y - screen_last.y; |
|
|
|
|
|
|
|
|
|
// TODO: Higher (screen space!) speed gives more weight to the new point
|
|
|
|
|
const weight_x = 1; |
|
|
|
|
const weight_y = 1; |
|
|
|
|
|
|
|
|
|
for (let i = points.length - exp_window; i < points.length; ++i) { |
|
|
|
|
xsum += points[i].x * weight_x; |
|
|
|
|
ysum += points[i].y * weight_y; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
xsum += point.x * weight_x; |
|
|
|
|
ysum += point.y * weight_y |
|
|
|
|
|
|
|
|
|
points.push({ |
|
|
|
|
'x': xsum / (exp_window + 1), |
|
|
|
|
'y': ysum / (exp_window + 1), |
|
|
|
|
'pressure': point.pressure |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
points.push(point); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
recompute_dynamic_data(state, context); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function geometry_add_prepoint_old(state, context, player_id, point, is_pen, raw = false) { |
|
|
|
|
if (!state.online) return; |
|
|
|
|
|
|
|
|
|
const player = state.players[player_id]; |
|
|
|
|