From 3d48a55104ae3796331263af87113cf02dbf6986 Mon Sep 17 00:00:00 2001 From: Matt Strapp Date: Fri, 17 Dec 2021 20:09:45 -0600 Subject: Do a6 Signed-off-by: Matt Strapp --- dev/a6-harold/README.md | 2 ++ dev/a6-harold/ground.cc | 40 ++++++++++++++++++++++++++-------------- dev/a6-harold/sky.cc | 28 ++++++++++++++++------------ 3 files changed, 44 insertions(+), 26 deletions(-) diff --git a/dev/a6-harold/README.md b/dev/a6-harold/README.md index e69de29..4fb595a 100644 --- a/dev/a6-harold/README.md +++ b/dev/a6-harold/README.md @@ -0,0 +1,2 @@ +# A6 +The only major bug that I found is a crash when the user tries to make a drawing of size 0 in the sky. This can be reproduce by just clicking in the sky. Otherwise everything works as it should. \ No newline at end of file diff --git a/dev/a6-harold/ground.cc b/dev/a6-harold/ground.cc index 51d4d92..969e2d0 100644 --- a/dev/a6-harold/ground.cc +++ b/dev/a6-harold/ground.cc @@ -164,18 +164,27 @@ void Ground::ReshapeGround(const Matrix4 &view_matrix, const Matrix4 &proj_matri // should pass through these two points on the ground. The plane should also // have a normal vector that points toward the camera and is parallel to the // ground plane. + int first_point = 0; + int last_point = stroke2d.size()-1; + Point3 start, end; + ScreenPtHitsGround(view_matrix, proj_matrix, stroke2d[first_point], &start); + ScreenPtHitsGround(view_matrix, proj_matrix, stroke2d[last_point], &end); + Vector3 plane_x = Vector3::Normalize(start - end); + Vector3 plane_y = Vector3(0, 1, 0); + Vector3 plane_normal = Vector3::Normalize(-look); - - - - // 2. Project the 2D stroke into 3D so that it lies on the "projection plane" // defined in step 1. - - - - - + std::vector stroke3d; + for (int i = 0; i < last_point; i++) { + Point3 pt3d; + Point3 mouseIn3d = GfxMath::ScreenToNearPlane(view_matrix, proj_matrix, stroke2d[i]); + Ray eyeThroughMouse = Ray(eye, (mouseIn3d - eye).ToUnit()); + float time; + eyeThroughMouse.IntersectPlane(start, plane_normal, &time, &pt3d); + stroke3d.push_back(pt3d); + } + // 3. Loop through all of the vertices of the ground mesh, and adjust the // height of each based on the equations in section 4.5 of the paper, also // repeated in the assignment handout. The equations rely upon a function @@ -186,11 +195,14 @@ void Ground::ReshapeGround(const Matrix4 &view_matrix, const Matrix4 &proj_matri Point3 P = ground_mesh_.read_vertex_data(i); // original vertex // adjust P according to equations... - - - - - + float h = hfunc(plane_normal, stroke3d, P); + float wd = 0; + float d = P.DistanceToPlane(start, plane_normal); + if (1 - pow(d / 5, 2) > 0) + wd = 1 - pow(d / 5, 2); + if (h != 0) + P = Point3(P[0], (1 - wd) * P[1] + wd * h, P[2]); + new_verts.push_back(P); } ground_mesh_.SetVertices(new_verts); diff --git a/dev/a6-harold/sky.cc b/dev/a6-harold/sky.cc index bc08ca0..8b04a69 100644 --- a/dev/a6-harold/sky.cc +++ b/dev/a6-harold/sky.cc @@ -34,12 +34,12 @@ bool Sky::ScreenPtHitsSky(const Matrix4 &view_matrix, const Matrix4 &proj_matrix Point3 eye = camera_matrix.ColumnToPoint3(3); // TODO: Stitch together your worksheet implementation of this method - return true; + Point3 mouseIn3d = GfxMath::ScreenToNearPlane(view_matrix, proj_matrix, normalized_screen_pt); + Ray eyeThroughMouse = Ray(eye, (mouseIn3d - eye).ToUnit()); + float t; + return eyeThroughMouse.IntersectSphere(Point3::Origin(), 1500, &t, sky_point); } - - - /// Creates a new sky stroke mesh by projecting each vertex of the 2D mesh /// onto the sky dome and saving the result as a new 3D mesh. void Sky::AddSkyStroke(const Matrix4 &view_matrix, const Matrix4 &proj_matrix, @@ -47,15 +47,19 @@ void Sky::AddSkyStroke(const Matrix4 &view_matrix, const Matrix4 &proj_matrix, { // TODO: Create a new SkyStroke and add it to the strokes_ array. + Mesh sky = stroke2d_mesh; + std::vector sky_points; + for (int i = 0; i < sky.num_vertices(); i++) { + Point3 sky_point; + ScreenPtHitsSky(view_matrix, proj_matrix, Point2(sky.read_vertex_data(i)[0], sky.read_vertex_data(i)[1]), &sky_point); + sky_points.push_back(sky_point); + } + sky.SetVertices(sky_points); - - - - - - - - + SkyStroke sky_stroke; + sky_stroke.mesh = sky; + sky_stroke.color = stroke_color; + strokes_.push_back(sky_stroke); } -- cgit v1.2.3