Пример #1
0
	void UIMethodsInit()
	{
		PosesInit();
		nameHandler = new NameHandler();
		fp = new vector< FixedPoint* >();
		//hl = new HumanLeg( point( 0.0f, 50.0f, 0.0f ), point( 0.0f, 0.0f, 0.0f ), point( 1.0f, 1.0f, 1.0f ) );
		//hlc = new HumanLegController( hl );
		pl = new Player( point( ((float)width)/2.0f, ((float)height)/2.0f, 0 ), point( 0.0f, 0.0f, 0.0f ) );
		selectedRect = new Rect( point( 0,0,0 ), point( 2000, 100, 0 ) );
		float pos[WAMS_PLAYER_DOF];
		pl->getPose( pos );
		//hlc->getPose( pos );
		keyframes.push_back( new Keyframe( pos, -1.0f ) );
		count = 0;
		cam.setLoc( 0, 0, -50 );
		cam.setLookAt( 0, 0, 50 );
		//cam2.setLoc( 0.0f, 300.0f, 0.0f );
		//cam.setLookAt( 0, 100, 0 );
	}
Пример #2
0
void
camera_uniform_block::update(const render_context_ptr& context,
                             const camera&             cam)
{
    _uniform_block.begin_manipulation(context); {
        _uniform_block->_ws_position                 = cam.position();
        _uniform_block->_ws_near_plane               = cam.view_frustum().get_plane(frustum::near_plane).vector();
        _uniform_block->_p_matrix                    = cam.projection_matrix();
        _uniform_block->_p_matrix_inverse            = cam.projection_matrix_inverse();
        _uniform_block->_v_matrix                    = cam.view_matrix();
        _uniform_block->_v_matrix_inverse            = cam.view_matrix_inverse();
        _uniform_block->_v_matrix_inverse_transpose  = cam.view_matrix_inverse_transpose();
        _uniform_block->_vp_matrix                   = cam.view_projection_matrix();
        _uniform_block->_vp_matrix_inverse           = cam.view_projection_matrix_inverse();
    } _uniform_block.end_manipulation();
}
Пример #3
0
void image::generateImage(object mxdObject, camera m3dCamera, pose m34dPose)
{
  this->mxdImage = m3dCamera.getIntrinsic() * m34dPose.getPoseMatrix() * mxdObject.getObjectPoints();

  for (unsigned i = 0; i < this->mxdImage.cols(); i++)
  {
    this->mxdImage(0,i) = round(this->mxdImage(0,i)/this->mxdImage(2,i));
    this->mxdImage(1,i) = round(this->mxdImage(1,i)/this->mxdImage(2,i));
    this->mxdImage(2,i) = round(this->mxdImage(2,i)/this->mxdImage(2,i));
  }
}
Пример #4
0
void rasterized_color_triangle_app::on_key_down(SDL_Keysym const key)
{
	app::on_key_down(key);

	float const moving_speed{0.01f};
	float const rotation_speed{0.05f};

	if (key.sym == SDLK_a)
	{
		m_camera.move_left(moving_speed);
	}
	else if (key.sym == SDLK_d)
	{
		m_camera.move_right(moving_speed);
	}
	else if (key.sym == SDLK_w)
	{
		m_camera.move_forward(moving_speed);
	}
	else if (key.sym == SDLK_s)
	{
		m_camera.move_backward(moving_speed);
	}
	else if (key.sym == SDLK_r)
	{
		m_camera.move_up(moving_speed);
	}
	else if (key.sym == SDLK_f)
	{
		m_camera.move_down(moving_speed);
	}
	else if (key.sym == SDLK_q)
	{
		m_camera.yaw(-rotation_speed);
	}
	else if (key.sym == SDLK_e)
	{
		m_camera.yaw(rotation_speed);
	}
	else if (key.sym == SDLK_1)
	{
		m_shader_option = shader_option::color;
	}
	else if (key.sym == SDLK_2)
	{
		m_shader_option = shader_option::texture;
	}

	// Update model-view-projection according to camera changes
	update_shader_mvp();
}
Пример #5
0
/**
 * Updates the camera based on the mouse movement.
 */
