Skip to content

Commit 5fbe31a

Browse files
committed
Implement compounding and cloning of extrusions and ring
1 parent 5721026 commit 5fbe31a

File tree

12 files changed

+257
-32
lines changed

12 files changed

+257
-32
lines changed

docs/VPythonDocs/clone.html

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/template.dwt" codeOutsideHTMLIsLocked="false" -->
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5+
<!-- InstanceBeginEditable name="doctitle" -->
6+
<title>VPython Help</title>
7+
<!-- InstanceEndEditable -->
8+
<!-- InstanceBeginEditable name="head" -->
9+
<link href="VisualRef.css" rel="stylesheet" type="text/css" />
10+
<style type="text/css">
11+
<!--
12+
.style1 {font-size: x-large}
13+
.style2 {font-size: xx-large}
14+
-->
15+
</style>
16+
<!-- InstanceEndEditable -->
17+
<script type="text/javascript">
18+
<!--
19+
function MM_jumpMenu(targ,selObj,restore){ //v3.0
20+
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
21+
if (restore) selObj.selectedIndex=0;
22+
}
23+
//-->
24+
</script>
25+
<link href="VPythonDocs/VisualRef.css" rel="stylesheet" type="text/css" />
26+
</head>
27+
28+
<body>
29+
<table width="800" border="0" cellpadding="1" cellspacing="0">
30+
<!--DWLayoutDefaultTable-->
31+
<tr>
32+
<td width="10" valign="top" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell-->&nbsp;</td>
33+
<td width="10" height="272" valign="top" bgcolor="#DDDDDD"><p>&nbsp;</p> </td>
34+
<td width="173" valign="top" bgcolor="#DDDDDD"><p class="Normal"><a href="index.html">Home</a></p>
35+
<p class="Normal">If you're new to Python <br />
36+
and VPython: <a href="VisualIntro.html">Introduction</a></p>
37+
<p class="Normal">A VPython <a href="VPython_Intro.pdf" target="_blank">tutorial</a></p>
38+
<p class="Normal"><a href="primitives.html">Pictures</a> of 3D objects</p>
39+
<p><select id="menu1" onchange="jumpMenu(this)"></select></p>
40+
<p><select id="menu2" onchange="jumpMenu(this)"></select></p>
41+
<p><select id="menu3" onchange="jumpMenu(this)"></select></p>
42+
43+
<p class="Normal">What's new in <a href="new_features.html">VPython 6</a></p>
44+
<p class="Normal"><a href="http://vpython.org" target="_blank">Classic VPython web site</a><br />
45+
<a href="license.txt" target="_blank">VPython license</a><br />
46+
<a href="http://www.python.org" target="_blank">Python web site</a> <br /></p></td>
47+
<td width="21" valign="top" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell-->&nbsp;</td>
48+
<td width="586" rowspan="2" valign="top"><!-- InstanceBeginEditable name="content" -->
49+
<div>
50+
<table width="100%" border="1">
51+
<tr>
52+
<td width="77%"><div align="center"><span class="style1 style2"><font color="#0000A0">clone</font></span></div></td>
53+
<td width="23%"><div align="center"><img src="images/clone.jpg" alt="ring" width="114" height="254" /><a href="arrow.html"></a></div></td>
54+
</tr>
55+
</table>
56+
</div>
57+
<div>
58+
<p class="Normal"> You can clone objects:</p>
59+
<p class="program">b = box(pos=vector(1,1,0), axis=vector(1,1,0),<br />
60+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;color=color.red)<br />
61+
bcopy = b.clone(pos=vector(1,-1,0))</p>
62+
<p class="Normal">This will give you two copies of a box, differing only in their positions. After making the clone, changes to the clone do not affect the original box. </p>
63+
<p class="Normal">If you simply say <strong>b.clone()</strong>, all of the properties of the new object are exactly the same as those of the original object.</p>
64+
<p class="Normal"><strong><font color="#0000a0">Current restrictions</font></strong></p>
65+
<p class="Normal">Currently you cannot clone curve-based objects (curve, helix), nor labels. You also cannot clone triangles/quads, because it is the underlying vertex objects that control their appearance. You <em>can</em> clone compound objects.</p>
66+
<p class="Normal">Currently there is no way to clone an object from one canvas to another.</p>
67+
<!-- InstanceEndEditable --></td>
68+
</tr>
69+
<tr>
70+
<td height="16" colspan="4"></td>
71+
</tr>
72+
</table>
73+
</body>
74+
<script type="text/javascript" language="javascript" src="navigation.js"></script>
75+
<!-- InstanceEnd --></html>

