Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#ActualBrother Bob

Posted 22 July 2013 - 12:06 PM

I was helping someone else on another thread to get a model of his rotating towards where he touches the screen with his finger.  Since I already had your code pasted into a simple framework I decided to work on his using the ship code we have been working on.  Here are the results so far.  It is still in the preliminary stages but it is working. 

 

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

void Render(void)

{

       
//============================= - The next seven lines of code seems to have round 1 taken care of.
incrementTime += 0.001;  
       //--------------------------------
       
       distanceBetweenModels[1] = ship_02_POSITION[1] - ship_01_POSITION[1];                              
       distanceBetweenModels[0] = ship_02_POSITION[0] - ship_01_POSITION[0];                                    
 
       //------------------------------------------------------------------------------------------------------
 
       targetRotation = atan2(distanceBetweenModels[0], distanceBetweenModels[1])* 180 / 3.14159;        
 
       
       blendedRotation = (startRotation * (1.0 - sliderTime)) + (targetRotation * sliderTime);                        
 
       if(sliderTime <= 1.0) // This will prevent the rotation from over-shooting
       {
             sliderTime += incrementTime;                                                                                                
       }
 
       //=====================================================================================================================
      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();
       //=========================================================================================
 
}

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

 

What happens here is ship_01 rotates towards ship_02 when the program starts up.  There is nothing yet to update the program so that it will keep happening as the program parameters changes.  It is basically, for now,  a two frame animation that causes a smooth rotation to take place.  It has to be updated still so that it can be an infinite number of frames that take place one after the other as things progress.  We'll have to see how this goes but I think it will work better than my other solutions up to this point.


#3marcClintDion

Posted 22 July 2013 - 03:09 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.


#2marcClintDion

Posted 02 July 2013 - 12:13 AM

I was helping someone else on another thread to get a model of his rotating towards where he touches the screen with his finger.  Since I already had your code pasted into a simple framework I decided to work on his using the ship code we have been working on.  Here are the results so far.  It is still in the preliminary stages but it is working. 

 

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

void Render(void)

{

       
       //============================= - The next seven lines of code seems to have round 1 taken care of.
       incrementTime += 0.001;     
       //--------------------------------    
       
       distanceBetweenModels[1] = ship_02_POSITION[1] - ship_01_POSITION[1];                                 
       distanceBetweenModels[0] = ship_02_POSITION[0] - ship_01_POSITION[0];                                                     
 
       //------------------------------------------------------------------------------------------------------
 
       targetRotation = atan2(distanceBetweenModels[0], distanceBetweenModels[1])* 180 / 3.14159;            
 
       
       blendedRotation = (startRotation * (1.0 - sliderTime)) + (targetRotation * sliderTime);                                 
 
       if(sliderTime <= 1.0) // This will prevent the rotation from over-shooting
       {
             sliderTime += incrementTime;                                                                                                   
       }
 
       //=====================================================================================================================
      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();
       //=========================================================================================
 
}

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

 

What happens here is ship_01 rotates towards ship_02 when the program starts up.  There is nothing yet to update the program so that it will keep happening as the program parameters changes.  It is basically, for now,  a two frame animation that causes a smooth rotation to take place.  It has to be updated still so that it can be an infinite number of frames that take place one after the other as things progress.  We'll have to see how this goes but I think it will work better than my other solutions up to this point.


#1marcClintDion

Posted 01 July 2013 - 06:41 PM

I was helping someone else on another thread to get a model of his rotating towards where he touches the screen with his finger.  Since I already had your code pasted into a simple framework I decided to work on his using the ship code we have been working on.  Here are the results so far.  It is still in the preliminary stages but it is working. 

 

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

void Render(void)

{

       
       //============================= - The next seven lines of code seems to have round 1 taken care of.
       incrementTime += 0.001;     
       //--------------------------------    
       
       distanceBetweenModels[1] = ship_02_POSITION[1] - ship_01_POSITION[1];                                      //  Y2 - Y1      <--distance formula...high school math? check!
       distanceBetweenModels[0] = ship_02_POSITION[0] - ship_01_POSITION[0];                                                 //  X2 - X1                         
 
       //------------------------------------------------------------------------------------------------------
 
       targetRotation = atan2(distanceBetweenModels[0], distanceBetweenModels[1])* 180 / 3.14159;                    //<- atan2 function... high school math? ...check!
 
       
       blendedRotation = (startRotation * (1.0 - sliderTime)) + (targetRotation * sliderTime);                                    //<- mix()... high school math?  sure why not... check!
 
       if(sliderTime <= 1.0) // This will prevent the rotation from over-shooting
       {
             sliderTime += incrementTime;                                                                                                   
       }
 
       //=====================================================================================================================
      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();
       //=========================================================================================
 
}

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

 

What happens here is ship_01 rotates towards ship_02 when the program starts up.  There is nothing yet to update the program so that it will keep happening as the program parameters changes.  It is basically, for now,  a two frame animation that causes a smooth rotation to take place.  It has to be updated still so that it can be an infinite number of frames that take place one after the other as things progress.  We'll have to see how this goes but I think it will work better than my other solutions up to this point.


PARTNERS