Other Input Methods Pre-Lab Lecture 4 1. Revisit 2  Pre-Lab 3 – Animation  Boundary Information  Layer Concept  Animation algorithm  Next Position.

Slides:



Advertisements
Similar presentations
View-Based Application Development Lecture 1 1. Flows of Lecture 1 Before Lab Introduction to the Game to be developed in this workshop Comparison between.
Advertisements

Working with Profiles in IX1D v 3 – A Tutorial © 2006 Interpex Limited All rights reserved Version 1.0.
Detecting Collisions CSE 391 Fall 2012 Tony Scarlatos.
IS660Z Programming Games Using Visual Basic Overview of Cannonball.
Visual Basic: ballistics
Animation and Input CSCI Day Six. Animation Basic Steps to Draw Something: var vertices = [ … ]; var BufferId = gl.CreateBuffer(); gl.bindBuffer.
Cosc 5/4730 Input Keyboard, touch, and Accelerometer.
Event Handling. Overview How to listen (and not listen) for events Creating a utility library (and why you should) Typology of events Pairing event listeners.
Animation Pre-Lab Lecture 3 1. Revisit 2  Pre-Lab 2  Create new UI components through codes  Too many UI components that are required to put on the.
Inspiration 9 Visual Diagramming Software HOW TO USE THE PROGRAM IN THE SKILLS CENTER ROOM 801.
Informationsteknologi Wednesday, November 7, 2007Computer Graphics - Class 51 Today’s class Geometric objects and transformations.
Online Calculator Basic Word Processing Skills Computer Keyboard Skills Computer Mouse Skills Basic Computer Terminology Computer Mouse Skills “I really.
The Accelerometer CSE 391 Fall 2011 Tony Scarlatos.
3.3. G AME I NPUT Handling input within games. In lecture exploration of answers to frequently asked student questions.
Game Rules Implementation Lecture 5 1. Revisit 2  Lab 4 – Other Input Methods  Touches Basics  Relationship between TouchesBegan, TouchesMoved, and.
Touches Detection and Other Remaining Parts Lecture 3 1.
UIAlertView, UIActionSheet, and Facebook Connection Lecture 4 1.
Mrs. Chapman. Tabs (Block Categories) Commands Available to use Script Area where you type your code Sprite Stage All sprites in this project.
The Science of Digital Media Microsoft Surface 7May Metropolia University of Applied Sciences Display Technologies Seminar.
View Controllers (second part) Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
Civil 114 Civil Engineering Drawing AutoCAD
Event Handling Events and Listeners Timers and Animation.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering 3 October 2007.
Google SketchUp Castle
CHAPTER 10 Recursion. 2 Recursive Thinking Recursion is a programming technique in which a method can call itself to solve a problem A recursive definition.
1 CGS1060 Mobile UIs Copyright 2012 by Janson Industries.
 jQuery Mobile An Introduction. What is jQuery Mobile  A framework built on top of jQuery, used for creating mobile web applications  Designed to make.
