Пример #1
0
        internal BoundingBoxSide(PositionName position, NVector3 extent, UIColor color = null) : base()
        {
            if (color == null)
            {
                color = Utilities.AppYellow;
            }
            Tiles      = new List <Tile>();
            this.color = color;
            this.face  = position;

            // inline Swift setup() and setupExtensions() functions
            size = Size(extent);

            var   yAxis       = Axis.Y.Normal().ToSCNVector3();
            var   xAxis       = Axis.X.Normal().ToSCNVector3();
            var   zAxis       = Axis.Z.Normal().ToSCNVector3();
            float halfTurn    = (float)Math.PI;
            float quarterTurn = (float)Math.PI / 2;

            switch (face)
            {
            case PositionName.Front:
                LocalTranslate(new SCNVector3(0, 0, extent.Z / 2));
                break;

            case PositionName.Back:
                LocalTranslate(new SCNVector3(0, 0, -extent.Z / 2));
                LocalRotate(SCNQuaternion.FromAxisAngle(yAxis, halfTurn));
                break;

            case PositionName.Left:
                LocalTranslate(new SCNVector3(-extent.X / 2, 0, 0));
                LocalRotate(SCNQuaternion.FromAxisAngle(yAxis, -quarterTurn));
                break;

            case PositionName.Right:
                LocalTranslate(new SCNVector3(extent.X / 2, 0, 0));
                LocalRotate(SCNQuaternion.FromAxisAngle(yAxis, quarterTurn));
                break;

            case PositionName.Bottom:
                LocalTranslate(new SCNVector3(0, -extent.Y / 2, 0));
                LocalRotate(SCNQuaternion.FromAxisAngle(xAxis, halfTurn));
                break;

            case PositionName.Top:
                LocalTranslate(new SCNVector3(0, extent.Y / 2, 0));
                LocalRotate(SCNQuaternion.FromAxisAngle(xAxis, -quarterTurn));
                break;
            }

            for (int index = 0; index < 12; index++)
            {
                var line = new SCNNode();
                line.Geometry = Cylinder(lineThickness, extensionLength);
                if (index < 4)
                {
                    xAxisExtLines.Add(line);
                    line.LocalRotate(SCNQuaternion.FromAxisAngle(zAxis, -quarterTurn));
                    if (index == 2 || index == 3)
                    {
                        line.LocalRotate(SCNQuaternion.FromAxisAngle(xAxis, halfTurn));
                    }
                    xAxisExtNode.AddChildNode(line);
                }
                else if (index < 8)
                {
                    yAxisExtLines.Add(line);
                    if (index == 5 || index == 7)
                    {
                        line.LocalRotate(SCNQuaternion.FromAxisAngle(xAxis, halfTurn));
                    }
                    yAxisExtNode.AddChildNode(line);
                }
                else
                {
                    zAxisExtLines.Add(line);
                    line.LocalRotate(SCNQuaternion.FromAxisAngle(xAxis, -quarterTurn));
                    zAxisExtNode.AddChildNode(line);
                }
            }

            UpdateExtensions();
            HideXAxisExtensions();
            HideYAxisExtensions();
            HideZAxisExtensions();

            AddChildNode(xAxisExtNode);
            AddChildNode(yAxisExtNode);
            AddChildNode(zAxisExtNode);
        }