summaryrefslogtreecommitdiffstats
path: root/dev/a6-harold/ground.cc
diff options
context:
space:
mode:
authorMatt Strapp <matt@mattstrapp.net>2021-12-17 20:09:45 -0600
committerMatt Strapp <matt@mattstrapp.net>2021-12-17 20:09:45 -0600
commit3d48a55104ae3796331263af87113cf02dbf6986 (patch)
tree1df2d8499de3446de64a5a58c73a3eab68b3f6e7 /dev/a6-harold/ground.cc
parentMerge branch 'support-code' of https://github.umn.edu/umn-csci-4611-f21/share... (diff)
downloadcsci4611-359e347a627342f176ff7a8c3ad77d43d5c3eb15.tar
csci4611-359e347a627342f176ff7a8c3ad77d43d5c3eb15.tar.gz
csci4611-359e347a627342f176ff7a8c3ad77d43d5c3eb15.tar.bz2
csci4611-359e347a627342f176ff7a8c3ad77d43d5c3eb15.tar.lz
csci4611-359e347a627342f176ff7a8c3ad77d43d5c3eb15.tar.xz
csci4611-359e347a627342f176ff7a8c3ad77d43d5c3eb15.tar.zst
csci4611-359e347a627342f176ff7a8c3ad77d43d5c3eb15.zip
Signed-off-by: Matt Strapp <matt@mattstrapp.net>
Diffstat (limited to 'dev/a6-harold/ground.cc')
-rw-r--r--dev/a6-harold/ground.cc40
1 files changed, 26 insertions, 14 deletions
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<Point3> 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);