Game Programming Algorithms and Techniques

Slides:



Advertisements
Similar presentations
Introduction to Macromedia Director 8.5 – Lingo
Advertisements

Cosc 5/4730 Input Keyboard, touch, and Accelerometer.
1 Computer Graphics Chapter 2 Input Devices. RM[2]-2 Input Devices Logical Input Devices  Categorized based on functional characteristics.  Each device.
DESCRIBING INPUT DEVICES
Lesson 4 Alternative Methods Of Input.
Intermediate GNVQ ICT Input Devices and Methods Manual input devices are used by people to enter data by hand. Keyboard Pointing devices Joystick Digital.
Session 1.1. Windows Phone Topics Session 1.1 Windows Phone The Windows Phone Device.
GCSE Information Technology Input Devices and Methods 3 Manual input devices are used by people to enter data by hand. Keyboard Pointing devices Joystick.
GCSE Information Technology Input Devices and Methods Objectives:  To understand what input devices are.  Identify their individual uses  Be able to.
INTRODUCTION TO HTML5 Drag and Drop in HTML5. Browsers Support  Currently, most of the major HTML5 desktop web browsers support the new HTML5 drag-and-drop.
1 Interacting with your computer Chapter 3 Mailto: Web :
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Abstract: Accelerometers As part of the smartphone philosophy, every phone has a wide variety of sensors available to the user. Sensors include light and.
(c) University of Washington07b-1 CSC 143 Java Events, Event Handlers, and Threads Reading: Ch. 17.
Guide to Programming with Python Chapter Twelve Sound, Animation, and Program Development: The Astrocrash Game.
CS-1020 Dr. Mark L. Hornick 1 Event-Driven Programming.
MOBILE SENSORS BY OLIVIA TUFFS-MOULDS. ACCELEROMETER An accelerometer is a device, hidden in the motherboard of a smartphone, is a sensor which detects.
Events. Slide 2©SoftMoore Consulting Events Events are generated when a user interacts with the view objects of an application. Examples –button clicked–
CPE 490/590 – Smartphone Development
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
CHAPTER 8 Sensors and Camera. Chapter objectives: Understand Motion Sensors, Environmental Sensors and Positional Sensors Learn how to acquire measurement.
Index Background Costumes Making object walk smoothly Controlling an object with the keyboard Control an object with the mouse Changing costume when hit.
ENGINEERING 1D04 Tutorial 4. What are we doing today? Focus Functions Scope of Variables Returning Values Objects Graphics library Aliasing Events Mouse.
Lecture Input Devices Keyboard. Mouse Microphone Digital Camera Scanner.
Android Android Sensors Android Sensors: – Accelerometer – Gravity sensor – Linear Acceleration sensor – Magnetic Field sensor – Orientation.
CS371m - Mobile Computing Gestures. Common Gestures 2.
Scratch Programming Cards
Lesson 4 Alternative Methods Of Input.
Unit 2 Technology Systems
Game Engine Architecture
Recursion Version 1.0.
CS 134 Alternate Inputs.
Alternative Methods Of Input
Standard Methods of Input.
Where are we ? Setup Sprites Input Collision Drawing Sprites
EE 200 Design Tools Laboratory 14
Methods of Computer Input and Output
PYGAME.
A First Look at GUI Applications
FOP: Buttons and Events
Keyboard Input.
Background Shapes & Collision Resolution (Top-down and Side-scrolling)
Frame Update, Level Representation & Graphics
TYPICAL INPUT DEVICES By Dajia Forbes 1c.
Understanding an App’s Architecture
Lesson Two: Everything You Need to Know
Lesson 1: Buttons and Events – 12/18
Introduction to Events
Lesson 4 Alternative Methods Of Input.
Interfacing Memory Interfacing.
Tries A trie is another type of tree structure. The word “trie” comes from the word “retrieval,” but is usually pronounced like “try.” For our purposes,
CS 106A, Lecture 14 Events and Instance Variables
Lesson 17: Building an App: Canvas Painter
CSCI1600: Embedded and Real Time Software
More programming with "Processing"
Input devices A piece of equipment that allows the user to give instructions and input data to the computer.
Topics discussed in this section:
Using Functions
Android Topics Sensors Accelerometer and the Coordinate System
Binary Search A binary search algorithm finds the position of a specified value within a sorted array. Binary search is a technique for searching an ordered.
Week 6: Time and triggers!
Lesson 4 Alternative Methods Of Input.
Events, Event Handlers, and Threads
Wireless Embedded Systems
Tonga Institute of Higher Education
Chapter 13: Handling Events
ECE 352 Digital System Fundamentals
CSCI1600: Embedded and Real Time Software
Tree A tree is a data structure in which each node is comprised of some data as well as node pointers to child nodes
Game User Input Mouse Input.
Presentation transcript:

