加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

VB Silverlight APP

发布时间:2020-12-17 08:19:07 所属栏目:百科 来源:网络整理
导读:Private Sub Application_Startup(ByVal o As Object,ByVal e As StartupEventArgs) Handles Me.Startup Dim gdm As GraphicsDeviceManager = GraphicsDeviceManager.Current If gdm.RenderMode = RenderMode.Unavailable Then Select Case gdm.RenderModeRe
Private Sub Application_Startup(ByVal o As Object,ByVal e As StartupEventArgs) Handles Me.Startup
        Dim gdm As GraphicsDeviceManager = GraphicsDeviceManager.Current
        If gdm.RenderMode = RenderMode.Unavailable Then
            Select Case gdm.RenderModeReason
                Case RenderModeReason.SecurityBlocked
                    MessageBox.Show( _
                    "3D support is currently disabled due to enforce" & _
                    " security. You can enable it by following these steps ...")
                Case RenderModeReason.GPUAccelerationDisabled
                    MessageBox.Show( _
                    "Developer error! Use the enableGPUAcceleration " & _
                    "parameter in the test page to enable 3D rendering.")
                Case RenderModeReason.Not3DCapable
                    MessageBox.Show( _
                    "Your computer doesn't appear to support 3D rendering.")
                Case RenderModeReason.TemporarilyUnavailable
                    MessageBox.Show( _
                    "There was a problem accessing the video card driver.")
            End Select
        Else
            ' Run the application as normal.
            Me.RootVisual = New MainPage()
        End If
    End Sub


http://space.silverlightchina.net/xpeter/demo/3D.htm


using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Test8
{

    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        Model myModel;
        float Angle = 0;
        float Angle1 = 0;
        float myScale = 1f;
        Vector2 currentPosition;
        float currentScaleWheelValue;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        protected override void Initialize()
        {
            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            myModel =Content .Load<Model>("Modelsteapot");
        }
        protected override void UnloadContent()
        {
        }
        private void CheckPutIn()
        {
            KeyboardState newState = Keyboard.GetState();
            //左右键控制绕Y轴旋转
            if (newState.IsKeyDown(Keys.Left))
                Angle += 0.01f;
            if (newState.IsKeyDown(Keys.Right))
                Angle -= 0.01f;
            //上下键控制绕Z轴旋转
            if (newState.IsKeyDown(Keys.Up))
                Angle1 += 0.01f;
            if (newState.IsKeyDown(Keys.Down))
                Angle1 -= 0.01f;
            //A、S键控制缩放
            if (newState.IsKeyDown(Keys.A))
                myScale += 0.01f;
            if (newState.IsKeyDown(Keys.S))
                myScale -= 0.01f;
            this.IsMouseVisible = true;
            MouseState newState1 = Mouse.GetState();
            //鼠标左键控制旋转
            if (newState1.LeftButton == ButtonState.Pressed)
            {
                if (currentPosition.X != newState1.X||currentPosition .Y!=newState1.Y)
                {
                    if (currentPosition.X < newState1.X)
                        Angle += 0.01f;
                    if (currentPosition.X > newState1.X)
                        Angle -= 0.01f;

                    if (currentPosition.Y > newState1.Y)
                        Angle1 += 0.01f;
                    if (currentPosition.Y < newState1.Y)
                        Angle1 -= 0.01f;
                }
                currentPosition.X = newState1.X;
                currentPosition.Y = newState1.Y;
            }
            //鼠标滚轮控制缩放
            if (newState1.ScrollWheelValue != currentScaleWheelValue)
            {
                if (currentScaleWheelValue > newState1.ScrollWheelValue)
                    myScale += 0.01F;
                if (currentScaleWheelValue < newState1.ScrollWheelValue)
                    myScale -=0.01f;
            }
            currentScaleWheelValue = newState1.ScrollWheelValue;
        }
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            CheckPutIn();
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            foreach (ModelMesh mesh in myModel.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.World = Matrix.CreateRotationY(Angle)*Matrix.CreateRotationZ(Angle1)*Matrix.CreateScale(myScale);
                    effect.View = Matrix.CreateLookAt(new Vector3(0,8,20),Vector3 .Zero,Vector3 .Up);
                    effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper .ToRadians(45),(float)graphics .GraphicsDevice .Viewport.Width/
                        (float)graphics.GraphicsDevice.Viewport .Height,1.0f,100.0f);
                }
                mesh.Draw();
            }

            base.Draw(gameTime);
        }
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读