Exemple #1
0
int main(int argc, char *argv[])
{
    int frames = 0;
    EON_Mat *mat[3];
    EON_Cam *cam;
    EON_Obj *land;
    EON_Obj *sky, *sky2;
    Landscape ls;
    EONx_Console *con;
    EON_Rend *rend;
    EON_Frame *frame;
    EON_Font *font;
    uint64_t ts = 0;

    CX_LogContext *Logger = CX_log_open_console(CX_LOG_MARK, stderr);

    srand(0); // initialize prng

    EONx_ConsoleStartup("Eon3D :: Fly v1.1", NULL);
    con = EONx_ConsoleCreate(800, // Screen width
                             600, // Screen height
                             90.0 // Field of view
                             );

    frame = EONx_ConsoleGetFrame(con);
    cam = EONx_ConsoleGetCamera(con);
    rend = EON_RendCreate(cam);
    cam->Pos.Y = 800; // move the camera up from the ground

    font = EON_TextDefaultFont();

    setup_materials(con, mat, Logger); // intialize materials and palette

    memset(&ls, 0, sizeof(ls));
    setup_landscape(&ls, mat[0],mat[1],mat[2]); // create landscape
    land = ls.land;
    sky = ls.sky;
    sky2 = ls.sky2;

    EON_ObjInfo(land, Logger);
    EON_ObjInfo(sky,  Logger);
    EON_ObjInfo(sky2, Logger);

    frames = 0;     // set up for framerate counter
    ts = eon_gettime_ms();
    while (!EONx_ConsoleNextEvent(con)) {
        // save time when the frame began, to be used later.
        uint64_t elapsed = 0;
        frames++;

        cam->Pos.Z += 1;

        EONx_ConsoleClearFrame(con);

        if (cam->Pos.Y > 2000) {
            // if above the sky, only render the skies, with no far clip plane
            cam->ClipBack = 0.0;
            EON_RenderBegin(rend);
            EON_RenderObj(rend, sky);
            EON_RenderObj(rend, sky2);
        } else {
            // otherwise, render the sky (but not the second sky),
            // and the land, with a far clip plane
            cam->ClipBack = 10000.0;
            EON_RenderBegin(rend);
            EON_RenderObj(rend, sky);
            EON_RenderObj(rend, land);
        }
        EON_RenderEnd(rend, frame);

        elapsed = (eon_gettime_ms() - ts) / 1000000;
        EON_TextPrintf(font, cam, frame,
                       cam->ClipLeft+5, cam->ClipTop, 0.0,
                      "%.3f FPS",
                      (frames/ (double) elapsed));

        EONx_ConsoleShowFrame(con);

        // wraparound
        if (cam->Pos.X >  LAND_SIZE/2) cam->Pos.X = -LAND_SIZE/2;
        if (cam->Pos.X < -LAND_SIZE/2) cam->Pos.X =  LAND_SIZE/2;
        if (cam->Pos.Z >  LAND_SIZE/2) cam->Pos.Z = -LAND_SIZE/2;
        if (cam->Pos.Z < -LAND_SIZE/2) cam->Pos.Z =  LAND_SIZE/2;
        if (cam->Pos.Y <  0          ) cam->Pos.Y =  8999;
        if (cam->Pos.Y >  8999       ) cam->Pos.Y =  0;
    }

    EON_FontDelete(font);
    EON_ObjDelete(land);
    EON_ObjDelete(sky);
    EON_ObjDelete(sky2);
    EON_MatDelete(mat[0]);
    EON_MatDelete(mat[1]);
    EON_MatDelete(mat[2]);

    EONx_ConsoleShutdown();

    return CX_log_close(Logger);
}
Exemple #2
0
void doFlyEffect(LICE_IBitmap *fb, HWND hwnd)
{
  static int initted;
  if (!initted)
  {
    initted=1;
    cam = new pl_Cam;
    cam->Fov=90.0;
    cam->WantZBuffer=true;
    if (cam->WantZBuffer) cam->Sort = -1;
    cam->Y = 800; // move the camera up from the ground
    cam->Pitch = 180.0;

    setup_materials(mat); // intialize materials and palette

    land = setup_landscape(mat[0],mat[1],mat[2]); // create landscape
    sky = land->Children.Get(0); // unhierarchicalize the sky from the land
    land->Children.Delete(0);
    sky2 = land->Children.Get(0);
    land->Children.Delete(0);

    int x;
    for(x=0;x<sizeof(lights)/sizeof(lights[0]);x++)
    {
      lights[x].Set(PL_LIGHT_POINT,(x%4 - 1.5) * LAND_SIZE /4.0,
                                   500+(rand()%1000),
                                   (x/4-1.5)*LAND_SIZE/4.0,(rand()%1000)/700.0,(rand()%1000)/700.0,(rand()%1000)/700.0,LAND_SIZE*1.0);
    }

  }

  LICE_Clear(fb,0);
      cam->Begin(fb);

      int x;
      for(x=0;x<sizeof(lights)/sizeof(lights[0]);x++)
        cam->RenderLight(&lights[x]);

  // lots of rendering special casing
  if (draw_sky) { // if we're drawing the sky
    if (cam->Y > 2000) { // if above the sky, only render the skies, with 
                         // no far clip plane

      cam->RenderObject(sky);
      cam->RenderObject(sky2);
    } else {           // otherwise, render the sky (but not the second sky),
                       // and the land, with a far clip plane


      cam->RenderObject(sky);
      cam->RenderObject(land);
    }
  } else { // not drawing sky, just render the land

    cam->RenderObject(land);
  }
  cam->End(); // finish rendering

  static POINT lpos;
  POINT p;
  GetCursorPos(&p);
  int mouse_x  = 0;
  int mouse_y  = 0;
  int mouse_b=0;

  if (hwnd)
  {
    mouse_x = p.x-lpos.x;
    mouse_y = p.y-lpos.y;
    if (GetAsyncKeyState(VK_RBUTTON)&0x8000) mouse_b|=2;

    RECT r;
    GetWindowRect(hwnd,&r);
    p.x=(r.right+r.left)/2;
    p.y=(r.bottom+r.top)/2;
    SetCursorPos(p.x,p.y);
  }
  lpos=p;
    // We calculate the amount of time in thousanths of seconds this frame took
    double prevtime = 10; //((uclock() / (float) UCLOCKS_PER_SEC) - prevtime)*1000.0;

    if (mouse_b & 2) { // if right button hit, we go forward quickly
      cam->X -=
        prevtime*4*sin(cam->Pan*PL_PI/180.0)*cos(cam->Pitch*PL_PI/180.0);
      cam->Z += 
        prevtime*4*cos(cam->Pan*PL_PI/180.0)*cos(cam->Pitch*PL_PI/180.0);
      cam->Y += 
        prevtime*4*sin(cam->Pitch*PL_PI/180.0);
    } else if (mouse_b & 1) { // if left button hit, we go forward slowly
      cam->X -= 
        prevtime*2*sin(cam->Pan*PL_PI/180.0)*cos(cam->Pitch*PL_PI/180.0);
      cam->Z += 
        prevtime*2*cos(cam->Pan*PL_PI/180.0)*cos(cam->Pitch*PL_PI/180.0);
      cam->Y += 
        prevtime*2*sin(cam->Pitch*PL_PI/180.0);
    }
    cam->Pitch += (mouse_y*mouse_sens); // update pitch and pan of ship
    cam->Pan += (mouse_x*mouse_sens)*(-cos(cam->Pitch*PL_PI/180.0));
    
    if (cam->X > LAND_SIZE/2) cam->X = LAND_SIZE/2; // make sure we don't go 
    if (cam->X < -LAND_SIZE/2) cam->X = -LAND_SIZE/2; // too far away
    if (cam->Z > LAND_SIZE/2) cam->Z = LAND_SIZE/2;
    if (cam->Z < -LAND_SIZE/2) cam->Z = -LAND_SIZE/2;
    if (cam->Y < 0) cam->Y = 0;
    if (cam->Y > 8999) cam->Y = 8999;
#if 0 

    while (kbhit()) switch(getch()) { // handle keystrokes
      case 27: done++; break;    // ESC == quit
        // + is for zooming in.
      case '=': case '+': cam->Fov -= 1.0; if (cam->Fov < 1.0) cam->Fov = 1.0;
        sprintf(lastmessage,"FOV: %2.f",cam->Fov);
      break;
        // - is for zooming out
      case '-': cam->Fov += 1.0; if (cam->Fov > 179.0) cam->Fov = 179.0;
        sprintf(lastmessage,"FOV: %2.f",cam->Fov);
      break;
        // [ decreases mouse sensitivity
      case '[': mouse_sens /= 1.1; 
        sprintf(lastmessage,"MouseSens: %.3f",mouse_sens);
      break;
        // ] increases mouse sensitivity
      case ']': mouse_sens *= 1.1; 
        sprintf(lastmessage,"MouseSens: %.3f",mouse_sens);
      break;
        // v toggles vsync
      case 'v': wait_vsync ^= 1;
        sprintf(lastmessage,"VSync %s",wait_vsync ? "on" : "off");
      break;
        // s toggles sky
      case 's': draw_sky ^= 1;
        sprintf(lastmessage,"Sky %s",draw_sky ? "on" : "off");
      break;
    } 
#endif

    //LICE_ScaledBlit(fb,mat[2]->Texture,0,0,fb->getWidth(),fb->getHeight(),0,0,mat[2]->Texture->getWidth(),mat[2]->Texture->getHeight(),1.0f,0);
}
Exemple #3
0
                       /* Main!!! */
