当前位置: 首页>>代码示例>>C#>>正文


C# Canguro.Project方法代码示例

本文整理汇总了C#中Canguro.Project方法的典型用法代码示例。如果您正苦于以下问题:C# Canguro.Project方法的具体用法?C# Canguro.Project怎么用?C# Canguro.Project使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Canguro的用法示例。


在下文中一共展示了Canguro.Project方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

        /// <summary>
        /// Executuion method for this command
        /// </summary>
        /// <param name="activeView"> The view to zoom </param>
        public override void Run(Canguro.View.GraphicView activeView)
        {
            /// Get the joint list
            ItemList<Joint> jList = Canguro.Model.Model.Instance.JointList;

            // We need two vectors for having mininum and maximum BB corners
            Vector3 min = new Vector3(-1, -1, -1);
            Vector3 max = new Vector3(1, 1, 1);

            /// Get maximum and minimun from joint list
            foreach (Joint j in jList)
            {
                if (j != null && j.IsVisible )
                {
                    Vector3 pos = j.Position;
                    min.X = (min.X > pos.X) ? pos.X : min.X;
                    min.Y = (min.Y > pos.Y) ? pos.Y : min.Y;
                    min.Z = (min.Z > pos.Z) ? pos.Z : min.Z;
                    max.X = (max.X < pos.X) ? pos.X : max.X;
                    max.Y = (max.Y < pos.Y) ? pos.Y : max.Y;
                    max.Z = (max.Z < pos.Z) ? pos.Z : max.Z;
                }
            }

            /// Get line list
            ItemList<LineElement> lineList = Canguro.Model.Model.Instance.LineList;
            /// When all joints are invisible, we cannot compute a BB, so lets check against line joints
            foreach (LineElement l in lineList)
            {
                if (l != null && l.IsVisible)
                {
                    Vector3 pos = l.I.Position;
                    min.X = (min.X > pos.X) ? pos.X : min.X;
                    min.Y = (min.Y > pos.Y) ? pos.Y : min.Y;
                    min.Z = (min.Z > pos.Z) ? pos.Z : min.Z;
                    max.X = (max.X < pos.X) ? pos.X : max.X;
                    max.Y = (max.Y < pos.Y) ? pos.Y : max.Y;
                    max.Z = (max.Z < pos.Z) ? pos.Z : max.Z;

                    pos = l.J.Position;
                    min.X = (min.X > pos.X) ? pos.X : min.X;
                    min.Y = (min.Y > pos.Y) ? pos.Y : min.Y;
                    min.Z = (min.Z > pos.Z) ? pos.Z : min.Z;
                    max.X = (max.X < pos.X) ? pos.X : max.X;
                    max.Y = (max.Y < pos.Y) ? pos.Y : max.Y;
                    max.Z = (max.Z < pos.Z) ? pos.Z : max.Z;
                }
            }
            if (min.X < max.X)
            {
                // Diagonal de bounding box
                Vector3 diagonal = max - min;
                Vector3 center = min + Vector3.Multiply(diagonal, 0.5f);
                float modelSize = Vector3.Length(diagonal);
                float screenSize = (float)Math.Min(activeView.Viewport.Height-20, activeView.Viewport.Width-20);

                /************ Codigo genial **************
                 * Calculo de escala
                 * Calculo de traslacion
                 *****************************************/

                // Translation to bounding box center
                Vector3 centerProjected = center;
                activeView.Project(ref centerProjected);

                MouseEventArgs e = new MouseEventArgs(MouseButtons.Left, 1, (int)centerProjected.X, (int)centerProjected.Y, 0);
                activeView.ArcBallCtrl.OnBeginPan(e);

                e = new MouseEventArgs(MouseButtons.Left, 1, activeView.Viewport.Width/2, activeView.Viewport.Height/2, 0);
                activeView.ArcBallCtrl.OnMovePan(e);

                activeView.ViewMatrix = activeView.ArcBallCtrl.ViewMatrix;

                // View volume scaling

                Vector2[] maxDims = findMaxPoints(min, max, activeView);
                float sizeX = maxDims[1].X - maxDims[0].X;
                float sizeY = maxDims[1].Y - maxDims[0].Y;

                float newScale = 0.0f;

                newScale  = screenSize * activeView.ArcBallCtrl.ScalingFac / (float)Math.Max(sizeX, sizeY);

                activeView.ArcBallCtrl.ZoomAbsolute(newScale);
                activeView.ViewMatrix = activeView.ArcBallCtrl.ViewMatrix;
            }
        }
