コード例 #1
0
        public ViewControl()
        {
            // this control will be painted using some 3d API
            // no need for double buffering
            // also no need for the OS to paint it.
            this.ResizeRedraw   = false;
            this.DoubleBuffered = false;
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.Opaque, true);
            AllowDrop = true;
            m_camera  = new Camera();


            m_camera.SetPerspective((float)(Math.PI / 4), 1.0f, 0.1f, 2048);
            m_cameraController        = new MayaStyleCameraController();
            m_cameraController.Camera = m_camera;

            Sphere3F sphere = new Sphere3F(new Vec3F(0, 0, 0), 25.0f);
            float    nearZ  = m_camera.PerspectiveNearZ;

            m_camera.ZoomOnSphere(sphere);
            m_camera.PerspectiveNearZ = nearZ;
            m_camera.CameraChanged   += new EventHandler(CameraChanged);
        }
コード例 #2
0
ファイル: AABB.cs プロジェクト: tkdgur4427/SGDManagedEngine
        /// <summary>
        /// Extends box to contain sphere, initializing this box if it is currently uninitialized</summary>
        /// <param name="sphere">Input sphere</param>
        /// <returns>The extended box</returns>
        public void Extend(Sphere3F sphere)
        {
            float r = sphere.Radius;

            Extend(sphere.Center + new Vec3F(r, r, r));
            Extend(sphere.Center - new Vec3F(r, r, r));
        }
コード例 #3
0
ファイル: TestSphere3F.cs プロジェクト: zparr/ATF
        private void TestToStringWithCulture(CultureInfo culture)
        {
            CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;

            Thread.CurrentThread.CurrentCulture = culture;
            try
            {
                string listSeparator    = culture.TextInfo.ListSeparator;
                string decimalSeparator = culture.NumberFormat.NumberDecimalSeparator;
                var    o = new Sphere3F(new Vec3F(1.1f, 2.2f, 3.3f), 4.4f);

                string s = o.ToString(null, null);
                TestToStringResults(o, s, listSeparator, decimalSeparator);

                string s2 = o.ToString();
                Assert.AreEqual(s, s2);

                s = o.ToString("G", culture);
                TestToStringResults(o, s, listSeparator, decimalSeparator);

                s = o.ToString("R", culture);
                TestToStringResults(o, s, listSeparator, decimalSeparator);
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = originalCulture;
            }
        }
コード例 #4
0
        public static void ZoomOnSphere(Camera cam, Sphere3F sphere)
        {
            float nearZ = cam.PerspectiveNearZ;

            // todo refactor cam.ZoomOnSphere()
            cam.ZoomOnSphere(sphere);
            cam.PerspectiveNearZ = nearZ;
        }
コード例 #5
0
 /// <summary>
 /// Sets the DomNode attribute value to the given Sphere3F</summary>
 /// <param name="domNode">DomNode holding value</param>
 /// <param name="attribute">Attribute of the DomNode that contains the data</param>
 /// <param name="s">Sphere3F value to be set</param>
 public static void SetSphere(DomNode domNode, AttributeInfo attribute, Sphere3F s)
 {
     float[] value = new float[4];
     value[0] = s.Center.X;
     value[1] = s.Center.Y;
     value[2] = s.Center.Z;
     value[3] = s.Radius;
     domNode.SetAttribute(attribute, value);
 }
コード例 #6
0
        public static void DrawSphere(GUILayer.SimpleRenderingContext context, Sphere3F sphere, Color c)
        {
            // create matrix from AABB
            T1.Set(sphere.Center);
            float scale = 2 * sphere.Radius;

            T1.M11 = scale;
            T1.M22 = scale;
            T1.M33 = scale;
            DrawSphere(context, T1, c);
        }
コード例 #7
0
        public static void DrawSphere(Sphere3F sphere, Color c)
        {
            // create matrix from AABB
            T1.Set(sphere.Center);
            float scale = 2 * sphere.Radius;

            T1.M11 = scale;
            T1.M22 = scale;
            T1.M33 = scale;
            DrawSphere(T1, c);
        }
