Ejemplo n.º 1
0
// The initialization method caused when a world object is created
World6::World6(WindowFramework* windowFrameworkPtr)
   : m_windowFramework(windowFrameworkPtr),
     m_title("title", COnscreenText::TS_plain),
     m_sizescale(1),
     m_sky(),
     m_skyTex(NULL),
     m_sun(),
     m_sunTex(NULL),
     m_orbitscale(1),
     m_orbitRootMercury(),
     m_orbitRootVenus(),
     m_orbitRootMars(),
     m_orbitRootEarth(),
     m_orbitRootMoon(),
     m_mercury(),
     m_mercuryTex(NULL),
     m_venus(),
     m_venusTex(NULL),
     m_mars(),
     m_marsTex(NULL),
     m_earth(),
     m_earthTex(NULL),
     m_moon(),
     m_moonTex(NULL),
     m_yearscale(1),
     m_dayscale(1),
     m_dayPeriodSun(NULL),
     m_orbitPeriodMercury(NULL),
     m_dayPeriodMercury(NULL),
     m_orbitPeriodVenus(NULL),
     m_dayPeriodVenus(NULL),
     m_orbitPeriodEarth(NULL),
     m_dayPeriodEarth(NULL),
     m_orbitPeriodMoon(NULL),
     m_dayPeriodMoon(NULL),
     m_orbitPeriodMars(NULL),
     m_dayPeriodMars(NULL),
     m_mouse1EventText("label"),
     m_skeyEventText("label"),
     m_ykeyEventText("label"),
     m_vkeyEventText("label"),
     m_ekeyEventText("label"),
     m_mkeyEventText("label"),
     m_yearCounterText("label"),
     m_yearCounter(0),
     m_simRunning(true)
   {
   // The standard camera position and background initialization
   m_windowFramework->get_graphics_window()->get_active_display_region(0)->
      set_clear_color(Colorf(0, 0, 0, 0));
   // base.disableMouse() // Note: mouse ain't enable by default in C++
   NodePath camera = m_windowFramework->get_camera_group();
   camera.set_pos(0, 0, 45);
   camera.set_hpr(0, -90, 0);

   // The global variables we used to control the speed and size of objects
   m_yearscale = 60;
   m_dayscale = m_yearscale / 365.0 * 5;
   m_orbitscale = 10;
   m_sizescale = 0.6;

   load_planets();            // Load, texture, and position the planets
   rotate_planets();          // Set up the motion to start them moving

   // The standard title text that's in every tutorial
   // Things to note:
   // -fg represents the forground color of the text in (r,g,b,a) format
   // -pos  represents the position of the text on the screen.
   //       The coordinate system is a x-y based wih 0,0 as the center of the
   //       screen
   // -align sets the alingment of the text relative to the pos argument.
   //       Default is center align.
   // -scale set the scale of the text
   // -mayChange argument lets us change the text later in the program.
   //        By default mayChange is set to 0. Trying to change text when
   //        mayChange is set to 0 will cause the program to crash.
   m_title.set_text("Panda3D: Tutorial 1 - Solar System");
   m_title.set_fg(Colorf(1, 1, 1, 1));
   m_title.set_pos(LVecBase2f(0.8, -0.95));
   m_title.set_scale(0.07);
   m_title.reparent_to(m_windowFramework->get_aspect_2d());
   m_mouse1EventText = gen_label_text(
     "Mouse Button 1: Toggle entire Solar System [RUNNING]", 0);
   m_skeyEventText = gen_label_text("[S]: Toggle Sun [RUNNING]", 1);
   m_ykeyEventText = gen_label_text("[Y]: Toggle Mercury [RUNNING]", 2);
   m_vkeyEventText = gen_label_text("[V]: Toggle Venus [RUNNING]", 3);
   m_ekeyEventText = gen_label_text("[E]: Toggle Earth [RUNNING]", 4);
   m_mkeyEventText = gen_label_text("[M]: Toggle Mars [RUNNING]", 5);
   m_yearCounterText = gen_label_text("0 Earth years completed", 6);

   m_yearCounter = 0;            // year counter for earth years
   m_simRunning = true;          // boolean to keep track of the
                                    // state of the global simulation

   // Events
   // Each self.accept statement creates an event handler object that will call
   // the specified function when that event occurs.
   // Certain events like "mouse1", "a", "b", "c" ... "z", "1", "2", "3"..."0"
   // are references to keyboard keys and mouse buttons. You can also define
   // your own events to be used within your program. In this tutorial, the
   // event "newYear" is not tied to a physical input device, but rather
   // is sent by the function that rotates the Earth whenever a revolution
   // completes to tell the counter to update
   // Note: need to listen to input events
   m_windowFramework->enable_keyboard();
   PandaFramework* pfw = m_windowFramework->get_panda_framework();
   // Exit the program when escape is pressed
   pfw->define_key("escape", "sysExit", sys_exit, NULL);
   pfw->define_key("mouse1", "handleMouseClick", call_handle_mouse_click, this);
   pfw->define_key("e", "handleEarth", call_handle_earth, this);
   pfw->define_key("s",                   // message name
         "togglePlanetSun",           // Note: event description
         call_toggle_planet<P_sun>,   // function to call
         this);                       // arguments to be passed to togglePlanet
                                      // See togglePlanet's definition below for
                                      // an explanation of what they are
   // Repeat the structure above for the other planets
   pfw->define_key("y", "togglePlanetMercury",
      call_toggle_planet<P_mercury>, this);
   pfw->define_key("v", "togglePlanetVenus",
      call_toggle_planet<P_venus>, this);
   pfw->define_key("m", "togglePlanetMars",
      call_toggle_planet<P_mars>, this);
   EventHandler::get_global_event_handler()->add_hook("newYear",
                                                       call_inc_year,
                                                       this);
   }
