Пример #1
0
int main(int argc, char * argv[])
{
    sf::RenderWindow window(sf::VideoMode(640, 480), "OpenGL");

    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    g_Resources->SetShaderPath("/home/gergondet/ros/perception_blort/blort_ros/Tracker/shader/");

    TomGine::tgCamera::Parameter camPar;
    TomGine::tgCamera camera;
    camPar.width = 640;
    camPar.height = 480;
    camPar.fx = 568.168672;
    camPar.fy = 566.360327;
    camPar.cx = 349.631248;
    camPar.cy = 256.295344;
    camPar.k1 = -0.059636;
    camPar.k2 = 0.232352;
    camPar.k3 = 0;
    camPar.p1 = -0.003432;
    camPar.p2 = 0.017361;
    camPar.pos.x = 0.31188;
    camPar.pos.y = -0.3;
    camPar.pos.z = 0.243049;
    vec3 rotv; rotv.x = -1.917587; rotv.y = -0.453044; rotv.z = 0.389306;
    camPar.rot.fromRotVector(rotv);
    camera.Load(camPar);

    Tracking::TrackerModel * model = new Tracking::TrackerModel();
    Tracking::ModelLoader loader;
    loader.LoadPly(*model, "/home/gergondet/ros/perception_blort/blort_ros/Resources/ply/can.ply");

    bool running = true;
    while (running)
    {
        // handle events
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
            {
                // end the program
                running = false;
            }
            else if (event.type == sf::Event::Resized)
            {
                // adjust the viewport when the window is resized
                glViewport(0, 0, event.size.width, event.size.height);
            }
        }

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        window.clear(sf::Color(0x77, 0x77, 0x77, 255));

        window.pushGLStates();
        window.popGLStates();
        camera.Activate();
        model->drawPass();

        window.display();
    }

    delete model;
    return 0;
}
Пример #2
0
BOOL CTomGineThread::OnTask()
{
	m_running.Lock();
	
	m_mutex.Lock();
		tgEngine m_engine(m_width, m_height, 5.0f, 0.01f, "TomGine", true);
		
		if(m_use_campars)
		{
			TomGine::tgCamera cam;
			cam.Load(m_camPars);
			m_engine.SetCamera(cam);
			m_engine.UpdateCameraViews(cam);
		}
	m_mutex.Unlock();
	
	tgMaterial matBlueBlend;
	matBlueBlend.Color(0.0f, 0.0f, 1.0f, 0.5f);
	m_cone.m_material = matBlueBlend;
	
	tgShapeCreator m_shape_creator;
	m_shape_creator.CreateSphere(m_sphere, 0.1, 5, ICOSAHEDRON);
	m_shape_creator.CreateCone(m_cone, 1.0, 1.0, 16, 1, false);
// 	tgModel &model, float radius, float height, int slices, int stacks, bool closed
	
	glClearColor(1,1,1,0);
	
	while(!m_quit)
	{
		m_mutex.Lock();
			
			// Draw model
			m_pose.Activate();
				m_model.DrawFaces();
				
// 				for(unsigned i=0; i<m_viewlist.size(); i++)
// 				{
// 					m_viewlist[i].Activate();
// 					m_cone.DrawFaces();
// 				}
			
			// TODO test if Siftex is visible
			
			
			// Draw points
			glColor3f(0.0f,1.0f,0.0f);
			glDisable(GL_LIGHTING);
			glPointSize(2);
			glBegin(GL_POINTS);
			for(unsigned int i=0; i<m_siftexlist.size(); i++)
			{
				glVertex3f(m_siftexlist[i].pos.x, m_siftexlist[i].pos.y, m_siftexlist[i].pos.z);
			}
			glEnd();
			glEnable(GL_LIGHTING);
			
			// Draw normals
			glColor3f(0.0f, 0.0f, 1.0f);
			glDisable(GL_LIGHTING);
			glBegin(GL_LINES);
			for(unsigned int i=0; i<m_lastsiftexlist.size(); i++)
			{
				glVertex3f(m_lastsiftexlist[i].pos.x, m_lastsiftexlist[i].pos.y, m_lastsiftexlist[i].pos.z);
				glVertex3f(	m_lastsiftexlist[i].pos.x - m_lastsiftexlist[i].viewray.x,
										m_lastsiftexlist[i].pos.y - m_lastsiftexlist[i].viewray.y,
										m_lastsiftexlist[i].pos.z - m_lastsiftexlist[i].viewray.z);
			}
			glEnd();
			glEnable(GL_LIGHTING);
			
			for(unsigned i=0; i<m_viewlist.size(); i++)
			{
			  m_viewlist[i].Activate();
			  
			  glPushMatrix();
			  glScalef(m_viewscale[i].x,m_viewscale[i].y,m_viewscale[i].z);
			  glEnable(GL_BLEND);
			  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
			  m_cone.DrawFaces();
			  glDisable(GL_BLEND);
			  glPopMatrix();
			  
			  m_viewlist[i].Deactivate();
			}
			
			m_pose.Deactivate();
		m_mutex.Unlock();
		
		Sleep(10);
		
		m_engine.Update();
	}

	m_running.Unlock();
	return TRUE;
}