<- back
hw4 (100 pts) upload hw.cpp to glow codebase reference solution

🟢 questions tend to be easier; I will give extensive hints (e.g. pseudocode, pointing out exactly where your bug is). 🟦 questions tend to be harder; I will give only minor hints (e.g. high-level approach, pointing out generally where your bug is). 🏴 questions tend to be hardest; I will only answer clarifying questions (e.g. what does this word mean?) 🚨 I highly recommend completing all the Green questions first (_not_ including extra credit creative coding). 🚨 If you have time, I recommend then going back to the Blue and Black questions, and trying the easiest ones first. I recommend working on extra credit creative coding only after attempting all problems (or if you need a break). Collaboration is encouraged on all problems, provided you follow the spirit of the 50 ft rule and that all code you submit is your own. You are not expected to solve all the questions perfectly; final semester grades may be curved up.
a. (10 pts) 🟢 Camera Explorer Calculate the camera's distrance to origin (D) as a function of its the angle of view (theta) and height of its field of view at the origin (H). More instructions, and a diagram are in the code. There will be a right triangle involved 🙂👍 b. (80 pts) Mini World A camera "looks along" its $-\hat{\mathbf{z}}$ axis. I.e., for a camera (with a right-handed coordinate system) the vector $\begin{bmatrix}0\\0\\-1\end{bmatrix}$ in that coordinate system points forward. So, given a camera with camera matrix $\mathbf{C}=\begin{bmatrix}\hat{\mathbf{x}} & \hat{\mathbf{y}} & \hat{\mathbf{z}} & {\mathbf{o}} \\ 0 & 0 & 0 & 1 \end{bmatrix}$, we can transform the camera's forward vector into world coordinates using the code vec3 cameraForwardInWorldCoordinates = transformVector(C, V3(0, 0, -1)); The code that sets up the scene is in hw4b() and included below if you are interested. Note that all angles are written in radians; the orbit camera's distance is positive; the tracking camera's target is a pointer to the human's origin; the human is 10 units tall. OrbitCamera orbit = { 200, RAD(75), RAD(15), RAD(-30) }; FPSCamera human = { V3(0, 10, -20), RAD(60), RAD(180), 0 }; TrackingCamera track = { V3(-50, 50, 50), RAD(45), &human.origin }; ArbitraryCamera plane = { V3(0, 100, -500), RAD(45), RotationY(RAD(180)) }; HINT: double CLAMP(double a, double L, double R); returns a if a is less than L, r if a is greater than R, and otherwise a; i.e. it returns a clamped to the internal [L, R]. - (8 pts) 🟢 complete orbit_camera_get_C(...) NOTE: my answer to this question is one line. NOTE: 🚨 there was a typo in the documentation! E.g., mat4 RotationX(double angle_in_randians); is correct (function takes a single double and returns a mat4). - (8 pts) 🟢 complete fps_camera_get_C(...) - (8 pts) 🟢 complete tracking_camera_get_C(...) - (8 pts) 🟢 complete arbitrary_camera_get_C(...) - (8 pts) 🟢 complete orbit_camera_move(...) NOTE: in this question, you are recreating (most of) the camera controls i shipped with cow (Camera3D). it should zoom in and out when you move (roll?) the mouse wheel, and rotate appropriately when you left click and drag 👍 NOTE: the answer to this question is _very_ simple, and the theta involved is _not_ the theta from hw4a. do _not_ use atan, tan, oribt->distance etc. :) - (8 pts) 🟢 complete fps_camera_move(...) NOTE: pressing W should move you in the direction you are facing;
HINTvec3 humansForwardVectorInWorldCoordinates = transformVector(RotationY(human->theta), V3(0, 0, -1));
NOTE: "strafing" means moving left/right in your coordinate system (i.e., side stepping)
HINT human->origin += .01 * humansForwardVectorInWorldCoordinates;
- (8 pts) 🟢 complete arbitrary_camera_move(...) NOTE: you should move in the direction you are facing - (8 pts) 🟢 complete draw_basic_box_with_fake_shadows(...) NOTE: alpha of 0 is fully transparent, alpha of 1 is fully opaque NOTE: we are assuming a directional light source from the sun directly over head (i.e. all rays of light are going straight down) human->origin += .01 * humansForwardVectorInWorldCoordinates; - (8 pts) 🟢 add your bouncy castle from the previous assignment to the world - (8 pts) 🟢 (Creative Coding) add some boxy clouds and whatever else you like to the world (what if the person could jump? that would be kinda cool) a. (10 pts) 🟦 The Arcball Implement the matrix-version (_not_ quaternions) of the rather interesting arcball camera controls. Explanation is in Section 2 here.
🐄