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
|
|
@ -20,6 +20,7 @@ binrw = "0.8.0"
|
||||||
static_assertions = "1.1.0"
|
static_assertions = "1.1.0"
|
||||||
num_enum = "0.5.6"
|
num_enum = "0.5.6"
|
||||||
vbsp-derive = { path = "derive", version = "*" }
|
vbsp-derive = { path = "derive", version = "*" }
|
||||||
|
cgmath = "0.18.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
obj = "0.10"
|
obj = "0.10"
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ use crate::error::UnsupportedLumpVersion;
|
||||||
use crate::{lzma_decompress_with_header, BspError, FixedString, Vector};
|
use crate::{lzma_decompress_with_header, BspError, FixedString, Vector};
|
||||||
use binrw::{BinRead, BinReaderExt, BinResult, ReadOptions};
|
use binrw::{BinRead, BinReaderExt, BinResult, ReadOptions};
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
|
use cgmath::{Deg, Quaternion, Rotation3};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::io::{Cursor, Read, Seek};
|
use std::io::{Cursor, Read, Seek};
|
||||||
use std::mem::size_of;
|
use std::mem::size_of;
|
||||||
|
|
@ -115,7 +116,7 @@ pub struct StaticPropLumps {
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct StaticPropLump {
|
pub struct StaticPropLump {
|
||||||
pub origin: Vector,
|
pub origin: Vector,
|
||||||
pub angles: [f32; 3],
|
angles: [f32; 3],
|
||||||
pub prop_type: u16,
|
pub prop_type: u16,
|
||||||
pub first_leaf: u16,
|
pub first_leaf: u16,
|
||||||
pub leaf_count: u16,
|
pub leaf_count: u16,
|
||||||
|
|
@ -131,6 +132,16 @@ pub struct StaticPropLump {
|
||||||
pub lightmap_resolution: [u16; 2],
|
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 {
|
impl BinRead for StaticPropLump {
|
||||||
type Args = (u16,);
|
type Args = (u16,);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::error::EntityParseError;
|
use crate::error::EntityParseError;
|
||||||
use binrw::BinRead;
|
use binrw::BinRead;
|
||||||
|
use cgmath::Vector3;
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::ops::{Add, Mul, Sub};
|
use std::ops::{Add, Mul, Sub};
|
||||||
|
|
@ -103,3 +104,9 @@ impl FromStr for Vector {
|
||||||
Ok(Vector { x, y, z })
|
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