示例#1
1
文件: model.cpp 项目: v-bayer/bcFIT
//generator pseudonahodnych cisiel exponencialneho rozlozenia so stredom v x
double Model::GeneratorExp(double x)
{
	std::mt19937 rng((int)std::time(0) * RandomGenerator());	//ak sa generator zavola v rovnakom strojovom case generuje rovnake hodnoty	
	std::exponential_distribution<double> distrib(1 / x);		//semienko je teda vynasobene nahodnym cislom z intervalu 0 - 100

	return distrib(rng);
}
示例#2
0
void Scenes::Menu::frame(float FrameTime)
{
#if 1
	// Check if a new motion should be loaded
	if (!KnownMotions.empty()) {
		if (!Motion || Motion->isFinished()) {
			// Set the model to its initial state
			Model->Reset();

			// Add a waiting time 
			if (Motion != nullptr)
				WaitTime = (float)RandomGenerator() / (float)RandomGenerator.max() * 15.0f;

			// Initialize a new random VMD motion
			Motion.reset(new VMD::Motion);
			std::shuffle(KnownMotions.begin(), KnownMotions.end(), RandomGenerator);

			Motion->loadFromFile(KnownMotions.front());

			Motion->attachModel(Model);
		}
		else if (!Paused) {
			if (WaitTime <= 0.0f)
				Motion->advanceFrame(FrameTime * 30.0f);
			else 
				WaitTime -= FrameTime;
		}
	}
#endif

	Model->Update(FrameTime);
}
示例#3
0
Room::Room()
{
	Boss endBoss = Boss(10);
	RandomGenerator rg = RandomGenerator();
	size = RoomSize[rg.getRandom(0, 2)];
	content = RoomContent[rg.getRandom(0, 3)];
	description = RoomDescription[rg.getRandom(0, 3)];
	appearance = RoomAppearance[rg.getRandom(0, 3)];
	lighting = RoomLighting[rg.getRandom(0,3)];
	connected[RoomDirection::NORTH] =  nullptr;
	connected[RoomDirection::EAST] = nullptr;
	connected[RoomDirection::SOUTH] = nullptr;
	connected[RoomDirection::WEST] = nullptr;
	visited = false;
	visiting = false;
	exit = false;
	equipment.push_back(Equipment());
}
示例#4
0
文件: model.cpp 项目: v-bayer/bcFIT
//funkcia, ktora spracuje prechody s pravdepodobnostou
void Model::SpracujPravdepod()
{
	std::vector<Prechod *> p;	//vektor, do ktoreho si ulozim vsetky prechody s rovnakym ID
	int priorID;
	int a = 100;
	int b;
	int pravdepodobnost;
	for (unsigned int i = 0; i < prechody.size(); i++)
	{
		if (prechody[i]->GetTyp() == PRAVDEPO && prechody[i]->JeVykonatelny())
		{
			pravdepodobnost = RandomGenerator();	//vygenerujem cislo s rovnomernou pravdepodobnostou
			priorID = prechody[i]->GetIdPrav();		//ziskam id pravdepodobnosti prechodu
			p.push_back(prechody[i]);	
			while (i < prechody.size() && prechody[i]->JeVykonatelny())	//najdem si vsetky prechody s tymto pravdep_ID
			{
				if (prechody[i]->GetIdPrav() == priorID)	//a ulozim do vektoru
					p.push_back(prechody[i]);
				i++;
			}
			for (unsigned int j = 0; j < p.size(); j++)	//prejdem cez vsetky prechody v ramci jedneho ID
			{
				b = a - p.back()->GetPravdepod();	//vypocitam si prvy interval, do ktoreho sa musi nahodne cislo trafit
				if (pravdepodobnost <= a && pravdepodobnost > b)	//aby sa vykonal tento prechod
				{
					p.back()->SpracujZnacky();
					p.clear();
				}
				else	//inak si nastavym novy interval
				{
					a = b;
					p.pop_back();	//a vymazem prechod z vektoru
				}
			}
			i = 0;	//po spracovani prechodov s rovnakym ID, sa prejdu vsetky od zaciatku
			SpracujPrioritne();		//spracuju sa prioritne, lebo sa zmenil stav systemu
		}
	}
}
示例#5
0
文件: starfield.cpp 项目: Kazade/KGLT
void starfield(smlt::TexturePtr texture_ptr, uint32_t width, uint32_t height) {
    smlt::Texture& texture = *texture_ptr;

    texture.resize(width, height);
    texture.set_format(TEXTURE_FORMAT_RGBA8888);

    const float GLOBAL_DENSITY = 0.01f;
    const float MAX_SIZE = 2.0;
    const float MAX_BRIGHTNESS = 255;

    Simplex::ptr noise = Simplex::create();
    auto rgen = RandomGenerator();

    for(uint32_t y = 0; y < height; ++y) {
        for(uint32_t x = 0; x < width; ++x) {
            float this_density = (noise->noise(x, y) + 1.0) / 2.0;

            if(rgen.float_in_range(0, 1) < this_density * GLOBAL_DENSITY) {
                float weight = rgen.float_in_range(0, 1) * this_density;
                float size = std::max(1.0f, weight * MAX_SIZE);
                float brightness = weight * MAX_BRIGHTNESS;

                smlt::Colour colour = smlt::Colour::WHITE;
                float col_rand = rgen.float_in_range(0, 1);
                if(col_rand < 0.05) {
                    colour = smlt::Colour::ORANGE;
                } else if(col_rand < 0.07) {
                    colour = smlt::Colour::YELLOW;
                } else if(col_rand < 0.1) {
                    colour = smlt::Colour::BLUE;
                }
                draw_circle(texture_ptr, x, y, size, brightness, colour);
            }
        }
    }
}
示例#6
0
文件: TipsConvert.cpp 项目: uvbs/XDLL
string TipsConvert::UrlConvert(const string& url)
{
	string urlNew = url;
	int nPos;
	string sKey;
	// 检查有没有[area]
	sKey = "[area]";
	do 
	{
		nPos = urlNew.find(sKey);
		if (nPos == -1) break;
		string sReplace = boost::lexical_cast<string>(TipsUtil::GetAreaCode());
		urlNew.replace(nPos, sKey.size(), sReplace);
	} while(true);
	// 检查有没有[seconds1970]
	sKey = "[seconds1970]";
	do
	{
		nPos = urlNew.find(sKey);
		if (nPos == -1) break;
		string sReplace = boost::lexical_cast<string>(TipsUtil::GetSeconds1970());
		urlNew.replace(nPos, sKey.size(), sReplace);
	} while(true);

	// 检查有没有[number=min~max]
	sKey = "[number=";
	do 
	{
		nPos = urlNew.find(sKey);
		if (nPos == -1) break;

		int nEndPos = urlNew.find("]", nPos);
		if (nEndPos == -1)
		{	// 配置有问题,直接替换为空
			urlNew.replace(nPos, sKey.size(), "");
			continue;
		}
		int nLength = nEndPos-nPos+1;
		string sRandom = urlNew.substr(nPos+sKey.size(), nEndPos-nPos-sKey.size());

		vector<string> items;
		strings::split( std::back_inserter(items), sRandom, string("~") );
		if (items.size() < 2)
		{
			urlNew.replace(nPos, nLength, "0");
			continue;
		}
		try {
			int nMin = boost::lexical_cast<int>(items[0]);
			int nMax = boost::lexical_cast<int>(items[1]);
			if (nMin > nMax)
			{	// 如果 nMin 比 nMax 大则交换
				int temp = nMin;
				nMin = nMax;
				nMax = temp;
			}
			int nValue = nMin + RandomGenerator().NextIn(nMax-nMin);
			urlNew.replace(nPos, nLength, boost::lexical_cast<string>(nValue));
		}
		catch (...)
		{
			urlNew.replace(nPos, nLength, "0");
			continue;
		}

	} while (true);

	// 检查有没有[infiled=aaa|bbb|ccc|ddd|eee]
	sKey = "[infield=";
	do 
	{
		nPos = urlNew.find(sKey);
		if (nPos == -1) break;
		
		int nEndPos = urlNew.find("]", nPos);
		if (nEndPos == -1)
		{	// 配置有问题,直接替换为空
			urlNew.replace(nPos, sKey.size(), "");
			continue;
		}
		int nLength = nEndPos-nPos+1;
		string sRandom = urlNew.substr(nPos+sKey.size(), nEndPos-nPos-sKey.size());
		
		vector<string> items;
		strings::split( std::back_inserter(items), sRandom, string("|") );
		if (items.size() == 2)
		{
			urlNew.replace(nPos, nLength, "");
			continue;
		}
		
		int nIndex = RandomGenerator().NextIn(items.size());
		urlNew.replace(nPos, nLength, items[nIndex]);
	} while (true);

	return urlNew;
}
示例#7
0
文件: dubstep.cpp 项目: ronj/invent
 //On most platforms, you probably want to use std::random_device("/dev/urandom")()
 random_selector(RandomGenerator g = RandomGenerator(std::random_device()()))
   : gen(g) {}
