private CameraState UpdateMoveCamera() { if (m_enableMovementDampening) { transform.parent.rotation = Quaternion.Lerp(transform.parent.rotation, m_targetRotationQt, Time.deltaTime * m_orbitDampening); transform.localPosition = new Vector3( Mathf.Lerp(transform.localPosition.x, m_targetTransform.x, Time.deltaTime * m_scrollDampening), Mathf.Lerp(transform.localPosition.y, m_targetTransform.y, Time.deltaTime * m_scrollDampening), Mathf.Lerp(transform.localPosition.z, m_targetTransform.z, Time.deltaTime * m_scrollDampening)); } else { transform.parent.rotation = m_targetRotationQt; transform.localPosition = m_targetTransform; } if (Mathf.Abs(transform.localPosition.x - m_targetTransform.x) < 1.0 && Mathf.Abs(transform.localPosition.y - m_targetTransform.y) < 1.0 && Mathf.Abs(transform.localPosition.z - m_targetTransform.z) < 1.0 && Quaternion.Angle(transform.parent.rotation, m_targetRotationQt) < 1.0) { // Is the observed visible, but invisible because of a change in camera position? // if (m_isObservedVisible) if (m_observed[m_indexObserved].activeSelf) { // If the observed object is a particle system, then use the default Randomization member function. ParticleObservation po = m_observed[m_indexObserved].GetComponent <ParticleObservation>(); if (po != null) { // Since the observed can be seen, then randomize its appearance. The observed may take time to complete // the change in it's appearance, so we will wait in the state machine using CameraState.Rendering. po.Randomize(); } // Allow time for the observed to finalize it's appearance. return(CameraState.Rendering); } else { // The observed is invisible, so skip rendering. return(CameraState.Rendered); } } // The camera is not yet in position, so remain in this state. return(CameraState.InMotion); }
private CameraState WaitForRandomize() { ParticleObservation po = m_observed[m_indexObserved].GetComponent <ParticleObservation>(); if (po != null) { if (po.IsRandomizeFinished()) { return(CameraState.Rendered); } else { return(CameraState.Rendering); } } return(CameraState.Rendered); }
/// <summary> /// Calculate the percentage of the particle system that is visible in the camera's field of /// view. This is useful for determining if enough smoke is visible in the randomly placed /// camera. /// </summary> /// <param name="camera">Unity Camera object</param> /// <param name="go">Unity GameObject</param> /// <returns> /// true: if enough of the particle system is visible, as determined /// by the ParticleObservation property /// false: if not enough of the particle system is visible</returns> public bool IsInsidePercent(Camera camera, GameObject go) { ParticleSystem m_System = go.GetComponent <ParticleSystem>(); if (m_System == null) { Debug.Log("Error: Observation does not have a particle system."); return(false); } // Create the particle buffer, if has not already been created. if (m_Particles == null || m_Particles.Length < m_System.main.maxParticles) { m_Particles = new ParticleSystem.Particle[m_System.main.maxParticles]; } ParticleObservation po = go.GetComponent <ParticleObservation>(); if (po == null) { Debug.Log("Observation does not contain a ParticleObservation component."); return(false); } Renderer m_Renderer = go.GetComponent <Renderer>(); if (!m_Renderer.isVisible) { Debug.Log("Observation is being culled from the camera view."); return(false); } int numParticlesAlive = m_System.GetParticles(m_Particles); int numActiveParticles = 0; int numInactiveParticles = 0; int isBehindPlaneCount = 0; int isOffscreenCount = 0; for (int i = 0; i < numParticlesAlive; i++) { bool isBehindPlane = false; Vector3 cameraNormal = camera.transform.TransformDirection(Vector3.forward); Vector3 vectorFromCamera = m_Particles[i].position - camera.transform.position; float cameraNormalDot = Vector3.Dot(cameraNormal, vectorFromCamera); if (cameraNormalDot <= 0) { isBehindPlane = true; isBehindPlaneCount++; } bool isOffscreen = false; Vector3 particleScreen = camera.WorldToViewportPoint(m_Particles[i].position); // Use values above between 0 and 1 to assure that the particles remain away from the edige // of the FOV, in this case .1 and .9. // TODO-JYW: Should this be parameterized? if (particleScreen.x < .2 || particleScreen.x > .8 || particleScreen.y < .2 || particleScreen.y > .8) { isOffscreen = true; isOffscreenCount++; } if (!isBehindPlane && !isOffscreen) { numActiveParticles++; } else { numInactiveParticles++; } } // Is the number of active particles high enough? Debug.Log(string.Format("Behind screen: {0}, Off screen: {1}, Active: {2}, Max: {3}, Percent: {4}", isBehindPlaneCount, isOffscreenCount, numActiveParticles, (float)(numActiveParticles + numInactiveParticles), (float)numActiveParticles / (float)(numActiveParticles + numInactiveParticles))); return(((float)numActiveParticles / (float)(numActiveParticles + numInactiveParticles)) >= po.m_percentVisible); }