public bool ColideDector(Vector3 agentPosition) { float min_dist = 99; if (actor.InSolver) { for (int i = 0; i < actor.velocities.Length; ++i) { // if the particle is visually close enough to the agent. float distance = Vector3.Distance(agentPosition, actor.GetParticlePosition(i)); if (min_dist > distance) { min_dist = distance; } if (Vector3.Distance(agentPosition, actor.GetParticlePosition(i)) < 0.8) { Debug.Log("Collision happened"); return(true); } } // Debug.Log("Min Distance is : "+ min_dist); } else { Debug.LogError("solver not in use for some reason"); } return(false); }
void OnDrawGizmos() { if (actor == null || !actor.InSolver) { return; } Gizmos.color = Color.red; Vector3 com = Vector3.zero; float massAccumulator = 0; // To iterate over all particles in an actor, you can use the length of any property array. // They are all the same length. In this case, we use the invMasses array. for (int i = 0; i < actor.invMasses.Length; ++i) { if (actor.invMasses[i] > 0) { massAccumulator += 1.0f / actor.invMasses[i]; com += actor.GetParticlePosition(i) / actor.invMasses[i]; } } com /= massAccumulator; Gizmos.DrawWireSphere(com, 0.1f); }
// Update is called once per frame void OnDrawGizmos() { Vector4 b1 = new Vector4(1, 0, 0, 0); Vector4 b2 = new Vector4(0, 1, 0, 0); Vector4 b3 = new Vector4(0, 0, 1, 0); for (int i = 0; i < actor.activeParticleCount; ++i) { Vector3 position = actor.GetParticlePosition(actor.solverIndices[i]); actor.GetParticleAnisotropy(i, ref b1, ref b2, ref b3); Gizmos.color = Color.red; Gizmos.DrawRay(position, b1 * b1.w * size); Gizmos.color = Color.green; Gizmos.DrawRay(position, b2 * b2.w * size); Gizmos.color = Color.blue; Gizmos.DrawRay(position, b3 * b3.w * size); } }
// Update is called once per frame void OnDrawGizmos() { Vector4 b1 = new Vector4(1, 0, 0, 0); Vector4 b2 = new Vector4(0, 1, 0, 0); Vector4 b3 = new Vector4(0, 0, 1, 0); for (int i = 0; i < actor.activeParticleCount; ++i) { Vector3 position = actor.GetParticlePosition(actor.solverIndices[i]); Quaternion quat = actor.GetParticleOrientation(actor.solverIndices[i]); Gizmos.color = Color.red; Gizmos.DrawRay(position, quat * b1 * size); Gizmos.color = Color.green; Gizmos.DrawRay(position, quat * b2 * size); Gizmos.color = Color.blue; Gizmos.DrawRay(position, quat * b3 * size); } }
private Vector3 GetPosParticle(int index) { return(actor.GetParticlePosition(GetIndexParticle(index))); }