Presentation on theme: "Computer Graphics Programming: Matrices and Transformations CSE 3451 Matt Boggus."— Presentation transcript:
Computer Graphics Programming: Matrices and Transformations CSE 3451 Matt Boggus
Outline Computer graphics overview Types of 3D modeling – Solid – Shell/Boundary Unity Mesh objects
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
Computer Graphics The graphics pipeline is a series of conversions of points into different coordinate systems or spaces
Computer Graphics Virtual cameras in Unity will handle everything from the viewing transformation on
Solid modeling Define the volume of an object Example: volume elements (voxels) http://mossman.es/videogames-based-in-voxels/
Shell/Boundary modeling Represent the surface of an object (i.e. the boundary between the solid volume and air) http://www.webreference.com/3d/cararra/3.html
Polygon winding order Clockwise Counter-clockwise Unity uses a clockwise winding order for determining front-facing polygons
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 – http://docs.unity3d.com/Documentation/Manual/Ge neratingMeshGeometryProcedurally.html http://docs.unity3d.com/Documentation/Manual/Ge neratingMeshGeometryProcedurally.html – http://docs.unity3d.com/Documentation/ScriptRefere nce/Mesh.html http://docs.unity3d.com/Documentation/ScriptRefere nce/Mesh.html The code on the following slides is attached to a cube game object (rather than an EmptyObject)
Mesh pt. 1 – assign vertices Mesh mesh = new Mesh(); gameObject.GetComponent ().mesh = mesh; Vector3 vertices = new Vector3; vertices = new Vector3(0.0f, 0.0f, 0.0f); vertices = new Vector3(width, 0.0f, 0.0f); vertices = new Vector3(0.0f, height, 0.0f); vertices = new Vector3(width, height, 0.0f); mesh.vertices = vertices;
Mesh pt. 2 – assign triangles int tri = new int; // Lower left triangle of a quad tri = 0; tri = 2; tri = 1; // Upper right triangle of a quad tri = 2; tri = 3; tri = 1; mesh.triangles = tri;
More mesh values // Normal vectors (one per vertex) – for illumination Vector3 normals = new Vector3; // compute normals… mesh.normals = normals; // Texture coordinates (one per vertex) – for texturing Vector2 uv = new Vector2; // assign uvs… mesh.uv = uv; Side note: You can also use mesh.RecalculateNormals(); if you want Unity to try to compute normals for you.
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
Your consent to our cookies if you continue to use this website.