Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualBrother Bob

Posted 22 July 2013 - 12:12 PM

Well, I think before you go much further, you should consider reorganizing the fundamentals of your draw functions.  Right now, both ships have offsets from the center of the screen hard-coded into the line_loop function calls.  I think you should make only one ship definition which is centered on the screen at (0.0, 0.0), X and Y.

 

Now both ships can be drawn with only one function which is being fed the individual ships configuration.  This will make all of the rest of the code come together much more smoothly.  For instance, right now, because the offsets are hard-coded into the ships, when you rotate them, they will behave like they are on a swing-arm. 

As they are now, you have to use an extra glTranslate call to center the rotation pivot back to the center of the ship.  This adds code and confuses things.  Things will get much worse than this when you add collision detection.

 

//=============================================================================

//Instead you can make a function something like this

 

void DrawShip(GLfloat position_X, GLfloat position_Y, GLfloat position_Z, GLfloat rotation, GLfloat color)

{

glPushMatrix();

  glTranslatef(position_X, position_Y, position_Z);   glRotatef(rotation, 0.0f, 0.0f,1.0f);   glColor3f(color,0.0f,0.0f); glBegin(GL_LINE_LOOP); glVertex3f(...); glVertex3f(...);

glVertex3f(...);

glVertex3f(...);

glVertex3f(...); glVertex3f(...);

  glEnd();

glPopMatrix();

}

 

//==========================================================================================================

//-------------------------------------------------------------------------------------------------------------------------------------------------------------------

//==========================================================================================================

 

Now each ship can be drawn as follows

//------------------------------------------------------

 

void Render(void)

{

        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

  //============================================

 

 

  //---------------------------------------------------------------------------------------------------------------------------------------

    //draw ship_01  

  DrawShip(ship_01_POSITION_X, ship_01_POSITION_Y, ship_01_POSITION_Z, ship_01_ROTATION, ship_01_COLOR);

  //---------------------------------------------------------------------------------------------------------------------------------------

        //draw ship_02

  DrawShip(ship_02_POSITION_X, ship_02_POSITION_Y, ship_02_POSITION_Z, ship_02_ROTATION, ship_02_COLOR);

  //---------------------------------------------------------------------------------------------------------------------------------------

 

 

  //============

  glutSwapBuffers();

}


#4marcClintDion

Posted 22 July 2013 - 03:10 AM

There is far too much arrogance and out right abuse by site moderators, they are teaching other people to behave this way.  The posts I've made will all be shorty removed and replaced with this notice.  Game development is not the only thing being taught here, bad behavior is being taught as well.


#3marcClintDion

Posted 28 June 2013 - 08:13 PM

Well, I think before you go much further, you should consider reorganizing the fundamentals of your draw functions.  Right now, both ships have offsets from the center of the screen hard-coded into the line_loop function calls.  I think you should make only one ship definition which is centered on the screen at (0.0, 0.0), X and Y.

 

Now both ships can be drawn with only one function which is being fed the individual ships configuration.  This will make all of the rest of the code come together much more smoothly.  For instance, right now, because the offsets are hard-coded into the ships, when you rotate them, they will behave like they are on a swing-arm. 

As they are now, you have to use an extra glTranslate call to center the rotation pivot back to the center of the ship.  This adds code and confuses things.  Things will get much worse than this when you add collision detection.

 

//=============================================================================

//Instead you can make a function something like this

 

void DrawShip(GLfloat position_X, GLfloat position_Y, GLfloat position_Z, GLfloat rotation, GLfloat color)

{

     glPushMatrix();

        glTranslatef(position_X, position_Y, position_Z);
        glRotatef(rotation, 0.0f, 0.0f,1.0f);
        glColor3f(color,0.0f,0.0f);
             glBegin(GL_LINE_LOOP);
                   glVertex3f(...);
                   glVertex3f(...);

                   glVertex3f(...);

                   glVertex3f(...);

                   glVertex3f(...);
                   glVertex3f(...);

            glEnd();

     glPopMatrix();

}

 

//==========================================================================================================

//-------------------------------------------------------------------------------------------------------------------------------------------------------------------

//==========================================================================================================

 

Now each ship can be drawn as follows

//------------------------------------------------------

 

void Render(void)

{

        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

        //============================================

 

 

                //---------------------------------------------------------------------------------------------------------------------------------------

                //draw ship_01      

                DrawShip(ship_01_POSITION_X, ship_01_POSITION_Y, ship_01_POSITION_Z, ship_01_ROTATION, ship_01_COLOR);

                //---------------------------------------------------------------------------------------------------------------------------------------

                //draw ship_02   

                DrawShip(ship_02_POSITION_X, ship_02_POSITION_Y, ship_02_POSITION_Z, ship_02_ROTATION, ship_02_COLOR);

                //---------------------------------------------------------------------------------------------------------------------------------------

 

 

        //============

        glutSwapBuffers();

}


