2
# Copyright (C) 2001-2002 Jean-Baptiste LAMY
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.
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.
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
18
# Lesson 101: Setting up : a fullscreen moving cube
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.
25
import soya, soya.soya3d as soya3d, soya.model as model, soya.cube as cube, soya.idler as idler, soya.widget as widget
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.
33
soya.init("Soya tutorial !", 800, 600, 1)
35
# The toggle_fullscreen function can be used to switch between fullscreen and
38
#soya.toggle_fullscreen()
40
# Hides the mouse cursor over the 3D view. This can also be used in windowed
42
# Use "soya.cursor_set_visible(1)" to shows the cursor again.
44
soya.cursor_set_visible(0)
46
# This function will be called to check if the user has pressed a key.
50
# soya.process_event() returns all the events that have occurred since the
51
# previous call. We scan all the event.
53
for event in soya.process_event():
55
# If the event is a keydown, ends the demo.
56
# Events are tupples; the first item indicates the nature of the event.
58
if event[0] == soya.KEYDOWN: sys.exit()
60
# See lesson 001 for the rest of the code !
62
scene = soya3d.World()
64
material = model.Material()
66
cube = cube.Cube(scene, material)
67
cube.rotate_vertical(30.0)
69
light = soya3d.Light(scene)
70
light.set_xyz(1.5, 2.0, 0.2)
72
camera = soya3d.Camera(scene)
75
soya.set_root_widget(widget.Group())
76
soya.root_widget.add(camera)
77
soya.root_widget.add(widget.FPSLabel())
80
def advance_time(proportion):
81
cube.rotate_lateral(proportion * 2.0)
82
cube.rotate_incline(proportion * 1.0)
84
cube.advance_time = advance_time
85
cube.begin_round = manage_event
87
idler.Idler(scene).idle()