Exemplo n.º 1
0
        private void ViveRightController_TriggerUnclicked(object sender, ClickedEventArgs e)
        {
            switch (ViveBridge.InteractionMode)
            {
            case InteractionMode.ScalePrefabs:
            case InteractionMode.Manipulation:
                ReleaseObject();
                DisplayBox(ViveBridge.CollidedName, false);
                break;

            case InteractionMode.SpawnPrimitives:
                Vector3 primitivePosition = VivePawn.CalculatePrimitivePosition(ViveManipulator.MinimumPrimitiveDistance,
                                                                                transform.position, transform.forward);
                primitivePosition.y -= ViveManipulator.PrimitiveScale;
                if (ViveBridge.IndicatorCount == 8)
                {
                    return;
                }
                var primitive = SpawnFactory.Spawn("Prefabs/Scene1/SphereMarker", primitivePosition, transform.rotation, Vector3.zero, false);
                primitiveManager.RegisterPrimitive(primitive);
                primitiveManager.RegisterPosition(primitivePosition);
                ViveBridge.IndicatorCount++;
                UpdateTextMesh();
                break;

            case InteractionMode.SpawnObjects:
                PlaceObject();
                break;
            }
        }
Exemplo n.º 2
0
        GameObject Calculate2(bool network = true)
        {
            List <Vector3> plane1    = points.Take(4).ToList();
            List <Vector3> plane2    = new List <Vector3>();
            float          averageY1 = plane1.Select(p => p.y).Average();
            float          averageY2 = 0;

            plane1.Sort(Less);

            if (points.Count == 8)
            {
                plane2    = points.Skip(4).Take(4).ToList();
                averageY2 = points.Count == 8 ? plane2.Select(p => p.y).Average() : 0;
                plane2.Sort(Less);
            }

            center = Average(points);

            Vector2 a = new Vector2(plane1[0].x, plane1[0].z);
            Vector2 b = new Vector2(plane1[1].x, plane1[1].z);
            Vector2 c = new Vector2(plane1[2].x, plane1[2].z);
            Vector2 d = new Vector2(plane1[3].x, plane1[3].z);

            Vector2 ab = b - a;
            Vector2 bc = c - b;

            float angle;
            float angleRight = 0;
            float angleY;
            float width = ab.magnitude;
            float depth = bc.magnitude;

            if (Mathf.Abs(width - depth) <= 0.05)
            {
                bc    = (c - a);
                depth = bc.magnitude;
            }

            float abR = Vector2.Angle(Vector2.right, ab);
            float abU = Vector2.Angle(Vector2.up, ab);
            float bcR = Vector2.Angle(Vector2.right, bc);
            float bcU = Vector2.Angle(Vector2.up, bc);

            if (AngleDir(ab, Vector2.up) > 0)
            {
                angle = abU > 90 ? abR: 180 - abR;
            }
            else
            {
                angle = bcU > 90 ? 180 - abR : abR;
            }

            Vector3 scale = new Vector3(width, averageY1, depth);

            if (points.Count == 8)
            {
                scale.y = Mathf.Abs(averageY1 - averageY2);
            }

            Debug.Log("Angle: " + angle + "\tDir: " + AngleDir(ab, Vector2.up) + "\tabRight: " + Vector2.Angle(Vector2.right, ab) + "\tabUp: " + Vector2.Angle(Vector2.up, ab) +
                      "\n\t\t\tbcRight: " + Vector2.Angle(Vector2.right, bc) + "\tbcUp: " + Vector2.Angle(bc, Vector2.up));


            var rotation = Quaternion.AngleAxis(angle, Vector3.up);
            var position = new Vector3(center.x, points.Count == 4 ? averageY1 / 2 : center.y, center.z);

            var box = SpawnFactory.Spawn("Prefabs/Scene1/Primitive", position, rotation, scale, network);

            return(box);
        }