guix-epistemia

Personal Guix channel
Log | Files | Refs

vr.scm (8907B)


      1 (define-module (epistemia packages vr)
      2   #:use-module (guix packages)
      3   #:use-module (guix build-system cmake)
      4   #:use-module (guix build-system gnu)
      5   #:use-module (guix gexp)
      6   #:use-module (guix git-download)
      7   #:use-module ((guix licenses) :prefix license:)
      8   #:use-module (guix utils)
      9   #:use-module (gnu packages algebra)
     10   #:use-module (gnu packages compression)
     11   #:use-module (gnu packages gl)
     12   #:use-module (gnu packages graphics)
     13   #:use-module (gnu packages libusb)
     14   #:use-module (gnu packages maths)
     15   #:use-module (gnu packages sdl))
     16 
     17 (define-public survive
     18   (package
     19     (name "survive")
     20     (version "44b1e2f0cb95e5697bc0b86f58fd8520a813b713")
     21     (source (origin
     22 	      (method git-fetch)
     23 	      (uri (git-reference
     24 		     (url "https://github.com/collabora/libsurvive")
     25 		     (commit version)))
     26 	      (file-name (git-file-name name version))
     27 	      (sha256
     28                (base32
     29                 "1kpp5lxyz10c5sgsgrb0igny9d737byh4w4m626zxngm2nvlqqgv"))
     30 	      (patches (list (plain-file "0001-ootx-Respect-disable-calibrate-when-detecting-lighth.patch" "\
     31 From ec9f580245c6419bb4ef77fe0d4db1dbb4e77b5d Mon Sep 17 00:00:00 2001
     32 From: Vineet Kumar <git@vineetk.net>
     33 Date: Wed, 25 Nov 2026 02:18:56 +0100
     34 Subject: [PATCH] ootx: Respect disable-calibrate when detecting lighthouse
     35  movement
     36 
     37 Signed-off-by: Vineet Kumar <git@vineetk.net>
     38 ---
     39  src/survive_process_gen2.c | 16 ++++++++++++++--
     40  1 file changed, 14 insertions(+), 2 deletions(-)
     41 
     42 diff --git a/src/survive_process_gen2.c b/src/survive_process_gen2.c
     43 index aa2c9da..590275f 100644
     44 --- a/src/survive_process_gen2.c
     45 +++ b/src/survive_process_gen2.c
     46 @@ -48,7 +48,9 @@ static void ootx_packet_clbk_d_gen2(ootx_decoder_context *ct, ootx_packet *packe
     47  	BaseStationData *b = &ctx->bsd[id];
     48  	b->OOTXChecked |= true;
     49  	FLT accel[3] = {v15.accel_dir[0], v15.accel_dir[1], v15.accel_dir[2]};
     50 -	bool upChanged = norm3d(b->accel) != 0.0 && dist3d(b->accel, accel) > 1e-3;
     51 +	bool upChanged = !survive_configi(ctx, \"disable-calibrate\", SC_GET, 0) &&
     52 +	    norm3d(b->accel) != 0.0 &&
     53 +	    dist3d(b->accel, accel) > 1e-3;
     54 
     55  	if (upChanged) {
     56  		SV_VERBOSE(10, \"OOTX up direction changed for %x (%f)\", b->BaseStationID, norm3d(b->accel));
     57 @@ -95,7 +97,16 @@ static void ootx_packet_cblk_d_gen1(ootx_decoder_context *ct, ootx_packet *packe
     58  	BaseStationData *b = &ctx->bsd[id];
     59  	b->OOTXChecked = true;
     60  	FLT accel[3] = {v6.accel_dir_x, v6.accel_dir_y, v6.accel_dir_z};
     61 -	bool upChanged = norm3d(b->accel) != 0.0 && dist3d(b->accel, accel) > 1e-3;
     62 +	bool upChanged =
     63 +	    !survive_configi(ctx, \"disable-calibrate\", SC_GET, 0) &&
     64 +	    norm3d(b->accel) != 0.0 &&
     65 +	    dist3d(b->accel, accel) > 1e-3;
     66 +
     67 +	if (upChanged) {
     68 +		SV_INFO(\"Gen1 OOTX up direction changed for %x: delta=%f\",
     69 +			b->BaseStationID,
     70 +			dist3d(b->accel, accel));
     71 +	}
     72 
     73  	bool doSave = b->BaseStationID != v6.id || b->OOTXSet == false || upChanged || b->mode != v6.mode_current;
     74  	b->sys_unlock_count = v6.sys_unlock_count;
     75 @@ -120,6 +131,7 @@ static void ootx_packet_cblk_d_gen1(ootx_decoder_context *ct, ootx_packet *packe
     76  		b->accel[2] = v6.accel_dir_z;
     77  		b->mode = v6.mode_current;
     78 
     79 +		SV_INFO(\"Resetting Gen1 lighthouse %d position\", id);
     80  		survive_reset_lighthouse_position(ctx, id);
     81 
     82  		SURVIVE_INVOKE_HOOK(ootx_received, ctx, id);
     83 --
     84 2.55.0\n")))))
     85     (build-system cmake-build-system)
     86     (arguments (list #:tests? #f))
     87     (inputs (list zlib-ng
     88 		  libusb
     89 		  freeglut
     90 		  eigen
     91 		  openblas))
     92     (home-page "https://github.com/collabora/libsurvive")
     93     (synopsis "Open Source Lighthouse Tracking System")
     94     (description "\
     95 Libsurvive is a set of tools and libraries that enable 6 dof tracking on lighthouse and vive based systems that is completely open source and can run on any device. It currently supports both SteamVR 1.0 and SteamVR 2.0 generation of devices and should support any tracked object commercially available.
     96 
     97 Since the focus is on tracking; it does not independently run the HMD. For an open souce stack that does that see monado")
     98     (license license:x11)))
     99 
    100 (define-public monado-git
    101   (package
    102     (inherit monado)
    103     (name "monado-git")
    104     (version "2069b76b3a66fb5916e3cedae84d9524c1ebab4a")
    105     (source (origin
    106               (method git-fetch)
    107               (uri (git-reference
    108                     (url "https://gitlab.freedesktop.org/monado/monado")
    109                     (commit version)))
    110               (file-name (git-file-name name version))
    111               (sha256
    112                (base32
    113                 "0q4ipjx779ifza0z6wccvh1b36z29xm5lxlbd1iv00iqlj4na4ws"))
    114 	      (patches (list (plain-file "0001-vive-Default-Bigscreen-Beyond-distortion-aspect-rati.patch" "\
    115 From 8cf925570862f62fdc77d48c6bfc955b9eb28600 Mon Sep 17 00:00:00 2001
    116 From: Vineet Kumar <git@vineetk.net>
    117 Date: Wed, 25 Nov 2026 02:01:15 +0100
    118 Subject: [PATCH 1/2] vive: Default Bigscreen Beyond distortion aspect ratio to
    119  1.0
    120 
    121 Signed-off-by: Vineet Kumar <git@vineetk.net>
    122 ---
    123  src/xrt/auxiliary/vive/vive_config.c | 3 +++
    124  1 file changed, 3 insertions(+)
    125 
    126 diff --git a/src/xrt/auxiliary/vive/vive_config.c b/src/xrt/auxiliary/vive/vive_config.c
    127 index d46ce7cde..38f0a6cca 100644
    128 --- a/src/xrt/auxiliary/vive/vive_config.c
    129 +++ b/src/xrt/auxiliary/vive/vive_config.c
    130 @@ -512,6 +512,9 @@ vive_config_parse(struct vive_config *d, char *json_string, enum u_logging_level
    131  		success = JSON_FLOAT(device_json, \"physical_aspect_x_over_y\", &d->distortion.values[0].aspect_x_over_y);
    132  		if (success) {
    133  			d->distortion.values[1].aspect_x_over_y = d->distortion.values[0].aspect_x_over_y;
    134 +		} else if (d->variant == VIVE_VARIANT_BEYOND) {
    135 +			d->distortion.values[0].aspect_x_over_y = 1.0f;
    136 +			d->distortion.values[1].aspect_x_over_y = 1.0f;
    137  		}
    138  	}
    139 
    140 --
    141 2.55.0\n")
    142 			     (plain-file "0002-vive-Add-support-for-DISTORT_POLY3-lens-distortion.patch" "\
    143 From 3216e6529bdd553a4397b89fa37b48af9723e152 Mon Sep 17 00:00:00 2001
    144 From: Vineet Kumar <git@vineetk.net>
    145 Date: Wed, 25 Nov 2026 02:01:31 +0100
    146 Subject: [PATCH 2/2] vive: Add support for DISTORT_POLY3 lens distortion
    147 
    148 Signed-off-by: Vineet Kumar <git@vineetk.net>
    149 ---
    150  src/xrt/auxiliary/util/u_distortion_mesh.c | 20 +++++++-------------
    151  src/xrt/auxiliary/util/u_distortion_mesh.h |  2 ++
    152  src/xrt/auxiliary/vive/vive_config.c       |  4 ++++
    153  3 files changed, 13 insertions(+), 13 deletions(-)
    154 
    155 diff --git a/src/xrt/auxiliary/util/u_distortion_mesh.c b/src/xrt/auxiliary/util/u_distortion_mesh.c
    156 index 9fab79ead..f37e9f194 100644
    157 --- a/src/xrt/auxiliary/util/u_distortion_mesh.c
    158 +++ b/src/xrt/auxiliary/util/u_distortion_mesh.c
    159 @@ -157,21 +157,15 @@ u_compute_distortion_vive(struct u_vive_values *values, float u, float v, struct
    160  		float k3 = val.coefficients[i][2];
    161  		float k4 = val.coefficients[i][3];
    162 
    163 -		/*
    164 -		 *                     1.0
    165 -		 * d = -------------------------------------- + k4
    166 -		 *      1.0 + r^2 * k1 + r^4 * k2 + r^6 * k3
    167 +		 /*
    168 +		 * DISTORT_POLY3:
    169 +		 * d = 1 + k1*r² + k2*r⁴ + k3*r⁶
    170  		 *
    171 -		 * The variable k4 is the scaled part of DISTORT_DPOLY3_SCALED.
    172 -		 *
    173 -		 * Optimization to reduce the number of multiplications.
    174 -		 *    1.0 + r^2 * k1 + r^4 * k2 + r^6 * k3
    175 -		 *    1.0 + r^2 * ((k1 + r^2 * k2) + r^2 * k3)
    176 +		 * DISTORT_DPOLY3[_SCALED]:
    177 +		 * d = 1 / (1 + k1*r² + k2*r⁴ + k3*r⁶) + k4
    178  		 */
    179 -
    180 -		float top = 1.f;
    181 -		float bottom = 1.f + r2 * (k1 + r2 * (k2 + r2 * k3));
    182 -		float d = (top / bottom) + k4;
    183 +		float polynomial = 1.f + r2 * (k1 + r2 * (k2 + r2 * k3));
    184 +		float d = (val.use_poly3[i]) ? polynomial : ((1.f / polynomial) + k4);
    185 
    186  		struct xrt_vec2 offset = {0.5f, 0.5f};
    187 
    188 diff --git a/src/xrt/auxiliary/util/u_distortion_mesh.h b/src/xrt/auxiliary/util/u_distortion_mesh.h
    189 index 7f704eb3d..24a8df2b0 100644
    190 --- a/src/xrt/auxiliary/util/u_distortion_mesh.h
    191 +++ b/src/xrt/auxiliary/util/u_distortion_mesh.h
    192 @@ -80,6 +80,8 @@ struct u_vive_values
    193 
    194  	//! r/g/b, a/b/c/d
    195  	float coefficients[3][4];
    196 +
    197 +	bool use_poly3[3];
    198  };
    199 
    200  /*!
    201 diff --git a/src/xrt/auxiliary/vive/vive_config.c b/src/xrt/auxiliary/vive/vive_config.c
    202 index 38f0a6cca..17b917c5a 100644
    203 --- a/src/xrt/auxiliary/vive/vive_config.c
    204 +++ b/src/xrt/auxiliary/vive/vive_config.c
    205 @@ -133,6 +133,10 @@ _get_distortion_properties(struct vive_config *d, const cJSON *eye_transform_jso
    206  			continue;
    207  		}
    208 
    209 +		const cJSON *type = u_json_get(distortion, \"type\");
    210 +		d->distortion.values[eye].use_poly3[i] = cJSON_IsString(type)
    211 +		  && strcmp(type->valuestring, \"DISTORT_POLY3\") == 0;
    212 +
    213  		JSON_FLOAT(distortion, \"center_x\", &d->distortion.values[eye].center[i].x);
    214  		JSON_FLOAT(distortion, \"center_y\", &d->distortion.values[eye].center[i].y);
    215 
    216 --
    217 2.55.0\n")))))
    218     (arguments
    219      (substitute-keyword-arguments (package-arguments (@@ (gnu packages machine-learning) ggml))
    220        ((#:configure-flags flags #~'())
    221 	#~(append #$flags (list "-DXRT_BUILD_DRIVER_SURVIVE=ON")))))
    222     (inputs
    223      (modify-inputs (package-inputs monado)
    224        (append sdl2
    225 	       survive)))))