summaryrefslogtreecommitdiffstats
path: root/dev/a6-harold/billboards.h
diff options
context:
space:
mode:
authorJessie Speert <speer034@umn.edu>2021-04-12 15:41:35 -0700
committerJessie Speert <speer034@umn.edu>2021-04-12 15:41:35 -0700
commitcce47f292f7327ab7f11eb277ab6f03dbf19b7f1 (patch)
tree8238f9564e0c3f89a7cb4dd3a13051f24fe6e3a9 /dev/a6-harold/billboards.h
parentUploading Assignment 5 (and worksheet) (diff)
downloadcsci4611-cce47f292f7327ab7f11eb277ab6f03dbf19b7f1.tar
csci4611-cce47f292f7327ab7f11eb277ab6f03dbf19b7f1.tar.gz
csci4611-cce47f292f7327ab7f11eb277ab6f03dbf19b7f1.tar.bz2
csci4611-cce47f292f7327ab7f11eb277ab6f03dbf19b7f1.tar.lz
csci4611-cce47f292f7327ab7f11eb277ab6f03dbf19b7f1.tar.xz
csci4611-cce47f292f7327ab7f11eb277ab6f03dbf19b7f1.tar.zst
csci4611-cce47f292f7327ab7f11eb277ab6f03dbf19b7f1.zip
Added assignment 6 directory and worksheet
Diffstat (limited to '')
-rw-r--r--dev/a6-harold/billboards.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/dev/a6-harold/billboards.h b/dev/a6-harold/billboards.h
new file mode 100644
index 0000000..7de2799
--- /dev/null
+++ b/dev/a6-harold/billboards.h
@@ -0,0 +1,78 @@
+/** CSci-4611 Assignment 6: Harold
+ */
+
+#ifndef BILLBOARDS_H_
+#define BILLBOARDS_H_
+
+#include <mingfx.h>
+using namespace mingfx;
+
+#include "ground.h"
+
+/** Billboards are strokes planted in the ground that rotate automatically to
+ face the viewer. This class holds the entire collection of billboard strokes.
+ */
+class Billboards {
+public:
+ Billboards();
+ virtual ~Billboards();
+
+ void Init(ShaderProgram *stroke3d_shaderprog);
+
+ /// Projects a 2D normalized screen point (e.g., the mouse position in normalized
+ /// device coordinates) to a 3D point on a plane defined by an "origin", which can
+ /// really be any point coincident with the plane, and the plane normal. Returns
+ /// true if the screen point projects onto the plane and stores the result in
+ /// plane_point. Returns false if the screen point does not project onto the plane.
+ bool ScreenPtHitsPlane(const Matrix4 &view_matrix, const Matrix4 &proj_matrix,
+ const Point3 &plane_origin, const Vector3 &plane_normal,
+ const Point2 &normalized_screen_pt, Point3 *plane_point);
+
+
+ /// Checks to see if a ray starting at the eye point and passing through 2D
+ /// normalized screen point projects onto any of the billboards in the scene. If
+ /// so, returns the id of the closest billboard intersected. If not, returns -1.
+ int IntersectBillboard(const Matrix4 &view_matrix, const Matrix4 &proj_matrix,
+ const Point2 &normalized_screen_pt);
+
+
+ /// Adds a new stroke as a billboard by projecting it onto a plane parallel
+ /// to the filmplane that intersects with the anchor point, which should lie
+ /// on the ground.
+ void AddBillboardStroke(const Matrix4 &view_matrix, const Matrix4 &proj_matrix,
+ const std::vector<Point2> &stroke2d, const Mesh &stroke2d_mesh,
+ const Color &stroke_color, Ground *ground_ptr);
+
+ /// Edits an existing billboard by adding an additional stroke to it.
+ void AddToBillboard(const Matrix4 &view_matrix, const Matrix4 &proj_matrix,
+ int billboard_id, const Mesh &stroke2d_mesh,
+ const Color &stroke_color);
+
+
+ /// Adjusts the transformation matrix used to draw each billboard so that the
+ /// billboard will face the camera. Needs to be called each time the camera
+ /// is moved within the scene.
+ void UpdateBillboardRotations(const Point3 &current_eye_point);
+
+
+ /// Draws all of the billboards
+ void Draw(const Matrix4 &view_matrix, const Matrix4 &proj_matrix);
+
+private:
+
+ // each billboard stores the following
+ struct Billboard {
+ Mesh mesh;
+ Color color;
+ Point3 anchor_pt;
+ AABB bounding_box;
+ Matrix4 transform;
+ };
+
+ // the array of all active billboards
+ std::vector<Billboard> billboards_;
+
+ ShaderProgram *stroke3d_shaderprog_;
+};
+
+#endif