Ejemplo n.º 2
0
// The initialization method caused when a world object is created
World5::World5(WindowFramework* windowFrameworkPtr)
   : m_windowFrameworkPtr(windowFrameworkPtr),
     m_title("title", COnscreenText::TS_plain),
     m_sizescale(1),
     m_sky(),
     m_skyTex(NULL),
     m_sun(),
     m_sunTex(NULL),
     m_orbitscale(1),
     m_orbitRootMercury(),
     m_orbitRootVenus(),
     m_orbitRootMars(),
     m_orbitRootEarth(),
     m_orbitRootMoon(),
     m_mercury(),
     m_mercuryTex(NULL),
     m_venus(),
     m_venusTex(NULL),
     m_mars(),
     m_marsTex(NULL),
     m_earth(),
     m_earthTex(NULL),
     m_moon(),
     m_moonTex(NULL),
     m_yearscale(1),
     m_dayscale(1),
     m_dayPeriodSun(NULL),
     m_orbitPeriodMercury(NULL),
     m_dayPeriodMercury(NULL),
     m_orbitPeriodVenus(NULL),
     m_dayPeriodVenus(NULL),
     m_orbitPeriodEarth(NULL),
     m_dayPeriodEarth(NULL),
     m_orbitPeriodMoon(NULL),
     m_dayPeriodMoon(NULL),
     m_orbitPeriodMars(NULL),
     m_dayPeriodMars(NULL)
   {
   // This is the initialization we had before
   m_title.set_text("Panda3D: Tutorial 1 - Solar System");
   m_title.set_fg(Colorf(1, 1, 1, 1));
   m_title.set_pos(LVecBase2f(0.8, -0.95));
   m_title.set_scale(0.07);
   m_title.reparent_to(m_windowFrameworkPtr->get_aspect_2d());

   // Set the background to black
   m_windowFrameworkPtr->set_background_type(WindowFramework::BT_black);
   // Note: mouse ain't enable by default in C++
   // base.disableMouse()              // disable mouse control of the camera
   NodePath camera = m_windowFrameworkPtr->get_camera_group();
   camera.set_pos(0, 0, 45);           // Set the camera position (X, Y, Z)
   camera.set_hpr(0, -90, 0);          // Set the camera orientation
                                       // (heading, pitch, roll) in degrees

   // Here again is where we put our global variables. Added this time are
   // variables to control the relative speeds of spinning and orbits in the
   // simulation
   // Number of seconds a full rotation of Earth around the sun should take
   m_yearscale = 60;
   // Number of seconds a day rotation of Earth should take.
   // It is scaled from its correct value for easier visability
   m_dayscale = m_yearscale / 365.0 * 5;
   m_sizescale = 0.6;                  // relative size of planets
   m_orbitscale = 10;                  // relative size of orbits

   load_planets();                     // Load our models and make them render

   // Finally, we call the rotatePlanets function which puts the planets,
   // sun, and moon into motion.
   rotate_planets();
   }