title: How to access private variables from another class?
body: <p>I'm working on a project in OpenGL, and I have it working in its most basic form. Now, I need to make it so that my "get" matrices for rotation and orbit are in my Box.cpp file, my speed variables are private, and that I have set functions for those speed variables.</p>
  
  <p>I need to access those variables in main, but since they're private, I cannot obviously.</p>
  
  <p>Can someone point me in the right direction?</p>
  
  <p>main.cpp:</p>
  
  <pre><code>#include "vgl.h"
  #include &lt;glm/glm.hpp&gt;
  #include &lt;glm/gtc/matrix_transform.hpp&gt;
  #include &lt;glm/gtc/type_ptr.hpp&gt;
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include "Box.h"
  #include "Camera.h"
  #include "VertexBufferData.h"
  #include &lt;glm/gtc/quaternion.hpp&gt;
  #include &lt;glm/gtx/quaternion.hpp&gt;
  
  using namespace std;
  using namespace glm;
  
  #define SPACEBAR_KEY 32
  #define ESCAPE_KEY 033
  
  Camera* camera;
  vector&lt;Box * &gt; gameObjects;
  bool keyDown[255];
  
  void CheckKeyboard(){
  
      if (keyDown['a'])
          camera-&gt;RotateLeft();
      if (keyDown['d'])
          camera-&gt;RotateRight();
      if (keyDown['w'])
          camera-&gt;MoveForward();
      if (keyDown['s'])
          camera-&gt;MoveBackWard();
      if (keyDown['e'])
          camera-&gt;StrafeRight();
      if (keyDown['q'])
          camera-&gt;StrafeLeft();
  }
  
  void closeApp()
  {
      delete camera;
      for (auto it = gameObjects.begin(); it != gameObjects.end(); ++it) {
          delete (*it);
      }
  }
  
  
  void keyboard(unsigned char key, int x, int y)
  {
      switch (key) 
      {
          case ESCAPE_KEY:  // ASCII Escape Key Code
              closeApp();
              exit(EXIT_SUCCESS);
              break;
          default:
              keyDown[key] = true;
      }
  
      glutPostRedisplay();
  }
  
  void keyboardUp(unsigned char key, int x, int y)
  {
      keyDown[key] = false;
  }
  
  void mouseWheel(int button, int direction, int x, int y)
  {
  
      if (button == 16)
          camera-&gt;ResetFOV();
      else if (direction &gt; 0)
          camera-&gt;ZoomIn();
      else
          camera-&gt;ZoomOut();
  }
  
  void mouseMovement(int x, int y)
  {
      static bool warp = true;
  
      if (warp)
      {
          if (x&gt;glutGet(GLUT_WINDOW_WIDTH) / 2)
              camera-&gt;RotateRight();
          else if (x&lt;glutGet(GLUT_WINDOW_WIDTH) / 2)
              camera-&gt;RotateLeft();
  
          if (y&gt;glutGet(GLUT_WINDOW_HEIGHT) / 2)
              camera-&gt;RotateUp();
          else if (y&lt;glutGet(GLUT_WINDOW_HEIGHT) / 2)
              camera-&gt;RotateDown();
  
          glutWarpPointer(glutGet(GLUT_WINDOW_WIDTH) / 2, glutGet(GLUT_WINDOW_HEIGHT) / 2);
          warp = false;
      }
      else
          warp = true;
  }
  
  void timer(int value)
  {
      glutPostRedisplay();
      glutTimerFunc(25, timer, 0);
  }
  
  void display()
  {
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  
      CheckKeyboard();
      camera-&gt;Update();
      for (auto it = gameObjects.begin(); it != gameObjects.end(); ++it) {
          (*it)-&gt;shaderProgram-&gt;bindShader();
          glm::mat4 MVP = camera-&gt;ProjectionMatrix *  camera-&gt;ViewMatrix * (*it)-&gt;getModelMatrix();
          (*it)-&gt;shaderProgram-&gt;sendUniform4x4("MVP", glm::value_ptr(MVP));
          (*it)-&gt;Draw();
      }
      glutSwapBuffers();
  }
  
  void init()
  {
      int i = 0;
  
      camera = new Camera();
      memset(keyDown, false, sizeof(keyDown));
  
      glClearColor(0.0f, 0.0f, 0.4f, 0.0f);
      glutWarpPointer(glutGet(GLUT_WINDOW_WIDTH) / 2, glutGet(GLUT_WINDOW_HEIGHT) / 2);
      glutSetCursor(GLUT_CURSOR_FULL_CROSSHAIR);
  
      glEnable(GL_DEPTH_TEST);
      glDepthFunc(GL_LEQUAL);
      glEnable(GL_CULL_FACE);
  
      VertexBufferData vertexBufferData = VertexBufferData("Data\\Models\\Objects.xml");
  
      gameObjects.push_back(new Box(vertexBufferData, glm::vec3(0.0f, 0.0f, 0.0f), "Data\\Shaders\\Vertex.shader", "Data\\Shaders\\Fragment.shader"));
  
      gameObjects.push_back(new Box(vertexBufferData, glm::vec3(4.0f, 0.0f, 0.0f), "Data\\Shaders\\Vertex.shader", "Data\\Shaders\\Fragment.shader"));
  
      gameObjects[1]-&gt;rotationSpeed = 5.0f;
      gameObjects[0]-&gt;rotationSpeed = 2.5f;
      gameObjects[1]-&gt;orbitSpeed = 1.0f;
      //gameObjects[1]-&gt;setRotation(45.0f, vec3(0.0f, 0.0f, 1.0f));
      //gameObjects[0]-&gt;setScaleMatrix(vec3(2, 2, 2));
      //gameObjects[1]-&gt;setOrbitMatrix(vec3(2.0f, 0.0f, 0.0f), 45.0f, 1, 365, 0);
  }
  
  
  
  int main(int argc, char** argv)
  {
      glutInit(&amp;argc, argv);
  
      glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH);
      glutInitWindowSize(1024, 768);
      glutInitContextProfile(GLUT_CORE_PROFILE);
      glutCreateWindow("Satterwhite_Project_3");
  
  
      if (glewInit())
      {
          cerr &lt;&lt; "Unable to init glew" &lt;&lt; endl;
          exit(EXIT_FAILURE);
      }
  
      init();
      glutDisplayFunc(display);
      glutKeyboardFunc(keyboard);
      glutKeyboardUpFunc(keyboardUp);
      glutPassiveMotionFunc(mouseMovement);
      glutMouseWheelFunc(mouseWheel);
      glutTimerFunc(25, timer, 0);
      glutMainLoop();
      return 0;
  }
  </code></pre>
  
  <p>Box.cpp:</p>
  
  <pre><code>#include "Box.h"
  
  Box::Box(VertexBufferData &amp;vbd,  vec3 initialPosition,const string vertexShader, const string fragmentShader):GameObject(vertexShader, fragmentShader)
  {   
      degreesRotated = 0.0f;
      rotationSpeed = 0.0f;
      orbitSpeed = 0.0f;
      Position=initialPosition;
      vertexBufferData =vbd;
  
      RotationMatrix=mat4(1.0f);
      OrbitMatrix = mat4(1.0f);
      ScaleMatrix=mat4(1.0f);
      TranslationMatrix =translate(glm::mat4(1.0f), Position);
  
      if (!shaderProgram-&gt;initialize())
      {
          std::cerr &lt;&lt; "Could not initialize the shaders" &lt;&lt; std::endl;
      }
  
      shaderProgram-&gt;bindShader();
  
      glGenVertexArrays(1, &amp;VAO);
      glBindVertexArray(VAO);
  
      glGenBuffers(1, &amp;vertexBuffer);
      glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
      glBufferData(GL_ARRAY_BUFFER, vertexBufferData.verticiesSize, &amp;vertexBufferData.verticies[0], GL_STATIC_DRAW);
  
      glGenBuffers(1, &amp;fragmentBuffer);
      glBindBuffer(GL_ARRAY_BUFFER, fragmentBuffer);
      glBufferData(GL_ARRAY_BUFFER, vertexBufferData.colorSize, &amp;vertexBufferData.colors[0], GL_STATIC_DRAW);
  
      shaderProgram-&gt;linkProgram();
  }
  void Box::setRotation(float degrees, vec3 axis)
  {
      RotationMatrix = rotate(RotationMatrix, degrees, axis);
  }
  
  void Box::setScaleMatrix(vec3 scale)
  {
      ScaleMatrix = glm::scale(mat4(1.0f), scale);
  }
  
  void Box::setOrbitMatrix(float degrees, vec3 axis)
  {
      OrbitMatrix = rotate(OrbitMatrix, degrees, axis);
  }
  
  void Box::Draw()
  {
      shaderProgram-&gt;bindShader();
  
      glEnableVertexAttribArray(0);
      glEnableVertexAttribArray(1);
  
      glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
      glVertexAttribPointer(0, 3, GL_FLOAT,GL_FALSE, 0, BUFFER_OFFSET(0));
  
      glBindBuffer(GL_ARRAY_BUFFER, fragmentBuffer);
      glVertexAttribPointer(1, 3, GL_FLOAT,GL_FALSE, 0, BUFFER_OFFSET(0));    
  
      glDrawArrays(GL_TRIANGLES, 0, vertexBufferData.verticies.size());
  
      glDisableVertexAttribArray(0);
      glDisableVertexAttribArray(1);
  }
  </code></pre>
  
  <p>Box.h:</p>
  
  <pre><code>#pragma once
  #include "GameObject.h"
  
  class Box :  public GameObject
  {
  
  private:
      mat4 ModelMatrix;
      mat4 RotationMatrix;
      mat4 OrbitMatrix;
      mat4 TranslationMatrix;
      mat4 ScaleMatrix;
  public:
      float rotationSpeed, orbitSpeed, degreesRotated;
      void Draw();
      virtual ObjectType getType() const { return BOX; }
  
      mat4 getModelMatrix() {return getOrbitMatrix()*TranslationMatrix*getRotationMatrix()*ScaleMatrix;}
      mat4 getRotationMatrix()
      { 
          setRotation(rotationSpeed, vec3(0.0f, 0.0f, 1.0f));
          return RotationMatrix;
      }
      mat4 getTranslationMatrix() {return TranslationMatrix;}
      mat4 getOrbitMatrix()
      {
          setOrbitMatrix(orbitSpeed, vec3(0.0f, 0.0f, 1.0f));
          return OrbitMatrix;
      }
      mat4 getScaleMatrix() {return ScaleMatrix;}
      void setRotation(float degrees, vec3 axis);
      void setScaleMatrix(vec3 scale);
      void setOrbitMatrix(float degrees, vec3 axis);
  
      Box(VertexBufferData &amp;vertexBufferData, vec3 initialPosition, const string vertexShader, const string fragmentShader);
  
      vec3 Position;
  };
  </code></pre>