Esempio n. 1
0
Vector4f ColorGradient::GetColorWOErrorChecking(float f) const
{
    f = Mathf::Clamp(f, OrderedNodes[0].Position, OrderedNodes[OrderedNodes.size() - 1].Position);

	//Edge cases. Choose a random node side if the given value sits right on a Node.
	if (f == OrderedNodes[0].Position)
	{
		return ((rand() % 9) < 5) ? OrderedNodes[0].LeftColor : OrderedNodes[0].RightColor;
	}
	if (f == OrderedNodes[OrderedNodes.size() - 1].Position)
	{
		return ((rand() % 9) < 5) ? OrderedNodes[OrderedNodes.size() - 1].LeftColor : OrderedNodes[OrderedNodes.size() - 1].RightColor;
	}

	//Count to the first node above the given position.
	int index;
	for (index = OrderedNodes.size() - 1; OrderedNodes[index].Position > f && index > 0; --index) { }

	//Lerp between the two color values.

	Vector4f leftCol = OrderedNodes[index].RightColor;
	Vector4f rightCol = OrderedNodes[index + 1].LeftColor;
	Interval posInt(OrderedNodes[index].Position, OrderedNodes[index + 1].Position, 0.001f, true, true);
	Vector4b needReversed((unsigned char)(leftCol.x > rightCol.x), leftCol.y > rightCol.y, leftCol.z > rightCol.z, leftCol.w > rightCol.w);
	float ref = posInt.Reflect(f);
	float rx = (needReversed.x) ? ref : f,
		  ry = (needReversed.y) ? ref : f,
		  rz = (needReversed.z) ? ref : f,
		  rw = (needReversed.w) ? ref : f;
	Interval ix(leftCol.x, rightCol.x, 0.001f, true, true),
			 iy(leftCol.y, rightCol.y, 0.001f, true, true),
			 iz(leftCol.z, rightCol.z, 0.001f, true, true),
			 iw(leftCol.w, rightCol.w, 0.001f, true, true);
	rx = posInt.MapValue(ix, rx);
	ry = posInt.MapValue(iy, ry);
	rz = posInt.MapValue(iz, rz);
	rw = posInt.MapValue(iw, rw);
	Vector4f ret(rx, ry, rz, rw);

	return ret;
}
Esempio n. 2
0
void myCallback() {
  puts("C: myCallback");
  iz();
}