DOC PREVIEW
Duke CPS 004 - Graphics

This preview shows page 1-2-19-20 out of 20 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

GraphicsThe PlanHardwareCoordinate SystemsSlide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Built-in ShapesUser-defined ShapesShapesSprites and ShapesMaking a SpriteSlide 17Slide 18Slide 19Slide 20CompSci 45.1GraphicsCompSci 45.2The PlanHardwareCoordinate SystemBuilt-in ShapesUser-defined ShapesSprites and ShapesMaking a SpriteCompSci 45.3HardwareMonitorResolutions (640x480, 800x600, 1280x1024)Bit depth (8, 15, 16, 24, 32)Refresh rate (75-85 Hz)Video CardAssists monitorOptimizes graphicsCompSci 45.4Coordinate SystemsCartesianPolarScreen (Graphics)Java 2D (Graphics2D)CompSci 45.5Coordinate SystemsCartesianRectangularX increases to the rightY increases as you go upOrigin typically at centerReal valuedyx0CompSci 45.6Coordinate SystemsPolarr increases as distance from the origin increasestheta increases in the counterclockwise directiongrid lines make concentric circles and sectorsOrigin typically at centerr is real valuedtheta is from 0 to 2*PIrtheta0.CompSci 45.7Coordinate SystemsConversion between Cartesian and Polar[x, y] = [r*cos(theta), r*sin(theta)]r = sqrt(x*x+y*y)theta = acos(x/r) if y>0theta = - acos(x/r) if y<=0No need to memorize this, but you may see it in the codeCompSci 45.8Coordinate SystemsScreen (Graphics)RectangularX increases to the rightY increases as you go downOrigin at upper leftNon-negative integer valuedxy0CompSci 45.9Coordinate SystemsJava 2D (Graphics2D)RectangularX increases to the rightY increases as you go downOrigin at upper leftReal valued (approximated)xy0CompSci 45.10Coordinate SystemsJava2D to Screen conversionSimple – round the floating point to an integer (or just truncate)Screen to Java2D conversionNone needed because integers are approximated by realsCompSci 45.11Coordinate SystemsWhy use Java2D coordinate system?Smoother motionInteger values often need to be rounded which can lead to more calculation errorSimpler to rotate and expandCompSci 45.12Built-in ShapesIn java.awt.geom packageEllipse2D.DoubleRectangle2D.DoubleRoundRectangle2D.DoubleAll constructed with (x, y, width, height)What about circles and squares?CompSci 45.13User-defined ShapesAlso in java.awt.geomGeneralPathLinesCurvesoQuadraticoCubicCan be transformed via AffineTransformAreaConstructive Area GeometryUseful tool for finding intersectionsCompSci 45.14ShapesAll classes so far are all ShapesCan draw them using a Graphics2DCan get boundary informationCan be used to make a Sprite…CompSci 45.15Sprites and ShapesSprites haveSizeShapeOrientationLocationColorOptionally a TrackerCompSci 45.16Making a SpriteHow to make a Sprite:1. Extend Sprite2. In the constructora. Call super()b. Make any Shapec. Call setShape(yourShape)CompSci 45.17Making a Spritepackage tipgame.game.test.sprite;import java.awt.geom.*;public class SquareSprite extends Sprite{ public SquareSprite() {super();Rectangle2D.Double rectangle;rectangle=new Rectangle2D.Double(0, 0, 1, 1);setShape(rectangle); }}How to make a Sprite:1. Extend Sprite2. In the constructora. Call super()b. Make any Shapec. Call setShape(yourShape)CompSci 45.18Making a SpriteSee the video game engine web site for the source code examples that followhttp://www.cs.duke.edu/~cjj1/professional/tipgame/CompSci 45.19Making a SpriteIn the constructor of LightSprite:super();Area area=new Area();Rectangle2D.Double box=new Rectangle2D.Double(0, 0, 0.2, 0.6);area.add(new Area(box));Ellipse2D.Double circle=new Ellipse2D.Double(0.02, 0.02, 0.16, 0.16);area.subtract(new Area(circle));circle=new Ellipse2D.Double(0.02, 0.22, 0.16, 0.16);area.subtract(new Area(circle));circle=new Ellipse2D.Double(0.02, 0.42, 0.16, 0.16);area.subtract(new Area(circle));setShape(area);What does this look like?CompSci 45.20Making a SpriteIn the constructor of TriangleSprite:super();GeneralPath path=new GeneralPath();path.moveTo(0.0f, 0.0f);path.lineTo(1.0f, (float)Math.sqrt(3));path.lineTo(-1.0f, (float)Math.sqrt(3));path.closePath();setShape(path);How could you make a space ship


View Full Document

Duke CPS 004 - Graphics

Documents in this Course
Lecture

Lecture

18 pages

Chapter 7

Chapter 7

18 pages

Chapter 9

Chapter 9

15 pages

Java 1

Java 1

24 pages

Java 3

Java 3

11 pages

Lecture

Lecture

10 pages

Chapter 4

Chapter 4

28 pages

Chap 2

Chap 2

16 pages

Lecture

Lecture

12 pages

HTML

HTML

16 pages

Java 1

Java 1

6 pages

Chapter 4

Chapter 4

16 pages

The Plan

The Plan

25 pages

Lecture

Lecture

16 pages

Chapter 6

Chapter 6

21 pages

Lecture

Lecture

18 pages

Lecture

Lecture

23 pages

Lecture

Lecture

16 pages

Lecture

Lecture

19 pages

Lecture

Lecture

12 pages

Lecture

Lecture

5 pages

Lecture

Lecture

26 pages

Lecture

Lecture

16 pages

Chapter 7

Chapter 7

23 pages

Lecture

Lecture

21 pages

Lecture

Lecture

4 pages

Lecture

Lecture

4 pages

Lecture

Lecture

8 pages

Lecture

Lecture

4 pages

Lecture

Lecture

10 pages

Chapter 4

Chapter 4

32 pages

Java

Java

4 pages

CompSci 4

CompSci 4

18 pages

Lecture

Lecture

26 pages

CompSci 4

CompSci 4

12 pages

HTML

HTML

17 pages

Lecture

Lecture

16 pages

Chapter 5

Chapter 5

22 pages

Lecture

Lecture

4 pages

Chapter 4

Chapter 4

10 pages

Chapter 2

Chapter 2

15 pages

Chapter 8

Chapter 8

14 pages

Lecture

Lecture

15 pages

Load more
Download Graphics
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Graphics and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Graphics 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?