"D3DXMatrixTransformation2D": Rotation Not In Degrees?

Started by
3 comments, last by L. Spiro 10 years, 5 months ago

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

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

JeZxLee
Fallen Angel Software
www.FallenAngelSoftware.com

Advertisement

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
} 

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.

Hi,

Thanks, I got it working...

JeZ+Lee

JeZxLee
Fallen Angel Software
www.FallenAngelSoftware.com

#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

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

This topic is closed to new replies.

Advertisement