Added the basic Rotors Template#2
Open
GildedSeraphim wants to merge 1 commit intoHaraldWik:masterfrom
Open
Conversation
HaraldWik
requested changes
Apr 3, 2026
Owner
HaraldWik
left a comment
There was a problem hiding this comment.
Mainly just some formatting / styling fixes. Otherwise looks great!
| result.yz = -r.yz; | ||
| result.zx = -r.zx; | ||
| return result; | ||
| } |
Owner
There was a problem hiding this comment.
You can do result = .{ } and use aggregate struct initialization.
| result[0] = S_x * r.scalar + S_y * r.xy + S_xyz * r.yz - S_z * r.zx; | ||
| result[1] = S_y * r.scalar - S_x * r.xy + S_z * r.yz + S_xyz * r.zx; | ||
| result[2] = S_z * r.scalar + S_xyz * r.xy - S_y * r.yz + S_x * r.zx; | ||
| return result; |
Owner
There was a problem hiding this comment.
Same here, you can just do
return .{
result[0] = S_x * r.scalar + S_y * r.xy + S_xyz * r.yz - S_z * r.zx;
result[1] = S_y * r.scalar - S_x * r.xy + S_z * r.yz + S_xyz * r.zx;
result[2] = S_z * r.scalar + S_xyz * r.xy - S_y * r.yz + S_x * r.zx;
}| const new_z: @Vector(3, T) = transform(r, @Vector(3, f32){ 0.0, 0.0, 1.0 }); | ||
|
|
||
| const result: Mat4x4(T) = .new(.{ new_x[0], new_x[1], new_x[2], 0.0, new_y[0], new_y[1], new_y[2], 0.0, new_z[0], new_z[1], new_z[2], 0.0, 0.0, 0.0, 0.0, 0.0 }); | ||
| return result; |
Owner
There was a problem hiding this comment.
you can instantly just do
return .new( [...] )|
|
||
| if (dot > 0.99995) { | ||
| return nlerp(from, to, t); | ||
| } |
Owner
There was a problem hiding this comment.
I would do
if (dot > 0.99995) return nlerp(from, to, t);| const to_factor: f32 = std.math.sin((t * theta) / std.math.sin(theta)); | ||
|
|
||
| var result: @This() = undefined; | ||
| result.scalar = from_factor * from.scalar + to_factor * to.scalar; |
Owner
There was a problem hiding this comment.
same here just do
return .{
.scalar = from_factor * from.scalar + to_factor * to.scalar;
.xy = from_factor * from.xy + to_factor * to.xy;
.yz = from_factor * from.yz + to_factor * to.yz;
.zx = from_factor * from.zx + to_factor * to.zx;
};| return result; | ||
| } | ||
|
|
||
| pub fn from_vec_to_rotor(from_dir: @Vector(3, T), to_dir: @Vector(3, T)) @This() { |
Owner
There was a problem hiding this comment.
functions are typicaly camelCase, not snake_case
|
|
||
| fn lerp(a: f32, b: f32, t: f32) f32 { | ||
| return a + t * (b - a); | ||
| } |
Owner
There was a problem hiding this comment.
I believe there is std.math.lerp
| } | ||
|
|
||
| pub fn transform(r: @This(), v: @Vector(3, T)) @Vector(3, T) { | ||
| const S_x: f32 = r.scalar * v[0] + r.xy * v[1] - r.zx * v[2]; |
Owner
There was a problem hiding this comment.
always have variables and constants as snake_case with no upper case letters
| const std = @import("std"); | ||
| const vec = @import("vector.zig"); | ||
| const Mat4x4 = @import("matrix.zig").@"4x4"; | ||
| const Quaternion = @import("quaternion.zig").Hamiltonian; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added rotors, review needed and it might not work idk we'll see where this goes :)