Пример #1
0
void drawScene3D()
{
    // setup projection
    #ifdef TEST_PROJECTION_MORPHING
    updateProjection();
    #endif

    glMatrixMode(GL_PROJECTION);
    auto proj = projection.ToMatrix4();
    glLoadMatrix_T(proj.Ptr());

    // update view matrix
    glMatrixMode(GL_MODELVIEW);
    viewMatrix = cameraTransform.GetMatrix().Inverse();

    // update view frustum
    updateFrustum();

    // draw models
    for (const auto& mdl : models)
    {
        drawModel(mdl);
        drawAABB(mdl.mesh.BoundingBox(mdl.transform.GetMatrix()));
    }
}
Пример #2
0
void initGL()
{
    // setup GL configuration
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_NORMALIZE);
    glEnable(GL_LIGHT0);
    glEnable(GL_CULL_FACE);

    #if 0
    glCullFace(GL_FRONT);
    #else
    glCullFace(GL_BACK);
    glFrontFace(GL_CW);
    #endif

    #ifdef ENABLE_PRESENTATION
    glClearColor(0, 1, 0, 1);
    #else
    glClearColor(0, 0, 0, 1);
    #endif

    glPixelStorei(GL_PACK_ALIGNMENT, 1);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    // setup lighting
    GLfloat lightPos[]  = { 0.0f, 0.0f, -1.0f, 0.0f };
    
    glLightfv(GL_LIGHT0, GL_POSITION, lightPos);

    // initialize projection
    updateProjection();
}
Пример #3
0
void keyboardCallback(unsigned char key, int x, int y)
{
    switch (key)
    {
        case 27: // ESC
            quitApp();
            break;

        case '\t': // TAB
            wireframeMode = !wireframeMode;
            break;

        case '\r': // ENTER
            orthoProj = !orthoProj;
            updateProjection();
            break;

        case ' ': // SPACE
            showBox = !showBox;
            break;

        default:
            if (key >= '1' && key <= '9')
                showModel(static_cast<size_t>(key - '1'));
            break;
    }
}
Пример #4
0
VizCoordinateSystem *VizProjection::insertPile(IsCsResult csAt, int dimensionality) {
  VizCoordinateSystem *vcs = createCoordinateSystem(dimensionality);
  m_coordinateSystems.insert(std::next(std::begin(m_coordinateSystems), csAt.pileIdx()),
                             std::vector<VizCoordinateSystem *> {vcs});
  updateProjection();
  return vcs;
}
Пример #5
0
void VizProjection::ensureFitsHorizontally(VizCoordinateSystem *coordinateSystem, int minimum, int maximum) {
  size_t column = static_cast<size_t>(-1);
  int columnMin;
  int columnMax;
  for (size_t col = 0, col_end = m_coordinateSystems.size(); col < col_end; col++) {
    std::vector<VizCoordinateSystem *> pile = m_coordinateSystems.at(col);
    columnMin = INT_MAX;
    columnMax = INT_MIN;
    for (size_t row = 0, row_end = pile.size(); row < row_end; row++) {
      int hmin, hmax, vmin, vmax;
      VizCoordinateSystem *cs = pile.at(row);
      cs->minMax(hmin, hmax, vmin, vmax);
      if (cs == coordinateSystem) {
        column = col;
      }
      columnMin = std::min(columnMin, hmin);
      columnMax = std::max(columnMax, hmax);
    }
    // Found, no further iteration needed.
    if (column == col) {
      break;
    }
  }
  CLINT_ASSERT(column != static_cast<size_t>(-1), "Polyhedron not found in the coordinate system");

  columnMin = std::min(columnMin, minimum);
  columnMax = std::max(columnMax, maximum);

  std::vector<VizCoordinateSystem *> pile = m_coordinateSystems.at(column);
  for (size_t row = 0, row_end = pile.size(); row < row_end; row++) {
    VizCoordinateSystem *cs = pile.at(row);
    cs->setHorizontalMinMax(columnMin, columnMax);
  }
  updateProjection();
}
Пример #6
0
// Inits parameters for the camera
void Camera::init()
{
    // View Data
    // Camera position and orientation
    this->c[0]=0.0;  this->c[1]=0.0; this->c[2]=1.0; // Camera position    
    this->x[0]=1.0;  this->x[1]=0.0; this->x[2]=0.0; normalize(this->x); // x axis
    this->y[0]=0.0;  this->y[1]=1.0; this->y[2]=0.0; normalize(this->y); // y axis
    this->z[0]=0.0;  this->z[1]=0.0; this->z[2]=1.0; normalize(this->z); // z axis
    setToIdentity(this->view);
    this->updateView();
    
    // Projection data
    // Projection type : perspective:true / orthographic:false
    this->perspectiveProjection=false;
    // Projection frustum data
    GLfloat l=1.0;
    this->left=-l; 
    this->right=l;
    this->bottom=-l;
    this->top=l; 
    this->near=0.4;/*0.1 à l'origine*/
    this->far=100;/*100 à l'origine*/
    setToIdentity(this->projection);
    updateProjection();
}
Пример #7
0
Matrix4 Camera::getProjection()
{
	if (projectionDirty_)
		updateProjection();

	return projection_;
}
Пример #8
0
void initialize()
{
	hasSavePoint = false;
	if (currLevel == 0){
		//glutSetCursor(GLUT_CURSOR_NONE);
		setMouse(win1.width / 2, win1.height / 2);
		updateProjection(win1);
	}
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glClearColor(0.0, 0.0, 0.0, 1.0);											// specify clear values for the color buffers	
	loadImages();
	levels[currLevel] = new Level(currLevel + 1);
	Stamina = 100;
	makeEntites();
	levelEdges = levels[currLevel]->getEdges();
	
	camera1 = new Camera(Vector3(levels[currLevel]->startPoint->x, 2, levels[currLevel]->startPoint->y), findPosition(levels[currLevel]), Vector3(0, 1, 0));
	if (levels[currLevel]->startNode->left || levels[currLevel]->startNode->right){
		cylinder1.yaw(90);
	}
	startPlayer = cylinder1;
	resetEnemies();
	sound = new Sound();
	sound->Load();
	sound->Play(SOUND_MUSIC1);
	
}
Пример #9
0
void initGL()
{
    // setup GL configuration
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_NORMALIZE);
    glEnable(GL_COLOR_MATERIAL);
    glEnable(GL_CULL_FACE);

    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

    // initialize projection
    updateProjection();

    // create model
    Gm::MeshGenerator::CuboidDescriptor mdlDesc;

    #ifdef TEST_BLOATED_CUBE

    mdlDesc.segments = { 5, 5, 5 };
    mdlDesc.size = { 1, 1, 1 };
    auto mdl = createCuboidModel(mdlDesc);

    for (auto& v : mdl->mesh.vertices)
        v.position = Gs::Lerp(v.position, v.position.Normalized(), 0.5f);

    #else

    mdlDesc.segments = { 1, 2, 3 };
    mdlDesc.size = { 1, 1.5f, 0.5f };
    auto mdl = createCuboidModel(mdlDesc);

    #endif

    mdl->transform.SetPosition({ 0, 0, -2 });
}
Пример #10
0
    bool Director::drawScene()
    {   
        // CALCULATE DELTA TIME
        calculateDeltaTime();

        // DISPATCH EVENTS
        EventManager::Instance().dispatchEvents();
        
        // SCHEDULE
        if(!m_isPaused) {
            Scheduler::Instance().tick( m_dt );
            ActionManager::Instance().update( m_dt );
        }
        
        if(m_dirtyFlags)
            updateProjection();

        if(p_nextScene)
            setNextScene();
        

        // RENDERING
#if FZ_RENDER_ON_DEMAND
        bool newContent = m_sceneIsDirty;
        if(m_sceneIsDirty) {
#endif
            
#if !FZ_GL_SHADERS
            glLoadIdentity();
#endif
            MS::loadBaseMatrix(m_transformMV);
            
            // CLEAR OPENGL BUFFERS
            fzGLClearColor(m_clearColor);
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            
            if(p_runningScene) {
                p_runningScene->internalVisit();
                CHECK_GL_ERROR_DEBUG();
            }
            
            FZ_ASSERT(MS::getLevel() == 1, "A matrix hasn't been popped. Review the push/pop code.");
        
            // SHOW FPS
            if( m_displayFPS )
                showFPS();
            
#if FZ_RENDER_ON_DEMAND
            m_sceneIsDirty = false;
        }
#endif
        PerformManager::Instance().clean();
        
#if FZ_RENDER_ON_DEMAND
        return newContent;
#else
        return true;
#endif
    }
