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


C# Device.SetTransform方法代码示例

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


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

示例1: loop

 public override void loop(Device i_d3d)
 {
     lock (this._ss)
     {
         this._ms.update(this._ss);
         this._rs.drawBackground(i_d3d, this._ss.getSourceImage());
         i_d3d.BeginScene();
         i_d3d.Clear(ClearFlags.ZBuffer, Color.DarkBlue, 1.0f, 0);
         if (this._ms.isExistMarker(this.mid1))
         {
             //立方体を20mm上(マーカーの上)にずらしておく
             Matrix transform_mat2 = Matrix.Translation(0, 0, 20.0f);
             //変換行列を掛ける
             transform_mat2 *= this._ms.getD3dMarkerMatrix(this.mid1);
             // 計算したマトリックスで座標変換
             i_d3d.SetTransform(TransformType.World, transform_mat2);
             // レンダリング(描画)
             this._rs.colorCube(i_d3d, 40);
         }
         if (this._ms.isExistMarker(this.mid2))
         {
             //立方体を20mm上(マーカーの上)にずらしておく
             Matrix transform_mat2 = Matrix.Translation(0, 0, 20.0f);
             //変換行列を掛ける
             transform_mat2 *= this._ms.getD3dMarkerMatrix(this.mid2);
             // 計算したマトリックスで座標変換
             i_d3d.SetTransform(TransformType.World, transform_mat2);
             // レンダリング(描画)
             this._rs.colorCube(i_d3d, 40);
         }
         i_d3d.EndScene();
     }
     i_d3d.Present();
 }
开发者ID:whztt07,项目名称:NyARToolkitCS,代码行数:34,代码来源:Program.cs

示例2: Draw

 /// <summary>
 /// 剛体の描画
 /// </summary>
 /// <param name="device">SlimDXデバイス</param>
 public void Draw(Device device)
 {
     device.VertexFormat = PDDVertex.FVF;
     Viewport viewport = device.Viewport;
     float aspectRatio = (float)viewport.Width / (float)viewport.Height;
     Matrix view, proj;
     SlimMMDXCore.Instance.Camera.GetCameraParam(aspectRatio, out view, out proj);
     device.SetTransform(TransformState.World, Matrix.Identity);
     device.SetTransform(TransformState.View, view);
     device.SetTransform(TransformState.Projection, proj);
     device.DrawUserPrimitives(PrimitiveType.LineList, primitiveCount, lines);
     primitiveCount = 0;
 }
开发者ID:himapo,项目名称:ccm,代码行数:17,代码来源:PhysicsDebugDraw.cs

示例3: ModelCamera

 public ModelCamera(Control focusControl, ControlRender dev)
 {
     mControl = focusControl;
     focusControl.MouseClick += (obj, e) => focusControl.Focus();
     mDevice = dev.Device;
     mInput = dev.InputManager;
     mDevice.SetTransform(TransformState.View, Matrix.LookAtLH(mPosition, Vector3.Zero, Vector3.UnitZ));
 }
开发者ID:remixod,项目名称:sharpwow,代码行数:8,代码来源:ModelCamera.cs

