Point() публичный Метод

public Point ( float dist ) : Vector3
dist float
Результат Vector3
Пример #1
0
    public Hit Hit(Ray ray)
    {
        var   oc  = ray.origin - center;
        float a   = Vector3.Dot(ray.direction, ray.direction);
        float b   = Vector3.Dot(oc, ray.direction);
        float c   = Vector3.Dot(oc, oc) - radius * radius;
        float dis = b * b - a * c;

        if (dis > 0)
        {
            float e = (float)Math.Sqrt(dis);

            float t = (-b - e) / a;
            if (t > 0.007f)
            {
                var point = ray.Point(t);
                return(new Hit(t, point, (point - center).Unit()));
            }

            t = (-b + e) / a;
            if (t > 0.007f)
            {
                var point = ray.Point(t);
                return(new Hit(t, point, (point - center).Unit()));
            }

            return(default);
Пример #2
0
    public bool Hit(ref Ray ray, ref Hit hit)
    {
        var   oc  = ray.origin - center;
        float a   = Vector3.Dot(ray.direction, ray.direction);
        float b   = Vector3.Dot(oc, ray.direction);
        float c   = Vector3.Dot(oc, oc) - radius * radius;
        float dis = b * b - a * c;

        if (dis > 0)
        {
            float e = MathF.Sqrt(dis);
            float t = (-b - e) / a;
            if (t > 0.007f)
            {
                var point = ray.Point(t);
                var unit  = (point - center).Unit();
                hit = new Hit(t, ref point, ref unit);
                return(true);
            }

            t = (-b + e) / a;
            if (t > 0.007f)
            {
                var point = ray.Point(t);
                var unit  = (point - center).Unit();
                hit = new Hit(t, ref point, ref unit);
                return(true);
            }
        }

        return(false);
    }
Пример #3
0
    public Hit?Hit(Ray ray)
    {
        var   oc  = ray.origin.Sub(this.center);
        float a   = ray.direction.Dot(ray.direction);
        float b   = oc.Dot(ray.direction);
        float c   = oc.Dot(oc) - this.radius * this.radius;
        float dis = b * b - a * c;

        if (dis > 0)
        {
            float e = (float)Math.Sqrt(dis);

            float t = (-b - e) / a;
            if (t > 0.007f)
            {
                var hit = new Hit();

                hit.dist   = t;
                hit.point  = ray.Point(t);
                hit.normal = hit.point.Sub(this.center).Unit();

                return(hit);
            }

            t = (-b + e) / a;
            if (t > 0.007f)
            {
                var hit = new Hit();

                hit.dist   = t;
                hit.point  = ray.Point(t);
                hit.normal = hit.point.Sub(this.center).Unit();

                return(hit);
            }

            return(null);
        }

        return(null);
    }
Пример #4
0
  public Hit Hit (Ray ray) {
    var oc = ray.origin.Sub(this.center);
    float a = ray.direction.Dot(ray.direction);
    float b = oc.Dot(ray.direction);
    float c = oc.Dot(oc) - this.radius * this.radius;
    float dis = b * b - a * c;

    if (dis > 0) {
      float e = (float) Math.Sqrt(dis);

      float t = (-b - e) / a;
      if (t > 0.007f) {
        var hit = new Hit();

        hit.dist = t;
        hit.point = ray.Point(t);
        hit.normal = hit.point.Sub(this.center).Unit();

        return hit;
      }

      t = (-b + e) / a;
      if (t > 0.007f) {
        var hit = new Hit();

        hit.dist = t;
        hit.point = ray.Point(t);
        hit.normal = hit.point.Sub(this.center).Unit();

        return hit;
      }

      return null;
    }

    return null;
  }