Sharedwww / talks / 2006-05-09-sage-digipen / tutorial / state-1.pyOpen in CoCalc
Author: William A. Stein
1# Soya 3D tutorial
2# Copyright (C) 2004 Jean-Baptiste LAMY
3#
4# This program is free software; you can redistribute it and/or modify
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
19# state-1: CoordSystState object
20
21# In this lesson, you'll learn how to use CoordSystState to interpolate between
22# two State (position, orientation and scaling) of a 3D object.
23
24
25import sys, os, os.path, soya, soya.cube
26
27soya.init()
28soya.path.append(os.path.join(os.path.dirname(sys.argv[0]), "data"))
29
30# Creates the scene.
31
32scene = soya.World()
33
34
35# Create a volume class that interpolates between two States.
36
37class InterpolatingVolume(soya.Volume):
38  def __init__(self, parent = None, shape = None):
39    soya.Volume.__init__(self, parent, shape)
40
41    # Create two State objects, based on the current position of 'self'.
42
43    self.state1 = soya.CoordSystState(self)
44    self.state2 = soya.CoordSystState(self)
45
46    self.factor = 0.0
47
49    self.factor += 0.01 * proportion
50
51    # interpolate(state1, state2, factor) interpolates between state1 and state2.
52
53    self.interpolate(self.state1, self.state2, self.factor)
54
55
56
57volume = InterpolatingVolume(scene, soya.cube.Cube(None).shapify())
58
59# Moves, rotates and scales the States.
60# Notice that States have the Soya's usual positioning method (actually State even inherit
61# from CoordSyst).
62
63volume.state1.set_xyz(-1.0, -0.5, 0.0)
64
65volume.state2.set_xyz(1.0, 1.0, -1.0)
66volume.state2.rotate_lateral(90.0)
67volume.state2.scale(3.0, 1.0, 1.0)
68
69
71
72light = soya.Light(scene)
73light.set_xyz(0.0, 0.2, 1.0)
74
75# Creates a camera.
76
77camera = soya.Camera(scene)
78camera.set_xyz(0.0, 0.0, 4.0)
79camera.fov = 100.0
80soya.set_root_widget(camera)
81
82
83# Main loop
84
85soya.Idler(scene).idle()
86
87
88# TODO / exercice : turn this demo into a puzzle game !
89