Jump to content
  • Advertisement
Sign in to follow this  
Prog101

getting the direction vector

This topic is 4144 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have run into a little problem i need to get the direction of which way my tower faces, how can i get the direction vector?
const float TankTower::ANGLE_RATE = 1.0f; 
const float TankTower::MAX_ANGLE = 45.0f; 

void TankTower::getWorldPosition(D3DXVECTOR3 &position) 
{ 
   position.x = finalMatrix.m[3][0]; 
   position.y = finalMatrix.m[3][1]; 
   position.z = finalMatrix.m[3][2]; 
} 
/******************************************************************** 
* update() 
********************************************************************/ 
void TankTower::update(float dtime, D3DXVECTOR3 TankTowerOffSetPos,bool Left, bool Right) 
{    
   positionVector.x = TankTowerOffSetPos.x; 
   positionVector.y = TankTowerOffSetPos.y; 
   positionVector.z = TankTowerOffSetPos.z; 
   //Turn the Tower of the Tank 

   if (Right) 
   { 
      if (TurningAngle <= MAX_ANGLE) 
      { 
         TurningAngle += ANGLE_RATE; 
      } 
      else 
         TurningAngle = MAX_ANGLE; 
   } 
   if (Left) 
   { 
      if (TurningAngle >= -MAX_ANGLE) 
      { 
         TurningAngle += -ANGLE_RATE; 
      } 
      else 
         TurningAngle = -MAX_ANGLE; 
   } 
} 
/******************************************************************** 
* render() 
********************************************************************/ 
void TankTower::render(LPDIRECT3DDEVICE9 device) 
{ 
   D3DXMatrixTranslation(&transMatrix, positionVector.x, positionVector.y, positionVector.z); 
   // Turn the TankTower to a steering angle 
   D3DXMatrixRotationY(&rotMatrix,D3DXToRadian(TurningAngle)); 
   D3DXMatrixScaling(&scaleMatrix, size, size, size); 
   D3DXMatrixMultiply(&transMatrix, &rotMatrix, &transMatrix); 
   D3DXMatrixMultiply(&transMatrix, &scaleMatrix, &transMatrix);    
   // multiply the TankTower matrix by the Tank matrix to set it relative to the Tank 
   D3DXMatrixMultiply(&finalMatrix, &transMatrix, &pTank->transMatrix); 
   device->SetTransform(D3DTS_WORLD, &finalMatrix); 
   Model->render(device); 
} 
 

Share this post


Link to post
Share on other sites
Advertisement
Assuming this is in 2D (since your turret orientation is represented by a single angle), you can get the x coord with a cos, and the y with a sin.

Share this post


Link to post
Share on other sites
Does the turret rotate in 2D or 3D? As long as it just rotates in the XZ (or whatever) plane, it should work fine. Just substitute z for y in my earlier post.

Heres how it works in the D3D coord system:

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!