CoCalc Public Fileswww / talks / 2006-05-09-sage-digipen / tutorial / multiple-cameras-1.py
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
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
20import soya, soya.cube, soya.sphere, soya.widget
21
22soya.init()
23
24# Creates 2 worlds, one with a cube and the other with a sphere.
25
26w1 = soya.World()
27w2 = soya.World()
28w1.atmosphere = soya.Atmosphere()
29w2.atmosphere = soya.Atmosphere()
30w2.atmosphere.bg_color = 0.5, 0.0, 0.3, 1.0
31soya.cube.Cube(w1)
32soya.sphere.Sphere(w2)
33
34
35# Create a normal camera in w1.
36
37c1 = soya.Camera(w1)
38c1.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
44class 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
59c2 = FixedViewportCamera(w2, 400, 20, 220, 100)
60c2.z = 12
61
62# We set the camera c2 as "partial", i.e. a camera that doesn't clear the whole screen.
63
64c2.partial = 1
65
66g = soya.widget.Group()