Sign in to follow this  

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 this post

Link to post
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 rectangle

// Set rotation transform
D3DXMatrixRotationX(&matRot, ...);
pDevice->setTransform(D3DTS_WORLD, &matRot);

// Draw rectangle again (It'll be transformed this time)

Share this post

Link to post
Share on other sites
Thanks much for your help.

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

Here's my code:

public void Render()
if (m_oDevice == null)

//Hintergrund blau einfärben
m_oDevice.Clear(ClearFlags.Target, Color.Blue, 1.0f, 0);

//Szene beginnen

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

//Szene auf den Monitor ausgeben

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

Share this post

Link to post
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?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this