void mouseMove(int x, int y) {
   dx = mouse_sensitivity * (p2wx(x) - lastx);
   dy = mouse_sensitivity * (p2wy(g2py(y)) - lasty);
   //dy = mouse_sensitivity * (p2wy(y) - lasty);
   
   cam.update(cam.cam_spin_flag ? 0 : dx, dy);

   //lastx = p2wx(x);
   lasty = p2wy(g2py(y));
   lasty = p2wy(y);
   glutPostRedisplay();
}
Пример #6
0
void overhead(){
  glMatrixMode(GL_MODELVIEW);             
  glLoadIdentity(); 
  glDrawBuffer( GL_BACK );
  glViewport(windowHeight-windowHeight/3,windowWidth-windowWidth/3,windowWidth/3,windowHeight/3);
  glScissor(windowHeight-windowHeight/3,windowWidth-windowWidth/3,windowWidth/3,windowHeight/3);
  glEnable(GL_SCISSOR_TEST);
  glClearDepth(1.0);
  glClearColor(0,0,0,1);
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  glDisable(GL_SCISSOR_TEST);
      glPushMatrix();
        overheadCam.update_pos_arcball();
        glPushMatrix(); {
            sky->drawSkybox(200, 200, 200);               // draw our axes so we know how we are oriented
        }; glPopMatrix();
        // draw ground
        glPushMatrix(); {
            drawGround();
        }; glPopMatrix();

        // draw the car based on the world object coordinates controlled by user interaction
        glPushMatrix(); {
            glTranslatef(porsche.getX(), porsche.getY(), porsche.getZ());
            glColor3f(1,1,1);
            glutSolidSphere(3, 10, 10);
        };glPopMatrix();

        for (unsigned int i=0; i<cash.size(); i++){
            glPushMatrix(); {
                glTranslatef(cash.at(i)->getX(),cash.at(i)->getY(),cash.at(i)->getZ());
                glColor3f(0.6,0.4,0.2);
                glutSolidCube(targsize);
            };glPopMatrix();
        }

        for (unsigned int i=0; i<fuzz.size(); i++){
            if (fuzz.at(i)->getY()>-10){
                glPushMatrix(); {
                  glTranslatef(fuzz.at(i)->getX(), fuzz.at(i)->getY(), fuzz.at(i)->getZ());
                  if (fuzz.at(i)->inPursuit){
                    glColor3f(fuzz.at(i)->r,0,fuzz.at(i)->b);
                  }else{
                    glColor3f(0,0,0);
                  }
                  glutSolidSphere(3, 10, 10);
                }; glPopMatrix();
            }
        }

      glPopMatrix();
  glMatrixMode(GL_PROJECTION);
}
Пример #7
0
void blob_finder::detect(const camera &cam, const cv::Mat &mask, blobs_t &blobs)
{
	detector.detect(mask, blobs);

	for (auto &b : blobs)
	{
		b.cam = cam.i;
		b.rel = cam.cam2rel(b.center);
		auto pol = rect2pol(b.rel);
		b.dist = pol.x;
		b.angle = pol.y;
	}
}
Пример #8
0
/**
 * Draws the scene (used in display).
 */
