void updateSearch() { 

  if (!valid(init) || !valid(goal)) { 
    return;
  }

  if (!checker or (changes & (GoalChanged | InflationChanged))) {
    delete checker;
    checker = 0;
    checker = new BipedChecker(&grid, goal.x(), goal.y(), inflate_h, inflate_z);
  }
  
  searchResult = 0;
  helper.clear();

  double start = gettimeasdouble();

  searchResult = helper.search(init.x(), init.y(), initTheta,
                               goal.x(), goal.y(), goalr,
                               checker, maxDepth, viewDepth);

  planTime = gettimeasdouble() - start;

  changes = NoChange;


}
bool valid(const vec2i& p) {
  return ( p.x() >= 0 && 
           p.y() >= 0 && 
           size_t(p.x()) < grid.nx() && 
           size_t(p.y()) < grid.ny() &&
           grid(p.x(), p.y()) );
}
Beispiel #3
0
 void setup()
 {
     size = window->getFramebufferSize();
     if (grabber.open(0, size.x(), size.y()) < 0)
         throw "Failed to open capture device";
     if (grabber.start() < 0)
         throw "Failed to start capture device";
 }
EGLAPI EGLSurface EGLAPIENTRY
HookEglCreateWindowSurface(EGLDisplay dpy, EGLConfig config,
                           EGLNativeWindowType win, const EGLint* attrib_list) {
  // Apply scaler setting
  ANativeWindow* window = Android_JNI_GetNativeWindow();
  ANativeWindow_setBuffersGeometry(window, g_android_scaler_resolution.x(),
                                   g_android_scaler_resolution.y(), 0);
  return eglCreateWindowSurface(dpy, config, win, attrib_list);
}
Beispiel #5
0
int Grid::cellType(vec2i coord) {
	int index = coord.y() * d_cols + coord.x();
	if (d_map[index]) {
		return 1;
	} else {
		d_map[index] = 1;
		return 0;
	}
}
Beispiel #6
0
// Initialize the 'renderer_' member. No other members have been initialized at
// this point.
bool Game::InitializeRenderer() {
#ifdef __ANDROID__
  vec2i window_size = GetWindowSize();
  if (fplbase::IsTvDevice()) {
    window_size = vec2i(kAndroidTvMaxScreenWidth, kAndroidTvMaxScreenHeight);
  }
#else
  vec2i window_size(1200, 800);
#endif  // __ANDROID__
  if (!renderer_.Initialize(window_size, GetConfig().window_title()->c_str())) {
    LogError("Renderer initialization error: %s\n",
             renderer_.last_error().c_str());
    return false;
  }

#ifdef __ANDROID__
  // Restart the app if HW scaler setting failed.
  auto retry = fplbase::LoadPreference("HWScalerRetry", 0);
  const auto kMaxRetry = 3;
  auto current_window_size = fplbase::AndroidGetScalerResolution();
  if (current_window_size.x() != window_size.x() ||
      current_window_size.y() != window_size.y()) {
    if (retry < kMaxRetry) {
      LogError("Restarting application.");
      fplbase::SavePreference("HWScalerRetry", retry + 1);
      fplbase::RelaunchApplication();
      return false;
    }
    // The HW may not support the API. Fallback to native resolution pass until
    // the API success next time.
  } else {
    // HW scaler setting was success. Clear retry counter.
    fplbase::SavePreference("HWScalerRetry", 0);
  }
#endif  // __ANDROID__

  renderer_.set_color(mathfu::kOnes4f);
  // Initialize the first frame as black.
  renderer_.ClearFrameBuffer(mathfu::kZeros4f);

#ifdef ANDROID_HMD
  vec2i size = fplbase::AndroidGetScalerResolution();
  const vec2i viewport_size =
      size.x() && size.y() ? size : renderer_.window_size();
  fplbase::InitializeUndistortFramebuffer(viewport_size.x(), viewport_size.y());
#endif  // ANDROID_HMD

#if ZOOSHI_OVERDRAW_DEBUG
  renderer_.SetBlendMode(BlendMode::kBlendModeAdd);
  renderer_.force_blend_mode() = BlendMode::kBlendModeAdd;
  renderer_.override_pixel_shader() =
      "void main() { gl_FragColor = vec4(0.2, 0.2, 0.2, 1); }";
#endif  // ZOOSHI_OVERDRAW_DEBUG

  return true;
}
void AndroidPreCreateWindow() {
  // Apply scaler setting prior creating surface
  if (g_android_scaler_resolution.x() && g_android_scaler_resolution.y()) {
    // Initialize OpenGL function pointers inside SDL
    if (SDL_GL_LoadLibrary(NULL) < 0) {
      SDL_LogError(SDL_LOG_CATEGORY_ERROR,
                   "couldn't initialize OpenGL library\n");
    }

    // Hook eglCreateWindowSurface call
    SDL_VideoDevice* device = SDL_GetVideoDevice();
    device->egl_data->eglCreateWindowSurface = HookEglCreateWindowSurface;
  }
}
void AndroidSetScalerResolution(const vec2i& resolution) {
  // Check against the real size of the device
  JNIEnv* env = reinterpret_cast<JNIEnv*>(SDL_AndroidGetJNIEnv());
  jobject activity = reinterpret_cast<jobject>(SDL_AndroidGetActivity());
  jclass fpl_class = env->GetObjectClass(activity);
  jmethodID get_size =
      env->GetMethodID(fpl_class, "GetLandscapedSize", "()[I");
  jintArray size = (jintArray)env->CallObjectMethod(activity, get_size);
  jint* size_ints = env->GetIntArrayElements(size, NULL);

  int width = std::min(size_ints[0], resolution.x());
  int height = std::min(size_ints[1], resolution.y());
  g_android_scaler_resolution = vec2i(width, height);

  // Update the underlying activity with the scaled resolution
  jmethodID set_resolution =
      env->GetMethodID(fpl_class, "SetHeadMountedDisplayResolution", "(II)V");
  env->CallVoidMethod(activity, set_resolution, width, height);

  env->ReleaseIntArrayElements(size, size_ints, JNI_ABORT);
  env->DeleteLocalRef(size);
  env->DeleteLocalRef(fpl_class);
  env->DeleteLocalRef(activity);
}
Beispiel #9
0
 void Shader::setUniform(const std::string &name, const vec2i v, bool warn) {
     glUniform2i(uniform(name, warn), v.x(), v.y());
 }
