示例#1
0
        private void checkInput()
        {
            if (mouseStateCurrent != null)
                mouseStatePrevious = mouseStateCurrent;

            mouseStateCurrent = Mouse.GetState();

            if (mouseStateCurrent.LeftButton == ButtonState.Pressed)
            {
                if (mouseStateCurrent.X < mouseStatePrevious.X)
                {
                    effect.World *= Matrix.CreateRotationY(MathHelper.ToRadians(1));
                }
                else if (mouseStateCurrent.X > mouseStatePrevious.X)
                {
                    //rotate right
                    effect.World *= Matrix.CreateRotationY(MathHelper.ToRadians(-1));
                }

                if (mouseStateCurrent.Y < mouseStatePrevious.Y)
                {
                    //rotate up
                    effect.World *= Matrix.CreateRotationX(MathHelper.ToRadians(1));
                }
                else if (mouseStateCurrent.Y > mouseStatePrevious.Y)
                {
                    //rotate down
                    effect.World *= Matrix.CreateRotationX(MathHelper.ToRadians(-1));
                }
            }

            if (mouseStateCurrent.ScrollWheelValue > mouseStatePrevious.ScrollWheelValue)
            {
                currDist += 0.2f;
                effect.View = Matrix.CreateLookAt(new Vector3(0, 0, currDist), new Vector3(0, 0, 0), Vector3.Up);
            }
            else if (mouseStateCurrent.ScrollWheelValue < mouseStatePrevious.ScrollWheelValue)
            {
                currDist -= 0.2f;
                effect.View = Matrix.CreateLookAt(new Vector3(0, 0, currDist), new Vector3(0, 0, 0), Vector3.Up);
            }

            if (keyStateCurrent != null)
                keyStatePrevious = keyStateCurrent;

            keyStateCurrent = Keyboard.GetState();

            if (keyStateCurrent.IsKeyDown(Keys.N) && !keyStatePrevious.IsKeyDown(Keys.N))
            {
                currentCorner = lrTriangleMesh.CN(currentCorner);
                int vertexIdx = lrTriangleMesh.CV(currentCorner);

                Vector3 cubePos = new Vector3((float)lrTriangleMesh.V[vertexIdx].X, (float)lrTriangleMesh.V[vertexIdx].Y, (float)lrTriangleMesh.V[vertexIdx].Z);

                currentCube = new Cube(new Vector3(0.01f, 0.01f, 0.01f), cubePos);
            }
            else if (keyStateCurrent.IsKeyDown(Keys.P) && !keyStatePrevious.IsKeyDown(Keys.P))
            {
                currentCorner = lrTriangleMesh.CP(currentCorner);
                int vertexIdx = lrTriangleMesh.CV(currentCorner);

                Vector3 cubePos = new Vector3((float)lrTriangleMesh.V[vertexIdx].X, (float)lrTriangleMesh.V[vertexIdx].Y, (float)lrTriangleMesh.V[vertexIdx].Z);

                currentCube = new Cube(new Vector3(0.01f, 0.01f, 0.01f), cubePos);
            }
            else if (keyStateCurrent.IsKeyDown(Keys.O) && !keyStatePrevious.IsKeyDown(Keys.O))
            {
                currentCorner = lrTriangleMesh.CO(currentCorner);
                int vertexIdx = lrTriangleMesh.CV(currentCorner);

                Vector3 cubePos = new Vector3((float)lrTriangleMesh.V[vertexIdx].X, (float)lrTriangleMesh.V[vertexIdx].Y, (float)lrTriangleMesh.V[vertexIdx].Z);

                currentCube = new Cube(new Vector3(0.01f, 0.01f, 0.01f), cubePos);
            }
            else if (keyStateCurrent.IsKeyDown(Keys.S) && !keyStatePrevious.IsKeyDown(Keys.S))
            {
                currentCorner = lrTriangleMesh.CS(currentCorner);
                int vertexIdx = lrTriangleMesh.CV(currentCorner);

                Vector3 cubePos = new Vector3((float)lrTriangleMesh.V[vertexIdx].X, (float)lrTriangleMesh.V[vertexIdx].Y, (float)lrTriangleMesh.V[vertexIdx].Z);

                currentCube = new Cube(new Vector3(0.01f, 0.01f, 0.01f), cubePos);
            }
            else if (keyStateCurrent.IsKeyDown(Keys.F) && !keyStatePrevious.IsKeyDown(Keys.F))
            {
                int v = lrTriangleMesh.CV(currentCorner);
                int vertexIdx = lrTriangleMesh.VN(v);
                currentCorner = lrTriangleMesh.VC(vertexIdx);

                Vector3 cubePos = new Vector3((float)lrTriangleMesh.V[vertexIdx].X, (float)lrTriangleMesh.V[vertexIdx].Y, (float)lrTriangleMesh.V[vertexIdx].Z);

                currentCube = new Cube(new Vector3(0.01f, 0.01f, 0.01f), cubePos);
            }
            else if (keyStateCurrent.IsKeyDown(Keys.B) && !keyStatePrevious.IsKeyDown(Keys.B))
            {
                int v = lrTriangleMesh.CV(currentCorner);
                int vertexIdx = lrTriangleMesh.VP(v);
                currentCorner = lrTriangleMesh.VC(vertexIdx);

                Vector3 cubePos = new Vector3((float)lrTriangleMesh.V[vertexIdx].X, (float)lrTriangleMesh.V[vertexIdx].Y, (float)lrTriangleMesh.V[vertexIdx].Z);

                currentCube = new Cube(new Vector3(0.01f, 0.01f, 0.01f), cubePos);
            }
        }
示例#2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            IFLTriangleMesh iflTriangleMesh = MeshLoader.LoadMesh<IFLTriangleMesh>(inputPath);
            IConverter<LRTriangleMesh> converter = Converter.GetSpecificConverter<IFLTriangleMesh, LRTriangleMesh>(iflTriangleMesh);
            lrTriangleMesh = converter.Convert();

            base.Initialize();

            BasicEffect e = new BasicEffect(GraphicsDevice);

            e.VertexColorEnabled = true;

            e.View = Matrix.CreateLookAt(new Vector3(0, 0, 5), new Vector3(0, 0, 0), Vector3.Up);

            float aspect = GraphicsDevice.Viewport.AspectRatio;

            e.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(60f), aspect, 1, 100);
            effect = e;

            this.IsMouseVisible = true;
            mouseStatePrevious = Mouse.GetState();
            keyStateCurrent = Keyboard.GetState();

            this.Window.AllowUserResizing = true;

            RasterizerState s = new RasterizerState();
            s.CullMode = CullMode.None;
            GraphicsDevice.RasterizerState = s;

            int vertex = 0;
            currentCorner = lrTriangleMesh.VC(vertex);

            Vector3 cubePos = new Vector3((float)lrTriangleMesh.V[vertex].X, (float)lrTriangleMesh.V[vertex].Y, (float)lrTriangleMesh.V[vertex].Z);

            currentCube = new Cube(new Vector3(0.01f, 0.01f, 0.01f), cubePos);
        }