docs/VPythonDocs/compound.html

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/template.dwt" codeOutsideHTMLIsLocked="false" -->
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5+
<!-- InstanceBeginEditable name="doctitle" -->
6+
<title>VPython Help</title>
7+
<!-- InstanceEndEditable -->
8+
<!-- InstanceBeginEditable name="head" -->
9+
<link href="VisualRef.css" rel="stylesheet" type="text/css" />
10+
<style type="text/css">
11+
<!--
12+
.style1 {font-size: x-large}
13+
.style2 {font-size: xx-large}
14+
-->
15+
</style>
16+
<!-- InstanceEndEditable -->
17+
<script type="text/javascript">
18+
<!--
19+
function MM_jumpMenu(targ,selObj,restore){ //v3.0
20+
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
21+
if (restore) selObj.selectedIndex=0;
22+
}
23+
//-->
24+
</script>
25+
<link href="VPythonDocs/VisualRef.css" rel="stylesheet" type="text/css" />
26+
</head>
27+
28+
<body>
29+
<table width="800" border="0" cellpadding="1" cellspacing="0">
30+
<!--DWLayoutDefaultTable-->
31+
<tr>
32+
<td width="10" valign="top" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell-->&nbsp;</td>
33+
<td width="10" height="272" valign="top" bgcolor="#DDDDDD"><p>&nbsp;</p> </td>
34+
<td width="173" valign="top" bgcolor="#DDDDDD"><p class="Normal"><a href="index.html">Home</a></p>
35+
<p class="Normal">If you're new to Python <br />
36+
and VPython: <a href="VisualIntro.html">Introduction</a></p>
37+
<p class="Normal">A VPython <a href="VPython_Intro.pdf" target="_blank">tutorial</a></p>
38+
<p class="Normal"><a href="primitives.html">Pictures</a> of 3D objects</p>
39+
<p><select id="menu1" onchange="jumpMenu(this)"></select></p>
40+
<p><select id="menu2" onchange="jumpMenu(this)"></select></p>
41+
<p><select id="menu3" onchange="jumpMenu(this)"></select></p>
42+
43+
<p class="Normal">What's new in <a href="new_features.html">VPython 6</a></p>
44+
<p class="Normal"><a href="http://vpython.org" target="_blank">Classic VPython web site</a><br />
45+
<a href="license.txt" target="_blank">VPython license</a><br />
46+
<a href="http://www.python.org" target="_blank">Python web site</a> <br /></p></td>
47+
<td width="21" valign="top" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell-->&nbsp;</td>
48+
<td width="586" rowspan="2" valign="top"><!-- InstanceBeginEditable name="content" -->
49+
<div>
50+
<table width="100%" border="1">
51+
<tr>
52+
<td width="78%"><div align="center"><span class="style1 style2"><font color="#0000A0">compound</font></span></div></td>
53+
<td width="22%"><div align="center"><img src="images/compound.jpg" alt="ring" width="137" height="138" /><a href="arrow.html"></a></div></td>
54+
</tr>
55+
</table>
56+
</div>
57+
<div>
58+
<p class="Normal">The <strong>compound</strong> object lets you group objects together and manage them as though they were one object, by specifying in the usual way <span class="attribute">pos</span>, <span class="attribute">color</span>, <span class="attribute">size</span>, <span class="attribute">axis</span>, <span class="attribute">up</span>, and <span class="attribute">texture</span>. Moreover, the display of a complicated compound object is faster than displaying the individual objects one at a time. The object shown above is a compound of a cylinder and a box:</p>
59+
<p class="program">handle = cylinder( size=vector(1,.2,.2), &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;color=vector(0.72,0.42,0) )<br />
60+
<br />
61+
head = box( size=vector(.2,.6,.2), pos=vector(1.1,0,0), &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;color=color.gray(.6) )<br />
62+
<br />
63+
hammer = compound([handle, head])<br />
64+
hammer.axis = vector(1,1,0)</p>
65+
<p class="Normal">Note that after creating the hammer as a compound object, changing the axis rotates the combined object. The positions of the cylinder and box are relative to the origin, vec(0,0,0). If you set <span class="program"><strong>hammer.pos.x = 1</strong></span>, you move the hammer 1 unit to the right. The objects in a compound are &quot;frozen&quot;. You can't change their attributes such as colors or orientations except as a group.</p>
66+
<p class="Normal">Setting <strong>hammer.color</strong> to something other than white makes a multiplicative blend of the overall color with the colors of the individual objects. For example, if the color of the handle is cyan, vec(0,1,1), and the hammer color is yellow, vec(1,1,0), the blend results in vec(0*1, 1*1, 0*0) or vec(0,1,0), which is green.</p>
67+
<p class="Normal"><strong><font color="#0000a0">Setting parameters when creating a compound</font></strong></p>
68+
<p class="Normal">You can optionally specify parameters for a compound. The following statement is equivalent to creating the hammer, then changing the axis:</p>
69+
<p class="program">hammer = compound( [handle, head],<br />
70+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;axis=vector(1,1,0) ) </p>
71+
<p class="Normal"><strong><font color="#0000a0">Compound and world coordinates</font></strong></p>
72+
<p class="Normal">There are two functions for translating between compound and world coordinates, which may differ if the compound object has been moved or rotated. Suppose the name of the compound is <strong>c</strong><strong>c_pos</strong> is a position within that compound, and <strong>world_pos</strong> is the corresponding position in world coordinates:</p>
73+
<p class="program">world_pos = c.compound_to_world(c_pos)</p>
74+
<p class="program">c_pos = c.world_to_compound(world_pos) </p>
75+
<p class="Normal"><strong><font color="#0000a0">Current restrictions</font></strong></p>
76+
<p class="Normal">Currently objects in a compound can have their own colors and opacities but they cannot have individual textures or bumpmaps, which can only be specified for the combined object, and which affect all of the compounded objects.</p>
77+
<p class="Normal">Currently label objects and objects based on curve objects (curve, helix) cannot be compounded. However, <a href="triangle.html">triangles</a>, <a href="triangle.html">quads</a>, and even other compounds can be compounded.</p>
78+
<!-- InstanceEndEditable --></td>
79+
</tr>
80+
<tr>
81+
<td height="16" colspan="4"></td>
82+
</tr>
83+
</table>
84+
</body>
85+
<script type="text/javascript" language="javascript" src="navigation.js"></script>
86+
<!-- InstanceEnd --></html>