Beispiel #10
0
 void Camera::setViewport(vec2i dim)
 {
     vpWidth = dim.x();
     vpHeight = dim.y();
     hasProjChanged = true;
 }
Beispiel #11
0
 void draw()
 {
     window->clear();
     grabber.update();
     grabber.draw(size.x() / 4, size.y() / 4, size.x() / 2, size.y() / 2);
 }
void display() {

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glEnable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, grid_texture);

  glColor3ub(255,255,255);

  glBegin(GL_QUADS);

  glTexCoord2f(1, 0);
  glVertex2f(grid.nx(), 0);

  glTexCoord2f(0, 0);
  glVertex2f(0, 0);

  glTexCoord2f(0, 1);
  glVertex2f(0, grid.ny());

  glTexCoord2f(1, 1);
  glVertex2f(grid.nx(), grid.ny());

  glEnd();

  glDisable(GL_TEXTURE_2D);

  if (valid(init)) {
    glPushMatrix();

    glColor3ub(63,255,63);
    glTranslated(init.x(), init.y(), 0);
    gluDisk(quadric, 0, goalr, 32, 1);

    glRotated(initTheta*180/M_PI, 0, 0, 1);
    glBegin(GL_TRIANGLES);
    glVertex2f(6, 0);
    glVertex2f(0, 2);
    glVertex2f(0, -2);
    glEnd();

    glPopMatrix();

  }

  if (valid(goal)) {
    glPushMatrix();
    glColor3ub(255,63,63);
    glTranslated(goal.x(), goal.y(), 0);
    gluDisk(quadric, 0, goalr, 32, 1);
    glPopMatrix();
  }

  draw(searchResult, true);

  glMatrixMode(GL_PROJECTION);
  glPushMatrix();
  glLoadIdentity();
  gluOrtho2D(0, width, 0, height);

  std::ostringstream ostr;
  ostr << "Goal pos:     (" << goal.x() << ", " << goal.y() << ")\n"
       << "Init pos:     (" << init.x() << ", " << init.y() << ")\n"
       << "Init theta:   " << initTheta*180/M_PI << "\n"
       << "XY inflation: " << inflate_h << "\n"
       << "Z inflation:  " << inflate_z << "\n"
       << "Max depth:    " << maxDepth << "\n"
       << "View depth:   " << viewDepth << "\n"
       << "Auto-plan:    " << (auto_plan ? "on" : "off") << "\n"
       << "\n"
       << "Plan cost: " << (searchResult ? searchResult->costToCome : 0) << "\n"
       << "Plan time: " << (searchResult ? planTime : 0) << "\n";

  if (show_help) { 
    ostr << "\n\n"
         << " Left-click init pos\n"
         << "Shift+click init theta\n"
         << "Right-click goal pos\n\n"
         << "        1/2 max depth\n"
         << "        3/4 view depth\n"
         << "        -/+ XY inflation\n"
         << "          A auto-plan\n"
         << "      Enter re-plan\n"
         << "        ESC quit\n"
         << "          ? hide help";
  } else {
    ostr << "\nPress ? to toggle help.";
  }
    


  std::string str = ostr.str();
  
  void* font = GLUT_BITMAP_8_BY_13;
  const int tx = 8;
  const int ty = 13;
  const int th = ty+2;
  int maxwidth = 0;
  int linewidth = 0;
  int rh = th;

  for (size_t i=0; i<str.length(); ++i) {
    char c = str[i];
    if (c == '\n') { 
      maxwidth = std::max(maxwidth, linewidth);
      linewidth = 0;
      rh += th;
    } else { 
      linewidth += tx;
    }
  }
  maxwidth = std::max(maxwidth, linewidth);

  int rw = maxwidth + 20;
  rh += 10;

  glColor4ub(191,191,255,225);
  glEnable(GL_BLEND);
  glBegin(GL_QUADS);
  glVertex2f( 0, height);
  glVertex2f(rw, height);
  glVertex2f(rw, height-rh);
  glVertex2f( 0, height-rh);
  glEnd();
  glDisable(GL_BLEND);

  int rx = 10;
  int ry = height-th;

  glColor3ub(0,0,0);
  glRasterPos2i(rx, ry);

  for (size_t i=0; i<str.length(); ++i) {
    char c = str[i];
    if (c == '\n') {
      ry -= th;
      glRasterPos2i(rx, ry);
    } else {
      glutBitmapCharacter(font, str[i]);
    }
  }

  glPopMatrix();

  glutSwapBuffers();

}