   2D rotating vertices with rotation center
  HiI'm trying to rotate four vertices (a quad) around a specific rotation center. What I know by now is, that I have to transform my coordinates (the vertices) with an rotation matrix (e.g from D3DXMatrixRotationZ(...)).But how exactly will the transforming be done? Is there a methode available like D3DXMatrixRotationZ(...)?Also what about the rotation center? How do I apply this one? I searched around in the forums but that didn't give me the right clue. I also read the article "2D in Direct3D using Textured Quads", but this didn't helped my eighter.Thanks in advance   
Quote:Original post by SnowprogI'm trying to rotate four vertices (a quad) around a specific rotation center. What I know by now is, that I have to transform my coordinates (the vertices) with an rotation matrix (e.g from D3DXMatrixRotationZ(...)).But how exactly will the transforming be done? Is there a methode available like D3DXMatrixRotationZ(...)?Also what about the rotation center? How do I apply this one? I searched around in the forums but that didn't give me the right clue. I also read the article "2D in Direct3D using Textured Quads", but this didn't helped my eighter.All rotations happen around the origin. If you want to rotate about a different point, you need to move the quad there, rotate, and then move back. You can do that with the following code (untested):void CreateRotationMatrix(const D3DXVECTOR3& vRotationPt, float fAngle, D3DXMATRIX& matOut){   D3DXMATRIX matTransA, matRotate, matTransB;   D3DXMatrixTranslation(&matTransA, -vRotationPt.x, -vRotationPt.y, -vRotationPt.z);   D3DXMatrixRotationZ(&matRotate, fAngle);   D3DXMatrixTranslation(&matTransB, vRotationPt.x, vRotationPt.y, vRotationPt.z);   matOut = matTransA * matRotate * matTransB;}Alternatively, the D3DXMatrixTransformation() function may be of interest to you.   ;Quote:Original post by Evil SteveAlternatively, the D3DXMatrixTransformation() function may be of interest to you.Hi Steve,thank you for your response. I understand now how to calculate correct rotation center. Maybe you can help me once more with D3DXMatrixTransformation(). How do I apply the resulting matrix to my vertex buffer?;Quote:Original post by SnowprogHow do I apply the resulting matrix to my vertex buffer?IDirect3DDevice9::SetTransform(D3DTS_WORLD, &mat;Or, if you're using vertex shaders, it depends on your shader.   ;Quote:Original post by Evil SteveIDirect3DDevice9::SetTransform(D3DTS_WORLD, &mat);Ok, as far as I know (which is maybe wrong) I can not use SetTransform() in 2D because I have already tranformed vertices (I'm quite new to this field and have only some theorie knowledge from books). I'm using a vertex like this:m_pVertexBuffer[0].x = 100;m_pVertexBuffer[0].y = 200;m_pVertexBuffer[0].z = 0.0f;m_pVertexBuffer[0].rhw = 1.0f;m_pVertexBuffer[0].color = color;m_pVertexBuffer[0].u = 0.0f;m_pVertexBuffer[0].v = 0.0f;;Quote:Original post by SnowprogQuote:Original post by Evil SteveIDirect3DDevice9::SetTransform(D3DTS_WORLD, &mat);Ok, as far as I know (which is maybe wrong) I can not use SetTransform() in 2D because I have already tranformed vertices (I'm quite new to this field and have only some theorie knowledge from books). I'm using a vertex like this:m_pVertexBuffer[0].x = 100;m_pVertexBuffer[0].y = 200;m_pVertexBuffer[0].z = 0.0f;m_pVertexBuffer[0].rhw = 1.0f;m_pVertexBuffer[0].color = color;m_pVertexBuffer[0].u = 0.0f;m_pVertexBuffer[0].v = 0.0f;If you're using transformed vertices, then you'll have to do the rotation manually with sin() and cos(). I'd recommend not using transformed vertices though, and using an orthographic projection matrix instead (See D3DXMatrixOrthoLH()). That'd allow you to use transforms and avoid having to do it yourself (And would also allow you to use vertex shaders if you wish)   ;Quote:I'd recommend not using transformed vertices though, and using an orthographic projection matrix instead (See D3DXMatrixOrthoLH()). That'd allow you to use transforms and avoid having to do it yourself (And would also allow you to use vertex shaders if you wish)Thank you! I will try it.;Quote:I'd recommend not using transformed vertices though, and using an orthographic projection matrix instead (See D3DXMatrixOrthoLH()). That'd allow you to use transforms and avoid having to do it yourself (And would also allow you to use vertex shaders if you wish)Okay I give up. To much new stuff for me. [crying] My code looks like this and (obviously) is not working.#define D3DFVF_CUSTOMVERTEX_POSITIONTEXTURED (D3DFVF_XYZ | D3DFVF_TEX1)struct CUSTOMVERTEX_POSITIONTEXTURED{  float x, y, z;  float u, v;};CUSTOMVERTEX_POSITIONTEXTURED* pVertexBuffer = new CUSTOMVERTEX_POSITIONTEXTURED[4];// quad coordinates: location(100,100) size(100,100)pVertexBuffer[0].x = 0.0f;pVertexBuffer[0].y = 0.0f;pVertexBuffer[0].z = 1.0f;pVertexBuffer[1].x = 100.0f;pVertexBuffer[1].y = 0.0f;pVertexBuffer[1].z = 1.0f;pVertexBuffer[2].x = 0.0f;pVertexBuffer[2].y = 100.0f;pVertexBuffer[2].z = 1.0f;pVertexBuffer[3].x = 100.0f;pVertexBuffer[3].y = 100.0f;pVertexBuffer[3].z = 1.0f;// texture coordinates for quadpVertexBuffer[0].u = 0;pVertexBuffer[0].v = 0;pVertexBuffer[1].u = 1.0f;pVertexBuffer[1].v = 0;pVertexBuffer[2].u = 0;pVertexBuffer[2].v = 1.0f;pVertexBuffer[3].u = 1.0f;pVertexBuffer[3].v = 1.0f;D3DXMATRIX orthoMatrix;D3DXMatrixOrthoLH(&orthoMatrix, 1024, 768, 1, 1);D3DXMATRIX translationMatrix;D3DXMatrixTranslation(&translationMatrix, 200, 100, 0); //offsetting it (200,100)D3DXMATRIX outMatrix = orthoMatrix * translationMatrix;pDevice->SetTransform(D3DTS_WORLD, &outMatrix);pDevice->SetFVF(D3DFVF_CUSTOMVERTEX_POSITIONTEXTURED);pDevice->SetTexture(0, pTexture);pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, pVertexBuffer, sizeof(CUSTOMVERTEX_POSITIONTEXTURED));delete [] pVertexBuffer;;Quote:Okay I give up. To much new stuff for me. [crying] My code looks like this and (obviously) is not working.*** Source Snippet Removed ***Found some new information but it is still not working. The new code is:CUSTOMVERTEX_POSITIONTEXTURED* pVertexBuffer = new CUSTOMVERTEX_POSITIONTEXTURED[4];// quad coordinates: location(100,100) size(100,100)pVertexBuffer[0].x = 0.0f;pVertexBuffer[0].y = 0.0f;pVertexBuffer[0].z = 1.0f;pVertexBuffer[1].x = 100.0f;pVertexBuffer[1].y = 0.0f;pVertexBuffer[1].z = 1.0f;pVertexBuffer[2].x = 0.0f;pVertexBuffer[2].y = 100.0f;pVertexBuffer[2].z = 1.0f;pVertexBuffer[3].x = 100.0f;pVertexBuffer[3].y = 100.0f;pVertexBuffer[3].z = 1.0f;// texture coordinates for quadpVertexBuffer[0].u = 0;pVertexBuffer[0].v = 0;pVertexBuffer[1].u = 1.0f;pVertexBuffer[1].v = 0;pVertexBuffer[2].u = 0;pVertexBuffer[2].v = 1.0f;pVertexBuffer[3].u = 1.0f;pVertexBuffer[3].v = 1.0f;D3DXMATRIX identityMatrix; D3DXMatrixIdentity(&identityMatrix);D3DXMATRIX orthoMatrix;D3DXMatrixOrthoLH(&orthoMatrix, 1024, 768, 1, 1);D3DXMATRIX translationMatrix;D3DXMatrixTranslation(&translationMatrix, 200, 100, 0); //offsetting it (200,100)pDevice->SetTransform(D3DTS_VIEW, &identityMatrix);pDevice->SetTransform(D3DTS_PROJECTION, &orthoMatrix);pDevice->SetTransform(D3DTS_WORLD, &translationMatrix); pDevice->SetRenderState(D3DRS_ZENABLE, false);pDevice->SetFVF(D3DFVF_CUSTOMVERTEX_POSITIONTEXTURED);pDevice->SetTexture(0, pTexture);pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, pVertexBuffer, sizeof(CUSTOMVERTEX_POSITIONTEXTURED));delete [] pVertexBuffer;;  Okay. I got it. I will post later on wht I did.Thanks for your help!   