Generate collision indices

master
Mark 2024-01-05 13:25:44 -08:00
parent 9ee22d3618
commit 46313b4880
Signed by: Mark
GPG Key ID: C6D63995FE72FD80
2 changed files with 17 additions and 36 deletions

View File

@ -6,7 +6,6 @@ hull = 200
linear_drag = 0.2
angular_drag = 0.2
space.outfit = 200
space.engine = 50
space.weapon = 50
@ -14,7 +13,7 @@ space.weapon = 50
engines = [{ x = 0.0, y = -1.05, size = 50.0 }]
guns = [{ x = 0.0, y = 1 }, { x = 0.1, y = 0.80 }, { x = -0.1, y = 0.80 }]
collision.points = [
collision = [
#[rustfmt:skip],
[0.53921, 1.0000],
[0.53921, 0.29343],
@ -38,28 +37,3 @@ collision.points = [
[-0.53921, 0.29343],
[-0.53921, 1.0000],
]
# TODO: generate this automatically
collision.indices = [
#[rustfmt:skip],
[0, 1],
[1, 2],
[2, 3],
[3, 4],
[4, 5],
[5, 6],
[6, 7],
[7, 8],
[8, 9],
[9, 10],
[10, 11],
[11, 12],
[12, 13],
[13, 14],
[14, 15],
[15, 16],
[16, 17],
[17, 18],
[18, 19],
[19, 0],
]

View File

@ -21,18 +21,12 @@ pub(crate) mod syntax {
pub guns: Vec<Gun>,
pub hull: f32,
pub mass: f32,
pub collision: Collision,
pub collision: Vec<[f32; 2]>,
pub angular_drag: f32,
pub linear_drag: f32,
pub space: outfitspace::syntax::OutfitSpace,
}
#[derive(Debug, Deserialize)]
pub struct Collision {
pub points: Vec<[f32; 2]>,
pub indices: Vec<[u32; 2]>,
}
#[derive(Debug, Deserialize)]
pub struct Engine {
pub x: f32,
@ -153,6 +147,7 @@ impl crate::Build for Ship {
linear_drag: ship.linear_drag,
size,
hull: ship.hull,
engines: ship
.engines
.iter()
@ -164,6 +159,7 @@ impl crate::Build for Ship {
size: e.size,
})
.collect(),
guns: ship
.guns
.iter()
@ -174,11 +170,22 @@ impl crate::Build for Ship {
},
})
.collect(),
collision: Collision {
indices: ship.collision.indices,
indices: (0..ship.collision.len())
.map(|x| {
// Auto-generate mesh lines:
// [ [0, 1], [1, 2], ..., [n, 0] ]
let next = if x == ship.collision.len() - 1 {
0
} else {
x + 1
};
[x as u32, next as u32]
})
.collect(),
points: ship
.collision
.points
.iter()
.map(|x| point![x[0] * (size / 2.0) * aspect, x[1] * size / 2.0])
.collect(),