Ejemplo n.º 1
0
TEST(Proxy, Signal)
{
  boost::shared_ptr<Foo> foo(new Foo);
  qi::AnyObject gfoo = qi::AnyReference::from(foo).toObject();
  ASSERT_TRUE(!!gfoo);
  qi::detail::printMetaObject(std::cerr, gfoo.metaObject());
  // The session must die before foo.
  TestSessionPair p;
  p.server()->registerService("foo", gfoo);
  qi::AnyObject client = p.client()->service("foo");
  ASSERT_EQ(0, client.call<int>("count1"));
  qi::ProxySignal<void(int, int)> proxy1(client, "sig1");
  foo->subscribe1();
  proxy1(1, 2);
  PERSIST_ASSERT(, foo->count1() == 3, 500);
  // small hack, reuse foo function to test callback on proxy signal
  Foo foo2;
  qi::SignalLink l =  proxy1.connect(boost::bind(&Foo::on1, &foo2, _1, _2));
  proxy1(3, 4);
  PERSIST_ASSERT(, foo->count1() == 10, 500);
  PERSIST_ASSERT(, foo2.count1() == 7, 500);
  proxy1.disconnect(l);
  proxy1(1, 1);
  PERSIST_ASSERT(, foo->count1() == 12, 500);
  PERSIST_ASSERT(, foo2.count1() == 7, 500);
}
Ejemplo n.º 2
0
bool b3HullShape::TestSphere(b3TestSphereOutput* output, const b3Sphere& sphere, const b3Transform& xf) const
{
	b3Transform xf1 = xf;
	b3Transform xf2 = b3Transform_identity;

	b3ShapeGJKProxy proxy1(this, 0);
	
	b3GJKProxy proxy2;
	proxy2.vertexCount = 1;
	proxy2.vertexBuffer[0] = sphere.vertex;
	proxy2.vertices = proxy2.vertexBuffer;
	proxy2.radius = sphere.radius;

	b3GJKOutput gjk = b3GJK(xf1, proxy1, xf2, proxy2);

	float32 r1 = proxy1.radius;
	float32 r2 = proxy2.radius;

	float32 totalRadius = r1 + r2;

	if (gjk.distance > totalRadius)
	{
		return false;
	}

	if (gjk.distance > 0.0f)
	{
		b3Vec3 c1 = gjk.point1;
		b3Vec3 c2 = gjk.point2;
		b3Vec3 n = (c2 - c1) / gjk.distance;

		output->point = c1;
		output->normal = n;
		output->separation = gjk.distance - totalRadius;

		return true;
	}

	// Perform computations in the local space of the first hull.
	b3Vec3 support = b3MulT(xf1, sphere.vertex);

	u32 maxIndex = ~0;
	float32 maxSeparation = -B3_MAX_FLOAT;

	for (u32 i = 0; i < m_hull->faceCount; ++i)
	{
		b3Plane plane = m_hull->GetPlane(i);
		float32 separation = b3Distance(support, plane);

		if (separation > totalRadius)
		{
			return false;
		}

		if (separation > maxSeparation)
		{
			maxIndex = i;
			maxSeparation = separation;
		}
	}

	B3_ASSERT(maxIndex != ~0);

	b3Plane plane = b3Mul(xf1, m_hull->GetPlane(maxIndex));
	
	output->point = b3ClosestPointOnPlane(sphere.vertex, plane);
	output->separation = maxSeparation - totalRadius;
	output->normal = plane.normal;
	return true;
}