Jump to content

  • Log In with Google      Sign In   
  • Create Account

rendering space ships


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
53 replies to this topic

#41 marcClintDion   Members   -  Reputation: 431

Like
0Likes
Like

Posted 07 July 2013 - 11:58 PM

I've made a change to how the colors are initialized and passed into DrawShip(), the changes allow the color to vary from ship to ship by using an array for the colors.

It's also a cleaner to pass the other variables to DrawShip() in this manner but not required.

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

 

GLfloat ship_01_COLOR[] = {1.0f, 0.0f, 0.0f};
GLfloat ship_02_COLOR[] = {0.0f, 1.0f, 0.0f};
 
//-----------------------------------------------------------------------------------------------------------------------------------------------
 
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);
        glTranslatef(position_X, position_Y, position_Z);
        glColor3f(color[0], color[1], color[2]);
        glBegin(GL_LINE_LOOP);
                glVertex3f(0.0f,-0.25f,0.0f);
                glVertex3f(-0.25f,-0.5f,0.0f);
                glVertex3f(-0.5f,-0.5f,0.0f);
                glVertex3f(-0.0f,0.5f,0.0f);
                glVertex3f(0.5f,-0.5f,0.0f);
                glVertex3f(0.25f,-0.5f,0.0f);
                glVertex3f(0.0f,-0.25f,0.0f);
        glEnd();
        glPopMatrix();
}

 

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

 

void Render()

{

 

        //=============================================================================================================
        glPushMatrix();
                DrawShip(ship_01_POSITION_X,ship_01_POSITION_Y,ship_01_POSITION_Z,ship_01_ROTATION, ship_01_COLOR);
        glPopMatrix();
        //=============================================================================================================
        glPushMatrix();
                DrawShip(ship_02_POSITION_X,ship_02_POSITION_Y,ship_02_POSITION_Z,ship_02_ROTATION, ship_02_COLOR);
        glPopMatrix();
        //=============================================================================================================

 

 

}


Consider it pure joy, my brothers and sisters, whenever you face trials of many kinds, because you know that the testing of your faith produces perseverance. Let perseverance finish its work so that you may be mature and complete, not lacking anything.


Sponsor:

#42 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 08 July 2013 - 02:38 PM

thanks marc but I still cant get the ship follow its nose when moving up and down.



#43 marcClintDion   Members   -  Reputation: 431

Like
0Likes
Like

Posted 08 July 2013 - 08:05 PM

Hopefully you will be able to make some sense of this.  The ship does a bit of a round about when the rotation transitions across 0-360 and 360-0 but aside from this it's working.  What I mean by round-about is the ship is not rotating by the shortest path possible.  It will require extra logic to fix this.  Sorry for not posting it in the format you are using(GLUT) and with all those control functions.  

       if(ship_01_ROTATION < targetAngle)       {               ship_01_ROTATION += 5.0;                                     }       if(ship_01_ROTATION > targetAngle)       {               ship_01_ROTATION -= 5.0;                                     }       //else if              //=======================================================================================================         glDisable(GL_CULL_FACE);     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );glViewport(0, 0, nWidth, nHeight);            glMatrixMode( GL_PROJECTION );glLoadIdentity();       glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);                  glScalef(.1, .1, .1);        //=============================================================================================================        glPushMatrix();                DrawShip(ship_01_POSITION_X,ship_01_POSITION_Y,ship_01_POSITION_Z,ship_01_ROTATION, ship_01_COLOR);        glPopMatrix();        //=============================================================================================================        glPushMatrix();                DrawShip(ship_02_POSITION_X,ship_02_POSITION_Y,ship_02_POSITION_Z,ship_02_ROTATION, ship_02_COLOR);        glPopMatrix();        //=============================================================================================================        glPushMatrix();                DrawBullet(ship_01_bullet_POSITION_X,ship_01_POSITION_Y,ship_01_POSITION_Z, ship_01_ROTATION);        glPopMatrix();        //=============================================================================================================            SwapBuffers( g_hDC );}//=====================================================================================================================//---------------------------------------------------------------------------------------------------------------------//---------------------------------------------------------------------------------------------------------------------//=====================================================================================================================void ProcessKeyboard(void){    //=======================================================================================    if (keys[VK_UP] && !keys[VK_LEFT]  && !keys[VK_RIGHT])    {       ship_01_POSITION_Y +=   0.05;       targetAngle         =   0.0;    }    if (keys[VK_DOWN] && !keys[VK_LEFT]  && !keys[VK_RIGHT])    {       ship_01_POSITION_Y -=   0.05;       targetAngle         = 180.0;    }    if (keys[VK_LEFT] && !keys[VK_DOWN]  && !keys[VK_UP])    {       ship_01_POSITION_X -=   0.05;       targetAngle         =  90.0;    }    if (keys[VK_RIGHT] && !keys[VK_DOWN]  && !keys[VK_UP])    {       ship_01_POSITION_X +=   0.05;       targetAngle         = 270.0;    }    //=======================================================================================    if (keys[VK_UP] && keys[VK_LEFT])    {       ship_01_POSITION_X -=   0.05*0.7;        ship_01_POSITION_Y +=   0.05*0.7;       targetAngle         =  45.0;    }    if (keys[VK_DOWN] && keys[VK_LEFT])    {       ship_01_POSITION_X -=   0.05*0.7;              ship_01_POSITION_Y -=   0.05*0.7;       targetAngle         = 120.0;    }    if (keys[VK_DOWN] && keys[VK_RIGHT])    {       ship_01_POSITION_X +=   0.05*0.7;              ship_01_POSITION_Y -=   0.05*0.7;       targetAngle         = 225.0;    }            if (keys[VK_UP] && keys[VK_RIGHT])    {       ship_01_POSITION_X +=   0.05*0.7;        ship_01_POSITION_Y +=   0.05*0.7;       targetAngle         =  315.0;    }

