int resizeWindow(render_context_type *rc, int width, int height ) { int x0,y0; static uint32_t w_width; static uint32_t w_height; w_width=width; w_height=height; if(width/RATIO > height) { w_width=height*RATIO; w_height=height; x0=(width-w_width)/2; y0=0; } else { w_width=width; w_height=width/RATIO; x0=0; y0=(height-w_height)/2; } rc->sdl_surface = SDL_SetVideoMode(width, height, 0, SDL_OPENGL |SDL_RESIZABLE | SDL_GL_DOUBLEBUFFER ); /* Setup our viewport. */ glViewport( x0, y0, ( GLsizei )w_width, ( GLsizei )w_height ); /* change to the projection matrix and set our viewing volume. */ set_perspective(); return 1; }
void Viewer::reset_perspective_screen() { double aspect = ((double)get_width()) / get_height(); double fovRadians = fovDegrees*M_PI/180.0; set_perspective(fovRadians, aspect, near, far); invalidate(); }
gint glarea_init (GtkWidget* widget, gpointer data) { // printf ("GLAREA_INIT - Realize Event\n"); gl_preview_struct *gl_hf = (gl_preview_struct *) data; GdkGLContext *glcontext = gtk_widget_get_gl_context (widget); GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget); /*** OpenGL BEGIN ***/ if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext)) { my_msg(_("Not able to display the Open GL preview"),WARNING); return FALSE; } glClearColor(0.0,0.0,0.0,1.0); glEnable(GL_DEPTH_TEST); glPolygonMode(GL_FRONT, GL_FILL); // glDisable(GL_CULL_FACE); set_perspective (gl_hf->cameras[gl_hf->current_camera_id]); // Lights glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glLightfv(GL_LIGHT0, GL_DIFFUSE, l0dif); glLightfv(GL_LIGHT0, GL_SPECULAR, l0dif); glLightfv(GL_LIGHT1, GL_DIFFUSE, l1dif); glLightfv(GL_LIGHT1, GL_SPECULAR, l1dif); glEnable(GL_COLOR_MATERIAL); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ; // Materials glMaterialfv(GL_FRONT, GL_SPECULAR, mspec); glMaterialf(GL_FRONT, GL_SHININESS, mshiny); glShadeModel (GL_SMOOTH); if (gdk_gl_drawable_is_double_buffered (gldrawable)) gdk_gl_drawable_swap_buffers (gldrawable); else glFlush (); gdk_gl_drawable_gl_end (gldrawable); return TRUE; }
static void angle_w_upd (GtkWidget *wdg, gpointer data) { // Angle variation // Specified in the widget as horizontal (the Povray standard), // must be transformed to vertical in OpenGL gl_preview_struct *gl_preview = (gl_preview_struct *) data; camera_struct *camera = gl_preview->cameras[gl_preview->current_camera_id]; if (camera->angle_w == (gint) GTK_ADJUSTMENT(wdg)->value) return; camera->angle_w = (gint) GTK_ADJUSTMENT(wdg)->value; set_perspective(camera); FLAG_CAMERA_CHANGE = TRUE; gl_draw (GTK_WIDGET(gl_preview->gl_area)); // gtk_widget_queue_draw(GTK_WIDGET(gl_preview->gl_area)); }
void InterpolatedCamera::_notification(int p_what) { switch(p_what) { case NOTIFICATION_ENTER_SCENE: { if (get_scene()->is_editor_hint() && enabled) set_fixed_process(false); } break; case NOTIFICATION_PROCESS: { if (!enabled) break; if (has_node(target)) { Spatial *node = get_node(target)->cast_to<Spatial>(); if (!node) break; float delta = speed*get_process_delta_time(); Transform target_xform = node->get_global_transform(); Transform local_transform = get_transform(); local_transform = local_transform.interpolate_with(target_xform,delta); set_global_transform(local_transform); if (node->cast_to<Camera>()) { Camera *cam = node->cast_to<Camera>(); if (cam->get_projection()==get_projection()) { float new_near = Math::lerp(get_znear(),cam->get_znear(),delta); float new_far = Math::lerp(get_zfar(),cam->get_zfar(),delta); if (cam->get_projection()==PROJECTION_ORTHOGONAL) { float size = Math::lerp(get_size(),cam->get_size(),delta); set_orthogonal(size,new_near,new_far); } else { float fov = Math::lerp(get_fov(),cam->get_fov(),delta); set_perspective(fov,new_near,new_far); } } } } } break; } }
void Camera::_update_camera_mode() { force_change = true; switch (mode) { case PROJECTION_PERSPECTIVE: { set_perspective(fov, near, far); } break; case PROJECTION_ORTHOGONAL: { set_orthogonal(size, near, far); } break; } }
Camera::Camera() { camera = VisualServer::get_singleton()->camera_create(); size=1; fov=0; near=0; far=0; current=false; viewport_ptr=NULL; force_change=false; mode=PROJECTION_PERSPECTIVE; set_perspective(60.0,0.1,100.0); keep_aspect=KEEP_HEIGHT; layers=0xFFFFFFFF; //active=false; }
void stage4_draw() { set_perspective(&bgcontext, 130, 3000); draw_stage3d(&bgcontext, 4000); if(bgcontext.cx[2] >= -1000 && bgcontext.cv[2] > 0) bgcontext.cv[2] -= 0.17; if(bgcontext.cx[1] < 100 && bgcontext.cv[2] < 0) bgcontext.cv[2] = 0; if(bgcontext.cx[2] >= 0 && bgcontext.cx[2] <= 10) bgcontext.cv[1] += 0.2; if(bgcontext.cx[1] >= 1200 && bgcontext.cx[1] <= 2000) bgcontext.cv[1] += 0.02; }
Camera::Camera() { camera = VisualServer::get_singleton()->camera_create(); size=1; fov=0; near=0; far=0; current=false; force_change=false; mode=PROJECTION_PERSPECTIVE; set_perspective(60.0,0.1,100.0); keep_aspect=KEEP_HEIGHT; layers=0xfffff; v_offset=0; h_offset=0; VisualServer::get_singleton()->camera_set_visible_layers(camera,layers); //active=false; }
void init_opengl(render_context_type *rc) { SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 8 ); if (NULL == (rc->sdl_surface = SDL_SetVideoMode(WINDOW_W, WINDOW_H, 0, SDL_OPENGL |SDL_RESIZABLE ))) { printf("Can't set OpenGL mode: %s\n", SDL_GetError()); SDL_Quit(); exit(1); } glClearColor(0.0,0.0,0.0,0.0); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1); SDL_WM_SetCaption("video capture",NULL); glViewport(0,0,WINDOW_W,WINDOW_H); glEnable(GL_TEXTURE_2D); glEnable(GL_LINE_SMOOTH); glEnable(GL_POINT_SMOOTH); glShadeModel(GL_SMOOTH); glClearStencil(0); glClearDepth(1.0f); glGenTextures(1,&rc->fb_texture); set_perspective(); }
int mainwin::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QMainWindow::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: actTrack(); break; case 1: actCalibrate(); break; case 2: actPerspective(); break; case 3: set_track(); break; case 4: set_calibrate(); break; case 5: set_perspective(); break; case 6: about(); break; case 7: updateStats(); break; case 8: end_signal(); break; case 9: play(); break; case 10: finished_play(); break; default: ; } _id -= 11; } return _id; }
int main() { set_perspective(1, 100.0); init(); //clear the screen draw_rect(0,0,320,240,0x0); flush_to_lcd(); uint32_t count = 1; char str[10]; uint16_t colors[] = {0xF800, 0xF600, 0x7E0, 0x1F, 0xFFFF,0xF800, 0xF600, 0x7E0, 0x1F, 0xFFFF,0xF800, 0xF600, 0x7E0, 0x1F, 0xFFFF}; //int16_t centerx = 320/2; //int16_t centery = 240/2; //int16_t polysize = 30; int16_t rot = 0; polygon poly; #ifdef FORAERY for (;;) #endif { count = 0; START_MEASURING_CYCLES(); rot++; if (rot >= 360) rot = 0; /* for (int i = 0; i < 15; i++) { poly.x0 = (i-7)*20+centerx+lcd_cos(rot+120)*polysize; poly.y0 = centery+lcd_sin(rot+120)*polysize; poly.x1 = (i-7)*20+centerx+lcd_cos(rot+120*2)*polysize; poly.y1 = centery+lcd_sin(rot+120*2)*polysize; poly.x2 = (i-7)*20+centerx+lcd_cos(rot+120*3)*polysize; poly.y2 = centery+lcd_sin(rot+120*3)*polysize; draw_b_poly(poly, colors[i]); } for (int i = 0; i < 15; i++) { poly.x0 = (i-7)*20+centerx+lcd_cos(rot+120)*polysize; poly.y0 = 20+centery+lcd_sin(rot+120)*polysize; poly.x1 = (i-7)*20+centerx+lcd_cos(rot+120*2)*polysize; poly.y1 = 20+centery+lcd_sin(rot+120*2)*polysize; poly.x2 = (i-7)*20+centerx+lcd_cos(rot+120*3)*polysize; poly.y2 = 20+centery+lcd_sin(rot+120*3)*polysize; draw_b_poly(poly, colors[i]); } */ translate_camera(Vector3D(0,1,4)); rotate_camera(20,lcd_sin(rot)*180.0, 0); Polygon3D p; //front p.p0 = Vector3D(-1, 1, 1); p.p1 = Vector3D(-1,-1, 1); p.p2 = Vector3D( 1,-1, 1); draw_poly3D(p, colors[0]); p.p0 = Vector3D(-1, 1, 1); p.p1 = Vector3D( 1,-1, 1); p.p2 = Vector3D( 1, 1, 1); draw_poly3D(p, colors[0]); //left side p.p0 = Vector3D(-1, 1, -1); p.p1 = Vector3D(-1,-1, -1); p.p2 = Vector3D(-1,-1, 1); draw_poly3D(p, colors[1]); p.p0 = Vector3D(-1, 1,-1); p.p1 = Vector3D(-1,-1, 1); p.p2 = Vector3D(-1, 1, 1); draw_poly3D(p, colors[1]); //right side p.p0 = Vector3D( 1, 1, 1); p.p1 = Vector3D( 1,-1, 1); p.p2 = Vector3D( 1,-1,-1); draw_poly3D(p, colors[2]); p.p0 = Vector3D( 1, 1, 1); p.p1 = Vector3D( 1,-1,-1); p.p2 = Vector3D( 1, 1,-1); draw_poly3D(p, colors[2]); //backside p.p0 = Vector3D( 1, 1,-1); p.p1 = Vector3D( 1,-1,-1); p.p2 = Vector3D(-1,-1,-1); draw_poly3D(p, colors[3]); p.p0 = Vector3D( 1, 1,-1); p.p1 = Vector3D(-1,-1,-1); p.p2 = Vector3D(-1, 1,-1); draw_poly3D(p,colors[3]); //top p.p0 = Vector3D(-1, 1,-1); p.p1 = Vector3D(-1, 1, 1); p.p2 = Vector3D( 1, 1, 1); draw_poly3D(p, colors[4]); p.p0 = Vector3D(-1, 1,-1); p.p1 = Vector3D( 1, 1, 1); p.p2 = Vector3D( 1, 1,-1); draw_poly3D(p, colors[4]); draw_poly_buffer(); draw_text(str,0,220,0xF800); flush_to_lcd(); END_MEASURING_CYCLES(count); #ifdef FORAERY itoa(66000000/count,str); #endif } #ifdef FORPC while (sfmlwindow.isOpen()) { //input sf::Vector2i localPosition = sf::Mouse::getPosition(sfmlwindow); if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) { //std::cout<<"x: " <<localPosition.x << " y: " << localPosition.y <<"\n"; } sf::Event eventti; while (sfmlwindow.pollEvent(eventti)) { switch(eventti.type) { case sf::Event::Closed: sfmlwindow.close(); break; default: break; } } //logic rot++; if (rot >= 360) rot = 0; translate_camera(Vector3D(0,1,4)); rotate_camera(20,lcd_sin(rot)*180.0, 0); Polygon3D p; //front p.p0 = Vector3D(-1, 1, 1); p.p1 = Vector3D(-1,-1, 1); p.p2 = Vector3D( 1,-1, 1); draw_poly3D(p, colors[0]); p.p0 = Vector3D(-1, 1, 1); p.p1 = Vector3D( 1,-1, 1); p.p2 = Vector3D( 1, 1, 1); draw_poly3D(p, colors[0]); //left side p.p0 = Vector3D(-1, 1, -1); p.p1 = Vector3D(-1,-1, -1); p.p2 = Vector3D(-1,-1, 1); draw_poly3D(p, colors[1]); p.p0 = Vector3D(-1, 1,-1); p.p1 = Vector3D(-1,-1, 1); p.p2 = Vector3D(-1, 1, 1); draw_poly3D(p, colors[1]); //right side p.p0 = Vector3D( 1, 1, 1); p.p1 = Vector3D( 1,-1, 1); p.p2 = Vector3D( 1,-1,-1); draw_poly3D(p, colors[2]); p.p0 = Vector3D( 1, 1, 1); p.p1 = Vector3D( 1,-1,-1); p.p2 = Vector3D( 1, 1,-1); draw_poly3D(p, colors[2]); //backside p.p0 = Vector3D( 1, 1,-1); p.p1 = Vector3D( 1,-1,-1); p.p2 = Vector3D(-1,-1,-1); draw_poly3D(p, colors[3]); p.p0 = Vector3D( 1, 1,-1); p.p1 = Vector3D(-1,-1,-1); p.p2 = Vector3D(-1, 1,-1); draw_poly3D(p,colors[3]); //top p.p0 = Vector3D(-1, 1,-1); p.p1 = Vector3D(-1, 1, 1); p.p2 = Vector3D( 1, 1, 1); draw_poly3D(p, colors[4]); p.p0 = Vector3D(-1, 1,-1); p.p1 = Vector3D( 1, 1, 1); p.p2 = Vector3D( 1, 1,-1); draw_poly3D(p, colors[4]); draw_poly_buffer(); draw_text(str,0,220,0xF800); flush_to_lcd(); //render simscreen_render(); sfmlwindow.display(); //sleep sf::sleep(sf::milliseconds(33)); } #endif return 0; }
/** * \fn void dialog_simulator_create() * \brief Function to create the main window. */ void dialog_simulator_create () { static char *str_exit, *str_options, *str_start, *str_stop, *str_save, *str_help; static char *tip_exit, *tip_options, *tip_start, *tip_stop, *tip_save, *tip_help; DialogSimulator *dlg; #if DEBUG printf ("dialog_simulator_create: start\n"); #endif dlg = dialog_simulator; #if HAVE_SDL exit_event->type = SDL_QUIT; #endif str_options = gettext ("_Options"); str_start = gettext ("S_tart"); str_stop = gettext ("Sto_p"); str_save = gettext ("_Save"); str_help = gettext ("_Help"); str_exit = gettext ("E_xit"); tip_options = gettext ("Fractal options"); tip_start = gettext ("Start fractal growing"); tip_stop = gettext ("Stop fractal growing"); tip_save = gettext ("Save graphical"); tip_help = gettext ("Help"); tip_exit = gettext ("Exit"); dlg->toolbar = (GtkToolbar *) gtk_toolbar_new (); dlg->button_options = (GtkToolButton *) gtk_tool_button_new (gtk_image_new_from_icon_name ("preferences-system", GTK_ICON_SIZE_SMALL_TOOLBAR), str_options); gtk_widget_set_tooltip_text (GTK_WIDGET (dlg->button_options), tip_options); gtk_toolbar_insert (dlg->toolbar, GTK_TOOL_ITEM (dlg->button_options), -1); g_signal_connect (dlg->button_options, "clicked", dialog_options_create, NULL); dlg->button_start = (GtkToolButton *) gtk_tool_button_new (gtk_image_new_from_icon_name ("system-run", GTK_ICON_SIZE_SMALL_TOOLBAR), str_start); gtk_widget_set_tooltip_text (GTK_WIDGET (dlg->button_start), tip_start); gtk_toolbar_insert (dlg->toolbar, GTK_TOOL_ITEM (dlg->button_start), -1); g_signal_connect (dlg->button_start, "clicked", fractal, NULL); dlg->button_stop = (GtkToolButton *) gtk_tool_button_new (gtk_image_new_from_icon_name ("process-stop", GTK_ICON_SIZE_SMALL_TOOLBAR), str_stop); gtk_widget_set_tooltip_text (GTK_WIDGET (dlg->button_stop), tip_stop); gtk_toolbar_insert (dlg->toolbar, GTK_TOOL_ITEM (dlg->button_stop), -1); g_signal_connect (dlg->button_stop, "clicked", fractal_stop, NULL); dlg->button_save = (GtkToolButton *) gtk_tool_button_new (gtk_image_new_from_icon_name ("document-save", GTK_ICON_SIZE_SMALL_TOOLBAR), str_save); gtk_widget_set_tooltip_text (GTK_WIDGET (dlg->button_save), tip_save); gtk_toolbar_insert (dlg->toolbar, GTK_TOOL_ITEM (dlg->button_save), -1); g_signal_connect (dlg->button_save, "clicked", dialog_simulator_save, NULL); dlg->button_help = (GtkToolButton *) gtk_tool_button_new (gtk_image_new_from_icon_name ("help-about", GTK_ICON_SIZE_SMALL_TOOLBAR), str_help); gtk_widget_set_tooltip_text (GTK_WIDGET (dlg->button_help), tip_help); gtk_toolbar_insert (dlg->toolbar, GTK_TOOL_ITEM (dlg->button_help), -1); g_signal_connect (dlg->button_help, "clicked", dialog_simulator_help, NULL); dlg->button_exit = (GtkToolButton *) gtk_tool_button_new (gtk_image_new_from_icon_name ("application-exit", GTK_ICON_SIZE_SMALL_TOOLBAR), str_exit); gtk_widget_set_tooltip_text (GTK_WIDGET (dlg->button_exit), tip_exit); gtk_toolbar_insert (dlg->toolbar, GTK_TOOL_ITEM (dlg->button_exit), -1); #if HAVE_FREEGLUT g_signal_connect (dlg->button_exit, "clicked", glutLeaveMainLoop, NULL); #elif HAVE_SDL g_signal_connect_swapped (dlg->button_exit, "clicked", (void (*)) SDL_PushEvent, exit_event); #elif HAVE_GLFW g_signal_connect (dlg->button_exit, "clicked", (void (*)) window_close, NULL); #endif dlg->label_time = (GtkLabel *) gtk_label_new (gettext ("Calculating time")); dlg->entry_time = (GtkSpinButton *) gtk_spin_button_new_with_range (0., 1.e6, 0.1); gtk_widget_set_sensitive (GTK_WIDGET (dlg->entry_time), 0); dlg->progress = (GtkProgressBar *) gtk_progress_bar_new (); gtk_progress_bar_set_text (dlg->progress, gettext ("Progress")); dlg->hscale = (GtkScale *) gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, -90., 0., 1.); dlg->vscale = (GtkScale *) gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, 0., 90., 1.); gtk_scale_set_digits (dlg->hscale, 0); gtk_scale_set_digits (dlg->vscale, 0); gtk_range_set_value (GTK_RANGE (dlg->hscale), phid); gtk_range_set_value (GTK_RANGE (dlg->vscale), thetad); g_signal_connect (dlg->hscale, "value-changed", set_perspective, NULL); g_signal_connect (dlg->vscale, "value-changed", set_perspective, NULL); dlg->label_horizontal = (GtkLabel *) gtk_label_new (gettext ("Horizontal perspective angle (º)")); dlg->label_vertical = (GtkLabel *) gtk_label_new (gettext ("Vertical perspective angle (º)")); dlg->grid = (GtkGrid *) gtk_grid_new (); gtk_grid_attach (dlg->grid, GTK_WIDGET (dlg->toolbar), 0, 0, 3, 1); gtk_grid_attach (dlg->grid, GTK_WIDGET (dlg->progress), 0, 1, 1, 1); gtk_grid_attach (dlg->grid, GTK_WIDGET (dlg->label_time), 1, 1, 1, 1); gtk_grid_attach (dlg->grid, GTK_WIDGET (dlg->entry_time), 2, 1, 1, 1); gtk_grid_attach (dlg->grid, GTK_WIDGET (dlg->label_horizontal), 0, 2, 1, 1); gtk_grid_attach (dlg->grid, GTK_WIDGET (dlg->hscale), 1, 2, 2, 1); gtk_grid_attach (dlg->grid, GTK_WIDGET (dlg->label_vertical), 0, 3, 1, 1); gtk_grid_attach (dlg->grid, GTK_WIDGET (dlg->vscale), 1, 3, 2, 1); dlg->logo = gtk_image_get_pixbuf (GTK_IMAGE (gtk_image_new_from_file ("logo.png"))); dlg->logo_min = gtk_image_get_pixbuf (GTK_IMAGE (gtk_image_new_from_file ("logo2.png"))); dlg->window = (GtkWindow *) gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (dlg->window, gettext ("Fractal growing")); gtk_window_set_icon (dlg->window, dlg->logo_min); gtk_container_add (GTK_CONTAINER (dlg->window), GTK_WIDGET (dlg->grid)); gtk_widget_show_all (GTK_WIDGET (dlg->window)); #if HAVE_FREEGLUT g_signal_connect (dlg->window, "delete_event", glutLeaveMainLoop, NULL); #elif HAVE_SDL g_signal_connect_swapped (dlg->window, "delete_event", (void (*)) SDL_PushEvent, exit_event); #elif HAVE_GLFW g_signal_connect (dlg->window, "delete_event", (void (*)) window_close, NULL); #endif set_perspective (); dialog_simulator_update (); #if DEBUG printf ("dialog_simulator_create: end\n"); #endif }
/** * \fn void dialog_options_create() * \brief Function to create a dialog to set the fractal options. */ void dialog_options_create () { int i; const char *array_fractals[N_FRACTAL_TYPES] = { gettext ("_Tree"), gettext ("_Forest"), gettext ("_Neuron") }; const char *array_algorithms[N_RANDOM_TYPES] = { "_mt19937", "_ranlxs0", "r_anlxs1", "ra_nlxs2", "ran_lxd1", "ranlx_d2", "ranlu_x", "ranlux_389", "_cmrg", "mr_g", "_taus2", "g_fsr4" }; const char *array_seeds[N_RANDOM_SEED_TYPES] = { gettext ("_Default"), gettext ("_Clock based"), gettext ("_Fixed") }; DialogOptions *dlg = dialog_options; dlg->button_diagonal = (GtkCheckButton *) gtk_check_button_new_with_mnemonic (gettext ("_Diagonal movement")); dlg->button_3D = (GtkCheckButton *) gtk_check_button_new_with_mnemonic ("3_D"); g_signal_connect (dlg->button_3D, "clicked", dialog_options_update, NULL); dlg->label_length = (GtkLabel *) gtk_label_new (gettext ("Length")); dlg->label_width = (GtkLabel *) gtk_label_new (gettext ("Width")); dlg->label_height = (GtkLabel *) gtk_label_new (gettext ("Height")); dlg->label_seed = (GtkLabel *) gtk_label_new (gettext ("Random seed")); dlg->entry_length = (GtkSpinButton *) gtk_spin_button_new_with_range (320., 2400., 1.); dlg->entry_width = (GtkSpinButton *) gtk_spin_button_new_with_range (320., 2400., 1.); dlg->entry_height = (GtkSpinButton *) gtk_spin_button_new_with_range (200., 2400., 1.); dlg->entry_seed = (GtkSpinButton *) gtk_spin_button_new_with_range (0., 4294967295., 1.); dlg->grid_fractal = (GtkGrid *) gtk_grid_new (); dlg->array_fractals[0] = NULL; for (i = 0; i < N_FRACTAL_TYPES; ++i) { dlg->array_fractals[i] = (GtkRadioButton *) gtk_radio_button_new_with_mnemonic_from_widget (dlg->array_fractals[0], array_fractals[i]); gtk_grid_attach (dlg->grid_fractal, GTK_WIDGET (dlg->array_fractals[i]), 0, i, 1, 1); } gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->array_fractals[fractal_type]), 1); dlg->frame_fractal = (GtkFrame *) gtk_frame_new (gettext ("Fractal type")); gtk_container_add (GTK_CONTAINER (dlg->frame_fractal), GTK_WIDGET (dlg->grid_fractal)); dlg->button_animate = (GtkCheckButton *) gtk_check_button_new_with_mnemonic (gettext ("_Animate")); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->button_animate), animating); dlg->grid_algorithm = (GtkGrid *) gtk_grid_new (); dlg->array_algorithms[0] = NULL; for (i = 0; i < N_RANDOM_TYPES; ++i) { dlg->array_algorithms[i] = (GtkRadioButton *) gtk_radio_button_new_with_mnemonic_from_widget (dlg->array_algorithms[0], array_algorithms[i]); gtk_grid_attach (dlg->grid_algorithm, GTK_WIDGET (dlg->array_algorithms[i]), 0, i, 1, 1); } gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->array_algorithms[random_algorithm]), 1); dlg->frame_algorithm = (GtkFrame *) gtk_frame_new (gettext ("Random algorithm")); gtk_container_add (GTK_CONTAINER (dlg->frame_algorithm), GTK_WIDGET (dlg->grid_algorithm)); dlg->grid_seed = (GtkGrid *) gtk_grid_new (); dlg->array_seeds[0] = NULL; for (i = 0; i < N_RANDOM_SEED_TYPES; ++i) { dlg->array_seeds[i] = (GtkRadioButton *) gtk_radio_button_new_with_mnemonic_from_widget (dlg->array_seeds[0], array_seeds[i]); gtk_grid_attach (dlg->grid_seed, GTK_WIDGET (dlg->array_seeds[i]), 0, i, 1, 1); g_signal_connect (dlg->array_seeds[i], "clicked", dialog_options_update, NULL); } gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->array_seeds[random_seed_type]), 1); dlg->frame_seed = (GtkFrame *) gtk_frame_new (gettext ("Random seed type")); gtk_container_add (GTK_CONTAINER (dlg->frame_seed), GTK_WIDGET (dlg->grid_seed)); dlg->grid = (GtkGrid *) gtk_grid_new (); gtk_grid_attach (dlg->grid, GTK_WIDGET (dlg->button_diagonal), 0, 0, 2, 1); gtk_grid_attach (dlg->grid, GTK_WIDGET (dlg->button_3D), 0, 1, 2, 1); gtk_grid_attach (dlg->grid, GTK_WIDGET (dlg->label_length), 0, 2, 1, 1); gtk_grid_attach (dlg->grid, GTK_WIDGET (dlg->entry_length), 1, 2, 1, 1); gtk_grid_attach (dlg->grid, GTK_WIDGET (dlg->label_width), 0, 3, 1, 1); gtk_grid_attach (dlg->grid, GTK_WIDGET (dlg->entry_width), 1, 3, 1, 1); gtk_grid_attach (dlg->grid, GTK_WIDGET (dlg->label_height), 0, 4, 1, 1); gtk_grid_attach (dlg->grid, GTK_WIDGET (dlg->entry_height), 1, 4, 1, 1); gtk_grid_attach (dlg->grid, GTK_WIDGET (dlg->frame_fractal), 0, 5, 2, 1); gtk_grid_attach (dlg->grid, GTK_WIDGET (dlg->button_animate), 0, 6, 2, 1); gtk_grid_attach (dlg->grid, GTK_WIDGET (dlg->frame_algorithm), 2, 0, 1, 8); gtk_grid_attach (dlg->grid, GTK_WIDGET (dlg->frame_seed), 0, 7, 2, 2); gtk_grid_attach (dlg->grid, GTK_WIDGET (dlg->label_seed), 0, 9, 1, 1); gtk_grid_attach (dlg->grid, GTK_WIDGET (dlg->entry_seed), 1, 9, 1, 1); dlg->dialog = (GtkDialog *) gtk_dialog_new_with_buttons (gettext ("Options"), dialog_simulator->window, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, gettext ("_OK"), GTK_RESPONSE_OK, gettext ("_Cancel"), GTK_RESPONSE_CANCEL, NULL); gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (dlg->dialog)), GTK_WIDGET (dlg->grid)); gtk_widget_show_all (GTK_WIDGET (dlg->dialog)); gtk_toggle_button_set_active ((GtkToggleButton *) dlg->button_diagonal, fractal_diagonal); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dlg->button_3D), fractal_3D); gtk_spin_button_set_value (dlg->entry_length, length); gtk_spin_button_set_value (dlg->entry_width, width); gtk_spin_button_set_value (dlg->entry_height, height); gtk_spin_button_set_value (dlg->entry_seed, random_seed); dialog_options_update (); if (gtk_dialog_run (dlg->dialog) == GTK_RESPONSE_OK) { fractal_diagonal = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dlg->button_diagonal)); fractal_3D = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dlg->button_3D)); for (i = 0; i < N_FRACTAL_TYPES; ++i) if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dlg->array_fractals[i]))) fractal_type = i; length = gtk_spin_button_get_value_as_int (dlg->entry_length); width = gtk_spin_button_get_value_as_int (dlg->entry_width); height = gtk_spin_button_get_value_as_int (dlg->entry_height); random_seed = gtk_spin_button_get_value_as_int (dlg->entry_seed); animating = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dlg->button_animate)); for (i = 0; i < N_RANDOM_TYPES; ++i) if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dlg->array_algorithms[i]))) random_algorithm = i; for (i = 0; i < N_RANDOM_SEED_TYPES; ++i) if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dlg->array_seeds[i]))) random_seed_type = i; medium_start (); set_perspective (); breaking = 1; } gtk_widget_destroy (GTK_WIDGET (dlg->dialog)); }
void Viewer::reset() { if ( !m_initflag ) { update_mode( MODELROTATE ); } // Default mouse information m_button1 = false; m_button2 = false; m_button3 = false; m_ixpos = 0.0; m_xpos = 0.0; m_iypos = 0.0; m_ypos = 0.0; m_txpos = 0.0; // Initialize viewport for ( int i = 0; i < 4; i += 1 ) { m_viewport[i] = ( Point2D() ); } // Default FOV of 30 m_fov = 30.0; // Set the default far and near plane values m_near = 2.0; m_far = 20.0; // Initialize all the transformation matrices m_projection = Matrix4x4(); m_modelling = Matrix4x4(); m_viewing = Matrix4x4(); m_scaling = Matrix4x4(); // Start off by pushing the cube back into the screen Vector4D row1, row2, row3, row4; row1 = Vector4D( 1, 0, 0, 0 ); row2 = Vector4D( 0, 1, 0, 0 ); row3 = Vector4D( 0, 0, 1, 8 ); row4 = Vector4D( 0, 0, 0, 1 ); m_viewing = Matrix4x4( row1, row2, row3, row4 ); // Initialize the unit cubes m_unitCube[0] = ( Point3D( 1.0, -1.0, -1.0) ); m_unitCube[1] = ( Point3D(-1.0, -1.0, -1.0) ); m_unitCube[2] = ( Point3D(-1.0, 1.0, -1.0) ); m_unitCube[3] = ( Point3D( 1.0, 1.0, -1.0) ); m_unitCube[4] = ( Point3D(-1.0, -1.0, 1.0) ); m_unitCube[5] = ( Point3D( 1.0, -1.0, 1.0) ); m_unitCube[6] = ( Point3D( 1.0, 1.0, 1.0) ); m_unitCube[7] = ( Point3D(-1.0, 1.0, 1.0) ); for ( int i = 0; i < 8; i += 1 ) { m_unitCubeTrans[i] = ( Point3D() ); } // Initialize the gnomons m_gnomon[0] = ( Point3D(0.0, 0.0, 0.0) ); m_gnomon[1] = ( Point3D(0.5, 0.0, 0.0) ); m_gnomon[2] = ( Point3D(0.0, 0.5, 0.0) ); m_gnomon[3] = ( Point3D(0.0, 0.0, 0.5) ); for ( int i = 0; i < 4; i += 1 ) { m_gnomonTrans[i] = ( Point3D() ); } m_viewflag = false; m_initflag = false; // Initialize the perspective set_perspective( m_fov, 1, m_near, m_far ); }
bool Viewer::on_motion_notify_event( GdkEventMotion* event ) { if ( m_button1 || m_button2 || m_button3 ) { m_txpos = m_xpos; m_xpos = event->x; switch ( m_mode ) { case VIEWROTATE: if ( m_button1 ) { m_viewing = m_viewing * rotation( (m_txpos - m_xpos) / 100.0, 'y' ).invert(); } if ( m_button2 ) { m_viewing = m_viewing * rotation( (m_txpos - m_xpos) / 100.0, 'z' ).invert(); } if ( m_button3 ) { m_viewing = m_viewing * rotation( (m_txpos - m_xpos) / 100.0, 'x' ).invert(); } break; case VIEWTRANSLATE: if ( m_button1 ) { m_viewing = translation( Vector3D(( m_txpos - m_xpos ) / 100.0, 0.0, 0.0) ).invert() * m_viewing; } if ( m_button2 ) { m_viewing = translation( Vector3D(0.0, ( m_txpos - m_xpos ) / 100.0, 0.0) ).invert() * m_viewing; } if ( m_button3 ) { m_viewing = translation( Vector3D(0.0, 0.0, ( m_txpos - m_xpos ) / 100.0) ).invert() * m_viewing; } break; case VIEWPERSPECTIVE: if ( m_button1 ) { m_fov -= ( m_txpos - m_xpos ) / 10.0; set_perspective( m_fov, 1, m_near, m_far ); } if ( m_button2 ) { m_near -= ( m_txpos - m_xpos ) / 10.0; } if ( m_button3 ) { m_far -= ( m_txpos - m_xpos ) / 10.0; } break; case MODELROTATE: if ( m_button1 ) { m_modelling = m_modelling * rotation( (m_txpos - m_xpos) / 100.0, 'y' ).invert(); } if ( m_button2 ) { m_modelling = m_modelling * rotation( (m_txpos - m_xpos) / 100.0, 'z' ).invert(); } if ( m_button3 ) { m_modelling = m_modelling * rotation( (m_txpos - m_xpos) / 100.0, 'x' ).invert(); } break; case MODELTRANSLATE: if ( m_button1 ) { m_modelling = m_modelling * translation( Vector3D (( m_txpos - m_xpos ) / -100.0, 0.0, 0.0) ); } if ( m_button2 ) { m_modelling = m_modelling * translation( Vector3D (0.0, ( m_txpos - m_xpos ) / -100.0, 0.0) ); } if ( m_button3 ) { m_modelling = m_modelling * translation( Vector3D (0.0, 0.0, ( m_txpos - m_xpos ) / -100.0) ); } break; case MODELSCALE: if ( m_button1 ) { m_scaling = m_scaling * scaling( Vector3D(1.0 + ( (m_txpos - m_xpos) / 100.0 ), 1.0, 1.0) ).invert(); } if ( m_button2 ) { m_scaling = m_scaling * scaling( Vector3D(1.0, 1.0 + ( m_txpos - m_xpos ) / 100.0, 1.0) ).invert(); } if ( m_button3 ) { m_scaling = m_scaling * scaling( Vector3D(1.0, 1.0, 1.0 + ( m_txpos - m_xpos ) / 100.0) ).invert(); } break; default: break; } invalidate(); } return true; }