Compare commits

..
Author SHA1 Message Date
Stefan MaierandClaude Opus 5.5 88354e5c6c VR roadmap: left-handed mode and graphics presets done on both headsets
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 21:21:35 +02:00
Stefan MaierandClaude Opus 5.5 8cdce233e4 Android settings: config.toml written beside itself and renamed over
A config.toml pushed by adb belongs to the shell and the app cannot open it
for writing, so the VR options' changes (handedness, graphics, refresh rate,
resolution) lasted only until a restart. Writing a temporary file and
renaming it over the old one replaces it all the same (the folder is the
app's), and a write cut short leaves the old file whole.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 20:55:22 +02:00
Stefan MaierandClaude Opus 5.5 81137e3af3 VR roadmap: left-handed mode and graphics presets good on the Steam Frame
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 20:40:01 +02:00
Stefan MaierandClaude Opus 5.5 fb670e79b9 VR roadmap: the left hand's ammo counter reads the right way round
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 20:33:11 +02:00
Stefan MaierandClaude Opus 5.5 8022a0b4a1 VR left-handed: the assault rifle's ammo counter reads the right way round
The mirrored first-person model leaves its geometry mirrored; a numeric
display drawn mirrored (rasterizer_set_model_skinning's winding flag) now
shows each digit's bitmap turned over in u (1-u on the first map's texture
transform) and swaps the digits' order across the display (the quad of the
n-th digit from the right shows the n-th from the left; digit count from
the counter limit, the compass's single digit unchanged). Only for 2d,
non-screen-space first maps of numeric chicago/generic shaders, only when
mirrored: right-handed and flat output unchanged.

debug.mirror_first_person (Android, default false): off the headset the
first-person weapon is mirrored across the camera's forward/up plane as
the left hand's is in VR, for checking such things in the emulator.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 20:33:11 +02:00
Stefan MaierandClaude Opus 5.5 696383f191 VR roadmap: the left hand's mirrored ammo display, an open point
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 20:01:39 +02:00
Stefan Maier 9a33ecd2d3 Revert "VR left-handed: the assault rifle's ammo display reads the right way round"
This reverts commit 530a32b64889c24e64c5e805949e31df1c68fb73.
2026-10-06 20:01:19 +02:00
Stefan Maier 9447bc2ae4 Revert "VR left-handed: the ammo display's subtree found without hanging"
This reverts commit 8e40d6ecacd92f3938e329e528a27c3eddd8dbe1.
2026-10-06 20:01:18 +02:00
Stefan Maier f04c8c4045 Revert "VR left-handed: a part is drawn mirrored only where all its nodes are"
This reverts commit 1a6061b932e7f293cc40351f90f4d0d68edb2bd2.
2026-10-06 20:01:18 +02:00
Stefan MaierandClaude Opus 5.5 b026590824 VR left-handed: a part is drawn mirrored only where all its nodes are
The assault rifle's ammo display, mirrored back, vanished: its part's
winding was judged by its first node alone, which may be the mirrored gun,
so its triangles were turned over and culled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 19:54:01 +02:00
Stefan MaierandClaude Opus 5.5 2a2b2cdbf3 VR left-handed: the ammo display's subtree found without hanging
Walking up from a node to the display through parent_node_index never
ended where the root names itself as its parent: the game hung loading a
level left-handed (Steam Frame). Each step now goes only to a parent
before its child, as vr_skeleton_build does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 19:50:52 +02:00
Stefan MaierandClaude Opus 5.5 5861e57d99 VR left-handed: the assault rifle's ammo display reads the right way round
Its node ("... display") and what hangs from it are mirrored back about
the display's own centre after the pose is mirrored: it stays where the
mirrored gun has it, reads as in the right hand, and its triangles keep
their winding (rasterizer_xbox.c decides per skinned part). After
HaloCE-Quest-VR (CC0).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 19:47:53 +02:00
Stefan MaierandClaude Opus 5.5 50d685e465 VR roadmap: step 2 in part built (left-handed mode, graphics presets, refresh rate)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 19:33:27 +02:00
Stefan MaierandClaude Opus 5.5 0e6b006878 VR options: graphics, refresh rate and resolution rows
The panel's second page (MORE) gets "Graphics" (vr.graphics: Low,
Medium, High, Max), "Refresh rate" and "Resolution" rows, with a note
of what they do. The refresh rate steps through the rates the runtime
offers (XR_FB_display_refresh_rate: host_xr_refresh_rates, new host
imports with host_xr_set_refresh_rate) and changes at once (vr.c asks
for it when vr.refresh_rate changes); where the runtime offers none
(SteamVR on the Steam Frame, whose rate is SteamOS's) the row shows the
rate it runs at, from its frames' period, and stays as it is. The
resolution (vr.resolution_scale, 70 to 120%) is read as the app starts:
the row says when a restart is needed. vr.log_performance's late frames
follow the rate as it changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 19:30:32 +02:00
Stefan MaierandClaude Opus 5.5 ca73ba7909 VR: graphics presets (vr.graphics)
port/linux/game/vr_graphics.c (after HaloCE-Quest-VR's, CC0) sets the
game's own effect switches each frame before drawing: "high" (the
default) draws everything as before; "medium" no object shadows,
environment reflections or lens flares; "low" nor specular light, bump
maps, detail objects (grass), the screen's fog layer, contrails, weather
or camouflage's second pass; "max" is "high" with per-pixel model
lighting and 512x512 shadow maps (d3d8_gl.c asks halo_vr_graphics). A
switch the game changes (scripts, console) is taken as its wish and
combined with the preset's. A client in another's game keeps grass, lens
flares and the fog layer as the host's rules have them; cheats.c leaves
the environment parts the preset may keep off there (shadows, specular,
reflections).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 19:28:48 +02:00
Stefan MaierandClaude Opus 5.5 c254d6df05 VR: left-handed, the rumble's motors follow the hands
The game's light (right) motor rumbles the weapon hand, the heavy one the
free hand (halo_vr_weapon_hand), as right-handed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 19:26:40 +02:00
Stefan MaierandClaude Opus 5.5 9910c4a9dc VR options: weapon hand and mirrored controls, two pages
The VR options panel gets a "Weapon hand" row (vr.handedness) and a
"Mirrored controls" row (vr.mirror_controls, dim when right-handed). Its
rows now go on two pages with tabs beside the title (PLAY, MORE; up and
down run on across them, a tab clicked shows its page). The controller
buttons page is built from the hands' jobs: the weapon hand's trigger
and grip, the free hand's, the move and turn sticks and the face
buttons (Quest X/Y for A/B; Steam Frame D-pad for A, B, X, Y) on the
sides the settings put them; the wrist, wheel and aiming notes name the
hands. network_vr.c's notes name the weapon and the free hand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 19:26:03 +02:00
Stefan MaierandClaude Opus 5.5 b1d59e654d VR: left-handed, the motion tracker on the right wrist
The wrist layer goes on the free hand's wrist: halo_xr_submit.wrist_hand
(new, after wrist_down); host_xr.c keeps both grips and places the layer
on the right wrist as the mirror image of the left one's, read the right
way round.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 19:22:25 +02:00
Stefan MaierandClaude Opus 5.5 1f3d1be207 VR: left-handed controls, mirrored with vr.mirror_controls
Left-handed, in play, vr.c hands xinput_sdl.c the controllers with the
weapon hand's trigger and grip as the right side's (fire, melee, the
wheel's throttle) and the free hand's as the left's (grenade, foregrip,
brake). vr.mirror_controls (default true) mirrors the sticks (move on
the right, turn and steer on the left), their clicks, the bumpers and
the face buttons too: on the Quest X/Y for A/B; on the Steam Frame, whose
A, B, X and Y are all on the right controller, the left D-pad takes them
as their mirror image (down A, left B, right X, up Y) and they take the
D-pad, so every function stays reachable. The menus keep the buttons.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 19:21:36 +02:00
Stefan MaierandClaude Opus 5.5 d97de6d499 VR: left-handed mode, the weapon in the left hand
vr.handedness = "left" puts the weapon in the left hand: aim, muzzle,
laser, crosshair, scope and turret aim follow the left controller; the
grenade, the foregrip and the fingers' closing round a grenade move to
the right hand, the grip's melee to the left. The first-person model is
posed as the right hand's in a mirror image of the room ("model space":
vr.c mirrors the controllers into it, first_person_weapons.c the body)
and the posed skeleton mirrored back, after HaloCE-Quest-VR (CC0); a
model whose node matrices mirror has its triangles' winding turned over
(rasterizer_set_model_skinning -> d3d8_gl.c, ended with the model and
each transparent group). halo_vr_left_hand is now halo_vr_free_hand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 19:20:59 +02:00
19 changed files with 1616 additions and 260 deletions

No files matched your search

