views:

111

answers:

1

i've a header file called base.h which has all initial display and stuff like, my main aim is to simulate a robot with degree of freedom.


class center_rods
{
    public:
        center_rods()
        {

        }

         void draw_center_rod()
         {
                glPushMatrix();
                        glTranslatef(0,1,0);
                        glRotatef(90.0,1.0,0.0,0.0);  
                        glScalef(0.3,5,0.3);
                        glColor3f(0,0,1);
                        glutSolidCube(1.0);
                glPopMatrix();
         }

/*  design and implementation of clamp holder of center rod, needs to be done   */

};



class base_of_robot: public base1 
{


    public:
        base_of_robot()
        {

        }

in main program called robo.cpp, i want to achieve these things, * can i pass arguements from main program to header file? because i use a glutkeyBoardFunc(), so i need my robot arm to translate and rotate based upon keys, like this


case 'a':
                    to_arm = 0, fro_arm = 0;
                    glutTimerFunc(100, myTimerFunc, 3);
                    break;
  • How do i pass parameters to header file, since all re-display is controlled from the header file.
+1  A: 

You should put some state to represent the transformations inside one of the classes (probably the robot). You can represent the orientation as Euler angles, a matrix or quaternion, but Euler angles are probably the simplest to start out with.

The glutkeyBoardFunc function should then modify this state through member functions defined on the enclosing class, like RotateX(float amountInRadians). Your draw functions should be based on the state in the classes. This way, you are passing data into an instance of the class defined in the header file.

Taking a step back, you should search for a basic tutorial on using glut which will show you how you might structure your program (e.g http://nehe.gamedev.net/). Many of these are written in C (or are largely procedural), so they often don't illustrate the object oriented design you hinted at.

Alex Peck
i'm using c++ to implement this, so doing oops way, so according to you, in header file of class, i need to define custom functions, then pass through objects.I'll try and then come back, thanks...
abhilashm86