Consider it pure joy, my brothers and sisters, whenever you face trials of many kinds, because you know that the testing of your faith produces perseverance. Let perseverance finish its work so that you may be mature and complete, not lacking anything.


#44 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 09 July 2013 - 11:26 PM

well I tried your code but it is still rotating as if its on a swing arm.



#45 marcClintDion   Members   -  Reputation: 431

Like
0Likes
Like

Posted 10 July 2013 - 02:01 AM

That's because you have glRotatef() before the glTranslatef().

 

I should have made that correction above when I changed how color is being handled when I re-posted your code for DrawShip. 

 

//=============================================================================================== You have the following...

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);
        glTranslatef(position_X, position_Y, position_Z);
        glColor3f(color[0], color[1], color[2]);
        glBegin(GL_LINE_LOOP);
                glVertex3f(0.0f,-0.25f,0.0f);
                glVertex3f(-0.25f,-0.5f,0.0f);
                glVertex3f(-0.5f,-0.5f,0.0f);
                glVertex3f(-0.0f,0.5f,0.0f);
                glVertex3f(0.5f,-0.5f,0.0f);
                glVertex3f(0.25f,-0.5f,0.0f);
                glVertex3f(0.0f,-0.25f,0.0f);
        glEnd();
        glPopMatrix();
}

//============================================================= Instead, it should look 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], color[1], color[2]);
        glBegin(GL_LINE_LOOP);
                glVertex3f(0.0f,-0.25f,0.0f);
                glVertex3f(-0.25f,-0.5f,0.0f);
                glVertex3f(-0.5f,-0.5f,0.0f);
                glVertex3f(-0.0f,0.5f,0.0f);
                glVertex3f(0.5f,-0.5f,0.0f);
                glVertex3f(0.25f,-0.5f,0.0f);
                glVertex3f(0.0f,-0.25f,0.0f);
        glEnd();
glPopMatrix();
}

Consider it pure joy, my brothers and sisters, whenever you face trials of many kinds, because you know that the testing of your faith produces perseverance. Let perseverance finish its work so that you may be mature and complete, not lacking anything.


#46 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 10 July 2013 - 03:52 PM

well I put translate before rotate and it moves up and down but does not follow its nose, it moves straight up and down.



#47 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 11 July 2013 - 05:09 PM

thanks for all the help marc I have almost solved my problem. I just need a little more help.



#48 marcClintDion   Members   -  Reputation: 431

Like
0Likes
Like

Posted 12 July 2013 - 04:37 AM

keep going


Consider it pure joy, my brothers and sisters, whenever you face trials of many kinds, because you know that the testing of your faith produces perseverance. Let perseverance finish its work so that you may be mature and complete, not lacking anything.


#49 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 12 July 2013 - 02:49 PM

I am still stuck, any advice?



#50 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 13 July 2013 - 04:13 PM

any more hints or tips?



#51 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 16 July 2013 - 02:52 PM

well I have been reading the red book 6th edition



#52 marcClintDion   Members   -  Reputation: 431

Like
0Likes
Like

Posted 17 July 2013 - 11:08 AM

Have you drawn out the asteroids yet? 

I suppose collision detection should be looked at as well.  Bounding box collisions and radial collisions should be enough. 

No collision response should be necessary except to show an explosion and shut off the model drawing.


Edited by Brother Bob, 22 July 2013 - 11:51 AM.
rollback

Consider it pure joy, my brothers and sisters, whenever you face trials of many kinds, because you know that the testing of your faith produces perseverance. Let perseverance finish its work so that you may be mature and complete, not lacking anything.


#53 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 17 July 2013 - 04:54 PM

no not yet I am still working on the space ship movement.



#54 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 18 July 2013 - 07:28 PM

anymore input marc?






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS