(C) 2010 Pearson Education, Inc. All rights reserved. Omer Boyaci.

Slides:



Advertisements
Similar presentations
Image Navigator Help Session. Review Graphics2D class for drawing shapes in a component – paintComponent(Graphics g) – Graphics2D g2 = (Graphics2D)g;
Advertisements

Chapter 4 Transforming and Distorting Objects. Objectives Transform objects Offset and outline paths Create compound paths Work with the Pathfinder panel.
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 30 - Dynamic HTML: Structured Graphics ActiveX Control Outline 30.1Introduction 30.2Shape Primitives.
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 1 Chapter 2 2D Graphics: Basics.
2.3. B OUNDING V OLUMES Bounding volumes of use for collision detection.
HTML 5 Previous version: HTML4.01, 1999 Still work in progress, most browsers support some of it.
Graphics Programming. In this class, we will cover: The difference between AWT and Swing Creating a frame Frame positioning Displaying information in.
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 1 Chapter 2 2D Graphics: Basics F The architecture.
Swing Graphics ● Empty Swing containers have no visual appearance except for a background color ● Every JComponent must have a paintComponent method that.
Introduction to 3D Graphics John E. Laird. Basic Issues u Given a internal model of a 3D world, with textures and light sources how do you project it.
CS324e - Elements of Graphics and Visualization Java2D Graphics.
Guide to Programming with Python
© 2010 Delmar, Cengage Learning Chapter 4 Transforming and Distorting Objects.
AI & 2D Development COSC 315 Fall 2014 Bridget M. Blodgett.
Kirill Grouchnikov, Amdocs Desktop Matters Conference San Jose, March
Complex objects How might you design a class called NestedRects of graphical objects that look like this? Requirements for the constructor: –Like many.
2D Graphics: Rendering Details
Programming Games Simulated ballistic motion: cannon ball. Classwork: Final day for midterm project and all projects for first part of class. Homework:
Chapter 15 Graphics and Java 2D™ Java How to Program, 8/e (C) 2010 Pearson Education, Inc. All rights reserved.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 28 - Java Graphics and Java2D Outline 28.1Introduction.
Element. The element Used to dynamically draw graphics using javascript. Capable of drawing paths, circles, rectangles, text, and images.
AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007 Intro to Action Script 2 "The games of a.
CompSci Graphics. CompSci The Plan  Hardware  Coordinate System  Built-in Shapes  User-defined Shapes  Sprites and Shapes  Making a.
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.
Advanced User Interfaces with Java SD’98 - Session 3206 Ted Faison Faison Computing Inc.
Chapter 6 Working with Patterns and Brushes. Objectives Use the Move command Create a pattern Design a repeating pattern Use the Pattern Options panel.
1 VR assignment#2 WTK SDK Introduction By Jin-Bey Yu 2001/11/12.
11 Adding Tomato Targets Session Session Overview  We now have a game which lets a player bounce a piece of cheese on a bread bat  Now we have.
1 Chapter 3 2D Graphics: Rendering Details  Color spaces, paints stroke types  Affine transforms including translation, rotation, scaling, shearing,
1 Perception and VR MONT 104S, Fall 2008 Lecture 21 More Graphics for VR.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
Roy McElmurry. More:
© 2011 Delmar, Cengage Learning Chapter 6 Working with Patterns and Brushes.
Basic Perspective Projection Watt Section 5.2, some typos Define a focal distance, d, and shift the origin to be at that distance (note d is negative)
COMP135/COMP535 Digital Multimedia, 2nd edition Nigel Chapman & Jenny Chapman Chapter 4 Lecture 4 - Vector Graphics.
Image Panel & Image Navigator. Review Graphics2D class for drawing shapes in a component – paintComponent(Graphics g) – Graphics2D g2 = (Graphics2D)g;
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 19 – Dynamic HTML: Structured Graphics ActiveX Control Outline 19.1Introduction 19.2Shape.
CS COMPUTER GRAPHICS LABORATORY. LIST OF EXPERIMENTS 1.Implementation of Bresenhams Algorithm – Line, Circle, Ellipse. 2.Implementation of Line,
Simple Scene Management a layer has the size of the device screen it defines appearance and behavior a scene is composed of one or more layers app transitions.
Image Panel & Image Navigator. Review Graphics2D class for drawing shapes in a component – paintComponent(Graphics g) – Graphics2D g2 = (Graphics2D)g;
Coordinate Systems Lecture 1 Fri, Sep 2, The Coordinate Systems The points we create are transformed through a series of coordinate systems before.
11 Adding a Bread Bat Session Session Overview  We have created a cheese sprite that bounces around the display  We now need to create a bread.
Advanced Java Screen Update Techniques SD’98 - Session 4406 Ted Faison Faison Computing Inc.
Advanced AWT The Rendering Pipeline
Done already for your convenience!
MOM! Phineas and Ferb are … Aims:
Java Graphics CS 2511.
Graphics.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Intro & Point-to-Box, Circle-to-Circle, Point-to-Circle
Collision Detection Box-to-Box.
Important terms Black-box testing White-box testing Regression testing
CIS 488/588 Bruce R. Maxim UM-Dearborn
Important terms Black-box testing White-box testing Regression testing
Project Snake. Project Snake Snake For this project, we’re going to make Snake This includes Making the overall game logic (using a 2D array) Handling.
ISC440: Web Programming II Ch14: HTML5 Canvas
Java Graphics The basic rendering mechanism is the drawing system that controls when and how programs can draw on a graphics component. When a component.
Creating games with game editors
Transforming and Distorting Objects
Collision Detection Platforms.
Review Session Biggest discrepancy questions
Chapter 49 Java 2D.
Week 6: Time and triggers!
Collision Detection.
The coordinate system Susan Ibach | Technical Evangelist
What would happen if animals were round?
Graphical Interface Commands
Chapter 7 The Game Loop and Animation
Translation in Homogeneous Coordinates
Presentation transcript:

