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 002: Modeling : a moving pyramid
20
# This lesson is similar to the lesson 001, but it displays a pyramid instead of
21
# a cube. As there is no Soya primitive to draw a pyramid, we'll draw it by
22
# hand, with the functions and classes provided by the soya.model module.
23
# The pyramid is made of a quad base and 4 triangles.
25
# Import some Soya module.
27
import soya, soya.soya3d as soya3d, soya.model as model
29
# Initializes Soya (and creates the 3D window).
35
scene = soya3d.World()
37
# Creates the World that will contain the whole pyramid. As previously stated, the
38
# pyramid is composed of 5 faces; this world is used to group those 5 faces
39
# (exactly like a Frame can be used in Tkinter to group different widgets).
40
# The pyramid's parent is the scene.
42
pyramid = soya3d.World(scene)
44
# Creates a material for the pyramid.
46
material = model.Material()
48
# Creates the first face, the quad base of the pyramid.
49
# The first argument of the Face constructor is the parent World (the pyramid),
50
# the second is the list of vertices and the third is the material.
51
# The number of vertices determines the Face's nature:
58
# By default, the face is only visible from one side; which of the two sides
59
# depends on the order of the vertices. You can make the two sides visible
60
# with "face.double_sided = 1".
62
# The vertices is a list of Vertex object. The first argument of the constructor
63
# is (again) the parent, and the three following one are the x, y and z
66
# As 3D object, Point, Vector or Vertex have a parent too, though they are not
67
# considered as "children". The parent is used for automatic coordinates
68
# conversion, which will be detailed in a later lesson. Here, the coordinates
69
# are defined in the pyramid coordinate system.
71
# The order of the vertices in the list determines which side of the face is
72
# visible (for triangles, quads and polygons); you can get both side visible
73
# by setting the "double_sided" attribute to true.
75
model.Face(pyramid, [model.Vertex(pyramid, 0.5, -0.5, 0.5),
76
model.Vertex(pyramid, -0.5, -0.5, 0.5),
77
model.Vertex(pyramid, -0.5, -0.5, -0.5),
78
model.Vertex(pyramid, 0.5, -0.5, -0.5),
81
# Similarly, creates the 4 triangles.
83
model.Face(pyramid, [model.Vertex(pyramid, -0.5, -0.5, 0.5),
84
model.Vertex(pyramid, 0.5, -0.5, 0.5),
85
model.Vertex(pyramid, 0.0, 0.5, 0.0),
88
model.Face(pyramid, [model.Vertex(pyramid, 0.5, -0.5, -0.5),
89
model.Vertex(pyramid, -0.5, -0.5, -0.5),
90
model.Vertex(pyramid, 0.0, 0.5, 0.0),
93
model.Face(pyramid, [model.Vertex(pyramid, 0.5, -0.5, 0.5),
94
model.Vertex(pyramid, 0.5, -0.5, -0.5),
95
model.Vertex(pyramid, 0.0, 0.5, 0.0),
98
model.Face(pyramid, [model.Vertex(pyramid, -0.5, -0.5, -0.5),
99
model.Vertex(pyramid, -0.5, -0.5, 0.5),
100
model.Vertex(pyramid, 0.0, 0.5, 0.0),
103
# Creates and moves the light (see lesson 001).
105
light = soya3d.Light(scene)
106
light.set_xyz(1.0, 0.7, 1.0)
108
# Creates and moves the camera (see lesson 001).
110
camera = soya3d.Camera(scene)
112
soya.set_root_widget(camera)
115
def advance_time(proportion):
116
pyramid.rotate_lateral(proportion * 10.0)
117
pyramid.rotate_incline(proportion * 5.0)
119
pyramid.advance_time = advance_time