VB Silverlight

Imports Microsoft.Xna.Framework.Content
Imports Microsoft.Xna.Framework.Graphics
Imports Microsoft.Xna.Framework
Imports System.Windows.Graphics

Partial Public Class MainPage
    Inherits UserControl

    Public Sub New()
        InitializeComponent()
    End Sub

    Dim contentManager As ContentManager
    Dim spriteBatch As SpriteBatch
    Dim cameraPositon As Vector3 = New Vector3(0, 16.0F, 11.0F)
    Dim cameraTarget As Vector3 = New Vector3(0, 3.0F, -2.0F)
    Dim cameraUpVector As Vector3 = New Vector3(0, 19.0F, 11.0F)
    Dim mouseCaptured As Boolean
    Dim originalPosition As Vector2?
    Dim model As Model
    Dim graphicsDevice As GraphicsDevice
    Dim speed As Double = 0.1F


    Private Sub myDrawingSurface_MouseLeftButtonDown(sender As System.Object, e As System.Windows.Input.MouseButtonEventArgs)
        Focus()
        Dim location As System.Windows.Point = e.GetPosition(myDrawingSurface)
        Dim rectangle As Rect = New Rect(0, 0, myDrawingSurface.RenderSize.Width, myDrawingSurface.RenderSize.Height)
        If (rectangle.Contains(location)) Then
            mouseCaptured = True
            HandleMouseDown(New Vector2(CDbl(location.X), CDbl(location.Y)))
        End If
    End Sub

    Public Sub HandleMouseDown(ByVal position As Vector2)
        originalPosition = position
    End Sub

    Public Sub HandleMouseMove(ByVal position As Vector2)
        If (Not originalPosition.HasValue) Then
            originalPosition = position
        End If
        Dim diff As Vector2 = (originalPosition.Value - position)
        If diff = Vector2.Zero Then
            Return
        End If
        If diff.X = 0 Then
            Dim side As Integer = 0
            If position.X = 0 Then
                side = -1
            ElseIf position.X = myDrawingSurface.RenderSize.Width - 1 Then
                side = 1
            End If
            diff.X -= 20 * side
        End If
        diff *= 0.004F
        cameraTarget -= New Vector3(diff.X, cameraTarget.Y, cameraTarget.Z)
        originalPosition = position
    End Sub

    Private Sub myDrawingSurface_MouseLeftButtonUp(sender As System.Object, e As System.Windows.Input.MouseButtonEventArgs)
        If (mouseCaptured) Then
            mouseCaptured = False
        End If
    End Sub

    Private Sub myDrawingSurface_MouseMove(sender As System.Object, e As System.Windows.Input.MouseEventArgs)
        If (mouseCaptured) Then
            Dim location As System.Windows.Point = e.GetPosition(myDrawingSurface)
            HandleMouseMove(New Vector2(CDbl(location.X), CDbl(location.Y)))
        End If
    End Sub

    Private Sub myDrawingSurface_KeyUp(sender As System.Object, e As System.Windows.Input.KeyEventArgs)

    End Sub

    Private Sub myDrawingSurface_Loaded(sender As System.Object, e As System.Windows.RoutedEventArgs)
        graphicsDevice = GraphicsDeviceManager.Current.GraphicsDevice
        Dim contentManager As ContentManager = New ContentManager(Nothing, "Content/Searching3DContent")
        spriteBatch = New SpriteBatch(graphicsDevice)
        model = contentManager.Load(Of Model)("Searching")
    End Sub

    Private Sub myDrawingSurface_Draw(sender As System.Object, e As System.Windows.Controls.DrawEventArgs)
        graphicsDevice = GraphicsDeviceManager.Current.GraphicsDevice
        graphicsDevice.Clear(Color.Black)
        spriteBatch = New SpriteBatch(graphicsDevice)
        spriteBatch.Begin(0, BlendState.AlphaBlend)
        spriteBatch.End()
        graphicsDevice.DepthStencilState = DepthStencilState.Default
        DrawModels(graphicsDevice, model)
        e.InvalidateSurface()
    End Sub

    Public Sub DrawModels(ByVal graphicsDevice As GraphicsDevice, ByVal models As Model)
        Dim transforms = New Matrix(models.Bones.Count) {}
        models.CopyAbsoluteBoneTransformsTo(transforms)
        For Each mesh As ModelMesh In models.Meshes
            For Each effect As BasicEffect In mesh.Effects
                effect.World = transforms(mesh.ParentBone.Index)
                effect.View = Matrix.CreateLookAt(cameraPositon, cameraTarget, cameraUpVector)
                effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.Pi / 3.3F, graphicsDevice.Viewport.AspectRatio, 1, 1000)
                effect.EnableDefaultLighting()
                effect.SpecularColor = Vector3.One
            Next
            mesh.Draw()
        Next
    End Sub

    Private Sub myDrawingSurface_KeyDown(sender As System.Object, e As System.Windows.Input.KeyEventArgs)
        Dim direction As Vector3 = Vector3.Zero
        Select Case e.Key
            Case Key.W
                direction = New Vector3(0, 0, -speed)
            Case Key.S
                direction = New Vector3(0, 0, speed)
            Case Key.A
                direction = New Vector3(-speed, 0, 0)
            Case Key.D
                direction = New Vector3(speed, 0, 0)
        End Select
        If direction <> Vector3.Zero Then
            cameraTarget = New Vector3(direction.X + cameraTarget.X, direction.Y + cameraTarget.Y, direction.Z + cameraTarget.Z)
            cameraPositon = New Vector3(direction.X + cameraPositon.X, direction.Y + cameraPositon.Y, direction.Z + cameraPositon.Z)
        End If
    End Sub

    Private Sub myDrawingSurface_MouseWheel(sender As System.Object, e As System.Windows.Input.MouseWheelEventArgs)
        Dim direction As Vector3 = Vector3.Zero
        If e.Delta > 0 Then
            direction = New Vector3(0, -speed, -speed)
        Else
            direction = New Vector3(0, speed, speed)
        End If
        If direction <> Vector3.Zero Then
            cameraTarget = New Vector3(direction.X + cameraTarget.X, direction.Y + cameraTarget.Y, direction.Z + cameraTarget.Z)
        End If
    End Sub
