-- Leo's gemini proxy

-- Connecting to git.thebackupbox.net:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

repo: hackvr-turbo
action: commit
revision:
path_from:
revision_from: 509fe4a36d555dafe1ad64315ec0fd85ec2c8b8f:
path_to:
revision_to:

git.thebackupbox.net

hackvr-turbo

git://git.thebackupbox.net/hackvr-turbo

commit 509fe4a36d555dafe1ad64315ec0fd85ec2c8b8f
Author: Felix (xq) Queißner <git@mq32.de>
Date:   Sun Jul 5 14:54:21 2020 +0200

    Implements deletegroups, set, makes camera a group, fixes some bugs.

diff --git a/SPEC.md b/SPEC.md

index f659db9410c110436167dbc893368623d83e1a99..

index ..1fbb2a712ad73299b1eac6801eeeefc8fbb3fb74 100644

--- a/SPEC.md
+++ b/SPEC.md
@@ -85,7 +85,16 @@ Tries to let you output the various things that can be set.`
 ### `[groupspec] quit`
 Closes hackvr only if the id that is doing it is the same as yours.`

-### `[groupspec] set`
+### `[groupspec] set [key] [value]`
+
+Sets different properties in the world. Known properties are:
+
+| Property      | Type  | Description         |
+|---------------|-------|---------------------|
+| `global.zoom` | `int` | ???                 |
+| `camera.p.x`  | `int` | Camera X coordinate |
+| `camera.p.y`  | `int` | Camera Y coordinate |
+| `camera.p.z`  | `int` | Camera Z coordinate |

 ### `[groupspec] physics`

diff --git a/examples/square.sh b/examples/square.sh
new file mode 100755
index 0000000000000000000000000000000000000000..3b733c76e64068b9f6e3bcbdd36f4907d3b9c7d9
--- /dev/null
+++ b/examples/square.sh
@@ -0,0 +1,19 @@
+#!/usr/bin/env bash
+printf "%s move 0 0 -10\n" "$USER"
+printf "square addshape 2 4 1 1 0  -1 1 0  -1 -1 0  1 -1 0\n"
+inc=5
+end=180
+while true;do
+  for i in $(seq 1 $inc $end);do
+    printf "square rotate +%d +0 +0\n" "$inc"
+    sleep .01
+  done
+  for i in $(seq 1 $inc $end);do
+    printf "square rotate +0 +%d +0\n" "$inc"
+    sleep .01
+  done
+  for i in $(seq 1 $inc $end);do
+    printf "square rotate +0 +0 +%d\n" "$inc"
+    sleep .01
+  done
+done
diff --git a/lib/hackvr/lib.zig b/lib/hackvr/lib.zig

index 81f97bb5b94200881aaf6afb29fea958c14728cf..

index ..5cbed47359e595849a02652581c6f19defd384ea 100644

--- a/lib/hackvr/lib.zig
+++ b/lib/hackvr/lib.zig
@@ -94,6 +94,23 @@ pub const State = struct {
         return grp;
     }

