Class: RAGE::InputHandlers::SimpleCameraInputHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/rage/input.rb

Overview

Input handler providing the following simple controls

  • Mouse wheel in/out - zoom camera in/out

  • Hold left mouse button & drag, rotate camera

  • Hold right mouse button & drag, pan camera

Class Method Summary collapse

Class Method Details

.handle(event) ⇒ Object



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
130
131
132
133
134
135
136
137
138
139
# File 'lib/rage/input.rb', line 77

def self.handle(event)
   @@left_button_pressed  = false unless defined? @@left_button_pressed
   @@right_button_pressed = false unless defined? @@right_button_pressed

   case event
   when SDL::Event::MouseMotion
      # get state of mouse buttons
      left_pressed  = ((event.state & SDL::Mouse::BUTTON_LMASK) != 0)
      right_pressed = ((event.state & SDL::Mouse::BUTTON_RMASK) != 0)

      # if left button is down, rotate camera
      if left_pressed
        xpos, ypos, zpos    = RAGE::to_3d_coordinates(event.x, event.y)
        oxpos, oypos, ozpos = RAGE::to_3d_coordinates(event.x-event.xrel, event.y-event.yrel)

        if xpos > oxpos
           Game.current_viewport.camera.xrotate += 1
        elsif xpos < oxpos
           Game.current_viewport.camera.xrotate -= 1
        end

        if ypos > oypos
           Game.current_viewport.camera.yrotate += 1
        elsif ypos < oypos
           Game.current_viewport.camera.yrotate -= 1
        end

        if zpos > ozpos
           Game.current_viewport.camera.zrotate += 1
        elsif zpos < ozpos
           Game.current_viewport.camera.zrotate -= 1
        end

      # if right is down pan camera
      elsif right_pressed
        if event.xrel > 0
           Game.current_viewport.camera.pos[0]    -= 1
        elsif event.xrel < 0
           Game.current_viewport.camera.pos[0]    += 1
        end

        if event.yrel > 0
           Game.current_viewport.camera.pos[1]    += 1
        elsif event.yrel < 0
           Game.current_viewport.camera.pos[1]    -= 1
        end

      end

   when SDL::Event::MouseButtonDown
      # zoom out the camera
      if event.button == 5 # wheeldown
        Game.current_viewport.camera.pos[2]    += 1
      end

   when SDL::Event::MouseButtonUp
      # zoom in the camera
      if event.button == 4 # wheel up
        Game.current_viewport.camera.pos[2]    -= 1
      end

   end
end