View
221
Download
2
Tags:
Embed Size (px)
Citation preview
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, …)
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
General Architecture
OpenGL®
Game
Contra
application
middle ware
API
hardware
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
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
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)
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
Produce new application with middleware stuff
removed
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(); }}
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
Game engine 1.0
GLWindow Contains scene Manages resources, e.g. textures
Camera Control camera parameters
Agent Scene content
ContraCanvas
Agents: List of AgentTextures: Hashtable of Name IdCamera: Camera
init() display() useTexture(Name: String)reshape(Height: Integer, Width: Integer)
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)
Agent
Agent
View: GLWindowName: Stringx, y, z: Floatx-turn, y-turn, z-turn: FloatRoll, Pitch, Heading: FloatAgents: List of Agent
Display()
Euler Angles
head
rollpitch
Relative coordinate systems
Example: art dummy With nested objects/agents coordinate
systems should be relative Rotations need to be nested as well
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