Example #1
0
// Wat..
void RenderHands(CVPipeline * pipe)
{
	List<CVHand> & hands = pipe->hands;
//	std::vector<std::vector<cv::Point> > c;
	for(int i = 0; i < hands.Size(); i++)
	{
		CVHand & hand = hands[i];

		if (hand.contour && hand.contour->segments.Size())
			RenderContourSegments(hand.contour, pipe);
		else
			RenderContours(pipe);
	

	//	assert(hand.contour);
	//	c.clear();
	//	c.push_back(hand.contour->cvPointList);
		cv::circle(pipe->output, cv::Point(hand.center.x, hand.center.y), 20, cv::Scalar(0, 0, 255), 2);
		int fingersSize = hand.fingers.Size();
		for(int j = 0; j < fingersSize; j++)
		{
#define VEC3FTOCVPOINT(a) (cv::Point(a.x,a.y))
			CVFinger & finger = hand.fingers[j];
			Vector3f fingerPoint = finger.point;
			Vector4f fingerColor = finger.GetColor();
#define VECTOCVSCALAR(a) (cv::Scalar(a.z,a.y,a.x))
			cv::circle(pipe->output, cv::Point(fingerPoint.x, fingerPoint.y), 10, VECTOCVSCALAR(fingerColor), 2);
			cv::line(pipe->output, VEC3FTOCVPOINT(hand.center), VEC3FTOCVPOINT(fingerPoint), VECTOCVSCALAR(fingerColor), 4);

			Vector3f start = finger.start;
			if (start.MaxPart())
				cv::circle(pipe->output, cv::Point(start.x, start.y), 5, cv::Scalar(255,0,125), 2);
			Vector3f stop = finger.stop;
			if (stop.MaxPart())
				cv::circle(pipe->output, cv::Point(stop.x, stop.y), 5, cv::Scalar(0,255,255), 2);

			// Render each parallel pair in some colored circle or line?
			for (int i = 0; i < finger.parallelPairs.Size(); ++i)
			{
				CVContourSegmentPair & csp = finger.parallelPairs[i];
				// Parallel point.
				Vector3f pp = csp.one.rawInputStart, pp2 = csp.two.rawInputStart;
				cv::circle(pipe->output, cv::Point(pp.x, pp.y), 5, cv::Scalar(155,255,155), 2);
				cv::circle(pipe->output, cv::Point(pp2.x, pp2.y), 5, cv::Scalar(155,255,255), 2);
			}

		}

		// Render approximate velocity.
		Vector3f vel = hand.approximateVelocityFromOpticalFlow;
		Vector3f colorVel = vel;
		colorVel.y *= -1;
		Vector4f color = GetColorForDirection(colorVel.NormalizedCopy());
		// Paint it.
		cv::line(pipe->output, VectorToCVPoint(hand.center), VectorToCVPoint(hand.center + vel * 3), 
			VectorToCVScalarColor(color), 5);

		//		std::cout<<"\nfingers drawn: "<<hand.fingers.Size();
	}
}
Example #2
0
void MORPGIntegrator::IntegrateVelocity(Entity * forEntity, float timeInSeconds)
{

	PhysicsProperty * pp = forEntity->physics;
	Vector3f & position = forEntity->localPosition;

	// Add regular velocity (from physics and effects)
	Vector3f velocity = pp->velocity;
	// Add the relative velocity (from player desired movement)
	velocity += forEntity->rotationMatrix.Product(pp->relativeVelocity);

	Vector3f lookAt = forEntity->rotationMatrix.Product(Vector3f(0,0,2.f));

	Vector3f distanceTraveled;
	if (velocity.MaxPart())
	{
		//... and travel!
		distanceTraveled = velocity  * timeInSeconds;
		position += distanceTraveled;
	}	
	// Accelerate in the looking-direction
	Vector3f localAcceleration = forEntity->rotationMatrix.Product(pp->acceleration);
	pp->velocity += localAcceleration * timeInSeconds;

	// Apply linear damping
	pp->velocity *= pow(pp->linearDamping, timeInSeconds);

	// Rotate.
	Quaternion rotation(pp->angularVelocityQuaternion);
	if (rotation.w && rotation.MaxPart())
	{
		// Multiple the amount to rotate with time.
		rotation.angle *= timeInSeconds;
		// Recalculate it so that it becomes a unit quaternion again.
		rotation.RecalculateXYZW();
		pp->orientation = pp->orientation * rotation;
		//.. and don't forget to normalize it or it will die.
		pp->orientation.Normalize();
	}
	// Recalculate matrix after integration is done.
	forEntity->RecalculateMatrix();
}