コード例 #1
0
        // Initialise components
        public void InitialiseComponents()
        {
            // --------------------- //
            // Uncomment for testing //
            // --------------------- //

            // Triangle test
            //tri = new Triangle(ref dev, ref devCon);
            //tri.Initialise();

            // Cube test
            //cube = new Cube(ref dev, ref devCon);
            //cube.setDimensions(form.ClientSize.Width, form.ClientSize.Height);
            //cube.Initialise();

            // Cube import
            ci = new CubeImport(ref dev, ref devCon);
            ci.setDimensions(form.ClientSize.Width, form.ClientSize.Height);
            ci.Initialise();

            // ---- //
            // Live //
            // ---- //
            di = new DXInput();
            di.setDimensions(form.ClientSize.Width, form.ClientSize.Height);

            arc = new ArcCamera();
            arc.setDXInput(ref di);

            cam = new FPSCamera();
            cam.setDXInput(ref di);
            cam.setProjectionMatrix(form.ClientSize.Width, form.ClientSize.Height);

            sky = new Skydome(ref dev, ref devCon);
            sky.setDimensions(form.ClientSize.Width, form.ClientSize.Height);
            sky.Initialise();

            terrain = new Terrain(ref dev, ref devCon);
            terrain.setDimensions(form.ClientSize.Width, form.ClientSize.Height);
            terrain.Initialise();
        }
コード例 #2
0
        // Rotate based on ArcCamera.
        public void Update(ref DXInput di, ref ArcCamera arc)
        {
            float t = sw.ElapsedMilliseconds / 1000.0f;

            viewProj = Matrix.Multiply(arc.GetViewMatrix(), proj);

            // Left mouse button
            if ((di.currMouseState.Buttons[0] == true) && (di.prevMouseState.Buttons[0] == true))
            {
                xRot += 0.0025f;
            }
            // Middle mouse button
            else if ((di.currMouseState.Buttons[2] == true) && (di.prevMouseState.Buttons[2] == true))
            {
                zRot += 0.0025f;
            }
            // Right mouse button
            else if ((di.currMouseState.Buttons[1] == true) && (di.prevMouseState.Buttons[1] == true))
            {
                yRot += 0.0025f;
            }

            float yawDelta   = 0.0f;
            float pitchDelta = 0.0f;

            // Apply zoom distance using Q and Z.
            if ((di.currKeyboardState.IsPressed(SDI.Key.Q)) && (di.prevKeyboardState.IsPressed(SDI.Key.Q)))
            {
                arc.ApplyZoom(0.005f);
            }
            else if ((di.currKeyboardState.IsPressed(SDI.Key.Z)) && (di.prevKeyboardState.IsPressed(SDI.Key.Z)))
            {
                arc.ApplyZoom(-0.005f);
            }
            // Apply yaw using A and D.
            if ((di.currKeyboardState.IsPressed(SDI.Key.A)) && (di.prevKeyboardState.IsPressed(SDI.Key.A)))
            {
                yawDelta = -0.001f;
            }
            else if ((di.currKeyboardState.IsPressed(SDI.Key.D)) && (di.prevKeyboardState.IsPressed(SDI.Key.D)))
            {
                yawDelta = 0.001f;
            }
            // Apply pitch using W and S.
            if ((di.currKeyboardState.IsPressed(SDI.Key.W)) && (di.prevKeyboardState.IsPressed(SDI.Key.W)))
            {
                pitchDelta = -0.001f;
            }
            else if ((di.currKeyboardState.IsPressed(SDI.Key.S)) && (di.prevKeyboardState.IsPressed(SDI.Key.S)))
            {
                pitchDelta = 0.001f;
            }

            arc.ApplyRotation(yawDelta, pitchDelta);

            var rot = Matrix.RotationX(xRot) * Matrix.RotationY(yRot) * Matrix.RotationZ(zRot);
            var wvp = rot * viewProj;

            wvp.Transpose();
            devCon.UpdateSubresource(ref wvp, cBuffer);
        }