further programming for 3d applications ce00849-2 introduction to further programming for 3d...

27
Further Programming for 3D applications CE00849-2 Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and Technology Staffordshire University

Post on 21-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Further Programming for 3D applications CE00849-2 Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and

Further Programming for 3D applicationsCE00849-2

Introduction to Further Programming for 3D application

Bob Hobbs

Faculty of Computing, Engineering and Technology

Staffordshire University

Page 2: Further Programming for 3D applications CE00849-2 Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and

OutlineOutline• Module DetailsModule Details

• What is 3D programming?What is 3D programming?

• Typical Processing StepsTypical Processing Steps

• Modelling and RenderingModelling and Rendering

• ApplicationsApplications

• SummarySummary

Page 3: Further Programming for 3D applications CE00849-2 Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and

Module DetailsModule Details

• Teaching TeamTeaching Team– Bob HobbsBob Hobbs [email protected]– Dr. Len Noriega Dr. Len Noriega [email protected]

• Semester 1Semester 1 15 cats15 cats

• 3 Hours per week3 Hours per week– 1 Hour Lecture 1 Hour Lecture Tue 12pmTue 12pm– 2 Hours Practical 2 Hours Practical Mon 1pm, Tue 4pm & Mon 1pm, Tue 4pm &

Thu 9amThu 9am

Page 4: Further Programming for 3D applications CE00849-2 Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and

Module DetailsModule Details

Course Handbook & Lecture NotesCourse Handbook & Lecture Notes

•http://www.soc.staffs.ac.uk/rgh1

Assignment DetailsAssignment Details

• 50% assignment work50% assignment work

• 50% two hour exam50% two hour exam

Page 5: Further Programming for 3D applications CE00849-2 Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and

Program of StudyProgram of Study• Week 01 Week 01 IntroductionIntroduction• Week 02 Week 02 General 3D concepts, Motion and General 3D concepts, Motion and

CollisionCollision• Week 03 Week 03 Manipulating the Matrix stackManipulating the Matrix stack• Week 04Week 04 Model Importation and Binary File Model Importation and Binary File

handlinghandling• Week 05Week 05 Model Interaction and Viewing Model Interaction and Viewing

transformstransforms• Week 06Week 06 Windowing and GUI elements Windowing and GUI elements • Week 07 Week 07 Lighting and Shading TechniquesLighting and Shading Techniques• Week 08Week 08 Lighting and Shading TechniquesLighting and Shading Techniques• Week 09Week 09 Textures & Texture MappingTextures & Texture Mapping• Week 10Week 10 LOD, Mipmapping, tesselationLOD, Mipmapping, tesselation• Week 11 Week 11 Vertex and Pixel ShadingVertex and Pixel Shading• Week 12Week 12 AssessmentsAssessments

Page 6: Further Programming for 3D applications CE00849-2 Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and

Hierarchy of ModelsHierarchy of Models

Geometry

Physics

Bio-Mechanics

Behaviour

Page 7: Further Programming for 3D applications CE00849-2 Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and

How does this work ?How does this work ?

• Simulation LoopSimulation Loop– read input sensorsread input sensors– update objectsupdate objects– render scene in displayrender scene in display

• Uses traditional 3D graphics methods Uses traditional 3D graphics methods to render or ‘draw’ the sceneto render or ‘draw’ the scene

Page 8: Further Programming for 3D applications CE00849-2 Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and

Simulation LoopSimulation Loop

Check any defined actions

Read Sensors

Update objects with sensor input

Objects perform tasks

Step along any defined paths

Render universe

Page 9: Further Programming for 3D applications CE00849-2 Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and

Introducing OpenGLIntroducing OpenGL• Graphics basics:Graphics basics:

– Transform geometry (object Transform geometry (object world, world world, world eye)eye)– Apply perspective projection (eye Apply perspective projection (eye screen)screen)– Clip to the view frustumClip to the view frustum– Perform visible-surface processing (Z-buffer)Perform visible-surface processing (Z-buffer)– Calculate surface lighting etc.Calculate surface lighting etc.

• Implementing all this is a lot of work Implementing all this is a lot of work (surprise)(surprise)

• OpenGLOpenGL provides a standard provides a standard implementation implementation – So why study the basics?So why study the basics?

Page 10: Further Programming for 3D applications CE00849-2 Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and

OpenGL Design GoalsOpenGL Design Goals• SGI’s design goals for OpenGL:SGI’s design goals for OpenGL:

– Hardware independence without sacrificing Hardware independence without sacrificing performance performance

– Natural, concise API with some built-in Natural, concise API with some built-in extensibilityextensibility

• OpenGL has become a standard because:OpenGL has become a standard because:– It doesn’t try to do too muchIt doesn’t try to do too much

• Only renders the image, doesn’t manage windows, Only renders the image, doesn’t manage windows, etc.etc.

• No high-level animation, modeling, sound (!), etc.No high-level animation, modeling, sound (!), etc.

– It does enoughIt does enough• Useful rendering effects + high performanceUseful rendering effects + high performance

– It is promoted by SGI (& Microsoft, half-It is promoted by SGI (& Microsoft, half-heartedly)heartedly)

Page 11: Further Programming for 3D applications CE00849-2 Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and

OpenGL: ConventionsOpenGL: Conventions

• Functions in OpenGL start with Functions in OpenGL start with glgl– Functions starting with Functions starting with gluglu are utility are utility

functions (i.e., functions (i.e., gluLookAt()gluLookAt()))– Functions starting with Functions starting with glxglx are for interfacing are for interfacing

with the X Windows system (i.e., in gfx.c)with the X Windows system (i.e., in gfx.c)

