void
dmz::RenderModulePortalOSG::discover_plugin (
      const PluginDiscoverEnum Mode,
      const Plugin *PluginPtr) {

   if (Mode == PluginDiscoverAdd) {

      if (!_core) {

         _core = RenderModuleCoreOSG::cast (PluginPtr);
         if (_core) {

            _manipulator = _core->lookup_camera_manipulator (_portalName);

            _camera = _core->lookup_camera (_portalName);
            if (_camera.valid ()) {

               _camera->setComputeNearFarMode (
                  osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);

               _update_camera ();
            }
         }
      }
   }
   else if (Mode == PluginDiscoverRemove) {

      if (_core && (_core == RenderModuleCoreOSG::cast (PluginPtr))) {

         _core = 0;
         _camera = 0;
         _manipulator = 0;
      }
   }
}
Exemple #2
0
void Camera::set_h_offset(float p_offset) {
	h_offset=p_offset;
	_update_camera();
}
Exemple #3
0
void Camera::set_v_offset(float p_offset) {

	v_offset=p_offset;
	_update_camera();;
}
Exemple #4
0
void Camera::_request_camera_update() {

	_update_camera();
}
Exemple #5
0
void start_game(game *g) {
    _world_vertices(g);
    _setup_world(g);

    _reset_camera(g);
    _setup_camera(g);
    _update_camera(g);

    // Start game
    Uint32 start_loop = SDL_GetTicks();
    Uint32 last_ticks = SDL_GetTicks();
    SDL_Delay(1);
    Uint32 cur_ticks = SDL_GetTicks();

    SDL_Event e;
    size_t count = 0;

    while (g->state != ENDED) {
        _render_world(g);

        // Get time since last frame (ms)
        last_ticks = cur_ticks;
        cur_ticks = SDL_GetTicks();

        if (g->o.enabled) {
            // Calculate average and instant FPS
            if (g->o.fps_upd & 1) {
                g->avg_fps = count / ((cur_ticks - start_loop) / 1000.f);
                g->fps = 1000.0 / (cur_ticks - last_ticks);
                g->o.fps_upd = 0;
            }

            // Check if we should render FPS (only 2 times per second)
            if ((cur_ticks / 100) % 5 == 0) {
                g->o.fps_upd = 2;
            } else {
                g->o.fps_upd >>= 1;
            }

            _render_overlay(g);
        }

        SDL_GL_SwapWindow(g->win);

        // Events
        while (SDL_PollEvent(&e)) {
            _handle_event(g, e);
        }

        // Update camera
        _update_camera(g);

        // Update the world
        ++count;
        if (g->state == RUNNING) {
            switch (g->step) {
                case(WHOLE): world_step(g->w); break;
                case(HALF): world_half_step(g->w); break;
            }
        }

        _update_world_buffer(g);
    }
}
Exemple #6
0
static inline void _handle_event(game *g, SDL_Event e) {
    if (e.type == SDL_QUIT) {
        g->state = ENDED;
    }
    if (e.type == SDL_KEYUP) {
        switch(e.key.keysym.sym) {
            // Fills
            case(SDLK_0):
            case(SDLK_1):
            case(SDLK_2):
            case(SDLK_3):
            case(SDLK_4):
            case(SDLK_5):
            case(SDLK_6):
            case(SDLK_7):
            case(SDLK_8):
            case(SDLK_9):
                fill(g->w, e.key.keysym.sym - SDLK_0);
                g->state = PAUSED;
                break;

            case(SDLK_r):
                fill(g->w, RANDOM);
                g->state = PAUSED;
                break;

            // Quit
            case(SDLK_ESCAPE):
            case(SDLK_q): g->state = ENDED; break;

            // Overlay
            case(SDLK_TAB): g->o.enabled = 0; break;

            // Toggle vsync
            case(SDLK_v):
                if (e.key.keysym.mod & (KMOD_CTRL|KMOD_CAPS)) {
                    char *clip_text = SDL_GetClipboardText();
                    size_t clip_len = SDL_strlen(clip_text);
                    for (; clip_len > 0; clip_len--) {
                        if (clip_text[clip_len-1] == '\n') {
                            continue;
                        }
                        break;
                    }
                    world *dec_w = deserialize_world_b64(clip_text, clip_len);
                    if (dec_w != NULL) {
                        printf("Decoded world! %ux%u\n", dec_w->xlim, dec_w->ylim);
                        free(g->w);
                        g->w = dec_w;
                        _init_world_display(g);
                        _world_vertices(g);
                        _setup_world(g);
                        _reset_camera(g);
                        _setup_camera(g);
                        _update_camera(g);
                    }
                    SDL_free(clip_text);
                } else {
                    g->vsync = !g->vsync;
                    SDL_GL_SetSwapInterval(g->vsync);
                }
                break;

            // End running
            case(SDLK_n): g->state = PAUSED; break;
            // Toggle running
            case(SDLK_SPACE):
                g->state = g->state == RUNNING ? PAUSED : RUNNING;
                break;
            // Toggle sub-state
            case(SDLK_h):
                if (g->w->state != CALC) {
                    world_half_step(g->w);
                }
                g->step = g->step == WHOLE ? HALF : WHOLE;
                break;
            // Change color scheme
            case(SDLK_c):
                if (e.key.keysym.mod & KMOD_SHIFT) {
                    _update_colors(g, g->color_scheme - 1);
                } else if (e.key.keysym.mod & (KMOD_CTRL|KMOD_CAPS)) {
                    size_t ser_size;
                    char *enc_world = serialize_world_b64(g->w, &ser_size);
                    printf("Copying to clipboard: %lu bytes\n", ser_size);
                    if (SDL_SetClipboardText(enc_world) != 0) {
                        printf("SDL_Error: %s\n", SDL_GetError());
                    }
                    free(enc_world);
                } else {
                    _update_colors(g, g->color_scheme + 1);
                }
                g->o.fps_upd = 1;
                break;
            // Switch projection type
            case(SDLK_o):
                g->d.ortho = !g->d.ortho;
                _setup_camera(g);
                _set_view(g);
                break;
            // Reset camera
            case(SDLK_u):
                _reset_camera(g);
                break;
            // Toggle padding
            case(SDLK_p):
                g->d.padding = !g->d.padding;
                _world_vertices(g);
                _setup_world(g);
                break;
            // Save file
            case(SDLK_x):
                if (g->filename != NULL) {
                    printf("Saving to file: %s\n", g->filename);
                    write_to_file(g->filename, g->w, BASE64);
                }
                break;
        }
    } else if (e.type == SDL_KEYDOWN) {
        switch(e.key.keysym.sym) {
            // Start running
            case(SDLK_n): g->state = RUNNING; break;
            // Single step
            case(SDLK_m):
                g->state = PAUSED;
                world_half_step(g->w);
                break;
            // Translate up
            case(SDLK_w):
            case(SDLK_UP):
                _move_camera(g, UP);
                break;
            // Translate left
            case(SDLK_a):
            case(SDLK_LEFT):
                _move_camera(g, LEFT);
                break;
            // Translate up
            case(SDLK_s):
            case(SDLK_DOWN):
                _move_camera(g, DOWN);
                break;
            // Translate right
            case(SDLK_d):
            case(SDLK_RIGHT):
                _move_camera(g, RIGHT);
                break;

            // Overlay
            case(SDLK_TAB): g->o.enabled = 1; break;
        }
    } else if (e.type == SDL_MOUSEBUTTONDOWN) {
        switch (e.button.button) {
            // Invert cell under cursor
            case(SDL_BUTTON_LEFT):
                g->state = PAUSED;
                _handle_mouse_click(g, e.button.x, e.button.y);
                break;
        }
    } else if (e.type == SDL_MOUSEWHEEL) {
        _calc_zoom(g, e.wheel.y > 0 ? 1 : -1);
    }
}
void
dmz::RenderModulePortalOSG::set_fov (const Float32 Value) {

   _fov = Value;
   _update_camera ();
}
void
dmz::RenderModulePortalOSG::set_far_clip_plane (const Float32 Value) {

   _farClip = Value;
   _update_camera ();
}