Пример #1
0
const RectangleF* FieldController::FindClosestRectangles(RectangleF* pRectangle, Chromosome* pChromosome, bool bDirection)
{
	std::vector<const RectangleF*> pModels = FindIntersectedRectangles(pRectangle, pChromosome, bDirection);

	const RectangleF* pResultModel = NULL;

	Vector2F projectionAxis;
	if (!bDirection)
		projectionAxis = Vector2F(0, 1);
	else
		projectionAxis = Vector2F(1, 0);

	Vector2F min, max, modelMin, modelMax;
	float minLength = 12345678.f;

	GetProjection(pRectangle, projectionAxis, modelMin, modelMax);

	for (int i = 0, i_end = pModels.size(); i < i_end; ++i)
	{
		GetProjection(pModels[i], projectionAxis, min, max);
		// we are interested in one side models only 
		if (min > modelMin)
		{
			Vector2F lengthVec = (modelMax - min);
			float tempLength = lengthVec.X() * lengthVec.X() + lengthVec.Y() * lengthVec.Y();
			if (tempLength < minLength)
			{
				pResultModel = pModels[i];
				minLength = tempLength;
			}
		}
	}

	return pResultModel;
}
Пример #2
0
//----------------------------------------------------------------------------
void Player::LookAt(const Vector2F& rLookAt)
{
	mLookAt = rLookAt;
	Application* pApp = Application::GetApplication();

	const Float width = pApp->GetWidthF() * 0.5F;
	Float deadZoneX = width * mLookUpDeadZone.X();
	Float xB = width - deadZoneX;
	if (rLookAt.X() > deadZoneX)
	{
		mYawIncrement -= mRotateSpeed * (rLookAt.X() - deadZoneX) / xB;
	}
	else if (rLookAt.X() < -deadZoneX)
	{
		mYawIncrement -= mRotateSpeed * (rLookAt.X() + deadZoneX) / xB;
	}

	const Float height = pApp->GetHeightF() * 0.5F;
	Float deadZoneY = height * mLookUpDeadZone.Y();
	Float yB = height - deadZoneY;
	if (rLookAt.Y() > deadZoneY)
	{
		mPitchIncrement -= mRotateSpeed * (rLookAt.Y() - deadZoneY) / yB;
	}
	else if (rLookAt.Y() < -deadZoneY)
	{
		mPitchIncrement -= mRotateSpeed * (rLookAt.Y() + deadZoneY) / yB;
	}
}
Пример #3
0
//----------------------------------------------------------------------------
void Camera::GetPickRay(const Vector2F& rPosition, Vector3F& rRayOrigin,
	Vector3F& rRayDirection)
{
	WIRE_ASSERT(rPosition.X() >= -1.0F && rPosition.X() <= 1.0F);
	WIRE_ASSERT(rPosition.Y() >= -1.0F && rPosition.Y() <= 1.0F);
	Matrix4F projectionMatrix = GetProjectionMatrix();
	Vector3F v(rPosition.X() / projectionMatrix(0, 0),
		rPosition.Y() / projectionMatrix(1, 1), 1);

	rRayDirection = GetViewMatrixInverse34().Times3(v);
	rRayOrigin = GetViewMatrixInverse34().GetColumn(3);
}
Пример #4
0
void FieldController::GetProjection(const RectangleF* pRect, const Vector2F& dir, Vector2F& min, Vector2F& max)
{
	Vector2F	projectionAxis(-dir.Y(), dir.X());
	float		sqrlen = projectionAxis.X() * projectionAxis.X() + projectionAxis.Y() * projectionAxis.Y();


	// projection rectangle points to projAxis
	float dp = pRect->GetTopLeft().X() * projectionAxis.X() + pRect->GetTopLeft().Y() * projectionAxis.Y();
	float tempValue = dp / sqrlen;

	min.X() = tempValue * projectionAxis.X();
	min.Y() = tempValue * projectionAxis.Y();

	dp = pRect->GetBottomRight().X() * projectionAxis.X() + pRect->GetBottomRight().Y() * projectionAxis.Y();
	tempValue = dp / sqrlen;

	max.X() = tempValue * projectionAxis.X();
	max.Y() = tempValue * projectionAxis.Y();

}
Пример #5
0
//----------------------------------------------------------------------------
Texture2D* Sample5::CreateTexture()
{
	if (mspTexture)
	{
		return mspTexture;
	}

	// define the properties of the image to be used as a texture
	const UInt width = 256;
	const UInt height = 256;
	const Image2D::FormatMode format = Image2D::FM_RGB888;
	const UInt bpp = Image2D::GetBytesPerPixel(format);
	ColorRGB* const pColorDst = WIRE_NEW ColorRGB[width*height];

	// create points with random x,y position and color
	TArray<Cell> cells;
	Random random;
	for (UInt i = 0; i < 10; i++)
	{
		Cell cell;
		cell.point.X() = random.GetFloat() * width;
		cell.point.Y() = random.GetFloat() * height;
		cell.color.R() = random.GetFloat();
		cell.color.G() = random.GetFloat();
		cell.color.B() = random.GetFloat();

		Float max = 0.0F;
		max = max < cell.color.R() ? cell.color.R() : max;
		max = max < cell.color.G() ? cell.color.G() : max;
		max = max < cell.color.B() ? cell.color.B() : max;
		max = 1.0F / max;
		cell.color *= max;
		cells.Append(cell);
	}

	// iterate over all texels and use the distance to the 2 closest random
	// points to calculate the texel's color
	Float max = 0;
	for (UInt y = 0; y < height; y++)
	{
		for (UInt x = 0; x < width; x++)
		{
			Float minDist = MathF::MAX_REAL;
			Float min2Dist = MathF::MAX_REAL;
			UInt minIndex = 0;

			for (UInt i = 0; i < cells.GetQuantity(); i++)
			{
				Vector2F pos(static_cast<Float>(x), static_cast<Float>(y));

				// Handle tiling
				Vector2F vec = cells[i].point - pos;
				vec.X() = MathF::FAbs(vec.X());
				vec.Y() = MathF::FAbs(vec.Y());
				vec.X() = vec.X() > width/2 ? width-vec.X() : vec.X();
				vec.Y() = vec.Y() > height/2 ? height-vec.Y() : vec.Y();

				Float distance = vec.Length();

				if (minDist > distance)
				{
					min2Dist = minDist;
					minDist = distance;
					minIndex = i;
				}
				else if (min2Dist > distance)
				{
					min2Dist = distance;
				}
			}

			Float factor = (min2Dist - minDist) + 3;
			ColorRGB color = cells[minIndex].color * factor;
			pColorDst[y*width+x] = color;

			max = max < color.R() ? color.R() : max;
			max = max < color.G() ? color.G() : max;
			max = max < color.B() ? color.B() : max;
		}
	}

	// convert and normalize the ColorRGBA float array to an 8-bit per
	// channel texture
	max = 255.0F / max;
	UChar* const pDst = WIRE_NEW UChar[width * height * bpp];
	for (UInt i = 0; i < width*height; i++)
	{
		ColorRGB color = pColorDst[i];
		pDst[i*bpp] = static_cast<UChar>(color.R() * max);
		pDst[i*bpp+1] = static_cast<UChar>(color.G() * max);
		pDst[i*bpp+2] = static_cast<UChar>(color.B() * max);
	}

	Image2D* pImage = WIRE_NEW Image2D(format, width, height, pDst);
	Texture2D* pTexture = WIRE_NEW Texture2D(pImage);
	// The texture tiles are supposed to be seamless, therefore
	// we need the UV set to be repeating.
	pTexture->SetWrapType(0, Texture2D::WT_REPEAT);
	pTexture->SetWrapType(1, Texture2D::WT_REPEAT);

	// save the texture for later reference
	mspTexture = pTexture;

	return pTexture;
}