示例4: Init

        public int Init(Device d3dDev)
        {
            try
              {
            d3dDev.RenderState.CullMode = Cull.None;
            d3dDev.RenderState.Lighting = false;

            d3dDev.RenderState.AlphaBlendEnable = true;
            d3dDev.RenderState.SourceBlend = Blend.SourceAlpha;
            d3dDev.RenderState.DestinationBlend = Blend.InvSourceAlpha;
            d3dDev.RenderState.AlphaTestEnable = true;
            d3dDev.RenderState.ReferenceAlpha = 0x10;
            d3dDev.RenderState.AlphaFunction = Compare.Greater;

            d3dDev.SamplerState[0].AddressU = TextureAddress.Clamp;
            d3dDev.SamplerState[0].AddressV = TextureAddress.Clamp;
            d3dDev.SamplerState[0].MagFilter = TextureFilter.Linear;
            d3dDev.SamplerState[0].MinFilter = TextureFilter.Linear;
            d3dDev.SamplerState[0].MipFilter = TextureFilter.Linear;

            vertexBuffer = new VertexBuffer(
              typeof(CustomVertex.PositionColoredTextured),
              4,
              d3dDev,
              Usage.WriteOnly,
              CustomVertex.PositionColoredTextured.Format,
              Pool.Managed
              );

            Surface backBuffer = d3dDev.GetBackBuffer(0, 0, BackBufferType.Mono);
            SurfaceDescription backBufferDesc = backBuffer.Description;

            float aspect = (float)backBufferDesc.Width / (float)backBufferDesc.Height;
            Matrix matProj = Matrix.PerspectiveFovLH((float)Math.PI / 4, aspect, 1.0f, 100.0f);
            d3dDev.SetTransform(TransformType.Projection, matProj);

            Vector3 from = new Vector3(1.0f, 1.0f, -3.0f);
            Vector3 at = new Vector3(0.0f, 0.0f, 0.0f);
            Vector3 up = new Vector3(0.0f, 1.0f, 0.0f);
            Matrix matView = Matrix.LookAtLH(from, at, up);
            d3dDev.SetTransform(TransformType.View, matView);

            time = GetTickCount();

            backBuffer.Dispose();
              }
              catch(DirectXException e)
              {
            return e.ErrorCode;
              }
              catch
              {
            return E_FAIL;
              }

              return 0;
        }
开发者ID:coolsula,项目名称:vidplaycorder,代码行数:57,代码来源:PlaneScene.cs

示例5: UpdateCamera

        public void UpdateCamera(Device dev, TimeSpan diff)
        {
            if (Input.InputManager.Input.HasFocus == false)
                return;

            bool changed = false;
            var inp = Input.InputManager.Input;
            float sensitivity = Game.GameManager.GameWindow.PropertyPanel.CameraSensitivity;

            if (inp[Keys.W])
            {
                mPosition += (float)diff.TotalSeconds * 50.0f * Vector3.UnitX;
                mTarget += (float)diff.TotalSeconds * 50.0f * Vector3.UnitX;
                changed = true;
            }
            if (inp[Keys.S])
            {
                mPosition -= (float)diff.TotalSeconds * 50.0f * Vector3.UnitX;
                mTarget -= (float)diff.TotalSeconds * 50.0f * Vector3.UnitX;
                changed = true;
            }
            if (inp[Keys.D])
            {
                var change = (float)diff.TotalSeconds * 50.0f * Vector3.UnitY;
                mPosition += change;
                mTarget += change;
                changed = true;
            }
            if (inp[Keys.A])
            {
                var change = (float)diff.TotalSeconds * 50.0f * Vector3.UnitY;
                mPosition -= change;
                mTarget -= change;
                changed = true;
            }
            if (inp[Keys.Q])
            {
                MouseWheelTurned(127);
            }
            if (inp[Keys.E])
            {
                MouseWheelTurned(-127);
            }

            if (changed)
            {
                dev.SetTransform(TransformState.View, Matrix.LookAtLH(mPosition, mTarget, mUp));
                ShaderCollection.CameraChanged(this);
                Game.GameManager.WorldManager.Update(this);
                ViewFrustum.BuildViewFrustum(dev.GetTransform(TransformState.View), dev.GetTransform(TransformState.Projection));
                Game.GameManager.InformPropertyChanged(Game.GameProperties.CameraPosition);
            }
        }
开发者ID:remixod,项目名称:sharpwow,代码行数:53,代码来源:OrthogonalCamera.cs

