void ParticleEngine::createParticle( Particle * p )
{
	p->position = vec3( 0.0f, 0.0f, 0.0f );
	p->velocity = currentVelocity( ) - vec3( 0.3f * randomFloat( ) - 0.15f,
											 0.3f * randomFloat( ) - 0.15f,
											 0.3f * randomFloat( ) - 0.15f );
	p->color = currentColor( );
	p->timeAlive = 0;
	p->lifespan = randomFloat( ) + 1;
}
示例#2
0
XnStatus XnVSwipeDetector::AddPoint(const XnPoint3D& pt, XnFloat fTime)
{
	m_pMovementDetectionBuffer->AddPoint(pt, fTime);
	if (m_pMovementDetectionBuffer->GetAvailableTimespan() < m_nMotionDetectionTime)
	{
		return XN_STATUS_NITE_NOT_ENOUGH_TIME;
	}

	XnV3DVector currentVelocity(m_pMovementDetectionBuffer->GetAverageVelocityByTime(m_nMotionDetectionTime, fTime));

	if (m_pPendingEvent != NULL)
	{
		XnFloat fMotionVelocity = currentVelocity.Magnitude();
		// we will wait for the final slowdown once our velocity is below
		// a certain threshold
		if (m_bWaitingForSlowdown)
		{
			if (fMotionVelocity <= m_fLowestVelocity)
			{
				m_fLowestVelocity = fMotionVelocity;
			}
			else
			{
				m_pPendingEvent->Raise(m_fPendingVelocity, m_fPendingAngle);
				m_pSwipeCBs->Raise(m_ePendingDirection, m_fPendingVelocity, m_fPendingAngle);
				m_pPendingEvent = NULL;
				m_ePendingDirection = DIRECTION_ILLEGAL;
				m_bWaitingForSlowdown = false;
				if (m_bUseSteady)
				{
					m_bInSteady = true;
					m_Steady.Reset();
				}
			}
		}
		else
		{
			m_bWaitingForSlowdown = true;
			m_fLowestVelocity = fMotionVelocity;
		} // if (m_bWaitingForSlowdown) else

		return XN_STATUS_OK;
	} // if (m_pPendingEvent != NULL)

	currentVelocity.Z = 0;
	XnFloat fMotionVelocity = currentVelocity.Magnitude();
	currentVelocity.Normalize();

	if (fMotionVelocity >= m_fMotionDetectionSpeed)
	{
		m_fPendingVelocity = fMotionVelocity;
		XnFloat fHowCloseToX = acos(DotProduct(currentVelocity, XnV3DVector(1, 0, 0))) * (180.0f/XnVMathCommon::PI);
		XnFloat fHowCloseToY = acos(DotProduct(currentVelocity, XnV3DVector(0, 1, 0))) * (180.0f/XnVMathCommon::PI);

		if (fabs(fabs(fHowCloseToX) - 180) < m_fAngleXThreshold)
		{
			m_pPendingEvent = m_pSwipeLeftCBs;
			m_ePendingDirection = DIRECTION_LEFT;
			m_fPendingAngle = fHowCloseToX;
			xnLogVerbose(XNV_NITE_MASK_EVENTS, "Swipe Detector %s [0x%08x]: Motion Velocity %5.2f m/s over threshold %5.2f in the last %d ms. Angle from X axis is %5.2f, within range [%5.2f-%5.2f] as LEFT",
				GetListenerName(), this,
				fMotionVelocity, m_fMotionDetectionSpeed, m_nMotionDetectionTime,
				fabs(fHowCloseToX), 180-m_fAngleXThreshold, 180+m_fAngleXThreshold);
		}

		if (fabs(fHowCloseToX) < m_fAngleXThreshold)
		{
			m_pPendingEvent = m_pSwipeRightCBs;
			m_ePendingDirection = DIRECTION_RIGHT;
			m_fPendingAngle = fHowCloseToX;
			xnLogVerbose(XNV_NITE_MASK_EVENTS, "Swipe Detector %s [0x%08x]: Motion Velocity %5.2f m/s over threshold %5.2f in the last %d ms. Angle from X axis is %5.2f, within range [%5.2f-%5.2f] as RIGHT",
				GetListenerName(), this,
				fMotionVelocity, m_fMotionDetectionSpeed, m_nMotionDetectionTime,
				fHowCloseToX, -m_fAngleXThreshold, m_fAngleXThreshold);
		}

		if (fabs(fabs(fHowCloseToY) - 180) < m_fAngleYThreshold)
		{
			m_pPendingEvent = m_pSwipeDownCBs;
			m_ePendingDirection = DIRECTION_DOWN;
			m_fPendingAngle = fHowCloseToY;
			xnLogVerbose(XNV_NITE_MASK_EVENTS, "Swipe Detector %s [0x%08x]: Motion Velocity %5.2f m/s over threshold %5.2f in the last %d ms. Angle from Y axis is %5.2f, within range [%5.2f-%5.2f] as DOWN",
				GetListenerName(), this,
				fMotionVelocity, m_fMotionDetectionSpeed, m_nMotionDetectionTime,
				fabs(fHowCloseToY), 180-m_fAngleYThreshold, 180+m_fAngleYThreshold);
		}

		if (fabs(fHowCloseToY) < m_fAngleYThreshold)
		{
			m_pPendingEvent = m_pSwipeUpCBs;
			m_ePendingDirection = DIRECTION_UP;
			m_fPendingAngle = fHowCloseToY;
			xnLogVerbose(XNV_NITE_MASK_EVENTS, "Swipe Detector %s [0x%08x]: Motion Velocity %5.2f m/s over threshold %5.2f in the last %d ms. Angle from Y axis is %5.2f, within range [%5.2f-%5.2f] as UP",
				GetListenerName(), this,
				fMotionVelocity, m_fMotionDetectionSpeed, m_nMotionDetectionTime,
				fHowCloseToY, -m_fAngleYThreshold, m_fAngleYThreshold);
		}
	} // if (fMotionVelocity >= m_fMotionDetectionSpeed)

	return XN_STATUS_OK;
} // XnVSwipeDetector::AddPoint