void SDFloader::read(std::string file) { // delete eventually existing scene scene_.materials.clear(); scene_.shapes.clear(); scene_.cameras.clear(); scene_.lights.clear(); std::ifstream f; std::string s; f.open(file, std::ios::in); while (!f.eof()) { // Solange noch Daten vorliegen getline(f, s); // Lese eine Zeile std::istringstream iss(s); std::string sub; iss >> sub; if(sub == "define"){ iss >> sub; if(sub == "material") add_material(iss); else if(sub == "shape") add_shape(iss); else if(sub == "camera") add_camera(iss); else if(sub == "light") add_light(iss); } else if(sub == "transform")
/** When this method is called, the writer must write the camera. @return The writer should return true, if writing succeeded, false otherwise.*/ bool DocumentImporter::writeCamera( const COLLADAFW::Camera* camera ) { if(mImportStage!=General) return true; Camera *cam = NULL; std::string cam_id, cam_name; cam_id = camera->getOriginalId(); cam_name = camera->getName(); if (cam_name.size()) cam = (Camera*)add_camera((char*)cam_name.c_str()); else cam = (Camera*)add_camera((char*)cam_id.c_str()); if (!cam) { fprintf(stderr, "Cannot create camera. \n"); return true; } cam->clipsta = camera->getNearClippingPlane().getValue(); cam->clipend = camera->getFarClippingPlane().getValue(); COLLADAFW::Camera::CameraType type = camera->getCameraType(); switch(type) { case COLLADAFW::Camera::ORTHOGRAPHIC: { cam->type = CAM_ORTHO; } break; case COLLADAFW::Camera::PERSPECTIVE: { cam->type = CAM_PERSP; } break; case COLLADAFW::Camera::UNDEFINED_CAMERATYPE: { fprintf(stderr, "Current camera type is not supported. \n"); cam->type = CAM_PERSP; } break; } switch(camera->getDescriptionType()) { case COLLADAFW::Camera::ASPECTRATIO_AND_Y: { switch(cam->type) { case CAM_ORTHO: { double ymag = camera->getYMag().getValue(); double aspect = camera->getAspectRatio().getValue(); double xmag = aspect*ymag; cam->ortho_scale = (float)xmag; } break; case CAM_PERSP: default: { double yfov = camera->getYFov().getValue(); double aspect = camera->getAspectRatio().getValue(); double xfov = aspect*yfov; // xfov is in degrees, cam->lens is in millimiters cam->lens = angle_to_lens(DEG2RADF(xfov)); } break; } } break; /* XXX correct way to do following four is probably to get also render size and determine proper settings from that somehow */ case COLLADAFW::Camera::ASPECTRATIO_AND_X: case COLLADAFW::Camera::SINGLE_X: case COLLADAFW::Camera::X_AND_Y: { switch(cam->type) { case CAM_ORTHO: cam->ortho_scale = (float)camera->getXMag().getValue(); break; case CAM_PERSP: default: { double x = camera->getXFov().getValue(); // x is in degrees, cam->lens is in millimiters cam->lens = angle_to_lens(DEG2RADF(x)); } break; } } break; case COLLADAFW::Camera::SINGLE_Y: { switch(cam->type) { case CAM_ORTHO: cam->ortho_scale = (float)camera->getYMag().getValue(); break; case CAM_PERSP: default: { double yfov = camera->getYFov().getValue(); // yfov is in degrees, cam->lens is in millimiters cam->lens = angle_to_lens(DEG2RADF(yfov)); } break; } } break; case COLLADAFW::Camera::UNDEFINED: // read nothing, use blender defaults. break; } this->uid_camera_map[camera->getUniqueId()] = cam; this->FW_object_map[camera->getUniqueId()] = camera; // XXX import camera options return true; }
Camera *rna_Main_cameras_new(Main *UNUSED(bmain), const char *name) { ID *id= add_camera(name); id_us_min(id); return (Camera *)id; }
void game_scene::start (void) { get_physics_world()->setGravity( btVector3(0.0F, 0.0F, 0.0F) ); // std::string shader_file_name = "ver.sdr f*g.sdr"; const unsigned int game_shader = 1; shader_load( shader_file_name, game_shader ); // set_ambient_color( glm::vec4(0.218F, 0.218F, 0.218F, 1.0F) ); // _light_base* light_one = new _light_base(); light_one->set_diffuse_color( glm::vec3(1.0F, 1.0F, 1.0F) ); /* light_one->set_diffuse_color( glm::vec3(0.36F, 0.05F, 0.67F) ); */ light_one->set_specular_color( glm::vec3(0.9F, 0.9F, 0.9F) ); light_one->set_position_in_world( glm::vec3( 0.0F, 0.0F, 0.0F) ); /* light_one->rotate( 8.0F, vec3( 0.0F, 1.0F, 0.0F ) ); */ light_one->translate( glm::vec3(400.0F, -100.0F, 400.0F) ); add_light( light_one ); _light_base* light_two = new _light_base(); light_two->set_diffuse_color( glm::vec3(0.F, 0.F, 1.F) ); light_two->set_specular_color( glm::vec3(0.9F, 0.9F, 0.9F) ); light_two->set_position_in_world( glm::vec3( 0.0F, 0.0F, 0.0F) ); /* light_two->rotate( 8.0F, vec3( 0.0F, 1.0F, 0.0F ) ); */ light_two->translate( glm::vec3(-400.0F, 200.0F, 400.0F) ); add_light( light_two ); /* std::cout<<"dot: "<<glm::dot( glm::vec3(0.0F, 0.0F, -4.0), glm::vec3(0.0F, 0.0F, -1.0) )<<std::endl; */ // camera_main* camera_m = new camera_main(); camera_m->set_ID( 11 ); camera_m->activate( true ); camera_m->perspective( 45.0F, 1366.0F / 768.0F, 1.0F, 1000.0F ); camera_m->set_position_in_world( glm::vec3( 0.0F, 0.0F, 0.0F ) ); camera_m->rotate( 0.0F, glm::vec3( 0.0F, 1.0F, 0.0F ) ); camera_m->_camera_base::translate( glm::vec3( 0.0F, 3.F, 8.0F ) ); camera_m->_camera_base::rotate( -10.0F, glm::vec3( 1.0F, 0.F, 0.0F ) ); add_camera( camera_m ); // btCollisionDispatcher* dispatcher = static_cast<btCollisionDispatcher*>( this->get_physics_world()->getDispatcher() ); btGImpactCollisionAlgorithm::registerAlgorithm( dispatcher ); // { ship* ship_a = new ship(); ship_a->activate( true ); /* ship_a->generate_model(); */ /* ship_a->load_model_data_from_assets( asset->get_model_data( "lowpolyspaceship.dae" ) ); */ ship_a->set_position_in_world( glm::vec3( 0.0F, 0.0F, 0.0F ) ); ship_a->translate( glm::vec3( .0F, 0.0F, -10.5F ) ); ship_a->set_material_diffuse_color( glm::vec4( 0.0, 0.6, 0.6, 1.0 ) ); ship_a->set_material_specular_color( glm::vec4( 0.0, 0.6, 0.6, 1.0 ) ); /* //////////////////// */ /* ship_a->init_rigid_body( 1.0F, btVector3( 0.6F, 0.6F, 0.6F ), tmpshape ); */ ship_a->get_rigidbody()->setDamping( 0.05F, 0.01F ); ship_a->get_rigidbody()->setAngularFactor( btVector3(0.4F, 0.4F, 0.4F) ); ship_a->get_rigidbody()->setLinearFactor( btVector3(0.4F, 0.4F, 0.4F) ); add_object( ship_a, game_shader ); } { stone_a_l* stone_a_l_a = new stone_a_l(); /* stone_a_l_a->generate_model(); */ /* stone_a_l_a->load_model_data_from_assets( asset->get_model_data( "lowpolyspacestone_a_l.dae" ) ); */ stone_a_l_a->set_position_in_world( glm::vec3( 0.0F, 0.0F, 0.0F ) ); stone_a_l_a->translate( glm::vec3( .0F, 0.0F, -5.0F ) ); stone_a_l_a->set_material_diffuse_color( glm::vec4( 0.0, 0.6, 0.6, 1.0 ) ); stone_a_l_a->set_material_specular_color( glm::vec4( 0.0, 0.6, 0.6, 1.0 ) ); /* //////////////////// */ /* stone_a_l_a->init_rigid_body( 1.0F, btVector3( 0.6F, 0.6F, 0.6F ), tmpshape ); */ stone_a_l_a->get_rigidbody()->setDamping( 0.05F, 0.01F ); stone_a_l_a->get_rigidbody()->setAngularFactor( btVector3(0.4F, 0.4F, 0.4F) ); stone_a_l_a->get_rigidbody()->setLinearFactor( btVector3(0.4F, 0.4F, 0.4F) ); add_object( stone_a_l_a, game_shader ); } { circle* circle_a = new circle(); circle_a->catch_contrtoller(); circle_a->catch_camera( camera_m->get_ID() ); circle_a->set_position_in_world( glm::vec3( 0.0F, 0.0F, 0.0F ) ); circle_a->translate( glm::vec3( .0F, 0.0F, 20.5F ) ); circle_a->set_material_diffuse_color( glm::vec4( 0.6, 0.6, 0.6, 1.0 ) ); circle_a->set_material_specular_color( glm::vec4( 0.6, 0.6, 0.6, 1.0 ) ); add_object( circle_a, game_shader ); } }