Delta Engine
»
Support
»
Rendering
»
Rotate a Material2D
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
|
|
|
|
Medals:  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  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);
});
|
|
|
|
Joined: 8/21/2011(UTC) Posts: 37
Was thanked: 1 time(s) in 1 post(s)
|
Originally Posted by: Benjamin Nitschke (DeltaEngine)  Just use Material2DColored, which has a Draw call that supports rotation and everything will work fine :)
Thanks.
|
|
|
|
Medals:  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? |
|
|
|
|
Medals:  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  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 ..
|
|
|
|
Medals:  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 |
|
|
|
|
Medals:  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  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!
|
|
|
|
Delta Engine
»
Support
»
Rendering
»
Rotate a Material2D
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.