index : btroops | |
Virtual board game-aid for BattleTroops, an infantry combat simulator wargame published by FASA in 1989. |
aboutsummaryrefslogtreecommitdiff |
diff options
-rw-r--r-- | index.js | 19 |
1 files changed, 14 insertions, 5 deletions
@@ -115,14 +115,19 @@ rect.addEventListener('mousemove', e => { console.log('angle', angle, 'degrees', radToDeg(angle)); - let smlArcAngle = Math.atan(pointDistanceInInches / (6 * calcY)) * 2; + let smlArcAngle = Math.atan(pointDistanceInInches / (6 * calcY)); + let medArcAngle = Math.atan((pointDistanceInInches / 2) / calcY); + let lrgArcAngle = Math.atan((21 * pointDistanceInInches) / (6 * calcY)); + + let arcAngle = lrgArcAngle; + let distance = Math.sqrt((x2px - x1px)**2 + (y2px - y1px)**2); - let newY1 = y2px + (distance * Math.cos(angle)) * Math.atan(smlArcAngle / 2); - let newY2 = y2px - (distance * Math.cos(angle)) * Math.atan(smlArcAngle / 2); + let newY1 = y2px + (distance * Math.cos(angle)) * Math.tan(arcAngle); + let newY2 = y2px - (distance * Math.cos(angle)) * Math.tan(arcAngle); - let newX1 = x2px + (distance * Math.sin(angle)) * Math.atan(smlArcAngle / 2); - let newX2 = x2px - (distance * Math.sin(angle)) * Math.atan(smlArcAngle / 2); + let newX1 = x2px + (distance * Math.sin(angle)) * Math.tan(arcAngle); + let newX2 = x2px - (distance * Math.sin(angle)) * Math.tan(arcAngle); // p.setAttributeNS(null, 'points', `${newX},${newY} ${x1px},${y1px} ${newX},${newY}`); // p.setAttributeNS(null, 'points', `${x2px},${y2px} ${x1px},${y1px} ${x2px},${y2px}`); @@ -176,6 +181,10 @@ rect.addEventListener('mousemove', e => { } } + distance = Math.sqrt((x2 - x1)**2 + (y2 - y1)**2); + newY = y2 + (distance * Math.cos(angle)) * Math.tan(arcAngle); + newX = x2 + (distance * Math.sin(angle)) * Math.tan(arcAngle); + aim.setAttributeNS(null, 'x2', `${newX}in`); aim.setAttributeNS(null, 'y2', `${newY}in`); |