Saturday, 15 May 2010

c++ - Changing vectors that were already created -


I am working on a project that pulls the solar system. I make planets only once in my main function.

  int main (int argc, char * argv []) {SolarSystem app (argc, argv); // Create Solar System App CreatePlanets (); // Create planets in solar system app.run (); Return 0; }   

This is my createPlanets () function which is vector & lt; Planet & gt; Sets the value for the planets; vector.

  Zero Solar System :: Creating Panels () const {// File Texture / Radius / / Orbit / Tilt Angle Planets Push_back (Planet ("Images / Sun.jpg", 696, 696, 2500.0, 0.0), 0.0)); // Planets. Push_back (Planet ("Images / Mercury JPG", 2.44, 2.44, 57 9 10.0, 45740.0, 0.0)); 1 1 Planet Push_back (Planet ("images / venus.jpg", 6.05, 6.05, 108200.0, 107464.0, 177.3)); 2 planets 2 Push_back (Planet ("Images / Earth.jpg", 6.37, 6.34, 14 9 600.0, 147102.0, 23.5)); // planet3.paste_back (planet ("picture / moon.jpg", 1.74, 1.73, 384.0, 383.0, 5.145)); 4 4 planets. Push_back (Planet ("Picture / Merse.jpg", 3.3 9, 3.37, 227, 40.0, 207425.0, 25.2)); // 5 planets Push_back (Planet ("Images / Jupiter JPG", 69.90, 65.24, 778330.0, 740734.0, 3.1)); / 6 planets Push_back (Planet ("Images / Neptune. JPG", 24.63, 24.08, 4504300.0, 4460608.0, 29.6)); 7 7 planets. Push_back (Planet ("Picture / Pluto JPG", 1.1 5, 1.15, 5913520.0, 4475140.0, 29.6)); // 8}   

I am creating a menu where the user can change the scale of the planets so that they can be easily seen (the actual scale planets are actually hard to find) . To change the shape, I have to go to vector and change the radius of every planet object there.

Does anyone know how I can do this? Each frame in the display function below draws the planets.

  Zero Solar System :: Display (GLCentexData and ContactData) console {if (ShowOrbit) display orbitpath (); // These variables set the orbit and rotation speed of each planet / Sun / Mer wain ear moon march jumps napa plu double orbit [] = {0.0, 4.15, 1.600, 1.00, 13.0, 0.40, 0.08, 0.006, 0.004}; Double rotat s [] = {1.0, 0.50, 0.125, 30.0, 1.00, 30.0, 75.0, 40.00, 5.000}; // ii = index counter for variables above 0; // Vector Iteration (Study :: Vector and LeTinum; Planet>: For :: Iterator = planets.bgIN (); it! = Planets.end (); ++ it) {// If the planet is displayed If the Sun is Sun (I == 0) // Shading Off GlDisable (GL_LIGHTING); Turn on the other // spot where the sun is in a light source {GLfloat light_diffuse [] = {1.5, 1.5, 1.5, 1.5}; GLfloat pos [] = {2500.0, 0.0, 0.0, 1.0}; GlEnable (GL_LIGHTING); GlLightfv (GL_LIGHT0, GLDIFIFE, LITE_Diffus); GlLightfv (GL_LIGHT0, GL_POSITION, position); } If (i == 4) // Moon {it-> displayPlanet (orbitCounter * orbitS [i], orbitCounter * rotatS [i], Planet [3] .getMajorAxis (), Planet [3] .getMinorAxis ()); } Other // Planets-> Displayplanet (Orbit counters * Orbits [I] * 0, Orbit counters * Rotat S [i], 0.0.0.0); I ++; } // used to calculate the base counter class and rotation speed class counter + = 0.05; // 9 0750.0 Whether Pluto is required once in a class around the Sun if (orbitCounter> 89750.0) orbitCounter = 0.0; }   

I want to add a statement where I can say

  int scale = 1; If (changeScale) scale == 100;   

Then I will multiply the radius by scale if the changeScale is not set, then the planet should remain in the same size. If changeScale is selected which will grow to 100 in the size of planets. Is there no way in which to accept every planet? If this is not possible, how can I do this to duplicate the planets every frame? I'm not sure how I can modify the object inside my vector.

Thank you!

You planet s in your vector Can modify. It will look something like this:

  planet [index] .mail = new_val;   

Or, if there are variables, then private and you have accessory methods,

  planet [index] .setMember ( New_val);   

So, if you want to change the radius, then it looks like one of the two lower statements:

  if (changeScale) {for (Int I = 0; i & lt; Planetary size (); ++ i) {Planets [i] .radius * = 100; // this planet [i] .createdia (planets [i] .getRadius () * 100); // or}}   

Or, you can use iterator s:

  if (changeScale) {for (Std :: vector & gt; planet & gt; :: iterator = planetary. BgIN (); it! = Planets.and (); ++ this) {(* this). Radius * = 100; // It (* this) .setRadius ((* this) .getRadius () * 100); //}}}}    

No comments:

Post a Comment