1 Windows Printing. 2 Objectives You will be able to Output text and graphics to a printer. Print multipage documents. Use the standard Windows print.
IPad 101 Tips and Tricks to Using Your iPad. WEDNESDAY, JUNE 11 12:30 – 1:30 ROOM E115.
Lab 8 – C# Programming Adding two numbers CSCI 6303 – Principles of I.T. Dr. Abraham Fall 2012.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
EEC-492/592 Kinect Application Development Lecture 10 Wenbing Zhao
1 iSee Player Tutorial Using the Forest Biomass Accumulation Model as an Example ( Tutorial Developed by: (
by Chris Brown under Prof. Susan Rodger Duke University June 2012
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Introduction to Arrays. definitions and things to consider… This presentation is designed to give a simple demonstration of array and object visualizations.
Designing Interface Components. Components Navigation components - the user uses these components to give instructions. Input – Components that are used.
CHRONOS-CONTROL COMPUTER CONTROL USING TI CHRONOS Cihat Keser Yeditepe University
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.
CSE 501N Fall ‘09 12: Recursion and Recursive Algorithms 8 October 2009 Nick Leidenfrost.
GAME:IT Helicopter Objectives: Review skills in making directional sprites Create objects that shoot and destroy for points Create random enemies on the.
View Controllers Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
VISTA IMAGING RADIOLOGY VIEWER. 2 The focus of this document is on the VistA Imaging Display Radiology Viewer. Other Display changes will be discussed.
Game Maker Terminology
1 Perception and VR MONT 104S, Fall 2008 Lecture 21 More Graphics for VR.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 3, Lecture 1.
Build-A-Button Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, October 8, 2003.
ITI 1120 Lab #5 Contributors: S. Boyd, R. Plesa, A. Felty, D. Inkpen, A. Williams, D. Amyot.
Class Builder Tutorial Presented By- Amit Singh & Sylendra Prasad.
Envision Tutorial Horner APG, LLC July 18, Introduction The Cscape Remote Viewer allows remote interaction with the user interface on Horner OCS.
Twist, Touch & Travel Touch, Twist, and Travel Harnessing the iPhone's Unique Features Glenda Adams Maverick Software
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Events Programming with Alice and Java First Edition by John Lewis.
JavaScript II ECT 270 Robin Burke. Outline Functions Events and event handling Form validation.
Part 1 Working with Devices in the CQ Lab. Agenda 2 How to select a device and reserve it. Basic device operations inside the Lab Other features to get.
 The terms LMB, MMB, RMB, and mouse wheel (MW).
1 CSC 221: Computer Programming I Fall 2009 Introduction to programming in Scratch  animation sprites  motion, control & sensing  costume changes 
Events. Slide 2©SoftMoore Consulting Events Events are generated when a user interacts with the view objects of an application. Examples –button clicked–
Document that explains the chosen concept to the animator 1.
CHAPTER 7 TouchGestures. Chapter objectives: To code the detection of and response to touch gestures. Patterns of common touches to create touch gestures.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
Touch and Go: Leading Touch UI with Open Source
AnDroid GoogleMaps API
FOP: Buttons and Events
Objectives To define terminology associated with Windows operating systems. To examine uses of Windows in business and industry. To explain techniques.
Lesson 1: Buttons and Events – 12/18
More programming with "Processing"
EEC-492/693/793 iPhone Application Development
Introduction to Excel 2007 Part 3: Bar Graphs and Histograms
Presentation transcript:

Other Input Methods Pre-Lab Lecture 4 1

Revisit 2  Pre-Lab 3 – Animation  Boundary Information  Layer Concept  Animation algorithm  Next Position Calculation  Data and Image object  Moving Out of Boundary  Lab 3  Shooting out a list of Bullets  Shrinking the Time Left Bar  Generating the target balloon and moving down

Overview of Lab 4 3 INPUT PROCESSOUTPUT Touch on Screen Tilt Device Tutorial 4 Part 1 Part 2 Part 3

Input method 4  Now, we can control  The movement of the user Image through the Left or Right Button  The Bullets Shooting through the Shoot Button  In fact, iPhone is well-known of the following two kinds of input method which will be discussed in this Pre-Lab Lecture  Touches and Gestures Detection  Device Tilting

Touch Event vs Action on UI Component 5  Similarity  Both of them involve the finger touches on the screen  Differences  If the finger touches on the screen which has a UI component, and this UI component can apply action, then this becomes an action to the UI component  e.g., Press a button activates the “Touch Up Inside”action on the left button in Tutorial 1 Part 3.  Otherwise, this becomes a touch event to the screen view  i.e., We can only know some basic information like  The point touches by the finger on the screen view  How many points currently touched on the screen view  By interpreting these basic information, some sophisticated touches actions and gestures can be detected.

Touches Actions and Gestures 6  Touches Actions and Gestures  Tapping  Single Tap – touch a single point of the screen once  Double Tap – touch a single point of the screen twice  Multitouch  Touch several points on the screen simultaneously  Dragging  Touch on a certain UI component and move the center of the UI component  Swipping  Moving on the screen to the right or left to represent next page/prev  Zooming In or Out  Moving two fingers towards or outwards to represent zoom in or zoom out gesture

Tapping – Single Tap 7 Screen View Touch point on screen Touch a Single Point on the Screen

Tapping – Double Taps and Multi Taps 8 Screen View First Touch point on screen Second Touch point on screen Double Taps: Touch a Single Point on the Screen twice within a short period of time Multiple Taps: Taps more than twice are possible to be detected

MultiTouches 9 Screen View Touch point 1 MultiTouches: It is possible to detect more than one touch on the screen simultaneously Touch point 2

Dragging 10 Screen View Dragging: Touches on a certain UI component (cannot apply action type) and move to other place on the screen together with the UI component

Swipping 11 Screen View Swipping: Touches on a certain point on the screen and move to other place Usually, moving right is used to represent the gesture of next page, and moving left is used to represent the gesture of previous page

Zooming in/out 12 Screen View Zooming in: Two fingers touch on the screen simultaneously and move towards each other. This is to represent the gesture that we would like to zoom in to look more detail on the image Zooming out: Two fingers touch on the screen simultaneously and move outwards

Basic Touches Event Handlers 13  Traditionally, iPhone SDK does not provide any method for interpreting the touches actions and gestures  They only provide three basic methods for handling three different stages of touches events  Touches Began  This method will be invoked ONCE when the finger first touches on the screen every time  Touches Moved  This method will be invoked CONTINUOUS when the finger moves on the screen  Touches Ended  This method will be invoked ONCE when the finger leaves the screen

Part 1A - Touch Events Test 14  Basically, the iPhone app can handle three basic touch events when you implement the following methods inside the view controller  TouchesBegan Method  TouchesMoved Method  TouchesEnded Method  We will then discuss how to interpret several common touches actions from these touches events  Single Tap on Screen  Moving on the Screen  Double Taps on the Screen  Two Touches on the Screen

Basic Touches Method 15 // Touches Began Method -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ Began”); } // Touches Moved Method -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ Moved”); } // Touches Ended Method -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ Ended”); }

Example Situation 1 – Single Tap on Screen 16 TouchesBegan TouchesEnded Finger touches the screen Finger leaves the screen

Example Situation 2 – Moving on the screen 17 TouchesBegan TouchesEnded Finger touches the screen Finger leaves the screen TouchesMoved Finger moves on the screen

Information provided by a touch event 18  Within each touch event method, you can request it to give you some more detail information  How many touches currently identified on the screen  The touch point of each touch on the screen  How many times a certain point is touch consecutively

Example: Touches Began Event 19 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ // By invoking the allTouches method of event, which is provided by the touches method (i.e., touches began method in this case), a set of touches will be returned. // Note that the return type is NSSet, and it is just a convention of using allTouches as a variable to hold the set. You can definitely use our variable name.  NSSet * allTouches = [event allTouches]; // By invoking allObjects method of the allTouches, we will then get an NSArray holding the UITouch object // Note that UITouch can be regarded as the object which actually holds a specific touches information on the screen, e.g., the point that this touch occurs. In the following code, we are interested in the first object of the array.  UITouch * touch = [[allTouches allObjects] objectAtIndex:0];

Information that we may interest in 20 // Touch Point Location Information // By invoking the locationInView method of the UITouch, we can get the actual touch point location of this touch on our current screen view by using our current screen view as the input parameter, i.e., [self view]  CGPoint touchPoint = [touch locationInView:[self view]]; // Number of touches simultaneously on screen // Recall that allTouches is the variable holding the set of touches on the screen. // We can ask for how many touches occur on the screen by asking for its size directly  [allTouches count]; // Number of Consecutive Touches on a single point // Recall that touch is a variable referring to a specific touch information on the screen // We can invoke its tapCount method to get this information  [touch tapCount];

Example Situation 3 – Double Taps or Multi Taps 21  NSSet * allTouches = [event allTouches];  UITouch * touch = [[allTouches allObjects] objectAtIndex:0];  switch ([touch tapCount]){  case 2:{  a point 2 times screen”);  CGPoint touchPoint = [touch locationInView:[self view]];  %f, y: %f”, touchPoint.x, touchPoint.y);  } }

