parent
35d26ddef9
commit
a93d7f04ae
2 changed files with 158 additions and 2 deletions
|
|
@ -553,12 +553,91 @@ pub const Vector4 = extern struct {
|
|||
pub fn equals(p: Vector4, q: Vector4) i32 {
|
||||
return math.vector4Equals(p, q);
|
||||
}
|
||||
};
|
||||
|
||||
pub const Quaternion = extern struct {
|
||||
x: f32,
|
||||
y: f32,
|
||||
z: f32,
|
||||
w: f32,
|
||||
|
||||
pub fn init(x: f32, y: f32, z: f32, w: f32) Quaternion {
|
||||
return Quaternion{ .x = x, .y = y, .z = z, .w = w };
|
||||
}
|
||||
|
||||
pub fn initVec(vec: @Vector(4, f32)) Quaternion {
|
||||
return Quaternion{ .x = vec[0], .y = vec[1], .z = vec[2], .w = vec[2] };
|
||||
}
|
||||
|
||||
pub fn initVector4(vec: Vector4) Quaternion {
|
||||
return Quaternion{ .x = vec.x, .y = vec.y, .z = vec.z, .w = vec.w };
|
||||
}
|
||||
|
||||
/// Get identity quaternion
|
||||
pub fn identity() Quaternion {
|
||||
return math.quaternionIdentity();
|
||||
}
|
||||
|
||||
/// Add two quaternions
|
||||
pub fn add(self: Quaternion, q: Quaternion) Quaternion {
|
||||
return math.quaternionAdd(self, q);
|
||||
}
|
||||
|
||||
/// Add quaternion and float value
|
||||
pub fn addValue(self: Quaternion, add_: f32) Quaternion {
|
||||
return math.quaternionAddValue(self, add_);
|
||||
}
|
||||
|
||||
/// Subtract two quaternions
|
||||
pub fn subtract(self: Quaternion, q: Quaternion) Quaternion {
|
||||
return math.quaternionSubtract(self, q);
|
||||
}
|
||||
|
||||
/// Subtract quaternion and float value
|
||||
pub fn subtractValue(self: Quaternion, add_: f32) Quaternion {
|
||||
return math.quaternionSubtractValue(self, add_);
|
||||
}
|
||||
|
||||
/// Computes the length of a quaternion
|
||||
pub fn length(self: Quaternion) f32 {
|
||||
return math.quaternionLength(self);
|
||||
}
|
||||
|
||||
/// Scale quaternion by float value
|
||||
pub fn scale(self: Quaternion, scale_: f32) Quaternion {
|
||||
return math.quaternionScale(self, scale_);
|
||||
}
|
||||
|
||||
/// Multiply quaternion by quaternion
|
||||
pub fn multiply(self: Quaternion, q: Quaternion) Quaternion {
|
||||
return math.quaternionMultiply(self, q);
|
||||
}
|
||||
|
||||
/// Divide two quaternions
|
||||
pub fn divide(self: Quaternion, q: Quaternion) Quaternion {
|
||||
return math.quaternionDivide(self, q);
|
||||
}
|
||||
|
||||
/// Normalize quaternion
|
||||
pub fn normalize(self: Quaternion) Quaternion {
|
||||
return math.quaternionNormalize(self);
|
||||
}
|
||||
|
||||
/// Calculate linear interpolation between two quaternions
|
||||
pub fn lerp(self: Quaternion, q: Quaternion, amount: f32) Quaternion {
|
||||
return math.quaternionLerp(self, q, amount);
|
||||
}
|
||||
|
||||
/// Invert provided quaternion
|
||||
pub fn invert(self: Quaternion) Quaternion {
|
||||
return math.quaternionInvert(self);
|
||||
}
|
||||
|
||||
/// Check whether two given quaternions are almost equal
|
||||
pub fn equals(p: Quaternion, q: Quaternion) i32 {
|
||||
return math.quaternionEquals(p, q);
|
||||
}
|
||||
|
||||
/// Calculate slerp-optimized interpolation between two quaternions
|
||||
pub fn nlerp(self: Quaternion, q: Quaternion, amount: f32) Quaternion {
|
||||
return math.quaternionNlerp(self, q, amount);
|
||||
|
|
@ -618,7 +697,6 @@ pub const Vector4 = extern struct {
|
|||
return math.quaternionTransform(self, mat);
|
||||
}
|
||||
};
|
||||
pub const Quaternion = Vector4;
|
||||
|
||||
pub const Matrix = extern struct {
|
||||
m0: f32,
|
||||
|
|
|
|||
|
|
@ -553,12 +553,91 @@ pub const Vector4 = extern struct {
|
|||
pub fn equals(p: Vector4, q: Vector4) i32 {
|
||||
return math.vector4Equals(p, q);
|
||||
}
|
||||
};
|
||||
|
||||
pub const Quaternion = extern struct {
|
||||
x: f32,
|
||||
y: f32,
|
||||
z: f32,
|
||||
w: f32,
|
||||
|
||||
pub fn init(x: f32, y: f32, z: f32, w: f32) Quaternion {
|
||||
return Quaternion{ .x = x, .y = y, .z = z, .w = w };
|
||||
}
|
||||
|
||||
pub fn initVec(vec: @Vector(4, f32)) Quaternion {
|
||||
return Quaternion{ .x = vec[0], .y = vec[1], .z = vec[2], .w = vec[2] };
|
||||
}
|
||||
|
||||
pub fn initVector4(vec: Vector4) Quaternion {
|
||||
return Quaternion{ .x = vec.x, .y = vec.y, .z = vec.z, .w = vec.w };
|
||||
}
|
||||
|
||||
/// Get identity quaternion
|
||||
pub fn identity() Quaternion {
|
||||
return math.quaternionIdentity();
|
||||
}
|
||||
|
||||
/// Add two quaternions
|
||||
pub fn add(self: Quaternion, q: Quaternion) Quaternion {
|
||||
return math.quaternionAdd(self, q);
|
||||
}
|
||||
|
||||
/// Add quaternion and float value
|
||||
pub fn addValue(self: Quaternion, add_: f32) Quaternion {
|
||||
return math.quaternionAddValue(self, add_);
|
||||
}
|
||||
|
||||
/// Subtract two quaternions
|
||||
pub fn subtract(self: Quaternion, q: Quaternion) Quaternion {
|
||||
return math.quaternionSubtract(self, q);
|
||||
}
|
||||
|
||||
/// Subtract quaternion and float value
|
||||
pub fn subtractValue(self: Quaternion, add_: f32) Quaternion {
|
||||
return math.quaternionSubtractValue(self, add_);
|
||||
}
|
||||
|
||||
/// Computes the length of a quaternion
|
||||
pub fn length(self: Quaternion) f32 {
|
||||
return math.quaternionLength(self);
|
||||
}
|
||||
|
||||
/// Scale quaternion by float value
|
||||
pub fn scale(self: Quaternion, scale_: f32) Quaternion {
|
||||
return math.quaternionScale(self, scale_);
|
||||
}
|
||||
|
||||
/// Multiply quaternion by quaternion
|
||||
pub fn multiply(self: Quaternion, q: Quaternion) Quaternion {
|
||||
return math.quaternionMultiply(self, q);
|
||||
}
|
||||
|
||||
/// Divide two quaternions
|
||||
pub fn divide(self: Quaternion, q: Quaternion) Quaternion {
|
||||
return math.quaternionDivide(self, q);
|
||||
}
|
||||
|
||||
/// Normalize quaternion
|
||||
pub fn normalize(self: Quaternion) Quaternion {
|
||||
return math.quaternionNormalize(self);
|
||||
}
|
||||
|
||||
/// Calculate linear interpolation between two quaternions
|
||||
pub fn lerp(self: Quaternion, q: Quaternion, amount: f32) Quaternion {
|
||||
return math.quaternionLerp(self, q, amount);
|
||||
}
|
||||
|
||||
/// Invert provided quaternion
|
||||
pub fn invert(self: Quaternion) Quaternion {
|
||||
return math.quaternionInvert(self);
|
||||
}
|
||||
|
||||
/// Check whether two given quaternions are almost equal
|
||||
pub fn equals(p: Quaternion, q: Quaternion) i32 {
|
||||
return math.quaternionEquals(p, q);
|
||||
}
|
||||
|
||||
/// Calculate slerp-optimized interpolation between two quaternions
|
||||
pub fn nlerp(self: Quaternion, q: Quaternion, amount: f32) Quaternion {
|
||||
return math.quaternionNlerp(self, q, amount);
|
||||
|
|
@ -618,7 +697,6 @@ pub const Vector4 = extern struct {
|
|||
return math.quaternionTransform(self, mat);
|
||||
}
|
||||
};
|
||||
pub const Quaternion = Vector4;
|
||||
|
||||
pub const Matrix = extern struct {
|
||||
m0: f32,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue