Upload
charleen-whitehead
View
221
Download
0
Embed Size (px)
Citation preview
Basic 3D Concepts
Basic 3D Concepts
Overview1. Coordinate systems
2. Transformations
3. Projection
4. Rasterization
ESTABLISHING A COORDINATE SYSTEM
Representing the 3D world Typically, objects in our world consist
of groups of triangles.
face = set of one or more contiguous coplanar adjacent triangles. adjacency?
How do we represent triangles?
Representing the 3D world
How do we represent triangles? By 3 points - the 3 vertices of the
triangle.
How are the points represented?
Representing the 3D world
How are the points represented? Since we are in 3D space, each point is a vector
consisting of 3 values, <x,y,z>, in a cartesian coordinate system. (scalar, vector, matrix)
2D 3D
Representing the 3D world In TorqueScript, a vector is
represented by a list/string of (typically) 3 numbers separated by a space. Example
$fred = “12.0 13 19”;$c0 = getword( $fred, 0 );echo( $c0 ); //what does this print?
Representing the 3D world Unity, uses the Vector3 class.
example (JavaScript)var aPosition = Vector3(1, 1, 1);
example (C#)using UnityEngine;using System.Collections;
public class example : MonoBehaviour {public Vector3 aPosition = new Vector3( 1, 1, 1 );
}
Unity’s Vector3 class
This structure is used throughout Unity to represent D positions and directions.
It also contains functions for doing common vector operations.
See http://unity3d.com/support/documentation/ScriptReference/Vector3.html for more information.
Unity’s Vector3 class
class variables: one, zero, forward, up, right
instance variables: x, y, z
methods: scale, normalize, cross, dot, reflect,
distance, etc. operators:
+, -, *, /, ==, !=
Representing the 3D world How does a vector such as “12.0 1 -5” map
into the “real” world?
We don’t (yet) know if 1 above specifies the H, W, or D!
Furthermore, we don’t know the relationship (l or r, u or d, f or b) between
“12.0 1 -5” and “12.0 2 -5”
Representing the 3D world How does a vector map into the “real”
world? Let’s establish a coordinate system Left is left-handed; right is right-handed. Index is +z, thumb is +y, middle is +x.
Representing objects Objects (models) are composed of polygons
which are composed of triangles.
But these triangles aren’t arbitrary!
Representing objects
Objects (models) are composed of polygons which are composed of triangles.
But these triangles aren’t arbitrary!
Representing the 3D world
We don’t know where our object will be placed in the world. It may even move in the world! We may have more than one in the world
too! So we don’t/can’t fix the object
coordinates in terms of world coordinates!
But we need to specify each of the triangle vertices as numbers.
So what can we do?
Representing the 3D world
So we don’t/can’t fix the object coordinates in terms of world coordinates!
But we need to specify each of the triangle vertices as numbers.
So what can we do? Each object has it’s own object
coordinate system with it’s own origin (0,0,0).
So where is the model origin?
Representing the 3D world
Each object has it’s own object coordinate system with it’s own origin (0,0,0).
So where is the model origin? Anywhere! It can be any point on (or
not on) the object.1. It can be the left-most (or right-most or
top-most or …) point on the object.2. It can be the geometric center
(centroid/center of mass) of the object.
Representing the 3D world
Typically, it is the geometric center (centroid/center of mass) of the object.
Let P be the set of points in the object.
Let Pi=<xi,yi,zi> be a particular point.
How can we calculate the centroid of an object?
Representing the 3D world Typically, it is the
geometric center (centroid/center of mass) of the object. Let P be the set of
points in the object.
Let Pi=<xi,yi,zi> be a particular point.
How can we calculate the centroid of an object?
P
z
P
y
P
xzyx
P
ii
P
ii
P
ii
111 ,,,,
Representing the 3D world
Interesting property of the centroid:
This may not even be a point on the object!
Can you think of a real world object with a center that isn’t on the object?
TRANSFORMATIONS
Transformation
Conversion from object coordinates to world coordinates. Consists of:
Rotation Translation Scale
Transformation
Translation
Transformation
Scale
Transformation
Rotation
Representing the 3D world
In Unity, the Transform Component determines the actual Position, Rotation, and Scale of all objects in the scene.
Every object has a Transform.
Representing the 3D world
In Unity, … Position
X, Y, and Z coordinates Rotation
around the X, Y, and Z axes, measured in degrees
Scale along X, Y, and Z axes A value "1" is the original size (size at which
the object was imported).
Representing the 3D world
In Unity, … All properties of a Transform are
measured relative to the Transform's parent.
If the Transform has no parent, the properties are measured relative to World Space.
PROJECTION
Problem
We have a 3D world consisting of height, width, and depth which is displayed on a 2D computer screen consisting only of height and width!
Projection
Remember that our world is 3D and the computer monitor is 2D.
Projection is the conversion from world coordinates to screen coordinates. Types:
1. parallel (orthographic)2. perspective
Parallel (orthographic) projection
The distance from the camera doesn't affect how large an object appears.
Perspective projection
The further an object is from the camera (viewpoint), the smaller it appears.
Similar to how our eye and how a camera works.
Controlling perspective projection
In both scenes, the fence appears to be relatively close, but the mountains vary greatly.
Controlling perspective projection
Controlling perspective projection
Entire transformation process
RASTERIZATION
Rendering (rasterization)
But that’s not all there is to do! All we’ve done so far is to project the
vertices of triangles onto the screen. What about the points in between (the
vertices)? What about color? What about light sources?
Rendering (rasterization)
The process of converting the 3D model of an object into an on-screen 2D image.
Note: This is most often done by the video card hardware for speed.
Rendering examples
Rendering examples
Note uniformity across face of triangle.
Rendering
Steps:1. transformation
2. projection
3. scan conversion (filling in the triangles) involves shading the surface (considers the
orientation of the surface w.r.t. the location of the light(s))
Rendering
Typically involves a z-buffer (because many points may be projected to the same point on the screen).
PHEW!