VB.NET 实现DirectSound9 (5) DS3D2[5]

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 a11s 的 blog

        '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)

本文关键:VB.NET 实现DirectSound9 (5) DS3D2
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top