Sign in to follow this  
enne87

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
pDevice->DrawPrimitive(...);

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

// Draw rectangle again (It'll be transformed this time)
pDevice->DrawPrimitive(...);

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)
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 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