Object Oriented Design. Goals Bottom Up Design: refactoring fundamental OpenGL functionality Game...
-
date post
20-Dec-2015 -
Category
Documents
-
view
225 -
download
2
Transcript of Object Oriented Design. Goals Bottom Up Design: refactoring fundamental OpenGL functionality Game...
![Page 1: Object Oriented Design. Goals Bottom Up Design: refactoring fundamental OpenGL functionality Game Engine 1.0 introduction.](https://reader035.fdocuments.us/reader035/viewer/2022062407/56649d435503460f94a1eaae/html5/thumbnails/1.jpg)
Object Oriented Design
![Page 2: Object Oriented Design. Goals Bottom Up Design: refactoring fundamental OpenGL functionality Game Engine 1.0 introduction.](https://reader035.fdocuments.us/reader035/viewer/2022062407/56649d435503460f94a1eaae/html5/thumbnails/2.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062407/56649d435503460f94a1eaae/html5/thumbnails/3.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062407/56649d435503460f94a1eaae/html5/thumbnails/4.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062407/56649d435503460f94a1eaae/html5/thumbnails/5.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062407/56649d435503460f94a1eaae/html5/thumbnails/6.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062407/56649d435503460f94a1eaae/html5/thumbnails/7.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062407/56649d435503460f94a1eaae/html5/thumbnails/8.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062407/56649d435503460f94a1eaae/html5/thumbnails/9.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062407/56649d435503460f94a1eaae/html5/thumbnails/10.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062407/56649d435503460f94a1eaae/html5/thumbnails/11.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062407/56649d435503460f94a1eaae/html5/thumbnails/12.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062407/56649d435503460f94a1eaae/html5/thumbnails/13.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062407/56649d435503460f94a1eaae/html5/thumbnails/14.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062407/56649d435503460f94a1eaae/html5/thumbnails/15.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062407/56649d435503460f94a1eaae/html5/thumbnails/16.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062407/56649d435503460f94a1eaae/html5/thumbnails/17.jpg)
Euler Angles
head
rollpitch
![Page 18: Object Oriented Design. Goals Bottom Up Design: refactoring fundamental OpenGL functionality Game Engine 1.0 introduction.](https://reader035.fdocuments.us/reader035/viewer/2022062407/56649d435503460f94a1eaae/html5/thumbnails/18.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062407/56649d435503460f94a1eaae/html5/thumbnails/19.jpg)
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