Beispiel #1
0
    /*
     * Description : Raycast forward to detect any paint receiver, when hit store the surface's normal and texcoord.
     */
    private void CalculateCollision()
    {
        Vector3 direction = transform.position - m_previousPosition;
        float   distance  = direction.magnitude;

        if (distance == 0.0f)
        {
            return;
        }

        direction /= distance;

        Ray        ray = new Ray(m_previousPosition, direction);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, distance, m_layerMask, QueryTriggerInteraction.Ignore))
        {
            m_paintReceiver = hit.collider.gameObject.GetComponent <PaintReceiver>();
            if (m_paintReceiver != null)
            {
                m_texCoord   = hit.textureCoord;
                m_wallNormal = hit.normal;

                if (PhotonNetwork.room != null)
                {
                    photonView.RPC("BroadcastIsColliding", PhotonTargets.All, hit.point);
                }
                else
                {
                    BroadcastIsColliding(hit.point);
                }
            }
        }
    }
Beispiel #2
0
    public void Initialize(PaintReceiver newPaintReceiver)
    {
        stamp      = new Stamp(brush);
        stamp.mode = paintMode;

        paintReceiver         = newPaintReceiver;
        paintReceiverCollider = newPaintReceiver.GetComponent <Collider>();
    }
Beispiel #3
0
    /*
     * Description : Calculating where the marker should move and rotate, after that raycast to get a new texcoord or if
     * marker is hitting new writable surface.
     * Note : Change this function to get different movement behaviour.
     */
    private void CalculatePencilPositionAndRotation()
    {
        //Marker will snap to the surface and move around, and always stay straight up from the surface.
        //Change this block of code for different movement behaviour.
        Vector3    offset          = m_rightController.transform.position - m_hitPoint;
        Vector3    vectorOnSurface = Vector3.ProjectOnPlane(offset, m_wallNormal);
        Vector3    targetPosition  = m_hitPoint + vectorOnSurface;
        Quaternion targetRotation  = Quaternion.LookRotation(-m_wallNormal);


        if (PhotonNetwork.room != null)
        {
            photonView.RPC("BroadcastPencilPositionAndRotation", PhotonTargets.All, targetPosition, targetRotation);
        }
        else
        {
            BroadcastPencilPositionAndRotation(targetPosition, targetRotation);
        }

        Ray        ray = new Ray(transform.position - (transform.forward * M_RAYCAST_OFFSET_DISTANCE), transform.forward);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, M_RAYCAST_DISTANCE, m_layerMask, QueryTriggerInteraction.Ignore))
        {
            PaintReceiver paintReceiver = hit.collider.gameObject.GetComponent <PaintReceiver>();
            if (m_paintReceiver != null)
            {
                if (m_paintReceiver != paintReceiver)
                {
                    if (PhotonNetwork.room != null)
                    {
                        photonView.RPC("ChangePaintReceiver", PhotonTargets.All);
                    }
                    else
                    {
                        ChangePaintReceiver();
                    }
                    lastDrawPosition = null;
                }
                m_texCoord = hit.textureCoord;
            }

            return;
        }

        if (PhotonNetwork.room != null)
        {
            photonView.RPC("HoldToHand", PhotonTargets.All);
        }
        else
        {
            HoldToHand();
        }

        BroadcastEndLine();
    }
Beispiel #4
0
    /*
     * Description : Handle if there's a change in PaintReceiver reference.
     */
    private void ChangePaintReceiver()
    {
        Ray        ray = new Ray(transform.position - (transform.forward * M_RAYCAST_OFFSET_DISTANCE), transform.forward);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, M_RAYCAST_DISTANCE, m_layerMask, QueryTriggerInteraction.Ignore))
        {
            m_paintReceiver = hit.collider.gameObject.GetComponent <PaintReceiver>();
        }
    }
Beispiel #5
0
    /*
     * Description : Handle all variable that need to be sync when marker is colliding with the surface.
     * Argument : aHitPoint : Hit point where the raycast hit to store through all the scene
     * Note : this function will raycast once through all the scene to get the paint receiver reference.
     */
    private void BroadcastIsColliding(Vector3 aHitPoint)
    {
        m_hitPoint       = aHitPoint;
        transform.parent = null;
        m_isColliding    = true;
        Ray        ray = new Ray(transform.position - (transform.forward * M_RAYCAST_OFFSET_DISTANCE), transform.forward);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, M_RAYCAST_DISTANCE, m_layerMask, QueryTriggerInteraction.Ignore))
        {
            m_paintReceiver = hit.collider.gameObject.GetComponent <PaintReceiver>();
        }
    }
Beispiel #6
0
 public void Initialize(PaintReceiver newPaintReceiver)
 {
     m_PaintReceiver         = newPaintReceiver;
     m_PaintReceiverCollider = newPaintReceiver.GetComponent <Collider>();
 }