+    /// Deletes all groups that match `pattern`, returns the numbe of removed groups
+    pub fn deleteGroups(self: *Self, pattern: []const u8) usize {
+        var delete_count: usize = 0;
+        var i: usize = 0;
+        while (i < self.groups.items.len) {
+            if (wildcardEquals(pattern, self.groups.items[i].name)) {
+                var grp = self.groups.swapRemove(i);
+                grp.deinit();
+
+                delete_count += 1;
+            } else {
+                i += 1;
+            }
+        }
+        return delete_count;
+    }
+
     /// Returns an iterator yielding all groups.
     pub fn iterator(self: *Self) GroupIterator {
         return GroupIterator{
@@ -184,6 +201,9 @@ pub fn applyEventToState(state: *State, event: parsing.Event) !void {
                 grp.name = new_name;
             }
         },
+        .delete_group => |cmd| {
+            _ = state.deleteGroups(cmd.groups);
+        },
         else => {
             std.debug.print("Event {} not implemented yet!\n", .{@as(parsing.EventType, event)});
         },
diff --git a/lib/hackvr/parser.zig b/lib/hackvr/parser.zig

index faa72f25290735610965d110e06da48d1938529c..

index ..3338213b4c1720280aa3fe26a26f89c245c308f4 100644

--- a/lib/hackvr/parser.zig
+++ b/lib/hackvr/parser.zig
@@ -73,7 +73,15 @@ pub const Parser = struct {
                 } else if (std.mem.eql(u8, cmd, "quit")) {
                     return Event{ .quit = selector };
                 } else if (std.mem.eql(u8, cmd, "set")) {
-                    return Event{ .set = selector };
+                    if (args.len != 2)
+                        return error.ArgumentMismatch;
+                    return Event{
+                        .set = SetData{
+                            .selector = selector,
+                            .key = args[0],
+                            .value = args[1],
+                        },
+                    };
                 } else if (std.mem.eql(u8, cmd, "physics")) {
                     return Event{ .physics = selector };
                 } else if (std.mem.eql(u8, cmd, "periodic")) {
@@ -441,6 +449,12 @@ pub const PingData = struct {
     ping_target: []const u8,
 };

+pub const SetData = struct {
+    selector: Selector,
+    key: []const u8,
+    value: []const u8,
+};
+
 pub const EventType = @TagType(Event);
 pub const Event = union(enum) {
     delete_group: GroupArgSelector,
@@ -452,7 +466,7 @@ pub const Event = union(enum) {
     status: Selector,
     dump: Selector,
     quit: Selector,
-    set: Selector,
+    set: SetData,
     physics: Selector,
     control: GroupArgSelector,
     add_shape: AddShapeData,
@@ -543,9 +557,11 @@ test "parser: cmd quit" {
 }

 test "parser: cmd set" {
-    const result = (try Parser.init().parseLine("foobar set")) orelse return error.ExpectedEvent;
+    const result = (try Parser.init().parseLine("foobar set key value")) orelse return error.ExpectedEvent;
     std.testing.expect(result == .set);
-    std.testing.expectEqualStrings("foobar", result.set.groups);
+    std.testing.expectEqualStrings("foobar", result.set.selector.groups);
+    std.testing.expectEqualStrings("key", result.set.key);
+    std.testing.expectEqualStrings("value", result.set.value);
 }

 test "parser: cmd physics" {
diff --git a/lib/zlm b/lib/zlm

index 060cf19b21cd4f3325f6263d8c6ca2f45e8c87f5..

index ..39020809a6d0002098df9d3397efc88fd5d0b1fa 160000

--- a/lib/zlm
+++ b/lib/zlm
@@ -1 +1 @@
-Subproject commit 060cf19b21cd4f3325f6263d8c6ca2f45e8c87f5
+Subproject commit 39020809a6d0002098df9d3397efc88fd5d0b1fa
diff --git a/src/main.zig b/src/main.zig

index 6da75acefa807f02220d2f74999c7cf495bf594c..

index ..249de3c2d4994c1a690aaa6389fad4e58733c5d3 100644

--- a/src/main.zig
+++ b/src/main.zig
@@ -63,7 +63,16 @@ const Vertex = extern struct {
     color: zlm.Vec3,
 };

-pub fn main() anyerror!void {
+fn getGroupTransform(group: hackvr.Group) zlm.Mat4 {
+    return zlm.Mat4.batchMul(&[_]zlm.Mat4{
+        zlm.Mat4.createAngleAxis(zlm.Vec3.unitZ, zlm.toRadians(group.rotation.z)),
+        zlm.Mat4.createAngleAxis(zlm.Vec3.unitX, zlm.toRadians(group.rotation.x)),
+        zlm.Mat4.createAngleAxis(zlm.Vec3.unitY, zlm.toRadians(group.rotation.y)),
+        zlm.Mat4.createTranslation(group.translation),
+    });
+}
+
+pub fn main() !void {
     var gpa_backing = std.testing.LeakCountAllocator.init(std.heap.c_allocator);
     defer {
         gpa_backing.validate() catch |err| {};
@@ -240,15 +249,15 @@ pub fn main() anyerror!void {
         std.os.O_NONBLOCK | try std.os.fcntl(std.io.getStdIn().handle, std.os.F_GETFL, 0),
     );

-    const Camera = struct {
-        position: zlm.Vec3,
-        pan: f32,
-        tilt: f32,
-    };
-    var camera = Camera{
-        .position = zlm.Vec3.zero,
-        .pan = 0,
-        .tilt = 0,
+    const user_name = try std.process.getEnvVarOwned(gpa, "USER");
+    defer gpa.free(user_name);
+
+    var camera = try state.getOrCreateGroup(user_name);
+    camera.translation = zlm.Vec3.zero;
+    camera.rotation = zlm.Vec3{
+        .x = 0,
+        .y = zlm.toRadians(-180.0),
+        .z = 0,
     };

     const dt = 1.0 / 60.0;
@@ -294,8 +303,27 @@ pub fn main() anyerror!void {

                         .event => |ev| {
                             slice = ev.rest;
-                            try hackvr.applyEventToState(&state, ev.event);
+                            switch (ev.event) {
+                                .set => |cmd| {
+                                    if (std.mem.eql(u8, cmd.key, "camera.p.x")) {
+                                        camera.translation.x = std.fmt.parseFloat(f32, cmd.value) catch camera.translation.x;
+                                    } else if (std.mem.eql(u8, cmd.key, "camera.p.y")) {
+                                        camera.translation.y = std.fmt.parseFloat(f32, cmd.value) catch camera.translation.y;
+                                    } else if (std.mem.eql(u8, cmd.key, "camera.p.z")) {
+                                        camera.translation.z = std.fmt.parseFloat(f32, cmd.value) catch camera.translation.z;
+                                    } else {
+                                        std.debug.print("unknown key for command set: {} {}\n", .{
+                                            cmd.key,
+                                            cmd.value,
+                                        });
+                                    }
+                                },
+                                else => try hackvr.applyEventToState(&state, ev.event),
+                            }
                             hackvr_dirty = true;
+
+                            //  we need to update the camera pointer as it may have changed
+                            camera = try state.getOrCreateGroup(user_name);
                         },
                     }
                 }
@@ -319,8 +347,8 @@ pub fn main() anyerror!void {
                         const motion = &event.motion;

                         if ((motion.state & 4) != 0) {
-                            camera.pan -= @intToFloat(f32, motion.xrel) / 150.0;
-                            camera.tilt -= @intToFloat(f32, motion.yrel) / 150.0;
+                            camera.rotation.y -= @intToFloat(f32, motion.xrel) / 150.0;
+                            camera.rotation.x -= @intToFloat(f32, motion.yrel) / 150.0;
                         }
                     },
                     else => {
@@ -361,10 +389,10 @@ pub fn main() anyerror!void {
             } else {
                 // Turning
                 if (keys[c.SDL_SCANCODE_RIGHT] != 0) {
-                    camera.pan -= turnspeed * dt;
+                    camera.rotation.y -= turnspeed * dt;
                 }
                 if (keys[c.SDL_SCANCODE_LEFT] != 0) {
-                    camera.pan += turnspeed * dt;
+                    camera.rotation.y += turnspeed * dt;
                 }
             }

@@ -378,19 +406,19 @@ pub fn main() anyerror!void {
             } else {
                 // Tilting
                 if (keys[c.SDL_SCANCODE_PAGEUP] != 0) {
-                    camera.tilt += turnspeed * dt;
+                    camera.rotation.x += turnspeed * dt;
                 }
                 if (keys[c.SDL_SCANCODE_PAGEDOWN] != 0) {
-                    camera.tilt -= turnspeed * dt;
+                    camera.rotation.x -= turnspeed * dt;
                 }
             }

-            const pan_rot = zlm.Mat4.createAngleAxis(zlm.Vec3.unitY, camera.pan);
-            const tilt_rot = zlm.Mat4.createAngleAxis(zlm.Vec3.unitX.scale(-1), camera.tilt);
+            const pan_rot = zlm.Mat4.createAngleAxis(zlm.Vec3.unitY, camera.rotation.x);
+            const tilt_rot = zlm.Mat4.createAngleAxis(zlm.Vec3.unitX.scale(-1), camera.rotation.y);

             move_dir = move_dir.transformDirection(tilt_rot.mul(pan_rot));

-            camera.position = camera.position.add(move_dir.scale(movespeed * dt));
+            camera.translation = camera.translation.add(move_dir.scale(movespeed * dt));
         }

         // Render scene from HackVR dataset
@@ -409,10 +437,8 @@ pub fn main() anyerror!void {
                     .count_tris = undefined,
                     .begin_lines = outline_list.items.len,
                     .count_lines = undefined,
-                    .transform = zlm.Mat4.mul(
-                        zlm.Mat4.createAngleAxis(zlm.Vec3.unitY, zlm.toRadians(group.rotation.y)),
-                        zlm.Mat4.createTranslation(group.translation),
-                    ),
+
+                    .transform = getGroupTransform(group.*),
                 };

                 for (group.shapes.items) |*shape| {
@@ -425,15 +451,15 @@ pub fn main() anyerror!void {
                         while (i < shape.points.len) {
                             try vertex_list.append(Vertex{
                                 .position = shape.points[0],
-                                .color = palette[shape.attributes.color],
+                                .color = palette[shape.attributes.color % 16],
                             });
                             try vertex_list.append(Vertex{
                                 .position = shape.points[i - 1],
-                                .color = palette[shape.attributes.color],
+                                .color = palette[shape.attributes.color % 16],
                             });
                             try vertex_list.append(Vertex{
                                 .position = shape.points[i],
-                                .color = palette[shape.attributes.color],
+                                .color = palette[shape.attributes.color % 16],
                             });

                             i += 1;
@@ -470,11 +496,11 @@ pub fn main() anyerror!void {

         const mat_proj = zlm.Mat4.createPerspective(1.0, 16.0 / 9.0, 0.1, 10000.0);
         const mat_view = zlm.Mat4.createLook(
-            camera.position,
+            camera.translation,
             zlm.Vec3{
-                .x = std.math.sin(camera.pan) * std.math.cos(camera.tilt),
-                .y = std.math.sin(camera.tilt),
-                .z = -std.math.cos(camera.pan) * std.math.cos(camera.tilt),
+                .x = std.math.sin(camera.rotation.y) * std.math.cos(camera.rotation.x),
+                .y = std.math.sin(camera.rotation.x),
+                .z = -std.math.cos(camera.rotation.y) * std.math.cos(camera.rotation.x),
             },
             zlm.Vec3.unitY,
         );
@@ -569,10 +595,7 @@ pub fn main() anyerror!void {
             var group_index: usize = 0;
             var groups = state.iterator();
             while (groups.next()) |group| : (group_index += 1) {
-                const transform = zlm.Mat4.mul(
-                    zlm.Mat4.createAngleAxis(zlm.Vec3.unitY, zlm.toRadians(group.rotation.y)),
-                    zlm.Mat4.createTranslation(group.translation),
-                );
+                const transform = getGroupTransform(group.*);

                 for (group.shapes.items) |*shape, shape_index| {
                     if (shape.points.len < 3) {

-----END OF PAGE-----

-- Response ended

-- Page fetched on Sun Jun 2 19:06:40 2024