19
Object Oriented Design

Object Oriented Design. Goals Bottom Up Design: refactoring fundamental OpenGL functionality Game Engine 1.0 introduction

  • View
    221

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Object Oriented Design. Goals  Bottom Up Design: refactoring fundamental OpenGL functionality  Game Engine 1.0 introduction

Object Oriented Design

Page 2: Object Oriented Design. Goals  Bottom Up Design: refactoring fundamental OpenGL functionality  Game Engine 1.0 introduction

Goals

Bottom Up Design: refactoring fundamental OpenGL functionality

Game Engine 1.0 introduction

Page 3: Object Oriented Design. Goals  Bottom Up Design: refactoring fundamental OpenGL functionality  Game Engine 1.0 introduction

Top Down Requirement Analysis (repeat)

Collect what the different applications/games need to have from the Game Engine

Danger: Getting carried away: create laundry list of

features Creating specification that cannot be

implemented (in time, within budget, …)

Page 4: Object Oriented Design. Goals  Bottom Up Design: refactoring fundamental OpenGL functionality  Game Engine 1.0 introduction

Bottom Up system design

Refactor existing functionality (the OpenGL mega blob) into service classes

Approach: look at instances of applications containing functionality that could be factored out of the application into a the middle ware layer => the Game Engine

Danger: Feature oriented: contrast between cool and necessary

functions

Page 5: Object Oriented Design. Goals  Bottom Up Design: refactoring fundamental OpenGL functionality  Game Engine 1.0 introduction

General Architecture

OpenGL®

Game

Contra

application

middle ware

API

hardware

Page 6: Object Oriented Design. Goals  Bottom Up Design: refactoring fundamental OpenGL functionality  Game Engine 1.0 introduction

Refactoring textured square example

Basic structure of OpenGL application is given by init, display, and reshape

Look for code that, in generalized form can be moved from application into middleware layer

=> collect these operations and attributes in a class called glWindow

Page 7: Object Oriented Design. Goals  Bottom Up Design: refactoring fundamental OpenGL functionality  Game Engine 1.0 introduction

INIT

Collect a set of good initializations that make sense for most applications

Turn most features ON (lighting, texture mode)

In worst case application can overwrite or extend INIT

Page 8: Object Oriented Design. Goals  Bottom Up Design: refactoring fundamental OpenGL functionality  Game Engine 1.0 introduction

DISPLAY

Refactor display method into preDisplay:

low level initializations that most applications would need anyway, e.g, clearing buffer.

Translating, rotating individual objects

mainDisplay: leave this to application to specialize postDisplay:

Cleanup, error handling Buffer swapping (to implement double buffering)

Page 9: Object Oriented Design. Goals  Bottom Up Design: refactoring fundamental OpenGL functionality  Game Engine 1.0 introduction

Factor out utility functions

Example: texture manager Replace complex implementations of texture

loading with single calls of texture managing functions located in middle ware (game engine)

=> useTexture (“image.png”) Load texture file if necessary (implement cache)

Assume file is contained in data/ folder relative to codeBase()

Bind texture Manage name space

Page 10: Object Oriented Design. Goals  Bottom Up Design: refactoring fundamental OpenGL functionality  Game Engine 1.0 introduction

Produce new application with middleware stuff

removed

Page 11: Object Oriented Design. Goals  Bottom Up Design: refactoring fundamental OpenGL functionality  Game Engine 1.0 introduction

Fat free applicationpackage contra;

import gl4java.*;import gl4java.utils.textures.*;import java.io.*;

public class textureGLWindow extends GLWindowApplet {

public void mainDisplay() { useTexture ("borg2.png"); gl.glBegin(GL_POLYGON); gl.glTexCoord2f( 1f, 1f); gl.glVertex3f( 1f, 1f, 0f); gl.glTexCoord2f( 1f, -1f); gl.glVertex3f( 1f, -1f, 0f); gl.glTexCoord2f(-1f, -1f); gl.glVertex3f(-1f, -1f, 0f); gl.glTexCoord2f(-1f, 1f); gl.glVertex3f(-1f, 1f, 0f); gl.glEnd(); }}

Page 12: Object Oriented Design. Goals  Bottom Up Design: refactoring fundamental OpenGL functionality  Game Engine 1.0 introduction

About texture files

Size: 2n x 2m

Size cannot be arbitrary Example

valid: 64 x 512 invalid: 150 x 248

File type Support only .png 24 bit: RGB 32 bit RGBA includes 8 bit transparency

Page 13: Object Oriented Design. Goals  Bottom Up Design: refactoring fundamental OpenGL functionality  Game Engine 1.0 introduction

Game engine 1.0

GLWindow Contains scene Manages resources, e.g. textures

Camera Control camera parameters

Agent Scene content

Page 14: Object Oriented Design. Goals  Bottom Up Design: refactoring fundamental OpenGL functionality  Game Engine 1.0 introduction

ContraCanvas

Agents: List of AgentTextures: Hashtable of Name IdCamera: Camera

init() display() useTexture(Name: String)reshape(Height: Integer, Width: Integer)

Page 15: Object Oriented Design. Goals  Bottom Up Design: refactoring fundamental OpenGL functionality  Game Engine 1.0 introduction

Camera

For details see Red Book chapter 3

Camera

View: GLWindoweye-x, eye-y, eye-z: Float center-x, center-y, center-z: Floatup-x, up-y, up-z: FloatFovy: FloatAspect: FloatNear: FloatFar: Float

aimCamera(eye-x, eye-y, eye-z, center-x, center-y, center-z, up-x, up-y, up-z, Fovy, Aspect, Near, Far: Float)

Page 16: Object Oriented Design. Goals  Bottom Up Design: refactoring fundamental OpenGL functionality  Game Engine 1.0 introduction

Agent

Agent

View: GLWindowName: Stringx, y, z: Floatx-turn, y-turn, z-turn: FloatRoll, Pitch, Heading: FloatAgents: List of Agent

Display()

Page 17: Object Oriented Design. Goals  Bottom Up Design: refactoring fundamental OpenGL functionality  Game Engine 1.0 introduction

Euler Angles

head

rollpitch

Page 18: Object Oriented Design. Goals  Bottom Up Design: refactoring fundamental OpenGL functionality  Game Engine 1.0 introduction

Relative coordinate systems

Example: art dummy With nested objects/agents coordinate

systems should be relative Rotations need to be nested as well

Page 19: Object Oriented Design. Goals  Bottom Up Design: refactoring fundamental OpenGL functionality  Game Engine 1.0 introduction

Homework PROJECT:

Make one object Use Game engine code: <URL> Each team member could make different object part of final

project Apply Textures

TEST applet (local and over network) Email URL to Alex & Andri Due: November 19

READING: OpenGL Red book chapter 9: Texture Mapping http://fly.cc.fer.hr/~unreal/theredbook/ Due: November 19