public Cylinder(Vector3 _center, float _radius, float _halfLength) { this.radius = _radius; this.halfLength = _halfLength; this.boundingCylinder = new BoundingCylinder(_center, _radius, _halfLength); this.color = Color.Red.ToArgb(); this.initialize(); }
public static bool testSphereCylinder(TgcBoundingSphere sphere, BoundingCylinder cylinder) { Vector3 n = cylinder.HalfHeight; Vector3 aPoint = cylinder.Position + n; float d = -Vector3.Dot(n, aPoint); Plane tapaSuperior = new Plane(n.X, n.Y, n.Z, d); aPoint = cylinder.Position - n; d = -Vector3.Dot(-n, aPoint); Plane tapaInferior = new Plane(-n.X, -n.Y, -n.Z, d); if (TgcCollisionUtils.classifyPointPlane(sphere.Center, tapaSuperior) != TgcCollisionUtils.PointPlaneResult.IN_FRONT_OF && TgcCollisionUtils.classifyPointPlane(sphere.Center, tapaInferior) != TgcCollisionUtils.PointPlaneResult.IN_FRONT_OF) { //el centro de la esfera esta entre ambos planos de las tapas del cilindro //float distanceSq = distanciaDePuntoARecta(n, cylinder.Position, sphere.Center); Vector3 cylAxisStart = cylinder.Position - n; Vector3 cylAxisEnd = cylinder.Position + n; float distanceSq = TgcCollisionUtils.sqDistPointSegment(cylAxisStart, cylAxisEnd, sphere.Center); if (distanceSq <= FastMath.Pow2(cylinder.Radius + sphere.Radius)) return true; else return false; } else { return false; } }