Example #1
0
void Perspective::updateProjectionMatrix(GLint width, GLint height)
{    
    float aspect= (float)width / (float)height;
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
    gluPerspective(angle, aspect, getZNear(), getZFar());
}
void TCompCamera::renderInMenu() {
	float fov_in_rad = getFov();
	float znear = getZNear();
	float zfar = getZFar();
	float ar = getAspectRatio();

	bool changed = false;
	//float fov_in_deg = rad2deg(fov_in_rad);
	//if (ImGui::SliderFloat("Fov", &fov_in_deg, 30.f, 110.f)) {
	//	changed = true;
	//	fov_in_rad = deg2rad(fov_in_deg);
	//}
	if (!isOrtho()) {
		float fov_in_deg = rad2deg(fov_in_rad);
		if (ImGui::DragFloat("Fov", &fov_in_deg, 0.1f, 1.f, 120.f)) {
			changed = true;
			fov_in_rad = deg2rad(clamp(fov_in_deg, 1.f, 120.f));
		}
	}
	changed |= ImGui::DragFloat("ZNear", &znear, 0.01f, 0.01f);
	changed |= ImGui::DragFloat("ZFar", &zfar, 0.01f, 1.f, 1000.f);
	if (changed)
		setProjection(fov_in_rad, znear, zfar);

	if (ImGui::SliderFloat("a/r", &ar, 0.f, 10.f)) {
		//setAspectRatio(ar);
	}
}
Example #3
0
void Viewer::run() {
    m_GUI.loadSettings(*m_Settings.m_pCacheRoot);

    setUp();

    m_nFrameID = 0;
    while (m_WindowManager.isOpen()) {
        auto startTime = m_WindowManager.getSeconds();

        m_WindowManager.handleEvents();

        m_GUI.startFrame();

        m_Camera.exposeIO(m_GUI);
        exposeConfigIO();
        exposeLightsIO();

        m_ViewController.setViewMatrix(m_Camera.getViewMatrix());

        drawFrame();

        auto size = m_WindowManager.getSize();
        glViewport(0, 0, (int)size.x, (int)size.y);
        m_bGUIHasFocus = m_GUI.draw();

        m_WindowManager.swapBuffers();

        if (!m_bGUIHasFocus) {
            float ellapsedTime = float(m_WindowManager.getSeconds() - startTime);
            if(m_ViewController.update(ellapsedTime)) {
                m_Camera = ProjectiveCamera(m_ViewController.getViewMatrix(), m_Camera.getFovY(),
                                            m_Settings.m_FramebufferSize.x, m_Settings.m_FramebufferSize.y,
                                            getZNear(), getZFar());
                m_CameraUpdateFlag.addUpdate();
            }
        }

        ++m_nFrameID;
    }

    tearDown();

    m_RenderModule.tearDown(m_Settings.m_pCacheRoot);
    storeCamera();

    if(m_nCurrentConfig < m_ConfigManager.getConfigs().size()) {
        // Store current config
        auto pConfig = m_Settings.m_pCacheRoot->FirstChildElement("Config");
        if(!pConfig) {
            pConfig = m_Settings.m_CacheDocument.NewElement("Config");
            m_Settings.m_pCacheRoot->InsertEndChild(pConfig);
        }
        setAttribute(*pConfig, "name", m_ConfigManager.getConfigName(m_nCurrentConfig));
    }

    m_GUI.storeSettings(*m_Settings.m_pCacheRoot);

    m_Settings.m_CacheDocument.SaveFile(m_Settings.m_CacheFilePath.c_str());
}
Example #4
0
/**************************************
Debug Function.
***************************************/
void Camera::debug(){
    system("clear");
    cout << " Eye:    " << getEyeX() << "  " << getEyeY() << "  " << getEyeZ() << endl;
    cout << " Center: " << getCenterX() << "  " << getCenterY() << "  " << getCenterZ() << endl;
    cout << " Up:     " << getUpX() << "  " << getUpY() << "  " << getUpZ() << endl;
    cout << endl;
    cout << " Perspective: " << getFovy() << "  " << getAspect() << "  " << getZNear() << "  " << getZFar() << endl;
}
Example #5
0
void Camera::print()
{
    cout << "- Camera - Base" << endl;
    cout << "| ID: " << getID() << endl;
    cout << "| ids: " << getIds() << endl;
    cout << "| near: " << getZNear() << endl;
    cout << "| far: " << getZFar() << endl;
}
Example #6
0
void Perspective::print()
{
    cout << "- Camera - Perspective" << endl;
    cout << "| ID: " << getID() << endl;
    cout << "| ids: " << getIds() << endl;
    cout << "| pos: {" << getPos()[0] << ", "<< getPos()[1]<< ", " << getPos()[2] << "}" << endl;
    cout << "| near: " << getZNear() << endl;
    cout << "| far: " << getZFar() << endl;
    cout << "| angle: " << getAngle() << endl;
    cout << "| target: {" << getTarget()[0] << ", "<< getTarget()[1] << ", " << getTarget()[2] << "}" << endl;
}
void CameraOrthographicImp::getProjectionMatrix44( float * returnMatrix44, bool bRightHand, bool bRowMajor )
{
    float columnMajor[16];

    columnMajor[ 1 ] = columnMajor[ 2 ] = columnMajor[ 3 ]
    = columnMajor[ 4 ] = columnMajor[ 6 ] = columnMajor[ 7 ]
    = columnMajor[ 8 ] = columnMajor[ 9 ] = columnMajor[ 11 ]
    = columnMajor[ 12 ] = columnMajor[ 13 ] = 0.f;

    columnMajor[ 0 ] = 2.f / getXMag();
    columnMajor[ 5 ] = 2.f / getYMag();
    columnMajor[ 15 ] = 1.f;

    if( bRightHand ) {
        columnMajor[ 10 ] = 1.f / ( getZNear() - getZFar() );
        columnMajor[ 14 ] = getZNear() / ( getZNear() - getZFar() );

    } else {
        columnMajor[ 10 ] = 1.f / ( getZFar() - getZNear() );
        columnMajor[ 14 ] = -getZNear() / ( getZFar() - getZNear() );
 
    }

    memcpy( returnMatrix44, columnMajor, sizeof( columnMajor ) );
    
    if( bRowMajor ) {
        returnMatrix44[ 11 ] = columnMajor[ 14 ];
        returnMatrix44[ 14 ] = columnMajor[ 11 ];
    }
}
Example #8
0
void Camera::sethFovy( const FovyValueType fovy)
{
	Camera::AspectValueType aspect;
	Camera::ZNearValueType zNear;
	Camera::ZFarValueType zFar;

	setFovy( fovy );

	if ( getAspect( aspect ) && getZNear( zNear ) && getZFar( zFar ) )
	{
		vgm::MatrixR matrix;
		matrix.setPerspective( fovy, aspect, zNear, zFar );
		setProjection( matrix );
	}
	else
	{
		vgAssertN( false, "sethFovy() called before zNear, zFar and aspect have been initialized.");
	}
}
Example #9
0
void	Camera :: apply ()
{
	float		m [16];
													// create a coordinate space transform
													// (rotation) matrix
	m [0 ] = sideDir.x;
	m [1 ] = upDir.x;
	m [2 ] = -viewDir.x;
	m [3 ] = 0;

	m [4 ] = sideDir.y;
	m [5 ] = upDir.y;
	m [6 ] = -viewDir.y;
	m [7 ] = 0;

	m [8 ] = sideDir.z;
	m [9 ] = upDir.z;
	m [10] = -viewDir.z;
	m [11] = 0;

	m [12] = 0;
	m [13] = 0;
	m [14] = 0;
	m [15] = 1;

														// set current viewport
	glViewport     ( 0, 0, getWidth (), getHeight () );

	glMatrixMode   ( GL_PROJECTION );					// select projection matrix
	glLoadIdentity ();									// reset projection matrix

														// calculate aspect ratio of the window
	gluPerspective ( getFov (), getAspect (), getZNear (), getZFar () );

	glMatrixMode   ( GL_MODELVIEW );					// select modelview matrix
	glLoadIdentity ();									// reset modelview matrix

	glMultMatrixf ( m );
	glTranslatef  ( -pos.x, -pos.y, -pos.z );
	
	glGetFloatv ( GL_PROJECTION_MATRIX, proj );
}
void TCompLightDirShadowsDynamic::setNewFov(float fov_in_rads) {
	float fov_in_degs = rad2deg(fov_in_rads);
	setProjection(fov_in_rads, getZNear(), getZFar());
}
Example #11
0
/***************************************
****************************************
Others and the most importants functions
****************************************
****************************************/
void Camera::setPerspective(){
    glEnable(GL_DEPTH_TEST);
    glMatrixMode(GL_PROJECTION);
    gluPerspective(getFovy(),getAspect(),getZNear(),getZFar());
    glutSetCursor(GLUT_CURSOR_NONE);
}