예제 #1
0
    void StrokeAround()
    {
        Vector3 pnt    = Random.insideUnitSphere;
        Vector3 dir    = Random.onUnitSphere;
        Stroke  stroke = new Stroke(pnt, pointPrefab, edgePrefab, worldOrigin, colors[Random.Range(0, 2)]);

        for (int i = 0; i < 10; ++i)
        {
            dir += 0.7f * Random.insideUnitSphere;
            dir.Normalize();
            pnt += 0.1f * dir;
            stroke.AddSegment(pnt);
        }
        drawing.Add(stroke);
        undoStack.Push(stroke);
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        if (!markerIsDefinitive)
        {
            Session.GetTrackables <AugmentedImage>(augmentedImages, TrackableQueryFilter.Updated);

            foreach (AugmentedImage img in augmentedImages)
            {
                if (markerPlaceholder == null)
                {
                    Anchor anchor = img.CreateAnchor(img.CenterPose);
                    markerPlaceholder = Instantiate(markerPrefab, anchor.transform);
                    markerId          = img.Name;
                    coordText.text    = "Tap when the red pyramid\nis aligned to the marker.";
                }
            }
        }

        if (Input.touchCount > 0)
        {
            // Waits for the user to close the palette before drawing
            if (palette.activeSelf)
            {
                return;
            }

            int id = Input.touches[0].fingerId;
            if (EventSystem.current.IsPointerOverGameObject(id))
            {
                return;
            }

            if (markerPlaceholder != null)
            {
                if (!markerIsDefinitive)
                {
                    markerIsDefinitive = true;

                    Vector3    p = markerPlaceholder.transform.position;
                    Quaternion r = markerPlaceholder.transform.rotation;
                    //Destroy(markerPlaceholder);
                    markerPlaceholder.SetActive(false);
                    marker = new GameObject();
                    marker.transform.position = p;
                    marker.transform.rotation = r;

                    StartCoroutine(LoadArea());
                }
                else
                {
                    Touch     touch = Input.GetTouch(0);
                    Matrix4x4 m     = cam.projectionMatrix.inverse;

                    Vector3 p = transform.localToWorldMatrix.MultiplyPoint(new Vector3(-0.001f, 0.002f, .3f));

                    if (touch.phase == TouchPhase.Began)
                    {
                        currentStroke = new Stroke(p, pointPrefab, edgePrefab, marker, paletteMaterials[currentPaletteMaterial]);
                    }
                    else if (touch.phase == TouchPhase.Ended)
                    {
                        drawing.Add(currentStroke);
                        undoStack.Push(currentStroke);
                    }
                    else
                    {
                        currentStroke.AddSegment(p);
                    }
                }
            }
            else
            {
                coordText.text = "Marker not there";
            }
        }
    }