~seh999/jcog/proto3

« back to all changes in this revision

Viewing changes to spacetime/src/opencog/spacetime/control/virtual/VirtualRawMousePointerTrafo.java

  • Committer: SeH
  • Date: 2009-09-19 22:59:48 UTC
  • Revision ID: seh999@gmail.com-20090919225948-q3ab80xa57i74mm6
start of major jReality refactoring

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 *
 
3
 * This file is part of jReality. jReality is open source software, made
 
4
 * available under a BSD license:
 
5
 *
 
6
 * Copyright (c) 2003-2006, jReality Group: Charles Gunn, Tim Hoffmann, Markus
 
7
 * Schmies, Steffen Weissmann.
 
8
 *
 
9
 * All rights reserved.
 
10
 *
 
11
 * Redistribution and use in source and binary forms, with or without
 
12
 * modification, are permitted provided that the following conditions are met:
 
13
 *
 
14
 * - Redistributions of source code must retain the above copyright notice, this
 
15
 *   list of conditions and the following disclaimer.
 
16
 *
 
17
 * - Redistributions in binary form must reproduce the above copyright notice,
 
18
 *   this list of conditions and the following disclaimer in the documentation
 
19
 *   and/or other materials provided with the distribution.
 
20
 *
 
21
 * - Neither the name of jReality nor the names of its contributors nor the
 
22
 *   names of their associated organizations may be used to endorse or promote
 
23
 *   products derived from this software without specific prior written
 
24
 *   permission.
 
25
 *
 
26
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
27
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
28
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
29
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 
30
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 
31
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 
32
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 
33
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 
34
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
35
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 
36
 * POSSIBILITY OF SUCH DAMAGE.
 
37
 *
 
38
 */
 
39
 
 
40
 
 
41
package opencog.spacetime.control.virtual;
 
42
 
 
43
import java.util.List;
 
44
import java.util.Map;
 
45
 
 
46
import opencog.math.Rn;
 
47
import opencog.spacetime.control.InputSlot;
 
48
import opencog.spacetime.control.ToolEvent;
 
49
import opencog.spacetime.control.VirtualDevice;
 
50
import opencog.spacetime.control.VirtualDeviceContext;
 
51
import opencog.spacetime.space.data.DoubleArray;
 
52
 
 
53
 
 
54
 
 
55
/**
 
56
 *
 
57
 * TODO: comment this
 
58
 *
 
59
 * @author brinkman
 
60
 *
 
61
 */
 
62
public class VirtualRawMousePointerTrafo implements VirtualDevice {
 
63
 
 
64
  InputSlot outSlot;
 
65
  InputSlot ndcToWorldSlot;
 
66
  InputSlot pointerNdcSlot;
 
67
  
 
68
  double[] ndcToWorld = new double[16];
 
69
  double[] pointerNdc = new double[16];
 
70
  double[] pointerTrafo = new double[16];
 
71
  DoubleArray outArray = new DoubleArray(pointerTrafo);
 
72
  
 
73
  
 
74
  public ToolEvent process(VirtualDeviceContext context) {
 
75
        try {
 
76
    ndcToWorld = context.getTransformationMatrix(ndcToWorldSlot).toDoubleArray(ndcToWorld);
 
77
    pointerNdc = context.getTransformationMatrix(pointerNdcSlot).toDoubleArray(pointerNdc);
 
78
        } catch (Exception e) {
 
79
                return null;
 
80
        }
 
81
  
 
82
        double x = pointerNdc[3];
 
83
        double y = pointerNdc[7];
 
84
        
 
85
        pointerNdc[0] = x+1;
 
86
        pointerNdc[4] = y;
 
87
        pointerNdc[8] = -1;
 
88
        pointerNdc[12] = 1;
 
89
        
 
90
        pointerNdc[1] = x;
 
91
        pointerNdc[5] = y+1;
 
92
        pointerNdc[9] = -1;
 
93
        pointerNdc[13] = 1;
 
94
        
 
95
        pointerNdc[2] = x;
 
96
        pointerNdc[6] = y;
 
97
        pointerNdc[10] = 1;
 
98
        pointerNdc[14] = 1;
 
99
        
 
100
        pointerTrafo = Rn.times(pointerTrafo, ndcToWorld, pointerNdc);
 
101
        return new ToolEvent(context.getEvent().getSource(), context.getEvent().getTimeStamp(), outSlot, outArray);
 
102
  }
 
103
 
 
104
  public void initialize(List inputSlots, InputSlot result, Map configuration) {
 
105
    outSlot = result;
 
106
    ndcToWorldSlot = (InputSlot) inputSlots.get(0);
 
107
    pointerNdcSlot = (InputSlot) inputSlots.get(1);
 
108
  }
 
109
 
 
110
  public void dispose() {
 
111
  }
 
112
 
 
113
  public String getName() {
 
114
    return "RawMousePointerTrafo";
 
115
  }
 
116
 
 
117
  public String toString() {
 
118
    return "VirtualDevice: "+getName();
 
119
  }
 
120
  
 
121
 }