Example #1
0
int main(int argc, char **argv)
{
	Viewer *myViewer = new Viewer();
	myViewer->Init(argc, argv);
	myViewer->InitWorld();
	myViewer->SetValue(BUFFER, MDOUBLE);
	myViewer->CreateWin("AIEFG Assignment", 1000, 700);
	myViewer->InitCamera();
	myViewer->Show();

	return 0;
}
Example #2
0
/**
 * @function OnToolMovie
 * @brief
 * @date 2011-10-13
 */
void GRIPFrame::OnToolMovie(wxCommandEvent& event){
    wxString dirname = wxDirSelector(wxT("Choose output directory for movie pictures:")); // , "", wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST

    if ( dirname.empty() ){ // filename
        std::cout << "No Directory Selected" << std::endl;
	return;
    }

    string path = string(dirname.mb_str());

    char *buf = new char[1000];

	//Create a new Viewer Window
	wxFrame *movieFrame = new wxFrame(NULL,wxID_ANY, wxT("MovieWindow"),wxPoint(0, 0), wxSize(renderW,renderH),wxDEFAULT_FRAME_STYLE & ~ (wxRESIZE_BORDER | wxMAXIMIZE_BOX));
	//#ifndef WIN32 // Weird hack to make wxWidgets work in Linux
	movieFrame->Show();
	//#endif

	int attrib[] = {WX_GL_DOUBLEBUFFER,WX_GL_RGBA,	WX_GL_DEPTH_SIZE, 16,0};
	Viewer *movieViewer = new Viewer(movieFrame, viewer, wxID_ANY, wxPoint(0, 0), wxSize(renderW, renderH), 0, _T("MovieWindow"), attrib);
	movieViewer->backColor = viewer->backColor;
	movieViewer->gridColor = viewer->gridColor;	

	//movieFrame.AddChild(
	#ifdef WIN32  // Weird hack to make wxWidgets work with VC++ debug
	movieViewer->MSWSetOldWndProc((WXFARPROC)DefWindowProc);
	#endif

	int w,h;

	movieViewer->Show(true);
    movieViewer->Freeze();
    wxClientDC dc2(movieViewer);
    dc2.GetSize(&w, &h);
    movieViewer->InitGL();
    movieViewer->Thaw();
	movieViewer->handleEvents = false;
	movieViewer->Show(true);

	movieViewer->camT = viewer->camT;
	movieViewer->camRotT = viewer->camRotT;
	movieViewer->camRadius = viewer->camRadius;
	movieViewer->worldV = viewer->worldV;

    double curTargetTime = 0.0;
    std::vector<GRIPTimeSlice>::iterator it = timeVector.begin();
    int framesWritten = 0;

    double framerate = 30.0;

    do {
        if (it == timeVector.end()) break; // call it done
        while((*it).time < curTargetTime) it++;

		// Issue 122 from DART
        //mWorld->setState((*it).state);
		Eigen::VectorXd newState = (*it).state;   
    	setState_Issue122( newState );

        movieViewer->DrawGLScene();
        wxYield();

        unsigned char* imageData = (unsigned char*) malloc(w * h * 3);
        glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, imageData);
        wxImage img_ud(w,h,imageData);
        wxImage img = img_ud.Mirror(false);

        sprintf(buf, "%s/%06d.png",path.c_str(), framesWritten);

        wxString fname = wxString(buf,wxConvUTF8);
        cout << "Saving frame at t = " << (*it).time << " (targeting " << curTargetTime << ") into " << buf << "" << endl;
        img.SaveFile(fname, wxBITMAP_TYPE_PNG);

        framesWritten++;

        curTargetTime += 1.0 / framerate;
    } while (curTargetTime < timeVector.back().time);


	delete movieViewer;
	delete movieFrame;
	viewer->InitGL();

    delete buf;
    event.Skip();
}