cocos2d::TransitionFade * utilities::XMLToTransitionFade(const tinyxml2::XMLElement *xmlElement, cocos2d::Scene * transiteTo)
{
	auto durationElement = xmlElement->FirstChildElement("Duration");
	assert(durationElement && "utilities::XMLToTransitionFade() the xml element has no duration element.");
	auto durationSec = durationElement->FloatAttribute("Value");

	auto color3BElement = xmlElement->FirstChildElement("Color3B");
	if (!color3BElement)
		return cocos2d::TransitionFade::create(durationSec, transiteTo);

	return cocos2d::TransitionFade::create(durationSec, transiteTo, XMLToColor3B(color3BElement));
}
Exemplo n.º 2
0
void ResourceLoader::loadGameSettings(const char * xmlPath)
{
	//Load the xml file.
	tinyxml2::XMLDocument xmlDoc;
	xmlDoc.LoadFile(xmlPath);
	const auto rootElement = xmlDoc.RootElement();
	assert(rootElement && "ResourceLoader::loadGameSettings() failed to load xml file.");

	//Load the design resolution.
	auto resolutionElement = rootElement->FirstChildElement("DesignResolution");
	pimpl->m_DesignResolution.width = resolutionElement->FloatAttribute("Width");
	pimpl->m_DesignResolution.height = resolutionElement->FloatAttribute("Height");

	//Load the grid size.
	auto gridSizeElement = rootElement->FirstChildElement("GridSize");
	pimpl->m_DesignGridSize.width = gridSizeElement->FloatAttribute("Width");
	pimpl->m_DesignGridSize.height = gridSizeElement->FloatAttribute("Height");

	//Load other settings.
	pimpl->m_FramesPerSecond = rootElement->FirstChildElement("FramesPerSecond")->FloatAttribute("Value");
	pimpl->m_ResourceListPath = rootElement->FirstChildElement("ResourceListPath")->Attribute("Value");
	pimpl->m_InitialScenePath = rootElement->FirstChildElement("InitialScenePath")->Attribute("Value");
}
Exemplo n.º 3
0
void Viewer::initScene() {
    auto pScene = m_Settings.m_pRoot->FirstChildElement("Scene");
    if(!pScene) {
        std::clog << "No Scene  tag found in viewer settings file" << std::endl;
        return;
    }

    m_SceneDocumentFilePath = m_Path + pScene->Attribute("path");

    if(tinyxml2::XML_NO_ERROR != m_SceneDocument.LoadFile(m_SceneDocumentFilePath.c_str())) {
        throw std::runtime_error("Unable to load scene file");
    }
    pScene = m_SceneDocument.RootElement();
    if(!pScene) {
        throw std::runtime_error("No root element in scene's XML file");
    }
    auto path = m_SceneDocumentFilePath.directory();

    m_pScene = makeUnique<Scene>(pScene, path, m_ShaderManager);

    m_ZNearFar.y = 2.f * length(m_pScene->getGeometry().getBBox().size());
    getAttribute(*pScene, "far", m_ZNearFar.y);
    float nearFarRatio = pScene->FloatAttribute("nearFarRatio");
    m_ZNearFar.x = m_ZNearFar.y * nearFarRatio;

    auto pCamera = m_Settings.m_pCacheRoot->FirstChildElement("ProjectiveCamera");
    Vec3f eye(0), point(0, 0, -1), up(0, 1, 0);
    float fovY = radians(45.f);
    if(pCamera) {
        loadPerspectiveCamera(*pCamera, eye, point, up, fovY);
    }

    m_Camera = ProjectiveCamera(lookAt(eye, point, up), fovY,
                                m_Settings.m_FramebufferSize.x,
                                m_Settings.m_FramebufferSize.y,
                                m_ZNearFar.x, m_ZNearFar.y);
}
Exemplo n.º 4
0
void GPUOctree::dumpIndirection(const char *filename)
{
	m_idr = new short[INDIRECTIONPOOLSIZE*4];
	m_dt = new float[DATAPOOLSIZE*4];

	setIndirection(m_root);
	
	half *idr_r = new half[INDIRECTIONPOOLSIZE];
	half *idr_g = new half[INDIRECTIONPOOLSIZE];
	half *idr_b = new half[INDIRECTIONPOOLSIZE];
	half *idr_a = new half[INDIRECTIONPOOLSIZE];
	
	for(long i=0; i<INDIRECTIONPOOLSIZE; i++) {
		idr_r[i] = (half)m_idr[i*4];
		idr_g[i] = (half)m_idr[i*4+1];
		idr_b[i] = (half)m_idr[i*4+2];
		idr_a[i] = (half)m_idr[i*4+3];
	}
	
// save indirection	
	Header idrheader (INDIRECTIONPOOLWIDTH, INDIRECTIONPOOLWIDTH); 
	idrheader.insert ("root_size", FloatAttribute (m_rootSize));
	idrheader.insert ("root_center", V3fAttribute (Imath::V3f(m_rootCenter.x, m_rootCenter.y, m_rootCenter.z))); 

		idrheader.channels().insert ("R", Channel (HALF));
		idrheader.channels().insert ("G", Channel (HALF));                                   // 1 
        idrheader.channels().insert ("B", Channel (HALF));
		idrheader.channels().insert ("A", Channel (HALF));                   // 2  
    
	std::string idrname = filename;
	idrname += ".idr";
        OutputFile idrfile (idrname.c_str(), idrheader);                               // 4 
        FrameBuffer idrframeBuffer;
		 idrframeBuffer.insert ("R",                                // name   // 6 
                            Slice (HALF,                        // type   // 7 
                                   (char *) idr_r,            // base   // 8 
                                   sizeof (*idr_r) * 1,       // xStride// 9 
                                   sizeof (*idr_r) * INDIRECTIONPOOLWIDTH));
        idrframeBuffer.insert ("G",                                // name   // 6 
                            Slice (HALF,                        // type   // 7 
                                   (char *) idr_g,            // base   // 8 
                                   sizeof (*idr_g) * 1,       // xStride// 9 
                                   sizeof (*idr_g) * INDIRECTIONPOOLWIDTH));
		 idrframeBuffer.insert ("B",                                // name   // 6 
                            Slice (HALF,                        // type   // 7 
                                   (char *) idr_b,            // base   // 8 
                                   sizeof (*idr_b) * 1,       // xStride// 9 
                                   sizeof (*idr_b) * INDIRECTIONPOOLWIDTH));
		 idrframeBuffer.insert ("A",                                // name   // 6 
                            Slice (HALF,                        // type   // 7 
                                   (char *) idr_a,            // base   // 8 
                                   sizeof (*idr_a) * 1,       // xStride// 9 
                                   sizeof (*idr_a) * INDIRECTIONPOOLWIDTH));
       
        idrfile.setFrameBuffer (idrframeBuffer);                                // 16 
        idrfile.writePixels (INDIRECTIONPOOLWIDTH); 
        
        delete[] idr_r;
	delete[] idr_g;
	delete[] idr_b;
	delete[] idr_a;
// save data

	half *dt_r = new half[DATAPOOLSIZE];
	half *dt_g = new half[DATAPOOLSIZE];
	half *dt_b = new half[DATAPOOLSIZE];
	half *dt_a = new half[DATAPOOLSIZE];
	
	for(long i=0; i<DATAPOOLSIZE; i++) {
		dt_r[i] = (half)m_dt[i*4];
		dt_g[i] = (half)m_dt[i*4+1];
		dt_b[i] = (half)m_dt[i*4+2];
		dt_a[i] = (half)m_dt[i*4+3];
	}
	
	Header dtheader (DATAPOOLWIDTH, DATAPOOLWIDTH); 
		dtheader.channels().insert ("R", Channel (HALF));
		dtheader.channels().insert ("G", Channel (HALF));                                   // 1 
        dtheader.channels().insert ("B", Channel (HALF));
		dtheader.channels().insert ("A", Channel (HALF));                   // 2  
    
	std::string dtname = filename;
	dtname += ".exr";
        OutputFile dtfile (dtname.c_str(), dtheader);                               // 4 
        FrameBuffer dtframeBuffer;
		 dtframeBuffer.insert ("R",                                // name   // 6 
                            Slice (HALF,                        // type   // 7 
                                   (char *) dt_r,            // base   // 8 
                                   sizeof (*dt_r) * 1,       // xStride// 9 
                                   sizeof (*dt_r) * DATAPOOLWIDTH));
        dtframeBuffer.insert ("G",                                // name   // 6 
                            Slice (HALF,                        // type   // 7 
                                   (char *) dt_g,            // base   // 8 
                                   sizeof (*dt_g) * 1,       // xStride// 9 
                                   sizeof (*dt_g) * DATAPOOLWIDTH));
		 dtframeBuffer.insert ("B",                                // name   // 6 
                            Slice (HALF,                        // type   // 7 
                                   (char *) dt_b,            // base   // 8 
                                   sizeof (*dt_b) * 1,       // xStride// 9 
                                   sizeof (*dt_b) * DATAPOOLWIDTH));
		 dtframeBuffer.insert ("A",                                // name   // 6 
                            Slice (HALF,                        // type   // 7 
                                   (char *) dt_a,            // base   // 8 
                                   sizeof (*dt_a) * 1,       // xStride// 9 
                                   sizeof (*dt_a) * DATAPOOLWIDTH));
       
        dtfile.setFrameBuffer (dtframeBuffer);                                // 16 
        dtfile.writePixels (DATAPOOLWIDTH); 
		
	delete[] dt_r;
	delete[] dt_g;
	delete[] dt_b;
	delete[] dt_a;
}
Exemplo n.º 5
0
XMLObject* RBFFactory::create(tinyxml2::XMLElement *xml){
	auto rbf = new RBFSystem();
	
	int i = 10;
	
	for(auto c = xml->FirstChildElement() ; c != 0 ; c = c->NextSiblingElement() ) {
		auto n = c->Value();
		if(std::strcmp(n,"TrendFunction") == 0){
			rbf->_trend._c[0] = c->FloatAttribute("c0");
			rbf->_trend._c[1] = c->FloatAttribute("c1");
			rbf->_trend._c[2] = c->FloatAttribute("c2");
			rbf->_trend._c[3] = c->FloatAttribute("c3");
		}else if(std::strcmp(n,"minPosition") == 0){
			rbf->_min.x = c->FloatAttribute("x");
			rbf->_min.y = c->FloatAttribute("y");
			rbf->_min.z = c->FloatAttribute("z");
		}else if(std::strcmp(n,"maxPosition") == 0){
			rbf->_max.x = c->FloatAttribute("x");
			rbf->_max.y = c->FloatAttribute("y");
			rbf->_max.z = c->FloatAttribute("z");
		}else if(std::strcmp(n,"centers") == 0){
			float x,y,z,w,a;
			for(auto k = c->FirstChildElement() ; k != c->LastChildElement() ; k = k->NextSiblingElement() ) {
				auto type = k->Value();

				x = k->FloatAttribute("x");
				y = k->FloatAttribute("y");
				z = k->FloatAttribute("z");
				w = k->FloatAttribute("weight");

				if(std::strcmp(type,"ThinPlateSplineRBF") == 0){
					rbf->_kernels.push_back(new ThinPlateSplineRBF(x,y,z,w));
				}
				else if(std::strcmp(type,"Biharmonic") == 0){
					rbf->_kernels.push_back(new Biharmonic(x,y,z,w));
				}
				else if(std::strcmp(type,"Triharmonic") == 0){
					rbf->_kernels.push_back(new Triharmonic(x,y,z,w));
				}
				else if(std::strcmp(type,"GausianRBF") == 0){
					a = k->FloatAttribute("a");
					rbf->_kernels.push_back(new GausianRBF(x,y,z,w,a));
				}
				else if(std::strcmp(type,"MultiQuadricRBF") == 0){
					a = k->FloatAttribute("a");
					rbf->_kernels.push_back(new MultiQuadricRBF(x,y,z,w,a));
				}
				else if(std::strcmp(type,"InverseMultiQuadricRBF") == 0){
					a = k->FloatAttribute("a");
					rbf->_kernels.push_back(new InverseMultiQuadricRBF(x,y,z,w,a));
				}
			}
		}else{
			std::cerr << "Unkown xml child attribute for RBF System:" << n << std::endl;
		}
	}
	
	

	return rbf;

}