sphereIntersect method
Implementation
OctreeData? sphereIntersect(Sphere sphere, OctreeNode octree, ){
_sphere.copy(sphere);
final List<Triangle> triangles = [];
getSphereTriangles(_sphere, triangles, octree.subTrees);
bool hit = false;
for(int i = 0; i < triangles.length; i ++ ) {
OctreeData? result = triangleSphereIntersect(_sphere, triangles[i]);
if(result != null) {
hit = true;
_sphere.center.add(result.normal..scale(result.depth));
}
}
if(hit){
vmath.Vector3 collisionVector = _sphere.center.clone()..sub(sphere.center);
double depth = collisionVector.length;
print('here3');
return OctreeData(
point: _sphere.center.clone()..addScaled(collisionVector..normalize(), sphere.radius),
normal: collisionVector..normalize(),
depth: depth
);
}
triangles.clear();
return null;
}