PDA

View Full Version : 3D Music Interface


Psirus
02-26-2008, 10:10 AM
I am currently using the trial version of Vizard, and I must say it is pretty fun.
I am doing a project for university, and I am a bit stuck, hoping someone can help me.

I have cubes in my interface, and you can select the cubes which you want and they will play a track according to the cube you select.

I have the sounds in constantly running and looping with 0 volume. This is so they are in sync.

I want it so when you select a cube, it moves and turns the volume of the assigned track up so you can hear it. You click on it again, it moves to its original position and the volume goes back down to 0.


I though it would be a lot simpler, basically I imagined it to be:

on mousedown_leftbutton
box1.translate(50,0,0)
sound1.volume(50)
on mousedown_rightbutton
box1.translate(-50,0,0)
sound1.volume(0)

Obviously this is not the case.

I managed to get it to ..
When you left click any box box1 moves and changes the volume.
Here is the code for that:

def left_mouseclick(button):
if button == viz.MOUSEBUTTON_LEFT in box1:
object = viz.pick()
if object.valid():
box1.visible(viz.ON)
box1.translate(0,60,30)
sound1.volume(300)
if button == viz.MOUSEBUTTON_RIGHT:
object = viz.pick()
if object.valid():
box1.visible(viz.ON)
box1.translate(0,0,0)
sound1.volume(0)

viz.callback(viz.MOUSEDOWN_EVENT,left_mouseclick)


I have also managed to get individual picking, but when I try to set is as onpick(sound1.volume(50)) the sound just starts at volume 50, which is baffling me. Here is the code for that:

#Add a node to apply an action to.
sound1 = viz.addAudio('1.wav')
sound1.loop(viz.ON)
sound1.volume(0)
sound1.pause()
#Add the node that you'll pick.
box1 = viz.add( '1.wrl' )
#Apply the action to the node when you pick the other object.
vizact.onpick( box1, sound1.volume(50))


Completely baffled now, I have run out of ideas. I also tried doing this:

def onPick(button):
if button == viz.MOUSEBUTTON_LEFT in box1:
sound1.volume(50)
elif button == viz.MOUSEBUTTON_RIGHT in box1:
sound1.volume(0)
viz.callback(viz.MOUSEDOWN_EVENT,onMouseDown)

But I do not think that is the proper use of 'in' and it does not work at all.

Any help would be greatly appreciated.

Thanks, Dan

farshizzo
02-26-2008, 10:31 AM
You are using the vizact.onpick function incorrectly. Here is a sample script that shows how to use it. Clicking a box will slide it to the other side of the screen and set the volume up.import viz
viz.go()

viz.clearcolor(viz.GRAY)
viz.mouse(viz.OFF)

#Array of sounds
FILES = ['bounce.wav','carousel.wav','bach_air.mid']

def ToggleBox(box):
box.active = not box.active
if box.active:
box.runAction(vizact.moveTo(pos=box.onPos,speed=20 ))
box.audio.volume(1)
else:
box.runAction(vizact.moveTo(pos=box.offPos,speed=2 0))
box.audio.volume(0)

#Create boxes
boxes = []
for i,f in enumerate(FILES):
box = viz.add('box.wrl')
box.audio = viz.addAudio(f,loop=True,volume=0.0)
box.active = False
box.offPos = (-2,i*2,10)
box.onPos = (2,i*2,10)
box.setPosition(box.offPos)
vizact.onpick(box,ToggleBox,box)
boxes.append(box)

#Start sounds
for b in boxes:
b.audio.play()

Psirus
02-26-2008, 10:37 AM
Ah ok thanks.
I will give it a go and get back to you with the results.

Thank you very much for the quick reply!

Psirus
02-26-2008, 11:48 AM
Thank you so much.
I got it working perfectly with this. :)