开发者ID:rforsbach,项目名称:Treu-Structure,代码行数:91,代码来源:ZoomAll.cs

示例2: Snap

        public override float Snap(Canguro.View.GraphicView activeView, Point mousePoint)
        {
            Vector3 mousePosition;

            // Project points
            Vector3 p = position, p2 = position + direction;
            activeView.Project(ref p);
            activeView.Project(ref p2);
            Vector3 v = p2 - p;
            p.Z = 0.1f;

            mousePosition = new Vector3((float)mousePoint.X, (float)mousePoint.Y, 0.1f);
            float r = Vector3.Dot(v, mousePosition - p) / Vector3.Dot(v, v);
            Vector3 snapPoint = p + Vector3.Scale(v, r);

            snapPosition = position + Vector3.Scale(direction, r);

            Vector3 d = mousePosition - snapPoint;
            return lastSnapFitness = Vector3.Dot(d, d);
        }
开发者ID:rforsbach,项目名称:Treu-Structure,代码行数:20,代码来源:LineMagnet.cs

示例3: findMaxPoints

        /// <summary>
        /// From min and max coords of the BB, project them according to the active view, for determining zooming scale
        /// </summary>
        /// <param name="min"> The min coord of BB </param>
        /// <param name="max"> The max coord of BB </param>
        /// <param name="activeView"> Active view to zoom </param>
        /// <returns> Returns an array of two vectos in screen space </returns>
        private Vector2[] findMaxPoints(Vector3 min, Vector3 max, Canguro.View.GraphicView activeView)
        {
            Vector3[] boundingVolume = new Vector3[8];

            Vector2[] screen = new Vector2[2];

            screen[0] = new Vector2(float.MaxValue, float.MaxValue);
            screen[1] = new Vector2(float.MinValue, float.MinValue);

            boundingVolume[0] = min;
            boundingVolume[1] = new Vector3(min.X, min.Y, max.Z);
            boundingVolume[2] = new Vector3(max.X, min.Y, max.Z);
            boundingVolume[3] = new Vector3(max.X, min.Y, min.Z);

            boundingVolume[4] = new Vector3(max.X, max.Y, min.Z);
            boundingVolume[5] = max;
            boundingVolume[6] = new Vector3(min.X, max.Y, max.Z);
            boundingVolume[7] = new Vector3(min.X, max.Y, min.Z);

            for (int i = 0; i < boundingVolume.GetLength(0); ++i)
            {
                activeView.Project(ref boundingVolume[i]);
                screen[0].X = (screen[0].X > boundingVolume[i].X) ? boundingVolume[i].X : screen[0].X;
                screen[0].Y = (screen[0].Y > boundingVolume[i].Y) ? boundingVolume[i].Y : screen[0].Y;

                screen[1].X = (screen[1].X < boundingVolume[i].X) ? boundingVolume[i].X : screen[1].X;
                screen[1].Y = (screen[1].Y < boundingVolume[i].Y) ? boundingVolume[i].Y : screen[1].Y;
            }

            return screen;
        }
开发者ID:rforsbach,项目名称:Treu-Structure,代码行数:38,代码来源:ZoomAll.cs

示例4: Snap

        public override float Snap(Canguro.View.GraphicView activeView, Point mousePoint)
        {
            // Project point
            Vector3 p = position, q = new Vector3((float)mousePoint.X, (float)mousePoint.Y, 0.1f);
            activeView.Project(ref p);
            p.Z = 0.1f;

            Vector3 d = q - p;
            return lastSnapFitness = Vector3.Dot(d, d);
        }
开发者ID:rforsbach,项目名称:Treu-Structure,代码行数:10,代码来源:PointMagnet.cs


注:本文中的Canguro.Project方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。