mirror of
https://codeberg.org/icewind/vbsp.git
synced 2026-06-03 18:54:05 +02:00
expose prop angles as quaternion
This commit is contained in:
parent
243d2039c3
commit
7391f8124d
3 changed files with 20 additions and 1 deletions
|
|
@ -2,6 +2,7 @@ use crate::error::UnsupportedLumpVersion;
|
|||
use crate::{lzma_decompress_with_header, BspError, FixedString, Vector};
|
||||
use binrw::{BinRead, BinReaderExt, BinResult, ReadOptions};
|
||||
use bitflags::bitflags;
|
||||
use cgmath::{Deg, Quaternion, Rotation3};
|
||||
use std::borrow::Cow;
|
||||
use std::io::{Cursor, Read, Seek};
|
||||
use std::mem::size_of;
|
||||
|
|
@ -115,7 +116,7 @@ pub struct StaticPropLumps {
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct StaticPropLump {
|
||||
pub origin: Vector,
|
||||
pub angles: [f32; 3],
|
||||
angles: [f32; 3],
|
||||
pub prop_type: u16,
|
||||
pub first_leaf: u16,
|
||||
pub leaf_count: u16,
|
||||
|
|
@ -131,6 +132,16 @@ pub struct StaticPropLump {
|
|||
pub lightmap_resolution: [u16; 2],
|
||||
}
|
||||
|
||||
impl StaticPropLump {
|
||||
/// Get the rotation of the prop as quaternion
|
||||
pub fn rotation(&self) -> Quaternion<f32> {
|
||||
// angles are applied in roll, pitch, yaw order
|
||||
Quaternion::from_angle_y(Deg(self.angles[1]))
|
||||
* Quaternion::from_angle_x(Deg(self.angles[0]))
|
||||
* Quaternion::from_angle_z(Deg(self.angles[2]))
|
||||
}
|
||||
}
|
||||
|
||||
impl BinRead for StaticPropLump {
|
||||
type Args = (u16,);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use crate::error::EntityParseError;
|
||||
use binrw::BinRead;
|
||||
use cgmath::Vector3;
|
||||
use std::cmp::Ordering;
|
||||
use std::fmt::Debug;
|
||||
use std::ops::{Add, Mul, Sub};
|
||||
|
|
@ -103,3 +104,9 @@ impl FromStr for Vector {
|
|||
Ok(Vector { x, y, z })
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vector> for Vector3<f32> {
|
||||
fn from(v: Vector) -> Self {
|
||||
Vector3::new(v.x, v.y, v.z)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue