int main(int argc, char* argv[]) { osg::ref_ptr<osg::Group> root(new osg::Group); osg::ref_ptr<osg::Geode> sphere(build_sphere()); root->addChild(sphere.get()); osg::ref_ptr<osg::Light> light(new osg::Light); light->setLightNum(1); light->setPosition(osg::Vec4(0., 0., 0., 1.)); osg::ref_ptr<osg::LightSource> light_source(new osg::LightSource); light_source->setLight(light.get()); osg::ref_ptr<osg::MatrixTransform> transform(new osg::MatrixTransform); transform->addChild(light_source.get()); osg::Matrix matrix; matrix.makeTranslate(osg::Vec3(10., 0., 0.)); transform->setMatrix(matrix); root->addChild(transform.get()); boost::shared_ptr<shade::GLSLWrapper> state(new shade::osg::Wrapper(sphere->getOrCreateStateSet())); boost::shared_ptr<shade::Program> shader_program(setup_shading(state)); shader_program->compile(); state->make_current(); shader_program->upload(); run_viewer(root.get()); }
void MapNode::deSerialize(u8 *source, u8 version) { if(!ser_ver_supported(version)) throw VersionMismatchException("ERROR: MapNode format not supported"); if(version == 0) { param0 = source[0]; } else if(version == 1) { param0 = source[0]; // This version doesn't support saved lighting if(light_propagates() || light_source() > 0) param1 = 0; else param1 = source[1]; } else if(version <= 9) { param0 = source[0]; param1 = source[1]; } else { param0 = source[0]; param1 = source[1]; param2 = source[2]; } // Convert special values from old version to new if(version <= 18) { // In these versions, CONTENT_IGNORE and CONTENT_AIR // are 255 and 254 if(param0 == 255) param0 = CONTENT_IGNORE; else if(param0 == 254) param0 = CONTENT_AIR; } // version 19 is f****d up with sometimes the old values and sometimes not if(version == 19) { if(param0 == 255) param0 = CONTENT_IGNORE; else if(param0 == 254) param0 = CONTENT_AIR; } // Translate to our known version *this = mapnode_translate_to_internal(*this, version); }
void MapNode::deSerialize(u8 *source, u8 version) { if(!ser_ver_supported(version)) throw VersionMismatchException("ERROR: MapNode format not supported"); if(version == 0) { d = source[0]; } else if(version == 1) { d = source[0]; // This version doesn't support saved lighting if(light_propagates() || light_source() > 0) param = 0; else param = source[1]; } else if(version <= 9) { d = source[0]; param = source[1]; } else { d = source[0]; param = source[1]; param2 = source[2]; // Convert from old version to new if(version <= 18) { // In these versions, CONTENT_IGNORE and CONTENT_AIR // are 255 and 254 if(d == 255) d = CONTENT_IGNORE; else if(d == 254) d = CONTENT_AIR; } } }
int main(int argc, char* argv[]) { osg::ref_ptr<osg::Group> root(new osg::Group); osg::ref_ptr<osg::Geode> sphere(build_sphere()); root->addChild(sphere.get()); osg::ref_ptr<osg::Group> satellites_geometry(build_satellites()); osg::ref_ptr<osg::MatrixTransform> satellites(new osg::MatrixTransform); satellites->addChild(satellites_geometry.get()); satellites->setUpdateCallback(new RotateCallback(osg::Vec3(0., 1., 0.), 0.001)); root->addChild(satellites.get()); osg::ref_ptr<osg::Geode> plane(build_quad()); osg::ref_ptr<osg::MatrixTransform> plane_transform(new osg::MatrixTransform); plane_transform->addChild(plane.get()); osg::Matrix plane_transform_matrix; plane_transform_matrix.makeTranslate(0., -2., 0.); plane_transform->setMatrix(plane_transform_matrix); root->addChild(plane_transform.get()); osg::ref_ptr<osg::Light> light(new osg::Light); light->setLightNum(1); light->setPosition(osg::Vec4(0., 0., 0., 1.)); osg::ref_ptr<osg::LightSource> light_source(new osg::LightSource); light_source->setLight(light.get()); osg::ref_ptr<osg::MatrixTransform> transform(new osg::MatrixTransform); transform->addChild(light_source.get()); osg::Matrix matrix; matrix.makeTranslate(osg::Vec3(10., 0., 0.)); transform->setMatrix(matrix); root->addChild(transform.get()); osg::ref_ptr<osg::Texture2D> tex = new osg::Texture2D; int env_width = 1024; int env_height = 1024; tex->setTextureSize(env_width, env_height); tex->setInternalFormat(GL_RGBA); tex->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR); tex->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR); boost::shared_ptr<shade::osg::Texture> shade_tex(new shade::osg::Texture(tex.get())); osg::ref_ptr<osg::Camera> env_camera = new osg::Camera; env_camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); env_camera->setClearColor(osg::Vec4(0.5, 0.5, 0.5, 1.)); env_camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); env_camera->setViewport(0, 0, env_width, env_height); env_camera->setRenderOrder(osg::Camera::PRE_RENDER); env_camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT, osg::Camera::FRAME_BUFFER); env_camera->attach(osg::Camera::COLOR_BUFFER, tex, 0, 0, true); env_camera->addChild(sphere); env_camera->addChild(satellites); osg::ref_ptr<osg::StateSet> env_camera_state(env_camera->getOrCreateStateSet()); osg::FrontFace* cf = new osg::FrontFace(osg::FrontFace::CLOCKWISE); env_camera_state->setAttributeAndModes(cf); root->addChild(env_camera); setup_plane_shading(plane->getOrCreateStateSet(), shade_tex); osg::ref_ptr<osg::TextureCubeMap> osg_cube_tex = new osg::TextureCubeMap; int cube_map_size = 512; osg_cube_tex->setTextureSize(cube_map_size, cube_map_size); osg_cube_tex->setInternalFormat(GL_RGBA); struct { osg::Vec3 center; osg::Vec3 up; } cube_cameras[] = { {osg::Vec3(+1., 0., 0.), osg::Vec3(0., -1., 0.)}, {osg::Vec3(-1., 0., 0.), osg::Vec3(0., -1., 0.)}, {osg::Vec3(0., +1., 0.), osg::Vec3(0., 0., +1.)}, {osg::Vec3(0., -1., 0.), osg::Vec3(0., 0., +1.)}, {osg::Vec3(0., 0., +1.), osg::Vec3(0., -1., 0.)}, {osg::Vec3(0., 0., -1.), osg::Vec3(0., -1., 0.)}, }; for(int i = 0; i != 6; ++i) { osg::ref_ptr<osg::Camera> cm_camera = new osg::Camera; cm_camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); cm_camera->setClearColor(osg::Vec4(0.3, 0.3, 0.3, 1.)); cm_camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); cm_camera->setViewport(0, 0, cube_map_size, cube_map_size); cm_camera->setRenderOrder(osg::Camera::PRE_RENDER); cm_camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT, osg::Camera::FRAME_BUFFER); cm_camera->attach(osg::Camera::COLOR_BUFFER, osg_cube_tex, 0, i, true); cm_camera->setProjectionMatrixAsPerspective(90., 1., 0.1, 10.); cm_camera->setViewMatrixAsLookAt(osg::Vec3(0., 0., 0.), cube_cameras[i].center, cube_cameras[i].up); cm_camera->addChild(satellites); root->addChild(cm_camera); } boost::shared_ptr<shade::osg::Texture> cube_tex(new shade::osg::Texture(osg_cube_tex.get())); setup_sphere_shading(sphere->getOrCreateStateSet(), cube_tex); osg::ref_ptr<osgViewer::Viewer> viewer(build_viewer(root.get())); env_camera->setDataVariance(osg::Object::DYNAMIC); env_camera->setUpdateCallback(new MirrorCamera(viewer->getCamera(), plane_transform_matrix)); viewer->run(); }