End Class
    
    ''' <summary>
    ''' 获取模型资源
    ''' </summary>
    ''' <param name="obj"></param>
    ''' <param name="args"></param>
    ''' <remarks></remarks>
    Private Sub wb_OpenReadCompleted(obj As Object, args As OpenReadCompletedEventArgs)
        NewSearchingContent = New SearchingContentManager(Nothing, "Content/")
        graphicsDevice = GraphicsDeviceManager.Current.GraphicsDevice
        '添加Source资源
        Dim modelsDic As New Dictionary(Of String, Dictionary(Of String, Byte()))
        For Each modelNames As String In Source.Split(",")
            Dim modelsDicName As String = modelNames.Split("|")(0)

            For Each modelName As String In modelNames.Split("|")
                Dim modelDic As Dictionary(Of String, Byte()) = GetModelDictionary(args.Result, modelName)
                If Not modelsDic.ContainsKey(modelsDicName) Then modelsDic.Add(modelsDicName, modelDic)
            Next
            '读取完成加载模型
            NewSearchingContent.newModelByte = modelsDic
            listModel.Add(searchingContent.Load(Of Model)(modelsDicName))
        Next

        
    End Sub

    ''' <summary>
    ''' 获取模型资源字典
    ''' </summary>
    ''' <param name="result">资源包流文件</param>
    ''' <param name="modelName">模型名称</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function GetModelDictionary(ByVal result As Stream, ByVal modelName As String) As Dictionary(Of String, Byte())
        Dim xap As StreamResourceInfo = New Windows.Resources.StreamResourceInfo(result, Nothing)
        Dim modelStream As Stream = Application.GetResourceStream(xap, New Uri(modelName, UriKind.Relative)).Stream

        'Stream转换为bytes()
        Dim modelBytes() As Byte = New Byte(modelStream.Length) {}
        modelStream.Read(modelBytes, 0, modelBytes.Length)
        modelStream.Seek(0, SeekOrigin.Begin)

        Dim dic As New Dictionary(Of String, Byte())
        dic.Add(modelName, modelBytes)
        Return dic
    End Function

    Dim wb As New WebClient()

    Private Sub ModelEx_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        wb.OpenReadAsync(New Uri("SilverlightModel.xap", UriKind.Relative))
        AddHandler wb.OpenReadCompleted, AddressOf wb_OpenReadCompleted
    End Sub



 


代码下载地址: https://pan.quark.cn/s/b4a8e0160cfc 齿轮与轴系零件在机械设备中扮演着至关重要的角色,它们负责实现动力传输、调整运动形态以及承受工作载荷等核心功能。 在机械工程的设计实践中,齿轮和轴系的设计是一项关键的技术任务,其内容涵盖了材料选用、构造规划、承载能力分析等多个技术层面。 下面将系统性地介绍《齿轮及轴系零件结构设计指导书》中的核心知识点。 一、齿轮设计1. 齿轮种类:依据齿廓轮廓的不同,齿轮可划分为直齿齿轮、斜齿轮以及人字齿轮等类别,各类齿轮均具有特定的性能特点与适用工况,能够满足多样化的工作环境与载荷需求。 2. 齿轮规格参数:模数大小、压力角数值、齿数数量、分度圆尺寸等是齿轮设计的基础数据,这些参数直接决定了齿轮的物理尺寸与运行性能。 3. 齿轮材质选用:齿轮材料的确定需综合评估其耐磨损性能、硬度水平以及韧性表现,常用的材料包括铸铁、钢材、铝合金等。 4. 齿轮强度验证:需进行齿面接触应力分析与齿根弯曲应力分析,以确保齿轮在实际运行过程中不会出现过度磨损或结构破坏。 5. 齿轮加工工艺:涉及切削加工、滚齿加工、剃齿加工、淬火处理等工艺流程,工艺方案的选择将直接影响齿轮的加工精度与使用寿命。 二、轴设计1. 轴的分类方式:依据轴在机械装置中的功能定位与受力特点,可将轴划分为心轴、转轴以及传动轴等类型。 2. 轴的材料选择:通常采用钢材作为轴的材料,例如碳素结构钢或合金结构钢,特殊需求时可选用不锈钢材料或轻质合金材料。 3. 轴的构造规划:需详细考虑轴的轴向长度、截面直径、键槽布置、轴承安装位置等要素,以满足轴的强度要求、刚度要求以及稳定性要求。 4. 轴的强度验证:需进行轴的扭转强度分析与弯曲强度分析,以防止轴在运行过程中发生塑性变形...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值