Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Offline CARUFO  
#1 Posted : Monday, November 7, 2011 6:34:30 PM(UTC)
CARUFO

Joined: 8/21/2011(UTC)
Posts: 37

Was thanked: 1 time(s) in 1 post(s)
I want rotate a Material2D:
Code:

    position.Rotate(90f,new Point[4]);//i don't need the 4 points
    //and draw:
    texture.Draw(position);

But it don't work.
Whats wrong?

Edited by user Monday, November 7, 2011 6:36:45 PM(UTC)  | Reason: Not specified

Wanna join the discussion?! Login to your forum accountregister a new account. Or Connect via Facebook Twitter Google

Offline Benjamin  
#2 Posted : Monday, November 7, 2011 7:23:16 PM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
Originally Posted by: CARUFO Go to Quoted Post
I want rotate a Material2D:
Code:

    position.Rotate(90f,new Point[4]);//i don't need the 4 points
    //and draw:
    texture.Draw(position);

But it don't work.
Whats wrong?


Not sure what you are doing there. A position is just a 2D Point, if you rotate it, it still is at the same position.

If you position is a rectangle you are choosing a strange name ^^ but in any case Material2D won't do any rotations as it is not supported!

Just use Material2DColored, which has a Draw call that supports rotation and everything will work fine :)

See MaterialTests.DrawDefaultMaterialAutoRotated for an example:
Code:

float rotation = 0.0f;
Application.Start(delegate
{
	rotation += Time.Delta * 10.0f;
	Material2DColored.Default.Draw(new Rectangle(0.2f, 0.2f, 0.6f, 0.6f), rotation);
});
Offline CARUFO  
#3 Posted : Monday, November 7, 2011 8:30:24 PM(UTC)
CARUFO

Joined: 8/21/2011(UTC)
Posts: 37

Was thanked: 1 time(s) in 1 post(s)
Originally Posted by: Benjamin Nitschke (DeltaEngine) Go to Quoted Post

Just use Material2DColored, which has a Draw call that supports rotation and everything will work fine :)

Thanks.
Offline mc-kay  
#4 Posted : Sunday, November 20, 2011 11:55:27 PM(UTC)
mc-kay

Medals: Admin

Joined: 8/24/2011(UTC)
Posts: 138
Location: Hannover

Thanks: 1 times
Was thanked: 12 time(s) in 7 post(s)
Can I rotate around a specific point, e.g if I don't wont to rotate around the center of a Material2D?
Offline Benjamin  
#5 Posted : Monday, November 21, 2011 12:51:06 AM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
Originally Posted by: Hendrik Go to Quoted Post
Can I rotate around a specific point, e.g if I don't wont to rotate around the center of a Material2D?


Yes you can, but doing so is not as easy because it is a few layers down the rendering pipeline. Basically instead of
Code:

					// Apply the rotation normally (centered around itself)
					drawArea.Rotate(rotation, rotatedPoints);


this has to be done:
Code:

					// Apply the rotation around a custom point
					drawArea.Rotate(rotation, rotatedPoints, center);


drawArea is the Rectangle to be drawn. You could do all this calculations yourself, use the AddBillboard functionality (which also can do rotated points with any offset) or do it with a custom Geometry, but it is way easier to pass all the data along with the new Draw overload I just added. Just grab the latest nightly release for the updated code and the unit test in MaterialTests.cs:
Code:

		#region DrawMaterialRotatedAroundPoint
		/// <summary>
		/// Draw default material rotated around a custom point. As requested in
		/// http://forum.deltaengine.net/yaf_postsm1094_Rotate-a-Material2D.aspx
		/// </summary>
		[Test]
		public static void DrawMaterialRotatedAroundPoint()
		{
			float rotation = 0.0f;

			Application.Start(delegate
			{
				rotation += Time.Delta * 100.0f;

				Material2D.Default.Draw(new Rectangle(0.3f, 0.3f, 0.4f, 0.4f),
					rotation, new Point(0.3f, 0.3f));
			});
		}
		#endregion


Hope that helps and the nightly release will be up as soon as I figured out the scene Material2DColored offset issue ..
Offline mc-kay  
#6 Posted : Monday, November 21, 2011 11:04:29 PM(UTC)
mc-kay

Medals: Admin

Joined: 8/24/2011(UTC)
Posts: 138
Location: Hannover

Thanks: 1 times
Was thanked: 12 time(s) in 7 post(s)
@CARUFO
Rotate() does not effect your Rectangle direct, it stores the new points of the rotated Rectangle in the "Point[] rotPoints" return value.

@Benjamin
I found this a bit confusing too, why are the "rotPoints" not directly returner respectively why not use the "out" keyword?

Edited by user Monday, November 21, 2011 11:04:59 PM(UTC)  | Reason: Not specified

Offline Benjamin  
#7 Posted : Tuesday, November 22, 2011 2:23:23 AM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
Originally Posted by: Hendrik Go to Quoted Post

I found this a bit confusing too, why are the "rotPoints" not directly returner respectively why not use the "out" keyword?


Yes that is confusing, but I cannot change it that easily to return or even out parameters because of performance. Creating an array of 4 points (8 floats) costs a lot of performance on mobile platforms. If you do it hundred or thousands of times per frame you don't want all these newly created point arrays hanging around. Instead each caller uses his own point array (only initialized once).

Hope that makes sense ^^ it says so in the description of Rectangle.Rotate, but I have clarified the message a bit!
Rss Feed  Atom Feed
Users browsing this topic
OceanSpiders 2.0
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2022, Yet Another Forum.NET
This page was generated in 0.066 seconds.