File: mouse_drag.html

package info (click to toggle)
python-visual 3.2.1-4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,744 kB
  • ctags: 2,626
  • sloc: cpp: 11,327; sh: 8,185; python: 3,702; ansic: 458; makefile: 309
file content (66 lines) | stat: -rw-r--r-- 3,409 bytes parent folder | download | duplicates (2)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<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">Drag example</font></p>
<p class="Normal">You can program dragging with the mouse simply by continually 
  reading the current value of <span class="attribute">scene.mouse.pos</span>. 
  Here is a complete routine for dragging a sphere with the left button down. 
  Note the statements for making the cursor invisible during the drag.</p>
<h2 class="program0">scene.range = 10 # fixed size, no autoscaling</h2>
<p class="program"> </p>
<p class="program">ball = sphere(pos=(-5,0,0), radius=1., color=color.cyan)</p>
<p class="program">cube = box(pos=(+5,0,0), size=(2,2,2), color=color.red)</p>
<p class="program">pick = None # no object picked out of the scene yet</p>
<p class="program">while 1: </p>
<p class="program">&nbsp;&nbsp;&nbsp;&nbsp;if scene.mouse.events: </p>
<p class="program">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m1 = scene.mouse.getevent() 
  # obtain drag or drop event</p>
<p class="program">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if m1.drag 
  and m1.pick == ball: </p>
<p class="program">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;drag_pos 
  = m1.pickpos</p>
<p class="program">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pick 
  = m1.pick</p>
<p class="program">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scene.cursor.visible 
  = 0 # make cursor invisible </p>
<p class="program">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elif m1.drop: 
</p>
<p class="program">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pick 
  = None # end dragging</p>
<p class="program">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scene.cursor.visible 
  = 1 # cursor visible</p>
<p class="program">&nbsp;&nbsp;&nbsp;&nbsp;if pick: </p>
<p class="program">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new_pos = scene.mouse.project(normal=(0,0,1))</p>
<p class="program">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if new_pos 
  != drag_pos: </p>
<p class="program">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pick.pos 
  += new_pos - drag_pos</p>
<p class="program">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;drag_pos 
  = new_pos</p>
<p class="Normal">If you do a lot of processing of each mouse movement, or you 
  are leaving a trail behind the moving object, you may need to check whether 
  the &quot;new&quot; mouse position is in fact different from the previous position 
  before processing the &quot;move&quot;, as is done in the example above. For 
  example, a trail drawn with a curve object that contains a huge number of points 
  all at the same location may not display properly.</p>
<div>
  <div> 
    <p class="Normal">Choose Back, or <a href="mouse.html">Go to top of mouse 
      documentation</a></p>
    <div> 
      <h2 class="program0"> </h2>
    </div>
    <h2 class="program0">&nbsp;</h2>
  <div> 
      <h2 class="program0"> </h2>
    </div>
    <h2 class="program0">&nbsp;</h2>
  </div>
</div>
</body>
</html>