Do the extra credit

This commit is contained in:
Michael Zhang 2023-04-25 20:08:29 -05:00
parent ac5aa57d80
commit fdbbd5c51a
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B

View file

@ -548,6 +548,20 @@ void update() {
view_angle -= viewing_window::ANGLE_BY;
else if (is_spin_right_held)
view_angle += viewing_window::ANGLE_BY;
if (is_spin_up_held)
vertical_view_angle += viewing_window::ANGLE_BY;
else if (is_spin_down_held)
vertical_view_angle -= viewing_window::ANGLE_BY;
while (view_angle > 2 * PI)
view_angle -= 2 * PI;
while (view_angle < 0)
view_angle += 2 * PI;
while (vertical_view_angle > 2 * PI)
vertical_view_angle -= 2 * PI;
while (vertical_view_angle < 0)
vertical_view_angle += 2 * PI;
}
// Set up normalization matrix
@ -577,14 +591,20 @@ void update() {
auto m = Globals::view.m;
auto eye = Globals::eye_pos;
eye_dir[0] = sin(view_angle);
eye_dir[2] = cos(view_angle);
eye_dir[0] = sin(view_angle) * cos(vertical_view_angle);
eye_dir[2] = cos(view_angle) * cos(vertical_view_angle);
eye_dir[1] = -sin(vertical_view_angle);
const float up_vertical_view_angle = vertical_view_angle + PI / 2;
up_dir[0] = sin(view_angle) * cos(up_vertical_view_angle);
up_dir[2] = cos(view_angle) * cos(up_vertical_view_angle);
up_dir[1] = -sin(up_vertical_view_angle);
Vec3f n = eye_dir * -1.0f;
n.normalize();
// Up direction is (0, 1, 0)
Vec3f u = Globals::up_dir.cross(n);
Vec3f u = up_dir.cross(n);
u.normalize();
// v = n x u