docs/VPythonDocs/extrusion.html

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,36 @@
8383
</div>
8484
<p class="Normal"><strong><font color="#0000a0">Path direction</font></strong></p>
8585
<p class="Normal">The paths in the paths library all go counterclockwise in the xz plane, as seen from above. That is, if starting from a position on the x axis, they head in the -z direction and bend toward the left. If your shape has something sticking out on the right, it will be on the outer side of the extrusion, whereas something sticking out on the left will be on the inner side of the extrusion.</p>
86+
<div>
87+
<div>
88+
<div>
89+
<div>
90+
<div>
91+
<div></div>
92+
</div>
93+
<p class="Normal"><strong><font color="#0000a0">Compounds</font></strong></p>
94+
<p class="Normal">You can use extrusions.in <strong><a href="compound.html">compound</a></strong> objects.</p>
95+
</div>
96+
</div>
97+
</div>
98+
</div>
99+
<div>
100+
<div>
101+
<div>
102+
<div>
103+
<div>
104+
<div></div>
105+
</div>
106+
<p class="Normal"><strong><font color="#0000a0">Clones</font></strong> </p>
107+
<p class="Normal">As with other objects, you can make a <strong><a href="clone.html">clone</a></strong> of an extrusion, and this is a good way to make multiple copies of a complicated object. When you create an extrusion its shape and other characteristics become a &quot;model&quot; that is just as fundamental as the model of a box or cylinder object and is stored in the Graphic Processing Unit (GPU) memory for rapid display. If you clone your extrusion, this model can be used in the displaying of all of the clones.</p>
108+
</div>
109+
</div>
110+
</div>
111+
</div>
86112
<div>
87-
<div></div>
113+
<div></div>
88114
</div>
89-
<p class="Normal"><strong><font color="#0000a0">Dynamic change of attributes</font></strong> </p>
115+
<p class="Normal"><strong><font color="#0000a0">Dynamic change of attributes&nbsp;</font></strong> </p>
90116
<div>
91117
<div></div>
92118
</div>

