Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Graphics Programming: Matrices and Transformations CSE 3451 Matt Boggus.

Similar presentations

Presentation on theme: "Computer Graphics Programming: Matrices and Transformations CSE 3451 Matt Boggus."— Presentation transcript:

1 Computer Graphics Programming: Matrices and Transformations CSE 3451 Matt Boggus

2 Outline Computer graphics overview Types of 3D modeling – Solid – Shell/Boundary Unity Mesh objects

3 Computer Graphics Algorithmically generating a 2D image from 3D data (models, textures, lighting) Also called rendering Raster graphics – Array of pixels – About 25x25 in the example -> Algorithm tradeoffs: – Computation time – Memory cost – Image quality

4 Computer Graphics The graphics pipeline is a series of conversions of points into different coordinate systems or spaces

5 Computer Graphics Virtual cameras in Unity will handle everything from the viewing transformation on

6 Solid modeling Define the volume of an object Example: volume elements (voxels)

7 Shell/Boundary modeling Represent the surface of an object (i.e. the boundary between the solid volume and air)

8 OpenGL polygon modeling Legacy syntax example: glBegin(GL_POLYGON); glVertex2f(-0.5, -0.5); glVertex2f(-0.5, 0.5); glVertex2f(0.5, 0.5); glVertex2f(0.5, -0.5); glEnd();

9 Polygon winding order Clockwise Counter-clockwise Unity uses a clockwise winding order for determining front-facing polygons

10 Unity specifying geometry – Mesh class Requires two types of values – Vertices (specified as an array of 3D points) – Triangles (specified as an array of Vector3s whose values are indices in the vertex array) Documentation and Example – neratingMeshGeometryProcedurally.html neratingMeshGeometryProcedurally.html – nce/Mesh.html nce/Mesh.html The code on the following slides is attached to a cube game object (rather than an EmptyObject)

11 Mesh pt. 1 – assign vertices Mesh mesh = new Mesh(); gameObject.GetComponent ().mesh = mesh; Vector3[] vertices = new Vector3[4]; vertices[0] = new Vector3(0.0f, 0.0f, 0.0f); vertices[1] = new Vector3(width, 0.0f, 0.0f); vertices[2] = new Vector3(0.0f, height, 0.0f); vertices[3] = new Vector3(width, height, 0.0f); mesh.vertices = vertices;

12 Mesh pt. 2 – assign triangles int[] tri = new int[6]; // Lower left triangle of a quad tri[0] = 0; tri[1] = 2; tri[2] = 1; // Upper right triangle of a quad tri[3] = 2; tri[4] = 3; tri[5] = 1; mesh.triangles = tri;

13 More mesh values // Normal vectors (one per vertex) – for illumination Vector3[] normals = new Vector3[4]; // compute normals… mesh.normals = normals; // Texture coordinates (one per vertex) – for texturing Vector2[] uv = new Vector2[4]; // assign uvs… mesh.uv = uv; Side note: You can also use mesh.RecalculateNormals(); if you want Unity to try to compute normals for you.

14 Critical thinking – geometry modeling Which of the following statements is true? A.Smooth models like spheres are inexpensive to create B.A 3D model can be created faster than four hand drawn 2D images of the object from the front, back, and sides C.3D shapes can be constructed out of 2D primitives D.All meshes must be solid volumes

Download ppt "Computer Graphics Programming: Matrices and Transformations CSE 3451 Matt Boggus."

Similar presentations

Ads by Google