unsigned int Camera::Initialize() { m_viewMatrix = glm::mat4(); m_projMatrix = glm::mat4(); m_viewProjMatrix = glm::mat4(); m_position = glm::vec3(0.0f, 0.0f, 10.0f); m_target = glm::vec3(); m_up = glm::vec3(0.0f, 1.0f, 0.0f); m_direction = glm::vec3(); m_right = glm::vec3(); m_windowWidth = CSSET_WINDOW_WIDTH_DEFAULT; m_windowHeight = CSSET_WINDOW_HEIGHT_DEFAULT; // now try to read real values Engine* engine = System::GetInstance()->GetEngineData(); m_windowWidth = (float)engine->width; m_windowHeight = (float)engine->height; CalculateProjection(); CalculateViewProjection(); return CS_ERR_NONE; }
float CameraProjections::ComputeError(vector<OptimizorParam> &d) { double totalDis = 0; double maxDis = -9999999; int worseCoef = 3; int totalCount = 0; for (size_t i = 0; i < params.camCalibrator.opticalAngle.size(); i++) { cameraLocation = params.camCalibrator.cameraLocation[i]; cameraOrintation = params.camCalibrator.opticalAngle[i] + Point3d(d[0].data, d[1].data, d[2].data); diagnalAngleView = d[3].data; CalculateProjection(); Point2f res; if (GetOnRealCordinate(params.camCalibrator.clicked[i], res)) { double t = Distance2point(res, params.camCalibrator.rvizClicked[i]); totalDis += t; maxDis = std::max(maxDis, t); totalCount++; } else { return 10000000000; } } return (totalDis + (maxDis * worseCoef)) / (totalCount + worseCoef); }
/** Project average coords along eigenvectors */ int Analysis_Modes::ProjectCoords(DataSet_Modes const& modes) { double scale = factor_; int max_it = (int)(pcmax_ - pcmin_); // Check that size of eigenvectors match # coords int ncoord = tOutParm_->Natom() * 3; if (ncoord != modes.NavgCrd()) { mprinterr("Error: # selected coords (%i) != eigenvector size (%i)\n", ncoord, modes.NavgCrd()); return 1; } // Check that mode is valid. if (tMode_ < 1 || tMode_ > modes.Nmodes() ) { mprinterr("Error: mode %i is out of bounds.\n", tMode_); return Analysis::ERR; } // Setup frame to hold output coords, initalized to avg coords. Frame outframe; outframe.SetupFrameXM( modes.AvgCrd(), modes.Mass() ); // Point to correct eigenvector const double* Vec = modes.Eigenvector(tMode_-1); // Initialize coords to pcmin for (int idx = 0; idx < ncoord; idx++) outframe[idx] += pcmin_ * Vec[idx]; if (debug_>0) CalculateProjection(0, outframe, tMode_-1); if (trajout_.SetupTrajWrite( tOutParm_, CoordinateInfo(), max_it )) { mprinterr("Error: Could not open output modes traj '%s'\n", trajout_.Traj().Filename().full()); return 1; } // Write first frame with coords at pcmin. int set = 0; trajout_.WriteSingle(set++, outframe); // Main loop for (int it = 0; it < max_it; it++) { double* crd = outframe.xAddress(); // Move coordinates along eigenvector. for (int idx = 0; idx < ncoord; ++idx) crd[idx] += scale * Vec[idx]; if (debug_>0) CalculateProjection(set, outframe, tMode_-1); // DEBUG: calc PC projection for first 3 modes //for (int m = 0; m < 3; m++) // CalculateProjection(set, outframe, m); // Write frame trajout_.WriteSingle(set++, outframe); } trajout_.EndTraj(); return 0; }
void Camera::FlushDimensions() { Engine* engine = System::GetInstance()->GetEngineData(); m_windowWidth = (float)engine->width; m_windowHeight = (float)engine->height; CalculateProjection(); CalculateViewProjection(); }
Camera::Camera(GameObject* gameObject) : Component(gameObject) { Init(); CalculateView(); CalculateProjection(); }
// Constructor _Camera::_Camera(float Fov, float AspectRatio, float Near, float Far) : Fov(Fov), AspectRatio(AspectRatio), Near(Near), Far(Far), Type(THIRD_PERSON), Yaw(0.0f), Pitch(0.0f), Distance(5.0f), MinDistance(0.1f), PitchLimit(glm::radians(89.0f)), LookAt(glm::vec3(0.0f, 0.0f, 0.0f)), Up(glm::vec3(0.0f, 1.0f, 0.0f)), Position(glm::vec3(0.0f, 0.0f, 5.0f)), LastPosition(Position), InterpolatedPosition(Position) { CalculateProjection(); CalculateView(); CalculateTransform(); }
void CCameraInstance::LookAt(SFloat3* psFrom, SFloat3* psTo, SFloat3* psUp) { Float4x4LookAtRH(&mpsView->sD3DMatrix, psFrom, psTo, psUp); Float4x4Inverse(&mpsWorld->sD3DMatrix, NULL, &mpsView->sD3DMatrix); //Remove this? CalculateView(); CalculateProjection(); }
void MyCameraSingleton::SetTarget(vector3 a_v3Target) { m_v3Target = a_v3Target; m_v3Forward = glm::normalize(m_v3Target - m_v3Position); m_v3Upward = glm::normalize(glm::cross(m_v3Rightward, m_v3Forward)); m_v3Rightward = glm::normalize(glm::cross(m_v3Forward, m_v3Upward)); m_v3Top = m_v3Position + m_v3Upward; m_v3Target = m_v3Position + glm::normalize(m_v3Forward); CalculateProjection(); }
void MyCameraSingleton::MoveSideways(float a_fDistance) { m_v3Position += m_v3Rightward * a_fDistance; m_v3Target += m_v3Rightward * a_fDistance; m_v3Top += m_v3Rightward * a_fDistance; m_v3Forward = glm::normalize(m_v3Target - m_v3Position); m_v3Upward = glm::normalize(m_v3Top - m_v3Position); m_v3Rightward = glm::normalize(glm::cross(m_v3Forward, m_v3Upward)); if (m_nMode != CAMERAMODE::CAMPERSP) { CalculateProjection(); } }
BOOL CCameraInstance::Use(void) { //It's allowable to have a NULL surface... the render target won't be changed. if (mpsSurface != NULL) { gcD3D.SetRenderTarget(mpsSurface); } //Do this every frame... not a problem on todays hardware. CalculateView(); CalculateProjection(); return gcD3D.SetCamera(mpsProjection, mpsView); }
unsigned int Camera::Update() { if (m_projDirty) { CalculateProjection(); m_projDirty = false; } if (m_viewDirty) { CalculateViewProjection(); m_viewDirty = false; } return CS_ERR_NONE; }
void Camera::Init() { m_Transform = _gameObject->GetTransform(); m_bOrthogonal = false; m_b6DoF = false; m_v3Up = glm::vec3(0, 1.0f, 0); m_v3Forward = glm::vec3(-1.0f, 0, 0); m_fFOVy = 45.0f; m_fAspectRatio = static_cast<float>( GameWindow::GetCurrentWindow()->GetWidth() ) / GameWindow::GetCurrentWindow()->GetHeight(); m_fMinPlane = 0.001f; m_fMaxPlane = 1024.0f; m_fHeight = static_cast<float>( GameWindow::GetCurrentWindow()->GetHeight() ); CalculateDirectionVectors(); CalculateView(); CalculateProjection(); }
void CameraProjections::Calibrate() { if (params.camCalibrator.IsReady()) { if (params.topView.calibrateKinematic->get()) { ROS_INFO("Calibration Started!"); calibrating = true; initialParameters.clear(); initialParameters.push_back( OptimizorParam(params.orientation.x->get())); initialParameters.push_back( OptimizorParam(params.orientation.y->get())); initialParameters.push_back( OptimizorParam(params.orientation.z->get())); initialParameters.push_back( OptimizorParam(params.camera.diagonalAngleView->get(), 0.05)); optimizer.setParameters(initialParameters); if (!optimizer.TuneForBest(50, 0.0000001)) { ROS_WARN("Not complete success in converging"); } vector<OptimizorParam> p = optimizer.getParameters(); params.orientation.x->set(p[0].data); params.orientation.y->set(p[1].data); params.orientation.z->set(p[2].data); params.camera.diagonalAngleView->set(p[3].data); params.topView.calibrateKinematic->set(false); Update(); CalculateProjection(); calibrating = false; ROS_INFO("Calibration Finished!"); } } }
//The big 3 MyCameraSingleton::MyCameraSingleton() { Init(); CalculateProjection(); }
matrix4 MyCameraSingleton::GetVP(void) { CalculateView(); CalculateProjection(); return m_m4Projection * m_m4View; }
matrix4 MyCameraSingleton::GetMVP(matrix4 a_m4ModelToWorld) { CalculateView(); CalculateProjection(); return m_m4Projection * m_m4View * a_m4ModelToWorld; }
matrix4 MyCameraSingleton::GetProjectionMatrix(void){ CalculateProjection(); return m_m4Projection; }