コード例 #1
0
        public static GraphicsDevice CreateOutputTextureDevice(IRenderableSurface window)
        {
            var adapter = GetAdapter();
            var proxy   = new RenderToTextureDeviceProxy(adapter, window.Size);

            return(new GraphicsDevice(proxy, window.Size, adapter.Description));
        }
コード例 #2
0
 //public SynchronizedGraphics(IFrameRenderableSurface surface)
 //    : this(GraphicsDeviceFactory.CreateOutputTargetView(surface), surface) {
 //}
 SynchronizedGraphics(GraphicsDevice device, IFrameRenderableSurface surface)
 {
     Device               = device;
     surface.Resized     += OnResized;
     surface.Invalidated += OnInvalidated;
     this.surface         = surface;
     synchronizer         = new SynchronizationContext <SynchronizedGraphics, Size>(this);
 }
コード例 #3
0
 public SynchronizedGraphics(IFrameRenderableSurface surface)
 {
     Device               = GraphicsDeviceFactory.CreateOutputTargetView(surface);//CreateOutputTextureDevice
     surface.Resized     += OnResized;
     surface.Invalidated += OnInvalidated;
     this.surface         = surface;
     synchronizer         = new SynchronizationContext <SynchronizedGraphics, Size>(this);
 }
コード例 #4
0
 public SynchronizedGraphics(IRenderableWindow surface)
 {
     Device               = GraphicsDeviceFactory.CreateOutputHandleDevice(surface);
     surface.Resized     += OnResized;
     surface.Invalidated += OnInvalidated;
     this.surface         = surface;
     synchronizer         = new SynchronizationContext <SynchronizedGraphics, Size>(this);
 }
コード例 #5
0
        RenderEngine(GraphicsDevice device, IRenderableSurface surface,
                     IInputManager inputManager, IContextState context, EngineNotificator notificator)
            : base(surface, inputManager, context, notificator)
        {
            Graphics = new SynchronizedGraphics(surface, device);

            var includes = new System.Collections.Generic.Dictionary <string, IIncludeResourse>();

            includes.Add("Common", new IncludeResourse("Common", "D3DLab.Toolkit._CommonShaders.Common.hlsl"));

            Graphics.Device.Compilator.AddInclude(new D3DLab.SDX.Engine.Shader.D3DIncludeAdapter(includes));
        }
コード例 #6
0
        public Vector3 ScreenToVector3(Vector2 screen, CameraState camera, IRenderableSurface window)
        {
            var winW = window.Size.Width;
            var winH = window.Size.Height;

            var c = UnProject(screen, camera, window);

            var plane = new SharpDX.Plane(camera.Position.ToSDXVector3(), camera.LookDirection.ToSDXVector3());
            var ray   = new SharpDX.Ray(c.Position.ToSDXVector3(), -c.Direction.ToSDXVector3());
            var inter = plane.Intersects(ref ray, out SharpDX.Vector3 point);

            return(new Vector3(point.X, point.Y, point.Z));
        }
コード例 #7
0
ファイル: CameraGameObject.cs プロジェクト: GreyArmor/d3dlab
        public static CameraObject UpdateOrthographic <TRenderSystem>
            (ElementTag camera, IContextState context, IRenderableSurface win)
        {
            var manager = context.GetEntityManager();

            var obj = new CameraObject(camera, "OrthographicCamera");

            manager.GetEntity(camera)
            .AddComponent(new OrthographicCameraComponent(win.Size));

            {//entities ordering
                context.EntityOrder
                .RegisterOrder <TRenderSystem>(camera, 0)
                .RegisterOrder <DefaultInputSystem>(camera, 0);
            }

            return(obj);
        }
コード例 #8
0
        public DefaultEngine(IRenderableSurface surface, IInputManager inputManager, IContextState context, EngineNotificator notificator)
        {
            Context          = context;
            this.Surface     = surface;
            this.Notificator = notificator;
            InputManager     = inputManager;
            tokensource      = new CancellationTokenSource();
            token            = tokensource.Token;

            WorldTag = new ElementTag("World");
            context.GetEntityManager()
            .CreateEntity(WorldTag)
            .AddComponent(new PerfomanceComponent());

            CameraTag = new ElementTag("Camera");
            context.GetEntityManager()
            .CreateEntity(CameraTag);
            context.GetSynchronizationContext().Synchronize(-1);
        }
