Difference between revisions of "Project6Fall13"

From Immersive Visualization Lab Wiki
Jump to: navigation, search
(1. Build an Editor for Surfaces of Revolution (60 points))
(2. Texture Your Object (40 Points))
 
(28 intermediate revisions by one user not shown)
Line 5: Line 5:
 
==1. Build an Editor for Surfaces of Revolution (60 points)==
 
==1. Build an Editor for Surfaces of Revolution (60 points)==
  
A surface of revolution is an object that is rotationally symmetrical around a central axis.  
+
A surface of revolution is an object that is rotationally symmetrical around a central axis. The following picture shows approximately what is expected.
  
a) Start by drawing a vertical GL_LINE from top to bottom in the center of your OpenGL window. This is your axis of symmetry.  
+
[[Image:sor-editor.jpg]]
  
b) Generate control points for two connected cubic Bezier curves, and display the control points as GL_POINTS - you can create larger points with the glPointSize(size) command. If your points still aren't big enough, use glutSolidSphere. All control points need to be located to the right of the axis of symmetry. Make the interpolating control points red and the approximating ones green.
+
a) Start by drawing a GL_LINE from top to bottom in the center of your OpenGL window. This is your axis of symmetry. ('''5 points''')
  
c) Draw the cubic Bezier curve the control points describe in the color blue.
+
b) Generate control points for two connected cubic Bezier curves, and display the control points as GL_POINTS - you can create larger points with the <tt>glPointSize</tt> command. (If you max out the point size, use <tt>glutSolidSphere</tt>). All control points need to be located to the right of the axis of symmetry. Use different colors for the interpolating control points and the approximating ones. ('''5 points''')
  
d) Calculate the vertices for the surface of revolution by rotating the Bezier curve around the axis of symmetry in steps of about 10 degrees (make this a variable that can be changed upon request). Evaluate about 10 sample points (again, this needs to be a variable that can be changed upon request) along each Bezier curve segment. The two curves need to be C0 continuous at the junction point, but higher level continuity is not required for now.
+
c) Connect the control points with straight lines. ('''5 points''')
  
e) Connect the vertices with GL_QUADS to form a surface. Choose a nice color for the surface.  
+
d) Draw the cubic Bezier curves the control points describe in a different color than the lines: Evaluate at least 20 sample points (this needs to be a const value in your code that can be changed easily) along each Bezier curve segment. The two curves need to be C0 continuous at the junction point, but higher level continuity is not required for now. ('''10 points''')
  
f) Render each GL_QUAD twice, and calculate correct (normalized!) normals: render the quads once in clockwise vertex order and once counter-clockwise, so that both inside and outside of your surface of revolution are rendered correctly. Make sure backface culling is turned on with glEnable(GL_CULL_FACE), or else your surface will flicker.
+
e) Calculate the vertices for the surface of revolution by rotating the Bezier curve around the axis of symmetry in steps of at most 10 degrees (make this a const value that can be changed easily as well). ('''10 points''')
  
g) Enable at least one directional light source and position it so that it nicely illuminates the object. Use a light direction from above and behind the camera and slightly offset to the left.
+
f) Connect the vertices with GL_QUADS in counter-clockwise order to form a surface, and calculate (normalized!) normals. Use a perfect bright white (<tt>glColor3f(1,1,1)</tt>) for the color of the GL_QUADS. ('''10 points''')
  
h) Allow the user to move the control points with the mouse by clicking on them with the left mouse button and dragging them to a new location. Don't allow moving them across the axis of symmetry. Regenerate the surface of revolution for the new set of control points every time the mouse button is released.
+
'''Tip:''' You can compute normals as follows: Given the Bezier curve (x(t),y(t),0) in the x/y plane, you first compute the tangent vector (x'(t),y'(t),0). The corresponding 3D normal vector is then (-y'(t),x'(t),0), which you rotate around the y axis similar to the vertices. Don't forget to normalize the normal vectors.
  
==2. Texture Your Object ('''40 Points''')==
+
g) Enable at least one directional light source and position it so that it nicely illuminates the object. Use a light direction from above and behind the camera and slightly offset to the left. ('''5 points''')
 +
 
 +