(C) 2010 Pearson Education, Inc. All rights reserved. Omer Boyaci

 A sprite must monitor the game environment, for example, reacting to collisions with different sprites or stopping when it encounters an obstacle.  Collision processing can be split into two basic categories:  collision detection  collision response, with the range of responses being application specific. (C) 2010 Pearson Education, Inc. All rights reserved.

 Many varieties of collision detection exist:  a sprite may be represented by a single bounding box,  a reduced size bounding box,  or several bounding areas. (C) 2010 Pearson Education, Inc. All rights reserved.

 A single bounding box is simple to manipulate but prone to inaccuracy.  The reduced bounding box is better, but choosing a suitable reduction factor is difficult.  The greatest accuracy can be achieved with several boxes for each sprite at the expense of additional calculations. (C) 2010 Pearson Education, Inc. All rights reserved.

public Rectangle getMyRectangle( ){ return new Rectangle(locx, locy, width, height); } private void hasHitBat( ){ Rectangle rect = getMyRectangle( ); if (rect.intersects( bat.getMyRectangle( ) )) { // bat collision? Rectangle interRect = rect.intersection(bat.getMyRectangle( )); dy = -dy; // reverse ball's y-step direction locy -= interRect.height; // move the ball up } (C) 2010 Pearson Education, Inc. All rights reserved.

public abstract boolean hit(Rectangle rect,Shape s, boolean onStroke) Checks whether or not the specified Shape intersects the specified Rectangle, which is in device space. If onStroke is false, this method checks whether or not the interior of the specified Shape intersects the specified Rectangle. If onStroke is true, this method checks whether or not the Stroke of the specified Shape outline intersects the specified Rectangle. The rendering attributes taken into account include the Clip, Transform, and Stroke attributes. Parameters: rect - the area in device space to check for a hit s - the Shape to check for a hit onStroke - flag used to choose between testing the stroked or the filled shape. If the flag is true, the Stroke oultine is tested. If the flag is false, the filled Shape is tested. (C) 2010 Pearson Education, Inc. All rights reserved.

public boolean intersects(double x,double y,double w, double h) Tests whether the interior of this Area object intersects the interior of the specified rectangular area. Specified by: intersects in interface Shape Parameters: x, y - the coordinates of the upper left corner of the specified rectangular area w - the width of the specified rectangular area h - the height of teh specified rectangular area Returns: true if the interior intersects the specified rectangular area; false otherwise; (C) 2010 Pearson Education, Inc. All rights reserved.

 Collision detection is a matter of seeing if the bounding boxes for the ball and the bat intersect. If they overlap, the ball is made to bounce by having its y-step reversed.  The ball’s y-axis location is moved up slightly so it no longer intersects the bat. This rules out the (slim) possibility that the collision test of the ball and bat during the next update will find them still overlapping. This would occur if the rebound velocity were too small to separate the objects within one update.  The collision algorithm could be improved. For instance, some consideration could be given to the relative positions and speeds of the ball and bat to determine the direction and speed of the rebound. This would complicate the coding but improve the ball’s visual appeal. (C) 2010 Pearson Education, Inc. All rights reserved.

@Override public void paintComponent(Graphics g) { //... Downcast to a Graphics2D context. Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); (C) 2010 Pearson Education, Inc. All rights reserved.

 Rotate  to specify an angle of rotation in radians  Scale  to specify a scaling factor in the x and y directions  Shear  to specify a shearing factor in the x and y directions  Translate  to specify a translation offset in the x and y directions (C) 2010 Pearson Education, Inc. All rights reserved.

 Use the getTransform method to get the current transform.  Use transform, translate, scale, shear, or rotate to concatenate a transform.  Perform the rendering.  Restore the original transform using the setTransform method. (C) 2010 Pearson Education, Inc. All rights reserved.

 AffineTransform saveXform = g2.getTransform();  This transform will be restored to the Graphics2D after rendering.  After retrieving the current transform, another AffineTransform, toCenterAt, is created that causes shapes to be rendered in the center of the panel. The at AffineTransform is concatenated onto toCenterAt:  AffineTransform toCenterAt = new AffineTransform(); toCenterAt.concatenate(at);  toCenterAt.translate(-(r.width/2), -(r.height/2));  The toCenterAt transform is concatenated onto the Graphics2D transform with the transform method: g2.transform(toCenterAt);  After rendering is completed, the original transform is restored using the setTransform method: g2.setTransform(saveXform); (C) 2010 Pearson Education, Inc. All rights reserved.