Title: Model Construction, Interaction and Viewing
1Model Construction, Interaction and Viewing
- Week 5
- Further Programming for 3D Applications
2Using Modelling Software
- Maya
- 3d Studio Max
- VRML generators
3Features
- Primitives
- Groups
- Complex , irregular shapes
- Lines, Points, Facets
- Curved surfaces
- Texture mapped surfaces
- Lighting and Shading
- Interactions and Behaviours
4Primitives
- Facets constructed from known geometric
relationships - Uses polygons to map to standard mesh structure
- Scaling , shearing, rotation and translation used
to modify vertex information, vertex ordering
remains same
5Complex or Irregular objects
- Manual construction
- Lines and vertices positioned by hand/ eye
- Modification of primitives
- Extrusions
- Curved surfaces
- B-splines
- Bezier curves
- Parametric meshes
- etc
6Scene view
- Scene hierarchy required
- Must have mechanism to store results
- Output file structure must link to internal
structure - Hierarchy
- Relationship between hierarchical nodes
- Vertex list
- Vertex ordering list
- Lighting information
- Texture mapping
- May also hold recent viewing parameters
73DS File structure
- May be ASCII output
- Tags outline structures
- Must read between Tags
- Comma delimitation usually to separate vertex
list and ordering information
8The 3ds File Structure
- Sometimes more efficient to read binary output
- Consists of chunks of binary data
9Chunks
- A chunk is composed of 4 fieldsÂ
- Identifier
- a hexadecimal number of two byte of length that
identify the chunk.. - extrapolate the contained information in it and,
if necessary, in its children, - if instead the chunk is useless we jump it using
the following information... - Length of the chunk
- 4 bytes, that is the sum of the chunk length and
all the lengths of every contained sub-chunks. - Chunk data this field has a variable length. The
real data of the chunk are contained in this
field. - Sub-Chunks
10Typical structure
11Example
- MAIN CHUNK 0x4D4D 3D EDITOR CHUNK 0x3D3D
OBJECT BLOCK 0x4000 TRIANGULAR MESH
0x4100 VERTICES LIST
0x4110Â Â Â Â Â Â Â Â Â Â Â Â FACES DESCRIPTION
0x4120Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â FACES MATERIAL 0x4130
MAPPING COORDINATES LIST 0x4140
SMOOTHING GROUP LIST 0x4150
LOCAL COORDINATES SYSTEM 0x4160 LIGHT
0x4600 SPOTLIGHT 0x4610
CAMERA 0x4700 MATERIAL BLOCK 0xAFFF
12Traversal
- If we for example want to reach the chunk
VERTICES LIST - we have to read the MAIN CHUNK,
- the 3D EDITOR CHUNK,
- the OBJECT BLOCK
- and finally the TRIANGULAR MESH.
13Chunk Identification
14(No Transcript)
15(No Transcript)
16Load a 3DS object
- Implement a "while" loop that continues its
execution until the end of file is reached. - For each cycle read the chunk_id and the
chunk_length. - Through a switch statement analyse the content of
the chunk_id - If the chunk is a section of the tree not needed
to pass then jump the whole length of the chunk
moving the file pointer to the position
calculated using the length of the chunk added to
the current position. In this way jump the chunk
and all the contained sub-chunks. Â - Or if the chunk enables reach of another needed
chunk, or maybe it contains data that is needed,
then read its data, then read the next chunk.Â
17Computing Normals
- normal
- direction specifying orientation of polygon
- w0 means direction with homogeneous coords
- vs. w1 for points/vectors of object vertices
- used for lighting
- must be normalized to unit length
- can compute if not supplied with object
18Transforming Normals
- cannot transform normals using same matrix as
points - nonuniform scaling would cause to be not
perpendicular to desired plane!
given M, what should Q be?
inverse transpose of the modelling transformation
19Using Transformations
- three ways
- modelling transforms
- place objects within scene (shared world)
- affine transformations
- viewing transforms
- place camera
- rigid body transformations rotate, translate
- projection transforms
- change type of camera
- projective transformation
20Viewing and Projection
- need to get from 3D world to 2D image
- projection geometric abstraction
- what eyes or cameras do
- two pieces
- viewing transform
- where is the camera, what is it pointing at?
- perspective transform 3D to 2D
- flatten to image
21Rendering Pipeline
22Rendering Pipeline
23OpenGL Transformation Storage
- modeling and viewing stored together
- possible because no intervening operations
- perspective stored in separate matrix
- specify which matrix is target of operations
- common practice return to default modelview mode
after doing projection operations - glMatrixMode(GL_MODELVIEW)
- glMatrixMode(GL_PROJECTION)
24Coordinate Systems
- result of a transformation
- names
- convenience
- mouse leg, head, tail
- standard conventions in graphics pipeline
- object/modelling
- world
- camera/viewing/eye
- screen/window
- raster/device
25Projective Rendering Pipeline
object
world
viewing
O2W
W2V
V2C
VCS
OCS
WCS
clipping
C2N
CCS
- OCS - object/model coordinate system
- WCS - world coordinate system
- VCS - viewing/camera/eye coordinate system
- CCS - clipping coordinate system
- NDCS - normalized device coordinate system
- DCS - device/display/screen coordinate system
perspectivedivide
normalized device
N2D
NDCS
device
DCS
26Viewing Transformation
y
image plane
VCS
z
OCS
z
y
Peye
y
x
x
WCS
object
world
viewing
OCS
VCS
WCS
Mmod
Mcam
OpenGL ModelView matrix
27Basic Viewing
- starting spot - OpenGL
- camera at world origin
- probably inside an object
- y axis is up
- looking down negative z axis
- why? RHS with x horizontal, y vertical, z out of
screen - translate backward so scene is visible
- move distance d focal length
- where is camera in P1 template code?
- 5 units back, looking down -z axis
28Convenient Camera Motion
- rotate/translate/scale versus
- eye point, gaze/lookat direction, up vector
29OpenGL Viewing Transformation
- gluLookAt(ex,ey,ez,lx,ly,lz,ux,uy,uz)
- postmultiplies current matrix, so to be
safeglMatrixMode(GL_MODELVIEW)glLoadIdentity(
)gluLookAt(ex,ey,ez,lx,ly,lz,ux,uy,uz)// now
ok to do model transformations -
- demo Nate Robins tutorial projection
30Convenient Camera Motion
- rotate/translate/scale versus
- eye point, gaze/lookat direction, up vector
y
lookat
Pref
x
WCS
view
up
z
eye
Peye
31From World to View Coordinates W2V
- translate eye to origin
- rotate view vector (lookat eye) to w axis
- rotate around w to bring up into vw-plane
32Deriving W2V Transformation
33Deriving W2V Transformation
- rotate view vector (lookat eye) to w axis
- w normalized opposite of view/gaze vector g
34Deriving W2V Transformation
- rotate around w to bring up into vw-plane
- u should be perpendicular to vw-plane, thus
perpendicular to w and up vector t - v should be perpendicular to u and w
35Deriving W2V Transformation
- rotate from WCS xyz into uvw coordinate system
with matrix that has columns u, v, w - reminder rotate from uvw to xyz coord sys with
matrix M that has columns u,v,w
MW2VTR
36W2V vs. V2W
- MW2VTR
- we derived position of camera in world
- invert for world with respect to camera
- MV2W(MW2V)-1R-1T-1
- inverse is transpose for orthonormal matrices
- inverse is negative for translations
37W2V vs. V2W
- MW2VTR
- we derived position of camera in world
- invert for world with respect to camera
- MV2W(MW2V)-1R-1T-1
38Moving the Camera or the World?
- two equivalent operations
- move camera one way vs. move world other way
- example
- initial OpenGL camera at origin, looking along
-z axis - create a unit square parallel to camera at z
-10 - translate in z by 3 possible in two ways
- camera moves to z -3
- Note OpenGL models viewing in left-hand
coordinates - camera stays put, but world moves to -7
- resulting image same either way
- possible difference are lights specified in
world or view coordinates?
39World vs. Camera Coordinates Example
a (1,1)W
C2
b (1,1)C1 (5,3)W
c
c (1,1)C2 (1,3)C1 (5,5)W
b
a
C1
W