~jtaylor/ubuntu/oneiric/soya/fix-780305

« back to all changes in this revision

Viewing changes to tutorial/lesson-116.py

  • Committer: Bazaar Package Importer
  • Author(s): Marc Dequènes (Duck)
  • Date: 2005-01-30 09:55:06 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050130095506-f21p6v6cgaobhn5j
Tags: 0.9.2-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Soya 3D tutorial
2
 
# Copyright (C) 2001-2002 Jean-Baptiste LAMY
3
 
#
4
 
# This program is free software; you can redistribute it and/or modify
5
 
# it under the terms of the GNU General Public License as published by
6
 
# the Free Software Foundation; either version 2 of the License, or
7
 
# (at your option) any later version.
8
 
#
9
 
# This program is distributed in the hope that it will be useful,
10
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
# GNU General Public License for more details.
13
 
#
14
 
# You should have received a copy of the GNU General Public License
15
 
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 
 
18
 
# Lesson 116: 3D Sound
19
 
 
20
 
# In this lesson, we integrate 3D sounds by using OpenAL and PyOpenAL.
21
 
# PyOpenAL includes a special module for using it along with Soya.
22
 
#
23
 
# You need to install OpenAL and PyOpenAL before running this lesson !
24
 
# You may need to stop artsd daemon too (typically for KDE user)
25
 
#
26
 
# The lesson draws a moving cube that play a 3D sound.
27
 
 
28
 
import os, os.path, sys
29
 
 
30
 
import soya, soya.soya3d as soya3d, soya.model as model, soya.cube as cube
31
 
soya.init()
32
 
 
33
 
scene = soya3d.World()
34
 
 
35
 
camera = soya3d.Camera(scene)
36
 
camera.y = 0.3
37
 
camera.z = 2.0
38
 
 
39
 
soya.set_root_widget(camera)
40
 
 
41
 
 
42
 
# Imports OpenAL.
43
 
 
44
 
import pyopenal, pyopenal.openal4soya as openal4soya
45
 
 
46
 
# Inits the OpenAL for Soya module, and pass to it the location of the listener
47
 
# (usually the camera).
48
 
 
49
 
openal4soya.init(camera)
50
 
 
51
 
# Define the sound directory
52
 
 
53
 
openal4soya.PATH = os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), "data")
54
 
 
55
 
 
56
 
# Create a cube.
57
 
 
58
 
cube = soya3d.Volume(scene, cube.Cube().shapify())
59
 
 
60
 
# The cube continuously play a sound
61
 
#
62
 
# The parameters for play are:
63
 
#  - the sound file name (supported format: Wave, and Ogg Vorbis if PyVorbis is installed)
64
 
#  - the sound position
65
 
#  - the sound speed (a Vector, optional)
66
 
#    the speed is automatically computed if omitted
67
 
#  - 1 for looping (0 else)
68
 
#  - 1 to load the sound asynchronously (if not already cached)
69
 
 
70
 
openal4soya.play("test.wav", cube, None, 1)
71
 
 
72
 
 
73
 
light = soya3d.Light(scene)
74
 
light.set_xyz(1.5, 2.0, 2.2)
75
 
 
76
 
import time, math
77
 
 
78
 
angle = 3.0
79
 
 
80
 
while 1:
81
 
  
82
 
  # Move the cube.
83
 
  # The sound's source is automagically moved with the cube.
84
 
  
85
 
  angle += 0.1
86
 
  cube.set_xyz(3.0 * math.cos(angle), 0.0, 3.0 * math.sin(angle))
87
 
  
88
 
  soya.render()
89
 
  
90
 
  time.sleep(0.1)
91