docs/VPythonDocs/images/clone.jpg

22.4 KB
Loading

docs/VPythonDocs/images/compound.jpg

33.4 KB
Loading

docs/VPythonDocs/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@
103103
<p class="Normal"><a href="https://www.youtube.com/watch?v=kqFdB0lbGa8" target="_blank"><strong>Debugging Syntax Errors</strong></a></p>
104104
<p class="Normal"><strong><a href="http://vpython.org/video07.html" target="_blank">Lists, Part 1</a></strong></p>
105105
</blockquote>
106+
<p class="Normal">Here is a series of GlowScript tutorials by Rhett Allain in the context of predicting motion computationally, at the level of an introductory physics course:</p>
107+
<blockquote>
108+
<p class="Normal"><a href="https://bitly.com/bundles/rhettallain/o" target="_blank"><strong>Tutorials 1-7</strong></a></p>
109+
<p class="Normal"><a href="http://www.wired.com/2015/03/glowscript-tutorial-8-gravity-orbits/" target="_blank"><strong>Tutorial 8</strong></a></p>
110+
</blockquote>
106111
<p class="Normal"><strong>Getting started:</strong> To write a VPython program in the browser, sign in at glowscript.org, click the link to your programs, then click Create New Program. A blank edit page will open with a header line that says &quot;GlowScript 1.1 VPython&quot;. Start typing your program on the second line. Click &quot;Run this program&quot; to try out your program.</p>
107112
<p class="Normal"><span class="style1">Using the text editor, etc.</span></p>
108113
<p class="Normal">See the basic GlowScript <strong><a href="../GlowScriptDocs/index.html">Help</a></strong> for details about how to use the text editor, how to share your programs, etc.</p>

docs/VPythonDocs/navigation.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ s += '<option>Work with 3D objects</option>'
2929
s += '<option value="color.html">Color/Opacity</option>'
3030
s += '<option value="text_output.html">Text Output</option>'
3131
s += '<option value="materials.html">Materials/Textures</option>'
32+
s += '<option value="compound.html">Compound Objects</option>'
33+
s += '<option value="clone.html">Clone</option>'
3234
s += '<option value="shapes.html">Shapes Library</option>'
3335
s += '<option value="paths.html">Paths Library</option>'
3436
s += '<option value="defaults.html">Defaults</option>'

docs/VPythonDocs/paths.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@
5454
</table>
5555
<div></div>
5656
<div>
57-
<p class="Normal">The paths library is an auxiliary library to be used together with the 3D extrusion object. It helps in creating paths along which to extrude a 2D shape.</p>
58-
<p class="Normal">The extrusion object and the paths library are not currently available in GlowScript.</p>
57+
<p class="Normal">The paths library is an auxiliary library to be used together with the 3D extrusion object. It helps in creating paths along which to extrude a 2D shape. Currently the only paths available are paths.circle and paths.rectangle; examples are given in the description of the <strong><a href="extrusion.html">extrusion</a></strong> object. </p>
5958
</div>
6059
<!-- InstanceEndEditable --></td>
6160
</tr>

