Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


"D3DXMatrixTransformation2D": Rotation Not In Degrees?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 JeZ-l-Lee   Members   -  Reputation: 131

Like
0Likes
Like

Posted 02 November 2013 - 03:00 PM

Hi,

 

I am designing a 2D game engine using DirectX 9.0c.

Currently I am working on graphics core.

 

My question now is the following:

"D3DXMatrixTransformation2D" rotation function perimeter does not seem to be in degrees?

How do I change it into degrees? (0'-360')

(see source code below)

 

Thanks!

 

JeZ+Lee

 

Here is the source:

//-------------------------------------------------------------------------------------------------------------------------------
void render( void )
{
    float x = 400; // Test value
    float y = 240; // Test value

    DXDevice->BeginScene();

    DXDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f), 1.0f, 0 );

    Sprite->Begin(D3DXSPRITE_ALPHABLEND);

    D3DSURFACE_DESC textureInfo;
    SpriteTexture->GetLevelDesc(0, &textureInfo);
    float spriteWidth = (float)textureInfo.Width;
    float spriteHeight = (float)textureInfo.Height;
    RECT spriteRect;
    spriteRect.top = 0;
    spriteRect.left = 0;
    spriteRect.bottom = textureInfo.Height;
    spriteRect.right = textureInfo.Width;

    D3DXVECTOR3 spritePosition;
    spritePosition.x = 0.0f - (spriteWidth/2);
    spritePosition.y = 0.0f - (spriteHeight/2);
    spritePosition.z = 0.0f;

    D3DXMATRIX matrixSpriteTransform;

//    D3DXVECTOR2 spriteCentre = D3DXVECTOR2(spriteWidth/2, spriteHeight/2);

    D3DXVECTOR2 screenPostion = D3DXVECTOR2(x, y);

    float rotation = 0.0f; //<--- How to change to degrees ???

    D3DXVECTOR2 scaling(1.0f, 1.0f);

    D3DXMatrixTransformation2D(&matrixSpriteTransform, NULL, 0.0, &scaling, /*&spriteCentre*/NULL, rotation, &screenPostion);
    Sprite->SetTransform(&matrixSpriteTransform);

    Sprite->Draw( SpriteTexture, &spriteRect, NULL, &spritePosition, D3DCOLOR_RGBA(255,255,255,255) );

    Sprite->End();

    DXDevice->EndScene();
    DXDevice->Present( NULL, NULL, NULL, NULL );
}

//-------------------------------------------------------------------------------------------------------------------------------



Sponsor:

#2 N.I.B.   Members   -  Reputation: 1262

Like
2Likes
Like

Posted 02 November 2013 - 03:11 PM

No, it's not in degrees. You don't change the functions, you need to convert your degress to radians

#define _USE_MATH_DEFINES // define before math.h
#include <math.h>

float ToRadians(float Degrees) 
{
       return Degrees * M_PI / 180.0f; // M_PI is from math.h
} 


#3 belfegor   Crossbones+   -  Reputation: 2776

Like
2Likes
Like

Posted 02 November 2013 - 03:18 PM

D3DXMatrixTransformation2D expects angle in radians, you could convert your "degree" variable to radians with D3DXToRadian
 

float rotationInDegrees = 90.0f;
float rotationInRadians = D3DXToRadian( rotationInDegrees );
D3DXMatrixTransformation2D(......., rotationInRadians, ...);

I would avoid evil math.h header and i heard that M_PI is rotten too.



#4 JeZ-l-Lee   Members   -  Reputation: 131

Like
0Likes
Like

Posted 02 November 2013 - 03:21 PM

Hi,

 

Thanks, I got it working...

 

JeZ+Lee



#5 L. Spiro   Crossbones+   -  Reputation: 17293

Like
1Likes
Like

Posted 02 November 2013 - 08:56 PM

#define _USE_MATH_DEFINES // define before math.h
#include <math.h>

float ToRadians(float Degrees) 
{
       return Degrees * M_PI / 180.0f; // M_PI is from math.h
} 

Just a head’s up, you should save yourself from a costly division by writing it as:
return (M_PI / 180.0f) * Degrees;


L. Spiro

Edited by L. Spiro, 03 November 2013 - 05:56 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS