title: Rotating a D3DXVECTOR3 around a specific point
body: <p>This is probably a pretty simple thing but my knowledge of direct x is just not up to par with what I'm trying to achieve.</p>
  
  <p>For the moment I am trying to create a vehicle that moves around on terrain. I am attempting to make the vehicle recognize the terrain by creating a square (4 D3DXVECTOR3 points) around the vehicle who's points each detect the height of the terrain and adjust the vehicle accordingly.</p>
  
  <p>The vehicle is a simple object derived from Microsoft sample code. It has a world matrix, coordinates, rotations etc.</p>
  
  <p>What I am trying to achieve is to make these points move along with the vehicle, turning when it does so they can detect the difference in height. This requires me to update the points each time the vehicle moves but I cannot for the life of me figure out how to get them to rotate properly.</p>
  
  <p>So In summary I am looking for a simple way to rotate a vector about an origin (my vehicles coordinates).</p>
  
  <p>These points are situated near the vehicle wheels so if it worked they would stay there regardless of the vehicles y -axis rotation.</p>
  
  <p>Heres What Ive tryed:</p>
  
  <pre><code>D3DXVECTOR3 vec;
  D3DXVec3TransformCoord(&amp;vectorToHoldTransformation,&amp;SquareTopLeftPoint,&amp;matRotationY);
  SquareTopLeftPoint = vec;
  </code></pre>
  
  <p>This resulted in the point spinning madly out of control and leaving the map.</p>
  
  <pre><code>xRot = VehicleCoordinateX + cos(RotationY) * (SquareTopleftX - VehicleCoordinateX) - sin(RotationY) * (SquareTopleftZ - VehicleCoordinateZ);
  yRot = VehicleCoordinateZ + sin(RotationY) * (SquareTopleftX - VehicleCoodinateX) + cos(RotationY) * (SquareToplefteZ - VehicleCoordinateZ);
  </code></pre>
  
  <p>BoxPoint refers to the vector I am attempting to rotate.
  Vehicle is of course the origin of rotation
  RotationY is the amount it has rotated.</p>
  
  <p>This is the code for 1 of 4 vectors in this square but I assume once I get 1 write the rest are just copy-paste.</p>
  
  <p>No matter what I try the point either does not move or spirals out of control under leaving the map all-together.</p>
  
  <p>Here is a snippet of my object class</p>
  
  <pre><code>class Something
  {
  public:
      float x, y, z;
      float speed;          
      float rx, ry, rz;     
      float sx, sy, sz;
  
      float width;
      float length; 
      float frameTime;
  
  
      D3DXVECTOR3 initVecDir;
      D3DXVECTOR3 currentVecDir;
  
      D3DXMATRIX       matAllRotations;
      D3DXMATRIX       matRotateX;
      D3DXMATRIX       matRotateY;
      D3DXMATRIX       matRotateZ;
      D3DXMATRIX       matTranslate;
      D3DXMATRIX       matWorld;  
      D3DXMATRIX       matView;           
      D3DXMATRIX       matProjection;
      D3DXMATRIX       matWorldViewProjection;
  
  //these points represent a box that is used for collision with terrain.
          D3DXVECTOR3 frontLeftBoxPoint;
          D3DXVECTOR3 frontRightBoxPoint;
          D3DXVECTOR3 backLeftBoxPoint;
          D3DXVECTOR3 backRightBoxPoint;
      }
  </code></pre>
  
  <p>I was thinking it might be possible to do this using D3DXVec3TransformCoord</p>
  
  <pre><code>D3DXMatrixTranslation(&amp;matTranslate, origin.x,0,origin.z);
  D3DXMatrixRotationY(&amp;matRotateY, ry);
  D3DXMatrixTranslation(&amp;matTranslate2,width,0,-length);
  matAllRotations = matTranslate * matRotateY * matTranslate2;
  
  
  D3DXVECTOR3 newCoords;
  D3DXVECTOR3 oldCoords = D3DXVECTOR3(x,y,z);
  
  D3DXVec3TransformCoord(&amp;newCoords, &amp;oldCoords, &amp;matAllRotations);
  </code></pre>