Permalink
Browse files

Fixed bugs in nested display matrix calculations for sprites and box2…

…d sprites.
  • Loading branch information...
1 parent 3b4b75b commit 01a1ad833e24ca776327077aeed1ec417c82e4eb unknown committed May 10, 2010
View
Binary file not shown.
@@ -578,8 +578,9 @@ public virtual bool OnPlayerInput(int playerIndex, Move move, TimeSpan time)
return true;
}
protected int transformIndex = 0;
- Vector2 curPos;
- float curRot;
+ Vector2 absPosition;
+ float curRot;
+ //protected Matrix m = Matrix.Identity;
protected virtual void SetCurrentState()
{
for (int i = 0; i < transforms.Length; i++)
@@ -590,8 +591,65 @@ protected virtual void SetCurrentState()
break;
}
}
- V2DTransform t = transforms[transformIndex];
+ V2DTransform t = transforms[transformIndex];
+
+ //m = parent.m;
+
+ //Matrix sm = Matrix.CreateScale(State.Scale.X * t.Scale.X, State.Scale.Y * t.Scale.Y, 0f);
+ //Matrix rm = Matrix.CreateRotationZ(State.Rotation + t.Rotation);
+ //Matrix tm = Matrix.CreateTranslation(State.Position.X + t.Position.X, State.Position.Y + t.Position.Y, 0f);
+ //Matrix om = Matrix.CreateTranslation(Origin.X, Origin.Y, 0f);
+
+ //Matrix.Multiply(ref sm, ref m, out m); // scale
+ //Matrix.Subtract(ref om, ref m, out m);
+ //Matrix.Multiply(ref rm, ref m, out m); // rotate
+ //Matrix.Add(ref om, ref m, out m);
+ //Matrix.Add(ref tm, ref m, out m); // translate
+
+ //Vector3 s;
+ //Quaternion r;
+ //Vector3 tr;
+ //m.Decompose(out s, out r, out tr);
+ Vector2 relativePosition = State.Position + t.Position;
+ relativePosition *= parent.CurrentState.Scale;
+
+ CurrentState.Scale = parent.CurrentState.Scale * State.Scale * t.Scale;
+ CurrentState.Rotation = parent.CurrentState.Rotation + State.Rotation + t.Rotation;
+ float tempX = relativePosition.X;
+ float cosRot = (float)Math.Cos(parent.CurrentState.Rotation);
+ float sinRot = (float)Math.Sin(parent.CurrentState.Rotation);
+ relativePosition.X = cosRot * tempX - sinRot * relativePosition.Y;
+ relativePosition.Y = sinRot * tempX + cosRot * relativePosition.Y;
+
+ CurrentState.Position = parent.CurrentState.Position + relativePosition;
+
+
+ //absPosition = parent.CurrentState.Position + State.Position + t.Position;
+ //CurrentState.Position.X = (absPosition.X - State.Origin.X) * (1f/CurrentState.Scale.X);
+ //CurrentState.Position.Y = absPosition.Y - State.Origin.Y * (1f/CurrentState.Scale.Y);
+
+ //CurrentState.Scale = parent.CurrentState.Scale * State.Scale * t.Scale;
+ //absPosition = parent.CurrentState.Position + State.Position + t.Position;
+ //CurrentState.Position.X = (absPosition.X - State.Origin.X) * (1f/CurrentState.Scale.X);
+ //CurrentState.Position.Y = absPosition.Y - State.Origin.Y * (1f/CurrentState.Scale.Y);
+
+ //curRot = State.Rotation + t.Rotation;
+ //CurrentState.Rotation = parent.CurrentState.Rotation + State.Rotation + t.Rotation;
+
+ //absPosition = (Origin) * (1f / CurrentState.Scale.X);
+ //CurrentState.Position.X += (float)(Math.Cos(curRot) * absPosition.X - Math.Sin(curRot) * absPosition.Y);
+ //CurrentState.Position.Y += (float)(Math.Sin(curRot) * absPosition.X + Math.Cos(curRot) * absPosition.Y);
+
+ //curRot = State.Rotation + t.Rotation;
+ //float parRot = parent.CurrentState.Rotation;
+ //CurrentState.Rotation = parent.CurrentState.Rotation + curRot;
+
+ //CurrentState.Position.X = parent.CurrentState.Position.X + (float)(Math.Cos(curRot) * curPos.X - Math.Sin(curRot) * curPos.Y);
+ //CurrentState.Position.Y = parent.CurrentState.Position.Y + (float)(Math.Sin(curRot) * curPos.X + Math.Cos(curRot) * curPos.Y);
+
+
+ /*
CurrentState.Scale = parent.CurrentState.Scale * State.Scale * t.Scale;
//CurrentState.Rotation = parent.CurrentState.Rotation + State.Rotation + t.Rotation;
//CurrentState.Position = parent.CurrentState.Position + State.Position + t.Position;
@@ -612,6 +670,7 @@ protected virtual void SetCurrentState()
// CurrentState.Position.X = parent.CurrentState.Position.X + (float)(Math.Cos(curRot) * curPos.X - Math.Sin(curRot) * curPos.Y);
// CurrentState.Position.Y = parent.CurrentState.Position.Y + (float)(Math.Sin(curRot) * curPos.X + Math.Cos(curRot) * curPos.Y);
}
+ */
}
protected Rectangle destRect;
@@ -650,7 +709,8 @@ public virtual void Draw(SpriteBatch batch)
if (texture != null)
{
//batch.Draw(texture, destRect, sourceRectangle, color, CurrentState.Rotation, CurrentState.Origin, se, 1f / DepthCounter++);
- batch.Draw(texture, destRect, sourceRectangle, color, CurrentState.Rotation, CurrentState.Origin, se, 1f / DepthCounter++);
+ //batch.Draw(texture, destRect, sourceRectangle, color, CurrentState.Rotation, Origin, se, 1f / DepthCounter++);
+ batch.Draw(texture, destRect, sourceRectangle, color, CurrentState.Rotation, Origin, se, 1f / DepthCounter++);
}
@@ -420,8 +420,8 @@ public void UpdateTransform()
}
}
protected override void SetCurrentState()
- {
- if (body == null)
+ {
+ if (body == null)
{
base.SetCurrentState();
}
@@ -442,19 +442,25 @@ protected override void SetCurrentState()
UpdateTransform();
}
- Vector2 bPosition = new Vector2((int)(body.GetPosition().X * V2DScreen.WorldScale), (int)(body.GetPosition().Y * V2DScreen.WorldScale));
+ Vector2 bPosition = body.GetPosition() * V2DScreen.WorldScale;//new Vector2((int)(body.GetPosition().X * V2DScreen.WorldScale), (int)(body.GetPosition().Y * V2DScreen.WorldScale));
float br = body.GetAngle();
-
- CurrentState.Position = bPosition;// -parent.CurrentState.Position;// +t.Position;
- CurrentState.Scale = parent.CurrentState.Scale * State.Scale * t.Scale;
- CurrentState.Rotation = br;// -parent.CurrentState.Rotation + t.Rotation;
- CurrentState.Origin = State.Origin;
-
- //State.Position = CurrentState.Position - parent.CurrentState.Position - t.Position;
- State.Position = CurrentState.Position - parent.CurrentState.Position;
- //State.Scale = CurrentState.Scale;
- State.Rotation = CurrentState.Rotation - parent.CurrentState.Rotation;
- State.Origin = CurrentState.Origin;
+ Vector2 com = body.GetLocalCenter() * V2DScreen.WorldScale;
+ //Vector2 comOrg = Origin - com;
+
+ //float angle = (float)Math.Atan2(com.Y, com.X) + br;
+ //float length = (float)com.Length();
+
+ CurrentState.Scale = Vector2.One;// parent.CurrentState.Scale * State.Scale * t.Scale;
+ CurrentState.Rotation = br;// -parent.CurrentState.Rotation + t.Rotation;
+ CurrentState.Position = bPosition;// -new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * length;// -parent.CurrentState.Position;// +t.Position;
+ //Origin = new Vector2(0, -20);// origin;
+ //children[0].Origin = -Origin;
+ //((DisplayObjectContainer)children[0]).children[0].Origin = new Vector2(83, 47);// +Origin;
+ //CurrentState.Origin = Origin;
+
+ //State.Position = CurrentState.Position - parent.CurrentState.Position;
+ //State.Rotation = CurrentState.Rotation - parent.CurrentState.Rotation;
+ //State.Origin = CurrentState.Origin;
}
}
}
View
Binary file not shown.
View
@@ -12,7 +12,7 @@
namespace V2DTests
{
- [V2DScreenAttribute(backgroundColor = 0xFFFF88, gravityX = 10, debugDraw = true)]
+ [V2DScreenAttribute(backgroundColor = 0x000001, gravityX = 10, debugDraw = true)]
public class Demo : V2DScreen
{
private Sprite bkg;
@@ -21,7 +21,7 @@ public class Demo : V2DScreen
[V2DSpriteAttribute(isBullet=true)]
private V2DSprite hex;
private List<V2DSprite> flo;
- private List<V2DSprite> boy;
+ private List<Sprite> tank;
private TextBox txTest;
[GearJointAttribute(ratio = 2)]
@@ -41,12 +41,7 @@ public override void Initialize()
{
base.Initialize();
//bkg.Visible = false;
- //boy.Play();
- foreach (V2DSprite b in boy)
- {
- b.Play();
- b.PlayheadWrap += new AnimationEvent(b_PlayheadWrap);
- }
+ //boy.Play();
}
void b_PlayheadWrap(DisplayObjectContainer sender)
View
Binary file not shown.

0 comments on commit 01a1ad8

Please sign in to comment.