示例6: RunLoop

        public void RunLoop()
        {
            RunLoopCreated = true;
            mRunThread = new System.Threading.Thread(() =>
                {
                    ParentForm.Visible = true;
                    ParentForm.Visible = false;

                    var ctrl = mRenderWindow;
                    mDriver = new Direct3D();
                    mDevice = new Device(mDriver, 0, DeviceType.Hardware, ctrl.Handle, CreateFlags.HardwareVertexProcessing
                        | CreateFlags.Multithreaded,
                        new PresentParameters()
                        {
                            Windowed = true,
                            BackBufferFormat = Format.A8R8G8B8,
                            BackBufferHeight = ctrl.ClientSize.Height,
                            BackBufferWidth = ctrl.ClientSize.Width,
                            EnableAutoDepthStencil = true,
                            AutoDepthStencilFormat = Format.D24S8,
                            SwapEffect = SwapEffect.Discard,
                            DeviceWindowHandle = ctrl.Handle,
                        }
                        );

                    mDevice.SetTransform(TransformState.Projection, Matrix.PerspectiveFovLH((45.0f * (float)Math.PI) / 180.0f, ctrl.ClientSize.Width / (float)ctrl.ClientSize.Height, 0.1f, 100000.0f));
                    mDevice.SetRenderState(RenderState.Lighting, false);
                    mDevice.SetRenderState(RenderState.ZEnable, true);
                    mDevice.SetRenderState(RenderState.CullMode, Cull.None);
                    mDevice.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Linear);
                    mDevice.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Linear);
                    mDevice.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Linear);

                    InputManager = new Video.Input.InputManager();
                    InputManager.InputWindow = ctrl;
                    Camera = new ModelCamera(ctrl, this);
                    TextureManager = new Video.TextureManager(mDevice);

                    Application.Idle += (sender, args) =>
                        {
                            if (ParentForm.Visible == false)
                                return;

                            MSG msg = new MSG();
                            while (!PeekMessage(ref msg, IntPtr.Zero, 0, 0, 0))
                                RenderFrame();
                        };

                    if (LoadDone != null)
                        LoadDone();

                    LoadEvent.Set();

                    ParentForm.Visible = true;
                    Application.Run(ParentForm);
                }
            );

            mRunThread.Start();
            Game.GameManager.GameTerminated += () =>
                {
                    if (ParentForm.IsDisposed == false)
                        ParentForm.Invoke(new Action(ParentForm.Dispose));
                };
        }
开发者ID:remixod,项目名称:sharpwow,代码行数:65,代码来源:ControlRender.cs

示例7: init

        public void init(StreamWriter st)
        {
            st.WriteLine("初期化開始");

            pictureBox1.MouseWheel += new MouseEventHandler(pictureBox1_MouseWheel);

            st.WriteLine("デバイス作成の開始");
            device = new Device(new Direct3D(), 0, DeviceType.Hardware, this.pictureBox1.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters()
            {
                BackBufferWidth = this.pictureBox1.ClientSize.Width,
                BackBufferHeight = this.pictureBox1.ClientSize.Height,
                Windowed = true,
            });
            st.WriteLine("デバイス作成の終了");
            Capabilities caps = device.Capabilities;
            st.WriteLine("adapterOrdinal:" + caps.AdapterOrdinal);
            st.WriteLine("DeviceType:" + caps.DeviceType);
            if (caps.VertexShaderVersion.Major < 3)
            {
                MessageBox.Show("VertexShader3.0 以上がサポートされていません。\n現バージョン:" + caps.VertexShaderVersion);
                device.Dispose();
                Environment.Exit(0);
            }
            else if (caps.PixelShaderVersion.Major < 3)
            {
                MessageBox.Show("PixelShader3.0 以上がサポートされていません。\n現バージョン:" + caps.VertexShaderVersion);
                device.Dispose();
                Environment.Exit(0);
            }

            st.WriteLine("DeviceContextの初期化");
            DeviceContext.init(device);

            st.WriteLine("ZEnableの初期化");
            device.SetRenderState(RenderState.ZEnable, true);

            st.WriteLine("cameraの初期化");
            camera = new Camera(device);

            st.WriteLine("Floorの初期化");
            floorMap = new FloorMap(device);

            //            teapot = Mesh.CreateTeapot(device);
            //            device.SetRenderState(RenderState.ShadeMode, ShadeMode.Flat);

            st.WriteLine("照明の初期化");
            device.SetRenderState(RenderState.Lighting, true);
            device.SetLight(0, new Light() {
                Type = LightType.Directional,
                Diffuse = Color.White,
                Ambient = Color.Gray,
                Direction = new Vector3(1.0f, 1.0f, 0.0f),
            });
            device.EnableLight(0,true);
            standardLine = new StandardLine(device);
            //射影変換
            device.SetTransform(TransformState.Projection,
                                 Matrix.PerspectiveFovLH((float)(Math.PI / 4),
                                                         (float)this.pictureBox1.ClientSize.Width / (float)this.pictureBox1.ClientSize.Height,
                                                         0.1f, 1500.0f));
            //ビュー
            device.SetTransform(TransformState.View,
                                 camera.getLookAtLh());

            device.SetTransform(TransformState.World, Matrix.Identity);

            st.WriteLine("FloorModelの初期化");
            floorModel = new FloorModel(new MqoParser(device).parse(".\\projects\\sample\\model\\floor.mqo", new MqoModel()));

            st.WriteLine("初期化終了");
        }