docs/VPythonDocs/shapes.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@
5454
</table>
5555
<div></div>
5656
<div>
57-
<p class="Normal">The shapes library is an auxiliary library to be used together with the 3D <strong><a href="extrusion.html">extrusion</a></strong> object. It helps in creating complex 2D polygons by creating and combining basic geometric shapes. </p>
58-
<p class="Normal">The extrusion object and the paths library are not currently available in GlowScript.</p>
57+
<p class="Normal">The shapes library is an auxiliary library to be used together with the 3D <strong><a href="extrusion.html">extrusion</a></strong> object. It helps in creating complex 2D polygons by creating and combining basic geometric shapes. Currently the only shapes available are shapes.circle and shapes.rectangle; examples are given in the description of the <strong><a href="extrusion.html">extrusion</a></strong> object. </p>
5958
</div>
6059
<!-- InstanceEndEditable --></td>
6160
</tr>

lib/glow/autoscale.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
zy_camera: 0,
1717
last_zx_camera: -1,
1818
last_zy_camera: -1,
19-
find_autocenter: false,
19+
//find_autocenter: false,
2020

2121
point_extent: function (obj, p) {
2222
this.xmin = Math.min(p.x, this.xmin)
@@ -38,10 +38,11 @@
3838

3939
var exports = {
4040
Autoscale: {
41+
/*
4142
compute_autocenter: function compute_autocenter(canvas) {
4243
var ext = canvas.__extent
4344
if (!ext) ext = canvas.__extent = new extent()
44-
ext.find_autocenter = true
45+
//ext.find_autocenter = true
4546
ext.xmin = null
4647
ext.ymin = null
4748
ext.zmin = null
@@ -74,8 +75,9 @@
7475
if (check) {
7576
canvas.center = vec((ext.xmin + ext.xmax) / 2, (ext.ymin + ext.ymax) / 2, (ext.zmin + ext.zmax) / 2)
7677
}
77-
ext.find_autocenter = false
78+
//ext.find_autocenter = false
7879
},
80+
*/
7981
compute_autoscale: function compute_autoscale(canvas) {
8082
var ext = canvas.__extent
8183
if (!ext) ext = canvas.__extent = new extent()
@@ -146,19 +148,19 @@
146148
length = Math.sqrt(sizex * sizex + sizey * sizey + sizez * sizez) / 2
147149
else
148150
length = Math.sqrt(sizex * sizex + sizey * sizey / 4 + sizez * sizez / 4)
149-
if (!ext.find_autocenter) {
150-
// Quick check for whether this changed object can affect autoscaling
151-
var px = startx - ext.__centerx
152-
var py = starty - ext.__centery
153-
var pz = startz - ext.__centerz
154-
var zzx = (Math.abs(px) + length) * ext.__cot_hfov + Math.abs(pz) + length
155-
var zzy = (Math.abs(py) + length) * ext.__cot_hfov + Math.abs(pz) + length
156-
if (zzx < ext.zx_camera && zzy < ext.zy_camera) {
157-
obj.__zx_camera = null // obj.__zx_camera is no longer correct
158-
obj.__zy_camera = null
159-
return
160-
}
151+
//if (!ext.find_autocenter) {
152+
// Quick check for whether this changed object can affect autoscaling
153+
var px = startx - ext.__centerx
154+
var py = starty - ext.__centery
155+
var pz = startz - ext.__centerz
156+
var zzx = (Math.abs(px) + length) * ext.__cot_hfov + Math.abs(pz) + length
157+
var zzy = (Math.abs(py) + length) * ext.__cot_hfov + Math.abs(pz) + length
158+
if (zzx < ext.zx_camera && zzy < ext.zy_camera) {
159+
obj.__zx_camera = null // obj.__zx_camera is no longer correct
160+
obj.__zy_camera = null
161+
return
161162
}
163+
//}
162164
var axis = obj.__axis.norm()
163165
var up = obj.__up.norm()
164166
if (center_pos) start = start.sub(axis.multiply(sizex / 2))

0 commit comments

Comments
 (0)