1
0
Fork 0
mirror of https://codeberg.org/icewind/vbsp.git synced 2026-06-03 10:44:07 +02:00

allow getting prop data from static and dynamic props

This commit is contained in:
Robin Appelman 2023-12-27 20:41:03 +01:00
commit b4e08b6e65
2 changed files with 55 additions and 0 deletions

View file

@ -1,11 +1,13 @@
mod displacement;
mod entity;
mod game;
mod prop;
mod vector;
pub use self::displacement::*;
pub use self::entity::*;
pub use self::game::*;
pub use self::prop::PropPlacement;
pub use self::vector::*;
use crate::bspfile::LumpType;
use crate::{BspResult, StringError};

53
src/data/prop.rs Normal file
View file

@ -0,0 +1,53 @@
use crate::{Handle, PropDynamic, PropDynamicOverride, StaticPropLump, Vector};
use cgmath::{Deg, Quaternion, Rotation3};
#[derive(Debug, Clone)]
pub struct PropPlacement<'a> {
pub model: &'a str,
pub rotation: Quaternion<f32>,
pub scale: f32,
pub origin: Vector,
pub skin: i32,
}
impl<'a> Handle<'a, StaticPropLump> {
pub fn as_prop_placement(&self) -> PropPlacement<'a> {
PropPlacement {
model: self.model(),
rotation: self.rotation(),
scale: 1.0,
origin: self.origin,
skin: self.skin,
}
}
}
fn rotation(angles: [f32; 3]) -> Quaternion<f32> {
Quaternion::from_angle_y(Deg(angles[1]))
* Quaternion::from_angle_x(Deg(angles[0]))
* Quaternion::from_angle_z(Deg(angles[2]))
}
impl<'a> PropDynamic<'a> {
pub fn as_prop_placement(&self) -> PropPlacement<'a> {
PropPlacement {
model: self.model,
rotation: rotation(self.angles),
scale: self.scale,
origin: self.origin,
skin: 0,
}
}
}
impl<'a> PropDynamicOverride<'a> {
pub fn as_prop_placement(&self) -> PropPlacement<'a> {
PropPlacement {
model: self.model,
rotation: rotation(self.angles),
scale: self.scale,
origin: self.origin,
skin: 0,
}
}
}