Пример #11
0
VizCoordinateSystem *VizProjection::insertCs(IsCsResult csAt, int dimensionality) {
  CLINT_ASSERT(csAt.pileIdx() < m_coordinateSystems.size(), "Inserting CS in a non-existent pile");
  VizCoordinateSystem *vcs = createCoordinateSystem(dimensionality);
  std::vector<VizCoordinateSystem *> &pile = m_coordinateSystems.at(csAt.pileIdx());
  pile.insert(std::next(std::begin(pile), csAt.coordinateSystemIdx()), vcs);
  updateProjection();
  return vcs;
}
Пример #12
0
CameraPerspective::CameraPerspective()
		:
				mProjectionFovy(glm::radians(90.0)),
				mProjectionAspectRatio(1.0),
				mProjectionNearPlane(0.01),
				mProjectionFarPlane(100.0) {
	updateProjection();
}
Пример #13
0
// Sets the perspective similarly to gluPerspective
void Camera::setPerspectiveFromAngle(float fovy, float aspectRatio)
{
    this->top=this->near*tan(fovy/2.0);
    this->bottom=-this->top;
    this->left=this->bottom*aspectRatio;
    this->right=this->top*aspectRatio;

    updateProjection();
}
Пример #14
0
void VizProjection::ensureFitsVertically(VizCoordinateSystem *coordinateSystem, int minimum, int maximum) {
  int hmin, hmax, vmin, vmax;
  coordinateSystem->minMax(hmin, hmax, vmin, vmax);
  vmin = std::min(vmin, minimum);
  vmax = std::max(vmax, maximum);
  coordinateSystem->setMinMax(hmin, hmax, vmin, vmax);

  updateProjection();
}
Пример #15
0
///// updateGLSettings ////////////////////////////////////////////////////////
void GLView::updateGLSettings()
/// Updates the OpenGL settings.
/// It is only called when an update is really needed (determined by
/// staticUpdateIndex != updateIndex).
{
  updateIndex = staticUpdateIndex;

  ///// light position, specular and shininess
  GLfloat lightPosition[] = {baseParameters.lightPositionX, baseParameters.lightPositionY, baseParameters.lightPositionZ, 0.0f};
  GLfloat materialSpecular[] = {baseParameters.materialSpecular/100.0f, baseParameters.materialSpecular/100.0f, baseParameters.materialSpecular/100.0f, 0.0f};
  GLfloat materialShininess[] = {baseParameters.materialShininess};

  glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); // set light position for directional light
  glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, materialSpecular);
  glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, materialShininess);

  ///// background color
  //qglClearColor(baseParameters.backgroundColor);
  qglClearColor(QColor(baseParameters.backgroundColor));

  ///// smooth shading
  if(baseParameters.smoothShading)
    glShadeModel(GL_SMOOTH);
  else
    glShadeModel(GL_FLAT);

  ///// antialiasing
  if(baseParameters.antialias)
  {
    //polygon antialiasing is way to slow.
    //glEnable(GL_BLEND);
    //glEnable(GL_POLYGON_SMOOTH);
    //glDisable(GL_DEPTH_TEST);
    // antialiasing for lines and points.
    glEnable(GL_LINE_SMOOTH);
    glEnable(GL_POINT_SMOOTH);
  }
  else
  {
    //glDisable(GL_BLEND);
    //glDisable(GL_POLYGON_SMOOTH);
    //glEnable(GL_DEPTH_TEST);
    glDisable(GL_LINE_SMOOTH);
    glDisable(GL_POINT_SMOOTH);
  }

  ///// depth-cueing
  if(baseParameters.depthCue)
    glEnable(GL_FOG);
  else
    glDisable(GL_FOG);

  updateProjection(); // pure virtual which takes care of a change in projection

  ///// update the projection
  resizeGL(width(), height());
}
Пример #16
0
void StereoCamera::initBourke(GLfloat fovyDeg, GLfloat near, GLfloat far,
    GLfloat screenDist, GLfloat interOcularFactor) {
  near_ = near;
  far_ = far;
  screenDist_ = screenDist;
  interOcularHalfDist_ = 0.5f * interOcularFactor * screenDist_;
  screenHalfHeight_ = screenDist_ * tan(0.5f * glm::radians(fovyDeg));
  updateProjection();
}
Пример #17
0
Camera::Camera()
{
    _position = QVector3D(0.0f, 0.0f, 1.0f);
    _aspect = 4.0f/3.0f;
    _zoom = 90.0f;

    updateView();
    updateProjection();
}
Пример #18
0
void StereoCamera::init(GLfloat near, GLfloat far,
    GLfloat screenDist, GLfloat screenHeight, GLfloat interOcularDist) {
  near_ = near;
  far_ = far;
  screenDist_ = screenDist;
  screenHalfHeight_ = 0.5f * screenHeight;
  interOcularHalfDist_ = 0.5f * interOcularDist;
  updateProjection();
}
Пример #19
0
			inline
			void
			left(float left)
			{
				if (left != _left)
				{
					_left = left;
					updateProjection(_left, _right, _top, _bottom, _zNear, _zFar);
				}
			}