• Function names indicate argument Function names indicate argument type/#type/#– Functions ending with Functions ending with ff take floats take floats– Functions ending with Functions ending with ii take ints, functions take ints, functions

that end with that end with vv take an array, with take an array, with bb take take byte, etc.byte, etc.

– Ex: Ex: glColor3f()glColor3f() takes 3 floats, but takes 3 floats, but glColor4fv() glColor4fv() takes an array of 4 floatstakes an array of 4 floats

Page 12: Further Programming for 3D applications CE00849-2 Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and

OpenGL: Specifying OpenGL: Specifying GeometryGeometry• Geometry in OpenGL consists of a list of Geometry in OpenGL consists of a list of

vertices in between calls to vertices in between calls to glBegin()glBegin() and and glEnd()glEnd()– A simple example: telling GL to render a triangleA simple example: telling GL to render a triangle

glBegin(GL_POLYGON);glBegin(GL_POLYGON);glVertex3f(x1, y1, z1);glVertex3f(x1, y1, z1);glVertex3f(x2, y2, z2);glVertex3f(x2, y2, z2);glVertex3f(x3, y3, z3);glVertex3f(x3, y3, z3);glEnd();glEnd();

– Usage: Usage: glBegin(glBegin(geomtypegeomtype)) where geomtype is: where geomtype is:• Points, lines, polygons, triangles, quadrilaterals, etc...Points, lines, polygons, triangles, quadrilaterals, etc...

Page 13: Further Programming for 3D applications CE00849-2 Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and

What is 3D rendering?What is 3D rendering?

Object

Viewer

Generally deals with graphical display of 3D objects as seen by viewer

Synthetic image will vary according to: viewing direction, viewer position, illumination, object

properties, ...

Projection onto 2D surface

Page 14: Further Programming for 3D applications CE00849-2 Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and

What is 3D Computer What is 3D Computer Graphics?Graphics?• 3D graphics: generation of 3D graphics: generation of

graphical display (graphical display (renderingrendering) ) of 3D object(s) from of 3D object(s) from specification (specification (model(s)model(s)))

Specification Modelling

Graphical display

Rendering

such as

Page 15: Further Programming for 3D applications CE00849-2 Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and

Wireframe polygonal model Solid object

Vertices

Viewpoint

Typical Processing StepsTypical Processing Steps

Facets

Transformation

Hidden surface removal

Light source

Shading

Page 16: Further Programming for 3D applications CE00849-2 Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and

Object model(s)

Illumination model

Viewing and projection

specification

Graphics engine

Graphical display

Rendering: operations that produce view of scene projected onto view surface

Modelling: numerical description of scene objects, illumination, and viewer

Typical Processing StepsTypical Processing Steps

Page 17: Further Programming for 3D applications CE00849-2 Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and

ModellingModelling

Human Head Model

1438 facets

Page 18: Further Programming for 3D applications CE00849-2 Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and

ModellingModelling

Human Head Model

7258 facets

Page 19: Further Programming for 3D applications CE00849-2 Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and

ModellingModelling

Teacher and Board Model

2074 facets

Page 20: Further Programming for 3D applications CE00849-2 Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and

RenderingRendering

Shaded Human Head

1438 facets

Page 21: Further Programming for 3D applications CE00849-2 Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and

RenderingRendering

Shaded Teacher and Board

Page 22: Further Programming for 3D applications CE00849-2 Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and

Scene GraphsScene Graphs• In VR programming the structure In VR programming the structure

used is a scene graph which is used is a scene graph which is special tree structure designed to special tree structure designed to store information about a scene.store information about a scene.

• Typical elements includeTypical elements include– geometriesgeometries– positional informationpositional information– lightslights– fogfog

Page 23: Further Programming for 3D applications CE00849-2 Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and

Simple scene graphSimple scene graph

Fognode

Lightnode

Rootnode

Groupnode

Xformnode

Geomnode

Page 24: Further Programming for 3D applications CE00849-2 Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and

Scene Graph NodesScene Graph Nodes• Content NodesContent Nodes

– contain basic elements contain basic elements of a sceneof a scene• geometrygeometry

• lightlight

• positionposition

• fogfog

• Group NodesGroup Nodes– no contentno content– link the hierarchylink the hierarchy– allow grouping of allow grouping of

nodes sharing a nodes sharing a common statecommon state

Parent

Child #1

Parent

Child #2

Page 25: Further Programming for 3D applications CE00849-2 Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and

Example HierarchyExample Hierarchy

Geom

Lampost

Xform

T2

Geom

Dog

Xform

T1

Group

“Dog”

Group

“Lampost”Light

Root

Page 26: Further Programming for 3D applications CE00849-2 Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and

ApplicationsApplications• VR programming is used in VR programming is used in many many

applicationsapplications, e.g., e.g.– EntertainmentEntertainment (computer games, ‘movie’ special (computer games, ‘movie’ special

effects, ...)effects, ...)– Human computer interactionHuman computer interaction (GUI, ...) (GUI, ...)– ScienceScience, , educationeducation, , medicinemedicine (visualisation …) (visualisation …) – BusinessBusiness (marketing, ...) (marketing, ...)– ArtArt

Page 27: Further Programming for 3D applications CE00849-2 Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering and

SummarySummary• Simulation consists of a series of scenesSimulation consists of a series of scenes

• Objects defined as Scenes in a scene graph which Objects defined as Scenes in a scene graph which may be one object or a related collection of objectsmay be one object or a related collection of objects

• Each iteration of the simulation loop determines Each iteration of the simulation loop determines actions, translations(along paths) and other inputs actions, translations(along paths) and other inputs which affect properties of the objectswhich affect properties of the objects

• NOT animation !!!NOT animation !!!

• The world is redrawn using rendering processThe world is redrawn using rendering process