开发者ID:kistvan,项目名称:geditor,代码行数:71,代码来源:Form1.cs

示例8: UpdateCamera

        public void UpdateCamera(Device dev, TimeSpan diff)
        {
            if (Input.InputManager.Input.HasFocus == false)
                return;

            bool changed = false;
            var inp = Input.InputManager.Input;
            float sensitivity = Game.GameManager.GameWindow.PropertyPanel.CameraSensitivity;

            if (inp[Keys.W])
            {
                mPosition += (float)diff.TotalSeconds * mFront * 50;
                mTarget += (float)diff.TotalSeconds * mFront * 50;
                changed = true;
            }
            if (inp[Keys.S])
            {
                mPosition -= (float)diff.TotalSeconds * mFront * 50;
                mTarget -= (float)diff.TotalSeconds * mFront * 50;
                changed = true;
            }
            if (inp[Keys.D])
            {
                var change = (float)diff.TotalSeconds * mRight * 50;
                mPosition += change;
                mTarget += change;
                changed = true;
            }
            if (inp[Keys.A])
            {
                var change = (float)diff.TotalSeconds * mRight * 50;
                mPosition -= change;
                mTarget -= change;
                changed = true;
            }
            if (inp[Keys.Q])
            {
                var change = (float)diff.TotalSeconds * Vector3.UnitZ * 50;
                mPosition += change;
                mTarget += change;
                changed = true;
            }
            if (inp[Keys.E])
            {
                var change = (float)diff.TotalSeconds * Vector3.UnitZ * 50;
                mPosition -= change;
                mTarget -= change;
                changed = true;
            }

            var state = Input.InputManager.Input.Mouse.State;
            if (state.IsPressed((int)SlimDX.DirectInput.MouseObject.Button2) && Game.GameManager.SelectionManager.IsModelMovement == false)
            {
                if (state.X != 0 || state.Y != 0)
                {
                    if (state.X != 0)
                    {
                        int fac = (state.X < 0) ? -1 : 1;
                        Matrix rot = Matrix.RotationZ(state.X * 0.005f * sensitivity);
                        mFront = Vector3.TransformCoordinate(mFront, rot);
                        mFront.Normalize();
                        mTarget = mPosition + mFront;
                        mRight = Vector3.TransformCoordinate(mRight, rot);
                        mRight.Normalize();
                        mUp = Vector3.TransformCoordinate(mUp, rot);
                        mUp.Normalize();
                        changed = true;
                    }
                    if (state.Y != 0)
                    {
                        int fac = (state.Y < 0) ? -1 : 1;
                        Matrix rot = Matrix.RotationAxis(mRight, state.Y * 0.005f * sensitivity);
                        mFront = Vector3.TransformCoordinate(mFront, rot);
                        mFront.Normalize();
                        mTarget = mPosition + mFront;
                        mUp = Vector3.TransformCoordinate(mUp, rot);
                        mUp.Normalize();
                        changed = true;
                    }
                }
            }

            if (changed)
            {
                dev.SetTransform(TransformState.View, Matrix.LookAtLH(mPosition, mTarget, mUp));
                ShaderCollection.CameraChanged(this);
                Game.GameManager.WorldManager.Update(this);
                ViewFrustum.BuildViewFrustum(dev.GetTransform(TransformState.View), dev.GetTransform(TransformState.Projection));
                Game.GameManager.InformPropertyChanged(Game.GameProperties.CameraPosition);
            }
        }
开发者ID:remixod,项目名称:sharpwow,代码行数:91,代码来源:Camera.cs