Пример #20
0
			inline
			void
			top(float top)
			{
				if (top != _top)
				{
					_top = top;
					updateProjection(_left, _right, _top, _bottom, _zNear, _zFar);
				}
			}
Пример #21
0
			inline
			void
			bottom(float bottom)
			{
				if (bottom != _bottom)
				{
					_bottom = bottom;
					updateProjection(_left, _right, _top, _bottom, _zNear, _zFar);
				}
			}
Пример #22
0
			inline
			void
			right(float right)
			{
				if (right != _right)
				{
					_right = right;
					updateProjection(_left, _right, _top, _bottom, _zNear, _zFar);
				}
			}
Пример #23
0
			inline
			void
			zFar(float zFar)
			{
				if (zFar != _zFar)
				{
					_zFar = zFar;
					updateProjection(_left, _right, _top, _bottom, _zNear, _zFar);
				}
			}
Пример #24
0
			Camera::Camera(const std::string& iName, screen::core::Scene& iScene)
			: SceneNode(iName, iScene, NULL),
			  _fov(45.0f), _aspectRatio(4.0f/3.0f),
			  _near(0.1f), _far(100.0f), _projectionNeedsUpdate(true),
			  _viewNeedsUpdate(true)
			{
				SCREEN_DECL_CONSTRUCTOR(Camera);
				updateProjection();
				updateView();
			}
