Public Group

# Transformation problem

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

## Recommended Posts

Hello, I'm currently programming MDX with C#, I'm doin a 2D game to learn the language better. In the sprites I have my character face east, I Want him to face west if I'm going west. If I spin him 180 degrees he will be up-side-down, any1 know if it's possible to 'shift' him with transformation matrices?.

##### Share on other sites
You presumably want a reflection in the vertical (north-south) axis.

##### Share on other sites
Quote:
 Original post by ZahlmanYou presumably want a reflection in the vertical (north-south) axis.

Well.. I dont know what that's, can u post it with code?. Doesnt matter which language.

##### Share on other sites
Try scaling him -1 in the X direction, and 1 in the Y and Z directions. In OpenGL it would be done with

glScalef(-1.0f, 1.0f, 1.0f);

I think this will work, but I am not sure.

##### Share on other sites
Quote:
 Original post by FriskerWell.. I dont know what that's, can u post it with code?. Doesnt matter which language.
A reflection about the y axis would look like this in matrix form:
[-1 0][ 0 1]

##### Share on other sites
I try to use

<CODE>
D3DSprite = Matrix.Scaling(-1.0F, 1.0F, 1.0F);
</CODE>

But everything just dissapears :/

##### Share on other sites
Quote:
 Original post by FriskerI try to use D3DSprite = Matrix.Scaling(-1.0F, 1.0F, 1.0F);But everything just dissapears :/
You're probably applying the transformations in the wrong order. For example, if the reflection is being applied after the translation, the sprite could be getting 'reflected' right off the screen.

If you're still having problems with this, post the code where you set up the transform for rendering the sprite.

##### Share on other sites
Quote:
Original post by jyk
Quote:
 Original post by FriskerI try to use D3DSprite = Matrix.Scaling(-1.0F, 1.0F, 1.0F);But everything just dissapears :/
You're probably applying the transformations in the wrong order. For example, if the reflection is being applied after the translation, the sprite could be getting 'reflected' right off the screen.

If you're still having problems with this, post the code where you set up the transform for rendering the sprite.

public void FillPos(int x, int y)
{
Pos.X = x;
Pos.Y = y;
}

public void Draw(Sprite D3DSprite)
{
Rectangle rect = (Rectangle)Desc[aFrame];

Center.X = rect.Width / 2;
Center.Y = rect.Height / 2;

D3DSprite.Transform = Matrix.Scaling(-1.0F, 1.0F, 1.0F);

D3DSprite.Draw(tex, (Rectangle)Desc[aFrame], Center, Pos, Color.FromArgb(255,255,255,255));
}

I dont move my sprites with translation, D3D does move it with D3DSprite.Draw. Pos is the Position... I'm really clueless atm

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632998
• Total Posts
3009808
• ### Who's Online (See full list)

There are no registered users currently online

×