Explorar o código

add -c option

David Rose %!s(int64=22) %!d(string=hai) anos
pai
achega
1be1d02bc0
Modificáronse 1 ficheiros con 64 adicións e 0 borrados
  1. 64 0
      panda/src/testbed/pview.cxx

+ 64 - 0
panda/src/testbed/pview.cxx

@@ -18,6 +18,14 @@
 
 #include "pandaFramework.h"
 
+#ifndef HAVE_GETOPT
+  #include "gnu_getopt.h"
+#else
+  #ifdef HAVE_GETOPT_H
+    #include <getopt.h>
+  #endif
+#endif
+
 PandaFramework framework;
 
 void
@@ -43,11 +51,63 @@ event_W(CPT_Event, void *) {
   }
 }
 
+void 
+usage() {
+  cerr <<
+    "Usage: pview [opts] model [model ...]\n";
+    "       pview -h\n";
+}
+
+void 
+help() {
+  usage();
+  cerr << "\n"
+    "pview opens a quick Panda window for viewing one or more models and/or\n"
+    "animations.\n\n"
+
+    "Options:\n\n"
+    
+    "  -c\n"
+    "      Automatically center models within the viewing window on startup.\n"
+    "      This can also be achieved with the 'c' hotkey at runtime.\n\n"
+
+    "  -h\n"
+    "      Display this help text.\n\n";
+}
+
 int
 main(int argc, char *argv[]) {
   framework.open_framework(argc, argv);
   framework.set_window_title("Panda Viewer");
 
+  bool auto_center = false;
+
+  extern char *optarg;
+  extern int optind;
+  static const char *optflags = "ch";
+  int flag = getopt(argc, argv, optflags);
+
+  while (flag != EOF) {
+    switch (flag) {
+    case 'c':
+      auto_center = true;
+      break;
+
+    case 'h':
+      help();
+      return 1;
+    case '?':
+      usage();
+      return 1;
+    default:
+      cerr << "Unhandled switch: " << flag << endl;
+      break;
+    }
+    flag = getopt(argc, argv, optflags);
+  }
+  argc -= (optind - 1);
+  argv += (optind - 1);
+
   WindowFramework *window = framework.open_window();
   if (window != (WindowFramework *)NULL) {
     // We've successfully opened a window.
@@ -63,6 +123,10 @@ main(int argc, char *argv[]) {
     }
     window->loop_animations();
 
+    if (auto_center) {
+      window->center_trackball(framework.get_models());
+    }
+
     framework.enable_default_keys();
     framework.get_event_handler().add_hook("shift-w", event_W, NULL);
     framework.main_loop();