File: mouse_click.html

package info (click to toggle)
python-visual 3.2.9-4.1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 2,796 kB
  • ctags: 2,664
  • sloc: cpp: 11,958; sh: 8,185; python: 3,709; ansic: 480; makefile: 311
file content (48 lines) | stat: -rw-r--r-- 2,548 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<LINK REL="STYLESHEET" HREF="VisualRef.css" CHARSET="ISO-8859-1" TYPE="text/css">
</head>

<body bgcolor="#FFFFFF">
<p class="Normal"><font color="#0000A0">Click example</font></p>
<div> 
  <p class="Normal"> This program displays a sphere (which automatically creates 
    a window referred to as <span class="attribute">scene</span>), then repeatedly 
    waits for a mouse left click, prints the mouse position, and displays a small 
    red sphere. A mouse left click is defined as pressing and releasing the left 
    mouse button at nearly the same location.</p>
</div>
<div> 
  <h2 class="program0"> scene.range = 4</h2>
  <p class="program">sphere() # display a white sphere for context</p>
  <p class="program"> while 1:</p>
  <p class="program"> &nbsp;&nbsp;&nbsp;&nbsp;if scene.mouse.clicked:</p>
  <p class="program"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m = scene.mouse.getclick()</p>
  <p class="program"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loc = m.pos</p>
  <p class="program"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print loc</p>
  <p class="program"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sphere(pos=loc, 
    radius=0.1, color=(1,0,0))</p>
  <p class="Normal"> Try running this program. You will find that if you click 
    inside the white sphere, nothing seems to happen. This is because the mouse 
    click is in the x,y plane, so the little red sphere is buried inside the large 
    white sphere. If you rotate the scene and then click, you'll see that the 
    little red spheres go into the new plane parallel to the screen and passing 
    through <span class="attribute">display.center</span>. If you want all the 
    red spheres to go into the xy plane, do this:</p>
  </div>
<div> 
  <h2 class="program0"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loc = 
    m.project(normal=(0,0,1))</h2>
  <p class="program"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if loc: 
    # loc is None if no intersection with plane</p>
  <p class="program"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print 
    loc</p>
  <p class="program"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sphere(pos=loc, 
    radius=0.1, color=(1,0,0))</p>
</div>
<p class="Normal">Choose Back, or <a href="mouse.html">Go to top of mouse documentation</a></p>

</body>
</html>