Example #1
0
    void LateUpdate()
    {
        // if (Input.GetMouseButton(0) || m_alwaysOn)
        {
            Ray        ray     = Camera.main.ScreenPointToRay(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0f));
            RaycastHit hitInfo = new RaycastHit();
            if (m_particlesArea.GetComponent <Collider>().Raycast(ray, out hitInfo, 100))
            {
                float fWidth  = m_particlesArea.GetComponent <Renderer>().bounds.extents.x * 2f;
                float fRadius = (m_particlesRadius * m_particlesArea.GetWidth()) / fWidth;
                m_particlesArea.AddParticles(hitInfo.textureCoord, fRadius, m_particlesStrength * Time.deltaTime);
            }
        }

        //if (Input.GetMouseButtonDown(1))
        {
            m_previousMousePosition = Input.mousePosition;
        }

        //if (Input.GetMouseButton(1) || m_alwaysOn)
        {
            Ray        ray     = Camera.main.ScreenPointToRay(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0f));
            RaycastHit hitInfo = new RaycastHit();
            if (m_fluid.GetComponent <Collider>().Raycast(ray, out hitInfo, 100))
            {
                Vector3 direction = (Input.mousePosition - m_previousMousePosition + Vector3.up * 10f) * m_velocityStrength * Time.deltaTime;
                float   fWidth    = m_fluid.GetComponent <Renderer>().bounds.extents.x * 2f;
                float   fRadius   = (m_velocityRadius * m_fluid.GetWidth()) / fWidth;
                m_fluid.AddVelocity(hitInfo.textureCoord, direction, fRadius);
            }
            m_previousMousePosition = Input.mousePosition;
        }
    }
Example #2
0
    private void LinkToFluidSimulation()
    {
        float fResolutionRatio = m_simulation.Resolution / (float)m_nResolution;

        m_simulation.SetSize((int)(m_nWidth * fResolutionRatio), (int)(m_nHeight * fResolutionRatio));

        m_simulation.InitShaders();
        m_advectParticles.SetInts("_VelocitySize", new int[] { m_simulation.GetWidth(), m_simulation.GetHeight() });
    }
Example #3
0
    void LateUpdate()
    {
        Ray        ray     = new Ray(transform.position, new Vector3(0, 0, 1));
        RaycastHit hitInfo = new RaycastHit();

        if (m_fluid.GetComponent <Collider>().Raycast(ray, out hitInfo, 10))
        {
            float fWidth = m_fluid.GetComponent <Renderer>().bounds.extents.x * 2f;
            //float fHeight = m_fluid.renderer.bounds.extents.z * 2f;
            float fRadius = (GetRadius() * m_fluid.GetWidth()) / fWidth;
            m_fluid.AddObstacleCircle(hitInfo.textureCoord, fRadius, false);
        }
    }
Example #4
0
    Vector2 getFluidVelocity(Vector3 position)
    {
        Ray        ray     = Camera.main.ScreenPointToRay(position);
        RaycastHit hitInfo = new RaycastHit();

        if (fluid.GetComponent <Collider>().Raycast(ray, out hitInfo, 10))
        {
            Vector2 simSize       = new Vector2(fluid.GetWidth(), fluid.GetHeight());
            Vector2 posInSimSpace = new Vector2(hitInfo.textureCoord.x * simSize.x, hitInfo.textureCoord.y * simSize.y);
            Vector2 velInSimSpace = fluid.GetVelocity((int)posInSimSpace.x, (int)posInSimSpace.y) * Time.deltaTime;
            return(velInSimSpace);
        }
        return(Vector2.zero);
    }
Example #5
0
 void LateUpdate()
 {
     if (m_fluid)
     {
         Ray        ray     = new Ray(gameObject.transform.position, new Vector3(0, 0, 1));
         RaycastHit hitInfo = new RaycastHit();
         if (m_fluid.GetComponent <Collider>().Raycast(ray, out hitInfo, 10))
         {
             Vector2 simSize         = new Vector2(m_fluid.GetWidth(), m_fluid.GetHeight());
             Vector2 posInSimSpace   = new Vector2(hitInfo.textureCoord.x * simSize.x, hitInfo.textureCoord.y * simSize.y);
             Vector2 velInSimSpace   = m_fluid.GetVelocity((int)posInSimSpace.x, (int)posInSimSpace.y) * Time.deltaTime;
             Vector2 worldSize       = m_particleArea.GetRenderSize();
             Vector2 velInWorldSpace = new Vector2((velInSimSpace.x * worldSize.x) / simSize.x, (velInSimSpace.y * worldSize.y) / simSize.y);
             gameObject.transform.position = gameObject.transform.position + new Vector3(velInWorldSpace.x, velInWorldSpace.y, 0f);
         }
     }
 }
 void LateUpdate()
 {
     if (m_fluid)
     {
         Vector3 currentPosition = transform.position;
         if (m_speed != Vector3.zero)
         {
             Ray        ray     = new Ray(currentPosition, new Vector3(0, 0, 1));
             RaycastHit hitInfo = new RaycastHit();
             if (m_fluid.GetComponent <Collider>().Raycast(ray, out hitInfo, 10))
             {
                 float fWidth = m_fluid.GetComponent <Renderer>().bounds.extents.x * 2f;
                 //float fHeight = m_fluid.renderer.bounds.extents.z * 2f;
                 float fRadius = (GetRadius() * m_fluid.GetWidth()) / fWidth;
                 m_fluid.AddVelocity(hitInfo.textureCoord, -m_speed, fRadius);
             }
         }
     }
 }
    void LateUpdate()
    {
        for (int i = 0; i < Input.touchCount; ++i)
        {
            Touch      touch   = Input.GetTouch(i);
            Ray        ray     = Camera.main.ScreenPointToRay(new Vector3(touch.position.x, touch.position.y, 0f));
            RaycastHit hitInfo = new RaycastHit();
            if (m_particlesArea.GetComponent <Collider>().Raycast(ray, out hitInfo, 100))
            {
                float fWidth  = m_particlesArea.GetComponent <Renderer>().bounds.extents.x * 2f;
                float fRadius = (m_particlesRadius * m_particlesArea.GetWidth()) / fWidth;
                m_particlesArea.AddParticles(hitInfo.textureCoord, fRadius, m_particlesStrength * Time.deltaTime);

                if (touch.phase == TouchPhase.Moved)
                {
                    Vector3 direction = new Vector3(touch.deltaPosition.x, touch.deltaPosition.y) * m_velocityStrength * touch.deltaTime;
                    fWidth  = m_fluid.GetComponent <Renderer>().bounds.extents.x * 2f;
                    fRadius = (m_velocityRadius * m_fluid.GetWidth()) / fWidth;
                    m_fluid.AddVelocity(hitInfo.textureCoord, direction, fRadius);
                }
            }
        }
    }