Is Microsoft.DirectX.Direct3D.Sprite.Draw2D buggy?

Started by
4 comments, last by Skibum 14 years, 9 months ago
I'm using C# in a windows app and DirectX 9 on a vista machine. What I'm trying to do is to rotate an image in place so I can avoid having to make a ton of images all facing different directions. The png file "Ship.png" is a simple image, a 32x32 ship facing straight up. I have an Init and a Render which I think is all that needs shown here for this example. In my class:

	private Texture t = null;
	Sprite s = null;
	float rotationAngle = 0;

public void Init(Device d)
{
	// Load the Texture into variable "t", seems to work fine
	// My transparent color is 0x00FF00FF shown by the last argument
	t = TextureLoader.FromFile(d, "Ship.png", 32, 32, 0, Usage.Dynamic,
		Format.Unknown, Pool.Default, Filter.None, Filter.None,
		Color.FromArgb(255, 0, 255, 0).ToArgb());
	// init the sprite with the device
	s = new Sprite(d);
}


This will display the ship at 0,0, unmoving, good

	Texture t = null;
	Sprite s = null;
	float rotationAngle = 0;
	Point position = new Point(0, 0);
	Point rotationCenter = new Point(0, 0);

public void Render(Device d)
{
	s.Begin(SpriteFlags.AlphaBlend);
	s.Draw2D(t, rotationCenter, rotationAngle, position, Color.White.ToArgb());
	s.End();
}


So from the above Render I change to the following and end up with a rotating ship revolving around the top left corner counter-clockwise in and out of my window.

	Texture t = null;
	Sprite s = null;
	float rotationAngle = 0;
	Point position = new Point(0,0);
	Point rotationCenter = new Point(0, 0);
public void Render(Device d)
{
	s.Begin(SpriteFlags.AlphaBlend);
	rotationAngle -= 0.05f;
	s.Draw2D(t, rotationCenter, rotationAngle, position, Color.White.ToArgb());
	s.End();
}


So I change the rotationCenter line and nothing else and I end up with a ship that is rotating on the top left point of my window in the center of the ship, just like what I want but not where, it's 3/4 off the screen because the ship center is my top left window pixel.

	Texture t = null;
	Sprite s = null;
	float rotationAngle = 0;
	Point position = new Point(0,0);
	Point rotationCenter = new Point(16, 16);
public void Render(Device d)
{
	s.Begin(SpriteFlags.AlphaBlend);
	rotationAngle -= 0.05f;
	s.Draw2D(t, rotationCenter, rotationAngle, position, Color.White.ToArgb());
	s.End();
}


So then I change the position to Point(16, 16) thinking it will move the ship and keep it rotating like it should. It moves the ship to 16,16 but it still rotates around the 0,0 of the window so it's on and off the screen. That seems so messed up. If, instead of my Draw2D function I use Draw instead like below then it will work like I want it to but I have next to no idea why this will work and not the Draw2D.

	s.Transform = Matrix.Transformation2D(new Vector2(0, 0), 0, new Vector2(1, 1),
		new Vector2(16, 16), rotationAngle, new Vector2(0, 0));
	s.Draw(t, new Rectangle(0, 0, 32, 32), new Vector3(0, 0, 0),
		new Vector3(0, 0, 0), Color.White);


If I want to change the location of the image in my window then I would change the change below. I used (X-COORD, Y-COORD) to designate the locations in the source.

	s.Transform = Matrix.Transformation2D(new Vector2(0, 0), 0, new Vector2(1, 1),
		new Vector2(16, 16), rotationAngle, new Vector2(X-COORD, Y-COORD));
	s.Draw(t, new Rectangle(0, 0, 32, 32), new Vector3(0, 0, 0),
		new Vector3(0, 0, 0), Color.White);


The Transform on the sprite does not seem to change the working of s.Draw2D(). It's almost like whatever I do the Sprite.Draw2D function ignores my rotationCenter and uses Point(0,0) instead. I'm at a loss to figure this out. I've tried many more iterations than show above and haven't come up with a conclusion as to how to fix it (obviously, or I wouldn't be posting). Edit - change a comment
Advertisement
Use XNA instead of MDX. MDX is old and has a few serious bugs in it.
Alternatively there is SlimDX which is much closer to being a managed DirectX wrapper if that's what you prefer. The XNA framework, on the other hand, is much more a game framework than just a wrapper. So depending on what you prefer/need, one may be more useful than the other.

I would just suggest moving away from MDX. It hasn't been supported in years and is no longer actively supported. It very well may be buggy, but it will never be fixed. If you want a managed solution, SlimDX and XNA framework are your best two options for managed DirectX graphics.
The latest DirectX SDK is March 2009, that's only 4 months old and it's old? I haven't seen anything indicating that DirectX is a dying technology.
DirectX is not dying. Managed DirectX is already dead, having been deprecated a long time ago.
Ah I was mistaken and thought that "MDX" meant Microsoft DirectX, that clears things up a bit.

[Edited by - Skibum on July 16, 2009 9:30:27 PM]

This topic is closed to new replies.

Advertisement