示例9: GetSceneImage

        public Image GetSceneImage(Scene scene)
        {
            RecalculateData(scene);

            pp = new PresentParameters();
            pp.SwapEffect = SwapEffect.Discard;
            pp.Windowed = true;
            pp.BackBufferWidth = 512;
            pp.BackBufferHeight = 512;
            pp.BackBufferFormat = Format.A8R8G8B8;

            if(d3d != null)
            {
                d3d.Dispose();
            }
            if(device != null)
            {
                device.Dispose();
            }

            d3d = new Direct3D();
            device = new Device(d3d, 0, DeviceType.Hardware, handle, CreateFlags.HardwareVertexProcessing, pp);

            device.SetRenderState(RenderState.Lighting, true);

            for(int i = scene.lights.Count; i < maxLights; ++i)
            {
                device.EnableLight(i, false);
            }
            maxLights = scene.lights.Count;

            Modeler.Transformations.BoundingBox bb = new Modeler.Transformations.BoundingBox(scene);
            Camera cam = new Camera();
            Vector3 dir = Vector3.Normalize(bb.minBB - bb.maxBB);
            cam.position = bb.maxBB - 1 * (float)Math.Sqrt((bb.minBB.x - bb.maxBB.x) * (bb.minBB.x - bb.maxBB.x) +
                (bb.minBB.y - bb.maxBB.y) * (bb.minBB.y - bb.maxBB.y) + (bb.minBB.z - bb.maxBB.z) * (bb.minBB.z - bb.maxBB.z)) * dir;
            cam.lookAt = bb.maxBB;
            cam.fovAngle = 40;
            cam.rotateAngle = 0;

            Vector3 oldDir = defLight.Direction;

            Vector3 dirLight = new Vector3();
            dirLight.X = dir.X * (float)Math.Cos(-Math.PI / 4) + dir.Z * (float)Math.Sin(-Math.PI / 4);
            dirLight.Y = dir.Y;
            dirLight.Z = dir.Z * (float)Math.Cos(-Math.PI / 4) - dir.X * (float)Math.Sin(-Math.PI / 4);
            dir.Normalize();
            defLight.Direction = dirLight;
            device.SetLight(0, defLight);
            device.EnableLight(0, true);

            device.SetRenderState(RenderState.FillMode, FillMode.Solid);
            device.SetRenderState(RenderState.CullMode, Cull.None);
            device.SetRenderState(RenderState.ShadeMode, ShadeMode.Gouraud);

            Mesh mesh = numIndices >= 3 ? new Mesh(device, (int)numIndices / 3, scene.points.Count, MeshFlags.Managed | MeshFlags.Use32Bit, vertexElems) : null;
            VertexBuffer vb = mesh != null ? mesh.VertexBuffer : null;
            IndexBuffer ib = mesh != null ? mesh.IndexBuffer : null;

            if(mesh != null)
            {
                vb.Lock(0, 0, LockFlags.None).WriteRange(vertices);
                vb.Unlock();

                ib.Lock(0, 0, LockFlags.None).WriteRange(indices, 0, (int)numIndices);
                ib.Unlock();
            }

            Mesh selMesh = numSelIndices >= 3 ? new Mesh(device, (int)numSelIndices / 3, scene.points.Count, MeshFlags.Managed | MeshFlags.Use32Bit, vertexElems) : null;
            VertexBuffer selvb = selMesh != null ? selMesh.VertexBuffer : null;
            IndexBuffer selib = selMesh != null ? selMesh.IndexBuffer : null;

            if(selMesh != null)
            {
                selvb.Lock(0, 0, LockFlags.None).WriteRange(vertices);
                selvb.Unlock();

                selib.Lock(0, 0, LockFlags.None).WriteRange(selIndices, 0, (int)numSelIndices);
                selib.Unlock();
            }

            Viewport viewport = new Viewport(0, 0, 512, 512, 0, 1);

            Texture texture = new Texture(device, 64, 64, 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
            device.SetRenderTarget(0, texture.GetSurfaceLevel(0));

            float camRotAngle = cam.rotateAngle;
            float aspect = 1;
            float camAngle = 2.0f * (float)Math.Atan(Math.Tan(Utilities.DegToRad(cam.fovAngle) / 2.0f) / aspect);

            device.SetTransform(TransformState.View, Matrix.LookAtRH(
                cam.position,
                cam.lookAt,
                Utilities.RotatePointAroundVector(new Vector3(0, 1, 0),
                Vector3.Normalize(cam.lookAt - cam.position), camRotAngle)));

            device.SetTransform(TransformState.Projection, Matrix.PerspectiveFovRH(
                camAngle,
                aspect,
                0.01f,
//.........这里部分代码省略.........
开发者ID:BGCX261,项目名称:zpi-modeler-svn-to-git,代码行数:101,代码来源:Renderer.cs

示例10: GetBezierImage

        public Image GetBezierImage(BezierSurface bezier)
        {
            pp = new PresentParameters();
            pp.SwapEffect = SwapEffect.Discard;
            pp.Windowed = true;
            pp.BackBufferWidth = 512;
            pp.BackBufferHeight = 512;
            pp.BackBufferFormat = Format.A8R8G8B8;

            if (d3dBezier != null)
            {
                d3dBezier.Dispose();
            }
            if (deviceBezier != null)
            {
                deviceBezier.Dispose();
            }

            d3dBezier = new Direct3D();
            deviceBezier = new Device(d3d, 0, DeviceType.Hardware, handle, CreateFlags.HardwareVertexProcessing, pp);

            deviceBezier.SetRenderState(RenderState.Lighting, true);

            deviceBezier.SetLight(0, defLight);
            deviceBezier.EnableLight(0, true);

            deviceBezier.SetRenderState(RenderState.FillMode, FillMode.Solid);
            deviceBezier.SetRenderState(RenderState.CullMode, Cull.None);
            deviceBezier.SetRenderState(RenderState.ShadeMode, ShadeMode.Gouraud);

            Vertex[] gridVertices = new Vertex[bezier.OutputPoints.Length];
            Vertex[] controlVertices = new Vertex[bezier.ControlPoints.Length];

            List<int>[] vertexTriangle = new List<int>[bezier.OutputPoints.Length];
            Parallel.For(0, vertexTriangle.Length, index => vertexTriangle[index] = new List<int>());
            /*for(int i = 0; i < vertexTriangle.Length; ++i)
            {
                vertexTriangle[i] = new List<int>();
            }*/

            int[] indices = new int[3 * bezier.triangles.Count];
            //int[] selIndices = new int[3 * scene.triangles.Count];
            uint numIndices = 0;
            //uint numSelIndices = 0;

            //bool[] selPoints = new bool[scene.points.Count];
            //Parallel.For(0, selPoints.Length, index => selPoints[index] = false);

            for (int i = 0; i < bezier.triangles.Count; i++)
            {
                indices[numIndices++] = (int)bezier.triangles[i].p1;
                indices[numIndices++] = (int)bezier.triangles[i].p2;
                indices[numIndices++] = (int)bezier.triangles[i].p3;

                vertexTriangle[bezier.triangles[i].p1].Add(i);
                vertexTriangle[bezier.triangles[i].p2].Add(i);
                vertexTriangle[bezier.triangles[i].p3].Add(i);
            }

            // Liczenie normalnych siatki trojkątów
            for (int i = 0; i < bezier.OutputPoints.Length; i++)
            {
                Vector3 normal = new Vector3();
                foreach (int face in vertexTriangle[i])
                {
                    normal += Utilities.CalculateNormal(bezier.OutputPoints[(int)bezier.triangles[face].p3], bezier.OutputPoints[(int)bezier.triangles[face].p2],
                            bezier.OutputPoints[(int)bezier.triangles[face].p1]);
                }
                normal.Normalize();

                gridVertices[i].Position = new Vector3(bezier.OutputPoints[i].x, bezier.OutputPoints[i].y, bezier.OutputPoints[i].z);
                gridVertices[i].Normal = normal;
                gridVertices[i].Color = Color.Beige.ToArgb();

            }

            Mesh gridMesh = numIndices > 2 ? new Mesh(deviceBezier, (int)numIndices / 3, bezier.OutputPoints.Length, MeshFlags.Managed | MeshFlags.Use32Bit,
                                                        vertexElems) : null;
            VertexBuffer vb = gridMesh != null ? gridMesh.VertexBuffer : null;
            IndexBuffer ib = gridMesh != null ? gridMesh.IndexBuffer : null;

            if (gridMesh != null)
            {
                vb.Lock(0, 0, LockFlags.None).WriteRange(gridVertices);
                vb.Unlock();

                ib.Lock(0, 0, LockFlags.None).WriteRange(indices, 0, (int)numIndices);
                ib.Unlock();
            }

            Viewport viewport = new Viewport(0, 0, 512, 512, 0, 1);

            Texture texture = new Texture(deviceBezier, 64, 64, 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
            deviceBezier.SetRenderTarget(0, texture.GetSurfaceLevel(0));

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

            deviceBezier.SetTransform(TransformState.View, Matrix.LookAtRH(
                bezierCam.position,
                bezierCam.lookAt,
//.........这里部分代码省略.........
开发者ID:BGCX261,项目名称:zpi-modeler-svn-to-git,代码行数:101,代码来源:Renderer.cs

示例11: MainWindow

        /// <summary>
        /// 最上位ウインドウを作成
        /// </summary>
        public MainWindow()
        {
            // コンポーネント初期化
            InitializeComponent();

            // デバイスを作成
            Device device = new Device(
                new Direct3D(),
                0,
                DeviceType.Hardware,
                IntPtr.Zero,
                CreateFlags.HardwareVertexProcessing,
                new PresentParameters());

            // 光源を設定して有効化
            device.SetLight(0, new Light()
            {
                Type = LightType.Directional,
                Diffuse = Color.White,
                Ambient = Color.GhostWhite,
                Direction = new Vector3(0, -1, 1)
            });
            device.EnableLight(0, true);

            //射影変換を設定
            device.SetTransform(TransformState.Projection,
                Matrix.PerspectiveFovLH((float)(Math.PI / 4),
                (float)(this.Width / this.Height),
                0.1f, 20.0f));

            //ビューを設定
            device.SetTransform(TransformState.View,
                Matrix.LookAtLH(new Vector3(3, 2, -3),
                Vector3.Zero,
                new Vector3(0, 1, 0)));

            //マテリアル設定
            device.Material = new Material()
            {
                Diffuse = new Color4(Color.GhostWhite)
            };

            // 全面灰色でクリア
            device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, new Color4(0.2f, 0.2f, 0.2f), 1.0f, 0);

            // シーン開始
            device.BeginScene();

            //ティーポットを描画
            device.SetTransform(TransformState.World,
                Matrix.Translation(-3, 0, 5));
            Mesh.CreateTeapot(device).DrawSubset(0);

            //文字列を描画
            device.SetTransform(TransformState.World,
                Matrix.Translation(-4, -1, 0));
            Mesh.CreateText(device, new System.Drawing.Font("Arial", 10), "Hello, world!", 0.001f, 0.001f).DrawSubset(0);

            // シーン終了
            device.EndScene();

            // 画像をロック
            this.directXImage.Lock();

            // バックバッファー領域を指定
            this.directXImage.SetBackBuffer(D3DResourceType.IDirect3DSurface9, device.GetBackBuffer(0, 0).ComPointer);
            this.directXImage.AddDirtyRect(new Int32Rect(0, 0, directXImage.PixelWidth, directXImage.PixelHeight));

            // ロック解除
            this.directXImage.Unlock();
        }
开发者ID:aokomoriuta,项目名称:StudiesOfSlimDX,代码行数:74,代码来源:MainWindow.cs

示例12: Render

 public void Render(Device device)
 {
     device.SetTransform(TransformState.Projection, _projection);
     device.SetTransform(TransformState.View, _view);
 }
开发者ID:ousttrue,项目名称:csmeshio,代码行数:5,代码来源:View.cs

示例13: RenderXMeshesWithDevice

 private void RenderXMeshesWithDevice(Device device, Dictionary<SlimDX.Direct3D9.Mesh, RenderMesh> meshes)
 {
     foreach (SlimDX.Direct3D9.Mesh mesh in meshes.Keys)
     {
         foreach (Texture texture in meshes[mesh].Textures.Keys)
         {
             device.SetTexture(0, texture);
             foreach (Common.Tuple<Graphics.Content.Model9, Entity, string> renderObject in meshes[mesh].Textures[texture].RenderObjects)
             {
                 device.SetTransform(TransformState.World,
                     GetLatestMetaModel(renderObject.Second, renderObject.Third).GetWorldMatrix(Scene.Camera, renderObject.Second));
                 device.SetTransform(TransformState.View, Scene.Camera.View);
                 device.SetTransform(TransformState.Projection, Scene.Camera.Projection);
                 mesh.DrawSubset(0);
             }
         }
     }
 }
开发者ID:ChristianMarchiori,项目名称:DeadMeetsLead,代码行数:18,代码来源:SortedTestRenderer.cs

示例14: MainWindow

        /// <summary>
        /// 最上位ウインドウを作成
        /// </summary>
        public MainWindow()
        {
            // コンポーネント初期化
            InitializeComponent();

            // ウインドウが読み込まれたら
            this.Loaded += (sender, e) =>
            {
                // Direct3D作成
                var direct3D = new SlimDX.Direct3D9.Direct3D();

                // デバイスを初期化
                Device device = null;

                // ティーポッドと文字列を初期化
                Mesh teapod = null;
                Mesh helloWorld = null;

                // バッファーウインドウ作成
                IntPtr handle = new HwndSource(0, 0, 0, 0, 0, "buffer", IntPtr.Zero).Handle;

                // デバイスを作成
                device = new Device(direct3D, 0,
                    DeviceType.Hardware,
                    handle,
                    CreateFlags.HardwareVertexProcessing,
                    new PresentParameters()
                    {
                        BackBufferFormat = Format.X8R8G8B8,
                        BackBufferCount = 1,
                        BackBufferWidth = (int)this.Width,
                        BackBufferHeight = (int)this.Height,
                        Multisample = MultisampleType.None,
                        SwapEffect = SwapEffect.Discard,
                        EnableAutoDepthStencil = true,
                        AutoDepthStencilFormat = Format.D16,
                        PresentFlags = PresentFlags.DiscardDepthStencil,
                        PresentationInterval = PresentInterval.Default,
                        Windowed = true,
                        DeviceWindowHandle = handle
                    });

                // ティーポッドと文字列を作成
                teapod = Mesh.CreateTeapot(device);
                helloWorld = Mesh.CreateText(device, new System.Drawing.Font("Arial", 10), "Hello, world!", 0.001f, 0.001f);

                // 光源描画を有効化
                device.SetRenderState(RenderState.Lighting, true);

                // 光源を設定
                device.SetLight(0, new Light()
                {
                    Type = LightType.Directional,
                    Diffuse = Color.White,
                    Ambient = Color.GhostWhite,
                    Direction = new Vector3(0.0f, -1.0f, 0.0f)
                });

                // 光源を有効化
                device.EnableLight(0, true);

                //射影変換を設定
                device.SetTransform(TransformState.Projection,
                    Matrix.PerspectiveFovLH((float)(Math.PI / 4),
                    (float)(this.Width / this.Height),
                    0.1f, 20.0f));

                //ビューを設定
                device.SetTransform(TransformState.View,
                    Matrix.LookAtLH(new Vector3(3.0f, 2.0f, -3.0f),
                    Vector3.Zero,
                    new Vector3(0.0f, 1.0f, 0.0f)));

                //マテリアル設定
                device.Material = new Material()
                {
                    Diffuse = new Color4(Color.GhostWhite)
                };

                // 描画される時に描画処理を実行
                CompositionTarget.Rendering += (sender2, e2) =>
                {
                    // 画像をロックしてバックバッファーに設定
                    this.directXImage.Lock();
                    this.directXImage.SetBackBuffer(D3DResourceType.IDirect3DSurface9, device.GetBackBuffer(0, 0).ComPointer);

                    // フロントバッファーがあれば
                    if (directXImage.IsFrontBufferAvailable)
                    {
                        // デバイスの現在の状態を確かめて失敗したら
                        if (device.TestCooperativeLevel().IsFailure)
                        {
                            // 例外
                            throw new Direct3D9Exception("デバイスが無効です");
                        }

                        // 全面灰色でクリア
//.........这里部分代码省略.........
开发者ID:aokomoriuta,项目名称:StudiesOfOpenTK,代码行数:101,代码来源:MainWindow.cs


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