-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assignment 4 #1
base: master
Are you sure you want to change the base?
Assignment 4 #1
Changes from all commits
391f4c2
6ab0439
9854b0b
9004ce9
70c786f
73e5660
57baedd
9b5f4bf
40041d3
c51540e
2bd98bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
# Practical Assignment 4 | ||
**Dealine**: 12.11.2020 | ||
|
||
Please put your name here: | ||
**Name:** ....... | ||
|
||
**Name:** Katrin von Seggern & Jordan Streete | ||
## Problem 1 | ||
### Sphere Solid (Points 25) | ||
In this assignment we will continue working with _compound objects_: solids. | ||
|
@@ -35,7 +35,8 @@ Proceed as follows: | |
6. Extend your code in ```CSolidSphere``` constructor in such a way that the triangles will be created with the additional normals. Calculate these normals (_e.g._ using the spherical coordinate system) and pass them within the triangles' and quads' constructors. | ||
7. Test your implementation on the scene from Problem 1. Compare the difference between the Solid and Primitive spheres. Explain below why smoothed cone looks strange. How would you fix it? | ||
|
||
**Explanation and Suggestion:** ... | ||
**Explanation and Suggestion:** | ||
For the top vertex, we would take quads but since it is not in this code, it chooses a triangle. The smoothed cone was actually not completely smooth and even when we added in the height segment from the sample code, it was a bit bumpy. This might be because there are some areas of the original cone that are already smoothed but are then smoothed again. By adding the bool "smooth" in it as in the sample code, we would check for this case. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem is that you can assign only one normal to the top vertex, per triangle. Thus smooth transitions are not possible. To reduce the effect of faced shape, one can use the technique of multiple height segments. This will reduce the the effect of faced shape to the top segments. |
||
If everything is correct your images should look like this: | ||
|
||
|
@@ -77,6 +78,10 @@ Using the expieriense gained so far, add to the scene Barney and apply his textu | |
Test your implementation on barney.obj with barney.bmp. If everything is correct your image should look like this: | ||
![barney](./doc/barney.jpg) | ||
|
||
We could not get the textures quite correct (except for the one on Barney). The PrimSphere's texture looks closest to what we wanted it but it's a little distorted and the cone's and solid sphere's textures look way off. This is probably because we did not get the getTextureCoords function to work in the SolidSphere.h. | ||
The constructors for the texture coordinates are commented out but still there. | ||
We attached a folder with two renders because we forgot to save the intermediate renders. We also did not get the camera to focus on Barney. | ||
|
||
## Submission | ||
Please submit the assignment by making a pull request. | ||
**Important** : Please make sure that | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,7 +67,18 @@ class CPrimSphere : public IPrim | |
virtual Vec2f getTextureCoords(const Ray& ray) const override | ||
{ | ||
// --- PUT YOUR CODE HERE --- | ||
return Vec2f(0, 0); | ||
Vec3f hitPoint = (ray.org + (ray.t * ray.dir)) - m_origin; | ||
//taken from slides | ||
float x= hitPoint.val[0]; | ||
float y= hitPoint.val[2]; | ||
float z= hitPoint.val[1]; | ||
float phi = atan2(y, x); | ||
float theta = acosf(z / m_radius); | ||
if (isnan(phi)) { | ||
phi = 0; | ||
} | ||
return Vec2f((Pif + phi) / (2 * Pif), theta / Pif); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it should be |
||
//return Vec2f(0, 0); | ||
} | ||
|
||
virtual CBoundingBox getBoundingBox(void) const override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,11 @@ class CSolidCone : public CSolid { | |
const Vec3f top(0, height, 0); // The top point | ||
Vec3f dir0(1, 0, 0); // Initial direction | ||
Vec3f p0 = origin + radius * dir0; // Initial point | ||
Vec3f dir1, p1; // Next point | ||
|
||
//taken from SolidCone.cpp | ||
const Vec3f slope(0, radius / height, 0); | ||
Vec3f n0 = normalize(dir0 + slope); //initial normal | ||
Vec3f dir1, p1, n1; // Next point and normal | ||
float t0 = 0; // Initial texture coordinate | ||
for (size_t s = 0; s < sides; s++) { | ||
float t1 = static_cast<float>(s + 1) / sides; // Next texture coordinate: [1/sides; 1] | ||
|
@@ -34,15 +38,32 @@ class CSolidCone : public CSolid { | |
|
||
// --- PUT YOUR CODE HERE --- | ||
// Sides | ||
if (height >= 0) add(std::make_shared<CPrimTriangle>(pShader, origin + top, p1, p0)); | ||
else add(std::make_shared<CPrimTriangle>(pShader, origin + top, p0, p1)); | ||
n1 = normalize(dir1 + slope); | ||
float h0 = 0; | ||
size_t height_segments = sides / 2; | ||
for (int h = 0; h < height_segments - 1; h++) { | ||
float h1 = static_cast<float>(h + 1) / height_segments; // Next height: [1/height_segments; 1] | ||
add(std::make_shared<CSolidQuad>(pShader, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually you do not need to use quads in construction of the cone. I think this is exactly the reason why texturing did not work. |
||
p0 + h0 * (top - radius * dir0), | ||
p0 + h1 * (top - radius * dir0), | ||
p1 + h1 * (top - radius * dir1), | ||
p1 + h0 * (top - radius * dir1), | ||
Vec2f(t0, 1 - h0), Vec2f(t0, 1 - h1), Vec2f(t1, 1 - h1), Vec2f(t1, 1 - h0), | ||
n0, n0, n1, n1)); | ||
h0 = h1; | ||
} | ||
if (height >= 0) add(std::make_shared<CPrimTriangle>(pShader, origin + top, p1, p0, Vec2f(0.5f, 0), Vec2f(t1, 1), Vec2f(t0, 1), | ||
normalize(n0 + n1), n1, n0)); | ||
else add(std::make_shared<CPrimTriangle>(pShader, origin + top, p0, p1, Vec2f(0.5f, 0), Vec2f(t0, 1), Vec2f(t1, 1), | ||
normalize(n0 + n1), n0, n1)); | ||
|
||
// Cap | ||
if (height >= 0) add(std::make_shared<CPrimTriangle>(pShader, origin, p1, p0)); | ||
else add(std::make_shared<CPrimTriangle>(pShader, origin, p0, p1)); | ||
if (height >= 0) add(std::make_shared<CPrimTriangle>(pShader, origin, p1, p0, Vec2f(0.5f, 1), Vec2f(t1, 1), Vec2f(t0, 1))); | ||
else add(std::make_shared<CPrimTriangle>(pShader, origin, p0, p1, Vec2f(0.5f, 1), Vec2f(t0, 1), Vec2f(t1, 1))); | ||
|
||
dir0 = dir1; | ||
p0 = p1; | ||
n0 = n1; | ||
t0 = t1; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dear Katrin, dear Jordan, I asked you to submit separate solutions. I will count this submission only as the submission of Katrin.