コード例 #1
0
osg::Vec2 CityModel::findCollisionEdge(std::vector<osg::Vec2> &points, std::vector<osg::Vec2> &checks, osg::Vec2 &resultVector)
{
	osg::Vec2 direction1, direction2;

	if (points.size() == 1)
	{
		int i=0;
		for (; i < 4; i++)
		{
			if (points.front() == checks[i])
				break;
		}

		direction1 = checks[(i + 1) % 4] - checks[i];
		direction2 = checks[posMod(i - 1,4)] - checks[i];

		// insert same again, to apply 2nd direction later
		points.push_back(points.front());
		
	}
	else if (points.size() == 2)
		for (int i = 0; i < 4; i++)
			if (contains(points, checks[i]) && contains(points, checks[(i + 1) % 4]))
			{
				direction1 = checks[posMod(i - 1, 4)] - checks[i];
				direction2 = checks[(i + 2) % 4] - checks[(i + 1) % 4];
				break;
			}

	else if (points.size() == 3)
		for (int i = 0; i < 4; i++)
			if (!contains(points, checks[i]))
			{
				direction1 = checks[posMod(i - 1, 4)] - checks[i];
				direction2 = checks[(i + 2) % 4] - checks[(i + 1) % 4];
				break;
			}

	direction1.normalize();
	direction2.normalize();
	osg::Vec2 pix1 = worldToPixelIndex(points[0]);
	osg::Vec2 pix2 = worldToPixelIndex(points[1]);

	osg::Vec2 p1 = pixelToWorld( findBorder(pix1, direction1) );
	osg::Vec2 p2 = pixelToWorld( findBorder(pix2, direction2) );



	if (debugging)
	{
		std::vector<osg::Vec2> redPoints{ findBorder(pix1, direction1), findBorder(pix2, direction2) };

		std::vector<osg::Vec2> markPoints2{ worldToPixelIndex(checks[0]),
			worldToPixelIndex(checks[1]),
			worldToPixelIndex(checks[2]),
			worldToPixelIndex(checks[3])
		};
		writeDebugImage(pix1.x(), pix1.y(), &redPoints, &markPoints2);
		resultVector.set((p2 - p1).x(), (p2 - p1).y());
		std::cout << "[CityModel] resultVector" << resultVector.x() << " " << resultVector.y() << std::endl;
		while (1);
	}

	
	//resultNormal.set(osg::Vec3(p2-p1,0)^osg::Vec3(0,0,1));
	resultVector.set((p2 - p1).x(),(p2-p1).y());
	//center
	return (p2 + p1) / 2;
}
コード例 #2
0
 void    Frame(bool& request_warp, osg::Vec2& warp, bool& handled)
 {
     request_warp = true ;
     warp.set(0,0) ;
     handled = true ;
 }