180 likes | 358 Views
159.235 Graphics & Graphical Programming. Lecture 19 - Introduction to 3D Graphics. 3D Intro - Outline. 2D Viewing Parametric Equations 3D Models Projective Geometry 3d Graphics Rendering and Voxels Movies, games, and Virtual Reality Polygons and scenegraphs. 2D Viewing.
E N D
159.235 Graphics & Graphical Programming Lecture 19 - Introduction to 3D Graphics Graphics
3D Intro - Outline • 2D Viewing • Parametric Equations • 3D Models • Projective Geometry • 3d Graphics Rendering and Voxels • Movies, games, and Virtual Reality • Polygons and scenegraphs Graphics
2D Viewing • Our “model” so far has been entirely 2-dimensional • Model uses x,y Cartesian coordinates • Simple mapping to pixel space coordinates for our “rendering” • Cropping (what to do if model is outside our renderable window) • Not trivial but details hidden from us by the graphics library • Scaling and other Affine Transforms possible • Colours, text, drawing primitives such as line, rectangle, filled shapes … Graphics
Details of Drawing Shapes and Clipping Them • Graphics library (in our case the java Swing Library) does all this. • Some interesting algorithms in fact needed for this • Shapes drawn parametrically • Clipping regions calculated rather than just implemented naively • Important for speed and Performance Graphics
Parametric Equation for a Circle • x = R cos(theta) • y = R sin(theta) • R = sqrt( x^2 + y^2 ) • R is radius (a constant for a particular circle) • theta is a parameter of the equation (radians angle - 2Pi -> 1 full rotation or 360 degrees) • Implement as: • for( theta = 0; theta < 2Pi; theta += increment ) Graphics
Circle Equation is Basis for Polar Coordinates • (r,theta) <--> (x,y) • given a particular origin (x_0,y_0) • We have affine transform utility: • g2.translate( x-amount, y-amount); Graphics
What about 3D Models? • What do we do if we want to render something in 3D? • Our model has (x,y,z) cartesian coordinates • How do we translate this into a rendered view? • We use some projective geometry: • Project what you would see as a flat image or picture if you looked at a real world 3D object from a particular viewpoint Graphics
Projective Geometry • We need transformations to project the model coordinates to a view plane coordinate space (what we or a camera “sees”) • But we see a distorted view - things further away look different from things that are closer • So also apply a perspective transformation - to distort what a viewer would see from a particular point in model space • So a lot more computation needed to make all this work - luckily modern libraries will do a lot of the work for us Graphics
Geometry Implementation • If we needed to build a library we would need to go into details of the Mathematical formulations of the projection transforms • Typically write a a matrix that operates on a world coordinate space to a viewing one • World might be (x,y,z) • View might be (u,v) - like normal (x,y) but in the plane of the view Graphics
3D Graphics Implementation • Generally your application maintains a world model • This is mapped to the 3D internal representation • A projection computes what would be seen in a 2D view space • A rendering turns the 2D view into pixels Graphics
Rendering Pipeline • This sequence of getting from model world to pixels is often called the rendering pipeline • Sometimes have special hardware to help the various stages - eg polygon calculations • Our world model might be based on a wire-frame model built from polygonal shapes and with surface textures or images that we paste on top of them • Together this information constitutes the “scene-graph” Graphics
Voxels • We sometimes imagine a voxelated model • Voxel = volume element • Pixel = picture element • But until recently we did not have hardware that could “render” voxels directly • Polymer prototyping machines come close • The scene-graph model is more useful Graphics
3D Graphics is the basis of VR • Virtual Reality (VR) is when we try to fool our human senses into thinking we are interacting with a model world that need never actually exist in reality • It is entirely simulated in our program • We render it into displays that we can surround ourselves with and total immersion VR goes further and simulates other sensory information such as sounds or movements Graphics
3D Graphics used in Movies & Games • Recent examples - Shrek and Gollum • Wire-frame models that are updated according to some approximate physics calculations (not yet in real-time!) • Superpose texture maps (colours etc) onto the surfaces defined by the wire-frames • Render and image - becomes still frame in a movie or game. • Around 25 frames-per-second fools the human vision system into thinking we see continuous motion Graphics
3D Practicalities • How do we represent the world model? • Wireframe model is set of polygons • Possibly a very large set if the world object has smooth rounded surfaces • A cube could be modeled with just 6 polygons (6 squares in fact) • Each might have a separate texture and colour Graphics
Polygons • A polygon - many sided shape will have a set of vertices and edges • A Graphics library may provide a Polygon class • There are various file formats for storing polygon information • A growing set of proprietary and some free tools that let us design things - create the polygon information • We can then store/exchange/combine these files • Often our own applications generate the polygons from some “physics” (rules about our model world) Graphics
Generating World “Objects” • We can develop and combine algorithms to generate shapes • A cube is 6 squares • A sphere could be generated parametrically from parametric spherical trigonometrical equation • We can approximate a sphere by a surface made up of lots of polygons, with an opaque colour Graphics
Summary • 3D Graphics allows us to render a real world model into a projected view • The view can be rendered as per normal graphically • All the information in a “scene-graph” together with the viewpoint and lighting model etc tells us what we would see if the model were “real” • Uses in Movies, Games and VR systems • Computationally very expensive - supercomputers needed Graphics