Compare commits
No commits in common. "549f85f673a6d2e04dfa796f7110a7611a330a33" and "bb542224a5dd2ee5760bae10c7a50826738d6258" have entirely different histories.
549f85f673
...
bb542224a5
@ -9,5 +9,3 @@
|
|||||||
pub mod dr;
|
pub mod dr;
|
||||||
pub mod math;
|
pub mod math;
|
||||||
pub mod sr1;
|
pub mod sr1;
|
||||||
|
|
||||||
pub type IdType = i128;
|
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use nalgebra::Vector2;
|
use rapier2d_f64::geometry::{SharedShape, TriMeshFlags};
|
||||||
use rapier2d_f64::geometry::TriMeshFlags;
|
use rapier2d_f64::math::{Isometry, Point, Real};
|
||||||
use rapier2d_f64::math::{Point, Real};
|
|
||||||
use rapier2d_f64::parry::transformation::vhacd::VHACDParameters;
|
use rapier2d_f64::parry::transformation::vhacd::VHACDParameters;
|
||||||
|
|
||||||
pub enum ConnectType {
|
pub enum ConnectType {
|
||||||
@ -37,13 +36,10 @@ pub struct DRObjectProps<'a> {
|
|||||||
|
|
||||||
/// 为了保证能使用到 所有类型的 碰撞体
|
/// 为了保证能使用到 所有类型的 碰撞体
|
||||||
/// 写了这么长一个玩意
|
/// 写了这么长一个玩意
|
||||||
/// 形状参考
|
|
||||||
/// https://rapier.rs/docs/user_guides/rust/colliders
|
|
||||||
#[cfg(disable)]
|
#[cfg(disable)]
|
||||||
use rapier2d_f64::geometry::ColliderBuilder;
|
use rapier2d_f64::geometry::ColliderBuilder;
|
||||||
pub enum BoxColliderEnum {
|
pub enum BoxColliderEnum {
|
||||||
/// 组合
|
// rapier2d_f64::geometry::ColliderBuilder
|
||||||
Compound(Vec<(Vector2<Real>, BoxColliderEnum)>),
|
|
||||||
/// 球
|
/// 球
|
||||||
/// 半径
|
/// 半径
|
||||||
Ball(Real),
|
Ball(Real),
|
||||||
@ -98,11 +94,9 @@ pub enum BoxColliderEnum {
|
|||||||
Polyline(Vec<(Real, Real)>),
|
Polyline(Vec<(Real, Real)>),
|
||||||
/// 由一系列高度定义的某种东西,大概是地面之类的
|
/// 由一系列高度定义的某种东西,大概是地面之类的
|
||||||
Heightfield(Vec<(Real, Real)>),
|
Heightfield(Vec<(Real, Real)>),
|
||||||
// 凸分解的复合形状
|
/// 凸分解的复合形状
|
||||||
// 就是不知道能不能真用上
|
/// 就是不知道能不能真用上
|
||||||
// 凸分解,好像可以略微提升复杂刚体碰撞的性能
|
Compound(Vec<(Isometry<Real>, SharedShape)>), //凸分解,好像可以略微提升复杂刚体碰撞的性能
|
||||||
// todo
|
|
||||||
// convex_decomposition
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct TankProps {
|
pub struct TankProps {
|
||||||
|
@ -13,8 +13,8 @@ use crate::sr1_data::ship::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::data_type::math::{Point2D, Rotatable};
|
use crate::data_type::math::{Point2D, Rotatable};
|
||||||
use crate::data_type::IdType;
|
|
||||||
|
|
||||||
|
pub type IdType = i64;
|
||||||
pub type ConnectionType = Vec<(Vec<SR1PartData>, Option<Vec<Connection>>)>;
|
pub type ConnectionType = Vec<(Vec<SR1PartData>, Option<Vec<Connection>>)>;
|
||||||
|
|
||||||
pub fn radians_map_to_degrees(angle: f64) -> f64 {
|
pub fn radians_map_to_degrees(angle: f64) -> f64 {
|
||||||
|
@ -4,10 +4,9 @@ use pyo3::exceptions::PyValueError;
|
|||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
|
|
||||||
use crate::data_type::math::{Point2D, Rotatable};
|
use crate::data_type::math::{Point2D, Rotatable};
|
||||||
use crate::data_type::sr1::SaveStatus;
|
|
||||||
use crate::data_type::sr1::{get_max_box, SR1PartData, SR1PartListTrait};
|
use crate::data_type::sr1::{get_max_box, SR1PartData, SR1PartListTrait};
|
||||||
|
use crate::data_type::sr1::{IdType, SaveStatus};
|
||||||
use crate::data_type::sr1::{SR1PartList, SR1PartType, SR1Ship};
|
use crate::data_type::sr1::{SR1PartList, SR1PartType, SR1Ship};
|
||||||
use crate::data_type::IdType;
|
|
||||||
use crate::sr1_data::part_list::RawPartList;
|
use crate::sr1_data::part_list::RawPartList;
|
||||||
|
|
||||||
#[pyclass]
|
#[pyclass]
|
||||||
@ -309,22 +308,21 @@ impl PySR1Ship {
|
|||||||
parts
|
parts
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_part_box(&self, part_id: IdType) -> Option<((f64, f64), (f64, f64))> {
|
fn get_part_box(&self, part_id: i64) -> Option<((f64, f64), (f64, f64))> {
|
||||||
let part_data = self.ship.parts.iter().find(|&x| x.id == part_id);
|
let part_data = self.ship.parts.iter().find(|&x| x.id == part_id);
|
||||||
if let Some(part_data) = part_data {
|
if let Some(part_data) = part_data {
|
||||||
if let Some(part_type) = self.part_list.get_part_type(&part_data.part_type_id) {
|
let part_type = self.part_list.get_part_type(&part_data.part_type_id).unwrap();
|
||||||
// rotate
|
// rotate
|
||||||
let radius = part_data.angle;
|
let radius = part_data.angle;
|
||||||
let ((x1, y1), (x2, y2)) = part_type.get_box();
|
let ((x1, y1), (x2, y2)) = part_type.get_box();
|
||||||
let mut p1 = Point2D::new(x1, y1);
|
let mut p1 = Point2D::new(x1, y1);
|
||||||
let mut p2 = Point2D::new(x2, y2);
|
let mut p2 = Point2D::new(x2, y2);
|
||||||
p1.rotate_radius_mut(radius);
|
p1.rotate_radius_mut(radius);
|
||||||
p2.rotate_radius_mut(radius);
|
p2.rotate_radius_mut(radius);
|
||||||
// transform
|
// transform
|
||||||
p1.add_mut(part_data.x * 2.0, part_data.y * 2.0);
|
p1.add_mut(part_data.x * 2.0, part_data.y * 2.0);
|
||||||
p2.add_mut(part_data.x * 2.0, part_data.y * 2.0);
|
p2.add_mut(part_data.x * 2.0, part_data.y * 2.0);
|
||||||
return Some(((p1.x, p1.y), (p2.x, p2.y)));
|
return Some(((p1.x, p1.y), (p2.x, p2.y)));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -6,141 +6,14 @@
|
|||||||
* -------------------------------
|
* -------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use nalgebra::{Matrix2, Vector2};
|
|
||||||
|
use nalgebra::Vector2;
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use rapier2d_f64::math::Real;
|
|
||||||
|
|
||||||
use crate::data_type::IdType;
|
use crate::data_type::dr::BoxColliderEnum;
|
||||||
|
|
||||||
/// Id 位置 碰撞体
|
|
||||||
pub type BoundedShape = (IdType, Vector2<Real>, EditorShapeEnum);
|
|
||||||
|
|
||||||
pub enum EditorShapeEnum {
|
|
||||||
/// 矩形
|
|
||||||
/// 一个方向的向量 另一个方向的向量
|
|
||||||
Cuboid(Vector2<Real>, Vector2<Real>),
|
|
||||||
/// 三角形
|
|
||||||
/// 一个方向的向量 另一个方向的向量
|
|
||||||
Triangle(Vector2<Real>, Vector2<Real>),
|
|
||||||
/// 圆
|
|
||||||
/// 半径
|
|
||||||
Ball(Real),
|
|
||||||
/// 组合
|
|
||||||
Compound(Vec<EditorShapeEnum>),
|
|
||||||
}
|
|
||||||
|
|
||||||
// #[pyclass]
|
// #[pyclass]
|
||||||
pub struct EditorArea {
|
pub struct EditorArea {
|
||||||
/// 存储所有碰撞箱信息
|
/// 存储所有碰撞箱信息
|
||||||
pub collision_box: Vec<BoundedShape>,
|
pub collision_box: Vec<BoxColliderEnum>,
|
||||||
}
|
|
||||||
|
|
||||||
impl EditorArea {
|
|
||||||
/// 添加一个碰撞箱
|
|
||||||
pub fn add_box(&mut self, box_data: BoundedShape) {
|
|
||||||
self.collision_box.push(box_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 删除一个碰撞箱
|
|
||||||
pub fn remove_box_by_id(&mut self, id: IdType) -> bool {
|
|
||||||
for (i, box_data) in self.collision_box.iter().enumerate() {
|
|
||||||
if box_data.0 == id {
|
|
||||||
self.collision_box.remove(i);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 检查一个点是否碰撞到任意一个碰撞箱
|
|
||||||
pub fn check_hit(&self, point: Vector2<Real>) -> Option<IdType> {
|
|
||||||
for box_data in self.collision_box.iter() {
|
|
||||||
match &box_data.2 {
|
|
||||||
// 球 直接勾股定理秒了
|
|
||||||
EditorShapeEnum::Ball(r) => {
|
|
||||||
if (point - box_data.1).norm() <= *r {
|
|
||||||
return Some(box_data.0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 矩形
|
|
||||||
// 进行一个旋转
|
|
||||||
EditorShapeEnum::Cuboid(dir1, dir2) => {
|
|
||||||
// 先平移坐标系
|
|
||||||
let point = point - box_data.1;
|
|
||||||
// 求出逆矩阵
|
|
||||||
let inv = Matrix2::new(dir1.x, dir2.x, dir1.y, dir2.y).try_inverse().unwrap();
|
|
||||||
// 变换
|
|
||||||
let point = inv * point;
|
|
||||||
// 判断是否在矩形内
|
|
||||||
if point.x >= 0.0 && point.x <= 1.0 && point.y >= 0.0 && point.y <= 1.0 {
|
|
||||||
return Some(box_data.0);
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// 三角形
|
|
||||||
EditorShapeEnum::Triangle(dir1, dir2) => {
|
|
||||||
// 先平移坐标系
|
|
||||||
let point = point - box_data.1;
|
|
||||||
// 求出逆矩阵
|
|
||||||
let inv = Matrix2::new(dir1.x, dir2.x, dir1.y, dir2.y).try_inverse().unwrap();
|
|
||||||
// 变换
|
|
||||||
let point = inv * point;
|
|
||||||
// 判断是否在三角形内
|
|
||||||
if point.x >= 0.0 && point.y >= 0.0 && point.x + point.y <= 1.0 {
|
|
||||||
return Some(box_data.0);
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
EditorShapeEnum::Compound(shapes) => {
|
|
||||||
for shape in shapes {
|
|
||||||
match shape {
|
|
||||||
// 球 直接勾股定理秒了
|
|
||||||
EditorShapeEnum::Ball(r) => {
|
|
||||||
if (point - box_data.1).norm() <= *r {
|
|
||||||
return Some(box_data.0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 矩形
|
|
||||||
// 进行一个旋转
|
|
||||||
EditorShapeEnum::Cuboid(dir1, dir2) => {
|
|
||||||
// 先平移坐标系
|
|
||||||
let point = point - box_data.1;
|
|
||||||
// 求出逆矩阵
|
|
||||||
let inv = Matrix2::new(dir1.x, dir2.x, dir1.y, dir2.y).try_inverse().unwrap();
|
|
||||||
// 变换
|
|
||||||
let point = inv * point;
|
|
||||||
// 判断是否在矩形内
|
|
||||||
if point.x >= 0.0 && point.x <= 1.0 && point.y >= 0.0 && point.y <= 1.0 {
|
|
||||||
return Some(box_data.0);
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// 三角形
|
|
||||||
EditorShapeEnum::Triangle(dir1, dir2) => {
|
|
||||||
// 先平移坐标系
|
|
||||||
let point = point - box_data.1;
|
|
||||||
// 求出逆矩阵
|
|
||||||
let inv = Matrix2::new(dir1.x, dir2.x, dir1.y, dir2.y).try_inverse().unwrap();
|
|
||||||
// 变换
|
|
||||||
let point = inv * point;
|
|
||||||
// 判断是否在三角形内
|
|
||||||
if point.x >= 0.0 && point.y >= 0.0 && point.x + point.y <= 1.0 {
|
|
||||||
return Some(box_data.0);
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
EditorShapeEnum::Compound(_) => {
|
|
||||||
panic!("Compound in Compound");
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,8 @@ use serde::{Deserialize, Serialize};
|
|||||||
use serde_xml_rs::from_str;
|
use serde_xml_rs::from_str;
|
||||||
use serde_xml_rs::Error as XmlError;
|
use serde_xml_rs::Error as XmlError;
|
||||||
|
|
||||||
use crate::data_type::sr1::{SR1PartData, SR1PartDataAttr, SR1Ship};
|
use crate::data_type::sr1::{IdType, SR1PartData, SR1PartDataAttr, SR1Ship};
|
||||||
use crate::data_type::sr1::{SR1PartDataTrait, SR1ShipTrait};
|
use crate::data_type::sr1::{SR1PartDataTrait, SR1ShipTrait};
|
||||||
use crate::data_type::IdType;
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
#[serde(rename = "Ship")]
|
#[serde(rename = "Ship")]
|
||||||
@ -52,7 +51,7 @@ pub struct Part {
|
|||||||
pub pod: Option<Pod>,
|
pub pod: Option<Pod>,
|
||||||
#[serde(rename = "partType")]
|
#[serde(rename = "partType")]
|
||||||
pub part_type_id: String,
|
pub part_type_id: String,
|
||||||
pub id: IdType,
|
pub id: i64,
|
||||||
pub x: f64,
|
pub x: f64,
|
||||||
pub y: f64,
|
pub y: f64,
|
||||||
#[serde(rename = "editorAngle")]
|
#[serde(rename = "editorAngle")]
|
||||||
@ -120,7 +119,7 @@ pub struct Step {
|
|||||||
#[serde(rename = "Activate")]
|
#[serde(rename = "Activate")]
|
||||||
pub struct Activate {
|
pub struct Activate {
|
||||||
#[serde(rename = "Id")]
|
#[serde(rename = "Id")]
|
||||||
pub id: IdType,
|
pub id: i64,
|
||||||
pub moved: i8, // 1 or 0
|
pub moved: i8, // 1 or 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user