Game Programming Algorithms and Techniques Chapter 5 Input

Chapter 5 Objectives Input Devices Learn the difference between digital and analog devices Using analog filtering to reduce spurious input Event-Based Input Systems Basic principles of event systems Two different implementations of an input system for a game Mobile Input Learn about touch screens and gestures Understand when to use the different types of sensors on mobile devices

A variety of input devices Lots of different types of input devices are used for games: A variety of input devices

Digital and Analog Devices A digital input device can be either on or off: Keyboard button Mouse button Face button on controllers (usually) An analog input device has a range of values: Joysticks Accelerometer

Keyboard Input Basics We can't use stdio for keyboard input on most games. Instead, libraries keep an array of the state of all buttons for the keyboard. We can use keycodes to then figure out which index in the array to look up for a particular key, such as K_SPACE.

Tracking Key State Changes We don't want to just do this: if IsKeyDown(K_SPACE) fire missile end When the player presses the spacebar, it's likely to be active for several frames. Furthermore, if the spacebar is held, a missile will be fired every single frame.

Tracking Key State Changes, Cont'd Instead, we should track the state for this frame and the last frame: This way, if we map something to "just pressed," it will only fire once per key press. Last State Current State Result False Still released True Just pressed Just released Still pressed

Key State Implementation enum KeyState StillReleased, JustPressed, JustReleased, StillPressed end function UpdateKeyboard() // lastState and currentState are arrays // which store the entire state of the keyboard. lastState = currentState currentState = get keyboard state

Key State Implementation, Cont'd function GetKeyState(int keyCode) if lastState[keyCode] == true if currentState[keyCode] == true return StillPressed else return JustReleased end return JustPressed return StillReleased

Analog Input Because analog devices give a range of values, we have to be mindful of spurious inputs. For example, a joystick with a range of values for x/y (-32k to +32k) will rarely be exactly (0, 0). Analog filtering tries to eliminate spurious input data.

Joystick dead zone causes input within the inner circle to be ignored. We want to ignore input inside the inner circle, and then scale the remaining range from 0-100%. Joystick dead zone causes input within the inner circle to be ignored.

Simple Dead Zone (Doesn't Work) int deadZone = 3000 // (10%) Vector2 joy = get joystick input if joy.x >= -deadZone && joy.x <= deadZone joy.x = 0 end if joy.y >= -deadZone && joy.y <= deadZone joy.y = 0 Problems: Dead zone is a square. When outside of the dead zone, will suddenly get 10% value.

Better Dead Zone float deadZone = 3000 float maxValue = 32677 Vector2 joy = get joystick input float length = joy.length() // If the length < deadZone, we want no input if length < deadzone joy.x = 0 joy.y = 0 else // Calculate the percent between the deadZone and // maxValue circles float pct = (length – deadZone) / (maxValue – deadZone) // Normalize vector and multiply to get correct final // value joy = joy / length joy = joy * maxValue * pct end

Event Systems Polling Checking every frame for a specific value "Are we there yet?" Event-Based Register to relevant event Notified when event occurs

Event System (Example) class MouseManager List functions // Accepts functions passed as parameters with signature of // (int, int) function RegisterToMouseClick(function handler(int, int)) functions.Add(handler) end function Update(float deltaTime) bool mouseClicked = false int mouseX = 0, mouseY = 0 // Poll for a mouse click ... if mouseClicked foreach function f in functions f(mouseX, mouseY)

More Complex Event System What we'd like: To bind keys such as the spacebar to actions such as "Fire." To be able to pass active actions to the UI first, then gameplay. Still don't have to do low-level polling everywhere of relevance.

More Complex System (Diagram) Proposed input system

Touch Screens A touch screen allows the user to tap on the screen with his or her finger. Most touch screens today are multi-touch, meaning multiple fingers can be detected. Built-in libraries are available, both on iOS (UIGestureRecognizer) and Android (android.gesture).

Some of the Rubine algorithm features For detecting pen-based gestures; could also be used for single-finger detection. Some of the Rubine algorithm features

Accelerometer Detects acceleration along the cardinal axes Will always detect gravity because it's an acceleration Accelerometer

Gyroscope Detects rotation about the cardinal axes Gyroscope