コード例 #1
0
ファイル: Worley2D.cpp プロジェクト: Overdrivr/NazaraEngine
float NzWorley2D::Get()
{
    xc = x * m_scale;
    yc = y * m_scale;

    x0 = fastfloor(xc);
    y0 = fastfloor(yc);

    fractx = xc - static_cast<float>(x0);
    fracty = yc - static_cast<float>(y0);

    featurePoints.clear();
    //Dummy points : FIX ME : Remove them
    featurePoints[100.f] = NzVector2f(0.f,0.f);
    featurePoints[101.f] = NzVector2f(0.f,0.f);
    featurePoints[102.f] = NzVector2f(0.f,0.f);
    featurePoints[103.f] = NzVector2f(0.f,0.f);

    SquareTest(x0,y0,xc,yc);

    it = featurePoints.begin();
    std::advance(it,m_function);

    if(fractx < it->first)
        SquareTest(x0 - 1,y0,xc,yc);

    it = featurePoints.begin();
    std::advance(it,m_function);

    if(1.f - fractx < it->first)
        SquareTest(x0 + 1,y0,xc,yc);

    it = featurePoints.begin();
    std::advance(it,m_function);

    if(fracty < it->first)
        SquareTest(x0,y0 - 1,xc,yc);

    it = featurePoints.begin();
    std::advance(it,m_function);

    if(1.f - fracty < it->first)
        SquareTest(x0,y0 + 1,xc,yc);

    it = featurePoints.begin();
    std::advance(it,m_function);

    if(fractx < it->first &&
       fracty < it->first)
       SquareTest(x0 - 1, y0 - 1,xc,yc);

    it = featurePoints.begin();
    std::advance(it,m_function);

    if(1.f - fractx < it->first &&
       fracty < it->first)
       SquareTest(x0 + 1, y0 - 1,xc,yc);

    it = featurePoints.begin();
    std::advance(it,m_function);

    if(fractx < it->first &&
       1.f - fracty < it->first)
       SquareTest(x0 - 1, y0 + 1,xc,yc);

    it = featurePoints.begin();
    std::advance(it,m_function);

    if(1.f - fractx < it->first &&
       1.f - fracty < it->first)
       SquareTest(x0 + 1, y0 + 1,xc,yc);

    it = featurePoints.begin();
    std::advance(it,m_function);

    //Remove dummy points
    featurePoints.erase(--(featurePoints.end()));
    featurePoints.erase(--(featurePoints.end()));
    featurePoints.erase(--(featurePoints.end()));
    featurePoints.erase(--(featurePoints.end()));

    return it->first * scale[m_function];
}
コード例 #2
0
ファイル: Worley.cpp プロジェクト: Ilearn32/NazaraEngine
	float Worley::Get(float x, float y, float scale) const
	{
		std::map<float, Vector2f> featurePoints;

		float xc, yc;
		int x0, y0;
		float fractx, fracty;

		xc = x * scale;
		yc = y * scale;

		x0 = fastfloor(xc);
		y0 = fastfloor(yc);

		fractx = xc - static_cast<float>(x0);
		fracty = yc - static_cast<float>(y0);

		featurePoints.clear();

		SquareTest(x0,y0,xc,yc,featurePoints);

		std::size_t functionIndex = static_cast<std::size_t>(m_function);

		auto it = featurePoints.begin();
		std::advance(it, functionIndex);

		if(fractx < it->first)
			SquareTest(x0 - 1,y0,xc,yc,featurePoints);

		it = featurePoints.begin();
		std::advance(it, functionIndex);

		if(1.f - fractx < it->first)
			SquareTest(x0 + 1,y0,xc,yc,featurePoints);

		it = featurePoints.begin();
		std::advance(it, functionIndex);

		if(fracty < it->first)
			SquareTest(x0,y0 - 1,xc,yc,featurePoints);

		it = featurePoints.begin();
		std::advance(it, functionIndex);

		if (1.f - fracty < it->first)
			SquareTest(x0,y0 + 1,xc,yc,featurePoints);

		it = featurePoints.begin();
		std::advance(it, functionIndex);

		if (fractx < it->first && fracty < it->first)
			SquareTest(x0 - 1, y0 - 1,xc,yc,featurePoints);

		it = featurePoints.begin();
		std::advance(it, functionIndex);

		if (1.f - fractx < it->first && fracty < it->first)
		   SquareTest(x0 + 1, y0 - 1,xc,yc,featurePoints);

		it = featurePoints.begin();
		std::advance(it, functionIndex);

		if (fractx < it->first && 1.f - fracty < it->first)
		   SquareTest(x0 - 1, y0 + 1,xc,yc,featurePoints);

		it = featurePoints.begin();
		std::advance(it, functionIndex);

		if(1.f - fractx < it->first && 1.f - fracty < it->first)
		   SquareTest(x0 + 1, y0 + 1,xc,yc,featurePoints);

		it = featurePoints.begin();
		std::advance(it, functionIndex);

		return it->first * m_functionScales[functionIndex];
	}