void main() {
  char lastmessage[80] = "Fly 3.0"; // last message used for status line
  int draw_sky = 1;                 // do we draw the sky?
  int wait_vsync = 0;               // do we wait for vsync?
  int frames, t;                    // for framerate counter
  int i;

  pl_uChar *framebuffer;            // our doublebuffer
  pl_Mat *mat[3+1];                 // our materials, we have 1 extra for null
                                    // termination for plMatMakeOptPal2()
  pl_Cam *cam;                      // our camera
  pl_Obj *land;                     // the land object
  pl_Obj *sky, *sky2;               // the two skies
  int done = 0;

  char pal[768];                    // our palette

  srand(0);                         // initialize rng

  _control87(MCW_EM|PC_24,MCW_EM|MCW_PC);
     // Set the FPU in low precision, no exception mode (REQUIRED)

  printf("Plush 3D Fly v3.0.\n"
         "  %s\n"
         "  %s\n",plVersionString,plCopyrightString);
     // print out startup info

  mouse_init(); // initialize mouse

  printf("\n\nControls:\n"
         "  Mouse: rotate\n"
         "  Mouse buttons: left=move forward, right=move forward fast\n"
         "  s: toggle sky (default on)\n"
         "  -,+: adjust fov (default 90)\n"
         "  [,]: adjust mouse sensitivity\n"
         "  v: toggle vsync (default off)\n\n");

  printf("\nHit any key to begin...");
  getch();
  while (kbhit()) getch(); // make sure keyboard buffer is empty

  set_mode13();  // intialize graphics
  framebuffer = (pl_uChar *) malloc(320*200); // allocate framebuffer
      // create camera
  cam = plCamCreate(320, // width
                    200, // height
                    320.0/200.0*3.0/4.0, // aspect ratio
                    90.0, // fov
                    framebuffer, // framebuffer (our doublebuffer)
                    0);  // zbuffer (not used)
  cam->Y = 800; // move the camera up from the ground

  setup_materials(mat,pal); // intialize materials and palette

  land = setup_landscape(mat[0],mat[1],mat[2]); // create landscape
  sky = land->Children[0]; // unhierarchicalize the sky from the land
  land->Children[0] = 0;
  sky2 = land->Children[1];
  land->Children[1] = 0;

  frames = 0;     // set up for framerate counter
  t = uclock();
  while (!done) { // main loop
    // save time when the frame began, to be used later.
    float prevtime = uclock() / (float) UCLOCKS_PER_SEC;
    frames++; // update for framerate counter

    memset(framebuffer,1,64000); // clear our doublebuffer

    // lots of rendering special casing
    if (draw_sky) { // if we're drawing the sky
      if (cam->Y > 2000) { // if above the sky, only render the skies, with
                           // no far clip plane
        cam->ClipBack = 0.0;
        plRenderBegin(cam);
        plRenderObj(sky);
        plRenderObj(sky2);
      } else {           // otherwise, render the sky (but not the second sky),
                         // and the land, with a far clip plane
        cam->ClipBack = 10000.0;
        plRenderBegin(cam);
        plRenderObj(sky);
        plRenderObj(land);
      }
    } else { // not drawing sky, just render the land
      cam->ClipBack = 10000.0;
      plRenderBegin(cam);
      plRenderObj(land);
    }
    plRenderEnd(); // finish rendering

    // display framerate counter
    plTextPrintf(cam,cam->ClipLeft+5,cam->ClipTop,0.0,156,"%.2f fps",
        (frames/ (float) (uclock() - t)) * (float) UCLOCKS_PER_SEC);
    // display last message
    plTextPrintf(cam,cam->ClipLeft+5,cam->ClipBottom-16,0.0,156,lastmessage);


    if (wait_vsync) vsync(); // wait for vsync
      /* blit to screen. This is pretty darn fast on ip5's but on a 486 you
         would probably be faster doing a plain memcpy(), i.e:
         memcpy((void *) __djgpp_conventional_base+0xA0000,framebuffer,64000);
      */
    fpucopy((void *) __djgpp_conventional_base + 0xA0000,framebuffer,64000/16);

    // We calculate the amount of time in thousanths of seconds this frame took
    prevtime = ((uclock() / (float) UCLOCKS_PER_SEC) - prevtime)*1000.0;
    mouse_get(); // update the mouse
    if (mouse_b & 2) { // if right button hit, we go forward quickly
      cam->X -=
        prevtime*4*sin(cam->Pan*PL_PI/180.0)*cos(cam->Pitch*PL_PI/180.0);
      cam->Z +=
        prevtime*4*cos(cam->Pan*PL_PI/180.0)*cos(cam->Pitch*PL_PI/180.0);
      cam->Y +=
        prevtime*4*sin(cam->Pitch*PL_PI/180.0);
    } else if (mouse_b & 1) { // if left button hit, we go forward slowly
      cam->X -=
        prevtime*2*sin(cam->Pan*PL_PI/180.0)*cos(cam->Pitch*PL_PI/180.0);
      cam->Z +=
        prevtime*2*cos(cam->Pan*PL_PI/180.0)*cos(cam->Pitch*PL_PI/180.0);
      cam->Y +=
        prevtime*2*sin(cam->Pitch*PL_PI/180.0);
    }
    cam->Pitch += (mouse_y*mouse_sens); // update pitch and pan of ship
    cam->Pan -= (mouse_x*mouse_sens);

    if (cam->X > LAND_SIZE/2) cam->X = LAND_SIZE/2; // make sure we don't go
    if (cam->X < -LAND_SIZE/2) cam->X = -LAND_SIZE/2; // too far away
    if (cam->Z > LAND_SIZE/2) cam->Z = LAND_SIZE/2;
    if (cam->Z < -LAND_SIZE/2) cam->Z = -LAND_SIZE/2;
    if (cam->Y < 0) cam->Y = 0;
    if (cam->Y > 8999) cam->Y = 8999;

    while (kbhit()) switch(getch()) { // handle keystrokes
      case 27: done++; break;    // ESC == quit
        // + is for zooming in.
      case '=': case '+': cam->Fov -= 1.0; if (cam->Fov < 1.0) cam->Fov = 1.0;
        sprintf(lastmessage,"FOV: %2.f",cam->Fov);
      break;
        // - is for zooming out
      case '-': cam->Fov += 1.0; if (cam->Fov > 179.0) cam->Fov = 179.0;
        sprintf(lastmessage,"FOV: %2.f",cam->Fov);
      break;
        // [ decreases mouse sensitivity
      case '[': mouse_sens /= 1.1;
        sprintf(lastmessage,"MouseSens: %.3f",mouse_sens);
      break;
        // ] increases mouse sensitivity
      case ']': mouse_sens *= 1.1;
        sprintf(lastmessage,"MouseSens: %.3f",mouse_sens);
      break;
        // v toggles vsync
      case 'v': wait_vsync ^= 1;
        sprintf(lastmessage,"VSync %s",wait_vsync ? "on" : "off");
      break;
        // s toggles sky
      case 's': draw_sky ^= 1;
        sprintf(lastmessage,"Sky %s",draw_sky ? "on" : "off");
      break;
    }
  }
  // set text mode
  set_mode3();
  // clean up
  free(framebuffer);
  plObjDelete(land);
  plObjDelete(sky);
  plObjDelete(sky2);
  plMatDelete(mat[0]);
  plMatDelete(mat[1]);
  plMatDelete(mat[2]);
  plCamDelete(cam);

  printf("This has been a Plush demo app.\n"
         "Visit the Plush 3D homepage at: \n"
         "  http://nullsoft.home.ml.org/plush/\n\n");
}