コード例 #9
0
        public Vector2 Vector3ToScreen(Vector3 world, CameraState camera, IRenderableSurface window)
        {
            // Convert the given 3D point to homogenous
            var screenPosition = new Vector4(world, 1);

            // Push the 3D point through the camera transformation pipeline
            screenPosition = Vector4.Transform(screenPosition, camera.ViewMatrix);
            screenPosition = Vector4.Transform(screenPosition, camera.ProjectionMatrix);
            screenPosition = screenPosition / screenPosition.W;

            // At this point our screen position is the camera world ranging from
            // -1 to 1
            // We need adjust to our actual screen width and height
            var x = ((screenPosition.X + 1.0f) / 2.0f) * window.Size.Width;
            //don't forget the flipping of the y coordinate, since the origin of the window is in a different corner:
            var y = ((-screenPosition.Y + 1.0f) / 2.0f) * window.Size.Height;

            return(new Vector2(x, y));
        }
コード例 #10
0
        void Unproject(IRenderableSurface window, ref Vector3 source, ref Matrix4x4 matrix, out Vector3 vector)
        {
            var X        = 0;
            var Y        = 0;
            var MinDepth = 0f;
            var MaxDepth = 1f;

            vector.X = (((source.X - X) / (window.Size.Width)) * 2f) - 1f;
            vector.Y = -((((source.Y - Y) / (window.Size.Height)) * 2f) - 1f);
            vector.Z = (source.Z - MinDepth) / (MaxDepth - MinDepth);

            float a = (((vector.X * matrix.M14) + (vector.Y * matrix.M24)) + (vector.Z * matrix.M34)) + matrix.M44;

            vector = Vector3.Transform(vector, matrix);

            if (!SharpDX.MathUtil.IsOne(a))
            {
                vector = (vector / a);
            }
        }
コード例 #11
0
ファイル: CameraGameObject.cs プロジェクト: GreyArmor/d3dlab
        public static CameraObject CreateOrthographic <TRenderSystem, TToolkitFrameProperties>(
            IContextState context, IRenderableSurface win)
            where TRenderSystem : BaseRenderSystem <TToolkitFrameProperties>
            where TToolkitFrameProperties : IToolkitFrameProperties
        {
            var manager   = context.GetEntityManager();
            var cameraTag = new ElementTag("CameraEntity_" + Interlocked.Increment(ref cameras));

            var obj = new CameraObject(cameraTag, "OrthographicCamera");

            manager.CreateEntity(cameraTag)
            .AddComponent(new OrthographicCameraComponent(win.Size));

            {//entities ordering
                context.EntityOrder
                .RegisterOrder <TRenderSystem>(cameraTag, 0)
                .RegisterOrder <DefaultInputSystem>(cameraTag, 0);
            }

            return(obj);
        }
コード例 #12
0
        public Ray UnProject(Vector2 screen, CameraState camera, IRenderableSurface window)
        {
            var winW = window.Size.Width;
            var winH = window.Size.Height;

            var matrix = camera.ViewMatrix * camera.ProjectionMatrix;

            Matrix4x4.Invert(matrix, out matrix);

            //по X,Y позицией курсора, по Z: 0-мин. глубина, 1-максимальная глубина.
            var nearSource = new Vector3(screen, 0);
            var farSource  = new Vector3(screen, 1);

            Unproject(window, ref nearSource, ref matrix, out var nearPoint);
            Unproject(window, ref farSource, ref matrix, out var farPoint);

            //вычисляем направление и нормируем его.
            var direction = farPoint - nearPoint;

            direction.Normalize();

            return(new Ray(nearPoint, direction));
            //return UnProject(camera, winW, winH, screen);
        }