开发者

rotation, translation in opengl through header file?

开发者 https://www.devze.com 2022-12-20 01:01 出处:网络
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.

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消