bors[bot] on master
Added to the Mat3 the possibili… Code formatted with Merge #495 495: Mat3 construct… (compare)
bors[bot] on staging
Added to the Mat3 the possibili… Code formatted with Merge #495 495: Mat3 construct… (compare)
bors[bot] on staging.tmp
[ci skip][skip ci][skip netlify] (compare)
bors[bot] on staging.tmp
Added to the Mat3 the possibili… Code formatted with [ci skip][skip ci][skip netlify… (compare)
TexedShape
Hey, I have a question about using quaternions correctly, which I just asked in the the vulkanors/Lobby room...
Can someone tell me if I'm using cgmath correctly for this quaternion? It does rotate the scene, but as it approaches 90180 degrees rotation in either direction, the scene stretches out and warps into garbage, and I don't know why.
let rotation_scalar = (rotation_angle / 2.0 as f32).cos();
let rotation_vec = Vector3::new(
rotation_axis.x * (rotation_angle / 2.0 as f32).sin(),
rotation_axis.y * (rotation_angle / 2.0 as f32).sin(),
rotation_axis.z * (rotation_angle / 2.0 as f32).sin());
let mut rotation_quat = Quaternion::from_sv(rotation_scalar, rotation_vec);
that's the initial quaternion, and then to rotate it when the mouse moves, I'm doing this:
let diff_x = position.0  last_x;
if diff_x > 0.0 {
// println!("turn right");
rotation_quat.v.x += rotation_axis.x * ((rotation_angle + rotation_speed) / 2.0 as f32).sin();
rotation_quat.v.y += rotation_axis.y * ((rotation_angle + rotation_speed) / 2.0 as f32).sin();
rotation_quat.v.z += rotation_axis.z * ((rotation_angle + rotation_speed) / 2.0 as f32).sin();
rotation_quat.s += ((rotation_angle + rotation_speed) / 2.0 as f32).cos()
} else if diff_x < 0.0 {
// println!("turn left");
rotation_quat.v.x += rotation_axis.x * ((rotation_angle  rotation_speed) / 2.0 as f32).sin();
rotation_quat.v.y += rotation_axis.y * ((rotation_angle  rotation_speed) / 2.0 as f32).sin();
rotation_quat.v.z += rotation_axis.z * ((rotation_angle  rotation_speed) / 2.0 as f32).sin();
rotation_quat.s += ((rotation_angle  rotation_speed) / 2.0 as f32).cos()
}
last_x = position.0;
(rotation_speed is some value in radians, like 0.1 or something)
I haven't used quaternions before, but I wrote it according to a formula I found here: http://www.opengltutorial.org/intermediatetutorials/tutorial17quaternions/
my understanding is if you specify the data as a quaternion, it won't suffer problems of euclidean rotations, but then you have to turn the quaternion into a matrix to multiply it with the translation matrix, to apply the rotation
let rot_mat = Matrix4::from(rotation_quat);
to get the final orientation of the scene, I'm multiplying the matrices like this:
proj * view * trans_mat * rot_mat
Display
impl is it can be pretty contextdependent. Sometimes it's better to make a custom wrapper struct (with its domainspecific impl of Display
) that you only use when making other Display
implementations. We could however improve the debug output..?
Hey, I've been running into an issue with cgmath. I simply want to transform a vector and a point using a matrix, but I am getting this error.
error[E0284]: type annotations required: cannot resolve `<_ as cgmath::EuclideanSpace>::Diff == cgmath::Vector3<f64>`
> gstgeometryhelper/src/types/ray.rs:54:23

54  transformation_matrix.transform_vector(w);
 ^^^^^^^^^^^^^^^^
error: aborting due to previous error
I'm pretty sure this is a nonissue, but I can't seem to figure it out right now :/
https://github.com/rustgd/cgmath/blob/master/src/quaternion.rs#L50
Shouldn't the scalar part be after the vector part?
I'm writing a gltf reader and it seems that gltf stores the scalar part of the quaternion in the w component of the vec4. I just transmuted the vec4 into Quaternion
because it's marked as repr(C)
.