+98 -1
View File
@@ -25,6 +25,8 @@ named where code is taken over.
| Menus | The PC version's menus in VR (`vr.menus`), clicked with a laser; text typed on the on-screen keyboard |
| Multiplayer | Up to date with OpenCE (network version 20): cross-play, its server browser, co-op campaign, password lobbies; join codes and the VR online list |
| Bots | Bots in multiplayer: on foot (paths, items, objectives), in vehicles and at turrets; they make room for a joining person |
| Controls | Left-handed mode (`vr.handedness`): the weapon in the left hand, the arms and grips mirrored, sticks and buttons mirrored on both controllers (`vr.mirror_controls`), the assault rifle's counter read the right way round (2026-10-06) |
| Graphics | Presets low / medium / high / max (`vr.graphics`), refresh rate and resolution in the VR options, all kept over a restart (2026-10-06) |
| Arms and hands | Both arms by IK from shoulders that follow the torso, the elbow led by the hand's roll; fingers from trigger, grip and touch; `vr.body` arms / hands / off, `vr.fingers` (2026-10-06) |
## Next, in order
@@ -33,12 +35,107 @@ named where code is taken over.
| --- | --- | --- |
| 1 | Steam Frame CPU time: Mesa's trace markers off (after astromaddie/HaloCE-VR), no `glGet` stalls in the visibility counters' copies | **done** (in `main` 2026-10-06): markers quieted, no problems; the frame's work about unchanged (11-12.5 ms of 13.9 in a bot game) |
| 3a | Visible arms and hands: the arms by IK to the controllers, fingers by trigger and grip | **done** (in `main` 2026-10-06; Quest 3 and Steam Frame good; 0.02 ms a frame) |
| 2 | Controls and comfort: left-handed mode, buttons remapped, flashlight by tapping the head, finer turning and vignette choices, graphics presets and refresh rate in the VR options | |
| 2 | Controls and comfort: left-handed mode, buttons remapped, flashlight by tapping the head, finer turning and vignette choices, graphics presets and refresh rate in the VR options | first part **done** (in `main` 2026-10-06; Quest 3 and Steam Frame good): left-handed mode, graphics presets, refresh rate and resolution in the VR options. Left: buttons remapped, flashlight by tapping the head, finer turning and vignette choices |
| 3b | The whole body: torso from head and hands, legs and feet following in the room; full / arms only / hands only | |
| 3c | Weapons held physically, holsters at shoulder and hip (the buttons stay) | |
| 3d | Other VR players shown with their heads, hands and bodies (today their bodies move as flat players' do: only their aim and throws come from their hands) | |
| 4 | Later: disc image import in the launcher, sprint by arm swing (offline) | |
## Step 2, first part (done)
Left-handed mode and graphics presets, after HaloCE-Quest-VR (CC0): its
mirrored first-person model, its graphics switches.
Left-handed (`vr.handedness = "left"`):
- The weapon in the left hand: aim, shots, muzzle, laser, crosshair,
scope disc, turret aim. The first-person model is posed as the right
hand's in a mirror image of the room ("model space", `halo_vr.h`) and
mirrored back; a model whose node matrices mirror has its triangles'
winding turned over (`rasterizer_set_model_skinning`, `d3d8_gl.c`). The
arms reach to the other shoulders, the foregrip is gripped with the
right hand, the right hand's fingers follow its controller.
- Grenades held and thrown with the right trigger and hand; melee by the
left grip (a swing of either hand, as before); the motion tracker on the
right wrist (`halo_xr_submit.wrist_hand`); the rumble's light motor in
the weapon hand.
- The left trigger fires, the right one throws; at the Warthog's wheel the
left trigger accelerates, the right one brakes.
- With `vr.mirror_controls` (default): the right stick moves, the left
turns and steers; their clicks, the bumpers and the face buttons change
sides (Quest: X jumps, Y light / held grenades, A action and reload, B
switch weapon; Steam Frame: the left D-pad does A, B, X, Y as their
mirror image, down jump, left light, right action, up switch weapon,
and A, B, X, Y do the D-pad's). The menus keep their buttons; the
laser pointer works from either hand as before.
- Other machines see the shots leave the left hand (the network message
is unchanged: aim and muzzle from the camera).
- The assault rifle's ammo counter and compass read the right way round
on the mirrored model (2026-10-06): their geometry stays mirrored, each
digit's bitmap is drawn turned over in u and the digits' order across
the display swapped (numeric shaders drawn mirrored,
`rasterizer_xbox_transparent_geometry.c`). Checked flat in the emulator
with `debug.mirror_first_person` (the first-person weapon mirrored off
the headset): 60, 48, 36 ... 06 read correctly. Steam Frame good
(2026-10-06).
- Kept as they are (accepted 2026-10-06): the small static icons under the
counter (round and "x") stay mirror images (a texture atlas, not
numeric). The game's prompts still name the Xbox's buttons.
- Settings kept: on Android `config.toml` is written beside itself and
renamed over (`port_config.c`), so one pushed by adb (the shell's, which
the app could not open for writing) no longer loses the VR options'
changes at a restart.
- Headset tests 2026-10-06: Quest 3 and Steam Frame good (left hand,
controls mirrored and not, counter, presets, refresh rates, resolution,
settings kept over a restart).
Graphics (`vr.graphics`, `port/linux/game/vr_graphics.c`), set each frame
on the game's own switches:
| Preset | Leaves out |
| --- | --- |
| `"high"` (default) | nothing: as before |
| `"medium"` | object shadows, environment reflections, lens flares |
| `"low"` | also specular light, bump maps, grass and other detail objects, the screen's fog layer, contrails, weather, camouflage's second pass |
| `"max"` | nothing; models lit for each pixel, shadows at 512x512 |
A client in another's game keeps grass, lens flares and the fog layer as
the host's rules have them (`cheats.c`). Shadows, specular passes,
reflections and detail objects are draws (CPU, which the Frame's GL
driver is short of); bump maps, fog, camouflage and per-pixel lighting
the GPU's fill.
VR options (Y): two pages, PLAY (the comfort rows, "Weapon hand",
"Mirrored controls") and MORE ("Graphics", "Refresh rate", "Resolution",
the controller buttons page, Quit). The refresh rate steps through what
the runtime offers and changes at once; on the Steam Frame the row shows
SteamOS's rate. The resolution (`vr.resolution_scale`, 70-120%) takes a
restart. The controller buttons page shows the layout as set.
| Setting | Values |
| --- | --- |
| `vr.handedness` | `"right"` (default), `"left"` |
| `vr.mirror_controls` | `true` (default): sticks and buttons mirrored when left-handed; `false`: as right-handed (triggers and grips still follow the hands) |
| `vr.graphics` | `"low"`, `"medium"`, `"high"` (default), `"max"` |
| `vr.refresh_rate` | Hz, as offered (Quest 3: 72, 80, 90, 120) |
| `vr.resolution_scale` | 0.7 to 1.2, on restart |
To try in the headset (Quest 3 and Steam Frame):
1. Left-handed: aim, laser, crosshair, scope of sniper and rocket
launcher; weapon held right in the left hand, arms from the right
shoulders, nothing inside out (faces culled the wrong way would show
the inside of the gun or the glove).
2. Two-handed grip with the right hand; grenades in the right hand (held
and thrown); melee by grip and by swing; motion tracker on the right
wrist.
3. Buttons and sticks mirrored on the Touch and the Frame controllers
(every function reachable), then `Mirrored controls: Off`.
4. Vehicles: wheel, throttle and brake, steering stick, a gunner's aim;
menus and the laser pointer; a network game (shots from the left hand
on the other machine).
5. Graphics: each preset's look and smoothness (`vr.log_performance`),
in a bot game; Max on the Quest at 90 Hz; refresh rates 72/80/90/120
on the Quest; the Frame's row.
## Step 3a (done)
Tried on the Quest 3 and the Steam Frame, in `main`. The arm IK,
+5
View File
@@ -135,6 +135,11 @@ into a layer's image, opaque */
int host_xr_copy_layer_array(int layer, unsigned int texture, int array_layer);
/* darkens the eye images from their edges, strength 0..1 (0: off) */
void host_xr_set_vignette(float strength);
/* the refresh rates the headset offers (Hz, at most maximum of them; 0 when
it lets none be chosen), and the one it runs at (0: unknown); and asking
for the highest offered at or below wanted (0: the highest) */
int host_xr_refresh_rates(float *rates, int maximum, float *current);
void host_xr_set_refresh_rate(float wanted);
/* ---------- Android */
+56 -23
View File
@@ -120,10 +120,10 @@ static struct
XrAction haptic;
struct xr_hand_actions hands[HALO_XR_HAND_COUNT];
/* where the head and the left hand are this frame (the wrist layer) */
/* where the head and the hands are this frame (the wrist layer) */
XrPosef head;
XrPosef left_grip;
int left_grip_valid;
XrPosef grips[HALO_XR_HAND_COUNT];
int grips_valid[HALO_XR_HAND_COUNT];
int has_performance_settings;
/* (XR_META_performance_metrics: the compositor's counts, in the log,
@@ -946,11 +946,8 @@ static void hands_read(struct halo_xr_frame *frame)
{
out->flags = flags_from_location(location.locationFlags);
pose_from_xr(&out->grip, &location.pose);
if (hand == HALO_XR_HAND_LEFT)
{
xr.left_grip = location.pose;
xr.left_grip_valid = (out->flags & HALO_XR_POSE_VALID) != 0;
}
xr.grips[hand] = location.pose;
xr.grips_valid[hand] = (out->flags & HALO_XR_POSE_VALID) != 0;
}
location.locationFlags = 0;
if (XR_SUCCEEDED(xrLocateSpace(xr.hands[hand].aim_space, xr.local_space,
@@ -1048,7 +1045,9 @@ On the back of the left wrist, like a watch: behind the palm, where the
grip pose is, and out of the back of the hand. In the left grip pose -Z
runs to the fingers, +Y up the handle and -X out of the back of the hand;
the layer faces -X with its top towards the elbow, as the wrist turned to
the eyes reads it. Shown only while it is. */
the eyes reads it. Shown only while it is. Left-handed (wrist_hand), on the
right wrist, as the mirror image: there +X runs out of the back of the
hand. */
#define WRIST_IMAGE_SIZE 512
#define CROSSHAIR_IMAGE_SIZE 256
@@ -1088,26 +1087,32 @@ static void quaternion_rotate_vector(const XrQuaternionf *q, const XrVector3f *v
static int wrist_pose(const struct halo_xr_submit *submit, XrPosef *pose)
{
/* the layer's axes in the grip's: x = -Y, y = +Z, z = -X, so the
layer's right and down, as it is read, are the grip's -Y and -Z */
static const XrQuaternionf layer_in_grip = { 0.5f, -0.5f, -0.5f, 0.5f };
const XrVector3f offset = { -WRIST_ABOVE_HAND, -WRIST_DOWN_HANDLE - submit->wrist_right,
WRIST_BEHIND_PALM - submit->wrist_down };
/* the layer's axes in the left grip's: x = -Y, y = +Z, z = -X, so the
layer's right and down, as it is read, are the grip's -Y and -Z; in the
right grip's x = +Y, y = +Z, z = +X (the mirror image, read the right
way round: its x turned back) */
static const XrQuaternionf layer_in_left_grip = { 0.5f, -0.5f, -0.5f, 0.5f };
static const XrQuaternionf layer_in_right_grip = { 0.5f, 0.5f, 0.5f, 0.5f };
int right = submit->wrist_hand == HALO_XR_HAND_RIGHT;
const XrPosef *grip = &xr.grips[right ? HALO_XR_HAND_RIGHT : HALO_XR_HAND_LEFT];
const XrVector3f offset = { right ? WRIST_ABOVE_HAND : -WRIST_ABOVE_HAND,
-WRIST_DOWN_HANDLE - submit->wrist_right, WRIST_BEHIND_PALM - submit->wrist_down };
const XrVector3f layer_normal = { 0.0f, 0.0f, 1.0f };
/* clockwise as read: about the layer's normal, negatively */
float half_turn = -submit->wrist_turn * WRIST_PI / 360.0f;
/* clockwise as read: about the layer's normal, negatively (the mirror
image's the other way) */
float half_turn = (right ? 1.0f : -1.0f) * submit->wrist_turn * WRIST_PI / 360.0f;
XrQuaternionf turn = { 0.0f, 0.0f, sinf(half_turn), cosf(half_turn) };
XrQuaternionf unturned;
XrVector3f moved, normal, to_eyes;
float distance;
if (!xr.left_grip_valid)
if (!xr.grips_valid[right ? HALO_XR_HAND_RIGHT : HALO_XR_HAND_LEFT])
return 0;
quaternion_rotate_vector(&xr.left_grip.orientation, &offset, &moved);
pose->position.x = xr.left_grip.position.x + moved.x;
pose->position.y = xr.left_grip.position.y + moved.y;
pose->position.z = xr.left_grip.position.z + moved.z;
quaternion_multiply(&xr.left_grip.orientation, &layer_in_grip, &unturned);
quaternion_rotate_vector(&grip->orientation, &offset, &moved);
pose->position.x = grip->position.x + moved.x;
pose->position.y = grip->position.y + moved.y;
pose->position.z = grip->position.z + moved.z;
quaternion_multiply(&grip->orientation, right ? &layer_in_right_grip : &layer_in_left_grip, &unturned);
quaternion_multiply(&unturned, &turn, &pose->orientation);
quaternion_rotate_vector(&pose->orientation, &layer_normal, &normal);
@@ -1555,7 +1560,7 @@ int host_xr_begin_frame(struct halo_xr_frame *frame)
pose_from_xr(&frame->head, &head.pose);
xr.head = head.pose;
}
xr.left_grip_valid = 0;
xr.grips_valid[HALO_XR_HAND_LEFT] = xr.grips_valid[HALO_XR_HAND_RIGHT] = 0;
if (xr.focused)
hands_read(frame);
return 1;
@@ -2047,6 +2052,34 @@ void host_xr_set_vignette(float strength)
xr.vignette = strength < 0.0f ? 0.0f : strength > 1.0f ? 1.0f : strength;
}
/* the VR options' refresh rates: those the runtime offers (none where it
lets none be chosen, as SteamVR, whose rate is SteamOS's), and the one it
runs at, by XR_FB_display_refresh_rate or else by its frames' period */
int host_xr_refresh_rates(float *rates, int maximum, float *current)
{
float offered[16];
uint32_t count = 0, index;
*current = 0.0f;
if (!xr.initialized)
return 0;
if (xr.has_refresh_rate)
xr.get_refresh_rate(xr.session, current);
if (*current <= 0.0f && xr.frame_state.predictedDisplayPeriod > 0)
*current = 1e9f / (float)xr.frame_state.predictedDisplayPeriod;
if (!xr.has_refresh_rate || !XR_SUCCEEDED(xr.enumerate_refresh_rates(xr.session, 16, &count, offered)))
return 0;
for (index = 0; index < count && (int)index < maximum; index++)
rates[index] = offered[index];
return (int)index;
}
void host_xr_set_refresh_rate(float wanted)
{
if (xr.initialized)
refresh_rate_choose(wanted);
}
void host_xr_haptic(int hand, float amplitude, float seconds)
{
XrHapticActionInfo information = { XR_TYPE_HAPTIC_ACTION_INFO };
+2
View File
@@ -61,6 +61,8 @@ host_xr_end_frame
host_xr_haptic
host_xr_set_vignette
host_xr_copy_layer_array
host_xr_refresh_rates
host_xr_set_refresh_rate
host_android_path
host_errno
+8 -5
View File
@@ -24,7 +24,7 @@ enum
HALO_XR_LAYER_EYE_LEFT = 0,
HALO_XR_LAYER_EYE_RIGHT = 1,
HALO_XR_LAYER_OVERLAY = 2, /* HUD, menus, cinematics: a flat quad */
HALO_XR_LAYER_WRIST = 3, /* the motion tracker, on the left wrist */
HALO_XR_LAYER_WRIST = 3, /* the motion tracker, on the free hand's wrist */
HALO_XR_LAYER_SCOPE = 4, /* the zoomed view, a disc over the weapon */
HALO_XR_LAYER_CROSSHAIR = 5, /* the weapon's crosshair, where it aims */
HALO_XR_LAYER_NAMES = 6, /* players' names, each a quad over a head */
@@ -155,15 +155,18 @@ struct halo_xr_submit
float overlay_width; /* metres; the height follows from 4:3 */
/* the screen's placement in LOCAL space (HALO_XR_OVERLAY_SCREEN) */
struct halo_xr_pose screen;
/* the wrist layer was filled: shown on the back of the left wrist,
this wide (metres), while the wrist is turned to the eyes */
/* the wrist layer was filled: shown on the back of the left wrist (of
the right one, left-handed: wrist_hand, a HALO_XR_HAND_*), this wide
(metres), while the wrist is turned to the eyes */
int wrist;
float wrist_size;
/* its placement as the wrist turned to the eyes reads it: turned this
many degrees clockwise, and moved this far right and down (metres) */
/* its placement as the left wrist turned to the eyes reads it: turned
this many degrees clockwise, and moved this far right and down (metres;
on the right wrist, the mirror image) */
float wrist_turn;
float wrist_right;
float wrist_down;
int wrist_hand;
/* the scope layer was filled: a disc this wide (metres), here in LOCAL
space, facing back along the weapon */
int scope;
+13 -10
View File
@@ -3,19 +3,22 @@ NETWORK_VR.C
VR players' hands for the other machines: an extension of the distributed
netcode (port/linux/NETCODE.md, network_distributed.c). A VR player's
weapon aims where the right controller points and fires from the hand, and
the left hand holds a grenade and throws it its own way (port/linux/src/
vr.c); the input the netcode relays has only where the head looks, so the
other machines would show that player aiming and throwing where they look.
weapon aims where the weapon hand's controller points and fires from the
hand, and the free hand holds a grenade and throws it its own way
(port/linux/src/vr.c; the right hand and the left, or left-handed the other
way round); the input the netcode relays has only where the head looks, so
the other machines would show that player aiming and throwing where they
look.
Every tick, a machine with a VR player sends the host that player's hands
(_distributed_message_vr_poses, unreliable): where the weapon aims, where
its muzzle is from the unit's camera, whether the left hand holds a
grenade, and the last throw (from where, which way, how hard) for a second
after it. The host keeps them, its own VR players' too, and sends each
client those of the players of other machines. A machine drives a VR
player of another (players.c, weapons.c, units.c) as long as their hands
keep coming, else as before.
its muzzle is from the unit's camera (whichever hand holds it: the others
see shots leave the left hand of a left-handed player), whether the free
hand holds a grenade, and the last throw (from where, which way, how hard)
for a second after it. The host keeps them, its own VR players' too, and
sends each client those of the players of other machines. A machine drives
a VR player of another (players.c, weapons.c, units.c) as long as their
hands keep coming, else as before.
What the hands decide is only how the game looks: damage is the shooter's
report, which the host checks as any other (network_damage.c).
+183
View File
@@ -0,0 +1,183 @@
/*
VR_GRAPHICS.C
The VR graphics presets (vr.graphics, the VR options' "Graphics" row): which
of the game's costlier effects are drawn, for headsets with little time to
spare (the Steam Frame spends most of its frame in its GL driver: fewer
draws help it most; the Quest 3 holds 90 Hz with all of them).
- "high", the default: everything, as before;
- "medium": no object shadows, environment reflections or lens flares;
- "low": nor specular light, bump maps, grass and other detail objects,
the screen's fog layer, contrails, weather or camouflage's second pass;
- "max": "high", the models lit for each pixel and the shadows drawn at
512x512 (d3d8_gl.c asks halo_vr_graphics).
Each effect is a switch the game has already: the rasterizer's console
variables (rasterizer_debug_options) and render.c's effect switches, after
HaloCE-Quest-VR's vr_graphics.c (CC0). Scripts and the console set some of
them (render_effects turns particles off in some cutscenes): a switch is
drawn only while both the game and the preset want it. A change the game
made since the last frame is taken as its wish, kept and combined with the
preset's. Playing in another's game, a client draws grass, lens flares and
the screen's fog as the host's rules have it (cheats.c), whatever the
preset; the reductions it does keep there, cheats.c leaves alone
(vr_graphics_reduces).
What each costs: shadows (each object's map, blur and projection: draws),
specular light and reflections (passes of the level's geometry: draws and
fill), detail objects (many small draws), lens flares (their visibility
tests), contrails and weather (particles), bump maps, the fog layer and
camouflage's pass (the GPU's fill).
*/
#ifdef HALO_ANDROID
#include "cseries.h"
#include "rasterizer/rasterizer_console_vars.h"
#include "networking/network_game_globals.h"
#include "halo_vr.h"
/* source/render/render.c, render_objects.c; source/effects/
weather_particle_systems.c */
extern boolean render_shadows;
extern boolean render_contrails_enabled;
extern boolean render_weather_particle_systems_enabled;
extern boolean weather;
void platform_log(char const *format, ...);
/* an effect: whether each preset draws it (low, medium; high and max draw
everything), whether a client in another's game draws it anyway, and the
game's switches it governs */
struct vr_graphics_effect
{
char const *name;
boolean preset[2];
boolean host_rules;
boolean *switches[2];
};
static struct vr_graphics_effect vr_graphics_effects[] =
{
{ "shadows", { FALSE, FALSE }, FALSE,
{ &render_shadows, &rasterizer_debug_options.draw_environment_shadows } },
{ "specular", { FALSE, TRUE }, FALSE,
{ &rasterizer_debug_options.draw_environment_specular_lights,
&rasterizer_debug_options.draw_environment_specular_lightmaps } },
{ "reflections", { FALSE, FALSE }, FALSE,
{ &rasterizer_debug_options.draw_environment_reflections, NULL } },
{ "bump maps", { FALSE, TRUE }, FALSE,
{ &rasterizer_debug_options.bump_mapping_enabled, NULL } },
{ "detail objects", { FALSE, TRUE }, TRUE,
{ &rasterizer_debug_options.draw_detail_objects, NULL } },
{ "lens flares", { FALSE, FALSE }, TRUE,
{ &rasterizer_debug_options.draw_lens_flares, NULL } },
{ "screen fog", { FALSE, TRUE }, TRUE,
{ &rasterizer_debug_options.draw_environment_fog_screen, NULL } },
{ "contrails", { FALSE, TRUE }, FALSE,
{ &render_contrails_enabled, NULL } },
{ "weather", { FALSE, TRUE }, FALSE,
{ &weather, &render_weather_particle_systems_enabled } },
{ "camouflage pass", { FALSE, TRUE }, FALSE,
{ &rasterizer_debug_options.active_camouflage_multipass_enabled, NULL } },
};
#define NUMBER_OF_VR_GRAPHICS_EFFECTS (sizeof(vr_graphics_effects) / sizeof(vr_graphics_effects[0]))
#define VR_GRAPHICS_SWITCHES (sizeof(vr_graphics_effects[0].switches) / sizeof(vr_graphics_effects[0].switches[0]))
static struct
{
boolean started;
int preset;
boolean client;
/* whether the preset allows each effect; what the game wants of each
switch, and what was written last frame */
boolean allowed[NUMBER_OF_VR_GRAPHICS_EFFECTS];
boolean wanted[NUMBER_OF_VR_GRAPHICS_EFFECTS][VR_GRAPHICS_SWITCHES];
boolean written[NUMBER_OF_VR_GRAPHICS_EFFECTS][VR_GRAPHICS_SWITCHES];
} vr_graphics;
static void vr_graphics_choose(
int preset,
boolean client)
{
static char const *const names[] = { "low", "medium", "high", "max" };
unsigned int index;
vr_graphics.preset = preset;
vr_graphics.client = client;
for (index = 0; index < NUMBER_OF_VR_GRAPHICS_EFFECTS; index++)
{
struct vr_graphics_effect const *effect = &vr_graphics_effects[index];
vr_graphics.allowed[index] = preset >= HALO_VR_GRAPHICS_HIGH || effect->preset[preset] ||
(client && effect->host_rules);
}
platform_log("VR: graphics %s%s", names[preset], client ? " (in another's game)" : "");
}
/* each frame, before it is drawn (render.c) */
void vr_graphics_update(
void)
{
int preset = halo_vr_graphics();
boolean client = network_game_distributed_client();
unsigned int index, which;
if (!vr_graphics.started)
{
/* the game's switches as it starts are its wishes */
for (index = 0; index < NUMBER_OF_VR_GRAPHICS_EFFECTS; index++)
{
for (which = 0; which < VR_GRAPHICS_SWITCHES && vr_graphics_effects[index].switches[which]; which++)
{
vr_graphics.wanted[index][which] = *vr_graphics_effects[index].switches[which];
vr_graphics.written[index][which] = *vr_graphics_effects[index].switches[which];
}
}
vr_graphics.started = TRUE;
vr_graphics_choose(preset, client);
}
else if (preset != vr_graphics.preset || client != vr_graphics.client)
{
vr_graphics_choose(preset, client);
}
for (index = 0; index < NUMBER_OF_VR_GRAPHICS_EFFECTS; index++)
{
for (which = 0; which < VR_GRAPHICS_SWITCHES && vr_graphics_effects[index].switches[which]; which++)
{
boolean *game_switch = vr_graphics_effects[index].switches[which];
boolean value;
/* (the game, a script, the console changed it since: its wish) */
if (*game_switch != vr_graphics.written[index][which])
vr_graphics.wanted[index][which] = *game_switch;
value = vr_graphics.wanted[index][which] && vr_graphics.allowed[index];
*game_switch = value;
vr_graphics.written[index][which] = value;
}
}
}
/* whether the preset keeps this switch of the game's off now (cheats.c, a
client's rules: those it may keep off) */
boolean vr_graphics_reduces(
boolean const *game_switch)
{
unsigned int index, which;
if (!vr_graphics.started)
return FALSE;
for (index = 0; index < NUMBER_OF_VR_GRAPHICS_EFFECTS; index++)
{
for (which = 0; which < VR_GRAPHICS_SWITCHES && vr_graphics_effects[index].switches[which]; which++)
{
if (vr_graphics_effects[index].switches[which] == game_switch)
return !vr_graphics.allowed[index];
}
}
return FALSE;
}
#endif
+51 -19
View File
@@ -88,13 +88,14 @@ degrees on an axis (the other axis 0); nonzero if it has. The game counts
it as looking around (player_control.c's action tests). */
int halo_vr_look_delta(float *yaw, float *pitch);
/* The weapon in the right hand (vr.aim_with = "controller"; each returns 0,
and the game does as before, when the hand is not tracked):
/* The weapon in the right hand, or the left one (vr.handedness; vr.aim_with
= "controller"; each returns 0, and the game does as before, when the hand
is not tracked):
- the direction the player's weapon aims, where the controller points (the
body and the view keep facing where the head looks);
- where its shots start, as an offset from the unit's camera (world units);
- the camera the first-person weapon model is posed from, so that it lies
in the hand;
in the hand (in model space, below);
- the aiming laser's start and direction; */
int halo_vr_aim_vector(short local_player_index, float vector[3]);
int halo_vr_weapon_origin_offset(short local_player_index, float offset[3]);
@@ -104,9 +105,18 @@ int halo_vr_weapon_origin_offset(short local_player_index, float offset[3]);
int halo_vr_weapon_origin(short local_player_index, float origin[3]);
int halo_vr_weapon_camera(short local_player_index, float position[3], float forward[3], float up[3]);
int halo_vr_laser(short local_player_index, float start[3], float direction[3]);
/* Model space: the first-person model (first_person_weapons.c) is always
posed as the right hand's. Left-handed, it is posed in a mirror image of
the room and drawn mirrored back (its triangles' winding turned over); the
mirror: a point on it (world units) and its normal, or 0 when it is not
mirrored. What first_person_weapons.c and vr.c exchange about the model
is in model space: the weapon camera, the free hand, the foregrip, the
fingers (0 the model's left hand, the free one), the barrel and the laser
along it. */
int halo_vr_first_person_mirror(short local_player_index, float point[3], float normal[3]);
/* the laser for this frame, along the barrel (first_person_weapons.c: while
an animation turns the weapon, as in a reload), and the laser at the ready,
where the controller aims */
an animation turns the weapon, as in a reload; model space), and the laser
at the ready, where the controller aims (in the room) */
void halo_vr_set_laser(short local_player_index, const float start[3], const float direction[3]);
int halo_vr_ready_laser(short local_player_index, float start[3], float direction[3]);
/* The arms (interface/first_person_weapons.c):
@@ -114,16 +124,16 @@ int halo_vr_ready_laser(short local_player_index, float start[3], float directio
and the torso's flat heading (which follows the head beyond a few
degrees, and the hands; the stick's turns turn it at once), from which
the shoulders hang;
- the left hand's pose;
- the left hand on the weapon: given where the model's left hand holds it
- the free hand's pose (the left one, left-handed the right; model space);
- the free hand on the weapon: given where the model's left hand holds it
(world units) and the line from its right hand to its left in the
weapon's forward, right and up, whether the left hand grips it; then the
weapon's forward, right and up, whether the free hand grips it; then the
weapon aims along both hands; */
int halo_vr_body_frame(short local_player_index, float head[3], float neck[3], float forward[3]);
int halo_vr_left_hand(short local_player_index, float position[3], float forward[3], float up[3]);
int halo_vr_free_hand(short local_player_index, float position[3], float forward[3], float up[3]);
int halo_vr_two_hand(short local_player_index, const float foregrip[3], const float reference[3]);
/* - the fingers of a hand (0 the left, 1 the right), from the controller's trigger,
grip and touch: the thumb, index, middle finger and the last two, each
/* - the fingers of a hand of the model (0 the left, the free hand; 1 the
right, the weapon's), from the controller's trigger, grip and touch: the thumb, index, middle finger and the last two, each
curled 0 (straight) to 1; 0 when the hand is not tracked or vr.fingers
is off, else HALO_VR_FINGERS_CURLED, and HALO_VR_FINGERS_TOUCH too when
the controller tells where the fingers rest (else a finger off the
@@ -156,13 +166,14 @@ int halo_vr_melee(void);
0 with none): the game scales melee damage by the player's run instead,
and in VR a player punches standing (units.c) */
float halo_vr_melee_strength(void);
/* The grenade (units.c): whether the left trigger holds it in the hand; and
/* The grenade (units.c): whether the free hand's trigger holds it in the
hand; and
as it let go, whether the hand threw it: from where (world units), which
way (the game's axes) and how hard (0..1 of the game's throw) */
int halo_vr_grenade_held(short local_player_index);
int halo_vr_grenade_throw(short local_player_index, float origin[3], float direction[3], float *strength);
/* where the held grenade is drawn (render_objects.c): in the left palm, and
at what size */
/* where the held grenade is drawn (first_person_weapons.c): in the free
hand's palm, and at what size */
int halo_vr_grenade_in_hand(short local_player_index, float position[3], float forward[3], float up[3],
float *scale);
/* The scope (render.c): zoomed in by magnification, the camera for the
@@ -193,9 +204,9 @@ void halo_vr_capture_names(void);
void halo_vr_set_scope_raise(float metres);
void halo_vr_capture_scope(float left, float top, float right, float bottom);
/* where the weapon's gun node is as drawn, at the ready (world units;
first_person_weapons.c, each frame): shots, the crosshair and the laser
start there; and the direction its barrel points in the weapon camera's
frame (forward, left, up), which the camera is turned to aim */
first_person_weapons.c, each frame; model space): shots, the crosshair and
the laser start there; and the direction its barrel points in the weapon
camera's frame (forward, left, up), which the camera is turned to aim */
void halo_vr_set_barrel(short local_player_index, const float world[3], const float direction[3]);
/* how far, in world units, the weapon's aim runs before it hits something
(render.c, each frame); the crosshair floats there */
@@ -211,7 +222,8 @@ void halo_vr_capture_crosshair(void);
/* Vehicles (player_control.c, each tick): the seat the player sits in and
its vehicle's heading (yaw, radians). Seated, the body turns with the
vehicle; a driver who steers by facing (HALO_VR_SEAT_STEER) steers with the
right stick, else the right controller aims (HALO_VR_SEAT_AIM). And each
turning stick, else the weapon hand's controller aims (HALO_VR_SEAT_AIM).
And each
frame (render.c) the heading as drawn, between ticks. */
enum
{
@@ -237,6 +249,26 @@ int halo_vr_wheel_held(void);
/* the controllers' layout (HALO_XR_LAYOUT_*: 0 the Quest's, 1 the Steam
Frame's), for what the game tells the player */
int halo_vr_controller_layout(void);
/* the hand that holds the weapon (HALO_XR_HAND_*: 1 the right, 0 the left,
vr.handedness) */
int halo_vr_weapon_hand(void);
/* the graphics preset (vr.graphics; HALO_VR_GRAPHICS_HIGH outside VR): which
effects are drawn (port/linux/game/vr_graphics.c), and with "max" the
models lit for each pixel and larger shadows (d3d8_gl.c) */
enum
{
HALO_VR_GRAPHICS_LOW = 0,
HALO_VR_GRAPHICS_MEDIUM,
HALO_VR_GRAPHICS_HIGH,
HALO_VR_GRAPHICS_MAX,
};
int halo_vr_graphics(void);
/* the VR options: the refresh rates the headset offers (Hz, at most maximum;
0 when it lets none be chosen, as SteamVR), and the one it runs at (0:
unknown; vr.refresh_rate asks for one); and vr.resolution_scale as the app
started (it takes a restart) */
int halo_vr_refresh_rates(float *rates, int maximum, float *current);
float halo_vr_started_resolution_scale(void);
/* whether a seated player's view stays in first person (director.c) */
int halo_vr_vehicle_first_person(void);
/* VR test aid (debug.vehicle_spawn): both sticks held in for a moment asks
@@ -266,7 +298,7 @@ coming (each returns 0 otherwise, and for this machine's own players, and
the game does as before):
- where the weapon aims, on foot;
- where its shots start (world units), from the unit's camera;
- whether the left hand holds the grenade;
- whether the free hand holds the grenade;
- the hand's throw, once, as the grenade goes (as halo_vr_grenade_throw);
and this machine's own VR player's throw, to send (units.c). */
int halo_vr_network_aim(long player_index, float vector[3]);
+27 -4
View File
@@ -281,6 +281,10 @@ static long shadow_scale_choose(void)
long resolution = config_integer("display.shadow_resolution");
long scale = 1;
/* (VR's "max" graphics: 512 at least) */
if (halo_vr_graphics() == HALO_VR_GRAPHICS_MAX && resolution < 512)
resolution = 512;
while (scale < SHADOW_MAP_MAXIMUM_SCALE && SHADOW_MAP_SIZE * scale * 2 <= resolution)
scale *= 2;
return scale;
@@ -3170,6 +3174,22 @@ static GLenum blend_equation(DWORD operation)
}
}
/* the model being drawn mirrors: its node matrices are left-handed (the
left hand's first-person weapon in VR, first_person_weapons.c), and its
triangles' winding is turned over (set by rasterizer_xbox.c as it sets them,
after HaloCE-Quest-VR, CC0) */
static int mirrored_skinning;
void d3d8_set_mirrored_skinning(int mirrored)
{
mirrored_skinning = mirrored != 0;
}
int d3d8_mirrored_skinning(void)
{
return mirrored_skinning;
}
static void apply_raster_state(BOOL has_depth)
{
DWORD *rs = D3D__RenderState;
@@ -3305,6 +3325,8 @@ static void apply_raster_state(BOOL has_depth)
#endif
GLenum cull_mode = rs[D3DRS_CULLMODE] == rs[D3DRS_FRONTFACE] ? GL_FRONT : GL_BACK;
if (mirrored_skinning)
front_face = front_face == GL_CW ? GL_CCW : GL_CW;
if (gl_state.front_face != front_face)
{
gl_state.front_face = front_face;
@@ -3416,9 +3438,10 @@ static void draw_flush(void)
#endif
}
/* display.per_pixel_lighting: the model lighting programs' draws are lit for
each pixel (nv2a_psh.c model_lighting), from shaders of their own; read
again when a setting changes */
/* display.per_pixel_lighting (or VR's "max" graphics, vr.graphics): the
model lighting programs' draws are lit for each pixel (nv2a_psh.c
model_lighting), from shaders of their own; read again when a setting
changes */
static BOOL per_pixel_lighting(void)
{
static unsigned long read_at = (unsigned long)-1;
@@ -3427,7 +3450,7 @@ static BOOL per_pixel_lighting(void)
if (read_at != config_changes())
{
read_at = config_changes();
enabled = config_boolean("display.per_pixel_lighting") != 0;
enabled = config_boolean("display.per_pixel_lighting") != 0 || halo_vr_graphics() == HALO_VR_GRAPHICS_MAX;
}
return enabled;
}
+47 -13
View File
@@ -16,6 +16,7 @@ it exists, so that the player's edits and comments stay.
#include <SDL3/SDL.h>
#include <ctype.h>
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
@@ -164,6 +165,13 @@ static const struct config_setting config_settings[] =
{ "vr.refresh_rate", _config_real, "90.0", "HALO_VR_REFRESH_RATE", _environment_value, _platform_android,
"The display refresh rate to ask the headset for, in Hz (72, 90, 120);\n"
"it picks the nearest it has at or below. 0 for the highest." },
{ "vr.graphics", _config_string, "\"high\"", "HALO_VR_GRAPHICS", _environment_value, _platform_android,
"Which of the costlier effects are drawn: \"high\" all of them; \"medium\"\n"
"no object shadows, environment reflections or lens flares; \"low\" nor\n"
"specular light, bump maps, grass, the screen's fog, contrails, weather\n"
"or camouflage's second pass (a client in another's game keeps grass,\n"
"lens flares and fog); \"max\" all of them, the models lit for each\n"
"pixel and shadows at 512x512." },
{ "vr.positional_tracking", _config_boolean, "true", "HALO_VR_POSITIONAL", _environment_value, _platform_android,
"Moving your head moves the view (leaning, ducking); false only turns it.\n"
"The view recentres when play starts or resumes after a cinematic, and\n"
@@ -180,8 +188,19 @@ static const struct config_setting config_settings[] =
"Log the frame rate and where the frame time goes every five seconds\n"
"(adb logcat -s halo)." },
{ "vr.aim_with", _config_string, "\"controller\"", "HALO_VR_AIM_WITH", _environment_value, _platform_android,
"\"controller\": the weapon is in your right hand and aims where it points,\n"
"while you move and look with your head; \"head\": you aim where you look." },
"\"controller\": the weapon is in your hand (vr.handedness) and aims where\n"
"it points, while you move and look with your head; \"head\": you aim\n"
"where you look." },
{ "vr.handedness", _config_string, "\"right\"", "HALO_VR_HANDEDNESS", _environment_value, _platform_android,
"The hand that holds the weapon: \"right\", or \"left\", which mirrors the\n"
"weapon and the arms, throws grenades and grips the foregrip with the\n"
"right hand, and fires with the left trigger." },
{ "vr.mirror_controls", _config_boolean, "true", "HALO_VR_MIRROR_CONTROLS", _environment_value,
_platform_android,
"Left-handed, the sticks and buttons swap sides too: the right stick moves\n"
"and the left one turns, X jumps and A reloads (on the Steam Frame the\n"
"D-pad takes A, B, X and Y as their mirror image); false keeps them as\n"
"right-handed. The menus keep their buttons either way." },
{ "vr.laser", _config_boolean, "false", "HALO_VR_LASER", _environment_value, _platform_android,
"A laser from the weapon to what it aims at (with aim_with = \"controller\")." },
{ "vr.crosshair", _config_boolean, "true", "HALO_VR_CROSSHAIR", _environment_value, _platform_android,
@@ -196,7 +215,7 @@ static const struct config_setting config_settings[] =
{ "vr.weapon_down", _config_real, "0.14", "HALO_VR_WEAPON_DOWN", _environment_value, _platform_android,
"See weapon_forward." },
{ "vr.two_hand_reach", _config_real, "0.2", "HALO_VR_TWO_HAND_REACH", _environment_value, _platform_android,
"How near, in metres, the left hand must be to the weapon's foregrip for\n"
"How near, in metres, the free hand must be to the weapon's foregrip for\n"
"its grip button to take hold of it with both hands." },
{ "vr.body", _config_string, "\"arms\"", "HALO_VR_BODY", _environment_value, _platform_android,
"What of your body is drawn with the weapon: \"arms\", the arms and hands\n"
@@ -212,17 +231,17 @@ static const struct config_setting config_settings[] =
"false keeps the arm's shape as on the weapon, pointed at the shoulder." },
{ "vr.melee_swing_speed", _config_real, "2.0", "HALO_VR_MELEE_SWING", _environment_value, _platform_android,
"Thrusting a hand forward faster than this, in metres per second, is a\n"
"melee attack (the right grip is too); 0 turns it off." },
"melee attack (the weapon hand's grip is too); 0 turns it off." },
{ "vr.grenade_throw_speed", _config_real, "1.5", "HALO_VR_GRENADE_THROW", _environment_value, _platform_android,
"A grenade is held while the left trigger is, and thrown as it lets go:\n"
"along the hand's throw, when the hand moved faster than this (metres per\n"
"second; full strength at 4), else as the game throws it. 0 turns the\n"
"hand's throw off." },
"A grenade is held while the free hand's trigger is, and thrown as it\n"
"lets go: along the hand's throw, when the hand moved faster than this\n"
"(metres per second; full strength at 4), else as the game throws it. 0\n"
"turns the hand's throw off." },
{ "vr.grenade_scale", _config_real, "0.55", "HALO_VR_GRENADE_SCALE", _environment_value, _platform_android,
"The size the grenade held in the left hand is drawn at (1 as in the game)." },
"The size the grenade held in the free hand is drawn at (1 as in the game)." },
{ "vr.grenade_right", _config_real, "0.055", "HALO_VR_GRENADE_RIGHT", _environment_value, _platform_android,
"Where the held grenade is drawn, in metres from the left controller's\n"
"grip: towards the palm (right),", },
"Where the held grenade is drawn, in metres from the free controller's\n"
"grip: towards the palm (the left hand's right),", },
{ "vr.grenade_forward", _config_real, "0.01", "HALO_VR_GRENADE_FORWARD", _environment_value, _platform_android,
"the grip's forward (through the fist, towards the index finger),", },
{ "vr.grenade_down", _config_real, "0.01", "HALO_VR_GRENADE_DOWN", _environment_value, _platform_android,
@@ -554,6 +573,10 @@ static const struct config_setting config_settings[] =
"The headset's layer copies: 1 deferred (no waits for the GL thread or the\n"
"GPU in the middle of the frame), 0 each one restored and released at once,\n"
"-1 as the runtime needs (deferred on SteamVR). Read when the app starts." },
{ "debug.mirror_first_person", _config_boolean, "false", "HALO_MIRROR_FIRST_PERSON", _environment_value,
_platform_android,
"Off the headset (flat), the first-person weapon drawn mirrored, as the\n"
"left hand's is in VR: a test aid for what reads mirrored there. Read once." },
{ "debug.test_input", _config_string, "\"\"", "HALO_TEST_INPUT", _environment_value, _platform_all,
"\"bot:<seed>\" plays controller 1 with a scripted pattern (automated\n"
"network tests); \"look:<seed>\" stands still, only turning and looking\n"
@@ -695,13 +718,24 @@ static char *config_read_file(const char *path, size_t *size)
static int config_write_file(const char *path, const char *text)
{
#ifdef HALO_ANDROID
FILE *file = fopen(path, "wb");
/* written beside it and renamed over it: a file the app may not write
(one pushed by adb belongs to the shell) is replaced all the same, as the
folder is the app's, and a write cut short leaves the old file whole */
char temporary[1100];
FILE *file;
int written;
snprintf(temporary, sizeof(temporary), "%s.tmp", path);
file = fopen(temporary, "wb");
if (!file)
return 0;
written = fwrite(text, 1, strlen(text), file) == strlen(text);
return fclose(file) == 0 && written;
written = fclose(file) == 0 && written;
if (written && rename(temporary, path) == 0)
return 1;
platform_log("settings: cannot replace %s (%s)", path, strerror(errno));
remove(temporary);
return 0;
#else
return SDL_SaveFile(path, text, strlen(text));
#endif
+349 -62
View File
@@ -10,8 +10,9 @@ Frames of reference. The headset reports poses in its LOCAL space: metres,
+x right, +y up, -z forward, the origin and heading where the user last
recentred. The game's player stands in that space's place: its origin is
the game's camera position, and its forward is the "body" yaw kept here.
The right stick turns the body; the head turns on top of it, so the facing
the game uses (halo_vr_aim) is the body's yaw plus the head's.
The right stick (left-handed, mirrored: the left) turns the body; the head
turns on top of it, so the facing the game uses (halo_vr_aim) is the body's
yaw plus the head's.
*/
#include "halo_vr.h"
@@ -187,13 +188,13 @@ static struct
int laser;
float weapon_offset[3]; /* forward, right, down, metres: the weapon model's camera from the hand */
float muzzle_distance;
/* the left hand on the weapon (halo_vr_two_hand) */
/* the free hand on the weapon (halo_vr_two_hand) */
int two_hand_gripping;
int two_hand_latched; /* the grip is held (on the weapon or not) */
int two_hand_valid;
float two_hand_reach; /* metres from the foregrip a closing grip takes the weapon */
/* the grenade in the left hand (grenade_update, vr.grenade_throw_speed):
the left trigger held, the hand's last positions (LOCAL), and the throw
/* the grenade in the free hand (grenade_update, vr.grenade_throw_speed):
its trigger held, the hand's last positions (LOCAL), and the throw
as it let go */
float grenade_throw_speed;
float grenade_scale;
@@ -221,7 +222,7 @@ static struct
unsigned long long melee_aim_until_us;
int melee_grip_down;
float melee_strength; /* 0..1, the last attack's swing */
unsigned long long melee_jab_start_us; /* the right grip's attack: the weapon jabs */
unsigned long long melee_jab_start_us; /* the weapon hand's grip's attack: the weapon jabs */
/* the laser along the barrel, for the frame it was set in */
unsigned long frame_number;
unsigned long laser_frame;
@@ -245,6 +246,14 @@ static struct
int torso_valid;
unsigned long long torso_last_us;
float head_level_yaw;
/* the hands (vr.handedness): the weapon in the left one, and with
vr.mirror_controls the sticks and face buttons mirrored too */
int left_handed;
int mirror_controls;
/* vr.refresh_rate as last asked for (the VR options change it), and
vr.resolution_scale as the app started with it */
float refresh_rate_wanted;
float resolution_scale;
} vr;
/* d3d8_gl.c */
@@ -299,6 +308,23 @@ static int weapon_hand_tracked(short local_player_index);
static void controller_axes(float forward[3], float up[3], float right[3]);
static void hand_offset(float out[3]);
/* the hand that holds the weapon, the free one (the grenade, the
foregrip), and the one whose stick turns the body and steers */
static int weapon_hand(void)
{
return vr.left_handed ? HALO_XR_HAND_LEFT : HALO_XR_HAND_RIGHT;
}
static int free_hand(void)
{
return vr.left_handed ? HALO_XR_HAND_RIGHT : HALO_XR_HAND_LEFT;
}
static int turn_hand(void)
{
return vr.left_handed && vr.mirror_controls ? HALO_XR_HAND_LEFT : HALO_XR_HAND_RIGHT;
}
static void quaternion_rotate(const float q[4], const float v[3], float out[3])
{
/* out = q v q^-1 */
@@ -476,6 +502,32 @@ static void vr_read_live_settings(void)
vr.body_mode = !strcmp(body, "hands") ? HALO_VR_BODY_HANDS :
!strcmp(body, "off") ? HALO_VR_BODY_OFF : HALO_VR_BODY_ARMS;
}
{
int left_handed = !strcmp(config_string("vr.handedness"), "left");
if (left_handed != vr.left_handed)
{
/* (the hands change places: what the free hand held lets go) */
vr.two_hand_latched = vr.two_hand_gripping = 0;
vr.grenade_held = vr.grenade_thrown = 0;
vr.grenade_sample_count = 0;
vr.barrel_frame = 0;
platform_log("VR: the weapon in the %s hand", left_handed ? "left" : "right");
}
vr.left_handed = left_handed;
vr.mirror_controls = config_boolean("vr.mirror_controls");
}
{
/* (the refresh rate changes at once where the runtime lets it) */
float refresh_rate = (float)config_real("vr.refresh_rate");
if (vr.active && refresh_rate != vr.refresh_rate_wanted)
{
platform_log("VR: refresh rate %.0f Hz asked for", refresh_rate);
host_xr_set_refresh_rate(refresh_rate);
}
vr.refresh_rate_wanted = refresh_rate;
}
}
void halo_vr_initialize(void)
@@ -498,6 +550,7 @@ void halo_vr_initialize(void)
vr.crouch_limit = (float)config_real("vr.crouch_limit");
vr.rise_limit = 0.25f;
vr.log_performance = config_boolean("vr.log_performance");
vr.resolution_scale = (float)config_real("vr.resolution_scale");
vr.aim_with_controller = strcmp(config_string("vr.aim_with"), "head") != 0;
vr.weapon_offset[0] = (float)config_real("vr.weapon_forward");
vr.weapon_offset[1] = (float)config_real("vr.weapon_right");
@@ -561,6 +614,43 @@ int halo_vr_controller_layout(void)
return vr.active ? vr.frame.controller_layout : HALO_XR_LAYOUT_TOUCH;
}
int halo_vr_weapon_hand(void)
{
return weapon_hand();
}
int halo_vr_refresh_rates(float *rates, int maximum, float *current)
{
*current = 0.0f;
return vr.active ? host_xr_refresh_rates(rates, maximum, current) : 0;
}
float halo_vr_started_resolution_scale(void)
{
return vr.resolution_scale;
}
int halo_vr_graphics(void)
{
/* (read as it changes: d3d8_gl.c may ask before vr.c reads the live
settings again) */
static unsigned long read_at = (unsigned long)-1;
static int graphics = HALO_VR_GRAPHICS_HIGH;
if (!vr.active)
return HALO_VR_GRAPHICS_HIGH;
if (read_at != config_changes())
{
const char *name = config_string("vr.graphics");
read_at = config_changes();
graphics = !strcmp(name, "low") ? HALO_VR_GRAPHICS_LOW :
!strcmp(name, "medium") ? HALO_VR_GRAPHICS_MEDIUM :
!strcmp(name, "max") ? HALO_VR_GRAPHICS_MAX : HALO_VR_GRAPHICS_HIGH;
}
return graphics;
}
int halo_vr_eye_size(int *width, int *height)
{
const char *eye_width = getenv("HALO_VR_EYE_WIDTH");
@@ -650,6 +740,14 @@ static void performance_report(int stereo)
vr.report_start_us = now;
if (now - vr.report_start_us < 5000000)
return;
{
/* (the rate the headset runs at now: the VR options change it) */
float rates[1], current = 0.0f;
host_xr_refresh_rates(rates, 0, &current);
if (current > 1.0f)
vr.info.refresh_rate = current;
}
{
float frames = (float)vr.report_frames;
float seconds = (float)(now - vr.report_start_us) * 1e-6f;
@@ -714,15 +812,16 @@ static void look_update(void)
vr.look_valid = 1;
}
/* The grenade in the left hand: while the left trigger is held the game
keeps it in the hand (halo_vr_grenade_held); as the trigger lets go, the
fastest the hand moved in its last moments is the throw (halo_vr_grenade_throw). */
/* The grenade in the free hand (the left one, or left-handed the right):
while its trigger is held the game keeps it in the hand
(halo_vr_grenade_held); as the trigger lets go, the fastest the hand moved
in its last moments is the throw (halo_vr_grenade_throw). */
static void grenade_update(void)
{
const struct halo_xr_hand *hand = &vr.frame.hands[HALO_XR_HAND_LEFT];
const struct halo_xr_hand *hand = &vr.frame.hands[free_hand()];
unsigned long long now = now_us();
int valid = hand->active && (hand->flags & HALO_XR_POSE_VALID);
/* (at a wheel the left trigger brakes: xinput_sdl.c) */
/* (at a wheel the free hand's trigger brakes: xinput_sdl.c) */
int held = valid && vr.last_overlay_mode != HALO_XR_OVERLAY_SCREEN && !vr.wheel_hands &&
hand->trigger > (vr.grenade_held ? 0.2f : 0.3f);
int count = vr.grenade_sample_count;
@@ -796,7 +895,7 @@ static void grenade_update(void)
vr.grenade_strength = 0.25f;
if (vr.grenade_strength > 1.0f)
vr.grenade_strength = 1.0f;
host_xr_haptic(HALO_XR_HAND_LEFT, 0.6f, 0.06f);
host_xr_haptic(free_hand(), 0.6f, 0.06f);
platform_log("VR: grenade thrown at %.1f m/s", best_speed);
}
vr.grenade_sample_count = 0;
@@ -814,8 +913,8 @@ int halo_vr_grenade_in_hand(short local_player_index, float position[3], float f
{
static const float local_forward[3] = { 0.0f, 0.0f, -1.0f };
static const float local_up[3] = { 0.0f, 1.0f, 0.0f };
const struct halo_xr_hand *hand = &vr.frame.hands[HALO_XR_HAND_LEFT];
float held[3], offset[3], direction[3];
const struct halo_xr_hand *hand = &vr.frame.hands[free_hand()];
float held[3], offset[3], direction[3], grip_offset[3];
int axis;
if (!vr.aim_with_controller || local_player_index != 0 || !halo_vr_stereo_frame() || !hand->active ||
@@ -823,13 +922,16 @@ int halo_vr_grenade_in_hand(short local_player_index, float position[3], float f
{
return 0;
}
/* the grip's +x faces out of the left palm; the drawn hand's knuckles
run along the aim's y, and its fingers along the aim's -z
(first_person_weapons.c, vr_left_hand_free) */
/* the grip's +x faces out of the left palm, into the right one; the
drawn hand's knuckles run along the aim's y, and its fingers along the
aim's -z (first_person_weapons.c, vr_left_hand_free) */
memcpy(grip_offset, vr.grenade_offset, sizeof(grip_offset));
if (free_hand() == HALO_XR_HAND_RIGHT)
grip_offset[0] = -grip_offset[0];
{
float knuckles[3], fingers[3];
quaternion_rotate(hand->grip.orientation, vr.grenade_offset, held);
quaternion_rotate(hand->grip.orientation, grip_offset, held);
quaternion_rotate(hand->aim.orientation, local_up, knuckles);
quaternion_rotate(hand->aim.orientation, local_forward, fingers);
for (axis = 0; axis < 3; axis++)
@@ -878,9 +980,10 @@ static void melee_update(void)
vr.hand_last_us = now;
{
/* the right grip's melee attack (xinput_sdl.c) aims the same way */
int grip_down = vr.frame.hands[HALO_XR_HAND_RIGHT].active &&
(vr.frame.hands[HALO_XR_HAND_RIGHT].buttons & HALO_XR_BUTTON_SQUEEZE);
/* the weapon hand's grip's melee attack (xinput_sdl.c) aims the
same way */
int grip_down = vr.frame.hands[weapon_hand()].active &&
(vr.frame.hands[weapon_hand()].buttons & HALO_XR_BUTTON_SQUEEZE);
if (grip_down && !vr.melee_grip_down)
{
@@ -907,7 +1010,7 @@ static void melee_update(void)
if (vr.hand_last_valid[hand] && seconds > 0.0f && seconds < 0.1f && vr.melee_swing_speed > 0.0f &&
!vr.wheel_held[hand] &&
vr.last_overlay_mode != HALO_XR_OVERLAY_SCREEN && now >= vr.melee_ready_us &&
!(hand == HALO_XR_HAND_LEFT && (vr.grenade_held || now - vr.grenade_released_us < 500000)))
!(hand == free_hand() && (vr.grenade_held || now - vr.grenade_released_us < 500000)))
{
float velocity[3], forward_speed;
int axis;
@@ -963,7 +1066,7 @@ static void fingers_update(void)
target[0] = (state->buttons & HALO_XR_BUTTON_THUMB_TOUCH) ? 0.75f : 0.0f;
target[1] = fmaxf(state->trigger, (state->buttons & HALO_XR_BUTTON_INDEX_TOUCH) ? 0.22f : 0.0f);
target[2] = target[3] = state->squeeze;
if (hand == HALO_XR_HAND_LEFT && vr.grenade_held)
if (hand == free_hand() && vr.grenade_held)
{
for (finger = 0; finger < 4; finger++)
target[finger] = 0.8f;
@@ -1076,6 +1179,9 @@ int halo_vr_finger_curls(short local_player_index, int hand, float curls[4])
if (!vr.active || !vr.fingers || local_player_index != 0 || hand < 0 || hand >= HALO_XR_HAND_COUNT)
return 0;
/* (the model's hands: left-handed, its left is the right controller's) */
if (vr.left_handed)
hand = HALO_XR_HAND_COUNT - 1 - hand;
state = &vr.frame.hands[hand];
if (!state->active || !(state->flags & HALO_XR_POSE_VALID))
return 0;
@@ -1095,7 +1201,7 @@ float halo_vr_melee_strength(void)
static void turn_update(void)
{
const struct halo_xr_hand *hand = &vr.frame.hands[HALO_XR_HAND_RIGHT];
const struct halo_xr_hand *hand = &vr.frame.hands[turn_hand()];
unsigned long long now = SDL_GetTicks();
float seconds = vr.last_frame_ms ? (float)(now - vr.last_frame_ms) * 0.001f : 0.0f;
float x = hand->active ? hand->thumbstick[0] : 0.0f;
@@ -1144,7 +1250,7 @@ grips near it takes hold of it, and the hands turn it about its column: both
by the line between them, one about the wheel's middle. Where it is, the
driver's hands as drawn hold it (halo_vr_set_wheel); its column runs from
there back towards the driver, tipped up WHEEL_COLUMN_TILT. Held, its turn
steers (halo_vr_aim); let go, the right stick does. */
steers (halo_vr_aim); let go, the turning stick does. */
#define WHEEL_REACH 0.35f /* metres from its middle */
#define WHEEL_COLUMN_TILT (45.0f * PI / 180.0f) /* from the horizontal */
@@ -1404,8 +1510,9 @@ float halo_vr_gunner_camera_back(void)
return vr.gunner_camera_back / METRES_PER_WORLD_UNIT;
}
/* seated at a gun or a window, where the right controller aims it: at a
gun's handles (vr.turret_handles), the barrel rises as the hand tips down */
/* seated at a gun or a window, where the weapon hand's controller aims it:
at a gun's handles (vr.turret_handles), the barrel rises as the hand tips
down */
static void seat_aim_direction(float direction[3])
{
float up[3], right[3];
@@ -1416,7 +1523,8 @@ static void seat_aim_direction(float direction[3])
}
/* seated, where the aim runs from (world units) and along: from the eyes,
where the right controller points, or driving, the way the stick steers */
where the weapon hand's controller points, or driving, the way the stick
steers */
static int seat_aim(float start[3], float direction[3])
{
int axis;
@@ -1541,6 +1649,7 @@ void halo_vr_present(unsigned int back_buffer_texture)
submit.wrist_turn = vr.motion_tracker_turn;
submit.wrist_right = vr.motion_tracker_right;
submit.wrist_down = vr.motion_tracker_down;
submit.wrist_hand = free_hand();
d3d8_clear_back_buffer_region(WRIST_REGION_LEFT, WRIST_REGION_TOP, WRIST_REGION_RIGHT, WRIST_REGION_BOTTOM);
}
/* the crosshair, drawn apart (halo_vr_capture_crosshair), to where the
@@ -1831,9 +1940,10 @@ int halo_vr_aim(short local_player_index, float current_yaw, float current_pitch
head_angles(&head_yaw, &head_pitch);
if (vr.seat_mode == HALO_VR_SEAT_STEER)
{
/* driving: the right stick steers off the vehicle's heading, and
aims above or below the horizon (the body turns with the vehicle) */
const struct halo_xr_hand *hand = &vr.frame.hands[HALO_XR_HAND_RIGHT];
/* driving: the right stick (mirrored, the left) steers off the
vehicle's heading, and aims above or below the horizon (the body
turns with the vehicle) */
const struct halo_xr_hand *hand = &vr.frame.hands[turn_hand()];
float stick[2];
unsigned long long now = now_us();
float seconds = vr.steer_last_us ? (float)(now - vr.steer_last_us) * 1e-6f : 0.0f;
@@ -1872,7 +1982,7 @@ int halo_vr_aim(short local_player_index, float current_yaw, float current_pitch
}
else if (vr.seat_mode == HALO_VR_SEAT_AIM && weapon_hand_tracked(local_player_index))
{
/* a gunner or passenger: where the right controller points */
/* a gunner or passenger: where the weapon hand's controller points */
float forward[3];
seat_aim_direction(forward);
@@ -1949,42 +2059,125 @@ static void rotate_between(const float from[3], const float to[3], float v[3])
v[index] = v[index] * cosine + turned[index] * sine + axis[index] * along * (1.0f - cosine);
}
/* ---------- the weapon in the right hand (vr.aim_with = "controller") */
/* ---------- the weapon in the hand (vr.aim_with = "controller"): the right
one, or left-handed (vr.handedness) the left */
static int weapon_hand_tracked(short local_player_index)
{
const struct halo_xr_hand *hand = &vr.frame.hands[HALO_XR_HAND_RIGHT];
const struct halo_xr_hand *hand = &vr.frame.hands[weapon_hand()];
return vr.aim_with_controller && local_player_index == 0 && halo_vr_stereo_frame() &&
hand->active && (hand->flags & HALO_XR_POSE_VALID);
}
/* the weapon's axes in the game's: where the right controller points */
/* Left-handed, the first-person model (first_person_weapons.c) is posed as
the right hand's is, in a mirror image of the room, "model space", and
drawn mirrored back across the same mirror (as HaloCE-Quest-VR mirrors the
whole model across the weapon, CC0): its right hand takes the left
controller, its left hand the right one, its arms the other shoulders. The
mirror is the upright plane through the weapon hand's grip, square to
LOCAL's x: any upright one would do (the model, posed about the vertical
the same, mirrors back the same), and this one leaves the weapon hand
where it is. Right-handed, model space is the room. */
static void model_local_point(float point[3])
{
if (vr.left_handed)
point[0] = 2.0f * vr.frame.hands[weapon_hand()].grip.position[0] - point[0];
}
static void model_local_direction(float direction[3])
{
if (vr.left_handed)
direction[0] = -direction[0];
}
/* the mirror in the game's world: a point on it (world units) and its
normal, LOCAL's x */
static void mirror_plane(float point[3], float normal[3])
{
static const float local_x[3] = { 1.0f, 0.0f, 0.0f };
float offset[3];
int axis;
tracked_offset(vr.frame.hands[weapon_hand()].grip.position, offset);
for (axis = 0; axis < 3; axis++)
point[axis] = vr.game_camera[axis] + offset[axis] / METRES_PER_WORLD_UNIT;
local_to_game(local_x, vr.body_yaw, normal);
}
/* a point or a direction in the game's world, between the room and model
space (either way: the mirror is its own inverse) */
static void mirror_game_point(float point[3])
{
float on[3], normal[3], along;
int axis;
if (!vr.left_handed)
return;
mirror_plane(on, normal);
along = (point[0] - on[0]) * normal[0] + (point[1] - on[1]) * normal[1] + (point[2] - on[2]) * normal[2];
for (axis = 0; axis < 3; axis++)
point[axis] -= 2.0f * along * normal[axis];
}
static void mirror_game_direction(float direction[3])
{
float on[3], normal[3], along;
int axis;
if (!vr.left_handed)
return;
mirror_plane(on, normal);
along = direction[0] * normal[0] + direction[1] * normal[1] + direction[2] * normal[2];
for (axis = 0; axis < 3; axis++)
direction[axis] -= 2.0f * along * normal[axis];
}
int halo_vr_first_person_mirror(short local_player_index, float point[3], float normal[3])
{
if (!vr.left_handed || !weapon_hand_tracked(local_player_index))
return 0;
mirror_plane(point, normal);
return 1;
}
/* The weapon's frames, all in the game's axes:
- the controller's: where it points;
- the model's: the controller's turned so that the first-person model's
barrel, pointed in towards the screen's centre, points where the
controller does (barrel_direction);
- with both hands on it, both turned alike so that the line from the
model's right hand to its left, in the model's frame, runs from the right
controller to the left one.
model's right hand to its left, in the model's frame, runs from the
weapon hand's controller to the free one's.
The weapon aims along the controller's frame (so turned); the model hangs
from the model's frame. */
static void controller_axes(float forward[3], float up[3], float right[3])
from the model's frame. Turned in model space, both; the aim is then
mirrored back. */
static void hand_axes(int hand, int model, float forward[3], float up[3], float right[3])
{
static const float local_forward[3] = { 0.0f, 0.0f, -1.0f };
static const float local_up[3] = { 0.0f, 1.0f, 0.0f };
const float *orientation = vr.frame.hands[HALO_XR_HAND_RIGHT].aim.orientation;
const float *orientation = vr.frame.hands[hand].aim.orientation;
float direction[3];
quaternion_rotate(orientation, local_forward, direction);
if (model)
model_local_direction(direction);
local_to_game(direction, vr.body_yaw, forward);
quaternion_rotate(orientation, local_up, direction);
if (model)
model_local_direction(direction);
local_to_game(direction, vr.body_yaw, up);
/* the game's axes are right-handed with +z up: forward x up is right */
/* the game's axes are right-handed with +z up: forward x up is right
(in model space too: the mirrored controller's frame is a right hand's) */
cross3(forward, up, right);
}
/* where the weapon hand's controller points */
static void controller_axes(float forward[3], float up[3], float right[3])
{
hand_axes(weapon_hand(), 0, forward, up, right);
}
static void model_axes(const float forward[3], const float up[3], const float right[3],
float model_forward[3], float model_up[3], float model_right[3])
{
@@ -2010,11 +2203,11 @@ static void model_axes(const float forward[3], const float up[3], const float ri
}
/* with both hands on the weapon, the turn that brings the model's grips in
line with the hands (from, to); 0 without */
line with the hands (from, to; model space); 0 without */
static int two_hand_turn(const float model_forward[3], const float model_up[3], const float model_right[3],
float from[3], float to[3])
{
float left[3], right_hand[3];
float free_grip[3], free_offset[3], weapon_offset[3];
int axis;
if (!vr.two_hand_gripping || !vr.two_hand_valid)
@@ -2024,10 +2217,12 @@ static int two_hand_turn(const float model_forward[3], const float model_up[3],
from[axis] = model_forward[axis] * vr.two_hand_reference[0] + model_right[axis] * vr.two_hand_reference[1] +
model_up[axis] * vr.two_hand_reference[2];
}
tracked_offset(vr.frame.hands[HALO_XR_HAND_LEFT].grip.position, left);
tracked_offset(vr.frame.hands[HALO_XR_HAND_RIGHT].grip.position, right_hand);
memcpy(free_grip, vr.frame.hands[free_hand()].grip.position, sizeof(free_grip));
model_local_point(free_grip);
tracked_offset(free_grip, free_offset);
tracked_offset(vr.frame.hands[weapon_hand()].grip.position, weapon_offset);
for (axis = 0; axis < 3; axis++)
to[axis] = left[axis] - right_hand[axis];
to[axis] = free_offset[axis] - weapon_offset[axis];
return normalize3(from) > 0.0f && normalize3(to) > 0.0f;
}
@@ -2038,34 +2233,41 @@ static void turn_axes(const float from[3], const float to[3], float forward[3],
cross3(forward, up, right);
}
/* where the weapon aims */
/* where the weapon aims (in the room) */
static void weapon_axes(float forward[3], float up[3], float right[3])
{
float model_forward[3], model_up[3], model_right[3], from[3], to[3];
controller_axes(forward, up, right);
hand_axes(weapon_hand(), 1, forward, up, right);
model_axes(forward, up, right, model_forward, model_up, model_right);
if (two_hand_turn(model_forward, model_up, model_right, from, to))
turn_axes(from, to, forward, up, right);
if (vr.left_handed)
{
mirror_game_direction(forward);
mirror_game_direction(up);
cross3(forward, up, right);
}
}
/* how the weapon's model hangs */
/* how the weapon's model hangs (model space) */
static void weapon_model_axes(float forward[3], float up[3], float right[3])
{
float controller_forward[3], controller_up[3], controller_right[3], from[3], to[3];
controller_axes(controller_forward, controller_up, controller_right);
hand_axes(weapon_hand(), 1, controller_forward, controller_up, controller_right);
model_axes(controller_forward, controller_up, controller_right, forward, up, right);
if (two_hand_turn(forward, up, right, from, to))
turn_axes(from, to, forward, up, right);
}
/* the hand's offset from the game's camera, in world units */
/* the weapon hand's offset from the game's camera, in world units (the
same in model space) */
static void hand_offset(float out[3])
{
int axis;
tracked_offset(vr.frame.hands[HALO_XR_HAND_RIGHT].grip.position, out);
tracked_offset(vr.frame.hands[weapon_hand()].grip.position, out);
for (axis = 0; axis < 3; axis++)
out[axis] /= METRES_PER_WORLD_UNIT;
}
@@ -2087,7 +2289,10 @@ void halo_vr_set_barrel(short local_player_index, const float world[3], const fl
{
if (local_player_index != 0)
return;
/* (posed in model space: the barrel as drawn, in the room; its
direction stays the model's, which model_axes turns) */
memcpy(vr.barrel, world, sizeof(vr.barrel));
mirror_game_point(vr.barrel);
vr.barrel_frame = vr.frame_number;
if (!vr.barrel_direction_valid || memcmp(vr.barrel_direction, direction, sizeof(vr.barrel_direction)))
{
@@ -2152,7 +2357,7 @@ int halo_vr_weapon_camera(short local_player_index, float position[3], float for
weapon_model_axes(forward, up, right);
hand_offset(hand);
{
/* the right grip's melee attack, which the hand does not swing: the
/* the weapon hand's grip's melee attack, which it does not swing: the
weapon jabs forward and back (the game's own animation is held
off, first_person_weapons.c) */
float seconds = vr.melee_jab_start_us ? (float)(now_us() - vr.melee_jab_start_us) * 1e-6f : 1.0f;
@@ -2264,12 +2469,12 @@ int halo_vr_body_frame(short local_player_index, float head[3], float neck[3], f
return 1;
}
int halo_vr_left_hand(short local_player_index, float position[3], float forward[3], float up[3])
int halo_vr_free_hand(short local_player_index, float position[3], float forward[3], float up[3])
{
static const float local_forward[3] = { 0.0f, 0.0f, -1.0f };
static const float local_up[3] = { 0.0f, 1.0f, 0.0f };
const struct halo_xr_hand *hand = &vr.frame.hands[HALO_XR_HAND_LEFT];
float offset[3], direction[3];
const struct halo_xr_hand *hand = &vr.frame.hands[free_hand()];
float grip[3], offset[3], direction[3];
int axis;
if (!vr.aim_with_controller || local_player_index != 0 || !halo_vr_stereo_frame() || !hand->active ||
@@ -2277,25 +2482,30 @@ int halo_vr_left_hand(short local_player_index, float position[3], float forward
{
return 0;
}
tracked_offset(hand->grip.position, offset);
/* (in model space: left-handed, the right controller as a left one) */
memcpy(grip, hand->grip.position, sizeof(grip));
model_local_point(grip);
tracked_offset(grip, offset);
for (axis = 0; axis < 3; axis++)
position[axis] = vr.game_camera[axis] + offset[axis] / METRES_PER_WORLD_UNIT;
quaternion_rotate(hand->aim.orientation, local_forward, direction);
model_local_direction(direction);
local_to_game(direction, vr.body_yaw, forward);
quaternion_rotate(hand->aim.orientation, local_up, direction);
model_local_direction(direction);
local_to_game(direction, vr.body_yaw, up);
return 1;
}
int halo_vr_two_hand(short local_player_index, const float foregrip[3], const float reference[3])
{
const struct halo_xr_hand *hand = &vr.frame.hands[HALO_XR_HAND_LEFT];
const struct halo_xr_hand *hand = &vr.frame.hands[free_hand()];
float position[3], forward[3], up[3];
int squeezed = hand->squeeze > (vr.two_hand_latched ? 0.35f : 0.6f);
memcpy(vr.two_hand_reference, reference, sizeof(vr.two_hand_reference));
vr.two_hand_valid = 1;
if (!squeezed || !halo_vr_left_hand(local_player_index, position, forward, up))
if (!squeezed || !halo_vr_free_hand(local_player_index, position, forward, up))
{
vr.two_hand_latched = vr.two_hand_gripping = 0;
return 0;
@@ -2310,7 +2520,7 @@ int halo_vr_two_hand(short local_player_index, const float foregrip[3], const fl
vr.two_hand_latched = 1;
vr.two_hand_gripping = distance < vr.two_hand_reach;
if (vr.two_hand_gripping)
host_xr_haptic(HALO_XR_HAND_LEFT, 0.4f, 0.04f);
host_xr_haptic(free_hand(), 0.4f, 0.04f);
}
return vr.two_hand_gripping;
}
@@ -2338,8 +2548,11 @@ void halo_vr_set_laser(short local_player_index, const float start[3], const flo
{
if (local_player_index != 0)
return;
/* (from model space) */
memcpy(vr.laser_start, start, sizeof(vr.laser_start));
memcpy(vr.laser_direction, direction, sizeof(vr.laser_direction));
mirror_game_point(vr.laser_start);
mirror_game_direction(vr.laser_direction);
vr.laser_frame = vr.frame_number;
}
@@ -2694,7 +2907,7 @@ void halo_vr_set_scope_raise(float metres)
int halo_vr_scope(short local_player_index, float magnification, float position[3], float forward[3], float up[3],
float *vertical_field_of_view)
{
const struct halo_xr_hand *hand = &vr.frame.hands[HALO_XR_HAND_RIGHT];
const struct halo_xr_hand *hand = &vr.frame.hands[weapon_hand()];
float right[3], game_offset[3], local_forward[3], local_up[3], local_right[3], back[3];
float eye_distance = 0.0f;
int axis;
@@ -2774,6 +2987,65 @@ void halo_vr_capture_crosshair(void)
d3d8_clear_back_buffer(0.0f, 0.0f, 0.0f, 0.0f);
}
/* Left-handed, in play, the controllers as the gamepad's sides: the weapon
hand's trigger and grip are the right side's (fire, melee), the free hand's
the left side's (the grenade, both hands); with vr.mirror_controls the
sticks, their clicks, the bumpers and the face buttons change sides too,
the Quest's X and Y for A and B (after HaloCE-Quest-VR, CC0). The Steam
Frame has A, B, X and Y on the right controller only, a D-pad on the left:
the D-pad becomes them, as their mirror image (down A, left B, right X, up
Y), and they the D-pad. The menus keep the controllers as they are (A
accepts and B goes back, as the screens show). */
static void controllers_mirrored(struct halo_xr_hand hands[HALO_XR_HAND_COUNT])
{
struct halo_xr_hand *left = &hands[HALO_XR_HAND_LEFT];
struct halo_xr_hand *right = &hands[HALO_XR_HAND_RIGHT];
int left_buttons = left->buttons, right_buttons = right->buttons;
int swapped = HALO_XR_BUTTON_TRIGGER | HALO_XR_BUTTON_SQUEEZE;
int frame = vr.frame.controller_layout == HALO_XR_LAYOUT_FRAME;
float value;
int axis;
value = left->trigger;
left->trigger = right->trigger;
right->trigger = value;
value = left->squeeze;
left->squeeze = right->squeeze;
right->squeeze = value;
if (vr.mirror_controls)
{
for (axis = 0; axis < 2; axis++)
{
value = left->thumbstick[axis];
left->thumbstick[axis] = right->thumbstick[axis];
right->thumbstick[axis] = value;
}
swapped |= HALO_XR_BUTTON_THUMBSTICK | HALO_XR_BUTTON_BUMPER;
if (!frame)
swapped |= HALO_XR_BUTTON_A | HALO_XR_BUTTON_B;
}
left->buttons = (left_buttons & ~swapped) | (right_buttons & swapped);
right->buttons = (right_buttons & ~swapped) | (left_buttons & swapped);
if (vr.mirror_controls && frame)
{
const int face = HALO_XR_BUTTON_A | HALO_XR_BUTTON_B;
const int dpad = HALO_XR_BUTTON_DPAD_UP | HALO_XR_BUTTON_DPAD_DOWN | HALO_XR_BUTTON_DPAD_LEFT |
HALO_XR_BUTTON_DPAD_RIGHT;
/* (the right one's X and Y come as the left's A and B: host_xr.c) */
left->buttons &= ~(face | dpad);
right->buttons &= ~face;
right->buttons |= ((left_buttons & HALO_XR_BUTTON_DPAD_DOWN) ? HALO_XR_BUTTON_A : 0) |
((left_buttons & HALO_XR_BUTTON_DPAD_LEFT) ? HALO_XR_BUTTON_B : 0);
left->buttons |= ((left_buttons & HALO_XR_BUTTON_DPAD_RIGHT) ? HALO_XR_BUTTON_A : 0) |
((left_buttons & HALO_XR_BUTTON_DPAD_UP) ? HALO_XR_BUTTON_B : 0) |
((right_buttons & HALO_XR_BUTTON_A) ? HALO_XR_BUTTON_DPAD_DOWN : 0) |
((right_buttons & HALO_XR_BUTTON_B) ? HALO_XR_BUTTON_DPAD_LEFT : 0) |
((left_buttons & HALO_XR_BUTTON_A) ? HALO_XR_BUTTON_DPAD_RIGHT : 0) |
((left_buttons & HALO_XR_BUTTON_B) ? HALO_XR_BUTTON_DPAD_UP : 0);
}
}
/* the controllers, for the gamepad the game reads (xinput_sdl.c) */
int halo_vr_controllers(struct halo_xr_hand hands[HALO_XR_HAND_COUNT], int *menus)
{
@@ -2781,12 +3053,22 @@ int halo_vr_controllers(struct halo_xr_hand hands[HALO_XR_HAND_COUNT], int *menu
return 0;
memcpy(hands, vr.frame.hands, sizeof(vr.frame.hands));
*menus = vr.last_overlay_mode == HALO_XR_OVERLAY_SCREEN;
if (vr.left_handed && !*menus)
controllers_mirrored(hands);
return 1;
}
#else
int halo_vr_controller_layout(void) { return 0; }
int halo_vr_weapon_hand(void) { return 1; }
int halo_vr_graphics(void) { return HALO_VR_GRAPHICS_HIGH; }
int halo_vr_refresh_rates(float *rates, int maximum, float *current)
{
(void)rates; (void)maximum; *current = 0.0f;
return 0;
}
float halo_vr_started_resolution_scale(void) { return 1.0f; }
int halo_vr_active(void) { return 0; }
unsigned long long halo_vr_timing_start(void) { return 0; }
unsigned long halo_vr_frame_serial(void) { return 0; }
@@ -2887,11 +3169,16 @@ int halo_vr_body_frame(short local_player_index, float head[3], float neck[3], f
(void)local_player_index; (void)head; (void)neck; (void)forward;
return 0;
}
int halo_vr_left_hand(short local_player_index, float position[3], float forward[3], float up[3])
int halo_vr_free_hand(short local_player_index, float position[3], float forward[3], float up[3])
{
(void)local_player_index; (void)position; (void)forward; (void)up;
return 0;
}
int halo_vr_first_person_mirror(short local_player_index, float point[3], float normal[3])
{
(void)local_player_index; (void)point; (void)normal;
return 0;
}
int halo_vr_two_hand(short local_player_index, const float foregrip[3], const float reference[3])
{
(void)local_player_index; (void)foregrip; (void)reference;
+15 -4
View File
@@ -851,6 +851,14 @@ Holding a Warthog's wheel (vr.c), the right trigger is the throttle and the
left one the brake (backwards, once stopped): the left stick pushed up or
down as far, unless it is pushed further.
Left-handed (vr.handedness), vr.c hands the controllers over with the sides
swapped where the hands' jobs are (halo_vr_controllers): the left trigger
fires and the left grip strikes, the right ones hold and throw the grenade
and grip the foregrip; and with vr.mirror_controls the sticks, bumpers and
face buttons too (the right stick moves, X jumps, A reloads; on the Steam
Frame the left D-pad takes A, B, X and Y). Here "right" and "left" are the
sides so handed over.
In the menus the buttons are the Xbox's by position: A accepts, B goes back. */
#include "guest_host.h"
@@ -1038,12 +1046,15 @@ DWORD WINAPI XInputSetState(HANDLE device, PXINPUT_FEEDBACK feedback)
if (port < 0)
return ERROR_DEVICE_NOT_CONNECTED;
#ifdef HALO_ANDROID
/* VR: the heavy (left) motor in the left hand, the light one in the
right, as the game refreshes them every frame */
/* VR: the heavy (left) motor in the free hand, the light one in the
weapon's (left-handed, the other way round), as the game refreshes them
every frame */
if (port == 0 && halo_vr_active())
{
host_xr_haptic(HALO_XR_HAND_LEFT, feedback->Rumble.wLeftMotorSpeed / 65535.0f, 0.1f);
host_xr_haptic(HALO_XR_HAND_RIGHT, feedback->Rumble.wRightMotorSpeed / 65535.0f, 0.1f);
int weapon = halo_vr_weapon_hand();
host_xr_haptic(HALO_XR_HAND_COUNT - 1 - weapon, feedback->Rumble.wLeftMotorSpeed / 65535.0f, 0.1f);
host_xr_haptic(weapon, feedback->Rumble.wRightMotorSpeed / 65535.0f, 0.1f);
}
#endif
count = sdl_gamepads(gamepads);
+10
View File
@@ -118,6 +118,10 @@ void cheats_dispose_from_old_map(
/* network_game_globals.c's */
boolean network_game_distributed_client(void);
#ifdef HALO_ANDROID
/* port/linux/game/vr_graphics.c */
boolean vr_graphics_reduces(boolean const *game_switch);
#endif
/* bipeds.c's, player_control.c's */
extern boolean rider_ejection;
extern boolean player_autoaim_flag;
@@ -155,6 +159,12 @@ static boolean cheats_network_client_rasterizer_enforce(
environment_part <= &rasterizer_debug_options.draw_environment_fog_screen;
environment_part++)
{
#ifdef HALO_ANDROID
/* (VR: a part the graphics preset keeps off, as it may in another's
game: shadows, specular light, reflections; vr_graphics.c) */
if (vr_graphics_reduces(environment_part))
continue;
#endif
if (!*environment_part)
changed = TRUE;
*environment_part = TRUE;
+162 -15
View File
@@ -488,10 +488,11 @@ static boolean first_person_weapon_vr_pose_kept(
first_person_weapon_vr_pose_weapon[local_player_index]==first_person_weapon_get(local_player_index)->weapon_index;
}
/* VR: the grenade the player holds (the left trigger, units.c) hangs from
the body, which the first-person view leaves out, and with it the grenade:
drawn instead in the left hand, as it is this frame, with the hands (which
are drawn over the world, and would hide it wherever they overlap) */
/* VR: the grenade the player holds (the free hand's trigger, units.c)
hangs from the body, which the first-person view leaves out, and with it
the grenade: drawn instead in the free hand, as it is this frame, with the
hands (which are drawn over the world, and would hide it wherever they
overlap; in the room, not mirrored) */
static void first_person_weapon_draw_held_grenade(
long unit_index,
struct render_lighting *lighting,
@@ -1217,17 +1218,132 @@ static void first_person_weapon_set_state(
#ifdef HALO_ANDROID
/* ---------- VR arms
The first-person skeleton hangs from the camera at the right controller
(halo_vr_weapon_camera), so the weapon and the right hand lie where they
should; its arms, though, reach up to shoulders that float with the weapon.
Here each arm's upper arm and forearm are turned (two-bone inverse
kinematics, port/linux/game/vr_arms.c) to run from the player's shoulders,
below the neck and square to the torso, to its wrist, the controller's roll
shared along the forearm. The left wrist, unless the hand holds the
weapon's foregrip, goes to the left controller, its fingers with it. */
The first-person skeleton hangs from the camera at the weapon hand's
controller (halo_vr_weapon_camera), so the weapon and the right hand lie
where they should; its arms, though, reach up to shoulders that float with
the weapon. Here each arm's upper arm and forearm are turned (two-bone
inverse kinematics, port/linux/game/vr_arms.c) to run from the player's
shoulders, below the neck and square to the torso, to its wrist, the
controller's roll shared along the forearm. The left wrist, unless the hand
holds the weapon's foregrip, goes to the free controller, its fingers with
it.
Left-handed (vr.handedness) all this is done in model space (halo_vr.h): a
mirror image of the room, where the left controller holds the weapon as a
right hand would; the body is mirrored into it, and the posed skeleton
mirrored back (vr_mirror_pose), so that the weapon lies in the left hand,
the model's left arm reaches to the right controller. */
#define VR_METRES_PER_WORLD_UNIT 3.048f
/* a point or a vector across the mirror (a point on it, its normal) */
static void vr_mirror_point(
float const on[3],
float const normal[3],
float point[3])
{
float along = (point[0] - on[0]) * normal[0] + (point[1] - on[1]) * normal[1] + (point[2] - on[2]) * normal[2];
point[0] -= 2.f * along * normal[0];
point[1] -= 2.f * along * normal[1];
point[2] -= 2.f * along * normal[2];
}
static void vr_mirror_vector(
float const normal[3],
float vector[3])
{
float along = vector[0] * normal[0] + vector[1] * normal[1] + vector[2] * normal[2];
vector[0] -= 2.f * along * normal[0];
vector[1] -= 2.f * along * normal[1];
vector[2] -= 2.f * along * normal[2];
}
/* the posed skeleton across a mirror: every node mirrored, its axes too
(a left-handed frame: rasterizer_xbox.c turns its triangles' winding over).
Numeric displays drawn so, the assault rifle's ammo counter and compass,
are read the right way round by rasterizer_xbox_transparent_geometry.c. */
static void vr_mirror_nodes(
float const on[3],
float const normal[3],
real_matrix4x3 *node_matrices,
short node_count)
{
short node_index;
for (node_index = 0; node_index < node_count; node_index++)
{
real_matrix4x3 *node = &node_matrices[node_index];
real_vector3d *axes[3];
float vector[3];
short axis;
vector[0] = node->position.x;
vector[1] = node->position.y;
vector[2] = node->position.z;
vr_mirror_point(on, normal, vector);
node->position.x = vector[0];
node->position.y = vector[1];
node->position.z = vector[2];
axes[0] = &node->forward;
axes[1] = &node->left;
axes[2] = &node->up;
for (axis = 0; axis < 3; axis++)
{
vector[0] = axes[axis]->i;
vector[1] = axes[axis]->j;
vector[2] = axes[axis]->k;
vr_mirror_vector(normal, vector);
axes[axis]->i = vector[0];
axes[axis]->j = vector[1];
axes[axis]->k = vector[2];
}
}
}
/* the posed skeleton out of model space (left-handed) */
static void vr_mirror_pose(
short local_player_index,
real_matrix4x3 *node_matrices,
short node_count)
{
float on[3], normal[3];
if (halo_vr_first_person_mirror(local_player_index, on, normal))
vr_mirror_nodes(on, normal, node_matrices, node_count);
}
/* debug.mirror_first_person (a test aid, flat): the first-person weapon
mirrored across the camera's own forward and up, as the left hand's is in
VR; its numeric displays can so be checked off the headset */
int config_boolean(char const *name);
static void debug_mirror_first_person(
struct render_camera const *camera,
real_matrix4x3 *node_matrices,
short node_count)
{
static int wanted = -1;
real_vector3d left;
float on[3], normal[3];
if (wanted < 0)
wanted = config_boolean("debug.mirror_first_person") ? 1 : 0;
if (!wanted)
return;
cross_product3d(&camera->up, &camera->forward, &left);
if (normalize3d(&left) == 0.0f)
return;
on[0] = camera->position.x;
on[1] = camera->position.y;
on[2] = camera->position.z;
normal[0] = left.i;
normal[1] = left.j;
normal[2] = left.k;
vr_mirror_nodes(on, normal, node_matrices, node_count);
}
struct vr_arm_nodes
{
long graph_index;
@@ -1470,6 +1586,16 @@ static void vr_laser_follows_barrel(
{
return;
}
{
/* (the laser at the ready is the room's: into model space) */
float on[3], normal[3];
if (halo_vr_first_person_mirror(local_player_index, on, normal))
{
vr_mirror_point(on, normal, laser_start);
vr_mirror_vector(normal, laser_direction);
}
}
matrix4x3_from_point_and_vectors(&camera_matrix, &weapon_camera->position, &weapon_camera->forward,
&weapon_camera->up);
matrix4x3_multiply(&camera_matrix, &vr_arm_nodes.idle_pose[vr_arm_nodes.gun], &ready_gun);
@@ -1656,6 +1782,18 @@ static void first_person_weapon_vr_arms(
{
return;
}
{
/* (the body is the room's: into model space, where the shoulders
change sides) */
float on[3], normal[3];
if (halo_vr_first_person_mirror(local_player_index, on, normal))
{
vr_mirror_point(on, normal, head);
vr_mirror_point(on, normal, neck);
vr_mirror_vector(normal, body_forward);
}
}
/* (the shoulders hang from the neck, which the head turns about) */
eye.x = neck[0];
eye.y = neck[1];
@@ -1705,7 +1843,7 @@ static void first_person_weapon_vr_arms(
return;
if (!gripping && vr_arm_nodes.wrist[0] != NONE)
{
if (halo_vr_left_hand(local_player_index, hand_position, hand_forward, hand_up))
if (halo_vr_free_hand(local_player_index, hand_position, hand_forward, hand_up))
{
/* (rigid: the hand and its arm carried to the controller now;
bent, the arm is solved to it first, below, and the hand turned
@@ -1834,8 +1972,8 @@ static void first_person_weapon_build_node_matrices(
struct first_person_weapon *first_person_weapon= first_person_weapon_get(local_player_index);
struct render_camera const *camera= &render.camera;
#ifdef HALO_ANDROID
/* VR: posed from the right controller, so the weapon lies in the hand
(port/linux/src/vr.c) */
/* VR: posed from the weapon hand's controller, so the weapon lies in the
hand (port/linux/src/vr.c) */
struct render_camera weapon_camera;
float weapon_position[3], weapon_forward[3], weapon_up[3];
@@ -2202,8 +2340,17 @@ static void first_person_weapon_build_node_matrices(
(short)animation_graph->nodes.count,
camera,
first_person_weapon->state);
/* (left-handed: out of model space; what the frame takes from
the pose after, markers, effects, is then the room's) */
vr_mirror_pose(local_player_index, first_person_weapon->node_matrices,
(short)MIN(animation_graph->nodes.count, MAXIMUM_NODES_PER_ANIMATION));
halo_vr_timing_end(HALO_VR_TIMING_ARMS, timing);
}
else
{
debug_mirror_first_person(camera, first_person_weapon->node_matrices,
(short)MIN(animation_graph->nodes.count, MAXIMUM_NODES_PER_ANIMATION));
}
#endif
}
+441 -104
View File
@@ -6656,19 +6656,26 @@ enum
_vr_option_smooth_speed,
_vr_option_vignette,
_vr_option_wheel,
_vr_option_handedness,
_vr_option_mirror_controls,
_vr_option_laser,
_vr_option_crosshair,
_vr_option_motion_tracker,
_vr_option_body,
_vr_option_fingers,
_vr_option_graphics,
_vr_option_refresh_rate,
_vr_option_resolution,
_vr_option_controls,
_vr_option_quit,
NUMBER_OF_VR_OPTIONS,
/* (twelve rows between the title and the footer, in the box) */
/* (twelve rows a page between the title and the footer, in the box) */
VR_OPTIONS_TOP = 94,
VR_OPTIONS_ROW_HEIGHT = 22,
VR_OPTIONS_FOOTER = 362,
VR_OPTIONS_PER_PAGE = 12,
NUMBER_OF_VR_OPTION_PAGES = 2,
_vr_controls_on_foot = 0,
_vr_controls_vehicles,
@@ -6686,6 +6693,67 @@ static struct
boolean quit_armed;
} ui_vr_options_globals;
/* the panel's pages (its tabs), their rows in order (NONE past the last) */
static char const *const vr_option_page_names[NUMBER_OF_VR_OPTION_PAGES] = { "PLAY", "MORE" };
static short const vr_option_pages[NUMBER_OF_VR_OPTION_PAGES][VR_OPTIONS_PER_PAGE] =
{
{ _vr_option_turning, _vr_option_snap_angle, _vr_option_smooth_speed, _vr_option_vignette, _vr_option_wheel,
_vr_option_handedness, _vr_option_mirror_controls, _vr_option_laser, _vr_option_crosshair,
_vr_option_motion_tracker, _vr_option_body, _vr_option_fingers },
{ _vr_option_graphics, _vr_option_refresh_rate, _vr_option_resolution, _vr_option_controls, _vr_option_quit,
NONE, NONE, NONE, NONE, NONE, NONE, NONE },
};
/* the page a row is on, and its place there */
static short ui_vr_options_page_of(
short option,
short *index)
{
short page, row;
for (page = 0; page < NUMBER_OF_VR_OPTION_PAGES; page++)
{
for (row = 0; row < VR_OPTIONS_PER_PAGE; row++)
{
if (vr_option_pages[page][row] == option)
{
if (index)
*index = row;
return page;
}
}
}
if (index)
*index = 0;
return 0;
}
static short ui_vr_options_page_rows(
short page)
{
short rows = 0;
while (rows < VR_OPTIONS_PER_PAGE && vr_option_pages[page][rows] != NONE)
rows++;
return rows;
}
/* the settings' hands: the weapon in the left one, and the sticks and
buttons mirrored with it (vr.c) */
static boolean ui_vr_left_handed(
void)
{
char const *handedness = config_string("vr.handedness");
return handedness && strcmp(handedness, "left") == 0;
}
static boolean ui_vr_controls_mirrored(
void)
{
return ui_vr_left_handed() && config_boolean("vr.mirror_controls");
}
void platform_request_quit(void);
static real const vr_snap_angles[] = { 30.0f, 45.0f, 60.0f, 90.0f };
@@ -6695,6 +6763,61 @@ static char const *const vr_vignette_names[] = { "Off", "Light", "Medium", "Stro
/* vr.body's values, and as the panel shows them */
static char const *const vr_bodies[] = { "arms", "hands", "off" };
static char const *const vr_body_names[] = { "Arms and hands", "Hands only", "Weapon only" };
/* vr.graphics's (port/linux/game/vr_graphics.c), and vr.resolution_scale's
(read as the app starts) */
static char const *const vr_graphics_presets[] = { "low", "medium", "high", "max" };
static char const *const vr_graphics_names[] = { "Low", "Medium", "High", "Max" };
static real const vr_resolution_scales[] = { 0.7f, 0.8f, 0.9f, 1.0f, 1.1f, 1.2f };
static short ui_vr_options_graphics(
void)
{
char const *graphics = config_string("vr.graphics");
short index;
for (index = 0; index < (short)NUMBEROF(vr_graphics_presets); index++)
{
if (graphics && strcmp(graphics, vr_graphics_presets[index]) == 0)
return index;
}
return 2;
}
/* the refresh rates the headset offers, in order, and which of them
vr.refresh_rate chooses (the highest at or below it; 0 asks for the
highest); 0 rates where it lets none be chosen (SteamVR: SteamOS's) */
static short ui_vr_options_refresh_rates(
real rates[16],
short *chosen,
real *current)
{
float offered[16];
float now = 0.0f;
short count = (short)halo_vr_refresh_rates(offered, 16, &now);
real wanted = (real)config_real("vr.refresh_rate");
short index;
*current = now;
*chosen = 0;
for (index = 0; index < count; index++)
{
short place = index;
/* (in order, lowest first) */
while (place > 0 && rates[place - 1] > offered[index])
{
rates[place] = rates[place - 1];
place--;
}
rates[place] = offered[index];
}
for (index = 0; index < count; index++)
{
if (wanted <= 0.0f || rates[index] <= wanted + 0.5f)
*chosen = index;
}
return count;
}
static short ui_vr_options_body(
void)
@@ -6769,6 +6892,10 @@ static void ui_vr_options_change(
ui_vr_options_step("vr.comfort_vignette", vr_vignettes, NUMBEROF(vr_vignettes), change);
break;
case _vr_option_wheel: config_write_boolean("vr.vehicle_wheel", !config_boolean("vr.vehicle_wheel")); break;
case _vr_option_handedness: config_write("vr.handedness", ui_vr_left_handed() ? "right" : "left"); break;
case _vr_option_mirror_controls:
config_write_boolean("vr.mirror_controls", !config_boolean("vr.mirror_controls"));
break;
case _vr_option_laser: config_write_boolean("vr.laser", !config_boolean("vr.laser")); break;
case _vr_option_crosshair: config_write_boolean("vr.crosshair", !config_boolean("vr.crosshair")); break;
case _vr_option_motion_tracker:
@@ -6779,6 +6906,28 @@ static void ui_vr_options_change(
(short)NUMBEROF(vr_bodies)]);
break;
case _vr_option_fingers: config_write_boolean("vr.fingers", !config_boolean("vr.fingers")); break;
case _vr_option_graphics:
config_write("vr.graphics", vr_graphics_presets[(ui_vr_options_graphics() + change +
(short)NUMBEROF(vr_graphics_presets)) % (short)NUMBEROF(vr_graphics_presets)]);
break;
case _vr_option_refresh_rate:
{
real rates[16], current;
short chosen;
short count = ui_vr_options_refresh_rates(rates, &chosen, &current);
if (count > 0)
{
char text[16];
snprintf(text, sizeof(text), "%g", rates[(chosen + change + count) % count]);
config_write("vr.refresh_rate", text);
}
break;
}
case _vr_option_resolution:
ui_vr_options_step("vr.resolution_scale", vr_resolution_scales, NUMBEROF(vr_resolution_scales), change);
break;
case _vr_option_controls:
ui_vr_options_globals.controls = TRUE;
ui_vr_options_globals.page = _vr_controls_on_foot;
@@ -6825,7 +6974,7 @@ static boolean ui_vr_options_take_event(
{
ui_vr_options_globals.open = TRUE;
ui_vr_options_globals.controls = FALSE;
ui_vr_options_globals.selection = 0;
ui_vr_options_globals.selection = vr_option_pages[0][0];
ui_play_audio_feedback_sound(_ui_audio_feedback_forward);
return TRUE;
}
@@ -6883,7 +7032,23 @@ static boolean ui_vr_options_take_event(
}
else if (move)
{
ui_vr_options_globals.selection = (short)PIN(ui_vr_options_globals.selection + move, 0, NUMBER_OF_VR_OPTIONS - 1);
/* (past a page's last row or first, onto the next page or back) */
short row;
short page = ui_vr_options_page_of(ui_vr_options_globals.selection, &row);
row = (short)(row + move);
if (row < 0 && page > 0)
{
page--;
row = (short)(ui_vr_options_page_rows(page) - 1);
}
else if (row >= ui_vr_options_page_rows(page) && page < NUMBER_OF_VR_OPTION_PAGES - 1)
{
page++;
row = 0;
}
row = (short)PIN(row, 0, ui_vr_options_page_rows(page) - 1);
ui_vr_options_globals.selection = vr_option_pages[page][row];
ui_vr_options_globals.quit_armed = FALSE;
ui_play_audio_feedback_sound(_ui_audio_feedback_cursor);
}
@@ -6918,7 +7083,7 @@ static boolean ui_vr_options_take_pointer(
{
ui_vr_options_globals.open = TRUE;
ui_vr_options_globals.controls = FALSE;
ui_vr_options_globals.selection = 0;
ui_vr_options_globals.selection = vr_option_pages[0][0];
ui_play_audio_feedback_sound(_ui_audio_feedback_forward);
return TRUE;
}
@@ -6945,21 +7110,38 @@ static boolean ui_vr_options_take_pointer(
}
return TRUE;
}
if (x >= 118 && x < 522 && y >= VR_OPTIONS_TOP - 4 &&
y < VR_OPTIONS_TOP - 4 + NUMBER_OF_VR_OPTIONS * VR_OPTIONS_ROW_HEIGHT)
{
short row = (short)((y - (VR_OPTIONS_TOP - 4)) / VR_OPTIONS_ROW_HEIGHT);
short page = ui_vr_options_page_of(ui_vr_options_globals.selection, NULL);
if (row != ui_vr_options_globals.selection)
ui_vr_options_globals.quit_armed = FALSE;
ui_vr_options_globals.selection = row;
if (pointer->left_clicks)
ui_vr_options_change(1);
}
else if (pointer->left_clicks && x >= 118 && x < 522 && y >= VR_OPTIONS_FOOTER + 4 && y < VR_OPTIONS_FOOTER + 30)
{
ui_vr_options_close();
ui_play_audio_feedback_sound(_ui_audio_feedback_back);
if (pointer->left_clicks && y >= 68 && y < 88 && x >= 330 && x < 514)
{
/* (a tab: its page) */
short tab = (short)PIN((x - 330) / 92, 0, NUMBER_OF_VR_OPTION_PAGES - 1);
if (tab != page)
{
ui_vr_options_globals.selection = vr_option_pages[tab][0];
ui_vr_options_globals.quit_armed = FALSE;
ui_play_audio_feedback_sound(_ui_audio_feedback_cursor);
}
}
else if (x >= 118 && x < 522 && y >= VR_OPTIONS_TOP - 4 &&
y < VR_OPTIONS_TOP - 4 + ui_vr_options_page_rows(page) * VR_OPTIONS_ROW_HEIGHT)
{
short option = vr_option_pages[page][(y - (VR_OPTIONS_TOP - 4)) / VR_OPTIONS_ROW_HEIGHT];
if (option != ui_vr_options_globals.selection)
ui_vr_options_globals.quit_armed = FALSE;
ui_vr_options_globals.selection = option;
if (pointer->left_clicks)
ui_vr_options_change(1);
}
else if (pointer->left_clicks && x >= 118 && x < 522 && y >= VR_OPTIONS_FOOTER + 4 &&
y < VR_OPTIONS_FOOTER + 30)
{
ui_vr_options_close();
ui_play_audio_feedback_sound(_ui_audio_feedback_back);
}
}
return TRUE;
}
@@ -6987,6 +7169,56 @@ static void ui_vr_controls_note(
ui_join_code_draw_text(44, 596, y, text, FALSE, 0, &color);
}
/* a column of the controls page: its lines, what is pressed and what it
does ("" for a line that goes on the one above) */
enum
{
VR_CONTROLS_COLUMN_LINES = 12,
};
struct ui_vr_controls_column
{
short count;
char const *controls[VR_CONTROLS_COLUMN_LINES];
char const *actions[VR_CONTROLS_COLUMN_LINES];
};
static void ui_vr_controls_add(
struct ui_vr_controls_column *column,
char const *control,
char const *action)
{
if (column->count < VR_CONTROLS_COLUMN_LINES)
{
column->controls[column->count] = control;
column->actions[column->count] = action;
column->count++;
}
}
static void ui_vr_controls_column_render(
short x,
short y,
struct ui_vr_controls_column const *column)
{
short line;
for (line = 0; line < column->count; line++)
{
if (line > 0)
y = (short)(y + (column->controls[line][0] ? 22 : 18));
ui_vr_controls_line(x, y, column->controls[line], column->actions[line]);
}
}
/* The page of what the controllers' buttons do, as the hands are set
(vr.handedness, vr.mirror_controls: vr.c's halo_vr_controllers): the
weapon hand's trigger fires and its grip strikes; the free hand's throws
grenades and grips the foregrip; the move and turn sticks, and the face
buttons (on the Quest's right controller A and B jump and light, on its
left X and Y act and switch weapons; on the Steam Frame all four on the
right, its left D-pad taking them mirrored) change sides with the mirrored
controls. The menus keep their buttons. */
static void ui_vr_controls_render(
void)
{
@@ -6994,11 +7226,25 @@ static void ui_vr_controls_render(
real_argb_color title_color = { 1.0f, 0.55f, 0.75f, 1.0f };
real_argb_color tab_color = { 1.0f, 0.6f, 0.6f, 0.6f };
real_argb_color selected_color = { 1.0f, 1.0f, 1.0f, 1.0f };
struct ui_vr_controls_column columns[2];
boolean frame = halo_vr_controller_layout() == 1;
boolean left_handed = ui_vr_left_handed();
boolean mirrored = ui_vr_controls_mirrored();
/* the columns (0 the left controller, 1 the right) of the weapon hand,
the free hand, the turning stick and the jump button */
short gun = left_handed ? 0 : 1;
short free_column = (short)(1 - gun);
short turn = mirrored ? 0 : 1;
short move = (short)(1 - turn);
char const *wrist_note = left_handed ?
"Motion tracker: turn the back of your right wrist towards you." :
"Motion tracker: turn the back of your left wrist towards you.";
short tab;
short left = 44;
short right = 328;
short y = 112;
csmemset(columns, 0, sizeof(columns));
ui_join_code_draw_quad(24, 40, 616, 440, 0xFF050A18);
ui_join_code_draw_quad(24, 40, 616, 42, 0xFF3A6EA5);
ui_join_code_draw_quad(24, 438, 616, 440, 0xFF3A6EA5);
@@ -7014,111 +7260,134 @@ static void ui_vr_controls_render(
ui_join_code_draw_text(left, (short)(left + 270), 86, "LEFT CONTROLLER", FALSE, 0, &title_color);
ui_join_code_draw_text(right, (short)(right + 270), 86, "RIGHT CONTROLLER", FALSE, 0, &title_color);
ui_join_code_draw_quad(320, 86, 321, 300, 0xFF3A6EA5);
if (halo_vr_controller_layout() == 1)
if (frame)
{
/* the Steam Frame's controllers: A, B, X, Y and a menu button on the
right one, a D-pad and a View button on the left one */
right one, a D-pad and a View button on the left one; mirrored, the
D-pad does what A, B, X and Y do (down, left, right, up) */
char const *jump = mirrored ? "D-pad down" : "A";
char const *light = mirrored ? "D-pad left" : "B";
char const *act = mirrored ? "D-pad right" : "X";
char const *weapon = mirrored ? "D-pad up" : "Y";
short buttons = mirrored ? 0 : 1;
switch (ui_vr_options_globals.page)
{
case _vr_controls_on_foot:
ui_vr_controls_line(left, y, "Stick", "Move; click: crouch");
ui_vr_controls_line(left, y + 22, "Trigger", "Grenade: hold it,");
ui_vr_controls_line(left, y + 40, "", "let go as you throw");
ui_vr_controls_line(left, y + 62, "Grip", "Weapon in both hands");
ui_vr_controls_line(left, y + 84, "Bumper", "Switch grenades");
ui_vr_controls_line(left, y + 106, "View", "Scores");
ui_vr_controls_line(left, y + 128, "D-pad", "In the menus");
ui_vr_controls_line(right, y, "Stick", "Turn; click: zoom");
ui_vr_controls_line(right, y + 22, "Trigger", "Fire");
ui_vr_controls_line(right, y + 44, "Grip", "Melee (or punch)");
ui_vr_controls_line(right, y + 66, "A", "Jump");
ui_vr_controls_line(right, y + 88, "B", "Light; held: grenades");
ui_vr_controls_line(right, y + 110, "X", "Action, reload");
ui_vr_controls_line(right, y + 132, "Y", "Switch weapon");
ui_vr_controls_line(right, y + 154, "Menu", "Pause");
ui_vr_controls_note(320, "Motion tracker: turn the back of your left wrist towards you.");
ui_vr_controls_add(&columns[move], "Stick", "Move; click: crouch");
ui_vr_controls_add(&columns[turn], "Stick", "Turn; click: zoom");
ui_vr_controls_add(&columns[gun], "Trigger", "Fire");
ui_vr_controls_add(&columns[free_column], "Trigger", "Grenade: hold, throw");
ui_vr_controls_add(&columns[gun], "Grip", "Melee (or punch)");
ui_vr_controls_add(&columns[free_column], "Grip", "Weapon in both hands");
ui_vr_controls_add(&columns[buttons], jump, "Jump");
ui_vr_controls_add(&columns[buttons], light, "Light; held: grenades");
ui_vr_controls_add(&columns[buttons], act, "Action, reload");
ui_vr_controls_add(&columns[buttons], weapon, "Switch weapon");
ui_vr_controls_add(&columns[mirrored ? 0 : 1], "Bumper", "Flashlight");
ui_vr_controls_add(&columns[mirrored ? 1 : 0], "Bumper", "Switch grenades");
ui_vr_controls_add(&columns[0], "View", "Scores");
if (mirrored)
ui_vr_controls_add(&columns[1], "A, B, X, Y", "As the D-pad");
else
ui_vr_controls_add(&columns[0], "D-pad", "In the menus");
ui_vr_controls_add(&columns[1], "Menu", "Pause");
ui_vr_controls_note(320, wrist_note);
ui_vr_controls_note(340, "Scope: zoom, and look through the disc above the weapon.");
ui_vr_controls_note(360, "Right bumper: the flashlight too.");
break;
case _vr_controls_vehicles:
ui_vr_controls_line(left, y, "Stick", "Drive");
ui_vr_controls_line(left, y + 22, "Trigger", "Second weapon");
ui_vr_controls_line(left, y + 40, "", "(Banshee, tank)");
ui_vr_controls_line(right, y, "Stick", "Steer; up and down:");
ui_vr_controls_line(right, y + 18, "", "climb, dive");
ui_vr_controls_line(right, y + 40, "Trigger", "Fire");
ui_vr_controls_line(right, y + 62, "X", "Get in, get out");
ui_vr_controls_line(right, y + 84, "B", "Flashlight");
ui_vr_controls_note(300, "Warthog: grip the wheel with one hand or both and turn it.");
ui_vr_controls_note(320, "Holding it, the right trigger accelerates, the left one brakes");
ui_vr_controls_note(338, "and reverses. Let go, and the right stick steers.");
ui_vr_controls_note(360, "At a gun or as a passenger: aim with the right controller.");
ui_vr_controls_add(&columns[move], "Stick", "Drive");
ui_vr_controls_add(&columns[turn], "Stick", "Steer; up and down:");
ui_vr_controls_add(&columns[turn], "", "climb, dive");
ui_vr_controls_add(&columns[gun], "Trigger", "Fire");
ui_vr_controls_add(&columns[free_column], "Trigger", "Second weapon");
ui_vr_controls_add(&columns[free_column], "", "(Banshee, tank)");
ui_vr_controls_add(&columns[buttons], act, "Get in, get out");
ui_vr_controls_add(&columns[buttons], light, "Flashlight");
break;
default:
ui_vr_controls_line(left, y, "Stick", "Choose");
ui_vr_controls_line(left, y + 22, "D-pad", "Choose");
ui_vr_controls_line(left, y + 44, "Trigger", "Click where it points");
ui_vr_controls_line(right, y, "Stick", "Choose, scroll");
ui_vr_controls_line(right, y + 22, "A", "Accept");
ui_vr_controls_line(right, y + 44, "B", "Back");
ui_vr_controls_line(right, y + 66, "X, Y", "As the screen shows");
ui_vr_controls_line(right, y + 88, "Trigger", "Click where it points");
ui_vr_controls_note(300, "Point at the menus with either controller; its trigger clicks.");
ui_vr_controls_note(320, "On the keyboard, BACK and ENTER under it can be clicked too.");
ui_vr_controls_note(340, "Y on the main menu or the pause menu: these VR options.");
ui_vr_controls_add(&columns[0], "Stick", "Choose");
ui_vr_controls_add(&columns[0], "D-pad", "Choose");
ui_vr_controls_add(&columns[0], "Trigger", "Click where it points");
ui_vr_controls_add(&columns[1], "Stick", "Choose, scroll");
ui_vr_controls_add(&columns[1], "A", "Accept");
ui_vr_controls_add(&columns[1], "B", "Back");
ui_vr_controls_add(&columns[1], "X, Y", "As the screen shows");
ui_vr_controls_add(&columns[1], "Trigger", "Click where it points");
break;
}
ui_join_code_draw_text(44, 596, 412, "%b-button Back Left, right: the other pages", TRUE, 0, &tab_color);
return;
}
else
{
/* the Quest's: A and B on the right controller, X, Y and the menu
button on the left; mirrored, X and Y do what A and B do, and the
other way round */
short jumps = mirrored ? 0 : 1;
short acts = (short)(1 - jumps);
switch (ui_vr_options_globals.page)
{
case _vr_controls_on_foot:
ui_vr_controls_add(&columns[move], "Stick", "Move");
ui_vr_controls_add(&columns[move], "Stick click", "Crouch");
ui_vr_controls_add(&columns[turn], "Stick", "Turn");
ui_vr_controls_add(&columns[turn], "Stick click", "Zoom");
ui_vr_controls_add(&columns[gun], "Trigger", "Fire");
ui_vr_controls_add(&columns[gun], "Grip", "Melee (or punch");
ui_vr_controls_add(&columns[gun], "", "forward)");
ui_vr_controls_add(&columns[free_column], "Trigger", "Grenade: hold it,");
ui_vr_controls_add(&columns[free_column], "", "let go as you throw");
ui_vr_controls_add(&columns[free_column], "Grip", "Weapon in both hands");
ui_vr_controls_add(&columns[jumps], jumps ? "A" : "X", "Jump");
ui_vr_controls_add(&columns[jumps], jumps ? "B" : "Y", "Flashlight");
ui_vr_controls_add(&columns[jumps], jumps ? "B held" : "Y held", "Switch grenades");
ui_vr_controls_add(&columns[acts], acts ? "A" : "X", "Action, reload");
ui_vr_controls_add(&columns[acts], acts ? "B" : "Y", "Switch weapon");
ui_vr_controls_add(&columns[0], "Menu", "Pause");
ui_vr_controls_note(320, wrist_note);
ui_vr_controls_note(340, "Scope: zoom, and look through the disc above the weapon.");
ui_vr_controls_note(360, "Hold the Meta button to recentre the view.");
break;
case _vr_controls_vehicles:
ui_vr_controls_add(&columns[move], "Stick", "Drive");
ui_vr_controls_add(&columns[turn], "Stick", "Steer; up and down:");
ui_vr_controls_add(&columns[turn], "", "climb, dive");
ui_vr_controls_add(&columns[gun], "Trigger", "Fire");
ui_vr_controls_add(&columns[free_column], "Trigger", "Second weapon");
ui_vr_controls_add(&columns[free_column], "", "(Banshee, tank)");
ui_vr_controls_add(&columns[acts], acts ? "A" : "X", "Get in, get out");
ui_vr_controls_add(&columns[jumps], jumps ? "B" : "Y", "Flashlight");
break;
default:
ui_vr_controls_add(&columns[0], "Stick", "Choose");
ui_vr_controls_add(&columns[0], "X, Y", "As the screen shows");
ui_vr_controls_add(&columns[0], "Trigger", "Click where it points");
ui_vr_controls_add(&columns[1], "Stick", "Choose, scroll");
ui_vr_controls_add(&columns[1], "A", "Accept");
ui_vr_controls_add(&columns[1], "B", "Back");
ui_vr_controls_add(&columns[1], "Trigger", "Click where it points");
break;
}
}
ui_vr_controls_column_render(left, y, &columns[0]);
ui_vr_controls_column_render(right, y, &columns[1]);
switch (ui_vr_options_globals.page)
{
case _vr_controls_on_foot:
ui_vr_controls_line(left, y, "Stick", "Move");
ui_vr_controls_line(left, y + 22, "Stick click", "Crouch");
ui_vr_controls_line(left, y + 44, "Trigger", "Grenade: hold it,");
ui_vr_controls_line(left, y + 62, "", "let go as you throw");
ui_vr_controls_line(left, y + 84, "Grip", "Weapon in both hands");
ui_vr_controls_line(left, y + 106, "X", "Action, reload");
ui_vr_controls_line(left, y + 128, "Y", "Switch weapon");
ui_vr_controls_line(left, y + 150, "Menu", "Pause");
ui_vr_controls_line(right, y, "Stick", "Turn");
ui_vr_controls_line(right, y + 22, "Stick click", "Zoom");
ui_vr_controls_line(right, y + 44, "Trigger", "Fire");
ui_vr_controls_line(right, y + 66, "Grip", "Melee (or punch");
ui_vr_controls_line(right, y + 84, "", "forward)");
ui_vr_controls_line(right, y + 106, "A", "Jump");
ui_vr_controls_line(right, y + 128, "B", "Flashlight");
ui_vr_controls_line(right, y + 150, "B held", "Switch grenades");
ui_vr_controls_note(320, "Motion tracker: turn the back of your left wrist towards you.");
ui_vr_controls_note(340, "Scope: zoom, and look through the disc above the weapon.");
ui_vr_controls_note(360, "Hold the Meta button to recentre the view.");
break;
case _vr_controls_vehicles:
ui_vr_controls_line(left, y, "Stick", "Drive");
ui_vr_controls_line(left, y + 22, "Trigger", "Second weapon");
ui_vr_controls_line(left, y + 40, "", "(Banshee, tank)");
ui_vr_controls_line(left, y + 62, "X", "Get in, get out");
ui_vr_controls_line(right, y, "Stick", "Steer; up and down:");
ui_vr_controls_line(right, y + 18, "", "climb, dive");
ui_vr_controls_line(right, y + 40, "Trigger", "Fire");
ui_vr_controls_line(right, y + 62, "B", "Flashlight");
ui_vr_controls_note(300, "Warthog: grip the wheel with one hand or both and turn it.");
ui_vr_controls_note(320, "Holding it, the right trigger accelerates, the left one brakes");
ui_vr_controls_note(338, "and reverses. Let go, and the right stick steers.");
ui_vr_controls_note(360, "At a gun or as a passenger: aim with the right controller.");
ui_vr_controls_note(320, left_handed ? "Holding it, the left trigger accelerates, the right one brakes" :
"Holding it, the right trigger accelerates, the left one brakes");
ui_vr_controls_note(338, mirrored ? "and reverses. Let go, and the left stick steers." :
"and reverses. Let go, and the right stick steers.");
ui_vr_controls_note(360, left_handed ? "At a gun or as a passenger: aim with the left controller." :
"At a gun or as a passenger: aim with the right controller.");
break;
default:
ui_vr_controls_line(left, y, "Stick", "Choose");
ui_vr_controls_line(left, y + 22, "X, Y", "As the screen shows");
ui_vr_controls_line(left, y + 44, "Trigger", "Click where it points");
ui_vr_controls_line(right, y, "Stick", "Choose, scroll");
ui_vr_controls_line(right, y + 22, "A", "Accept");
ui_vr_controls_line(right, y + 44, "B", "Back");
ui_vr_controls_line(right, y + 66, "Trigger", "Click where it points");
ui_vr_controls_note(300, "Point at the menus with either controller; its trigger clicks.");
ui_vr_controls_note(320, "On the keyboard, BACK and ENTER under it can be clicked too.");
ui_vr_controls_note(340, "Y on the main menu or the pause menu: these VR options.");
if (left_handed)
ui_vr_controls_note(360, "Left-handed, the menus keep their buttons.");
break;
}
ui_join_code_draw_text(44, 596, 412, "%b-button Back Left, right: the other pages", TRUE, 0, &tab_color);
@@ -7133,6 +7402,8 @@ static void ui_vr_options_render(
real_argb_color hint_color = { 1.0f, 0.85f, 0.85f, 0.85f };
char value[48];
short row;
short page = ui_vr_options_page_of(ui_vr_options_globals.selection, NULL);
short tab;
boolean smooth = config_boolean("vr.smooth_turn") != 0;
if (!ui_vr_options_screen())
@@ -7158,15 +7429,26 @@ static void ui_vr_options_render(
ui_join_code_draw_quad(110, 62, 530, 396, 0xFF050A18);
ui_join_code_draw_quad(110, 62, 530, 64, 0xFF3A6EA5);
ui_join_code_draw_quad(110, 394, 530, 396, 0xFF3A6EA5);
ui_join_code_draw_text(126, 514, 72, "VR OPTIONS", FALSE, 0, &title_color);
for (row = 0; row < NUMBER_OF_VR_OPTIONS; row++)
ui_join_code_draw_text(126, 330, 72, "VR OPTIONS", FALSE, 0, &title_color);
/* (the pages' tabs, beside the title) */
for (tab = 0; tab < NUMBER_OF_VR_OPTION_PAGES; tab++)
{
short x0 = (short)(330 + tab * 92);
if (tab == page)
ui_join_code_draw_quad(x0, 68, (short)(x0 + 88), 88, 0x803A6EA5);
ui_join_code_draw_text(x0, (short)(x0 + 88), 72, vr_option_page_names[tab], FALSE, 2,
tab == page ? &text_color : &dim_color);
}
for (row = 0; row < ui_vr_options_page_rows(page); row++)
{
short y = (short)(VR_OPTIONS_TOP + row * VR_OPTIONS_ROW_HEIGHT);
short option = vr_option_pages[page][row];
char const *label = "";
boolean unused = FALSE;
value[0] = 0;
switch (row)
switch (option)
{
case _vr_option_turning:
label = "Turning";
@@ -7193,6 +7475,15 @@ static void ui_vr_options_render(
label = "Warthog steering wheel";
snprintf(value, sizeof(value), "%s", config_boolean("vr.vehicle_wheel") ? "On" : "Off (stick)");
break;
case _vr_option_handedness:
label = "Weapon hand";
snprintf(value, sizeof(value), "%s", ui_vr_left_handed() ? "Left" : "Right");
break;
case _vr_option_mirror_controls:
label = "Mirrored controls";
snprintf(value, sizeof(value), "%s", config_boolean("vr.mirror_controls") ? "Sticks, buttons" : "Off");
unused = !ui_vr_left_handed();
break;
case _vr_option_laser:
label = "Weapon laser";
snprintf(value, sizeof(value), "%s", config_boolean("vr.laser") ? "On" : "Off");
@@ -7214,6 +7505,38 @@ static void ui_vr_options_render(
snprintf(value, sizeof(value), "%s", config_boolean("vr.fingers") ? "Tracked" : "Off");
unused = ui_vr_options_body() == 2;
break;
case _vr_option_graphics:
label = "Graphics";
snprintf(value, sizeof(value), "%s", vr_graphics_names[ui_vr_options_graphics()]);
break;
case _vr_option_refresh_rate:
{
real rates[16], current;
short chosen;
short count = ui_vr_options_refresh_rates(rates, &chosen, &current);
label = "Refresh rate";
if (count > 0)
snprintf(value, sizeof(value), "%.0f Hz", rates[chosen]);
else if (current > 1.0f)
snprintf(value, sizeof(value), "%.0f Hz (system)", current);
else
snprintf(value, sizeof(value), "System's");
unused = count <= 1;
break;
}
case _vr_option_resolution:
{
real scale = vr_resolution_scales[ui_vr_options_nearest((real)config_real("vr.resolution_scale"),
vr_resolution_scales, NUMBEROF(vr_resolution_scales))];
label = "Resolution";
if (fabs(scale - halo_vr_started_resolution_scale()) > 0.01f)
snprintf(value, sizeof(value), "%.0f%% (restart)", scale * 100.0f);
else
snprintf(value, sizeof(value), "%.0f%%", scale * 100.0f);
break;
}
case _vr_option_controls:
label = "Controller buttons...";
break;
@@ -7222,7 +7545,7 @@ static void ui_vr_options_render(
"Quit Halo? Once more to quit" : "Quit Halo";
break;
}
if (row == ui_vr_options_globals.selection)
if (option == ui_vr_options_globals.selection)
ui_join_code_draw_quad(118, (short)(y - 4), 522, (short)(y + VR_OPTIONS_ROW_HEIGHT - 6), 0x803A6EA5);
ui_join_code_draw_text(128, 330, y, label, FALSE, 0, unused ? &dim_color : &text_color);
if (value[0])
@@ -7233,6 +7556,20 @@ static void ui_vr_options_render(
ui_join_code_draw_text(330, 512, y, shown, FALSE, 1, unused ? &dim_color : &text_color);
}
}
if (page == 1)
{
/* (what the graphics rows do) */
ui_join_code_draw_text(128, 512, 230, "Graphics: Medium and Low leave effects out (shadows,", FALSE, 0,
&dim_color);
ui_join_code_draw_text(128, 512, 248, "reflections, lens flares; grass, weather...) for a steadier", FALSE,
0, &dim_color);
ui_join_code_draw_text(128, 512, 266, "frame; Max lights models for each pixel. The refresh rate", FALSE, 0,
&dim_color);
ui_join_code_draw_text(128, 512, 284, "changes at once where the headset lets it (on the Steam", FALSE, 0,
&dim_color);
ui_join_code_draw_text(128, 512, 302, "Frame, in SteamOS); the resolution after a restart.", FALSE, 0,
&dim_color);
}
ui_join_code_draw_text(126, 514, VR_OPTIONS_FOOTER + 8, "%a-button Change %b-button Done", TRUE, 0, &text_color);
}
+20
View File
@@ -1227,6 +1227,11 @@ void rasterizer_set_model_lighting(
return;
}
#ifdef HALO_ANDROID
/* port/linux/src/d3d8_gl.c */
void d3d8_set_mirrored_skinning(int mirrored);
#endif
void rasterizer_set_model_skinning(
struct render_skinning const *skinning)
{
@@ -1263,6 +1268,21 @@ void rasterizer_set_model_skinning(
constants[2][2] = scale * matrix->up.k;
constants[2][3] = matrix->position.z;
}
#ifdef HALO_ANDROID
/* port: node matrices that mirror (VR, the left hand's first-person
weapon: first_person_weapons.c) turn the triangles' winding over while
they are drawn (after HaloCE-Quest-VR, CC0); _rasterizer_model_end and
rasterizer_transparent_geometry_group_draw end it */
{
real_matrix4x3 const *m = &skinning->node_matrices[0];
real determinant =
m->forward.i * (m->left.j * m->up.k - m->left.k * m->up.j) -
m->forward.j * (m->left.i * m->up.k - m->left.k * m->up.i) +
m->forward.k * (m->left.i * m->up.j - m->left.j * m->up.i);
d3d8_set_mirrored_skinning(determinant < 0.0f);
}
#endif
D3DDevice_SetVertexShaderConstant(
-36,
vsh_constants__nodematrices,
@@ -596,9 +596,18 @@ void _rasterizer_models_end(
return;
}
#ifdef HALO_ANDROID
/* port/linux/src/d3d8_gl.c: the model's mirroring (rasterizer_xbox.c) ends
with it */
void d3d8_set_mirrored_skinning(int mirrored);
#endif
void _rasterizer_model_end(
void)
{
#ifdef HALO_ANDROID
d3d8_set_mirrored_skinning(0);
#endif
if (rasterizer_debug_options.draw_models)
{
match_assert(
@@ -970,9 +970,83 @@ real_vector4d *offset_vector4d(
return result;
}
#ifdef HALO_ANDROID
/* port: a group's draw, its mirroring (rasterizer_set_model_skinning) put
back after it to what it was: a group drawn in the middle of a model's
(not queued) leaves the model's own */
int d3d8_mirrored_skinning(void);
void d3d8_set_mirrored_skinning(int mirrored);
/* port: a numeric display drawn mirrored (rasterizer_set_model_skinning:
the left hand's first-person weapon in VR; the assault rifle's ammo counter
and compass) reads the right way round. Its geometry stays mirrored with the
weapon (its vertices hang from the gun's nodes as well as the display's);
instead each digit's quad shows its bitmap turned over in u
(rasterizer_numeric_mirror_u), and as the quads' order across the display is
turned over too, the quad of the n-th digit from the right shows the n-th
from the left. The digits: as many as the counter's largest value needs,
that value itself wrapping to 0 (the compass's whole turn). FALSE, the
digit untouched, when not mirrored. Only for a first map in the model's own
u and v (2d, not in screen space), which rasterizer_numeric_mirror_u turns. */
static boolean rasterizer_numeric_mirrored_digit(
real value,
short counter_limit,
short frame_count,
short digit_index,
short *bitmap_sequence_index)
{
short counter_value;
short digit_count;
short place;
long power;
if (!d3d8_mirrored_skinning() || frame_count < 2)
return FALSE;
counter_value = PIN(fast_ftol(floor(counter_limit*value + 0.5f)), 0, counter_limit);
digit_count = 1;
for (power = frame_count; power < counter_limit; power *= frame_count)
digit_count++;
place = digit_count - 1 - digit_index;
if (place < 0)
place = digit_index;
while (place-- > 0)
counter_value /= frame_count;
*bitmap_sequence_index = counter_value%frame_count;
return TRUE;
}
/* the first map's u turned over (1-u: each digit's quad spans its bitmap) */
static void rasterizer_numeric_mirror_u(
real u_transform[4])
{
u_transform[0] = -u_transform[0];
u_transform[1] = -u_transform[1];
u_transform[2] = -u_transform[2];
u_transform[3] = 1.0f - u_transform[3];
}
static void rasterizer_transparent_geometry_group_draw_unmirrored(
struct transparent_geometry_group *group,
boolean dirty);
void rasterizer_transparent_geometry_group_draw(
struct transparent_geometry_group *group,
boolean dirty)
{
int mirrored = d3d8_mirrored_skinning();
rasterizer_transparent_geometry_group_draw_unmirrored(group, dirty);
d3d8_set_mirrored_skinning(mirrored);
}
static void rasterizer_transparent_geometry_group_draw_unmirrored(
#else
void rasterizer_transparent_geometry_group_draw(
#endif
struct transparent_geometry_group *group,
boolean dirty)
{
boolean success = TRUE;
boolean draw_active_camouflage_groups2 = FALSE;
@@ -1813,6 +1887,9 @@ void rasterizer_transparent_geometry_group_draw(
short map_index;
short stage_index;
long result;
#ifdef HALO_ANDROID
boolean numeric_mirrored = FALSE;
#endif
for (layer_index = 0;
layer_index < shader_transparent_generic->generic.extra_layers.count;
@@ -1872,6 +1949,18 @@ void rasterizer_transparent_geometry_group_draw(
counter_value /= frame_count;
bitmap_sequence_index = counter_value%frame_count;
#ifdef HALO_ANDROID
numeric_mirrored =
shader_transparent_generic->generic.type==_shader_transparent_generic_type_2d_map &&
!TEST_FLAG(shader_transparent_generic->generic.flags,
_shader_transparent_flag_first_map_is_in_screenspace_bit) &&
rasterizer_numeric_mirrored_digit(
group->animation->values[function_index],
counter_limit,
frame_count,
group->shader_permutation_index,
&bitmap_sequence_index);
#endif
}
if (shader_transparent_generic->generic.maps.count > 0)
@@ -2034,6 +2123,10 @@ void rasterizer_transparent_geometry_group_draw(
}
}
#ifdef HALO_ANDROID
if (numeric_mirrored)
rasterizer_numeric_mirror_u(vsh_constants__texanim[0]);
#endif
result = IDirect3DDevice8_SetVertexShaderConstant(
global_d3d_device,
VSH_CONSTANTS__TEXANIM_OFFSET,
@@ -2300,6 +2393,9 @@ void rasterizer_transparent_geometry_group_draw(
short layer_index;
short map_index;
long result;
#ifdef HALO_ANDROID
boolean numeric_mirrored = FALSE;
#endif
/* BUG (preserved for exact matching): January never advances layer_index, so the
* loop redraws extra layer 0 for as long as the block is non-empty (the bytes push
@@ -2374,6 +2470,18 @@ void rasterizer_transparent_geometry_group_draw(
counter_value /= frame_count;
bitmap_sequence_index = counter_value%frame_count;
#ifdef HALO_ANDROID
numeric_mirrored =
shader_transparent_chicago->chicago.type==_shader_transparent_chicago_type_2d_map &&
!TEST_FLAG(shader_transparent_chicago->chicago.flags,
_shader_transparent_flag_first_map_is_in_screenspace_bit) &&
rasterizer_numeric_mirrored_digit(
group->animation->values[function_index],
counter_limit,
frame_count,
group->shader_permutation_index,
&bitmap_sequence_index);
#endif
}
}
@@ -2548,6 +2656,10 @@ void rasterizer_transparent_geometry_group_draw(
}
}
#ifdef HALO_ANDROID
if (numeric_mirrored)
rasterizer_numeric_mirror_u(vsh_constants__texanim[0]);
#endif
result = IDirect3DDevice8_SetVertexShaderConstant(
global_d3d_device,
VSH_CONSTANTS__TEXANIM_OFFSET,
+8
View File
@@ -92,6 +92,9 @@ symbols in this file:
#include "physics/collisions.h"
#include "units/units.h"
#include "halo_vr.h"
/* port/linux/game/vr_graphics.c */
void vr_graphics_update(void);
#endif
#include "main/main.h"
#include "structures/structures.h"
@@ -948,6 +951,11 @@ void render_frame(
render.frame_index++;
render.time_delta_since_tick_sec = time_delta_since_tick_sec;
#ifdef HALO_ANDROID
/* VR: the graphics preset's effects (port/linux/game/vr_graphics.c) */
if (halo_vr_active())
vr_graphics_update();
#endif
memset(&parameters, 0, sizeof(parameters));
/* continuous between ticks (render_interpolation.c) */
parameters.game_time_sec = render_interpolation_game_time_sec(game_time_get());