Sharedwww / talks / 2006-05-09-sage-digipen / tutorial / multiple-cameras-1.pyOpen in CoCalc
Author: William A. Stein
1
# Soya 3D tutorial
2
# Copyright (C) 2005 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
# This shows how to use 2 cameras simultaneously.
19
20
import soya, soya.cube, soya.sphere, soya.widget
21
22
soya.init()
23
24
# Creates 2 worlds, one with a cube and the other with a sphere.
25
26
w1 = soya.World()
27
w2 = soya.World()
28
w1.atmosphere = soya.Atmosphere()
29
w2.atmosphere = soya.Atmosphere()
30
w2.atmosphere.bg_color = 0.5, 0.0, 0.3, 1.0
31
soya.cube.Cube(w1)
32
soya.sphere.Sphere(w2)
33
34
35
# Create a normal camera in w1.
36
37
c1 = soya.Camera(w1)
38
c1.z = 12
39
40
41
# By default, Soya automatically adapt the camera's viewport to fill the whole screen.
42
# If you want to use multiple cameras, you must inhibits this by overriding Camera.resize.
43
44
class FixedViewportCamera(soya.Camera):
45
def __init__(self, parent, left, top, width, height):
46
soya.Camera.__init__(self, parent)
47
48
self.set_viewport(left, top, width, height)
49
50
def resize(self, left, top, width, height):
51
pass
52
53
54
# Create a FixedViewportCamera in w2, and put this second rendering in the upper right
55
# corner of the screen.
56
# Notice that viewport dimension are given in pixels (soya.get_screen_width and
57
# soya.get_screen_height will probably be usefull for you :-).
58
59
c2 = FixedViewportCamera(w2, 400, 20, 220, 100)
60
c2.z = 12
61
62
# We set the camera c2 as "partial", i.e. a camera that doesn't clear the whole screen.
63
64
c2.partial = 1
65
66
g = soya.widget.Group()
67
g.add(c1)
68
g.add(c2)
69
70
soya.set_root_widget(g)
71
72
soya.Idler().idle()
73
74