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

« back to all changes in this revision

Viewing changes to tutorial/lesson-101.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 101: Setting up : a fullscreen moving cube
19
 
 
20
 
# This lesson shows how to use fullscreen and other initialization's options;
21
 
# it also introduces the event management.
22
 
# As the user cannot close the demo, it ends when a key is pressed.
23
 
 
24
 
import sys
25
 
import soya, soya.soya3d as soya3d, soya.model as model, soya.cube as cube, soya.idler as idler, soya.widget as widget
26
 
 
27
 
# Initializes Soya (and creates the 3D window).
28
 
# The first argument is the window's title (for windowed rendering).
29
 
# The second and third ones are the resolution in pixels (800x600, 1024x768,...).
30
 
# The fourth one is true for fullscreen and false for windowed rendering.
31
 
# The fifth one (not used here) is true for a resizeable window.
32
 
 
33
 
soya.init("Soya tutorial !", 800, 600, 1)
34
 
 
35
 
# The toggle_fullscreen function can be used to switch between fullscreen and
36
 
# windowed mode.
37
 
#
38
 
#soya.toggle_fullscreen()
39
 
 
40
 
# Hides the mouse cursor over the 3D view. This can also be used in windowed
41
 
# mode.
42
 
# Use "soya.cursor_set_visible(1)" to shows the cursor again.
43
 
 
44
 
soya.cursor_set_visible(0)
45
 
 
46
 
# This function will be called to check if the user has pressed a key.
47
 
 
48
 
def manage_event():
49
 
  
50
 
  # soya.process_event() returns all the events that have occurred since the
51
 
  # previous call. We scan all the event.
52
 
  
53
 
  for event in soya.process_event():
54
 
    
55
 
    # If the event is a keydown, ends the demo.
56
 
    # Events are tupples; the first item indicates the nature of the event.
57
 
    
58
 
    if event[0] == soya.KEYDOWN: sys.exit()
59
 
      
60
 
# See lesson 001 for the rest of the code !
61
 
 
62
 
scene = soya3d.World()
63
 
 
64
 
material = model.Material()
65
 
 
66
 
cube = cube.Cube(scene, material)
67
 
cube.rotate_vertical(30.0)
68
 
 
69
 
light = soya3d.Light(scene)
70
 
light.set_xyz(1.5, 2.0, 0.2)
71
 
 
72
 
camera = soya3d.Camera(scene)
73
 
camera.z = 5.0
74
 
 
75
 
soya.set_root_widget(widget.Group())
76
 
soya.root_widget.add(camera)
77
 
soya.root_widget.add(widget.FPSLabel())
78
 
 
79
 
 
80
 
def advance_time(proportion):
81
 
  cube.rotate_lateral(proportion * 2.0)
82
 
  cube.rotate_incline(proportion * 1.0)
83
 
  
84
 
cube.advance_time = advance_time
85
 
cube.begin_round  = manage_event
86
 
 
87
 
idler.Idler(scene).idle()