void plAnimatedMovementStrategy::IRecalcAngularVelocity(float elapsed, hsMatrix44 &prevMat, hsMatrix44 &curMat)
{
    fAnimAngularVel = 0.0f;
    float appliedVelocity = 0.0f;
    hsVector3 prevForward = GetYAxis(prevMat);
    hsVector3 curForward = GetYAxis(curMat);

    float angleSincePrev = AngleRad2d(curForward.fX, curForward.fY, prevForward.fX, prevForward.fY);
    bool sincePrevSign = angleSincePrev > 0.0f;
    if (angleSincePrev > float(M_PI))
        angleSincePrev = angleSincePrev - TWO_PI;

    const hsVector3 startForward = hsVector3(0.0f, -1.0f, 0.0f);    // the Y orientation of a "resting" armature....
    float angleSinceStart = AngleRad2d(curForward.fX, curForward.fY, startForward.fX, startForward.fY);
    bool sinceStartSign = angleSinceStart > 0.0f;
    if (angleSinceStart > float(M_PI))
        angleSinceStart = angleSinceStart - TWO_PI;

    // HANDLING ANIMATION WRAPPING:
    // under normal conditions, the angle from rest to the current frame will have the same
    // sign as the angle from the previous frame to the current frame.
    // if it does not, we have (most likely) wrapped the motivating animation from frame n back
    // to frame zero, creating a large angle from the previous frame to the current one
    if (sincePrevSign == sinceStartSign)
    {
        // signs are the same; didn't wrap; use the frame-to-frame angle difference
        appliedVelocity = angleSincePrev / elapsed;	// rotation / time
        if (fabs(appliedVelocity) < 3)
        {
            fAnimAngularVel = appliedVelocity;
        }
    }
}
Example #2
0
void Camera::Update()
{
	UpdateBasis();

    MathLib::vector4& camera_xAxis = GetXAxis();
    MathLib::vector4& camera_yAxis = GetYAxis();
    MathLib::vector4& camera_zAxis = GetZAxis();
    MathLib::vector4& camera_position = GetPosition();

	// Create world to camera space transform.
	{
		MathLib::matrix4x4 worldToCameraTransform_basisComponent
		(
			camera_xAxis.extractX(), camera_xAxis.extractY(), camera_xAxis.extractZ(), 0.0f,
			camera_yAxis.extractX(), camera_yAxis.extractY(), camera_yAxis.extractZ(), 0.0f,
			camera_zAxis.extractX(), camera_zAxis.extractY(), camera_zAxis.extractZ(), 0.0f,
			0.0f, 0.0f, 0.0f, 1.0f
		);

		MathLib::matrix4x4 worldToCameraTransform_translationComponent
		(
			1.0f, 0.0f, 0.0f, -camera_position.extractX(),
			0.0f, 1.0f, 0.0f, -camera_position.extractY(),
			0.0f, 0.0f, 1.0f, -camera_position.extractZ(),
			0.0f, 0.0f, 0.0f, 1.0f
		);

		MathLib::matrix4x4 worldToCameraTransform;
		MathLib::matrix4x4_mul(worldToCameraTransform_basisComponent, worldToCameraTransform_translationComponent, worldToCameraTransform);
		MathLib::matrix4x4_copy(worldToCameraSpaceMatrix, worldToCameraTransform);
	}

	// Create camera to world space transform.
	{
		MathLib::matrix4x4 orientation
		(
			camera_xAxis.extractX(), camera_yAxis.extractX(), camera_zAxis.extractX(), 0.0f, 
			camera_xAxis.extractY(), camera_yAxis.extractY(), camera_zAxis.extractY(), 0.0f, 
			camera_xAxis.extractZ(), camera_yAxis.extractZ(), camera_zAxis.extractZ(), 0.0f, 
			0.0f, 0.0f, 0.0f, 1.0f
		);

		MathLib::matrix4x4 translation
		(
			1.0f, 0.0f, 0.0f, camera_position.extractX(), 
			0.0f, 1.0f, 0.0f, camera_position.extractY(), 
			0.0f, 0.0f, 1.0f, camera_position.extractZ(), 
			0.0f, 0.0f, 0.0f, 1.0f
		);

		MathLib::matrix4x4_mul(translation, orientation, cameraToWorldSpaceMatrix);
	}
}
Example #3
0
void CSkeleton::ResetManuverVector(int chance, XMFLOAT3& mVector)
{
	XMVECTOR zAxis = XMLoadFloat3(GetZAxis());
	XMVECTOR yAxis = XMLoadFloat3(GetYAxis());
	zAxis = XMVector3Normalize(zAxis);
	yAxis = XMVector3Normalize(yAxis);


	XMVECTOR translateVector;

	if (chance == 0)
		translateVector = XMVector3Cross(zAxis, yAxis);
	else
		translateVector = XMVector3Cross(yAxis, zAxis);
	translateVector = XMVector3Normalize(translateVector);
	translateVector *= 150.0f;
	XMStoreFloat3(&mVector, translateVector);
}
Example #4
0
	//************************************************
	//*操纵杆输入线程
	//************************************************
	DWORD WINAPI t1::InputThreadProcedure(LPVOID lpStartupParam)
	{
		// get the data we passed to the thread. Note that we don't have to use this
		// at all if we don't want
		MYDATA* pMyData = (MYDATA*)lpStartupParam;

		// access some imaginary members of MYDATA, which you can define on
		// your own later
		pMyData->nTime = GetCurrentTime(); // imaginary function I created
		pMyData->nNumber = 5;


		// here's the thread's main loop ?kind of like the main loop in WinMain
		MSG msg;
		int i;
		for (;;)
		{
			//处理外部消息
			if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
			{
				GetMessage(&msg, NULL, 0, 0);

				if (msg.message == WM_THREADSTOP)
					break; // only way out of the for( ;; ) loop

				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
			else
			{
				switch (m_TestState)
				{
				case STATE_DISPLAYINSTURCTION:
				case STATE_DISPLAYNEXT:
				case STATE_DISPLAYOPTION:
					//呈现开始选项,等待按任意键开始测试
					if (JoystickUpdate())
					{
						for (i = 0; i<8; i++)
						{
							if (IsButtonDown(KEY_YES))
							{
								m_TrialNo++;
								TestInit();
								m_TestState = STATE_DISPLAYOBJ;
								break;
							}
						}
					}
					break;
				case STATE_DISPLAYOBJ:
				case STATE_MOVINGOBJ:
					//测试过程中获得操纵杆输入
					if (JoystickUpdate())
					{
						JoyX = GetXAxis();//GetYAxis();//
						JoyY = GetYAxis();//-GetZAxis();//
						if (m_Setting.m_MoveMode == MODE_MOVEROATE)
						{
							JoyZ = GetZAxis();//GetXAxis();//
							post_fai = (float)(JoyZ - post_fai0)*(3600.0 / 1024.0) / m_HardSetting.m_KnobSensitive;//GetZAxis()*PI/400.0;
							while (post_fai<-180)
							{
								post_fai = post_fai + 360;
							}
							while (post_fai>180)
							{
								post_fai = post_fai - 360;
							}
						}
					}
					break;
				case STATE_OVER:
					//测试结束,等待按任意键退出
					if (JoystickUpdate())
					{
						for (i = 0; i<12; i++)
						{
							if (IsButtonDown(i))
							{
								PostThreadMessage(dwInputThreadID, WM_THREADSTOP, 0, 0);
								m_TestState = STATE_NEXT;// STATE_EXIT --> STATE_NEXT
							}
						}
					}
					break;
				default:
					break;
				}
				// do the task ?add in your own stuff here

				// yield to other threads, because we almost never get messages
				// (note that we may be yielding to WinMain too)
				//以键盘代替操纵杆
				if (JOY == 0)
				{
					if (IsButtonDown(DIK_ESCAPE))
					{
						PostThreadMessage(dwInputThreadID, WM_THREADSTOP, 0, 0);
						m_TestState = STATE_EXIT;
					}
				}
			}
			Sleep(1);
		}
		g_nThreadExitCount++;
		return 0;
	}