void drawScene() {
   glMatrixMode(GL_MODELVIEW);
   glEnable(GL_DEPTH_TEST);

   glPushMatrix(); {
      cam.updateLookat();
      for (unsigned int i = 0; i < objs.size(); i++) {
         objs[i]->draw();
         if (draw_arrows) {
            glDisable(GL_DEPTH_TEST);
            objs[i]->drawArrows();
            glEnable(GL_DEPTH_TEST);
         }
         if (draw_bounding_box) {
            objs[i]->drawBoundingBox();
         }
         if (follow && objs[i]->classId == PART_ID) {
            particleSystem *temp = (particleSystem*)objs[i];
            cam.setFocus(temp->pos);
         }
      }
   } glPopMatrix();
}
Пример #9
0
image generateImage(const camera& cam, const sceneGraphNode& sceneGraph, const lightsource_base& ls)
{
  image result(cam.width(), cam.height());
  result.clear();

  // for every pixel
  for(image::size_type y=0; y < result.height(); y++)
    for(image::size_type x=0; x < result.width(); x++)
  {
      // create view ray
      ray r = cam.generateViewRay(x, y);

      // intersect
      intersectionPoint ip = sceneGraph.intersect(r);

      // if hit
      if(ip.isHit())
	result(x,y)  = ip.evaluate(ls);
    }

  // Done.
  return result;
}
// Draws the scene
void drawScene()
{
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

	// Camera
	cam.look();
	// Lights
	light01.draw(); // Diffuse
	light02.draw(false); // Ambient
	// Object
	ball01.draw();
	glutSwapBuffers();
}
Пример #11
0
void render()
{
	fr.SetCameraPos(Camera.getPos());
	glm::mat4 view = Camera.getView();
	glm::mat4 projection = Camera.getProjection();
	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
	glClearColor( 0.f, 0.f, 0.5f, 0.f );
	fr.render(view, projection);

	GBuffer::BindForWriting();

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glDepthMask(GL_TRUE);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LESS);
	glEnable(GL_CULL_FACE);
	glCullFace(GL_FRONT);
	glClearColor( 0.f, 0.f, 0.5f, 0.f );
	Terrain.render(view, projection);
	GBuffer::DefaultBuffer();
	//glDisable(GL_CULL_FACE);
	//glDisable(GL_DEPTH_TEST);
	return;
}
Пример #12
0
void water::update(const float4x4& view_projection, const camera& camera, const point_light& light) {
	// count normals
	GLint old_viewport[4];
  glGetIntegerv(GL_VIEWPORT, old_viewport);

  glViewport(0, 0, grid_size_x_, grid_size_z_);
  glDisable(GL_DEPTH_TEST);

	norm_tex_->BeginRenderingToThisTexture();
	glUseProgram(normal_prog_.program);
	setUniform(normal_prog_.program, "objectMatrix", object_matrix_);
	setUniform(normal_prog_.program, "inversedObjectMatrix", inversed_object_matrix_);
	setUniform(normal_prog_.program, "gridSizeX",    grid_size_x_);
  setUniform(normal_prog_.program, "gridSizeZ",   grid_size_z_);
  bindTexture(normal_prog_.program, WATER_POSITIONS, "inPositions", pos_tex_[c_]->GetColorTexId());
	full_screen_quad_->Draw();
	norm_tex_->EndRenderingToThisTexture();
	glEnable(GL_DEPTH_TEST);
  glViewport(old_viewport[0], old_viewport[1], old_viewport[2], old_viewport[3]);


	// draw water
	glUseProgram(render_prog_.program);
  setUniform(render_prog_.program, "cameraPosition", camera.get_pos());
	setUniform(render_prog_.program, "viewProjectionMatrix", view_projection);
  setUniform(render_prog_.program, "objectMatrix", object_matrix_);

	light.setup_shader(render_prog_.program);
	material_.setup_shader(render_prog_.program); 
	setUniform(render_prog_.program, "gridSizeX", grid_size_x_);
  setUniform(render_prog_.program, "gridSizeZ", grid_size_z_);
  bindTexture(render_prog_.program, WATER_POSITIONS, "inPositions", pos_tex_[c_]->GetColorTexId());
	bindTexture(render_prog_.program, WATER_NORMALS, "inNormals", norm_tex_->GetColorTexId());

	//glEnable(GL_DEPTH_TEST);
  glEnable(GL_BLEND); 
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);	

	water_mesh_->Draw(GL_TRIANGLES);

	glDisable(GL_BLEND); 
}
Пример #13
0
void GLWidget::paintGL(){

    glClearColor(0.1f, 0.1f, 0.1f, 0.0f);
    glClearDepth(1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glLoadIdentity();
    gluLookAt(Camera.mPos.x,  Camera.mPos.y,  Camera.mPos.z,
              Camera.mView.x, Camera.mView.y, Camera.mView.z,
              Camera.mUp.x,   Camera.mUp.y,   Camera.mUp.z);


     Camera.Mouse_Move();

     Keyboard_Operations();

     terra();
    glEnable(GL_LIGHTING);
     drawCube();
    glDisable(GL_LIGHTING);

     // Draw The Car
             glColor3f(1,1,1);
             glEnable(GL_LIGHTING);
             glPushMatrix();
             glTranslatef(20.0f,-3.0f,10.0f);
             Auto->draw();
             glPopMatrix();
             glDisable(GL_LIGHTING);


     rot+=1;
       // Framerate control
        int delay = time.msecsTo(QTime::currentTime());
        if (delay == 0)
           delay = 1;
        time = QTime::currentTime();
        timer->start(qMax(0, 30 - delay));

}
Пример #14
0
int main(int argc, char** argv) {
  int rc;
  Shader s;

  // set the camera to an initial position
  cam.setCamera(Vector3f(0,-10,100), Vector3f(0,0,0), Vector3f(0,1,0));

  glutInit(&argc, argv);
  // glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE|GLUT_DEPTH|GLUT_3_2_CORE_PROFILE);
  glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE|GLUT_DEPTH);
  glutInitWindowSize(600,600);
  glutInitWindowPosition(10, 10);

  glutCreateWindow("skybox");
  glutDisplayFunc(renderFun);
  glutIdleFunc(idleFun);
  // setCallbackFun();

  // initialize GLEW
  // GLenum err = glewInit();
  // if ( err != GLEW_OK)  printf(" Error initializing GLEW! \n");

  loadTextures();
  skybox.init();
  // skybox2.init();

  Init_Geometry();
  InitVBO();

  rc = loadShaders(s);
  if (rc != 0) {
    printf("error after createing shaders rc = %d \n", rc);
    getchar();
  }

  glutMainLoop();
}
Пример #15
0
void PtexViewer::frameView(bool reset)
{
    if (reset) _cam.reset();
    
    if (_displayFace>=0)
    {
        _cam.setLookAt(Vec3f(0.5, 0.5, 0));
        _cam.setDistance(1.41);
    }
    else
    {
        if (_mode3d && _envCube && reset)
        {
            _cam.setLookAt(Vec3f(0,0,0));
            _cam.setDistance(1e-4);
        }
        else
        {
            _cam.setLookAt(_bounds.getCenter());
            _cam.setDistance(_bounds.diagonal());
        }
    }
}
Пример #16
0
void PtexViewer::zoom(int z)
{
    _cam.zoom(z);
}
Пример #17
0
void PtexViewer::orbit(int x, int y)
{
    if (_mode3d && _displayFace<0) _cam.rotateXY(x,-y);
}
Пример #18
0
	void camStrafeRight( unsigned int changeInTime )
	{
		if( mode == CAMERA )
			if( isPressed('d') )
				cam.strafe( -4 );
	}
