Ejemplo n.º 1
0
void GLLogic::Init(void(*updateCallback)(int))
{
	//param
	m_updateCallback = updateCallback;

	//glut 
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	glutInitWindowSize(800, 600);
	glutInitWindowPosition(0, 0);
	glutCreateWindow("Rotating Planets");

	//cleaer
	glClearColor(0.f, 0.f, 0.f, 1.f);

	//culling
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
	glFrontFace(GL_CCW);

	//lighting
	InitLighting();

	//textures
	glEnable(GL_TEXTURE_2D);
	m_texIds[EARTH_IDX] = LoadTexture("Resources/earth.png");
	m_texIds[VENUS_IDX] = LoadTexture("Resources/venus.png");
	m_texIds[SILVA_IDX] = LoadTexture("Resources/silva.png");

	//planets
	for (int i = 0; i < PLANET_NUM; i++)
	{
		m_planets[i] = gluNewQuadric();
	}
}
Ejemplo n.º 2
0
void init()
{
    glClearColor(0,0,0,0);
    glShadeModel(GL_FLAT);

    s_transX = s_transY = 0.0;
    s_rotX = s_rotY = 0.0;
    s_focalDistance = 5;

    InitLighting();
}
Ejemplo n.º 3
0
void OGL3DBase::SetStereoView(bool leftSide)
{
    //  clear any clip planes
    ClearClipPlanes();

    double eyeMult = 1.0 / (plot3Dbase.eyeSeparationDivisor * 2.0);
    if (leftSide)
    {
        glDrawBuffer(GL_BACK_LEFT);
        PerspectiveSetup(eyeMult);
    }
    else
    {
        glDrawBuffer(GL_BACK_RIGHT);
        PerspectiveSetup(-eyeMult);
    }
    ClearBuffer();

    InitLighting();
    inAnnoView = false;
}
Ejemplo n.º 4
0
void MainWindowWrapper::SimuReshape(int width,  int height)
{
	glutPositionWindow(m_params.simu_window.x, m_params.simu_window.y);
	glutReshapeWindow(m_params.simu_window.w, m_params.simu_window.h);

	glViewport(0,0, m_params.simu_window.w, m_params.simu_window.h);

	//this should rely on the map not the window
	double y_max = sqrt(pow(m_params.simu_window.w,2) + pow(m_params.simu_window.h,2))/2.0;
	if(y_max > 0.05 && y_max < (m_params.simu_window.w*m_params.simu_window.h))
		m_DisplayParam.prespective_z = y_max;

	m_DisplayParam.prespective_z = 10000;

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	double aspect_ratio = (double)m_params.simu_window.w/(double)m_params.simu_window.h;

	gluPerspective(m_DisplayParam.prespective_fov,aspect_ratio,0.05,m_DisplayParam.prespective_z);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	if(m_DisplayParam.bDisplayMode == DISPLAY_FOLLOW && m_DrawAndControl)
	{
		m_DisplayParam.eye[0] = m_DisplayParam.centerRotX;
		m_DisplayParam.eye[1] = m_DisplayParam.centerRotY;
		m_DisplayParam.at[0] = m_DisplayParam.centerRotX;
		m_DisplayParam.at[1] = m_DisplayParam.centerRotY;
	}


	gluLookAt(m_DisplayParam.eye[0], m_DisplayParam.eye[1], m_DisplayParam.zoom,
			m_DisplayParam.at[0], m_DisplayParam.at[1], m_DisplayParam.at[2],
			m_DisplayParam.up[0], m_DisplayParam.up[1],m_DisplayParam.up[2]);

	InitLighting();

}
Ejemplo n.º 5
0
void OGL3DBase::InitView()
{
    viewIsStereo = false;
    ViewSetup();

    //  clear any clip planes
    ClearClipPlanes();

    int width, height;
    plotBase.CalcAvailablePixels(width, height);

    //  set projection
    if (plot3Dbase.ProjectionIsOrtho())
    {
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();

        double aspect = double(width)/ double(height);

        double maxMap = sqrt(xOrthoSpan * xOrthoSpan + yOrthoSpan * yOrthoSpan + zOrthoSpan * zOrthoSpan) / 2.0;
        double maxZrange = -maxMap * currView.scale * 2.0;
        if (aspect > 1.0)
            glOrtho(-maxMap * aspect, maxMap * aspect, -maxMap, maxMap, maxZrange * 2.0, 0.0);
        else
            glOrtho(-maxMap, maxMap, -maxMap / aspect, maxMap / aspect, maxZrange * 2.0, 0.0);

            //  set initial translation/rotation
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

        //  shift into z range
        glTranslated(0.0, 0.0, - maxZrange);

        //  attitude sliders
        //  scale
        glScaled(currView.scale, currView.scale, currView.scale);
        //  rotation around azimuth
        glRotated(currView.elevation -90.0, 1.0, 0.0, 0.0);
        //  azimuth around Z
        glRotated(currView.azimuth, 0.0, 0.0, 1.0);
        //  shift centre
        glTranslated(currView.translation.cX, currView.translation.cY, currView.translation.cZ);

        // scale for normalizations
        glScaled(xOrthoSpan / normSpan.cX, yOrthoSpan / normSpan.cY, zOrthoSpan / normSpan.cZ);

        // translate again for normalizations
        glTranslated(-normMid.cX, -normMid.cY, -normMid.cZ);

    }
    else
    {
        PerspectiveSetup(0.0);
    }

    glViewport(plotBase.plotUOffset + plotBase.leftMargin,
               plotBase.plotVOffset + plotBase.bottomMargin, width, height);
    //set scissors for clear
    ScissorSetup();
    // required for composite plots
    HardCopySetViewport();

    // clear viewport
    Clear();

    InitLighting();
    inAnnoView = false;

}