コード例 #8
0
        private void GenThumbnail(Uri resourceUri, string thumbnailPath)
        {
            NativeObjectAdapter gameLevel = GameEngine.GetGameLevel();

            try
            {
                IResource   resource = m_resourceService.Load(resourceUri);
                IGameObject gob      = m_resourceConverterService.Convert(resource);
                if (gob == null)
                {
                    return;
                }

                m_game.RootGameObjectFolder.GameObjects.Add(gob);

                GameEngine.SetRenderState(m_renderState);
                GameEngine.SetGameLevel(m_game.Cast <NativeObjectAdapter>());

                m_gameEngine.WaitForPendingResources();
                FrameTime fr = new FrameTime(0, 0);
                m_gameEngine.Update(fr, UpdateType.Paused);

                IBoundable boundable = gob.Cast <IBoundable>();
                Sphere3F   sphere    = boundable.BoundingBox.ToSphere();

                if (Math.Abs(sphere.Radius) <= float.Epsilon)
                {
                    sphere.Radius = 1.0f;
                }

                m_cam.SetPerspective(
                    (float)Math.PI / 4,
                    1.0f,
                    sphere.Radius * 0.01f,
                    sphere.Radius * 4.0f);


                Vec3F camPos = sphere.Center + new Vec3F(sphere.Radius, sphere.Radius, sphere.Radius) * 1.5f;
                m_cam.Set(camPos, sphere.Center, new Vec3F(0, 1, 0));

                GameEngine.Begin(m_renderSurface.InstanceId, m_cam.ViewMatrix, m_cam.ProjectionMatrix);
                GameEngine.RenderGame();
                GameEngine.End();
                GameEngine.SaveRenderSurfaceToFile(m_renderSurface.InstanceId, thumbnailPath);
                m_game.RootGameObjectFolder.GameObjects.Remove(gob);

                m_resourceService.Unload(resourceUri);
            }
            finally
            {
                GameEngine.SetGameLevel(gameLevel);
            }
        }
コード例 #9
0
        /// <summary>
        /// Gets the DomNode attribute as a Sphere3F</summary>
        /// <param name="domNode">DomNode holding value</param>
        /// <param name="attribute">Attribute of the DomNode that contains the data</param>
        /// <returns>DomNode attribute as a Sphere3F</returns>
        public static Sphere3F GetSphere(DomNode domNode, AttributeInfo attribute)
        {
            Sphere3F s = new Sphere3F();

            float[] value = domNode.GetAttribute(attribute) as float[];
            if (value != null)
            {
                s.Center = new Vec3F(value[0], value[1], value[2]);
                s.Radius = value[3];
            }
            return(s);
        }
コード例 #10
0
        /// <summary>
        /// Constructor</summary>
        /// <param name="yFOV">Y field of view, in radians</param>
        /// <param name="nearZ">Near z plane constant</param>
        /// <param name="farZ">Far z plane constant</param>
        public CanvasControl3D(float yFOV, float nearZ, float farZ)
        {
            m_camera = new Camera();
            m_camera.SetPerspective(yFOV, 1.0f, nearZ, farZ);

            m_cameraController        = new TrackBallCameraController();
            m_cameraController.Camera = m_camera;

            m_camera.CameraChanged += CameraChanged;
            Sphere3F sphere = new Sphere3F(new Vec3F(0, 0, 0), 25.0f);

            m_camera.ZoomOnSphere(sphere);
        }
コード例 #11
0
ファイル: TestSphere3F.cs プロジェクト: zparr/ATF
 private void TestToStringResults(Sphere3F o, string s, string listSeparator, string decimalSeparator)
 {
     string[] results = s.Split(new[] { listSeparator }, StringSplitOptions.RemoveEmptyEntries);
     Assert.AreEqual(results.Length, 4);
     foreach (string oneFloatString in results)
     {
         Assert.True(oneFloatString.Contains(decimalSeparator));
     }
     Assert.AreEqual(float.Parse(results[0]), o.Center.X);
     Assert.AreEqual(float.Parse(results[1]), o.Center.Y);
     Assert.AreEqual(float.Parse(results[2]), o.Center.Z);
     Assert.AreEqual(float.Parse(results[3]), o.Radius);
 }
