1 // mesh.h
2 //
3 // Copyright (C) 2001, Chris Laurel <claurel@shatters.net>
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 
10 #ifndef _SPHEREMESH_H_
11 #define _SPHEREMESH_H_
12 
13 #include <celmath/vecmath.h>
14 #include <celmath/frustum.h>
15 #include <celengine/mesh.h>
16 #include <celengine/dispmap.h>
17 
18 /*! The SphereMesh class is used to generate displacement mapped
19  *  spheres when loading the now-deprecated .cms geometry files.
20  *  It remains in the Celestia code base for backward compatibility,
21  *  and it's use is discouraged.
22  */
23 class SphereMesh
24 {
25 public:
26     SphereMesh(float radius, int _nRings, int _nSlices);
27     SphereMesh(Vec3f size, int _nRings, int _nSlices);
28     SphereMesh(Vec3f size,
29                const DisplacementMap& dispmap,
30                float height = 1.0f);
31     SphereMesh(Vec3f size,
32                int _nRings, int _nSlices,
33                DisplacementMapFunc func,
34                void* info);
35     ~SphereMesh();
36 
37     //! Convert this object into a standard Celestia mesh.
38     Mesh* convertToMesh() const;
39 
40  private:
41     void createSphere(float radius, int nRings, int nSlices);
42     void generateNormals();
43     void scale(Vec3f);
44     void fixNormals();
45     void displace(const DisplacementMap& dispmap, float height);
46     void displace(DisplacementMapFunc func, void* info);
47 
48     int nRings;
49     int nSlices;
50     int nVertices;
51     float* vertices;
52     float* normals;
53     float* texCoords;
54     float* tangents;
55     int nIndices;
56     unsigned short* indices;
57 };
58 
59 #endif // _SPHEREMESH_H_
60