# Rotation of a rectangle

## Recommended Posts

Hi! I use D3D9 and C#. Now I want to rotate a rectangle around the x-axis with the RotationX()-method. My quesstion: Is it possible to show the original rectangle and the rotated rectangle? Thanks, enne

##### Share on other sites
What sort of rectangle? Do you just have the 4 points in code? Are you rendering a couple of triangles to make it up? Is it a mesh?

Assuming you're rendering it as two triangles, then yes it's possible, You'll have to render it twice though. Once before applying the rotation and once after. In C++ (I don't know about C#), you'd do something like:
// Draw unrotated rectanglepDevice->DrawPrimitive(...);// Set rotation transformD3DXMATRIX matRot;D3DXMatrixRotationX(&matRot, ...);pDevice->setTransform(D3DTS_WORLD, &matRot);// Draw rectangle again (It'll be transformed this time)pDevice->DrawPrimitive(...);

##### Share on other sites

I tried that, but somehow D3D only draws one rectangle and not two.

Here's my code:

 public  void Render()        {            if (m_oDevice == null)                return;            //Hintergrund blau einfärben            m_oDevice.Clear(ClearFlags.Target, Color.Blue, 1.0f, 0);                        //Szene beginnen            m_oDevice.BeginScene();                        RenderDevice.VertexFormat = CustomVertex.PositionColored.Format;            RenderDevice.SetStreamSource(0, oVertexBuffer, 0);            RenderDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);            curMatrix = Matrix.RotationY(Geometry.DegreeToRadian(10));            m_oDevice.SetTransform(TransformType.World, curMatrix);            RenderDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);            //Szene beenden            m_oDevice.EndScene();            //Szene auf den Monitor ausgeben            m_oDevice.Present();        }

The Render()-Methode is called in the OnPaint() - method of my window.

##### Share on other sites
Ah, got it, thanks much :)

One last question: If I draw another rectangle, will it be rotated too and if yes, is it possible to decide which rectangle should be rotated and which not?

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628367
• Total Posts
2982280

• 10
• 9
• 13
• 24
• 11