Jump to content
  • Advertisement
Sign in to follow this  
enne87

Rotation of a rectangle

This topic is 3883 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!