Example Situation 4 – Two or More Touches on Screen 22  NSSet * allTouches = [event allTouches];  switch([allTouches count]){  case 2:{  2 points on screen”);  UITouch * touch1 = [[allTouches allObjects] objectAtIndex:0];  CGPoint touchPoint1 = [touch1 locationInView:[self view]];  %f, y: %f”, touchPoint1.x, touchPoint1.y);  UITouch * touch2 = [[allTouches allObjects] objectAtIndex:1];  CGPoint touchPoint2 = [touch2 locationInView:[self view]];  %f, y: %f”, touchPoint2.x, touchPoint2.y);  }

Discussion on Multi-Touches Case 23  Please note that the order of the touch points is not fixed  Refer to the previous example,  (a) First touch point is “x:204, y:109”  (b) Second touch point is “x:276. y:211”  However, even if you touch the two same points again, it is possible for (a) to be second touch point, and (b) to be the first touch point.  i.e., the order is reverse

Simulating two touch points in iPhone Simulator 24  In iPhone simulator, single touch point is used by default.  To simulate two points, you can press OPTION when you move the mouse pointer on the screen view.

Part 1B - Double Taps to Shoot 25  Hints:  Now, when you press the shoot button, the bullet will be shot To support the new function  Add in a method “fireBullet” to handle all the bullet shooting situations. Invoke the method when  Press the Shoot Button  Double Taps on the screen

Part 2 – Touch Moved and Dragging Practice 26  Objective:  Allow the shooter to be dragged horizontally when the user touches on the image.  The orientation of the image can be changed by swiping outside the image.  Algorithm:  Detect the touch move position on screen  Check whether the touch falls on the image or not  If true  Handle the userImage move situation  If false  Handle the angle change situation  Problem:  Why Implement the function in TouchesMoved?  How to distinguish whether your finger falls on the image or not?  How to calculate the angle moved