h) Allow the user to move the control points with the mouse by clicking on them with the left mouse button and dragging them to a new location. Don't allow moving them across the axis of symmetry. Regenerate the surface of revolution for the new set of control points every time the mouse button is released. ('''10 points''')
 +
 
 +
==2. Texture Your Object (40 Points)==
  
 
Take a photograph or find one on-line and drape it onto your surface of revolution. It needs to stretch across its entire surface area, from top to bottom and all the way around, but only on the outside, not the inside of the object.
 
Take a photograph or find one on-line and drape it onto your surface of revolution. It needs to stretch across its entire surface area, from top to bottom and all the way around, but only on the outside, not the inside of the object.
  
a) Convert the photograph to the PPM format. The free IrfanView image processing tool will do this for you.
+
To familiarize yourself with texture mapping in OpenGL, we provide a [[texture.cpp | sample program]], which loads a PPM file and uses it as a texture for a quad. You can cut and paste code from it into your own project.
  
b) Read the PPM image with this code.
+
Follow these steps:
  
c) For each vertex of the outwards facing quads, set its color to bright white (<tt>glColor3f(1.0, 1.0, 1.0)</tt>). This is necessary because the texel colors will get multiplied with the surface color. Then calculate the vertex's texture coordinates, ranging from 0 to 1 in both dimensions, and set them with <tt>glTexCoord2f</tt>. Make sure the image gets mapped right side up.
+
a) Convert your photograph to the PPM format. The free image processing tool [http://www.irfanview.com IrfanView] will do this for you. ('''5 points''')
  
d) Render the surface of revolution with the texture.
+
b) Read the PPM image and turn it into an OpenGL texture. You can use the code from the above referenced sample program. ('''10 points''')
  
e) Make sure your control points still work as before and allow changing the shape of the object.
+
c) Calculate texture coordinates for each vertex and set them with <tt>glTexCoord2f</tt>. Make sure the texture gets mapped right side up. The image needs to stretch to the entire height of the object and go all the way around it - this means that the texture coordinates at each vertex will need to be fractions of 1. ('''10 points''')
  
'''Tips:'''
+
d) Render the surface of revolution with the texture. ('''5 points''')
  
To familiarize yourself with texture mapping in OpenGL, we provide a [[texture.cpp | sample program]] which loads a PPM file and uses it as a texture for a quad. You can cut and paste code from it into your homework project.
+
e) Add support for the 't' key to toggle between the object with and without the texture. ('''5 points''')
  
Use the following settings for your texture after your first <tt>glBindTexture</tt> for correct lighting, filtering, and texture repeat mode settings:
+
f) Make sure your control points still work as before and allow changing the shape of the object. ('''5 points''')
 +
 
 +
'''Tips:'''
 +
 
 +
* Use the following settings for your texture after your first <tt>glBindTexture</tt> for correct lighting and filtering settings:
  
 
<pre>
 
<pre>
Line 55: Line 63:
 
</pre>
 
</pre>
  
You can compute normals as follows: Given the Bezier curve (x(t),y(t),0) in the x/y plane, you first compute the tangent vector (x'(t),y'(t),0). The corresponding 3D normal vector is then (-y'(t),x'(t),0), which you rotate around the y axis similar to the vertices. Don't forget to normalize the normal vectors. For the texture coordinates u/v, you can use the curve parameter t at each vertex as the u parameter. The v parameter at each vertex is proportional to the rotation angle around the y axis you applied to get the vertex.
+
* For the texture coordinates u/v, you can use the curve parameter t at each vertex as the u parameter. The v parameter at each vertex is proportional to the rotation angle around the y axis you applied to get the vertex.
 +
 
 +
==3. Optional: Polish Your Editor (10 Points)==
 +
 
 +
===Add your trackball rotation functions to rotate the object (2 points)===
 +
 
 +
Support the 'r' key to toggle between rotation mode and edit mode.
 +
 
 +
In rotation mode, the mouse controls the object like in project 4, allowing rotation and scale functionality. Axis of symmetry, control points and Bezier curves are not shown. Disable backface culling with <tt>glDisable(GL_CULL_FACE)</tt> to ensure that even the back facing parts of your object are drawn (note that the lighting for them will be incorrect due to their normals pointing in the wrong direction).
 +
 
 +
When edit mode is entered, the display switches back to what it was in parts 1 and 2 of the project.
 +
 
 +
===Allow adding and deleting Bezier curve segments (4 points)===
 +
 
 +
Support the 'a' key to add an additional cubic Bezier curve to the existing set of curves. It is sufficient to add them to one end of the set. Support the 'd' key to delete the most recently added curve. Update the surface of revolution every time one of these keys is pressed. The newly added curves must be shown with control points, just like the first two curves in part 1.
 +
 
 +
===Add support for Bezier handles (4 points) ===
 +
 
 +
Bezier handles force C1 continuity at the junction points. Consult the image on Bezier handles in the course slides to see how such a handle is visually displayed: It is a line through each junction point between two Bezier curves, which goes through the neighboring approximating control points. The line forces these adjacent control points to be in a line with the junction point. Moving one of the neighboring approximating control points will automatically move the other to keep them in line with the junction point. Moving the junction point will move both adjacent control points along with it.

Latest revision as of 12:21, 14 November 2013

Contents

Project 6: Surface of Revolution Editor

In this project you will need to build a simple editor for surfaces of revolution. This project is due on Friday, November 15th. The assignment will be discussed on November 8th at 4pm, the location is TBD.

1. Build an Editor for Surfaces of Revolution (60 points)

A surface of revolution is an object that is rotationally symmetrical around a central axis. The following picture shows approximately what is expected.

Sor-editor.jpg

a) Start by drawing a GL_LINE from top to bottom in the center of your OpenGL window. This is your axis of symmetry. (5 points)

b) Generate control points for two connected cubic Bezier curves, and display the control points as GL_POINTS - you can create larger points with the glPointSize command. (If you max out the point size, use glutSolidSphere). All control points need to be located to the right of the axis of symmetry. Use different colors for the interpolating control points and the approximating ones. (5 points)

c) Connect the control points with straight lines. (5 points)

d) Draw the cubic Bezier curves the control points describe in a different color than the lines: Evaluate at least 20 sample points (this needs to be a const value in your code that can be changed easily) along each Bezier curve segment. The two curves need to be C0 continuous at the junction point, but higher level continuity is not required for now. (10 points)

e) Calculate the vertices for the surface of revolution by rotating the Bezier curve around the axis of symmetry in steps of at most 10 degrees (make this a const value that can be changed easily as well). (10 points)

f) Connect the vertices with GL_QUADS in counter-clockwise order to form a surface, and calculate (normalized!) normals. Use a perfect bright white (glColor3f(1,1,1)) for the color of the GL_QUADS. (10 points)

Tip: You can compute normals as follows: Given the Bezier curve (x(t),y(t),0) in the x/y plane, you first compute the tangent vector (x'(t),y'(t),0). The corresponding 3D normal vector is then (-y'(t),x'(t),0), which you rotate around the y axis similar to the vertices. Don't forget to normalize the normal vectors.

g) Enable at least one directional light source and position it so that it nicely illuminates the object. Use a light direction from above and behind the camera and slightly offset to the left. (5 points)

h) Allow the user to move the control points with the mouse by clicking on them with the left mouse button and dragging them to a new location. Don't allow moving them across the axis of symmetry. Regenerate the surface of revolution for the new set of control points every time the mouse button is released. (10 points)

2. Texture Your Object (40 Points)

Take a photograph or find one on-line and drape it onto your surface of revolution. It needs to stretch across its entire surface area, from top to bottom and all the way around, but only on the outside, not the inside of the object.

To familiarize yourself with texture mapping in OpenGL, we provide a sample program, which loads a PPM file and uses it as a texture for a quad. You can cut and paste code from it into your own project.

Follow these steps:

a) Convert your photograph to the PPM format. The free image processing tool IrfanView will do this for you. (5 points)

b) Read the PPM image and turn it into an OpenGL texture. You can use the code from the above referenced sample program. (10 points)

c) Calculate texture coordinates for each vertex and set them with glTexCoord2f. Make sure the texture gets mapped right side up. The image needs to stretch to the entire height of the object and go all the way around it - this means that the texture coordinates at each vertex will need to be fractions of 1. (10 points)

d) Render the surface of revolution with the texture. (5 points)

e) Add support for the 't' key to toggle between the object with and without the texture. (5 points)

f) Make sure your control points still work as before and allow changing the shape of the object. (5 points)

Tips:

  • Use the following settings for your texture after your first glBindTexture for correct lighting and filtering settings:
  // Make sure no bytes are padded:
  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

  // Select GL_MODULATE to mix texture with quad color for shading:
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

  // Use bilinear interpolation:
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  • For the texture coordinates u/v, you can use the curve parameter t at each vertex as the u parameter. The v parameter at each vertex is proportional to the rotation angle around the y axis you applied to get the vertex.

3. Optional: Polish Your Editor (10 Points)

Add your trackball rotation functions to rotate the object (2 points)

Support the 'r' key to toggle between rotation mode and edit mode.

In rotation mode, the mouse controls the object like in project 4, allowing rotation and scale functionality. Axis of symmetry, control points and Bezier curves are not shown. Disable backface culling with glDisable(GL_CULL_FACE) to ensure that even the back facing parts of your object are drawn (note that the lighting for them will be incorrect due to their normals pointing in the wrong direction).

When edit mode is entered, the display switches back to what it was in parts 1 and 2 of the project.

Allow adding and deleting Bezier curve segments (4 points)

Support the 'a' key to add an additional cubic Bezier curve to the existing set of curves. It is sufficient to add them to one end of the set. Support the 'd' key to delete the most recently added curve. Update the surface of revolution every time one of these keys is pressed. The newly added curves must be shown with control points, just like the first two curves in part 1.

Add support for Bezier handles (4 points)

Bezier handles force C1 continuity at the junction points. Consult the image on Bezier handles in the course slides to see how such a handle is visually displayed: It is a line through each junction point between two Bezier curves, which goes through the neighboring approximating control points. The line forces these adjacent control points to be in a line with the junction point. Moving one of the neighboring approximating control points will automatically move the other to keep them in line with the junction point. Moving the junction point will move both adjacent control points along with it.