Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 28 Nov 2013
Offline Last Active Feb 03 2014 07:59 AM

Posts I've Made

In Topic: Pathfinding with virtual fields

21 December 2013 - 06:57 AM

DrEvil, thanks, it's realy good idea. I've done it and I saw on the vector field, that there are eternal loops, but I can't handle it. On the attached igms I've isolated with black areas wrong vectors. Direction defines as from cell center to periphery.


Don't know how to correct that.

In Topic: Pathfinding with virtual fields

14 December 2013 - 09:36 AM

Here is my screenshots.

In Topic: 2D Rects collision problems

10 December 2013 - 08:13 AM

Thanks, I've fixed it.

In Topic: How to read depth buffer value at a pixel to CPU and get its world coordinate

02 December 2013 - 01:37 PM

Projects a 3D vector from screen space into object space.

XMVECTOR XMVector3Unproject(
  [in]  XMVECTOR V,
  [in]  float ViewportX,
  [in]  float ViewportY,
  [in]  float ViewportWidth,
  [in]  float ViewportHeight,
  [in]  float ViewportMinZ,
  [in]  float ViewportMaxZ,
  [in]  XMMATRIX Projection,
  [in]  XMMATRIX View,
  [in]  XMMATRIX World

Is this all you need?

In Topic: 2D rotation problems

30 November 2013 - 04:16 PM

I've handled problem. The problem was in world matrix. The right variant (in my case) is World = scale * rotationZ * translation. And this line of code killed 2 days of my life angry.png


unbird, you are right about coefficients calculating and atan2, but it was another bug.


So the correct variant of setting GameObjects to draw lines:

for (Line& line: SidesCoordList)
		shared_ptr<GameObject> temp(new GameObject());
		float length = sqrt( pow(line.point2.x - line.point1.x, 2) + pow(line.point2.y - line.point1.y, 2) );

		float A = line.point1.y - line.point2.y;
		float B = line.point1.x - line.point2.x;
		float angle = atan2(A, B);

		XMFLOAT2 center = XMFLOAT2(  (line.point2.x + line.point1.x) / 2.0f, (line.point2.y + line.point1.y) / 2.0f );

		temp->SetRotation(-(XM_PIDIV2 - angle));
		temp->SetScale(XMFLOAT2( 5.0f, length ));


And here is function that defines if the object reach the line:

bool BulletManager::IsIntersecting(Line line, XMFLOAT2 point, float eps)
	if (!((point.x >= min(line.point1.x, line.point2.x) &&
		point.x <= max(line.point1.x, line.point2.x)) ||
		(point.y >= min(line.point1.y, line.point2.y) &&
		point.y <= max(line.point1.y, line.point2.y))) )
		return false;

	// Constructing canonical line equation
	float A = line.point1.y - line.point2.y;
	float B = line.point2.x - line.point1.x;
	float C = (-B * line.point2.y) - (A * line.point2.x);

	// Calculating distance from bullet to line
	float Dist = (abs((A * point.x) + (B * point.y) + C)) / sqrt(pow(A,2) + pow(B,2));

	if (Dist <= eps)
		return true;

	return false;

Maybe it will be useful for someone. Who knows...