int main (int argc, char ** argv) { ShapeContainer *shapes = new ShapeContainer(); shapes->addCircle(300,300,50,0.0,0.5,0.5); shapes->setVisible(true); shapes->setSelected(true); shape_cont.push_back(shapes); setCurrentContainer(shapes); glutInit(&argc, argv); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); glutInitWindowPosition(100, 100); win_w = 640; win_h = 480; glutInitWindowSize(640,480); glutCreateWindow("GLUT Window"); glutDisplayFunc(render); glutIdleFunc(idle); // glutIdleFunc(render); glutReshapeFunc(resizeWindow); glutKeyboardFunc(processNormalKeys); glutSpecialFunc(processSpecialKeys); glDisable(GL_DEPTH_TEST); glutMainLoop(); return 0; }
void reflection_animationApp::initShape() { // initialise shapes m_structure.init(m_shapeType, m_numlevels, m_incr, m_shapeDims.x, m_shapeDims.y); }
void MainWindow::open() { // std::cout << "opening file " << std::endl; QFileDialog::Options options; QString selectedFilter; QString fileName = QFileDialog::getOpenFileName(this, tr("open file"), QString(""), tr("All Files (*);;Text Files (*.txt)"), &selectedFilter, options); if (!fileName.isEmpty()) { std::ifstream data(fileName.toStdString().c_str(), std::ios_base::in); while(!data.eof()){ bool ok; std::string line; std::getline(data,line); // std::cout << "line = " << line << std::endl; if (line == "") continue; std::cout << "ShapeContainer" << std::endl; ShapeContainer *cont = new ShapeContainer(); QStringList cont_list = QString(line.c_str()).split(" "); QStringList cont_par = cont_list[1].split(","); cont->setLocation(cont_par.at(0).toFloat(),cont_par.at(1).toFloat()); cont->setColor(cont_par.at(4).toInt(&ok,10),cont_par.at(5).toInt(&ok,10),cont_par.at(6).toInt(&ok,10)); cont->setSelected(true); while( line != "***") { // std::cout << line << std::endl; QStringList list = QString(line.c_str()).split(" "); QStringList par = list[1].split(","); if (list[0] == "Shape"){ float x = par.at(0).toFloat(), y = par.at(1).toFloat(), w = par.at(2).toFloat(), h = par.at(3).toFloat(); int r = par.at(4).toInt(&ok,10), g = par.at(5).toInt(&ok,10), b = par.at(6).toInt(&ok,10); std::cout << "Shape("<<x<<","<<y<<","<<","<<w<<","<<h<<","<<r<<","<<g<<","<<b<<")"<<std::endl; Shape* shape = new Shape(x,y,w,h,r,g,b); cont->add(shape); } else if (list[0] == "Rectangle") { float x = par.at(0).toFloat(), y = par.at(1).toFloat(), w = par.at(2).toFloat(), h = par.at(3).toFloat(); int r = par.at(4).toInt(&ok,10), g = par.at(5).toInt(&ok,10), b = par.at(6).toInt(&ok,10); std::cout << "Rectangle(" << x << "," << y << "," << w << "," <<h<<","<<r<<","<<g<<","<<b<<")"<<std::endl; Shape *rect = new Rectangle(x,y,w,h,r,g,b); cont->add(rect); } else if (list[0] == "Circle") { float x = par.at(0).toFloat(), y = par.at(1).toFloat(), radius = par.at(2).toFloat(); int r = par.at(3).toInt(&ok,10), g = par.at(4).toInt(&ok,10), b = par.at(5).toInt(&ok,10); std::cout << "Circle("<<x<<","<<y<<","<<radius<<","<<r<<","<<g<<","<<b<<")"<<std::endl; Shape* circle = new Circle(x,y,radius,r,g,b); cont->add(circle); } std::getline(data,line); } shapeContainers.push_back(cont); std::cout << "***" << std::endl; } data.close(); if (shapeContainers.size()>0) setCurrentContainer(shapeContainers[0]); } }
void reflection_animationApp::draw() { // BACKGROUND gl::clear( Color( 0.0025f, 0.0025f, 0.0025f ) ); gl::enableDepthWrite( false ); gl::enableDepthRead( false ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // RENDER MODE switch (m_renderMode) { case ALPHA: gl::enableAlphaBlending(); break; case ADDITIVE: gl::enableAdditiveBlending(); break; default: gl::enableAlphaBlending(); break; } // DRAW // camera //m_eye = Vec3f( 0.0f, 0.0f, m_cameraDistance ); //m_camPers.lookAt( m_eye, m_center, m_up ); // matrices gl::setMatrices( m_mayaCam.getCamera() ); // draw pyramid m_structure.draw(); // GUI if (m_recording) { Surface frame = copyWindowSurface(); m_movieWriter.addFrame( frame ); } if(m_showInterface) params::InterfaceGl::draw(); }
void reflection_animationApp::update() { for( vector<Capture>::iterator cIt = m_capture.begin(); cIt != m_capture.end(); ++cIt ) { if( cIt->checkNewFrame() ) { m_surface = cIt->getSurface(); //m_textures[cIt - m_capture.begin()] = gl::Texture( m_surface ); } } // update master shape int tNow = getElapsedFrames(); m_structure.update(&m_surface, tNow); }
void MainWindow::MessageReceived(BMessage* message) { bool discard = false; // Figure out if we need the write lock on the Document. For most // messages we do, but exporting takes place in another thread and // locking is taken care of there. bool requiresWriteLock = true; switch (message->what) { case MSG_SAVE: case MSG_EXPORT: case MSG_SAVE_AS: case MSG_EXPORT_AS: requiresWriteLock = false; break; default: break; } if (requiresWriteLock && !fDocument->WriteLock()) { BWindow::MessageReceived(message); return; } if (message->WasDropped()) { const rgb_color* color; ssize_t length; // create styles from dropped colors for (int32 i = 0; message->FindData("RGBColor", B_RGB_COLOR_TYPE, i, (const void**)&color, &length) == B_OK; i++) { if (length != sizeof(rgb_color)) continue; char name[30]; sprintf(name, B_TRANSLATE_CONTEXT("Color (#%02x%02x%02x)", "Style name after dropping a color"), color->red, color->green, color->blue); Style* style = new (nothrow) Style(*color); style->SetName(name); Style* styles[1] = { style }; AddStylesCommand* styleCommand = new (nothrow) AddStylesCommand( fDocument->Icon()->Styles(), styles, 1, fDocument->Icon()->Styles()->CountStyles()); fDocument->CommandStack()->Perform(styleCommand); // don't handle anything else, // or we might paste the clipboard on B_PASTE discard = true; } } switch (message->what) { case B_REFS_RECEIVED: case B_SIMPLE_DATA: // If our icon is empty, open the file in this window, // otherwise forward to the application which will open // it in another window, unless we append. message->what = B_REFS_RECEIVED; if (fDocument->Icon()->Styles()->CountStyles() == 0 && fDocument->Icon()->Paths()->CountPaths() == 0 && fDocument->Icon()->Shapes()->CountShapes() == 0) { entry_ref ref; if (message->FindRef("refs", &ref) == B_OK) Open(ref); break; } if (modifiers() & B_SHIFT_KEY) { // We want the icon appended to this window. message->AddBool("append", true); message->AddPointer("window", this); } be_app->PostMessage(message); break; case B_PASTE: case B_MIME_DATA: { BMessage* clip = message; status_t err; if (discard) break; if (message->what == B_PASTE) { if (!be_clipboard->Lock()) break; clip = be_clipboard->Data(); } if (!clip || !clip->HasData("text/plain", B_MIME_TYPE)) { if (message->what == B_PASTE) be_clipboard->Unlock(); break; } Icon* icon = new (std::nothrow) Icon(*fDocument->Icon()); if (icon != NULL) { StyledTextImporter importer; err = importer.Import(icon, clip); if (err >= B_OK) { AutoWriteLocker locker(fDocument); SetIcon(NULL); // incorporate the loaded icon into the document // (either replace it or append to it) fDocument->MakeEmpty(false); // if append, the document savers are preserved fDocument->SetIcon(icon); SetIcon(icon); } } if (message->what == B_PASTE) be_clipboard->Unlock(); break; } case MSG_OPEN: // If our icon is empty, we want the icon to open in this // window. if (fDocument->Icon()->Styles()->CountStyles() == 0 && fDocument->Icon()->Paths()->CountPaths() == 0 && fDocument->Icon()->Shapes()->CountShapes() == 0) { message->AddPointer("window", this); } be_app->PostMessage(message); break; case MSG_SAVE: case MSG_EXPORT: { DocumentSaver* saver; if (message->what == MSG_SAVE) saver = fDocument->NativeSaver(); else saver = fDocument->ExportSaver(); if (saver != NULL) { saver->Save(fDocument); _PickUpActionBeforeSave(); break; } // else fall through } case MSG_SAVE_AS: case MSG_EXPORT_AS: { int32 exportMode; if (message->FindInt32("export mode", &exportMode) < B_OK) exportMode = EXPORT_MODE_MESSAGE; entry_ref ref; const char* name; if (message->FindRef("directory", &ref) == B_OK && message->FindString("name", &name) == B_OK) { // this message comes from the file panel BDirectory dir(&ref); BEntry entry; if (dir.InitCheck() >= B_OK && entry.SetTo(&dir, name, true) >= B_OK && entry.GetRef(&ref) >= B_OK) { // create the document saver and remember it for later DocumentSaver* saver = _CreateSaver(ref, exportMode); if (saver != NULL) { if (fDocument->WriteLock()) { if (exportMode == EXPORT_MODE_MESSAGE) fDocument->SetNativeSaver(saver); else fDocument->SetExportSaver(saver); _UpdateWindowTitle(); fDocument->WriteUnlock(); } saver->Save(fDocument); _PickUpActionBeforeSave(); } } // TODO: ... // _SyncPanels(fSavePanel, fOpenPanel); } else { // configure the file panel uint32 requestRefWhat = MSG_SAVE_AS; bool isExportMode = message->what == MSG_EXPORT_AS || message->what == MSG_EXPORT; if (isExportMode) requestRefWhat = MSG_EXPORT_AS; const char* saveText = _FileName(isExportMode); BMessage requestRef(requestRefWhat); if (saveText != NULL) requestRef.AddString("save text", saveText); requestRef.AddMessenger("target", BMessenger(this, this)); be_app->PostMessage(&requestRef); } break; } case B_CANCEL: // FilePanel was canceled, do not execute the fMessageAfterSave // next time a file panel is used, in case it was set! delete fMessageAfterSave; fMessageAfterSave = NULL; break; case MSG_UNDO: fDocument->CommandStack()->Undo(); break; case MSG_REDO: fDocument->CommandStack()->Redo(); break; case MSG_UNDO_STACK_CHANGED: { // relable Undo item and update enabled status BString label(B_TRANSLATE("Undo")); fUndoMI->SetEnabled(fDocument->CommandStack()->GetUndoName(label)); if (fUndoMI->IsEnabled()) fUndoMI->SetLabel(label.String()); else { fUndoMI->SetLabel(B_TRANSLATE_CONTEXT("<nothing to undo>", "Icon-O-Matic-Menu-Edit")); } // relable Redo item and update enabled status label.SetTo(B_TRANSLATE("Redo")); fRedoMI->SetEnabled(fDocument->CommandStack()->GetRedoName(label)); if (fRedoMI->IsEnabled()) fRedoMI->SetLabel(label.String()); else { fRedoMI->SetLabel(B_TRANSLATE_CONTEXT("<nothing to redo>", "Icon-O-Matic-Menu-Edit")); } break; } case MSG_MOUSE_FILTER_MODE: { uint32 mode; if (message->FindInt32("mode", (int32*)&mode) == B_OK) fCanvasView->SetMouseFilterMode(mode); break; } case MSG_ADD_SHAPE: { AddStylesCommand* styleCommand = NULL; Style* style = NULL; if (message->HasBool("style")) { new_style(fCurrentColor->Color(), fDocument->Icon()->Styles(), &style, &styleCommand); } AddPathsCommand* pathCommand = NULL; VectorPath* path = NULL; if (message->HasBool("path")) { new_path(fDocument->Icon()->Paths(), &path, &pathCommand); } if (!style) { // use current or first style int32 currentStyle = fStyleListView->CurrentSelection(0); style = fDocument->Icon()->Styles()->StyleAt(currentStyle); if (!style) style = fDocument->Icon()->Styles()->StyleAt(0); } Shape* shape = new (nothrow) Shape(style); Shape* shapes[1]; shapes[0] = shape; AddShapesCommand* shapeCommand = new (nothrow) AddShapesCommand( fDocument->Icon()->Shapes(), shapes, 1, fDocument->Icon()->Shapes()->CountShapes(), fDocument->Selection()); if (path && shape) shape->Paths()->AddPath(path); ::Command* command = NULL; if (styleCommand || pathCommand) { if (styleCommand && pathCommand) { Command** commands = new Command*[3]; commands[0] = styleCommand; commands[1] = pathCommand; commands[2] = shapeCommand; command = new CompoundCommand(commands, 3, B_TRANSLATE_CONTEXT("Add shape with path & style", "Icon-O-Matic-Menu-Shape"), 0); } else if (styleCommand) { Command** commands = new Command*[2]; commands[0] = styleCommand; commands[1] = shapeCommand; command = new CompoundCommand(commands, 2, B_TRANSLATE_CONTEXT("Add shape with style", "Icon-O-Matic-Menu-Shape"), 0); } else { Command** commands = new Command*[2]; commands[0] = pathCommand; commands[1] = shapeCommand; command = new CompoundCommand(commands, 2, B_TRANSLATE_CONTEXT("Add shape with path", "Icon-O-Matic-Menu-Shape"), 0); } } else { command = shapeCommand; } fDocument->CommandStack()->Perform(command); break; } // TODO: listen to selection in CanvasView to add a manipulator case MSG_PATH_SELECTED: { VectorPath* path; if (message->FindPointer("path", (void**)&path) < B_OK) path = NULL; fPathListView->SetCurrentShape(NULL); fStyleListView->SetCurrentShape(NULL); fTransformerListView->SetShape(NULL); fState->DeleteManipulators(); if (fDocument->Icon()->Paths()->HasPath(path)) { PathManipulator* pathManipulator = new (nothrow) PathManipulator(path); fState->AddManipulator(pathManipulator); } break; } case MSG_STYLE_SELECTED: case MSG_STYLE_TYPE_CHANGED: { Style* style; if (message->FindPointer("style", (void**)&style) < B_OK) style = NULL; if (!fDocument->Icon()->Styles()->HasStyle(style)) style = NULL; fStyleView->SetStyle(style); fPathListView->SetCurrentShape(NULL); fStyleListView->SetCurrentShape(NULL); fTransformerListView->SetShape(NULL); fState->DeleteManipulators(); Gradient* gradient = style ? style->Gradient() : NULL; if (gradient != NULL) { TransformGradientBox* transformBox = new (nothrow) TransformGradientBox(fCanvasView, gradient, NULL); fState->AddManipulator(transformBox); } break; } case MSG_SHAPE_SELECTED: { Shape* shape; if (message->FindPointer("shape", (void**)&shape) < B_OK) shape = NULL; if (!fIcon || !fIcon->Shapes()->HasShape(shape)) shape = NULL; fPathListView->SetCurrentShape(shape); fStyleListView->SetCurrentShape(shape); fTransformerListView->SetShape(shape); BList selectedShapes; ShapeContainer* shapes = fDocument->Icon()->Shapes(); int32 count = shapes->CountShapes(); for (int32 i = 0; i < count; i++) { shape = shapes->ShapeAtFast(i); if (shape->IsSelected()) { selectedShapes.AddItem((void*)shape); } } fState->DeleteManipulators(); if (selectedShapes.CountItems() > 0) { TransformShapesBox* transformBox = new (nothrow) TransformShapesBox( fCanvasView, (const Shape**)selectedShapes.Items(), selectedShapes.CountItems()); fState->AddManipulator(transformBox); } break; } case MSG_RENAME_OBJECT: fPropertyListView->FocusNameProperty(); break; default: BWindow::MessageReceived(message); } if (requiresWriteLock) fDocument->WriteUnlock(); }
MultiShape::MultiShape(const ShapeContainer& ToAdd) { this->Shapes.insert(this->Shapes.end(),ToAdd.begin(),ToAdd.end()); }
// Export status_t MessageExporter::Export(const Icon* icon, BPositionIO* stream) { status_t ret = B_OK; BMessage archive; PathContainer* paths = icon->Paths(); StyleContainer* styles = icon->Styles(); // paths if (ret == B_OK) { BMessage allPaths; int32 count = paths->CountPaths(); for (int32 i = 0; i < count; i++) { VectorPath* path = paths->PathAtFast(i); BMessage pathArchive; ret = _Export(path, &pathArchive); if (ret < B_OK) break; ret = allPaths.AddMessage("path", &pathArchive); if (ret < B_OK) break; } if (ret == B_OK) ret = archive.AddMessage("paths", &allPaths); } // styles if (ret == B_OK) { BMessage allStyles; int32 count = styles->CountStyles(); for (int32 i = 0; i < count; i++) { Style* style = styles->StyleAtFast(i); BMessage styleArchive; ret = _Export(style, &styleArchive); if (ret < B_OK) break; ret = allStyles.AddMessage("style", &styleArchive); if (ret < B_OK) break; } if (ret == B_OK) ret = archive.AddMessage("styles", &allStyles); } // shapes if (ret == B_OK) { BMessage allShapes; ShapeContainer* shapes = icon->Shapes(); int32 count = shapes->CountShapes(); for (int32 i = 0; i < count; i++) { Shape* shape = shapes->ShapeAtFast(i); BMessage shapeArchive; ret = _Export(shape, paths, styles, &shapeArchive); if (ret < B_OK) break; ret = allShapes.AddMessage("shape", &shapeArchive); if (ret < B_OK) break; } if (ret == B_OK) ret = archive.AddMessage("shapes", &allShapes); } // prepend the magic number to the file which // later tells us that this file is one of us if (ret == B_OK) { ssize_t size = sizeof(uint32); uint32 magic = B_HOST_TO_BENDIAN_INT32(kNativeIconMagicNumber); ssize_t written = stream->Write(&magic, size); if (written != size) { if (written < 0) ret = (status_t)written; else ret = B_IO_ERROR; } } if (ret == B_OK) ret = archive.Flatten(stream); return ret; }
void reflection_animationApp::setup() { // STRUCTURE m_shapeDims = Vec3f(50, 75, 50); m_numlevels = 12; m_incr = 2; m_shapeType = PYRAMID; initShape(); cout << m_structure.m_shapes.size() << endl; // DISPLAY m_showInterface = true; m_recording = false; m_path = getHomeDirectory() / "Desktop/"; m_showColour = true; m_renderMode = ALPHA; m_contrast = 4.0f; m_alpha = .45f; m_face1Display = ACTIVE; m_face2Display = DICHROIC1; m_face3Display = GLASS; m_face4Display = NONE; m_dichroic1Colour = Color(0.3f, 0.8f, 1.0f); m_dichroic2Colour = Color(1.0f, 0.8f, 0.3f); // ANIMATION m_aniMode = VIDEO; // radar m_interval = 360; m_frontarea = 1.5f; m_backarea = 6.0f; // GUI m_params = params::InterfaceGl( "Geometry/Animation Parameters [press TAB to hide]", Vec2i( 400, 600 ) ); // render m_params.addText( "render", "label=`Render`" ); m_params.addSeparator(); vector<string> rstrs; rstrs.push_back("ALPHA"); rstrs.push_back("ADDITIVE"); rstrs.push_back("MULTIPLY"); m_params.addParam( "Render Mode", rstrs, (int*)&m_renderMode ); m_params.addParam( "Use Colour", &m_showColour ); m_params.addParam( "Alpha", &m_alpha, "min=0.001 max=2.0 step=0.1" ); m_params.addParam( "Contrast", &m_contrast, "min=0.001 max=5.0 step=0.1" ); m_params.addParam( "Dichroic Colour 1", &m_dichroic1Colour ); m_params.addParam( "Dichroic Colour 2", &m_dichroic2Colour ); m_params.addText( "emptyline1", "label=` `" ); // structure m_params.addText( "structure", "label=`Structure`" ); m_params.addSeparator(); vector<string> dstrs; dstrs.push_back("ACTIVE"); dstrs.push_back("DICHROIC1"); dstrs.push_back("DICHROIC2"); dstrs.push_back("GLASS"); dstrs.push_back("NONE"); m_params.addParam( "Face 1 Display mode", dstrs, (int*)&m_face1Display ); m_params.addParam( "Face 2 Display mode", dstrs, (int*)&m_face2Display ); m_params.addParam( "Face 3 Display mode", dstrs, (int*)&m_face3Display ); m_params.addParam( "Face 4 Display mode", dstrs, (int*)&m_face4Display ); m_params.addText( "emptyline2", "label=` `" ); // generate shape m_params.addText( "generate", "label=`Generate`" ); m_params.addSeparator(); vector<string> sstrs; sstrs.push_back("PYRAMID"); sstrs.push_back("TETRAHEDRON"); sstrs.push_back("HOLLOW PYRAMID"); m_params.addParam( "Shape", sstrs, (int*)&m_shapeType ); m_params.addParam( "Number Of Levels", &m_numlevels ); m_params.addParam( "Vertical Interval", &m_incr ); m_params.addParam( "Shape Dimensions", &m_shapeDims ); m_params.addButton( "Recreate Shape", std::bind( &reflection_animationApp::initShape, this ) ); m_params.addText( "emptyline3", "label=` `" ); // animation m_params.addText( "animation", "label=`Animation`" ); m_params.addSeparator(); vector<string> astrs; astrs.push_back("STATIC"); astrs.push_back("RADAR"); astrs.push_back("VIDEO"); astrs.push_back("VIDEO_RADAR"); m_params.addParam( "Animation Mode", astrs, (int*)&m_aniMode ); m_params.addParam( "Interval", &m_interval ); m_params.addParam( "Size (front)", &m_frontarea ); m_params.addParam( "Size (tail)", &m_backarea ); m_params.addButton( "Recreate Shape", std::bind( &reflection_animationApp::initShape, this ) ); // CAMERA/PERSPECTIVE (not updated anymore -> mayacam) m_cameraDistance = 800.0f; m_eye = Vec3f( 0.0f, 0.0f, m_cameraDistance ); m_center = Vec3f::zero(); m_up = Vec3f::yAxis(); CameraPersp cam; cam.setEyePoint(m_eye); cam.setCenterOfInterestPoint(m_center); cam.setWorldUp(m_up); cam.setPerspective(60.0, getWindowAspectRatio(), 5.0, 5000.0); m_mayaCam.setCurrentCam( cam ); // CAPTURE/VIDEO/INPUT m_surface = Surface8u(600, 400, true); vector<Capture::DeviceRef> devices( Capture::getDevices() ); for( vector<Capture::DeviceRef>::const_iterator deviceIt = devices.begin(); deviceIt != devices.end(); ++deviceIt ) { Capture::DeviceRef device = *deviceIt; console() << "Found Device " << device->getName() << " ID: " << device->getUniqueId() << std::endl; try { if( device->checkAvailable() ) { m_capture.push_back( Capture( 600, 400, device ) ); m_capture.back().start(); // placeholder texture m_textures.push_back( gl::Texture() ); } else console() << "device is NOT available" << std::endl; } catch( CaptureExc & ) { console() << "Unable to initialize device: " << device->getName() << endl; } } // these should actually only be updated on change --> pointers to parameters DisplayMode* faceModesArr[] = { &m_face1Display, &m_face2Display, &m_face3Display, &m_face4Display }; vector<DisplayMode*> p_faceModes(faceModesArr, faceModesArr+4); m_structure.setMaterialSettings( p_faceModes, &m_showColour, &m_alpha, &m_contrast ); m_structure.setAnimationSettings( &m_aniMode ); m_structure.setRadarSettings( &m_interval, &m_frontarea, &m_backarea); }