コード例 #12
0
        /// <summary>
        /// Positions and orients the camera so that the given sphere fills the view</summary>
        /// <param name="sphere">Sphere to zoom to, in world space</param>
        public void ZoomOnSphere(Sphere3F sphere)
        {
            float d = sphere.Radius;

            if (d == 0)
            {
                d = 1;
            }

            // avoid getting too far away or too close
            if (d > FarZ)
            {
                d = FarZ;
            }
            else if (d < NearZ)
            {
                d = NearZ;
            }

            m_focusRadius = d;

            // The eye and the look-at-point are in what might be called the "world view" system.
            // So, the world coordinate of the sphere center needs to be xformed by AxisSystem.
            Vec3F lookAt;
            Vec3F up;

            GetViewVectors(out lookAt, out up);

            Vec3F lookAtPoint;

            AxisSystem.Transform(sphere.Center, out lookAtPoint);

            Vec3F eye = lookAtPoint - lookAt * d;

            Set(eye, lookAtPoint, up);

            // Adjust near plane if we're in perspective mode. Otherwise, we should leave it alone
            //  because orthographic modes might need a large negative near-Z.
            if (ViewType == ViewTypes.Perspective)
            {
                float nearZ = Math.Abs(sphere.Radius) * 0.1f;
                nearZ            = Math.Max(nearZ, 0.001f);
                PerspectiveNearZ = nearZ;
            }
        }
コード例 #13
0
        /// <summary>
        /// Fits current 3D scene</summary>
        public void Fit()
        {
            // calculate bounding sphere
            if (m_scene.Children.Count > 0)
            {
                // calculate bounding sphere
                Sphere3F sphere = CalcBoundSphere(m_scene.Children[0]);
                sphere.Radius *= 2.0f;

                float aspect = (float)m_designControl.Width / (float)m_designControl.Height;

                m_designControl.Camera.Frustum.SetPerspective(
                    (float)Math.PI / 4,
                    aspect,
                    sphere.Radius * 0.01f,
                    sphere.Radius * 5.0f);

                m_designControl.Camera.ZoomOnSphere(sphere);
            }
        }
コード例 #14
0
ファイル: GameContext.cs プロジェクト: coreafive/XLE
        public void Frame(IEnumerable <object> items)
        {
            IEnumerable <DomNode> rootDomNodes = DomNode.GetRoots(items.AsIEnumerable <DomNode>());
            AABB bound = new AABB();

            foreach (var item in items)
            {
                IBoundable boundable = null;
                DomNode    domItem   = item.As <DomNode>();
                if (domItem != null)
                {
                    foreach (var node in domItem.Lineage)
                    {
                        boundable = node.As <IBoundable>();
                        if (boundable != null)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    Slot slot = item.As <Slot>();
                    boundable = slot.Owner.As <IBoundable>();
                }

                IVisible vn = boundable.As <IVisible>();
                if (boundable != null && (vn == null || vn.Visible))
                {
                    bound.Extend(boundable.BoundingBox);
                }
            }

            if (!bound.IsEmpty)
            {
                Sphere3F sphere = bound.ToSphere();
                sphere.Radius *= 3.0f;
                IDesignView designView = Globals.MEFContainer.GetExportedValue <IDesignView>();
                Util.ZoomOnSphere(designView.ActiveView.Camera, sphere);
            }
        }
コード例 #15
0
        private Sphere3F CalcBoundSphere(SceneNode root)
        {
            Sphere3F sphere = Sphere3F.Empty;

            foreach (SceneNode node in root.Children)
            {
                IBoundable boundable   = node.DomNode.As <IBoundable>();
                Sphere3F   localSphere = new Sphere3F();

                if (boundable != null)
                {
                    localSphere.Extend(boundable.BoundingBox);
                }

                if (localSphere.Radius > 0)
                {
                    sphere.Extend(localSphere);
                }
            }

            return(sphere);
        }