Пример #1
0
void iPhysicsController::Update(float afTimeStep)
{
    if(mbActive==false || mbPaused) return;
    if(mpBody==NULL) return;

    cVector3f vInput = GetInputValue(mInputType);
    //Get the local input.
    if(	mbUseInputMatrixFix == false ||
            (mInputType != ePhysicsControllerInput_JointAngle && mInputType != ePhysicsControllerInput_JointDist) )
        {
            vInput = cMath::MatrixMul(cMath::MatrixInverse(mpBody->GetLocalMatrix().GetRotation()),vInput);
        }


    float fValue = GetAxisValue(mInputAxis, vInput);
    float fError = mfDestValue - fValue;

    float fOutput = GetOutputValue(fError,fValue,afTimeStep);

    if(mfMaxOutput>0)
        {
            if(fOutput>0)
                fOutput = cMath::Min(fOutput, mfMaxOutput);
            else
                fOutput = cMath::Max(fOutput, -mfMaxOutput);
        }

    if(mbLogInfo)
        Log("%s | Input: %f Dest: %f Error: %f OutPut: %f\n",msName.c_str(),fValue,mfDestValue,fError,fOutput);

    AddOutputValue(mOutputType,mOutputAxis,fOutput);

    ////////////////////////////////////////
    //Check if dest vale is reached
    if(mEndType == ePhysicsControllerEnd_OnDest && mpJoint)
        {
            if(std::abs(fValue - mfDestValue) < kEpsilonf)
                {
                    mbActive = false;
                    iPhysicsController *pNext = mpJoint->GetController(msNextController);
                    if(pNext) pNext->SetActive(true);
                }
        }
}
void DynamicDriftCorrectionAction::Draw() const
{
	// Do draw some stuff for debugging
#ifdef CLIENT_DEBUG
		// WebView pixels
		glm::vec2 webViewPixels(_pTab->GetWebViewWidth(), _pTab->GetWebViewHeight());

		// Function to move coordinate according to current zoom. Takes relative WebView coordinate
		const std::function<void(glm::vec2&)> applyZooming = [&](glm::vec2& rCoordinate)
		{
			rCoordinate -= _relativeZoomCoordinate;
			rCoordinate /= _logZoom; // inverse to WebView shader
			rCoordinate += _relativeZoomCoordinate;
			rCoordinate -= _relativeCenterOffset; // inverse to WebView shader
			rCoordinate *= webViewPixels;
		};

		/*
		// Zoom coordinate
		glm::vec2 zoomCoordinate(_relativeZoomCoordinate);
		applyZooming(zoomCoordinate);
		_pTab->Debug_DrawRectangle(zoomCoordinate, glm::vec2(5, 5), glm::vec3(1, 0, 0));
		*/

		// Click coordinate
		glm::vec2 coordinate;
		if (GetOutputValue("coordinate", coordinate)) // only show when set
		{
			// TODO: convert from CEF Pixel space to WebView Pixel space
			_pTab->Debug_DrawRectangle(coordinate, glm::vec2(5, 5), glm::vec3(0, 1, 0));
		}

		// Testing visualization
		glm::vec2 testCoordinate(0.3f, 0.5f);
		applyZooming(testCoordinate);
		_pTab->Debug_DrawRectangle(testCoordinate, glm::vec2(5, 5), glm::vec3(0, 0, 1));
#endif // CLIENT_DEBUG
}