public bool Hit(Ray r, double t_min, double t_max, out HitRecord rec) { bool enableDebug = false; bool db = enableDebug && _sampler.Next() < 0.00001; HitRecord rec1, rec2; if (_boundary.Hit(r, double.MinValue, double.MaxValue, out rec)) { rec1 = rec; if (_boundary.Hit(r, rec1.T + 0.0001, double.MaxValue, out rec2)) { if (enableDebug) { Console.WriteLine($"t0 t1 {rec1.T} {rec2.T}"); } if (rec1.T < t_min) { rec1.T = t_min; } if (rec2.T > t_max) { rec2.T = t_max; } if (rec1.T >= rec2.T) { return(false); } if (rec1.T < 0) { rec1.T = 0; } double distance_inside_boundary = (rec2.T - rec1.T) * r.Direction.Length; double hit_distance = -(1 / _density) * Math.Log(_sampler.NextDouble()); if (hit_distance < distance_inside_boundary) { var t = rec1.T + hit_distance / r.Direction.Length; var p = r.PointAt(rec.T); if (enableDebug) { Console.WriteLine($"hit_distance {hit_distance}; rec.T {rec.T}; rectP {rec.P}"); } var n = Vec3.Create(1, 0, 0); // arbitrary rec = new HitRecord(t, 0, 0, p, n, _phaseFunction); return(true); } } } return(false); }
public bool Hit(Ray r, double tMin, double tMax, out HitRecord rec) { Vector3D origin = new Vector3D(r.Origin); Vector3D direction = new Vector3D(r.Direction); origin.X = cosTheta * r.Origin.X - sinTheta * r.Origin.Z; origin.Z = sinTheta * r.Origin.X + cosTheta * r.Origin.Z; direction.X = cosTheta * r.Direction.X - sinTheta * r.Direction.Z; direction.Z = sinTheta * r.Direction.X + cosTheta * r.Direction.Z; Ray rotatedR = new Ray(origin, direction, r.Time); if (ptr.Hit(rotatedR, tMin, tMax, out rec)) { Vector3D p = new Vector3D(rec.p); Vector3D normal = new Vector3D(rec.normal); p.X = cosTheta * rec.p.X + sinTheta * rec.p.Z; p.Z = -sinTheta * rec.p.X + cosTheta * rec.p.Z; normal.X = cosTheta * rec.normal.X + sinTheta * rec.normal.Z; normal.Z = -sinTheta * rec.normal.X + cosTheta * rec.normal.Z; rec.p = p; rec.normal = normal; return(true); } else { return(false); } }
public void CollideWith(Collider2D collision) { IHitable hitOptions = collision.GetComponentInParent <IHitable>(); if (hitOptions != null) { if (chargedDive) { hitOptions.Hit(chargedDamage); } else { hitOptions.Hit(damage); } } }
private void OnTriggerEnter2D(Collider2D collision) { IHitable hitable = collision.GetComponentInParent <IHitable>(); if (hitable != null) { if (shotBy) { if (collision.transform.IsChildOf(shotBy.transform)) { return; } } hitable.Hit(this, out bool _destroy); if (_destroy) { DestroyProjectile(); } } else { if (ImpactSounds.Length > 0 && (Time.time - shotTime) > MinSoundLifetime) { SoundManager.instance.PlaySound(ImpactSounds[Random.Range(0, ImpactSounds.Length)], transform.position, ImpactVolume); } DestroyProjectile(); } }
public bool Hit(Ray r, float tmin, float tmax, ref HitRecord rec) { if (Box.Hit(r, tmin, tmax)) { HitRecord leftRecord = new HitRecord(), rightRecord = new HitRecord(); bool hitLeft = Left.Hit(r, tmin, tmax, ref leftRecord); bool hitRight = Right.Hit(r, tmin, tmax, ref rightRecord); if (hitLeft && hitRight) { rec = leftRecord.T < rightRecord.T ? leftRecord : rightRecord; return(true); } if (hitLeft) { rec = leftRecord; return(true); } if (hitRight) { rec = rightRecord; return(true); } return(false); } return(false); }
// ----------------------------------------------------------------------------------- // Activate // ----------------------------------------------------------------------------------- public virtual void Activate(Character owner, int level = 0) { owner.AdjustProperty(OnActiveModifier, level); foreach (StatusChance tmpl in addStatus) { owner.states.TryApplyStatus(tmpl.template, tmpl.probability); } foreach (StatusChance tmpl in removeStatus) { owner.states.TryRemoveStatus(tmpl.template, tmpl.probability); } foreach (ItemDropProbability tmpl in createItem) { Utl.SpawnItem(tmpl, tmpl.spawnProbability, owner.transform.position, dropPrefab); } if (dealDamage != null) { IHitable hitable = owner.gameObject.GetComponent(typeof(IHitable)) as IHitable; if (hitable != null) { hitable.Hit(new HitInfo(dealDamage, owner.transform.position, false, null, level)); } } }
private ColorVector GetRayColor(Ray ray, IHitable world, int depth) { // the 0.001 corrects for the "shadow acne" HitRecord hr = world.Hit(ray, 0.001f, float.MaxValue); if (hr != null) { if (depth < 50) { var scatterResult = hr.Material.Scatter(ray, hr); if (scatterResult.IsScattered) { return(scatterResult.Attenuation * GetRayColor(scatterResult.SpecularRay, world, depth + 1)); } } return(ColorVector.Zero); } else { var unitDirection = ray.Direction.ToUnitVector(); float t = 0.5f * (unitDirection.Y + 1.0f); return((((1.0f - t) * Vector3.One) + (t * new Vector3(0.5f, 0.7f, 1.0f))).ToColorVector()); } }
void OnTriggerEnter(Collider other) { IHitable hitable = other.gameObject.GetComponent(typeof(IHitable)) as IHitable; if (hitable != null) { hitable.Hit(new HitInfo(damage, transform.position, false, HitInfo.HitSources.Enviroment)); } }
public bool Hit(Ray r, float tMin, float tMax, ref HitRecord rec) { if (ptr.Hit(r, tMin, tMax, ref rec)) { rec.Normal = -rec.Normal; return(true); } return(false); }
public override void Apply(GameObject go) { IHitable targ = go.GetComponent <IHitable>(); if (targ != null) { targ.Hit(_amount); } }
public virtual void OnTriggerEnter(Collider other) { IHitable hittable = other.GetComponent <IHitable>(); if (hittable != null && (object)hittable != thrower) { hittable.Hit(this); } }
public void CollideWith(Collider2D collision) { IHitable hitOptions = collision.GetComponentInParent <IHitable>(); if (hitOptions != null) { Debug.Log("AirAttackSwing"); hitOptions.Hit(damage); } }
public bool Hit(Ray r, double t_min, double t_max, out HitRecord rec) { if (_source.Hit(r, t_min, t_max, out rec)) { rec.InvertNormal(); return(true); } rec = null; return(false); }
private void OnCollisionEnter2D(Collision2D collision) { Destroy(gameObject); IHitable hitable = collision.collider.GetComponent <IHitable>(); if (hitable != null) { hitable.Hit(damage); } }
public bool Hit(Ray r, double t_min, double t_max, out HitRecord rec) { var ray_moved = new Ray(r.Origin - _offset, r.Direction, r.Time); if (_hitable.Hit(ray_moved, t_min, t_max, out rec)) { rec.Displace(_offset); return(true); } return(false); }
public bool Hit(Ray r, float tMin, float tMax, ref HitRecord rec) { var moved = new Ray(r.Origin - displacement, r.Direction, r.Time); if (ptr.Hit(moved, tMin, tMax, ref rec)) { rec.P += displacement; return(true); } return(false); }
private void OnTriggerEnter2D(Collider2D collision) { if (inHitTags(collision.tag) || (target == null && hasTarget)) { IHitable hitableObject = collision.GetComponent <IHitable>(); if (hitableObject != null) { hitableObject.Hit(damage); } Destroy(gameObject); } }
public void CollideWith(Collider2D collision) { IHitable hitOptions = collision.GetComponentInParent <IHitable>(); if (hitOptions != null) { hitOptions.Hit(damage); } launchTimer = 0.0f; launching = false; }
//Checks if attacking and something is not itself and attack cooldown is ok private void OnTriggerStay(Collider other) { if (_attacking && other.gameObject != gameObject && _attkTimer > _attkRate) { IHitable hit = other.GetComponent <IHitable>(); if (hit != null) { hit.Hit(); _attkTimer = 0; } } }
public bool Hit(Ray r, double tMin, double tMax, out HitRecord rec) { if (ptr.Hit(r, tMin, tMax, out rec)) { rec.normal = -rec.normal; return(true); } else { return(false); } }
// by the animation event public void OnAttack() { RaycastHit hit; if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, attackDistance + 0.5f)) { IHitable hitable = hit.collider.gameObject.GetComponent(typeof(IHitable)) as IHitable; if (hitable != null) { hitable.Hit(new HitInfo(damage, hit.point, false, HitInfo.HitSources.Enemy)); } } }
private static Vec3 Color(Ray ray, IHitable geometry, int depth = 0) { if (geometry.Hit(ray, 0.001, Double.MaxValue, out HitInfo hit)) { if (depth < maxDepth && hit.material.Scatter(ray, hit, out Vec3 attenuation, out Ray scattered)) { return(attenuation * Color(scattered, geometry, depth + 1)); } else { return(Vec3.zero); } }
// ----------------------------------------------------------------------------------- // CheckHit // ----------------------------------------------------------------------------------- protected virtual void CheckHit() { RaycastHit hit; if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, 1f, LayersHelper.DefaultEnemyPlayer)) { IHitable hitable = hit.collider.gameObject.GetComponent(typeof(IHitable)) as IHitable; if (hitable != null) { hitable.Hit(new HitInfo(damage, hit.point, true, owner)); } Death(); } }
public void CollideWith(Collider2D collision) { IHitable hitOptions = collision.GetComponentInParent <IHitable>(); if (hitOptions != null) { hitOptions.Hit(damage); enemyHit = true; } else { wallHit = true; } }
public bool Hit(Ray r, double tMin, double tMax, out HitRecord rec) { Ray movedR = new Ray(r.Origin - offset, r.Direction, r.Time); if (ptr.Hit(movedR, tMin, tMax, out rec)) { rec.p += offset; return(true); } else { return(false); } }
public bool Hit(Ray r, double t_min, double t_max, out HitRecord rec) { var origin = RotateInverse(r.Origin); var direction = RotateInverse(r.Direction); var ray_rotated = new Ray(origin, direction, r.Time); if (_hitable.Hit(ray_rotated, t_min, t_max, out rec)) { var p = Rotate(rec.P); var n = Rotate(rec.Normal); rec = new HitRecord(rec.T, rec.U, rec.V, p, n, rec.Material); return(true); } return(false); }
private ColorVector GetRayColor(Ray ray, IHitable world) { HitRecord hr = world.Hit(ray, 0.0f, float.MaxValue); if (hr != null) { return((0.5f * new Vector3(hr.Normal.X + 1.0f, hr.Normal.Y + 1.0f, hr.Normal.Z + 1.0f)).ToColorVector()); } else { var unitDirection = ray.Direction.ToUnitVector(); float t = 0.5f * (unitDirection.Y + 1.0f); return((((1.0f - t) * Vector3.One) + (t * new Vector3(0.5f, 0.7f, 1.0f))).ToColorVector()); } }
public void CollideWith(Collider2D hit) { if (scanningPlayer) { player = hit.GetComponentInParent <Transform>(); } else { IHitable hitOptions = hit.GetComponent <IHitable>(); if (hitOptions != null) { hitOptions.Hit(damage); } } }
private Vec3 RaytraceColor(Ray r, IHitable hitable, int depth) { HitRecord rec; if (hitable.Hit(r, 0.001, Double.MaxValue, out rec)) { Ray scattered; Vec3 attenuation; if (depth < 50 && rec.Material.Scatter(r, rec, out attenuation, out scattered)) { return(attenuation * RaytraceColor(scattered, hitable, depth + 1)); } return(Vec3.Create(0.0)); } return(CreateSky(r)); }
private ColorVector GetRayColor(Ray ray, IHitable world) { // the 0.001 corrects for the "shadow acne" HitRecord hr = world.Hit(ray, 0.001f, float.MaxValue); if (hr != null) { var target = hr.P + hr.Normal + Vector3Extensions.GetRandomInUnitSphere(); return(0.5f * GetRayColor(new Ray(hr.P, target - hr.P), world)); } else { var unitDirection = ray.Direction.ToUnitVector(); float t = 0.5f * (unitDirection.Y + 1.0f); return((((1.0f - t) * Vector3.One) + (t * new Vector3(0.5f, 0.7f, 1.0f))).ToColorVector()); } }