Пример #25
0
void reshapeCallback(GLsizei w, GLsizei h)
{
    resolution.x = w;
    resolution.y = h;

    glViewport(0, 0, w, h);

    updateProjection();

    displayCallback();
}
Пример #26
0
void reshapeCallback(GLsizei w, GLsizei h)
{
    resolution.x = w;
    resolution.y = h;

    glViewport(0, 0, w, h);

    #ifndef TEST_PROJECTION_MORPHING
    updateProjection();
    #endif

    displayCallback();
}
Пример #27
0
ScreenCamera::ScreenCamera(unsigned int width, unsigned int height)
{
    _frame = NULL;

    // setup viewport
    _viewPort.X = 0, _viewPort.Y = 0;
    _viewPort.Width  = width,
    _viewPort.Height = height;
    _viewPort.MinZ   = 0;
    _viewPort.MaxZ   = 1;
    _fov = 60.0f;
    updateProjection();
}
Пример #28
0
void Renderer::toggleFullScreen(SDL_Window* mainWindow)
{
    int w, h;
    if(!isFullScreen)
    {
        SDL_SetWindowFullscreen(mainWindow, SDL_WINDOW_FULLSCREEN_DESKTOP);
        updateProjection( glm::perspective(45.0f, 16.0f / 9.0f, 0.1f, 500.f) );
        SDL_GetWindowSize(mainWindow, &w, &h);
        printf("Going fullscreen: %ix%i\n", w, h);
        glViewport(0,0,w,h);
        isFullScreen = true;
    }
    else
    {
        SDL_SetWindowFullscreen(mainWindow, 0);
        SDL_SetWindowSize( mainWindow, 800, 600);
        updateProjection( glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 500.f)) ;
        printf("Leaving fullscreen!\n");
        glViewport(0,0,800,600);
        isFullScreen = false;
    }
}
Пример #29
0
void Camera::updateFrustum()
{	
	if (projectionDirty_)
		updateProjection();

	Matrix3x4 transform = Matrix3x4::translationMatrix(position);

	transform.rotateY(degToRad(-yaw - 180.0f));
	transform.rotateX(degToRad(-pitch));

	frustum_.setTransform(transform);

	frustumDirty_ = false;
}
Пример #30
0
Camera::Camera(float width, float height, float xFoV, float yFoV, float nearClip, float farClip) {
    _xFoV = xFoV;
    _yFoV = yFoV;
    _farClip = farClip;
    _nearClip = nearClip;


    _position = XMFLOAT3(0.f, 0.f, 0.f);
    _target   = XMFLOAT3(0.f, 0.f, 1.f);
    _up       = XMFLOAT3(0.f, 1.f, 0.f);

    updateView();
    updateProjection(width, height);
}