View
212
Download
0
Embed Size (px)
Citation preview
ICG2011 Hwk2- How to do?
It’ll introduce
How to do Hwk2 step by step.
No code.
About Hwk2…
Texture Retargeting.
Load an image as texture, and retargeting it over any surface/object file.
Read hwk2 for more details.
Step1:Texture
Read the example code, …
Draw a Quad with texture.
Step2: GL_SELECT
Set name/PickMatrix to the quad, thus when user click on the polygon, program will return a signal.
You must use glSelect on the quad, or get no grade!
When click!!
In pickSquares…
(void) glRenderMode (GL_SELECT); glInitNames(); glPushName(0);
glMatrixMode (GL_PROJECTION); glPushMatrix (); glLoadIdentity (); gluPickMatrix ((GLdouble) x, (GLdouble) (viewport[3] - y), 20.0, 20.0, viewport); gluOrtho2D (0.0, 3.0, 0.0, 3.0); drawSquaresSelect();
glMatrixMode (GL_PROJECTION); glPopMatrix (); glFlush ();
hits = glRenderMode (GL_RENDER);
Define view volume
Draw selection BufferDraw your quad in this function again, and before drawing, use LoadName() and PushName() to assign a distinct name to the quad.
Step3: Define texture coordinate
Calculate the texture coordinate of point user clicked.
(0,0)
(0,1)
(1,0)
(1,1)
This point’s coordinate is near (0.5,0.25)
Step4: Retarget on other polygon (70%)
Click 3~4 times, and store the coordinate.
Draw a new polygon(triangle or quad, up to click times), and give each vertices the stored coordinate.
Step5: GL_SELECT on mesh
Generate a mesh, and set each vertices a name.
Your program has to “pick” each vertices user clicked.
When click, program knows which vertex is clicked.
Step6: Select vertices in region
After click 3 vertices (triangle is simpler), program give each vertices in the triangle region a distinct texture coordinate.
Program have to “scan” which vertices is in the region.
To each points(in screen) in the region, try pickMatrix() to select.
Step7: Give each vertex a coordinate
Use interpolation to give each vertex a coordinate.
Interpolation from 3 boundary vertex (user select).
(0,0)
(0,1)
(1,0)
Texture (0,0)
(0,1)
(1,0)
0.3
0.7
(0,0.7) 0.3
0.7
(0.7,0.3)
=>(0.35,0.5)(0.35,0.5)
Mesh
Step8: Display (85%)
Only display when polygon’s 3 vertices have assigned texture coordinate.
Step9: Obj loader(100%+?)
Use mesh.h/mesh.cpp loading obj files.
You may use vertices’ sequence as name.
Same as step 5~9.
You may generate a simple obj file for debugging, like quadric mesh (as step 5). – lower grade, maybe 95?
For outlier, use face_list in mesh loader to select all outlier vertices.
Due Day: 5/30 (Mon.) 23:59 pm