nodes/mathutil.pyΒΆ
Part of Q1K3.
1"""Yaw / pitch rotation helpers shared by the player, weapons, enemies and doors.
2
3Angles follow the port's JS-frame convention: yaw 0 looks along +Z, and yaw
4increases counter-clockwise when viewed from above.
5"""
6
7from __future__ import annotations
8
9import math
10
11from simvx.core import Vec3
12
13
14def rotate_y(p: Vec3, rad: float) -> Vec3:
15 """Rotate *p* around the Y axis by *rad* radians."""
16 s = math.sin(rad)
17 c = math.cos(rad)
18 return Vec3(p.z * s + p.x * c, p.y, p.z * c - p.x * s)
19
20
21def rotate_x(p: Vec3, rad: float) -> Vec3:
22 """Rotate *p* around the X axis by *rad* radians."""
23 s = math.sin(rad)
24 c = math.cos(rad)
25 return Vec3(p.x, p.y * c - p.z * s, p.y * s + p.z * c)
26
27
28def rotate_yaw_pitch(p: Vec3, yaw: float, pitch: float) -> Vec3:
29 """Rotate *p* by *pitch* around X, then *yaw* around Y."""
30 return rotate_y(rotate_x(p, pitch), yaw)