nbsp; ''''ok,初始化完成
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Buff.Play(0, BufferPlayFlags.Looping) End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click initDirectSound() End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove '''''''''''' 当鼠标左键按下去的时候有效,我可不希望鼠标经过就改变 If e.Button <> MouseButtons.Left Then Exit Sub Dim r = New Rectangle(e.X, e.Y, 3, 3)
Pic = PictureBox1.CreateGraphics() Me.Text = e.X.ToString + "," + e.Y.ToString Pic.DrawImage(BMP, 1, 1) Pic.DrawEllipse(New Pen(Color.Red), r) SetSoundPos(Convert.ToSingle(e.X), Convert.ToSingle(TextBox5.Text), Convert.ToSingle(e.Y)) ''''''''''''这里坐标变换一下,因为y轴向上,我们需要的是远近,所以负值给Z轴(从上面俯视) End Sub
Private Sub PictureBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.DoubleClick '''''''''''' 清除画板,只需双击一下,免得太乱 BMP = New Bitmap(400, 300) PictureBox1.BackgroundImage = BMP End Sub Sub SetSoundPos(ByVal x As Single, ByVal y As Single, ByVal z As Single) ''''''''''''''''''''''''''''''''''''用户改变位置以及速度之后,对Buff进行调整的代码 '''''''''''' 很简单,就是更改参数而已 '''''''''''' 定义域在-1 到 1 之间 Dim POS As Vector3 Dim Speed As Vector3
POS.X = (x - PictureBox1.Width / 2) / 100 POS.Y = y / 100 POS.Z = (z - PictureBox1.Height / 2) / 100
Speed.X = 1 Speed.Y = 1 Speed.Z = 1
Buff3D.Position = POS Buff3D.Velocity = Speed
Label6.Text = "相对坐标:(x,y)=" + x.ToString + "," + z.ToString End Sub End Class
================================================================================
这里对y轴的操作不多,我无法用Picturebox描述3D的效果,也许学会了D3D就可以比较形象的描述了
而且对于多普勒也没有过多的使用(我的音箱很难分辨),最好用那种汽车的单一的声音最好
还有速度的改变需要检测鼠标两次的位置判断(需要研究公式的,懒)否则多普勒不够真实
对于表现DirectSound3D的性能,这个例子是不够完善的,但是对于介绍使用DS3D的步骤,我想还是
说得过去的.其他的部分大家自己完善就可以了.
下次就是最后的部分了,利用DirectSound进行混音,实现特效.
倒是想过自己做一个封装,用于声音引擎,但是似乎牵扯到3D的地方必须了解D3D,所以DS一般都包含在游戏引擎里面
单独拿出来就没有太大的意义了(除非不使用3D)
上一页 [1] [2] [3] [Web开发]VS2005+SQL2005之.NET2.0数据库连接 [常用软件]公共场所慎用Foxmail5 以防泄露隐私 [VB.NET程序]定制VB.NET控件编程之拦截击键动作 [VB.NET程序]VB.NET VS C#. [VB.NET程序]VB.NET 中调用浏览目录对话框 [VB.NET程序]VB.NET and C# 语法比较手册 [VB.NET程序]VB.NET 拖动无边框的窗体 [VB.NET程序]C# to VB.NET 翻译器 [VB.NET程序]101 VB.NET Applications 读书笔记(1) [VB.NET程序]vb.net 程序设计规范(1)
|