diff options
author | Matt Strapp <matt@mattstrapp.net> | 2021-10-11 20:02:46 -0500 |
---|---|---|
committer | Matt Strapp <matt@mattstrapp.net> | 2021-10-11 20:02:46 -0500 |
commit | aa2a4faf537c9bc7e2e87ff38483e2bf53ed24cf (patch) | |
tree | d5049549bcb1fed21d118c200ae40bac7e1ebbcc /dev/a3-earthquake/earth.cc | |
parent | Fix gnu's stupidity (diff) | |
parent | Publish a3 (diff) | |
download | csci4611-aa2a4faf537c9bc7e2e87ff38483e2bf53ed24cf.tar csci4611-aa2a4faf537c9bc7e2e87ff38483e2bf53ed24cf.tar.gz csci4611-aa2a4faf537c9bc7e2e87ff38483e2bf53ed24cf.tar.bz2 csci4611-aa2a4faf537c9bc7e2e87ff38483e2bf53ed24cf.tar.lz csci4611-aa2a4faf537c9bc7e2e87ff38483e2bf53ed24cf.tar.xz csci4611-aa2a4faf537c9bc7e2e87ff38483e2bf53ed24cf.tar.zst csci4611-aa2a4faf537c9bc7e2e87ff38483e2bf53ed24cf.zip |
Merge branch 'support-code' of github.umn.edu:umn-csci-4611-f21/shared-upstream
Diffstat (limited to '')
-rw-r--r-- | dev/a3-earthquake/earth.cc | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/dev/a3-earthquake/earth.cc b/dev/a3-earthquake/earth.cc new file mode 100644 index 0000000..db43b10 --- /dev/null +++ b/dev/a3-earthquake/earth.cc @@ -0,0 +1,114 @@ +/** CSci-4611 Assignment 3: Earthquake + */ + +#include "earth.h" +#include "config.h" + +#include <vector> + +// for M_PI constant +#define _USE_MATH_DEFINES +#include <math.h> + + +Earth::Earth() { +} + +Earth::~Earth() { +} + +void Earth::Init(const std::vector<std::string> &search_path) { + // init shader program + shader_.Init(); + + // init texture: you can change to a lower-res texture here if needed + earth_tex_.InitFromFile(Platform::FindFile("earth-2k.png", search_path)); + + // init geometry + const int nslices = 10; + const int nstacks = 10; + + // TODO: This is where you need to set the vertices and indiceds for earth_mesh_. + + // As a demo, we'll add a square with 2 triangles. + std::vector<unsigned int> indices; + std::vector<Point3> vertices; + + // four vertices + vertices.push_back(Point3(0,0,0)); + vertices.push_back(Point3(1,0,0)); + vertices.push_back(Point3(1,1,0)); + vertices.push_back(Point3(0,1,0)); + + // indices into the arrays above for the first triangle + indices.push_back(0); + indices.push_back(1); + indices.push_back(2); + + // indices for the second triangle, note some are reused + indices.push_back(0); + indices.push_back(2); + indices.push_back(3); + + earth_mesh_.SetVertices(vertices); + earth_mesh_.SetIndices(indices); + earth_mesh_.UpdateGPUMemory(); +} + + + +void Earth::Draw(const Matrix4 &model_matrix, const Matrix4 &view_matrix, const Matrix4 &proj_matrix) { + // Define a really bright white light. Lighting is a property of the "shader" + DefaultShader::LightProperties light; + light.position = Point3(10,10,10); + light.ambient_intensity = Color(1,1,1); + light.diffuse_intensity = Color(1,1,1); + light.specular_intensity = Color(1,1,1); + shader_.SetLight(0, light); + + // Adust the material properties, material is a property of the thing + // (e.g., a mesh) that we draw with the shader. The reflectance properties + // affect the lighting. The surface texture is the key for getting the + // image of the earth to show up. + DefaultShader::MaterialProperties mat; + mat.ambient_reflectance = Color(0.5, 0.5, 0.5); + mat.diffuse_reflectance = Color(0.75, 0.75, 0.75); + mat.specular_reflectance = Color(0.75, 0.75, 0.75); + mat.surface_texture = earth_tex_; + + // Draw the earth mesh using these settings + if (earth_mesh_.num_triangles() > 0) { + shader_.Draw(model_matrix, view_matrix, proj_matrix, &earth_mesh_, mat); + } +} + + +Point3 Earth::LatLongToSphere(double latitude, double longitude) const { + // TODO: We recommend filling in this function to put all your + // lat,long --> sphere calculations in one place. + return Point3(0,0,0); +} + +Point3 Earth::LatLongToPlane(double latitude, double longitude) const { + // TODO: We recommend filling in this function to put all your + // lat,long --> plane calculations in one place. + return Point3(0,0,0); +} + + + +void Earth::DrawDebugInfo(const Matrix4 &model_matrix, const Matrix4 &view_matrix, const Matrix4 &proj_matrix) { + // This draws a cylinder for each line segment on each edge of each triangle in your mesh. + // So it will be very slow if you have a large mesh, but it's quite useful when you are + // debugging your mesh code, especially if you start with a small mesh. + for (int t=0; t<earth_mesh_.num_triangles(); t++) { + std::vector<unsigned int> indices = earth_mesh_.read_triangle_indices_data(t); + std::vector<Point3> loop; + loop.push_back(earth_mesh_.read_vertex_data(indices[0])); + loop.push_back(earth_mesh_.read_vertex_data(indices[1])); + loop.push_back(earth_mesh_.read_vertex_data(indices[2])); + quick_shapes_.DrawLines(model_matrix, view_matrix, proj_matrix, + Color(1,1,0), loop, QuickShapes::LinesType::LINE_LOOP, 0.005f); + } +} + |