#2marcClintDion

Posted 28 June 2013 - 08:11 PM

Well, I think before you go much further, you should consider reorganizing the fundamentals of your draw functions.  Right now, both ships have offsets from the center of the screen hard-coded into the line_loop function calls.  I think you should make only one ship definition which is centered on the screen at (0.0, 0.0), X and Y.

 

Now both ships can be drawn with only one function which is being fed the individual ships configuration.  This will make all of the rest of the code come together much more smoothly.  For instance, right now, because the offsets are hard-coded into the ships, when you rotate them, they will behave like they are on a swing-arm. 

As they are now, you have to use an extra glTranslate call to center the rotation pivot back to the center of the ship.  This adds code and confuses things.  Things will get much worse than this when you add collision detection.

 

Instead you can make a function something like this

 

void DrawShip(GLfloat position_X, GLfloat position_Y, GLfloat position_Z, GLfloat rotation, GLfloat color)

{

     glPushMatrix();

        glTranslatef(position_X, position_Y, position_Z);
        glRotatef(rotation, 0.0f, 0.0f,1.0f);
        glColor3f(color,0.0f,0.0f);
             glBegin(GL_LINE_LOOP);
                   glVertex3f(...);
                   glVertex3f(...);

                   glVertex3f(...);

                   glVertex3f(...);

                   glVertex3f(...);
                   glVertex3f(...);

            glEnd();

     glPopMatrix();

}

 

//=========================================================================

Now each ship can be drawn as follows

//------------------------------------------------------

 

void Render(void)

{

        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

        //============================================

 

 

                //---------------------------------------------------------------------------------------------------------------------------------------

                //draw ship_01      

                DrawShip(ship_01_POSITION_X, ship_01_POSITION_Y, ship_01_POSITION_Z, ship_01_ROTATION, ship_01_COLOR);

                //---------------------------------------------------------------------------------------------------------------------------------------

                //draw ship_02   

                DrawShip(ship_02_POSITION_X, ship_02_POSITION_Y, ship_02_POSITION_Z, ship_02_ROTATION, ship_02_COLOR);

                //---------------------------------------------------------------------------------------------------------------------------------------

 

 

        //============

        glutSwapBuffers();

}


#1marcClintDion

Posted 28 June 2013 - 08:10 PM

Well, I think before you go much further, you should consider reorganizing the fundamentals of your draw functions.  Right now, both ships have offsets from the center of the screen hard-coded into the line_loop function calls.  I think you should make only one ship definition which is centered on the screen at (0.0, 0.0), X and Y.

 

Now both ships can be drawn with only one function which is being fed the individual ships position.  This will make all of the rest of the code come together much more smoothly.  For instance, right now, because the offsets are hard-coded into the ships, when you rotate them, they will behave like they are on a swing-arm. 

As they are now, you have to use an extra glTranslate call to center the rotation pivot back to the center of the ship.  This adds code and confuses things.  Things will get much worse than this when you add collision detection.

 

Instead you can make a function something like this

 

void DrawShip(GLfloat position_X, GLfloat position_Y, GLfloat position_Z, GLfloat rotation, GLfloat color)

{

     glPushMatrix();

        glTranslatef(position_X, position_Y, position_Z);
        glRotatef(rotation, 0.0f, 0.0f,1.0f);
        glColor3f(color,0.0f,0.0f);
             glBegin(GL_LINE_LOOP);
                   glVertex3f(...);
                   glVertex3f(...);

                   glVertex3f(...);

                   glVertex3f(...);

                   glVertex3f(...);
                   glVertex3f(...);

            glEnd();

     glPopMatrix();

}

 

//=========================================================================

Now each ship can be drawn as follows

//------------------------------------------------------

 

void Render(void)

{

        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

        //============================================

 

 

                //---------------------------------------------------------------------------------------------------------------------------------------

                //draw ship_01      

                DrawShip(ship_01_POSITION_X, ship_01_POSITION_Y, ship_01_POSITION_Z, ship_01_ROTATION, ship_01_COLOR);

                //---------------------------------------------------------------------------------------------------------------------------------------

                //draw ship_02   

                DrawShip(ship_02_POSITION_X, ship_02_POSITION_Y, ship_02_POSITION_Z, ship_02_ROTATION, ship_02_COLOR);

                //---------------------------------------------------------------------------------------------------------------------------------------

 

 

        //============

        glutSwapBuffers();

}


PARTNERS