Пример #19
0
void renderScene(void){
    //update the modelview matrix based on the camera's position
    glMatrixMode(GL_MODELVIEW);             //make sure we aren't changing the projection matrix!
    glLoadIdentity();

    glDrawBuffer( GL_BACK );
    glClearColor(0,0,0,1);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glViewport( 0, 0, windowWidth, windowHeight);
    glPushMatrix();

        myCam.set_atx(porsche.getX());
        myCam.set_aty(porsche.getY());
        myCam.set_atz(porsche.getZ());
        myCam.set_eyex(porsche.getX());
        myCam.set_eyez(porsche.getZ());
        myCam.update_pos_arcball();

        glPushMatrix(); {
            sky->drawSkybox(200, 200, 200);               // draw our axes so we know how we are oriented
        }; glPopMatrix();

        // draw ground
        glPushMatrix(); {
            drawGround();
        }; glPopMatrix();

        for (unsigned int i=0; i<cash.size(); i++){
            glPushMatrix(); {
                cash.at(i)->drawCrate();
            };glPopMatrix();
        }

        // draw the car based on the world object coordinates controlled by user interaction
    	glPushMatrix(); {
      		glTranslatef(porsche.getX(), porsche.getY(), porsche.getZ());
      		glRotatef(porsche.getTheta(), 0.0, 1.0, 0.0);       //Rotate about the y-axis
      		glTranslatef(-porsche.getX(), -porsche.getY(), -porsche.getZ());
      		porsche.drawCar();	// draw our dodecahedron...or torus...teapot...or whatever
        }; glPopMatrix();

        // draw the car based on the world object coordinates controlled by user interaction
        for (unsigned int i=0; i<fuzz.size(); i++){
            glPushMatrix(); {
              glTranslatef(fuzz.at(i)->getX(), fuzz.at(i)->getY(), fuzz.at(i)->getZ());
              glRotatef(fuzz.at(i)->getTheta(), 0.0, 1.0, 0.0);
              glTranslatef(-fuzz.at(i)->getX(), -fuzz.at(i)->getY(), -fuzz.at(i)->getZ());
              fuzz.at(i)->drawCar();
            }; glPopMatrix();
        }
    glPopMatrix();

    glClear(GL_FRAMEBUFFER | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_PROJECTION);

    glDisable(GL_LIGHTING);
    glPushMatrix();
      glOrtho(-1,1,-1,1,-1,1);
        int locationX,locationY;
        if (!gameOver){
            locationX=-15;
            locationY=windowHeight-windowHeight/12;
        }else{
            locationX=windowWidth/2;
            locationY=windowHeight-windowHeight/2;
        }
        glViewport(locationX, locationY, windowWidth/12, windowHeight/12);
        glLoadIdentity();
      glColor3f(1,1,1);
        char c[15];
        sprintf(c, "%d", score);
        string temp=string(c);
      glRasterPos3i(0,0,0);
      glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'S');
      glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'C');
      glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'O');
      glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'R');
      glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'E');
      glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, ':');
      glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, ' ');
    for (unsigned int i=0; i<temp.size(); i++){
        glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, temp[i] );
    } 
    glMatrixMode(GL_PROJECTION);
  glPopMatrix();

  glPushMatrix();
      glOrtho(-1,1,-1,1,-1,1);
        if (!gameOver){
            locationX=150;
            locationY=windowHeight-windowHeight/12;
        }else{
            locationX=windowWidth/2;
            locationY=windowHeight-windowHeight/2+windowWidth/12;
        }
        glViewport(locationX, locationY, windowWidth/12, windowHeight/12);
        glLoadIdentity();
      glColor3f(healthR,healthG,0);
        char h[15];
        sprintf(h, "%d", health);
        string hea=string(h);
      glRasterPos3i(0,0,0);
      if (!gameOver){
        glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'H');
        glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'E');
        glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'A');
        glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'L');
        glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'T');
         glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'H');
        glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, ':');
        glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, ' ');
        for (unsigned int i=0; i<hea.size(); i++){
            glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, hea[i] );
        } 
        glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, '%');
    }else{
        glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'G');
        glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'A');
        glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'M');
        glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'E');
        glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, ' ');
        glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'O');
        glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'V');
        glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'E');
        glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'R');
    }
    glMatrixMode(GL_PROJECTION);
  glPopMatrix();

  if (stageUp&&!gameOver){
        glPushMatrix();
          glOrtho(-1,1,-1,1,-1,1);
            glViewport(windowWidth/2-75,windowHeight-windowHeight/2+windowWidth/12, windowWidth/12, windowHeight/12);
            glLoadIdentity();
          glColor3f(1,1,1);
            char s[3];
            sprintf(s, "%d", stage);
            string sta=string(s);
          glRasterPos3i(0,0,0);
            glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'S');
            glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'T');
            glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'A');
            glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'G');
            glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'E');
            glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, ' ');
            for (unsigned int i=0; i<sta.size(); i++){
                glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, sta[i] );
            } 
        glMatrixMode(GL_PROJECTION);
      glPopMatrix();
    }

  if (!gameOver){
    glPushMatrix();
        overhead();
    glPopMatrix();
  }
  glMatrixMode(GL_MODELVIEW);
  glFlush();
  //push the back buffer to the screen
  glutSwapBuffers();
}
Пример #20
0
void GLWidget::initializeGL(){   

    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
    glDepthFunc(GL_LEQUAL);
    glDepthRange(0.0f, 1.0f);


    //glClearColor(0.2,0.2,0.2,1);

    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// Really Nice Perspective Calculations



    Camera.Position_Camera(0, 0.5f, 5,	0, 0.5f, 0,   0, 1, 0);

    QApplication::setOverrideCursor(QCursor(Qt::BlankCursor));

    Auto = new MilkshapeModel();									// Memory To Hold The Model
            if ( Auto->loadModelData( "Auto.ms3d" ) == false )		// Loads The Model And Checks For Errors
            {

                //int ret = QMessageBox::warning(this, tr(""),tr("erro ao carregar modelo"), QMessageBox::Cancel);
            }


         // Carregando textura do pizo.
         glShadeModel(GL_SMOOTH);
         QImage img = convertToGLFormat(QImage(":/img/Concreto2.jpg"));
         glGenTextures(1, &texture[0]);

         glBindTexture( GL_TEXTURE_2D, texture[0] );
        // Texture using mipmaps
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
         gluBuild2DMipmaps(GL_TEXTURE_2D, 3, img.width(), img.height(), GL_RGBA, GL_UNSIGNED_BYTE, img.bits());


         QImage b;

         // carregando textura da caixa de madeira.

         if ( !b.load( ":/img/Crate.bmp"))
         {
               //qWarning( "Could not read image file, using single-color instead." );
               b = QImage( 16, 16, QImage::Format_RGB888 );
               b.fill( QColor(Qt::green).rgb() );
         }
         img = convertToGLFormat(b);
         glGenTextures(1, &texture[1]);
         glBindTexture( GL_TEXTURE_2D, texture[1] );

         glTexImage2D( GL_TEXTURE_2D, 0, 3, img.width(), img.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, img.bits() );
         glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
         glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );


         //Luz avermelhada (sala com lava?)
         GLfloat ambientLight[] = {1.0f, 1.0f, 1.0f, 1.0f};

         //Habilitamos a capacidade de iluminação
         glEnable(GL_LIGHTING);

         //Configuramos a OpenGL para utilizar como luz ambiente global
         //a iluminação definida por ambientLight[]
         glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight);


}
Пример #21
0
void zombieType::render(int i,camera &cam,bool unrender)
{
	animate();
	oamSet(&oamMain, i+10, x-cam.getX(), y-cam.getY(), 0, 0, SpriteSize_32x32, SpriteColorFormat_256Color, 
						sprite_gfx_mem, -1, false, unrender, false, false, false);
}
Пример #22
0
int 
main( int argc, char *argv[ ] )
{
	cmd_args args;
	if( !args.parse( argc, (const char**)argv ) ) {
		return 1;
	}

	//setup glut
	glutInit( &argc, argv );
	glutInitDisplayMode( GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA );
	glutInitWindowSize( 640, 480 );
	glutCreateWindow( "Flock of Birds Demo" );

	//setup gl
	init_gl( );

	//set callbacks
	glutKeyboardFunc( handle_keyboard );
	glutReshapeFunc( handle_resize );
	glutDisplayFunc( render );
	glutIdleFunc( render );

#if ENABLE_FBB
	fob::hemisphere hemisphere = fob::DOWN;
	fob::port_speed speed = args.speed;
	
	//talk to flock
	flock.open( args.serial, hemisphere, speed, args.sleep_ms );
	if( !flock ) {
		std::cerr << "fatal: " << flock.get_error( ) << std::endl;
		return 1;
	}

	//get a list of birds connected to the machine
	fob::bird_list& birds = flock.get_birds( );
	p_birds = &flock.get_birds( );
	num_birds = birds.size( );
	if( num_birds > MAX_ENTS ) num_birds = MAX_ENTS;
#else
	unsigned int num_birds = 1;
#endif
	
#if ENABLE_FBB
	//for each bird, set that we want position and orientation
	for( unsigned int i = 0; i < birds.size( ); ++i ) {
		if( !birds[ i ]->set_mode( fob::POSITION | fob::ORIENTATION | fob::BUTTONS ) ) {
			std::cerr << "fatal: " << flock.get_error( ) << std::endl;
			return 1;
		}
	}
#endif

	//setup the camera
	cam.set_position( 0.0, 100.0, 0.0 );
	cam.set_look_right( math::vector3( 0.0, 0.0, 0.0 ), math::vector3::X_AXIS );
	
#if ENABLE_FBB
	//set the flock flying
	flock.fly( );
	atexit( handle_exit );

	//let the bird start up . . .
	sleep( 1 );
#endif

	//create the button sphere
	sphere = gluNewQuadric( );

	//start glut
	glutMainLoop( );

	//no errors
	return 0;
}
Пример #23
0
void HandleEvents(SDL_Event e, float dt)
{
	//User requests quit
	if ( e.type == SDL_QUIT )
	{
		quit = true;
	}
	else if (e.type == SDL_KEYDOWN)
	{
		// handle key down events here
		if (e.key.keysym.sym == SDLK_ESCAPE)
		{
			quit = true;
		}

		// rotate camera left
		if (e.key.keysym.sym == SDLK_q)
		{
			Camera.rotateX(1 * dt);
		}

		// rotate camera right
		if (e.key.keysym.sym == SDLK_e)
		{
			Camera.rotateX(-1 * dt);
		}

		//Camera.applyRotation();

		// Move left
		if (e.key.keysym.sym == SDLK_a)
		{
			Camera.strafe(10 * dt);
		}
		// move back
		if (e.key.keysym.sym == SDLK_s)
		{
			Camera.translate(-10 * dt);
		}

		// move right
		if (e.key.keysym.sym == SDLK_d)
		{
			Camera.strafe(-10 * dt);
		}

		// move forward
		if (e.key.keysym.sym == SDLK_w)
		{
			Camera.translate(10 * dt);
		}

		if (e.key.keysym.sym == SDLK_y)
		{
			glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
		}
		if (e.key.keysym.sym == SDLK_u)
		{
			glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
		}
		if (e.key.keysym.sym == SDLK_z)
		{
			Camera.rotateY(-1 * dt);
		}
		if (e.key.keysym.sym == SDLK_x)
		{
			Camera.rotateY(1 * dt);
		}
		if (e.key.keysym.sym == SDLK_r)
		{
			Camera.flight(1 * dt);
		}
		if (e.key.keysym.sym == SDLK_f)
		{
			Camera.flight(-1 * dt);
		}
	}
	else if (e.type == SDL_KEYUP)
	{
		if (e.key.keysym.sym == SDLK_w)
		{
			cout << "W RELEASED" << endl;
			Camera.resetVerticalSpeed();
		}
		else if (e.key.keysym.sym == SDLK_s)
		{
			cout << "S RELEASED" << endl;
			Camera.resetVerticalSpeed();
		}
		if (e.key.keysym.sym == SDLK_a || e.key.keysym.sym == SDLK_d)
		{
			Camera.resetHorizontalSpeed();
		}
		if (e.key.keysym.sym == SDLK_q || e.key.keysym.sym == SDLK_e)
		{
			// Reset Horizontal rotation
			Camera.resetHorizontalRotation();
		}
		if (e.key.keysym.sym == SDLK_z || e.key.keysym.sym == SDLK_x)
		{
			Camera.resetVerticalRotation();
		}
		if (e.key.keysym.sym == SDLK_r || e.key.keysym.sym == SDLK_f)
		{
			Camera.resetFlightSpeed();
		}
	}
}
Пример #24
0
void PtexViewer::render(int selx, int sely)
{
    if (!_shaderProgram) makeShader();

    if (_options.bgColorLight) glClearColor(0.8,0.8,0.8,1);
    else glClearColor(0.0,0.0,0.0,1);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    
    GLint vp[4];  
    glGetIntegerv(GL_VIEWPORT, vp);
    float width = vp[2];
    float height = vp[3];
    float winasp = width/height;
    
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    bool selectMode = selx>=0 && sely>=0;
    
    if (selectMode)
        gluPickMatrix((double)selx,(double)vp[3]-sely,3,3,vp);
    
    if (!_mode3d||_displayFace>=0)
    {
        float sc = _cam.getDistance()/2;
        glOrtho(-sc, sc, -sc/winasp, sc/winasp, -100, 100);

        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glTranslatef(-_cam.getLookAt()[0],-_cam.getLookAt()[1],-_cam.getLookAt()[2]);
    }
    else
    {
        _cam.applyProjectionTransform(winasp, _bounds);

        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        _cam.applyModelViewTransform();
    }
    
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_POLYGON_OFFSET_FILL);
    glPolygonOffset(1.0,1.0);
    glColor4f(1.0, 1.0, 1.0, 1.0);
    glUseProgramObjectARB(_shaderProgram);
    _geometry.draw(_displayFace);
    glUseProgramObjectARB(0);
    if (!selectMode && _options.showGridLines)
    {
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glEnable(GL_LINE_SMOOTH);
        glColor4f(0.0, 0.0, 0.0, 0.25);
        _geometry.draw(_displayFace);
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
        glDisable(GL_BLEND);
        glDisable(GL_LINE_SMOOTH);
    }
    glDisable(GL_POLYGON_OFFSET_FILL);
    glDisable(GL_DEPTH_TEST);
    
    if (selectMode) return;
    
    // Display text information
    char str[64];
    
    if (_options.bgColorLight) glColor3f(0.0, 0.0, 0.0);
    else glColor3f(0.9, 0.9, 0.9);
    
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    
    if (!_options.envMode)
    {
        if (_numFaces==1) strcpy(str, "1 face");
        else sprintf(str,"%i faces",_numFaces);

        renderChars(-0.8,-0.92,GLUT_BITMAP_8_BY_13,str);
        if (_displayFace>=0 && _numFaces!=1)
        {
            sprintf(str,"Face ID: %i",_displayFace);
            renderChars(-0.8,0.92,GLUT_BITMAP_8_BY_13,str);
        }
        if (_numFaces==1)
        {
            int ures = _geometry.getFace(0)->ures;
            int vres = _geometry.getFace(0)->vres;
            sprintf(str,"Res: %i x %i",ures,vres);
            renderChars(-0.8,0.92,GLUT_BITMAP_8_BY_13,str);
        }
        else if (_displayFace>=0)
        {
            int ures = _geometry.getFace(_displayFace)->ures;
            int vres = _geometry.getFace(_displayFace)->vres;
            sprintf(str,"Face Res: %i x %i",ures,vres);
            renderChars(-0.2,0.92,GLUT_BITMAP_8_BY_13,str);
        }
        renderChars(0.25,-0.92,GLUT_BITMAP_8_BY_13,(char*)_typeStr.c_str());
    }
}
Пример #25
0
// RENDERS AN OBJECT USING A SKYBOX AS THE TEXTURE SOURCE
void displayBoxFun(GLuint shaderProg) {
  Matrix4f viewMat, projMat, modelMat, m;
  // set up the mode to wireframe

  // setting up the transformaiton of the object from model coord. system to world coord.
  modelMat = Matrix4f::identity();
  //modelMat = Matrix4f::translation(0,0,0);

  modelMat = Matrix4f::scale(50,50,50);

  // ROATE THE OBJECT AROUND THE CAMERA VECTOR
  // CAN ADD ROTATIONS AROUND THE PRIMARY AXIS
  modelMat = modelMat * Matrix4f::rotateVector(cam.getLookAtVector(),angle,1);

  // setting up the viewpoint transformation
  viewMat = cam.getViewMatrix(NULL);

  // setting up the projection transformation
  projMat= cam.getProjectionMatrix(NULL);

  // putting it all together
  m = projMat * viewMat * modelMat;

  // tell openfl which shader program to use
  glUseProgram(shaderProg);

  // transfer the modelViewProjection  matrix to the shader
  GLuint locMat= 0;
  locMat=glGetUniformLocation(shaderProg,  "modelViewProjMat");
  glUniformMatrix4fv(locMat,1,1,(float *)m.vm);

  // transfer the modelView matrix to the shader
  m = viewMat * modelMat;
  locMat=glGetUniformLocation(shaderProg,  "modelViewMat");
  glUniformMatrix4fv(locMat,1,1,(float *)m.vm);

  // transfer the model matrix to the shader
  m = modelMat;
  locMat=glGetUniformLocation(shaderProg,  "modelMat");
  glUniformMatrix4fv(locMat,1,1,(float *)m.vm);

  // load the camera position to the shader
  locMat=glGetUniformLocation(shaderProg,  "camPos");
  Vector3f camPos = cam.getPosition();
  glUniform3fv(locMat,1, (float *) &camPos);

  // load the refract flag to the shader
  locMat=glGetUniformLocation(shaderProg,  "refractFlag");
  glUniform1i(locMat, refractFlag);

  glActiveTexture(GL_TEXTURE3);
  GLuint texCube = skybox.getTexHandle();
  glBindTexture(GL_TEXTURE_CUBE_MAP, texCube);
  GLuint samLoc = glGetUniformLocation(shaderProg, "texCube");
  glUniform1i(samLoc, 3);

  GLint ttt = 0;
  glGetUniformiv(shaderProg, samLoc, &ttt);

  // bind the buffers to the shaders
  GLuint positionLoc = glGetAttribLocation(shaderProg, "vertex_position");
  GLuint normalLoc = glGetAttribLocation(shaderProg, "vertex_normal");

  glEnableVertexAttribArray(positionLoc);
  glEnableVertexAttribArray(normalLoc);

  glBindBuffer(GL_ARRAY_BUFFER, vertex_handle);
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, triangle_handle);

  // Tells OpenGL how to walk through the two VBOs
  struct sphereVertex v;
  int relAddress = (char *) v.pos - (char *) &v;
  glVertexAttribPointer(positionLoc,4,GL_FLOAT, GL_FALSE, sizeof(struct sphereVertex),(char*) NULL+relAddress);
  relAddress = (char *) v.normal - (char *) &v;
  glVertexAttribPointer(normalLoc,4,GL_FLOAT, GL_FALSE, sizeof(struct sphereVertex),(char*) NULL+relAddress);

  // draw the triangles
  glDrawElements(GL_TRIANGLES, numTriangles*3, GL_UNSIGNED_INT, (char*) NULL+0);

  // glUseProgram(0);
  // glUseProgram(shaderProg);

  // draw the second sphere

  modelMat = Matrix4f::identity();
  //modelMat = Matrix4f::translation(0,0,0);

  modelMat = Matrix4f::scale(50,50,50) * Matrix4f::translation(2, 0, 0);

  // ROATE THE OBJECT AROUND THE CAMERA VECTOR
  // CAN ADD ROTATIONS AROUND THE PRIMARY AXIS
  modelMat = modelMat * Matrix4f::rotateVector(cam.getLookAtVector(),angle,1);

  // setting up the viewpoint transformation
  viewMat = cam.getViewMatrix(NULL);

  // setting up the projection transformation
  projMat= cam.getProjectionMatrix(NULL);

  // putting it all together
  m = projMat * viewMat * modelMat;

  locMat= 0;
  locMat=glGetUniformLocation(shaderProg,  "modelViewProjMat");
  glUniformMatrix4fv(locMat,1,1,(float *)m.vm);

  // transfer the modelView matrix to the shader
  m = viewMat * modelMat;
  locMat=glGetUniformLocation(shaderProg,  "modelViewMat");
  glUniformMatrix4fv(locMat,1,1,(float *)m.vm);

  // transfer the model matrix to the shader
  m = modelMat;
  locMat=glGetUniformLocation(shaderProg,  "modelMat");
  glUniformMatrix4fv(locMat,1,1,(float *)m.vm);

  glActiveTexture(GL_TEXTURE3);
  GLuint texCube2 = skybox2.getTexHandle();
  glBindTexture(GL_TEXTURE_CUBE_MAP, texCube2);
  GLuint samLoc2 = glGetUniformLocation(shaderProg, "texCube");
  glUniform1i(samLoc2, 3);

  GLint ttt2 = 0;
  glGetUniformiv(shaderProg, samLoc, &ttt2);

  glBindBuffer(GL_ARRAY_BUFFER, vertex_handle2);
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, triangle_handle2);

  // Tells OpenGL how to walk through the two VBOs
  // struct sphereVertex v;
  relAddress = (char *) v.pos - (char *) &v;
  glVertexAttribPointer(positionLoc,4,GL_FLOAT, GL_FALSE, sizeof(struct sphereVertex),(char*) NULL+relAddress);
  relAddress = (char *) v.normal - (char *) &v;
  glVertexAttribPointer(normalLoc,4,GL_FLOAT, GL_FALSE, sizeof(struct sphereVertex),(char*) NULL+relAddress);

  // draw the triangles
  glDrawElements(GL_TRIANGLES, numTriangles*3, GL_UNSIGNED_INT, (char*) NULL+0);

  return;
}
Пример #26
0
	void camStrafeLeft( unsigned int changeInTime )
	{
		if( mode == CAMERA )
			if( isPressed('a') )
				cam.strafe( 4 );
	}
Пример #27
0
	void camBackward( unsigned int changeInTime )
	{
		if( mode == CAMERA )
			if( isPressed('s') )
				cam.move( -4 );
	}
Пример #28
0
void update(float dt)
{
	//No per frame update needed
	Camera.update();
}
Пример #29
0
void set_cornell_view(camera &cam, int nx, int ny)
{
    cam = camera(0.6981, float(nx)/float(ny));
    cam.look_at(vec3(278, 278, -800), vec3(278,278,0));
}
Пример #30
0
	void camForward( unsigned int changeInTime )
	{
		if( mode == CAMERA )
			if( isPressed('w') )
				cam.move( 4 );
	}