Skip to content

Commit

Permalink
make some math a little easier to read
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffomatic committed Dec 22, 2020
1 parent a47203d commit 235c204
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/systems/client/playerInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,12 @@ const handleAttackInput = (client: Client, frame: number): void => {

// Get camera ray in world space
const cameraWorldPos = client.camera.getPos()
const deltas = vec3.sub(vec3.create(), mouseWorldPos, cameraWorldPos)
const [dx, dy, dz] = vec3.sub(vec3.create(), mouseWorldPos, cameraWorldPos)

// Extrapolate ray to the xy-plane
const dydx = deltas[1] / deltas[0]
const dydz = deltas[1] / deltas[2]
// Extrapolate ray to the xx-plane
const targetPos = vec2.fromValues(
(dydx * cameraWorldPos[0] - cameraWorldPos[1]) / dydx,
(dydz * cameraWorldPos[2] - cameraWorldPos[1]) / dydz,
cameraWorldPos[0] - (cameraWorldPos[1] * dx) / dy,
cameraWorldPos[2] - (cameraWorldPos[1] * dz) / dy,
)

client.sendClientMessage({
Expand Down

0 comments on commit 235c204

Please sign in to comment.