summaryrefslogtreecommitdiffstats
path: root/dev/a6-harold/billboards.h
diff options
context:
space:
mode:
authorMatt Strapp <matt@mattstrapp.net>2021-12-17 13:17:58 -0600
committerMatt Strapp <matt@mattstrapp.net>2021-12-17 13:17:58 -0600
commite0a8f6b97c473d28af96f28ca6b46d41b91646a3 (patch)
tree8faef1da18b809c9585c11ba5917f1f8268cddf6 /dev/a6-harold/billboards.h
parentAdd README (diff)
parentClarify how to get eye point in Sky::ScreenPtHitsSky (diff)
downloadcsci4611-e0a8f6b97c473d28af96f28ca6b46d41b91646a3.tar
csci4611-e0a8f6b97c473d28af96f28ca6b46d41b91646a3.tar.gz
csci4611-e0a8f6b97c473d28af96f28ca6b46d41b91646a3.tar.bz2
csci4611-e0a8f6b97c473d28af96f28ca6b46d41b91646a3.tar.lz
csci4611-e0a8f6b97c473d28af96f28ca6b46d41b91646a3.tar.xz
csci4611-e0a8f6b97c473d28af96f28ca6b46d41b91646a3.tar.zst
csci4611-e0a8f6b97c473d28af96f28ca6b46d41b91646a3.zip
Merge branch 'support-code' of https://github.umn.edu/umn-csci-4611-f21/shared-upstream
Diffstat (limited to 'dev/a6-harold/billboards.h')
-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