Image Touch Detection Technique 27  Recall that to detect the touch location on the screen view  UITouch * touch = [[allTouches allObjects] objectAtIndex:0];  CGPoint touchPT = [touch locationInView:[self view]];  To check whether your finger touch falls on the image  touchPT.x > x1 and touchPT.x < x2  touchPT.y > y1 and touchPT.y <y2  Note that x2 = x1+width, y2 = y1+height (x1, y1) (x2, y1) (x1, y2) (x2, y2)

Angle Calculation Technique 28 P2 (x, y) P3 (x, y - 10) Artificial Point User Image Center Point Finger Touch Point P1 (x’, y’) Angle Can be Calculated For your simplicity, we implemented AngleCalculator.h and AngleCalculator.m Method find_angle returns the angle at p2 of the triangle formed by the three points by taking CGPoints p1, p2, p3 as input parameters. To make a CGPoint, you can use CGPointMake(float x, float y).

Image Angle Rotation 29  To change the angle of the userImage  We can rotate the userImage to the appropriate direction  // Rotate the view  CGAffineTransform transform = CGAffineTransformMakeRotation( ); .transform = transform;  Note that the angle of rotation refers to the angle start from the 0 no matter what the current angle of rotation is 0 0 angle of rotation

Input Method – Device Tilting 30  iPhone allows the application to detect device tilting through the taking of the accelerometer reading periodically  They provide accelerometer reading in three directions  X, Y, and Z  To simplify the case, we will only explain X and Y in the Pre-Lab  Accelerometer reading is bounded by (-1 < 0 < 1) depends on the degree you tilt the device  i.e., the larger the degree you tilt, the larger will be its absolute value. The maximum absolute value will be 1  We can use this to act as an another kind of input method to our application

Horizontal Position 31  This is the position in which the device is horizontally put on the desk  In this case,  X = 0, Y = 0  Suppose we rotate the device right

Right Rotation Position 32  This is the position in which the device is rotated to right on the desk  In this case,  X = 1, Y = 0  Suppose we rotate the device left this time

Left Rotation Position 33  This is the position in which the device is rotated to left on the desk  In this case,  X = -1, Y = 0  Suppose we rotate the device to vertical up position

Vertical Up Position 34  This is the position in which the device is rotated to vertical up position  In this case,  X = 0, Y = -1  Suppose we rotate the device to vertical upside down this time

Vertical Upside Down Position 35  This is the position in which the device is rotated to vertical upside down position  In this case,  X = 0, Y = 1

To conclude 36 +x -x -y +y

Recall: Screen View Orientation and Coordinate Representation 37 (0, 0) (480, 320) (480, 0) (0, 320) Landscape Mode (0, 0) (320, 0) (320, 480)(0, 480) Protriat Mode Coordinate System Changes when it changes from Protrait mode to landscape mode

Accelerometer Reading 38  However, this representation will not change even the orientation of the screen change +y +x Landscape Mode Home Button Protrait Mode +x -y -x +y -y -x

Part 3A - Detecting Device Tilting Event (UIAccelerometer Event) 39  Implement UIAccelerometer Delegate Protocol by changing the header of BallShootingViewController to  // This is to show that this view controller has implemented a method to handle the Accelerometer reading BallShootingViewController : UIViewController  Initialize the Accelerometer Reading with the update Interval by writing method initializationAccelerometer. Make sure you call this method in ViewDidLoad.  // Reset the Accelerometer  [[UIAccelerometer sharedAccelerometer] setDelegate:nil];  // Set the Accelerometer to take the reading every DEFAULT_TIMER_RATE second  [[UIAccelerometer sharedAccelerometer] setUpdateInterval:DEFAULT_TIMER_RATE];  // This is to tell the Accelerometer that the current view controller has implemented a method in handling when the reading is ready  [[UIAccelerometer sharedAccelerometer] setDelegate:self];

Part 3A - Detecting Device Tilting Event (UIAccelerometer Event) II 40  Implement the didAccelerate method in the view controller which will be invoked when accelerometer reading is ready  - (void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{  // You can get the corresponding X, Y, Z reading by looking for acceleration.x, acceleration.y, and acceleration.z in the didAccelerate mehtod  x: %f, Accel y: %f, Accel z: %f", acceleration.x, acceleration.y, acceleration.z);  }  Note that you must load your application to the real device to test the results.

Part 3B – Tilting Device to Move User Image 41  In part 3B, we would like the student to implement the function  Tilt device to right hand side in landscape mode to move userImage to right  Tilt device to left hand side in landscape mode to move userImage to left  Hints:  Applying appropriate offset (obtained from the accelerometer Reading) to the center position of the userImage  Careful handling the Accelerometer Reading when tilting the device