本文整理汇总了C++中target_camera::set_target方法的典型用法代码示例。如果您正苦于以下问题:C++ target_camera::set_target方法的具体用法?C++ target_camera::set_target怎么用?C++ target_camera::set_target使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类target_camera
的用法示例。
在下文中一共展示了target_camera::set_target方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load_content
bool load_content() {
geom.set_type(GL_TRIANGLE_STRIP);
// Create quad data
// Positions
vector<vec3> positions{vec3(-1.0f, -1.0f, 0.0f), vec3(1.0f, -1.0f, 0.0f), vec3(-1.0f, 1.0f, 0.0f),
vec3(1.0f, 1.0f, 0.0f)};
// Colours
vector<vec4> colours{vec4(1.0f, 0.0f, 0.0f, 1.0f), vec4(1.0f, 0.0f, 0.0f, 1.0f), vec4(1.0f, 0.0f, 0.0f, 1.0f),
vec4(1.0f, 0.0f, 0.0f, 1.0f)};
// Add to the geometry
geom.add_buffer(positions, BUFFER_INDEXES::POSITION_BUFFER);
geom.add_buffer(colours, BUFFER_INDEXES::COLOUR_BUFFER);
// Load in shaders
eff.add_shader("shaders/basic.vert", GL_VERTEX_SHADER);
eff.add_shader("shaders/basic.frag", GL_FRAGMENT_SHADER);
// Build effect
eff.build();
// Set camera properties
cam.set_position(vec3(10.0f, 10.0f, 10.0f));
cam.set_target(vec3(0.0f, 0.0f, 0.0f));
auto aspect = static_cast<float>(renderer::get_screen_width()) / static_cast<float>(renderer::get_screen_height());
cam.set_projection(quarter_pi<float>(), aspect, 2.414f, 1000.0f);
return true;
}
示例2: load_content
bool load_content() {
// Create mesh object, cheating and using the mesh builder for now
m = mesh(geometry_builder::create_box());
// Scale geometry
m.get_transform().scale = vec3(10.0f);
// Load in dissolve shader
eff.add_shader("33_Dissolve/dissolve.vert", GL_VERTEX_SHADER);
eff.add_shader("33_Dissolve/dissolve.frag", GL_FRAGMENT_SHADER);
// Build effect
eff.build();
// Load in textures
tex = texture("textures/checker.png");
dissolve = texture("textures/blend_map2.jpg");
// Set camera properties
cam.set_position(vec3(30.0f, 30.0f, 30.0f));
cam.set_target(vec3(0.0f, 0.0f, 0.0f));
auto aspect = static_cast<float>(renderer::get_screen_width()) / static_cast<float>(renderer::get_screen_height());
cam.set_projection(quarter_pi<float>(), aspect, 2.414f, 1000.0f);
return true;
}
示例3: load_content
bool load_content()
{
// *************
// Load in model
// *************
m = mesh(geometry("..\\resources\\models\\teapot.obj"));
// ***************
// Load in texture
// ***************
tex = texture("..\\resources\\textures\\checked.gif", false, false);
// Load in shaders
eff.add_shader("..\\resources\\shaders\\simple_texture.vert", GL_VERTEX_SHADER);
eff.add_shader("..\\resources\\shaders\\simple_texture.frag", GL_FRAGMENT_SHADER);
// Build effect
eff.build();
// Set camera properties
cam.set_position(vec3(200.0f, 200.0f, 200.0f));
cam.set_target(vec3(0.0f, 0.0f, 0.0f));
auto aspect = static_cast<float>(renderer::get_screen_width()) / static_cast<float>(renderer::get_screen_height());
cam.set_projection(quarter_pi<float>(), aspect, 2.414f, 1000.0f);
return true;
}
示例4: load_content
bool load_content() {
// *********************************
// Create shadow map- use screen size
shadow = shadow_map(renderer::get_screen_width(), renderer::get_screen_height());
// Create plane mesh
meshes["plane"] = mesh(geometry_builder::create_plane());
// Create "teapot" mesh by loading in models/teapot.obj
meshes["teapot"] = mesh(geometry("models/teapot.obj"));
// Need to rotate the teapot on x by negative pi/2
meshes["teapot"].get_transform().rotate(vec3(-90.0, 0.0, 0.0));
// Scale the teapot - (0.1, 0.1, 0.1)
meshes["teapot"].get_transform().scale = vec3(0.1,0.1,0.1);
// ***********************
// Set materials
// - all emissive is black
// - all specular is white
// - all shininess is 25
// ***********************
// White plane
meshes["plane"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f));
meshes["plane"].get_material().set_diffuse(vec4(1.0f, 1.0f, 1.0f, 1.0f));
meshes["plane"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f));
meshes["plane"].get_material().set_shininess(25.0f);
// Red teapot
meshes["teapot"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f));
meshes["teapot"].get_material().set_diffuse(vec4(1.0f, 0.0f, 0.0f, 1.0f));
meshes["teapot"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f));
meshes["teapot"].get_material().set_shininess(25.0f);
// *********************************
// Set spot properties
// Pos (20, 30, 0), White
// Direction (-1, -1, 0) normalized
// 50 range, 10 power
spot.set_position(vec3(20.0f, 30.0f, 0.0f));
spot.set_light_colour(vec4(1.0f, 1.0f, 1.0f, 1.0f));
spot.set_direction(normalize(vec3(-1.0f, -1.0f, 0.0f)));
spot.set_range(50.0f);
spot.set_power(10.0f);
// Load in shaders
shadow_eff.add_shader("50_Spot_Light/spot.vert", GL_VERTEX_SHADER);
shadow_eff.add_shader("50_Spot_Light/spot.frag", GL_FRAGMENT_SHADER);
// Build effect
shadow_eff.build();
// Set camera properties
cam.set_position(vec3(0.0f, 20.0f, -30.0f));
cam.set_target(vec3(0.0f, 0.0f, 0.0f));
cam.set_projection(quarter_pi<float>(), renderer::get_screen_aspect(), 0.1f, 1000.0f);
return true;
}
示例5: load_content
bool load_content() {
// Create cube data - eight corners
// Positions
vector<vec3> positions{
// *********************************
// Add the position data for cube corners here (8 total)
// *********************************
};
// Colours
vector<vec4> colours;
for (auto i = 0; i < positions.size(); ++i) {
colours.push_back(vec4((i + 1) % 2, 0.0f, i % 2, 1.0f));
}
// Create the index buffer
vector<GLuint> indices{
// *********************************
// Add index information here - 3 per triangle, 6 per face, 12 triangles
// Front
// Back
// Right
// Left
// Top
// Bottom
// *********************************
};
// Add to the geometry
geom.add_buffer(positions, BUFFER_INDEXES::POSITION_BUFFER);
geom.add_buffer(colours, BUFFER_INDEXES::COLOUR_BUFFER);
// ****************************
// Add index buffer to geometry
// ****************************
geom.add_index_buffer(indices);
// Load in shaders
eff.add_shader("shaders/basic.vert", GL_VERTEX_SHADER);
eff.add_shader("shaders/basic.frag", GL_FRAGMENT_SHADER);
// Build effect
eff.build();
// Set camera properties
cam.set_position(vec3(10.0f, 10.0f, 10.0f));
cam.set_target(vec3(0.0f, 0.0f, 0.0f));
auto aspect = static_cast<float>(renderer::get_screen_width()) / static_cast<float>(renderer::get_screen_height());
cam.set_projection(quarter_pi<float>(), aspect, 2.414f, 1000.0f);
return true;
}
示例6: load_content
bool load_content() {
// Construct geometry object
geometry geom;
// Create triangle data
// Positions
vector<vec3> positions{vec3(0.0f, 1.0f, 0.0f), vec3(-1.0f, -1.0f, 0.0f), vec3(1.0f, -1.0f, 0.0f)};
// *********************************
// Define texture coordinates for triangle
vector<vec2> UVs{ vec2(0.0f, 1.0f),
vec2(-1.0f, -1.0f),
vec2(1.0f, -1.0f) };
// *********************************
// Add to the geometry
geom.add_buffer(positions, BUFFER_INDEXES::POSITION_BUFFER);
// *********************************
// Add texture coordinate buffer to geometry
geom.add_buffer(positions, BUFFER_INDEXES::TEXTURE_COORDS_0);
// *********************************
// Create mesh object
m = mesh(geom);
m2 = mesh(geom);
m2.get_transform().translate(vec3(5.0f, 1.0f, 1.0f));
// Load in texture shaders here
eff.add_shader("27_Texturing_Shader/simple_texture.vert", GL_VERTEX_SHADER);
eff.add_shader("27_Texturing_Shader/simple_texture.frag", GL_FRAGMENT_SHADER);
// *********************************
// Build effect
eff.build();
// Load texture "textures/sign.jpg"
tex = texture("textures/sign.jpg");
tex2 = texture("textures/stonygrass.jpg");
// *********************************
// Set camera properties
cam.set_position(vec3(10.0f, 10.0f, 10.0f));
cam.set_target(vec3(0.0f, 0.0f, 0.0f));
auto aspect = static_cast<float>(renderer::get_screen_width()) / static_cast<float>(renderer::get_screen_height());
cam.set_projection(quarter_pi<float>(), aspect, 2.414f, 1000.0f);
return true;
}
示例7: load_content
bool load_content() {
// Create plane mesh
meshes["plane"] = mesh(geometry_builder::create_plane());
// Create scene
meshes["box"] = mesh(geometry_builder::create_box());
meshes["tetra"] = mesh(geometry_builder::create_tetrahedron());
meshes["pyramid"] = mesh(geometry_builder::create_pyramid());
meshes["disk"] = mesh(geometry_builder::create_disk(20));
meshes["cylinder"] = mesh(geometry_builder::create_cylinder(20, 20));
meshes["sphere"] = mesh(geometry_builder::create_sphere(20, 20));
meshes["torus"] = mesh(geometry_builder::create_torus(20, 20, 1.0f, 5.0f));
// Transform objects
meshes["box"].get_transform().scale = vec3(5.0f, 5.0f, 5.0f);
meshes["box"].get_transform().translate(vec3(-10.0f, 2.5f, -30.0f));
meshes["tetra"].get_transform().scale = vec3(4.0f, 4.0f, 4.0f);
meshes["tetra"].get_transform().translate(vec3(-30.0f, 10.0f, -10.0f));
meshes["pyramid"].get_transform().scale = vec3(5.0f, 5.0f, 5.0f);
meshes["pyramid"].get_transform().translate(vec3(-10.0f, 7.5f, -30.0f));
meshes["disk"].get_transform().scale = vec3(3.0f, 1.0f, 3.0f);
meshes["disk"].get_transform().translate(vec3(-10.0f, 11.5f, -30.0f));
meshes["disk"].get_transform().rotate(vec3(half_pi<float>(), 0.0f, 0.0f));
meshes["cylinder"].get_transform().scale = vec3(5.0f, 5.0f, 5.0f);
meshes["cylinder"].get_transform().translate(vec3(-25.0f, 2.5f, -25.0f));
meshes["sphere"].get_transform().scale = vec3(2.5f, 2.5f, 2.5f);
meshes["sphere"].get_transform().translate(vec3(-25.0f, 10.0f, -25.0f));
meshes["torus"].get_transform().translate(vec3(-25.0f, 10.0f, -25.0f));
meshes["torus"].get_transform().rotate(vec3(half_pi<float>(), 0.0f, 0.0f));
// Load texture
tex = texture("textures/checker.png");
// Load in shaders
eff.add_shader("27_Texturing_Shader/simple_texture.vert", GL_VERTEX_SHADER);
eff.add_shader("27_Texturing_Shader/simple_texture.frag", GL_FRAGMENT_SHADER);
// Build effect
eff.build();
// Set camera properties
cam.set_position(vec3(50.0f, 10.0f, 50.0f));
cam.set_target(vec3(0.0f, 0.0f, 0.0f));
cam.set_projection(quarter_pi<float>(), renderer::get_screen_aspect(), 0.1f, 1000.0f);
return true;
}
示例8: load_content
bool load_content() {
// Construct geometry object
geometry geom;
// Required buffers
vector<vec3> positions;
vector<vec3> normals;
// Define the initial tetrahedron - 4 points
vector<vec3> v{vec3(0.0f, 0.0f, 1.0f), vec3(0.0f, 0.942809f, -0.333333f), vec3(-0.816497f, -0.471405f, -0.333333f),
vec3(0.816497f, -0.471405f, 0.333333f)};
// Divide the triangles
divide_triangle({v[0], v[1], v[2]}, subdivisions, positions);
divide_triangle({v[3], v[2], v[1]}, subdivisions, positions);
divide_triangle({v[0], v[3], v[1]}, subdivisions, positions);
divide_triangle({v[0], v[2], v[3]}, subdivisions, positions);
// Copy positions (already normalized) into normals buffer
normals.insert(normals.end(), positions.begin(), positions.end());
// Add buffers to geometry
geom.add_buffer(positions, BUFFER_INDEXES::POSITION_BUFFER);
geom.add_buffer(normals, BUFFER_INDEXES::NORMAL_BUFFER);
// Create mesh object
m = mesh(geom);
// Load in simple cell shader
eff.add_shader("34_Simple_Cell_Shading/simple_cell.vert", GL_VERTEX_SHADER);
eff.add_shader("34_Simple_Cell_Shading/simple_cell.frag", GL_FRAGMENT_SHADER);
// Build effect
eff.build();
// Colour scale from red to black
vector<vec4> colour_data{vec4(0.12f, 0.0f, 0.0f, 1.0f), vec4(0.25f, 0.0f, 0.0f, 1.0f), vec4(0.5f, 0.0f, 0.0f, 1.0f),
vec4(1.0f, 0.0f, 0.0f, 1.0f)};
// Create 1D 4x1 texture from colour_data
tex = texture(colour_data, 4, 1, false, false);
// Set camera properties
cam.set_position(vec3(10.0f, 10.0f, 10.0f));
cam.set_target(vec3(0.0f, 0.0f, 0.0f));
auto aspect = static_cast<float>(renderer::get_screen_width()) / static_cast<float>(renderer::get_screen_height());
cam.set_projection(quarter_pi<float>(), aspect, 2.414f, 1000.0f);
return true;
}
示例9: load_content
bool load_content() {
// Set to points type
geom.set_type(GL_POINTS);
// Create sierpinski gasket
create_sierpinski(geom);
// Load in shaders
eff.add_shader("shaders/basic.vert", GL_VERTEX_SHADER);
eff.add_shader("shaders/basic.frag", GL_FRAGMENT_SHADER);
// Build effect
eff.build();
// Set camera properties
cam.set_position(vec3(2.0f, 2.0f, 2.0f));
cam.set_target(vec3(0.0f, 0.0f, 0.0f));
auto aspect = static_cast<float>(renderer::get_screen_width()) / static_cast<float>(renderer::get_screen_height());
cam.set_projection(quarter_pi<float>(), aspect, 2.414f, 1000.0f);
return true;
}
示例10: load_content
bool load_content() {
// *********************************
// Load in model, models/teapot.obj
mesh m(geometry("models/teapot.obj"));
// Load in texture, textures/checker.png
tex = texture("textures/checker.png");
// *********************************
// Load in shaders
eff.add_shader("27_Texturing_Shader/simple_texture.vert", GL_VERTEX_SHADER);
eff.add_shader("27_Texturing_Shader/simple_texture.frag", GL_FRAGMENT_SHADER);
// Build effect
eff.build();
// Set camera properties
cam.set_position(vec3(200.0f, 200.0f, 200.0f));
cam.set_target(vec3(0.0f, 0.0f, 0.0f));
cam.set_projection(quarter_pi<float>(), renderer::get_screen_aspect(), 0.1f, 1000.0f);
return true;
}
示例11: load_content
//.........这里部分代码省略.........
// Set lighting values
// *********************************
// Point 0, Position (-25, 5, -15)
// Red, 20 range
points[0].set_position(vec3(-25, 5, -15));
points[0].set_light_colour(vec4(1, 0, 0, 1));
points[0].set_range(20);
// Point 1, Position (-25, 5, -35)
// Red,20 range
points[1].set_position(vec3(-25, 5, -35));
points[1].set_light_colour(vec4(1, 0, 0, 1));
points[1].set_range(20);
// Point 2,Position (-10, 5, -15)
// Red,20 range
points[2].set_position(vec3(-10, 5, -15));
points[2].set_light_colour(vec4(1, 0, 0, 1));
points[2].set_range(20);
// Point 3,Position (-10, 5, -35)
// Red,20 range
points[3].set_position(vec3(-10, 5, -35));
points[3].set_light_colour(vec4(1, 0, 0, 1));
points[3].set_range(20);
// Spot 0, Position (-25, 10, -15)
// Green, Direction (1, -1, -1) normalized
// 20 range,0.5 power
spots[0].set_position(vec3(-25, 10, -15));
spots[0].set_light_colour(vec4(0, 1, 0, 1));
spots[0].set_range(20);
spots[0].set_power(0.5f);
spots[0].set_direction(normalize(vec3(1, -1, -1)));
// Spot 1,Position (-25, 10, -35)
// Green,Direction (1, -1, 1) normalized
// 20 range,0.5 power
spots[1].set_position(vec3(-25, 10, -15));
spots[1].set_light_colour(vec4(0, 1, 0, 1));
spots[1].set_range(20);
spots[1].set_power(0.5f);
spots[1].set_direction(normalize(vec3(1, -1, 1)));
// Spot 2,Position (-10, 10, -15)
// Green,Direction (-1, -1, -1) normalized
// 20 range,0.5 power
spots[2].set_position(vec3(-25, 10, -15));
spots[2].set_light_colour(vec4(0, 1, 0, 1));
spots[2].set_range(20);
spots[2].set_power(0.5f);
spots[2].set_direction(normalize(vec3(-1, -1, -1)));
// Spot 3,Position (-10, 10, -35)
// Green,Direction (-1, -1, 1) normalized
// 20 range,0.5 power
spots[3].set_position(vec3(-25, 10, -15));
spots[3].set_light_colour(vec4(0, 1, 0, 1));
spots[3].set_range(20);
spots[3].set_power(0.5f);
spots[3].set_direction(normalize(vec3(-1, -1, -1)));
// Spot 4,Position (-17.5, 15, -25)
// Blue,Direction (0, -1, 0)
// 30 range,1.0 power
spots[4].set_position(vec3(-25, 10, -15));
spots[4].set_light_colour(vec4(0, 0, 1, 1));
spots[4].set_range(20);
spots[4].set_power(1.0f);
spots[4].set_direction(normalize(vec3(0, -1, 0)));
// Set lighting values
light.set_ambient_intensity(vec4(0.3f, 0.3f, 0.3f, 1.0f));
light.set_direction(vec3(1.0f, 1.0f, -1.0f));
light.set_light_colour(vec4(1.0f, 1.0f, 1.0f, 1.0f));
// Load in shaders
eff.add_shader("52_Multifile_Shaders/shader.vert", GL_VERTEX_SHADER);
// Name of fragment shaders required
vector<string> frag_shaders{ "52_Multifile_Shaders/shader.frag", "shaders/part_direction.frag",
"shaders/part_point.frag", "shaders/part_spot.frag" };
eff.add_shader(frag_shaders, GL_FRAGMENT_SHADER);
// Build effect
eff.build();
// Set camera properties
cam.set_position(vec3(50.0f, 10.0f, 50.0f));
cam.set_target(vec3(0.0f, 0.0f, 0.0f));
cam.set_projection(quarter_pi<float>(), renderer::get_screen_aspect(), 0.1f, 1000.0f);
return true;
}
示例12: load_content
bool load_content() {
// *********************************
// Create frame buffer - use screen width and height
// Create screen quad
// *********************************
// Create plane mesh
meshes["plane"] = mesh(geometry_builder::create_plane());
// Create scene
meshes["box"] = mesh(geometry_builder::create_box());
meshes["tetra"] = mesh(geometry_builder::create_tetrahedron());
meshes["pyramid"] = mesh(geometry_builder::create_pyramid());
meshes["disk"] = mesh(geometry_builder::create_disk(20));
meshes["cylinder"] = mesh(geometry_builder::create_cylinder(20, 20));
meshes["sphere"] = mesh(geometry_builder::create_sphere(20, 20));
meshes["torus"] = mesh(geometry_builder::create_torus(20, 20, 1.0f, 5.0f));
// Transform objects
meshes["box"].get_transform().scale = vec3(5.0f, 5.0f, 5.0f);
meshes["box"].get_transform().translate(vec3(-10.0f, 2.5f, -30.0f));
meshes["tetra"].get_transform().scale = vec3(4.0f, 4.0f, 4.0f);
meshes["tetra"].get_transform().translate(vec3(-30.0f, 10.0f, -10.0f));
meshes["pyramid"].get_transform().scale = vec3(5.0f, 5.0f, 5.0f);
meshes["pyramid"].get_transform().translate(vec3(-10.0f, 7.5f, -30.0f));
meshes["disk"].get_transform().scale = vec3(3.0f, 1.0f, 3.0f);
meshes["disk"].get_transform().translate(vec3(-10.0f, 11.5f, -30.0f));
meshes["disk"].get_transform().rotate(vec3(half_pi<float>(), 0.0f, 0.0f));
meshes["cylinder"].get_transform().scale = vec3(5.0f, 5.0f, 5.0f);
meshes["cylinder"].get_transform().translate(vec3(-25.0f, 2.5f, -25.0f));
meshes["sphere"].get_transform().scale = vec3(2.5f, 2.5f, 2.5f);
meshes["sphere"].get_transform().translate(vec3(-25.0f, 10.0f, -25.0f));
meshes["torus"].get_transform().translate(vec3(-25.0f, 10.0f, -25.0f));
meshes["torus"].get_transform().rotate(vec3(half_pi<float>(), 0.0f, 0.0f));
// Set materials
// Red box
meshes["box"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f));
meshes["box"].get_material().set_diffuse(vec4(1.0f, 0.0f, 0.0f, 1.0f));
meshes["box"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f));
meshes["box"].get_material().set_shininess(25.0f);
// Green tetra
meshes["tetra"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f));
meshes["tetra"].get_material().set_diffuse(vec4(0.0f, 1.0f, 0.0f, 1.0f));
meshes["tetra"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f));
meshes["tetra"].get_material().set_shininess(25.0f);
// Blue pyramid
meshes["pyramid"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f));
meshes["pyramid"].get_material().set_diffuse(vec4(0.0f, 0.0f, 1.0f, 1.0f));
meshes["pyramid"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f));
meshes["pyramid"].get_material().set_shininess(25.0f);
// Yellow disk
meshes["disk"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f));
meshes["disk"].get_material().set_diffuse(vec4(1.0f, 1.0f, 0.0f, 1.0f));
meshes["disk"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f));
meshes["disk"].get_material().set_shininess(25.0f);
// Magenta cylinder
meshes["cylinder"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f));
meshes["cylinder"].get_material().set_diffuse(vec4(1.0f, 0.0f, 1.0f, 1.0f));
meshes["cylinder"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f));
meshes["cylinder"].get_material().set_shininess(25.0f);
// Cyan sphere
meshes["sphere"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f));
meshes["sphere"].get_material().set_diffuse(vec4(0.0f, 1.0f, 1.0f, 1.0f));
meshes["sphere"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f));
meshes["sphere"].get_material().set_shininess(25.0f);
// White torus
meshes["torus"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f));
meshes["torus"].get_material().set_diffuse(vec4(1.0f, 1.0f, 1.0f, 1.0f));
meshes["torus"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f));
meshes["torus"].get_material().set_shininess(25.0f);
// Load texture
tex = texture("textures/checked.gif");
// Set lighting values
light.set_ambient_intensity(vec4(0.3f, 0.3f, 0.3f, 1.0f));
light.set_light_colour(vec4(1.0f, 1.0f, 1.0f, 1.0f));
light.set_direction(vec3(1.0f, 1.0f, -1.0f));
// Load in shaders
eff.add_shader("48_Phong_Shading/phong.vert", GL_VERTEX_SHADER);
eff.add_shader("48_Phong_Shading/phong.frag", GL_FRAGMENT_SHADER);
tex_eff.add_shader("27_Texturing_Shader/simple_texture.vert", GL_VERTEX_SHADER);
tex_eff.add_shader("72_Blur/blur.frag", GL_FRAGMENT_SHADER);
// Build effects
eff.build();
tex_eff.build();
// Set camera properties
cam.set_position(vec3(50.0f, 10.0f, 50.0f));
cam.set_target(vec3(0.0f, 0.0f, 0.0f));
auto aspect = static_cast<float>(renderer::get_screen_width()) / static_cast<float>(renderer::get_screen_height());
//.........这里部分代码省略.........
示例13: load_content
bool load_content() {
// *********************************
// Create shadow map- use screen size
// Create plane mesh
// Create "teapot" mesh by loading in models/teapot.obj
// Need to rotate the teapot on x by negative pi/2
// Scale the teapot - (0.1, 0.1, 0.1)
// *********************************
// Load texture
tex = texture("textures/checker.png");
// ***********************
// Set materials
// - all emissive is black
// - all specular is white
// - all shininess is 25
// ***********************
// White plane
meshes["plane"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f));
meshes["plane"].get_material().set_diffuse(vec4(1.0f, 1.0f, 1.0f, 1.0f));
meshes["plane"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f));
meshes["plane"].get_material().set_shininess(25.0f);
// Red teapot
meshes["teapot"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f));
meshes["teapot"].get_material().set_diffuse(vec4(1.0f, 1.0f, 1.0f, 1.0f));
meshes["teapot"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f));
meshes["teapot"].get_material().set_shininess(25.0f);
// *******************
// Set spot properties
// *******************
// Pos (20, 30, 0), White
// Direction (-1, -1, 0) normalized
// 50 range, 10 power
spot.set_position(vec3(30.0f, 20.0f, 0.0f));
spot.set_light_colour(vec4(1.0f, 1.0f, 1.0f, 1.0f));
spot.set_direction(normalize(vec3(-1.0f, -1.0f, 0.0f)));
spot.set_range(500.0f);
spot.set_power(10.0f);
// Load in shaders
main_eff.add_shader("54_Shadowing/shadow.vert", GL_VERTEX_SHADER);
vector<string> frag_shaders{"54_Shadowing/shadow.frag", "shaders/part_spot.frag", "shaders/part_shadow.frag"};
main_eff.add_shader(frag_shaders, GL_FRAGMENT_SHADER);
shadow_eff.add_shader("50_Spot_Light/spot.vert", GL_VERTEX_SHADER);
shadow_eff.add_shader("50_Spot_Light/spot.frag", GL_FRAGMENT_SHADER);
// Build effects
main_eff.build();
shadow_eff.build();
// Set camera properties
cam.set_position(vec3(0.0f, 50.0f, -75.0f));
cam.set_target(vec3(0.0f, 0.0f, 0.0f));
cam.set_projection(quarter_pi<float>(), renderer::get_screen_aspect(), 0.1f, 1000.0f);
return true;
}
示例14: load_content
bool load_content() {
// Create plane mesh
meshes["plane"] = mesh(geometry_builder::create_plane());
// Create scene
meshes["box"] = mesh(geometry_builder::create_box());
meshes["tetra"] = mesh(geometry_builder::create_tetrahedron());
meshes["pyramid"] = mesh(geometry_builder::create_pyramid());
meshes["disk"] = mesh(geometry_builder::create_disk(20));
meshes["cylinder"] = mesh(geometry_builder::create_cylinder(20, 20));
meshes["sphere"] = mesh(geometry_builder::create_sphere(20, 20));
meshes["torus"] = mesh(geometry_builder::create_torus(20, 20, 1.0f, 5.0f));
// Transform objects
meshes["box"].get_transform().scale = vec3(5.0f, 5.0f, 5.0f);
meshes["box"].get_transform().translate(vec3(-10.0f, 2.5f, -30.0f));
meshes["tetra"].get_transform().scale = vec3(4.0f, 4.0f, 4.0f);
meshes["tetra"].get_transform().translate(vec3(-30.0f, 10.0f, -10.0f));
meshes["pyramid"].get_transform().scale = vec3(5.0f, 5.0f, 5.0f);
meshes["pyramid"].get_transform().translate(vec3(-10.0f, 7.5f, -30.0f));
meshes["disk"].get_transform().scale = vec3(3.0f, 1.0f, 3.0f);
meshes["disk"].get_transform().translate(vec3(-10.0f, 11.5f, -30.0f));
meshes["disk"].get_transform().rotate(vec3(half_pi<float>(), 0.0f, 0.0f));
meshes["cylinder"].get_transform().scale = vec3(5.0f, 5.0f, 5.0f);
meshes["cylinder"].get_transform().translate(vec3(-25.0f, 2.5f, -25.0f));
meshes["sphere"].get_transform().scale = vec3(2.5f, 2.5f, 2.5f);
meshes["sphere"].get_transform().translate(vec3(-25.0f, 10.0f, -25.0f));
meshes["torus"].get_transform().translate(vec3(-25.0f, 10.0f, -25.0f));
meshes["torus"].get_transform().rotate(vec3(half_pi<float>(), 0.0f, 0.0f));
// *********************************
// Set materials
// - all emissive is black
// - all specular is white
// - all shininess is 25
// Red box
meshes["box"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f));
meshes["box"].get_material().set_diffuse(vec4(1.0f, 0.0f, 0.0f, 1.0f));
meshes["box"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f));
meshes["box"].get_material().set_shininess(25.0f);
// Green tetra
meshes["tetra"].get_material().set_emissive(vec4(1.0f, 1.0f, 0.0f, 1.0f));
meshes["tetra"].get_material().set_diffuse(vec4(0.0f, 1.0f, 0.0f, 1.0f));
meshes["tetra"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f));
meshes["tetra"].get_material().set_shininess(25.0f);
// Blue pyramid
meshes["pyramid"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f));
meshes["pyramid"].get_material().set_diffuse(vec4(0.0f, 0.0f, 1.0f, 1.0f));
meshes["pyramid"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f));
meshes["pyramid"].get_material().set_shininess(25.0f);
// Yellow disk
meshes["disk"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f));
meshes["disk"].get_material().set_diffuse(vec4(1.0f, 1.0f, 0.0f, 1.0f));
meshes["disk"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f));
meshes["disk"].get_material().set_shininess(25.0f);
// Magenta cylinder
meshes["cylinder"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f));
meshes["cylinder"].get_material().set_diffuse(vec4(1.0f, 0.0f, 1.0f, 1.0f));
meshes["cylinder"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f));
meshes["cylinder"].get_material().set_shininess(25.0f);
// Cyan sphere
meshes["sphere"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f));
meshes["sphere"].get_material().set_diffuse(vec4(0.0f, 1.0f, 1.0f, 1.0f));
meshes["sphere"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f));
meshes["sphere"].get_material().set_shininess(25.0f);
// White torus
meshes["torus"].get_material().set_emissive(vec4(0.0f, 0.0f, 0.0f, 1.0f));
meshes["torus"].get_material().set_diffuse(vec4(1.0f, 1.0f, 1.0f, 1.0f));
meshes["torus"].get_material().set_specular(vec4(1.0f, 1.0f, 1.0f, 1.0f));
meshes["torus"].get_material().set_shininess(25.0f);
// *********************************
// Load texture
tex = texture("textures/checker.png");
// *********************************
// Set lighting values, Position (-25, 10, -10)
light.set_position(vec3(-25, 10, -10));
// Light colour white
light.set_light_colour(vec4(1.0f, 1.0f, 1.0f, 1.0f));
// Set range to 20
light.set_range(20);
// Load in shaders
eff.add_shader("49_Point_Light/point.vert", GL_VERTEX_SHADER);
eff.add_shader("49_Point_Light/point.frag", GL_FRAGMENT_SHADER);
// Build effect
eff.build();
// *********************************
// Set camera properties
cam.set_position(vec3(50.0f, 10.0f, 50.0f));
cam.set_target(vec3(0.0f, 0.0f, 0.0f));
cam.set_projection(quarter_pi<float>(), renderer::get_screen_aspect(), 0.1f, 1000.0f);
return true;
}