optimize face_nd: precalculate det
This commit is contained in:
parent
513414d4bd
commit
82b3201b0a
@ -238,17 +238,20 @@ pub struct TransformedMesh<'a>{
|
|||||||
mesh:&'a PhysicsMesh,
|
mesh:&'a PhysicsMesh,
|
||||||
transform:&'a crate::integer::Planar64Affine3,
|
transform:&'a crate::integer::Planar64Affine3,
|
||||||
normal_transform:&'a crate::integer::Planar64Mat3,
|
normal_transform:&'a crate::integer::Planar64Mat3,
|
||||||
|
transform_det:Planar64,
|
||||||
}
|
}
|
||||||
impl TransformedMesh<'_>{
|
impl TransformedMesh<'_>{
|
||||||
pub fn new<'a>(
|
pub fn new<'a>(
|
||||||
mesh:&'a PhysicsMesh,
|
mesh:&'a PhysicsMesh,
|
||||||
transform:&'a crate::integer::Planar64Affine3,
|
transform:&'a crate::integer::Planar64Affine3,
|
||||||
normal_transform:&'a crate::integer::Planar64Mat3,
|
normal_transform:&'a crate::integer::Planar64Mat3,
|
||||||
|
transform_det:Planar64,
|
||||||
)->TransformedMesh<'a>{
|
)->TransformedMesh<'a>{
|
||||||
TransformedMesh{
|
TransformedMesh{
|
||||||
mesh,
|
mesh,
|
||||||
transform,
|
transform,
|
||||||
normal_transform,
|
normal_transform,
|
||||||
|
transform_det,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn farthest_vert(&self,dir:Planar64Vec3)->VertId{
|
fn farthest_vert(&self,dir:Planar64Vec3)->VertId{
|
||||||
@ -269,7 +272,7 @@ impl MeshQuery<FaceId,DirectedEdgeId,VertId> for TransformedMesh<'_>{
|
|||||||
fn face_nd(&self,face_id:FaceId)->(Planar64Vec3,Planar64){
|
fn face_nd(&self,face_id:FaceId)->(Planar64Vec3,Planar64){
|
||||||
let (n,d)=self.mesh.face_nd(face_id);
|
let (n,d)=self.mesh.face_nd(face_id);
|
||||||
let transformed_n=*self.normal_transform*n;
|
let transformed_n=*self.normal_transform*n;
|
||||||
let transformed_d=Planar64::raw(((transformed_n.dot128(self.transform.matrix3*n)<<32)/n.dot128(n)) as i64)*d+transformed_n.dot(self.transform.translation);
|
let transformed_d=self.transform_det*d+transformed_n.dot(self.transform.translation);
|
||||||
(transformed_n,transformed_d)
|
(transformed_n,transformed_d)
|
||||||
}
|
}
|
||||||
fn vert(&self,vert_id:VertId)->Planar64Vec3{
|
fn vert(&self,vert_id:VertId)->Planar64Vec3{
|
||||||
|
@ -202,6 +202,7 @@ impl PhysicsModels{
|
|||||||
&self.meshes[self.models[model_id].mesh_id],
|
&self.meshes[self.models[model_id].mesh_id],
|
||||||
&self.models[model_id].transform,
|
&self.models[model_id].transform,
|
||||||
&self.models[model_id].normal_transform,
|
&self.models[model_id].normal_transform,
|
||||||
|
self.models[model_id].transform_det,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
fn model(&self,model_id:usize)->&PhysicsModel{
|
fn model(&self,model_id:usize)->&PhysicsModel{
|
||||||
@ -343,11 +344,11 @@ struct Hitbox{
|
|||||||
mesh:PhysicsMesh,
|
mesh:PhysicsMesh,
|
||||||
transform:crate::integer::Planar64Affine3,
|
transform:crate::integer::Planar64Affine3,
|
||||||
normal_transform:Planar64Mat3,
|
normal_transform:Planar64Mat3,
|
||||||
|
transform_det:Planar64,
|
||||||
}
|
}
|
||||||
impl Hitbox{
|
impl Hitbox{
|
||||||
fn new(mesh:PhysicsMesh,transform:crate::integer::Planar64Affine3)->Self{
|
fn new(mesh:PhysicsMesh,transform:crate::integer::Planar64Affine3)->Self{
|
||||||
//calculate extents
|
//calculate extents
|
||||||
let normal_transform=transform.matrix3.inverse_times_det().transpose();
|
|
||||||
let mut aabb=crate::aabb::Aabb::default();
|
let mut aabb=crate::aabb::Aabb::default();
|
||||||
for vert in mesh.verts(){
|
for vert in mesh.verts(){
|
||||||
aabb.grow(transform.transform_point3(vert));
|
aabb.grow(transform.transform_point3(vert));
|
||||||
@ -356,23 +357,28 @@ impl Hitbox{
|
|||||||
halfsize:aabb.size()/2,
|
halfsize:aabb.size()/2,
|
||||||
mesh,
|
mesh,
|
||||||
transform,
|
transform,
|
||||||
normal_transform,
|
normal_transform:transform.matrix3.inverse_times_det().transpose(),
|
||||||
|
transform_det:transform.matrix3.determinant(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn from_mesh_scale(mesh:PhysicsMesh,scale:Planar64Vec3)->Self{
|
fn from_mesh_scale(mesh:PhysicsMesh,scale:Planar64Vec3)->Self{
|
||||||
|
let matrix3=Planar64Mat3::from_diagonal(scale);
|
||||||
Self{
|
Self{
|
||||||
halfsize:scale,
|
halfsize:scale,
|
||||||
mesh,
|
mesh,
|
||||||
transform:crate::integer::Planar64Affine3::new(Planar64Mat3::from_diagonal(scale),Planar64Vec3::ZERO),
|
normal_transform:matrix3.inverse_times_det().transpose(),
|
||||||
normal_transform:Planar64Mat3::from_diagonal(scale).inverse_times_det().transpose(),
|
transform:crate::integer::Planar64Affine3::new(matrix3,Planar64Vec3::ZERO),
|
||||||
|
transform_det:matrix3.determinant(),//scale.x*scale.y*scale.z but whatever
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn from_mesh_scale_offset(mesh:PhysicsMesh,scale:Planar64Vec3,offset:Planar64Vec3)->Self{
|
fn from_mesh_scale_offset(mesh:PhysicsMesh,scale:Planar64Vec3,offset:Planar64Vec3)->Self{
|
||||||
|
let matrix3=Planar64Mat3::from_diagonal(scale);
|
||||||
Self{
|
Self{
|
||||||
halfsize:scale,
|
halfsize:scale,
|
||||||
mesh,
|
mesh,
|
||||||
transform:crate::integer::Planar64Affine3::new(Planar64Mat3::from_diagonal(scale),offset),
|
normal_transform:matrix3.inverse_times_det().transpose(),
|
||||||
normal_transform:Planar64Mat3::from_diagonal(scale).inverse_times_det().transpose(),
|
transform:crate::integer::Planar64Affine3::new(matrix3,offset),
|
||||||
|
transform_det:matrix3.determinant(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn roblox()->Self{
|
fn roblox()->Self{
|
||||||
@ -383,7 +389,7 @@ impl Hitbox{
|
|||||||
}
|
}
|
||||||
#[inline]
|
#[inline]
|
||||||
fn transformed_mesh(&self)->TransformedMesh{
|
fn transformed_mesh(&self)->TransformedMesh{
|
||||||
TransformedMesh::new(&self.mesh,&self.transform,&self.normal_transform)
|
TransformedMesh::new(&self.mesh,&self.transform,&self.normal_transform,self.transform_det)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -779,16 +785,17 @@ pub struct PhysicsModel{
|
|||||||
attr_id:usize,
|
attr_id:usize,
|
||||||
transform:crate::integer::Planar64Affine3,
|
transform:crate::integer::Planar64Affine3,
|
||||||
normal_transform:crate::integer::Planar64Mat3,
|
normal_transform:crate::integer::Planar64Mat3,
|
||||||
|
transform_det:Planar64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PhysicsModel{
|
impl PhysicsModel{
|
||||||
pub fn new(mesh_id:usize,attr_id:usize,transform:crate::integer::Planar64Affine3)->Self{
|
pub fn new(mesh_id:usize,attr_id:usize,transform:crate::integer::Planar64Affine3)->Self{
|
||||||
let normal_transform=transform.matrix3.inverse_times_det().transpose();
|
|
||||||
Self{
|
Self{
|
||||||
mesh_id,
|
mesh_id,
|
||||||
attr_id,
|
attr_id,
|
||||||
transform,
|
transform,
|
||||||
normal_transform,
|
normal_transform:transform.matrix3.inverse_times_det().transpose(),
|
||||||
|
transform_det:transform.matrix3.determinant(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user