Generate collision indices
parent
9ee22d3618
commit
46313b4880
|
@ -6,7 +6,6 @@ hull = 200
|
||||||
linear_drag = 0.2
|
linear_drag = 0.2
|
||||||
angular_drag = 0.2
|
angular_drag = 0.2
|
||||||
|
|
||||||
|
|
||||||
space.outfit = 200
|
space.outfit = 200
|
||||||
space.engine = 50
|
space.engine = 50
|
||||||
space.weapon = 50
|
space.weapon = 50
|
||||||
|
@ -14,7 +13,7 @@ space.weapon = 50
|
||||||
engines = [{ x = 0.0, y = -1.05, size = 50.0 }]
|
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 }]
|
guns = [{ x = 0.0, y = 1 }, { x = 0.1, y = 0.80 }, { x = -0.1, y = 0.80 }]
|
||||||
|
|
||||||
collision.points = [
|
collision = [
|
||||||
#[rustfmt:skip],
|
#[rustfmt:skip],
|
||||||
[0.53921, 1.0000],
|
[0.53921, 1.0000],
|
||||||
[0.53921, 0.29343],
|
[0.53921, 0.29343],
|
||||||
|
@ -38,28 +37,3 @@ collision.points = [
|
||||||
[-0.53921, 0.29343],
|
[-0.53921, 0.29343],
|
||||||
[-0.53921, 1.0000],
|
[-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],
|
|
||||||
]
|
|
||||||
|
|
|
@ -21,18 +21,12 @@ pub(crate) mod syntax {
|
||||||
pub guns: Vec<Gun>,
|
pub guns: Vec<Gun>,
|
||||||
pub hull: f32,
|
pub hull: f32,
|
||||||
pub mass: f32,
|
pub mass: f32,
|
||||||
pub collision: Collision,
|
pub collision: Vec<[f32; 2]>,
|
||||||
pub angular_drag: f32,
|
pub angular_drag: f32,
|
||||||
pub linear_drag: f32,
|
pub linear_drag: f32,
|
||||||
pub space: outfitspace::syntax::OutfitSpace,
|
pub space: outfitspace::syntax::OutfitSpace,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
pub struct Collision {
|
|
||||||
pub points: Vec<[f32; 2]>,
|
|
||||||
pub indices: Vec<[u32; 2]>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct Engine {
|
pub struct Engine {
|
||||||
pub x: f32,
|
pub x: f32,
|
||||||
|
@ -153,6 +147,7 @@ impl crate::Build for Ship {
|
||||||
linear_drag: ship.linear_drag,
|
linear_drag: ship.linear_drag,
|
||||||
size,
|
size,
|
||||||
hull: ship.hull,
|
hull: ship.hull,
|
||||||
|
|
||||||
engines: ship
|
engines: ship
|
||||||
.engines
|
.engines
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -164,6 +159,7 @@ impl crate::Build for Ship {
|
||||||
size: e.size,
|
size: e.size,
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
|
|
||||||
guns: ship
|
guns: ship
|
||||||
.guns
|
.guns
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -174,11 +170,22 @@ impl crate::Build for Ship {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
|
|
||||||
collision: Collision {
|
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
|
points: ship
|
||||||
.collision
|
.collision
|
||||||
.points
|
|
||||||
.iter()
|
.iter()
|
||||||
.map(|x| point![x[0] * (size / 2.0) * aspect, x[1] * size / 2.0])
|
.map(|x| point![x[0] * (size / 2.0) * aspect, x[1] * size / 2.0])
|
||||||
.collect(),
|
.collect(),
|
||||||
|
|
Loading…
Reference in New Issue