summaryrefslogtreecommitdiffstats
path: root/dev/a3-earthquake/earth.h
blob: 877b8abca2bcf0398438d1960141d42a6fe351f1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/** CSci-4611 Assignment 3:  Earthquake
 */

#ifndef EARTH_H_
#define EARTH_H_

#include <mingfx.h>
using namespace mingfx;


/** This class can draw a textured earth as either a plane or a sphere or
    somewhere inbetween in order to support morphing from one shape to another.
 */
class Earth {
public:
    Earth();
    virtual ~Earth();

    /// Load texture and define geometry.  Initializes the mesh to the planar
    /// version of the earth.  The searchPath is for finding the texture file.
    void Init(const std::vector<std::string>& search_path);

    /// Draw the Earth to screen using the current version of the mesh set with
    /// the last call to UpdateMesh.
    void Draw(const Matrix4& model_matrix, const Matrix4& view_matrix, const Matrix4& proj_matrix);

    /// Given latitude and longitude, calculate 3D position for the flat earth
    /// model that lies on a plane
    Point3 LatLongToPlane(double latitude, double longitude) const;

    /// Given latitude and longitude, calculate the 3D position for the spherical
    /// earth model.
    Point3 LatLongToSphere(double latitude, double longitude) const;

    /// This can be a helpful debugging aid when creating your triangle mesh.  It
    /// draws the triangles and normals for the current earth mesh.
    void DrawDebugInfo(const Matrix4& model_matrix, const Matrix4& view_matrix, const Matrix4& proj_matrix);

    /// Drawing either plane or sphere
    void set_globe_mode(bool mode);

protected:
    const int nslices = 10;
    const int nstacks = 10;

    // Stores the earth texture map
    Texture2D earth_tex_;

    // Stores the earth geometry as a renderable mesh
    Mesh earth_mesh_;

    // Renders meshes with texture and some simple shading
    DefaultShader shader_;
    DefaultShader::MaterialProperties earth_material_;

    // Used only for the DrawDebugInfo() routine
    QuickShapes quick_shapes_;

    //Helper values needed for making earth
    std::vector<unsigned int> indices_;
    std::vector<Point3> vertices_;
    std::vector<Point3> sphVertices_;
    std::vector<Vector3> normals_;
    std::vector<Vector3> sphNormals_;
    std::vector<Point2> tex_;
};


#endif