diff options
author | Matt Strapp <matt@mattstrapp.net> | 2021-10-18 20:43:13 -0500 |
---|---|---|
committer | Matt Strapp <matt@mattstrapp.net> | 2021-10-18 20:43:13 -0500 |
commit | 9d5c7eaac6e14caa0c5640efbf973e603eee0cf8 (patch) | |
tree | 2326363e9690ca2facb7bed0c7c7c5c14f5a1d64 /dev/a3-earthquake/quake_app.cc | |
parent | Do w3 (diff) | |
download | csci4611-9d5c7eaac6e14caa0c5640efbf973e603eee0cf8.tar csci4611-9d5c7eaac6e14caa0c5640efbf973e603eee0cf8.tar.gz csci4611-9d5c7eaac6e14caa0c5640efbf973e603eee0cf8.tar.bz2 csci4611-9d5c7eaac6e14caa0c5640efbf973e603eee0cf8.tar.lz csci4611-9d5c7eaac6e14caa0c5640efbf973e603eee0cf8.tar.xz csci4611-9d5c7eaac6e14caa0c5640efbf973e603eee0cf8.tar.zst csci4611-9d5c7eaac6e14caa0c5640efbf973e603eee0cf8.zip |
do a3submission-p3.0
Diffstat (limited to '')
-rw-r--r-- | dev/a3-earthquake/quake_app.cc | 63 |
1 files changed, 60 insertions, 3 deletions
diff --git a/dev/a3-earthquake/quake_app.cc b/dev/a3-earthquake/quake_app.cc index 7904bf3..ead8dca 100644 --- a/dev/a3-earthquake/quake_app.cc +++ b/dev/a3-earthquake/quake_app.cc @@ -78,6 +78,14 @@ void QuakeApp::OnLeftMouseDrag(const Point2 &pos, const Vector2 &delta) { void QuakeApp::OnGlobeBtnPressed() { // TODO: This is where you can switch between flat earth mode and globe mode + globe_mode_ = !globe_mode_; + earth_.set_globe_mode(globe_mode_); + if (globe_mode_) + globe_btn_->setCaption("Map"); + else + globe_btn_->setCaption("Globe"); + + } void QuakeApp::OnDebugBtnPressed() { @@ -109,6 +117,11 @@ void QuakeApp::UpdateSimulation(double dt) { // TODO: Any animation, morphing, rotation of the earth, or other things that should // be updated once each frame would go here. + if (globe_mode_) { + rotation_angle_ += GfxMath::ToRadians(5) / 60; + } else { + rotation_angle_ = 0; + } } @@ -123,8 +136,9 @@ void QuakeApp::InitOpenGL() { // Initialize the texture used for the background image stars_tex_.InitFromFile(Platform::FindFile("iss006e40544.png", search_path_)); -} + globe_mode_ = false; +} void QuakeApp::DrawUsingOpenGL() { quick_shapes_.DrawFullscreenTexture(Color(1,1,1), stars_tex_); @@ -132,9 +146,10 @@ void QuakeApp::DrawUsingOpenGL() { // You can leave this as the identity matrix and we will have a fine view of // the earth. If you want to add any rotation or other animation of the // earth, the model_matrix is where you would apply that. - Matrix4 model_matrix; + Matrix4 model_matrix = Matrix4::RotationY(rotation_angle_); // Draw the earth + earth_.Draw(model_matrix, view_matrix_, proj_matrix_); if (debug_mode_) { earth_.DrawDebugInfo(model_matrix, view_matrix_, proj_matrix_); @@ -142,7 +157,49 @@ void QuakeApp::DrawUsingOpenGL() { // TODO: You'll also need to draw the earthquakes. It's up to you exactly // how you wish to do that. - + // Earthquake eq; + float year_ago = current_time_ - PLAYBACK_WINDOW; + int start_index = quake_db_.FindMostRecentQuake(Date(year_ago)); + int end_index = quake_db_.FindMostRecentQuake(Date(current_time_)); + + for (int i = start_index; i < end_index; i++) { + Earthquake eq = quake_db_.earthquake(i); + float time = eq.date().ToSeconds(); + if (time > year_ago && time < current_time_) { + double magnitude_range = quake_db_.max_magnitude() - quake_db_.min_magnitude(); + double magnitude = (quake_db_.max_magnitude() -eq.magnitude()) / magnitude_range * 10.0; + float size = magnitude * 0.01 * ((time - year_ago) / (current_time_ - year_ago)); + if (size < 0.005) + size = 0.01; + if (size > 0.2) + size = 0.2; + // Set position of quake + // Depends on if in globe mode or not + Point3 pos; + if (globe_mode_) + pos = earth_.LatLongToSphere(eq.latitude(), eq.longitude()); + else + pos = earth_.LatLongToPlane(eq.latitude(), eq.longitude()); + + Color qColor = Color(1,1,1); // black, default (SHOULD NEVER BE SEEN) + if (magnitude < 3.0) + qColor = Color(0,0,1); // blue + else if (magnitude < 4.0) + qColor = Color(0,1,0); // green + else if (magnitude < 5.0) + qColor = Color(1,1,0); // yellow + else + qColor = Color(1,0,0); // red + + // Draw quake + // Vector3 translation = pos - Point3(0,0,0); + Matrix4 quake_matrix = Matrix4::Translation(Vector3(pos[0], + pos[1], pos[2])); + Matrix4 scale_matrix = Matrix4::Scale(Vector3(size, size, size)); + Matrix4 transform = quake_matrix * scale_matrix; + quick_shapes_.DrawSphere(model_matrix * transform, view_matrix_, proj_matrix_, qColor); + } + } } |