void CameraDefaultCtrl::onMouseMove(float x, float y) { if(m_bLeftDrag) { Vector2 nowPt(x,y); Vector2 delta = nowPt - m_lastDragPt; m_yaw += delta.x*2; m_pitch += delta.y*2; updateViewMat(); m_lastDragPt.x = x; m_lastDragPt.y = y; } else if(m_bRightDrag) { Vector3 vX(1, 0, 0); Vector3 vZ(0, 0, 1); Vector2 nowPt(x,y); Vector2 delta = nowPt - m_lastDragPt; delta *= m_moveSpeed; m_lookAt -= vX*delta.x; m_lookAt -= vZ*delta.y; updateViewMat(); m_lastDragPt = nowPt; } }
void Jacobian(const gsl_vector *X, gsl_matrix *J) const { std::vector<real_t> vX(m_arity); std::vector<real_t> vR(m_arity), vJ(m_arity*m_arity); m_f.roots_and_jacobian(&vX[0], &vR[0], &vJ[0]); ToGSL(J, vJ); }
void Roots(const gsl_vector *X, gsl_vector *R) const { std::vector<real_t> vX(FromGSL<real_t>(X)); std::vector<real_t> vR(m_arity); m_f.roots(&vX[0], &vR[0]); ToGSL(R, vR); }
XVECTOR XSQUARE_MATRIX::Forward_Substituion(const XVECTOR &i_vB) { XVECTOR vX(m_uiN); unsigned int uiRow; unsigned int uiCol; if (!m_bLU_Initialized) Perform_LU_Decomposition(); if (m_bLU_Initialized) { // Assuming we have a lower triangular matrix // perform forward substitution for (uiRow = 0; uiRow < m_uiN; uiRow++) { vX.m_lpdValues[uiRow] = i_vB.m_lpdValues[uiRow]; for (uiCol = 0; uiCol < uiRow; uiCol++) { vX.m_lpdValues[uiRow] -= m_lpdL_Values[uiRow * m_uiN + uiCol] * vX.m_lpdValues[uiCol]; } vX.m_lpdValues[uiRow] /= m_lpdL_Values[uiRow * (1 + m_uiN)]; } } return vX; }
Mat CmSaliencyRC::GetBorderReg(CMat &idx1i, int regNum, double ratio, double thr) { // Variance of x and y vecD vX(regNum), vY(regNum); int w = idx1i.cols, h = idx1i.rows;{ vecD mX(regNum), mY(regNum), n(regNum); // Mean value of x and y, pixel number of region for (int y = 0; y < idx1i.rows; y++){ const int *idx = idx1i.ptr<int>(y); for (int x = 0; x < idx1i.cols; x++, idx++) mX[*idx] += x, mY[*idx] += y, n[*idx]++; } for (int i = 0; i < regNum; i++) mX[i] /= n[i], mY[i] /= n[i]; for (int y = 0; y < idx1i.rows; y++){ const int *idx = idx1i.ptr<int>(y); for (int x = 0; x < idx1i.cols; x++, idx++) vX[*idx] += abs(x - mX[*idx]), vY[*idx] += abs(y - mY[*idx]); } for (int i = 0; i < regNum; i++) vX[i] = vX[i]/n[i] + EPS, vY[i] = vY[i]/n[i] + EPS; } // Number of border pixels in x and y border region vecI xbNum(regNum), ybNum(regNum); int wGap = cvRound(w * ratio), hGap = cvRound(h * ratio); vector<Point> bPnts; { ForPoints2(pnt, 0, 0, w, hGap) // Top region ybNum[idx1i.at<int>(pnt)]++, bPnts.push_back(pnt); ForPoints2(pnt, 0, h - hGap, w, h) // Bottom region ybNum[idx1i.at<int>(pnt)]++, bPnts.push_back(pnt); ForPoints2(pnt, 0, 0, wGap, h) // Left region xbNum[idx1i.at<int>(pnt)]++, bPnts.push_back(pnt); ForPoints2(pnt, w - wGap, 0, w, h) xbNum[idx1i.at<int>(pnt)]++, bPnts.push_back(pnt); } Mat bReg1u(idx1i.size(), CV_8U);{ // likelihood map of border region double xR = 1.0/(4*hGap), yR = 1.0/(4*wGap); vector<byte> regL(regNum); // likelihood of each region belongs to border background for (int i = 0; i < regNum; i++) { double lk = xbNum[i] * xR / vY[i] + ybNum[i] * yR / vX[i]; regL[i] = lk/thr > 1 ? 255 : 0; //saturate_cast<byte>(255 * lk / thr); } for (int r = 0; r < h; r++) { const int *idx = idx1i.ptr<int>(r); byte* maskData = bReg1u.ptr<byte>(r); for (int c = 0; c < w; c++, idx++) maskData[c] = regL[*idx]; } } for (size_t i = 0; i < bPnts.size(); i++) bReg1u.at<byte>(bPnts[i]) = 255; return bReg1u; }
// mirror a placement of one entity static void MirrorAndStretchPlacement(CPlacement3D &pl) { ASSERT(_wmtMirror==WMT_X||_wmtMirror==WMT_Y||_wmtMirror==WMT_Z||_wmtMirror==WMT_NONE); // if there should be mirror if (_wmtMirror!=WMT_NONE) { // make rotation matrix for the placement FLOATmatrix3D m; MakeRotationMatrix(m, pl.pl_OrientationAngle); // get row vectors, with object x flipped FLOAT3D vX(-m(1,1),m(1,2),m(1,3)); FLOAT3D vY(-m(2,1),m(2,2),m(2,3)); FLOAT3D vZ(-m(3,1),m(3,2),m(3,3)); // flip needed axis switch(_wmtMirror) { case WMT_X: pl.pl_PositionVector(1) = -pl.pl_PositionVector(1); vX = -vX; break; case WMT_Y: pl.pl_PositionVector(2) = -pl.pl_PositionVector(2); vY = -vY; break; case WMT_Z: pl.pl_PositionVector(3) = -pl.pl_PositionVector(3); vZ = -vZ; break; default: ASSERT(FALSE); } // compose matrix back from the vectors m(1,1) = vX(1); m(2,1) = vY(1); m(3,1) = vZ(1); m(1,2) = vX(2); m(2,2) = vY(2); m(3,2) = vZ(2); m(1,3) = vX(3); m(2,3) = vY(3); m(3,3) = vZ(3); // decompose matrix into angles DecomposeRotationMatrix(pl.pl_OrientationAngle, m); } pl.pl_PositionVector*=_fStretch; }
XVECTOR XSQUARE_MATRIX::Back_Substituion(const double * lpdValue_set, const XVECTOR &i_vB) { XVECTOR vX(m_uiN); unsigned int uiRow; unsigned int uiCol; // Assuming we have an upper triangular matrix // perform back substitution for (uiRow = m_uiN - 1; uiRow < m_uiN; uiRow--) { vX.m_lpdValues[uiRow] = i_vB.m_lpdValues[uiRow]; for (uiCol = uiRow + 1; uiCol < m_uiN; uiCol++) { vX.m_lpdValues[uiRow] -= lpdValue_set[uiRow * m_uiN + uiCol] * vX.m_lpdValues[uiCol]; } vX.m_lpdValues[uiRow] /= lpdValue_set[uiRow * (1 + m_uiN)]; } return vX; }
void CommandDisplayClipPropertiesDialog::ExecuteE() { EMMediaType eType(EM_TYPE_UNKNOWN); EMGClip* opClip; EMGTrack* opTrack; EMGUIUtilities* opGUIUtilities = EMGUIUtilities::Instance(); EMCommandRepository* opRepository = EMCommandRepository::Instance(); int32 vClipID(0); int32 vEntryID(-1); int64 vValue(0); int32 vX(0); int32 vY(0); string oFileName; char vTemp[100]; list<EMGClip*>* opClips = EMGClipRepository::Instance() -> GetSelectedClips(); list<EMGClip*>::iterator oClipIterator = opClips -> begin(); if(opClips -> size() == 0) return; while(oClipIterator != opClips -> end()) { opClip = *oClipIterator; eType = opClip -> GetType(); opTrack = opClip -> GetTrack(); switch(eType) { case EM_TYPE_ANY_AUDIO: vClipID = opClip ->GetMediaClipID(); vEntryID = *static_cast<int32*>(opRepository -> ExecuteCommand(MEDIA_INFO_COMMAND_GET_CLIP_ENTRY_ID, &vClipID, NULL, NULL)); m_oAudioDialog.SetNameValue(opClip -> GetLabel()); m_oAudioDialog.SetTypeValue("Audio"); m_oAudioDialog.SetBeginValue(opGUIUtilities -> GetTimeString(opClip -> GetPosition(), EM_SMPTE)); m_oAudioDialog.SetEndValue(opGUIUtilities -> GetTimeString(opClip -> GetPosition() + opClip -> GetLength(), EM_SMPTE)); m_oAudioDialog.SetDurationValue(opGUIUtilities -> GetTimeString(opClip -> GetLength(), EM_SMPTE)); vValue = *static_cast<int64*>(opRepository -> ExecuteCommand(MEDIA_INFO_COMMAND_GET_AUDIO_ENTRY_NUM_CHANNELS, &vEntryID)); m_oAudioDialog.SetChannelsValue(_i64toa(vValue, vTemp, 10)); vValue = *static_cast<int64*>(opRepository -> ExecuteCommand(MEDIA_INFO_COMMAND_GET_AUDIO_ENTRY_NUM_SAMPLES, &vEntryID)); m_oAudioDialog.SetSamplesValue(_i64toa(vValue, vTemp, 10)); oFileName = static_cast<const char*>(EMCommandRepository::Instance() -> ExecuteCommand(MEDIA_INFO_COMMAND_GET_ENTRY_FILENAME, &vEntryID)); //Full path to copied file oFileName.erase(0, oFileName.find_last_of('\\') + 1); //oFileName.erase(oFileName.find_last_of('.')); m_oAudioDialog.SetFileValue(oFileName); vValue = *static_cast<int64*>(opRepository -> ExecuteCommand(MEDIA_INFO_COMMAND_GET_ENTRY_DURATION, &vEntryID)); m_oAudioDialog.SetFileLengthValue(opGUIUtilities -> GetTimeString(vValue, EM_SMPTE)); vValue = *static_cast<int64*>(opRepository -> ExecuteCommand(MEDIA_INFO_COMMAND_GET_CLIP_MARK_IN, &vClipID)); m_oAudioDialog.SetMarkInValue(opGUIUtilities -> GetTimeString(vValue, EM_SMPTE)); vValue = *static_cast<int64*>(opRepository -> ExecuteCommand(MEDIA_INFO_COMMAND_GET_CLIP_MARK_OUT, &vClipID)); m_oAudioDialog.SetMarkOutValue(opGUIUtilities -> GetTimeString(vValue, EM_SMPTE)); m_oAudioDialog.Init(vX, vY, AUDIO); CalculatePosition(vX, vY, opClip, opTrack -> GetTrackInfo(), &m_oAudioDialog); m_oAudioDialog.MoveDialog(vX, vY); m_oAudioDialog.DisplayDialog(); break; case EM_TYPE_MIDI: { char vTemp[100]; uint32 vEvents(0); m_oMidiDialog.SetNameValue(opClip -> GetLabel()); m_oMidiDialog.SetTypeValue("Midi"); m_oMidiDialog.SetBeginValue(opGUIUtilities -> GetTimeString(opClip -> GetPosition(), EM_MEASURES)); m_oMidiDialog.SetEndValue(opGUIUtilities -> GetTimeString(opClip -> GetPosition() + opClip -> GetLength(), EM_MEASURES)); m_oMidiDialog.SetDurationValue(opGUIUtilities -> GetTimeString(opClip -> GetLength(), EM_MEASURES)); int32 vMediaClipID(opClip ->GetMediaClipID()); vEvents = (static_cast<list<EMMediaMIDIEvent*>*>(EMCommandRepository::Instance() -> ExecuteCommand(MEDIA_INFO_COMMAND_GET_MIDI_EVENTS_FOR_CLIP, &vMediaClipID, NULL, NULL))) -> size(); m_oMidiDialog.SetEventValue(string(itoa(vEvents, vTemp, 10))); m_oMidiDialog.Init(vX, vY, MIDI); CalculatePosition(vX, vY, opClip, opTrack -> GetTrackInfo(), &m_oMidiDialog); m_oMidiDialog.MoveDialog(vX, vY); m_oMidiDialog.DisplayDialog(); break; } case EM_TYPE_ANY_VIDEO: vClipID = opClip ->GetMediaClipID(); vEntryID = *static_cast<int32*>(opRepository -> ExecuteCommand(MEDIA_INFO_COMMAND_GET_CLIP_ENTRY_ID, &vClipID, NULL, NULL)); m_oVideoDialog.SetNameValue(opClip -> GetLabel()); m_oVideoDialog.SetTypeValue("Video"); m_oVideoDialog.SetBeginValue(opGUIUtilities -> GetTimeString(opClip -> GetPosition(), EM_SMPTE)); m_oVideoDialog.SetEndValue(opGUIUtilities -> GetTimeString(opClip -> GetPosition() + opClip -> GetLength(), EM_SMPTE)); m_oVideoDialog.SetDurationValue(opGUIUtilities -> GetTimeString(opClip -> GetLength(), EM_SMPTE)); // vValue = *static_cast<int64*>(opRepository -> ExecuteCommand(MEDIA_INFO_COMMAND_GET_VIDEO_ENTRY_NUM_FRAMES, &vEntryID)); // m_oVideoDialog.SetSamplesValue(_i64toa(vValue, vTemp, 10)); oFileName = static_cast<const char*>(EMCommandRepository::Instance() -> ExecuteCommand(MEDIA_INFO_COMMAND_GET_ENTRY_FILENAME, &vEntryID)); //Full path to copied file oFileName.erase(0, oFileName.find_last_of('\\') + 1); //oFileName.erase(oFileName.find_last_of('.')); m_oVideoDialog.SetFileValue(oFileName); m_oVideoDialog.SetDimentionValue(static_cast<const char*>(opRepository -> ExecuteCommand(MEDIA_INFO_COMMAND_GET_VIDEO_DIMENSION, &vEntryID))); vValue = *static_cast<int64*>(opRepository -> ExecuteCommand(MEDIA_INFO_COMMAND_GET_ENTRY_DURATION, &vEntryID)); m_oVideoDialog.SetFileLengthValue(opGUIUtilities -> GetTimeString(vValue, EM_SMPTE)); vValue = *static_cast<int64*>(opRepository -> ExecuteCommand(MEDIA_INFO_COMMAND_GET_CLIP_MARK_IN, &vClipID)); m_oVideoDialog.SetMarkInValue(opGUIUtilities -> GetTimeString(vValue, EM_SMPTE)); vValue = *static_cast<int64*>(opRepository -> ExecuteCommand(MEDIA_INFO_COMMAND_GET_CLIP_MARK_OUT, &vClipID)); m_oVideoDialog.SetMarkOutValue(opGUIUtilities -> GetTimeString(vValue, EM_SMPTE)); m_oVideoDialog.Init(vX, vY, VIDEO); CalculatePosition(vX, vY, opClip, opTrack -> GetTrackInfo(), &m_oVideoDialog); m_oVideoDialog.MoveDialog(vX, vY); m_oVideoDialog.DisplayDialog(); break; case EM_TYPE_TRANSITION: vClipID = opClip ->GetMediaClipID(); // vEntryID = *static_cast<int32*>(opRepository -> ExecuteCommand(MEDIA_INFO_COMMAND_GET_CLIP_ENTRY_ID, &vClipID, NULL, NULL)); m_oTransitionDialog.SetNameValue(opClip -> GetLabel()); m_oTransitionDialog.SetTypeValue("Transition"); m_oTransitionDialog.SetBeginValue(opGUIUtilities -> GetTimeString(opClip -> GetPosition(), EM_SMPTE)); m_oTransitionDialog.SetEndValue(opGUIUtilities -> GetTimeString(opClip -> GetPosition() + opClip -> GetLength(), EM_SMPTE)); m_oTransitionDialog.SetDurationValue(opGUIUtilities -> GetTimeString(opClip -> GetLength(), EM_SMPTE)); m_oTransitionDialog.Init(vX, vY, TRANSITION); CalculatePosition(vX, vY, opClip, opTrack -> GetTrackInfo(), &m_oTransitionDialog); m_oTransitionDialog.MoveDialog(vX, vY); m_oTransitionDialog.DisplayDialog(); break; } vX = 0; vY = 0; oClipIterator++; } }
void CAM_Render(CEntity *pen, CDrawPort *pdp) { if( cam_bRecord) { if (!_bInitialized) { _bInitialized = TRUE; SetSpeed(1.0f); _fStartTime = _pTimer->CurrentTick(); } FLOATmatrix3D m; MakeRotationMatrixFast(m, _cp.cp_aRot); FLOAT3D vX, vY, vZ; vX(1) = m(1,1); vX(2) = m(2,1); vX(3) = m(3,1); vY(1) = m(1,2); vY(2) = m(2,2); vY(3) = m(3,2); vZ(1) = m(1,3); vZ(2) = m(2,3); vZ(3) = m(3,3); _cp.cp_aRot(1)-=_pInput->GetAxisValue(MOUSE_X_AXIS)*0.5f; _cp.cp_aRot(2)-=_pInput->GetAxisValue(MOUSE_Y_AXIS)*0.5f; if( cam_bMoveForward) { _cp.cp_vPos -= vZ *cam_fSpeed; }; if( cam_bMoveBackward) { _cp.cp_vPos += vZ *cam_fSpeed; }; if( cam_bMoveLeft) { _cp.cp_vPos -= vX *cam_fSpeed; }; if( cam_bMoveRight) { _cp.cp_vPos += vX *cam_fSpeed; }; if( cam_bMoveUp) { _cp.cp_vPos += vY *cam_fSpeed; }; if( cam_bMoveDown) { _cp.cp_vPos -= vY *cam_fSpeed; }; if( cam_bTurnBankingLeft) { _cp.cp_aRot(3) += 10.0f; }; if( cam_bTurnBankingRight) { _cp.cp_aRot(3) -= 10.0f; }; if( cam_bZoomIn) { _cp.cp_aFOV -= 1.0f; }; if( cam_bZoomOut) { _cp.cp_aFOV += 1.0f; }; if( cam_bZoomDefault) { _cp.cp_aFOV = 90.0f; }; Clamp( _cp.cp_aFOV, 10.0f, 150.0f); if( cam_bResetToPlayer) { _cp.cp_vPos = pen->GetPlacement().pl_PositionVector; _cp.cp_aRot = pen->GetPlacement().pl_OrientationAngle; } if( cam_bSnapshot) { cam_bSnapshot = FALSE; WritePos(_cp); } } else { if (!_bInitialized) { _bInitialized = TRUE; ReadPos(_cp0); ReadPos(_cp1); SetSpeed(_cp0.cp_fSpeed); _fStartTime = _pTimer->CurrentTick(); } TIME tmNow = _pTimer->GetLerpedCurrentTick()-_fStartTime; if (tmNow>_cp1.cp_tmTick) { _cp0 = _cp1; ReadPos(_cp1); SetSpeed(_cp0.cp_fSpeed); } FLOAT fRatio = (tmNow-_cp0.cp_tmTick)/(_cp1.cp_tmTick-_cp0.cp_tmTick); _cp.cp_vPos = Lerp(_cp0.cp_vPos, _cp1.cp_vPos, fRatio); _cp.cp_aRot = Lerp(_cp0.cp_aRot, _cp1.cp_aRot, fRatio); _cp.cp_aFOV = Lerp(_cp0.cp_aFOV, _cp1.cp_aFOV, fRatio); } CPlacement3D plCamera; plCamera.pl_PositionVector = _cp.cp_vPos; plCamera.pl_OrientationAngle = _cp.cp_aRot; // init projection parameters CPerspectiveProjection3D prPerspectiveProjection; prPerspectiveProjection.FOVL() = _cp.cp_aFOV; prPerspectiveProjection.ScreenBBoxL() = FLOATaabbox2D( FLOAT2D(0.0f, 0.0f), FLOAT2D((float)pdp->GetWidth(), (float)pdp->GetHeight()) ); prPerspectiveProjection.AspectRatioL() = 1.0f; prPerspectiveProjection.FrontClipDistanceL() = 0.3f; CAnyProjection3D prProjection; prProjection = prPerspectiveProjection; // set up viewer position prProjection->ViewerPlacementL() = plCamera; // render the view RenderView(*pen->en_pwoWorld, *(CEntity*)NULL, prProjection, *pdp); }