MCPcopy Create free account
hub / github.com/cinder/Cinder / Earth

Method Earth

samples/Earthquake/src/Earth.cpp:20–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18using namespace ci::app;
19
20Earth::Earth()
21 : mLoc( 0 ), mRadius( 250 ), mMinMagToRender( 2 ), mNumQuakes( 0 )
22{
23 mLightDir = glm::normalize( vec3( 0.025f, 0.25f, 1.0f ) );
24
25 // Load the textures for the Earth.
26 auto fmt = gl::Texture2d::Format().wrap( GL_REPEAT ).mipmap().minFilter( GL_LINEAR_MIPMAP_LINEAR );
27 mTexDiffuse = gl::Texture2d::create( loadImage( loadResource( RES_EARTHDIFFUSE ) ), fmt );
28 mTexNormal = gl::Texture2d::create( loadImage( loadResource( RES_EARTHNORMAL ) ), fmt );
29 mTexMask = gl::Texture2d::create( loadImage( loadResource( RES_EARTHMASK ) ), fmt );
30
31 // Create the Earth mesh with a custom shader.
32 auto earthShader = gl::GlslProg::create( loadResource( RES_PASSTHRU_VERT ), loadResource( RES_EARTH_FRAG ) );
33 earthShader->uniform( "texDiffuse", 0 );
34 earthShader->uniform( "texNormal", 1 );
35 earthShader->uniform( "texMask", 2 );
36 mEarth = gl::Batch::create( geom::Sphere().radius( mRadius ).subdivisions( 120 ), earthShader );
37
38 // Create a cone mesh with a custom shader, which we use to visualize earthquakes.
39 gl::VboMeshRef mesh = gl::VboMesh::create( geom::Cone().height( 1 ).ratio( 0.25f ).subdivisionsHeight( 6 ).subdivisionsAxis( 30 ) );
40
41 // Create an array of initial per-instance model matrices.
42 std::vector<mat4> transforms;
43 transforms.resize( MAX_NUMBER_OF_QUAKES );
44
45 // Create the VBO which will contain per-instance (rather than per-vertex) data.
46 mInstanceDataVbo = gl::Vbo::create( GL_ARRAY_BUFFER, transforms.size() * sizeof( mat4 ), transforms.data(), GL_STATIC_DRAW );
47
48 // We need a geom::BufferLayout to describe this data as mapping to the CUSTOM_0 semantic,
49 // and the 1 (rather than 0) as the last param indicates per-instance (rather than per-vertex).
50 geom::BufferLayout instanceDataLayout;
51 instanceDataLayout.append( geom::Attrib::CUSTOM_0, 16, sizeof( mat4 ), 0, 1 /* per instance */ );
52
53 // Now add it to the VboMesh we already made of the Cone.
54 mesh->appendVbo( instanceDataLayout, mInstanceDataVbo );
55
56 // And finally, build our batch, mapping our CUSTOM_0 attribute to the "iModelMatrix" GLSL vertex attribute.
57 auto quakeShader = gl::GlslProg::create( loadResource( RES_QUAKE_VERT ), loadResource( RES_QUAKE_FRAG ) );
58 mQuake = gl::Batch::create( mesh, quakeShader, { { geom::Attrib::CUSTOM_0, "iModelMatrix" } } );
59}
60
61void Earth::update()
62{

Callers

nothing calls this directly

Calls 14

loadImageFunction · 0.85
loadResourceFunction · 0.85
uniformMethod · 0.80
heightMethod · 0.80
appendVboMethod · 0.80
normalizeFunction · 0.50
FormatClass · 0.50
createFunction · 0.50
SphereFunction · 0.50
wrapMethod · 0.45
resizeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected