-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExampleCameraControl.js
More file actions
120 lines (84 loc) · 3.3 KB
/
ExampleCameraControl.js
File metadata and controls
120 lines (84 loc) · 3.3 KB
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
function ExampleCameraControl() {}
{
} ;
ExampleCameraControl.prototype.init = function()
{
this.camera = ogre.camera ;
this.node = ( new ogre.SceneNode() ).init() ;
this.node.setParent( ogre.root ) ;
this.camera.setParent( this.node ) ;
this.movementProcesses = {} ;
this.activeHandlers = {} ;
this.setDefaultInputHandlers() ;
return this ;
} ;
ExampleCameraControl.prototype.defaultKeyPressedHandler = function( input )
{
var self = this ;
switch( input.keyChar )
{
case 'w' :
if( typeof this.movementProcesses[ input.keyCode ] == 'undefined' )
this.movementProcesses[ input.keyCode ] = setInterval( function() { self.node.moveL3N( 0, 0, 10 ) ; }, 20 ) ;
break ;
case 's' :
if( typeof this.movementProcesses[ input.keyCode ] == 'undefined' )
this.movementProcesses[ input.keyCode ] = setInterval( function() { self.node.moveL3N( 0, 0, -10 ) ; }, 20 ) ;
break ;
case 'd' :
if( typeof this.movementProcesses[ input.keyCode ] == 'undefined' )
this.movementProcesses[ input.keyCode ] = setInterval( function() { self.node.moveL3N( -10, 0, 0 ) ; }, 20 ) ;
break ;
case 'a' :
if( typeof this.movementProcesses[ input.keyCode ] == 'undefined' )
this.movementProcesses[ input.keyCode ] = setInterval( function() { self.node.moveL3N( 10, 0, 0 ) ; }, 20 ) ;
break ;
}
} ;
ExampleCameraControl.prototype.defaultMousePressedHandler = function( input )
{
var hit = this.camera.pick( input.x, input.y ) ;
if( hit )
hit.entity.emit( 'mousePressed', input ) ;
} ;
ExampleCameraControl.prototype.defaultMouseReleasedHandler = function( input )
{
var hit = this.camera.pick( input.x, input.y ) ;
if( hit )
hit.entity.emit( 'mouseReleased', input ) ;
} ;
ExampleCameraControl.prototype.defaultMouseMovedHandler = function( input )
{
var hit = this.camera.pick( input.x, input.y ) ;
if( hit )
hit.entity.emit( 'mouseMoved', input ) ;
} ;
ExampleCameraControl.prototype.defaultKeyReleasedHandler = function( input )
{
if( typeof this.movementProcesses[ input.keyCode ] == undefined ) return ;
clearInterval( this.movementProcesses[ input.keyCode ] ) ;
this.movementProcesses[ input.keyCode ] = undefined ;
} ;
ExampleCameraControl.prototype.setDefaultInputHandlers = function()
{
var self = this ;
this.activeHandlers[ 'keyPressed' ] = function( input ) { self.defaultKeyPressedHandler( input ) ; } ;
this.activeHandlers[ 'keyReleased' ] = function( input ) { self.defaultKeyReleasedHandler( input ) ; } ;
this.activeHandlers[ 'mousePressed' ] = function( input ) { self.defaultMousePressedHandler( input ) ; } ;
this.activeHandlers[ 'mouseReleased' ] = function( input ) { self.defaultMouseReleasedHandler( input ) ; } ;
this.activeHandlers[ 'mouseMoved' ] = function( input ) { self.defaultMouseMovedHandler( input ) ; } ;
for( var i in this.activeHandlers )
ogre.input.on( i, this.activeHandlers[ i ] ) ;
}
ExampleCameraControl.prototype.removeDefaultInputHandlers = function()
{
for( var handlerType in this.activeHandlers )
{
if( typeof this.activeHandlers[ handlerType ] == undefined )
{
Input.removeListener( handlerType, this.activeHandlers[ handlerType ] ) ;
this.activeHandlers[ handlerType ] = undefined ;
}
}
}
exports.ExampleCameraControl = ExampleCameraControl ;