File: simple-cube.e

package info (click to toggle)
entity 0.7.2-6
  • links: PTS
  • area: main
  • in suites: woody
  • size: 5,352 kB
  • ctags: 5,272
  • sloc: ansic: 61,707; sh: 7,921; makefile: 732; perl: 399
file content (129 lines) | stat: -rwxr-xr-x 4,333 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env entity

<object default-lang="tcl">
  <?tcl proc quit {node args} { if {"q" == [lindex $args 0]} { $node entity:exit } } ?>
  
  <window onkeypress = "quit" ondelete = "entity:exit" 
   title = "Arc Test (q to quit)" width = "400" height = "400">
    
    <object expand = "true" fill = "true" dragable="true" 
     default-lang = "tcl" tooltip = "drag me with the left button">
      
       <graph name="graph-data"
             selectable = "false"
             expand="true"
             fill="true"
             zoomable = "true"
             cross = "false"
             xmin = "-10" xmax = "10" ymin = "-10" ymax = "10"
             onmousemotion = "motion">
        <!-- the point attributes x and y are unset initially
             and are calculated using the motion routine which
             uses the point data
         -->
        <!-- front -->
        <graph-line linewidth = "3" type = "line" color = "#0000ff">
          <graph-point>-4 -4  6</graph-point>
          <graph-point>-4  4  6</graph-point>
          <graph-point> 4  4  6</graph-point>
          <graph-point> 4 -4  6</graph-point>
          <graph-point>-4 -4  6</graph-point>
        </graph-line>
        <!-- back -->
        <graph-line linewidth = "3" type = "line" color = "#0000ff">
          <graph-point>-4 -4 -6</graph-point>
          <graph-point>-4  4 -6</graph-point>
          <graph-point> 4  4 -6</graph-point>
          <graph-point> 4 -4 -6</graph-point>
          <graph-point>-4 -4 -6</graph-point>
        </graph-line>
        <!-- top -->
        <graph-line linewidth = "3" type = "line" color = "#0000ff">
          <graph-point>-4  6 -4</graph-point>
          <graph-point>-4  6  4</graph-point>
          <graph-point> 4  6  4</graph-point>
          <graph-point> 4  6 -4</graph-point>
          <graph-point>-4  6 -4</graph-point>
        </graph-line>
        <!-- bottom -->
        <graph-line linewidth = "3" type = "line" color = "#0000ff">
          <graph-point>-4 -6 -4</graph-point>
          <graph-point>-4 -6  4</graph-point>
          <graph-point> 4 -6  4</graph-point>
          <graph-point> 4 -6 -4</graph-point>
          <graph-point>-4 -6 -4</graph-point>
        </graph-line>
        <!-- left -->
        <graph-line linewidth = "3" type = "line" color = "#0000ff">
          <graph-point>-6 -4 -4</graph-point>
          <graph-point>-6 -4  4</graph-point>
          <graph-point>-6  4  4</graph-point>
          <graph-point>-6  4 -4</graph-point>
          <graph-point>-6 -4 -4</graph-point>
        </graph-line>
        <!-- right -->
        <graph-line linewidth = "3" type = "line" color = "#0000ff">
          <graph-point> 6 -4 -4</graph-point>
          <graph-point> 6 -4  4</graph-point>
          <graph-point> 6  4  4</graph-point>
          <graph-point> 6  4 -4</graph-point>
          <graph-point> 6 -4 -4</graph-point>
        </graph-line>
      </graph>
      <?tcl

        set X -1
        set Y -1
        set RX 30
        set RY 30

        proc motion {node button x y} {
          global X Y RX RY
          if {1 == $button && $X >= 0} {
            set dx [expr $x - $X]
            set dy [expr $y - $Y]
            set RX [expr $RX + $dx]
            set RY [expr $RY + $dy]
            foreach point [$node children graph-point] {
              rotate_point $point $RX $RY
            }
          }
          set X $x
          set Y $y
        }

        proc sind alpha {
          return [expr sin($alpha * 0.0174533)]
        }

        proc cosd alpha {
          return [expr cos($alpha * 0.0174533)]
        }

        proc rotate_point {point rx ry} {
          set data [$point get_data]
          set x [lindex $data 0]
          set y [lindex $data 1]
          set z [lindex $data 2]

          set tmp [expr  [cosd $rx] * $x + [sind $rx] * $z]
          set z   [expr -[sind $rx] * $x + [cosd $rx] * $z]
          set x $tmp

          set tmp [expr  [cosd $ry] * $y - [sind $ry] * $z]
          set z   [expr  [sind $ry] * $y + [cosd $ry] * $z]
          set y $tmp

          $point attrib x $x y $y
        }

        # initialize point attributes
        set object [enode object]
        foreach point [$object children graph-point] {
          rotate_point $point $RX $RY
        }

      ?>
    </object>
  </window>
</object>