本文整理汇总了C++中Object::AddData方法的典型用法代码示例。如果您正苦于以下问题:C++ Object::AddData方法的具体用法?C++ Object::AddData怎么用?C++ Object::AddData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Object
的用法示例。
在下文中一共展示了Object::AddData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BuildScene
bool basic_builder::BuildScene( string file_name, Camera &camera, Scene &scene ) const
{
int line_num = 0;
char input_line[512];
Plugin *dat = NULL; // A container for arbitrary data.
Object *obj = NULL; // The current object, which was the last object created.
Shader *shd = NULL; // The current shader.
Aggregate *agg = NULL; // Current aggregate object, to which all objects are now added.
Envmap *env = NULL; // Current environment map.
Material *mat = NULL; // Current material pointer.
Material material; // Current material.
scene.object = NULL;
scene.envmap = NULL;
scene.rasterize = NULL;
// Attempt to open the input file.
file_name += ".sdf";
std::ifstream fin;
fin.open( file_name.c_str() );
if( fin.fail() )
{
cerr << "Error: Could not open file " << file_name << endl;
return false; // Report failure.
}
cout << "Reading " << file_name << "... ";
cout.flush();
// Set some defaults.
material.diffuse = White;
material.emission = Black;
material.specular = White;
material.ambient = Black;
material.reflectivity = Black;
material.translucency = Black;
material.ref_index = 0.0;
material.Phong_exp = 0.0;
camera.x_res = default_image_width;
camera.y_res = default_image_height;
camera.x_win = Interval( -1.0, 1.0 );
camera.y_win = Interval( -1.0, 1.0 );
// Process lines until the end of file is reached.
// Print a warning for all lines that are unrecognizable.
while( fin.getline( input_line, 512 ) )
{
line_num++;
if( Skip( input_line ) ) continue;
// Ask each registered object if it recognizes the line. If it does, it will
// create a new instance of the object and return it as the function value.
Plugin *plg = Instance_of_Plugin( input_line );
if( plg != NULL )
{
switch( plg->PluginType() )
{
case data_plugin:
if( obj == NULL ) cerr << "Error: data ignored. Line " << line_num << endl;
else obj->AddData( obj );
break;
case shader_plugin:
shd = (Shader*)plg;
break;
case aggregate_plugin:
obj = (Object*)plg;
obj->shader = shd;
obj->envmap = env;
obj->material = Copy( mat, material );
obj->parent = agg;
if( Emitter( material ) )
{
cerr << "Error: An aggregate object cannot be an emitter. Line "
<< line_num << ": "
<< input_line << endl;
return false;
}
if( agg != NULL ) // If there is alrealy an agg obj, this one is a child.
{
// agg->AddChild( obj );
// Do not add aggregates as children until they are complete.
agg->material = Copy( mat, material );
}
else if( scene.object == NULL ) scene.object = obj;
agg = (Aggregate *)obj;
break;
case primitive_plugin:
obj = (Object*)plg;
obj->shader = shd;
obj->envmap = env;
obj->material = Copy( mat, material );
obj->parent = agg;
//.........这里部分代码省略.........