示例#8
0
GameMap::GameMap() : GameMap(RandomGenerator())
{
}
示例#9
0
bool Scenes::Menu::initialize()
{
	Shader.reset(new PMX::PMXShader);
	assert(Shader);
	if (!Shader->InitializeBuffers(Renderer->GetDevice(), nullptr))
		return false;
	Shader->SetLightCount(1);
	Shader->SetLights(DirectX::XMVectorSplatOne(), DirectX::XMVectorSplatOne(), DirectX::XMVectorSplatOne(), DirectX::XMVectorSet(-1.0f, -1.0f, 1.0f, 0.0f), DirectX::XMVectorZero(), 0);

	auto &Viewport = Renderer->getViewport();
	Camera.reset(new Renderer::Camera(DirectX::XM_PIDIV4, (float)Viewport.Width / (float)Viewport.Height, Renderer::SCREEN_NEAR, Renderer::SCREEN_DEPTH));
	assert(Camera);
	Camera->SetPosition(0, 10.0f, 0.0f);

	Frustum.reset(new Renderer::ViewFrustum);
	assert(Frustum);

	// Create a list of motions to be used as idle animations
	fs::directory_iterator EndIterator;
	fs::path MotionPath(L"./Data/Motions/Idle/");
	for (fs::directory_iterator Entry(MotionPath); Entry != EndIterator; Entry++) {
		if (fs::is_regular_file(Entry->status()) && Entry->path().extension().wstring().compare(L".vmd") == 0) {
			KnownMotions.emplace_back(Entry->path().generic_wstring());
		}
	}

	DirectX::XMMATRIX View, Projection;
	Camera->setFocalDistance(-35.0f);
	Camera->update(0.0f);
	Camera->getViewMatrix(View);
	Camera->getProjectionMatrix(Projection);

	Frustum->Construct(Renderer::SCREEN_DEPTH, Projection, View);

	Shader->SetEyePosition(Camera->GetPosition());
	Shader->SetMatrices(DirectX::XMMatrixIdentity(), View, Projection);

	// Initializes the model
	// Pause the physics environment, to prevent resource race
	Physics->pause();
	// Select a model to be displayed
#if 1
	auto ModelList = ModelHandler->getKnownModels();
	do {
		size_t Index = RandomGenerator() % ModelList.size();
		for (auto &ModelPath : ModelList) {
			if (Index-- == 0) {
				Model = ModelHandler->loadModel(ModelPath.first, Physics);
				ModelList.erase(ModelPath.first);
				break;
			}
		}
	} while (!Model);
#else
	Model = ModelHandler->loadModel(L"Tda式改変WIMミク ver.2.9", Physics);
	Model->SetDebugFlags(PMX::Model::DebugFlags::RenderBones);
#endif
	Model->SetShader(Shader);

	if (!Model->Initialize(Renderer, Physics))
		return false;
	Physics->resume();

	return true;
}