Docsity

2D Bit-Mapped Graphics - Computer Game Design | EECS 494, Study notes of Electrical and Electronics Engineering

Partial preview of the text

Download 2D Bit-Mapped Graphics - Computer Game Design | EECS 494 and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

Arcade Games:

2D Bit-mapped Graphics

John Laird and Sugih Jamin

September 11, 2006

2D Graphics

  • Most 2D games use sprite instead, but basic primitives applicable in 3D graphics
  • Points
    • x,y
  • Lines
    • Two points
    • Draw by drawing all points in between
    • Low-level support for this in hardware or software 4, -2,-

Polygons

  • Defined by vertices
  • Closed: all lines connected
  • Draw one line at a time
  • Can be concave or convex
  • Basis for many games
  • Basis for 3D graphics (triangle)
  • Required data:
    • Position: x, y
    • Number of vertices
    • List of vertices
    • Color (shading) moveto(100,100) lineto(100,300) lineto(500,300) lineto(500,100) lineto(100,100) 100,

Operations on Polygon

  • Translation: moving
  • Scaling: changing size
  • Rotation: turning
  • Clipping and scrolling

Positioning an object

  • Problem: If we move an object, do we need to change

the values of every vertex?

Triangle location: 4, P1: 0, 1 P2: -1, - P3: 1, - P P2 P

  • Solution: change frame of reference
    • World coordinate system for object positions
      • coordinates relative to screen
    • Local coordinate system for points in object
      • coordinates relative to the position of the object (frame of reference)

Scaling: Changing Size

  • Multiply the coordinates of each vertex by the scaling

factor.

  • Everything just expands from the center.
  • object[v1].x *= scale
  • object[v1].y *= scale

Matrix Operations

  • Translation, rotation, scaling can all be collapsed into matrix operations:
  • Translation:
  • Scaling:
  • Rotation: 1 0 0 0 1 0 dx dy 1 x y (^1) * sx 0 0 0 sy 0 0 0 1 cos -sin 0 sin cos 0 0 0 1 sx, sy = x y (^1) * scaling values x y (^1) *

Putting it all together

sxcos -sxsin 0 sysin sycos 0 dx dy 1 x y** (^1) *

Clipping

  • Display the parts of the objects on the screen
    • Can get array out of bound errors if not careful
    • Easy for sprites – done in DirectX
  • Approaches:
    • Border vs. image space or object space

Image Space vs. Object Space

  • Image space:
    • What is going to be displayed
    • Primitives are pixels
    • Operations related to number of pixels
      • Bad when must do in software
      • Good if can do in parallel in hardware – have one “processor”/pixel
  • Object space:
    • Objects being simulated in games
    • Primitives are objects or polygons
    • Operations related to number of objects

Image Space Clipping

  • Image Space:
    • The pixel-level representation of the complete image.
  • Clipping
    • For each pixel, test if it is inside the visible region
    • If buffer is 320x200, test 0-319 in x, 0-199 in y.
  • Evaluation
    • Easy to implement
    • Works for all objects: lines, pixels, squares, bit maps
    • Works for subregions
    • Expensive! Requires overhead for every point rendered if done in software
    • Cheap if done in hardware (well the hardware cost something)

Object Space Clipping

  • Object space:
    • Analytical representation of lines, polygons, etc.
  • Clipping
    • Change object to one that doesn’t need to be clipped (e.g., shorten the line)
    • New object is passed to render engine without any testing for clipping
  • Evaluation
    • Usually more efficient than image space software
      • But hardware support of image space is fast
    • Need different algorithm for different types of objects
      • Lines are easy. Concave objects are problematic
      • Usually just worry about bitmaps

Arcade Games

  • Examples
    • Missile Command, Space Invaders, Breakout, Centipede, Pac-Man, Frogger, Tempest, Joust,
  • Important Traits:
    • Easy-to-learn – simple controls
    • Move objects around the screen
    • Single-screen – or simple scrolling
    • Infinite Play
    • Multiple Lives
    • Scoring – highest score
    • Little to no story

Game Loop

Initialization Overall Game Control Exit wait Game Session Control Player Input Main Logic

  • Physics
  • Game AI
  • Collision Processing Render scene to buffer Copy buffer to display Time sync 1 cycle/frame