Sphere x Sphere

This commit is contained in:
ousttrue 2024-11-20 20:42:39 +09:00
parent 2100a04284
commit 423830cc76
3 changed files with 19 additions and 11 deletions

View File

@ -21,16 +21,29 @@ namespace RotateParticle.Jobs
{
[ReadOnly] public NativeArray<BlittableCollider> Colliders;
[ReadOnly] public NativeArray<Matrix4x4> CurrentColliders;
[WriteOnly] public NativeArray<Vector3> NextPositions;
[ReadOnly] public NativeArray<TransformInfo> Info;
[NativeDisableParallelForRestriction] public NativeArray<Vector3> NextPositions;
public void Execute(int index)
{
var info = Info[index];
var pos = NextPositions[index];
for (int i = 0; i < Colliders.Length; ++i)
{
var c = Colliders[i];
switch (c.colliderType)
{
case BlittableColliderType.Sphere:
{
var col_pos = CurrentColliders[i].MultiplyPoint(c.offset);
var d = Vector3.Distance(pos, col_pos);
var min_d = info.Settings.radius + c.radius;
if (d < min_d)
{
Vector3 normal = (pos - col_pos).normalized;
pos += normal * (min_d - d);
}
}
break;
default:
@ -38,15 +51,7 @@ namespace RotateParticle.Jobs
break;
}
}
// var d = Vector3.Distance(from, to);
// if (d > (ra + rb))
// {
// resolved = default;
// return false;
// }
// Vector3 normal = (to - from).normalized;
// resolved = new(from, from + normal * (d - rb));
// return true;
NextPositions[index] = pos;
}
}
}

View File

@ -222,8 +222,9 @@ namespace RotateParticle.Jobs
// collision
handle = new CollisionJob
{
Colliders = _colliders,
Colliders = _colliders,
CurrentColliders = _currentColliders,
Info = _info,
NextPositions = _nextPositions,
}.Schedule(_info.Length, 128, handle);

View File

@ -173,6 +173,8 @@ namespace RotateParticle
{
c.InitializeColliderSide(_newPos, _colliderGroups);
}
await awaitCaller.NextFrame();
}
/// <summary>