Rewrite ThrowsParticle using world coordinates.
The old dynamics were crazy, so this implements a simpler model using a cubic lerp.
This commit is contained in:
@@ -26,8 +26,11 @@ namespace OpenRA
|
|||||||
public static readonly WVec Zero = new WVec(0, 0, 0);
|
public static readonly WVec Zero = new WVec(0, 0, 0);
|
||||||
|
|
||||||
public static WVec operator +(WVec a, WVec b) { return new WVec(a.X + b.X, a.Y + b.Y, a.Z + b.Z); }
|
public static WVec operator +(WVec a, WVec b) { return new WVec(a.X + b.X, a.Y + b.Y, a.Z + b.Z); }
|
||||||
public static WVec operator -(WVec a, WVec b) { return new WVec(a.X - b.X, a.Y - b.Y, a.Y - b.Y); }
|
public static WVec operator -(WVec a, WVec b) { return new WVec(a.X - b.X, a.Y - b.Y, a.Z - b.Z); }
|
||||||
public static WVec operator -(WVec a) { return new WVec(-a.X, -a.Y, -a.Z); }
|
public static WVec operator -(WVec a) { return new WVec(-a.X, -a.Y, -a.Z); }
|
||||||
|
public static WVec operator /(WVec a, int b) { return new WVec(a.X / b, a.Y / b, a.Z / b); }
|
||||||
|
public static WVec operator *(int a, WVec b) { return new WVec(a * b.X, a * b.Y, a * b.Z); }
|
||||||
|
public static WVec operator *(WVec a, int b) { return b*a; }
|
||||||
|
|
||||||
public static bool operator ==(WVec me, WVec other) { return (me.X == other.X && me.Y == other.Y && me.Z == other.Z); }
|
public static bool operator ==(WVec me, WVec other) { return (me.X == other.X && me.Y == other.Y && me.Z == other.Z); }
|
||||||
public static bool operator !=(WVec me, WVec other) { return !(me == other); }
|
public static bool operator !=(WVec me, WVec other) { return !(me == other); }
|
||||||
@@ -48,6 +51,8 @@ namespace OpenRA
|
|||||||
(int)((lx * mtx[2] + ly*mtx[6] + lz*mtx[10]) / mtx[15]));
|
(int)((lx * mtx[2] + ly*mtx[6] + lz*mtx[10]) / mtx[15]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static WVec Lerp(WVec a, WVec b, int mul, int div) { return a + (b - a) * mul / div; }
|
||||||
|
|
||||||
public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode(); }
|
public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode(); }
|
||||||
|
|
||||||
public override bool Equals(object obj)
|
public override bool Equals(object obj)
|
||||||
|
|||||||
@@ -8,19 +8,30 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using OpenRA.FileFormats;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Mods.RA.Render;
|
using OpenRA.Mods.RA.Render;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA
|
namespace OpenRA.Mods.RA
|
||||||
{
|
{
|
||||||
class ThrowsParticleInfo : ITraitInfo, Requires<RenderUnitInfo>
|
class ThrowsParticleInfo : ITraitInfo, Requires<RenderSimpleInfo>
|
||||||
{
|
{
|
||||||
public readonly string Anim = null;
|
public readonly string Anim = null;
|
||||||
public readonly int[] Offset = new[] { 0, 0, 0, 0 };
|
|
||||||
public readonly int[] Spread = new[] { 0, 0 };
|
[Desc("Initial position relative to body")]
|
||||||
public readonly float Speed = 20;
|
public readonly WVec Offset = WVec.Zero;
|
||||||
public readonly string AnimKey = null;
|
|
||||||
|
[Desc("Maximum distance to throw the particle")]
|
||||||
|
public readonly WRange ThrowRange = new WRange(768);
|
||||||
|
|
||||||
|
[Desc("Maximum height to throw the particle")]
|
||||||
|
public readonly WRange ThrowHeight = new WRange(256);
|
||||||
|
|
||||||
|
[Desc("Number of ticks to animate")]
|
||||||
|
public readonly int Length = 15;
|
||||||
|
|
||||||
|
[Desc("Maximum rotation rate")]
|
||||||
public readonly float ROT = 15;
|
public readonly float ROT = 15;
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new ThrowsParticle(init, this); }
|
public object Create(ActorInitializer init) { return new ThrowsParticle(init, this); }
|
||||||
@@ -28,51 +39,56 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
class ThrowsParticle : ITick
|
class ThrowsParticle : ITick
|
||||||
{
|
{
|
||||||
float2 pos;
|
ThrowsParticleInfo info;
|
||||||
float alt;
|
WVec pos;
|
||||||
|
WVec initialPos;
|
||||||
|
WVec finalPos;
|
||||||
|
int tick = 0;
|
||||||
|
|
||||||
float2 v;
|
|
||||||
float va;
|
|
||||||
float facing;
|
float facing;
|
||||||
float dfacing;
|
float rotation;
|
||||||
|
|
||||||
const float gravity = 1.3f;
|
|
||||||
|
|
||||||
public ThrowsParticle(ActorInitializer init, ThrowsParticleInfo info)
|
public ThrowsParticle(ActorInitializer init, ThrowsParticleInfo info)
|
||||||
{
|
{
|
||||||
|
this.info = info;
|
||||||
|
|
||||||
var self = init.self;
|
var self = init.self;
|
||||||
var ifacing = self.Trait<IFacing>();
|
var rs = self.Trait<RenderSimple>();
|
||||||
var ru = self.Trait<RenderUnit>();
|
|
||||||
|
|
||||||
alt = 0;
|
// TODO: Carry orientation over from the parent instead of just facing
|
||||||
facing = Turreted.GetInitialTurretFacing( init, 0 );
|
var bodyFacing = init.Contains<FacingInit>() ? init.Get<FacingInit,int>() : 0;
|
||||||
pos = new Turret(info.Offset).PxPosition(self, ifacing).ToFloat2();
|
facing = Turreted.GetInitialTurretFacing(init, 0);
|
||||||
|
|
||||||
v = Game.CosmeticRandom.Gauss2D(1) * info.Spread.RelOffset();
|
// Calculate final position
|
||||||
dfacing = Game.CosmeticRandom.Gauss1D(2) * info.ROT;
|
var throwRotation = WRot.FromFacing(Game.CosmeticRandom.Next(1024));
|
||||||
va = info.Speed;
|
var throwOffset = new WVec((int)(Game.CosmeticRandom.Gauss1D(1)*info.ThrowRange.Range), 0, 0).Rotate(throwRotation);
|
||||||
|
|
||||||
var anim = new Animation(ru.GetImage(self), () => (int)facing);
|
initialPos = pos = info.Offset.Rotate(rs.QuantizeOrientation(self, WRot.FromFacing(bodyFacing)));
|
||||||
|
finalPos = initialPos + throwOffset;
|
||||||
|
|
||||||
|
// Facing rotation
|
||||||
|
rotation = Game.CosmeticRandom.Gauss1D(2) * info.ROT;
|
||||||
|
|
||||||
|
var anim = new Animation(rs.GetImage(self), () => (int)facing);
|
||||||
anim.PlayRepeating(info.Anim);
|
anim.PlayRepeating(info.Anim);
|
||||||
|
rs.anims.Add(info.Anim, new AnimationWithOffset(anim, wr => wr.ScreenPxOffset(pos), null));
|
||||||
ru.anims.Add(info.AnimKey, new AnimationWithOffset(
|
|
||||||
anim, wr => pos - new float2(0, alt), null));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick(Actor self)
|
public void Tick(Actor self)
|
||||||
{
|
{
|
||||||
va -= gravity;
|
if (tick == info.Length)
|
||||||
alt += va;
|
return;
|
||||||
|
tick++;
|
||||||
|
|
||||||
if (alt < 0) alt = 0;
|
// Lerp position horizontally and height along a sinusoid using a cubic ease
|
||||||
else
|
var t = (tick*tick*tick / (info.Length*info.Length) - 3*tick*tick / info.Length + 3*tick);
|
||||||
{
|
var tp = WVec.Lerp(initialPos, finalPos, t, info.Length);
|
||||||
pos += v;
|
var th = new WAngle(512*(info.Length - t) / info.Length).Sin()*info.ThrowHeight.Range / 1024;
|
||||||
v = .9f * v;
|
pos = new WVec(tp.X, tp.Y, th);
|
||||||
|
|
||||||
facing += dfacing;
|
// Spin the particle
|
||||||
dfacing *= .9f;
|
facing += rotation;
|
||||||
}
|
rotation *= .9f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,9 +73,6 @@ LTNK.Husk:
|
|||||||
Image: ltnk
|
Image: ltnk
|
||||||
ThrowsParticle@turret:
|
ThrowsParticle@turret:
|
||||||
Anim: turret
|
Anim: turret
|
||||||
Spread: 3,3
|
|
||||||
Speed: 6
|
|
||||||
AnimKey: turret
|
|
||||||
|
|
||||||
MTNK.Husk:
|
MTNK.Husk:
|
||||||
Inherits: ^Husk
|
Inherits: ^Husk
|
||||||
@@ -86,9 +83,6 @@ MTNK.Husk:
|
|||||||
Image: mtnk
|
Image: mtnk
|
||||||
ThrowsParticle@turret:
|
ThrowsParticle@turret:
|
||||||
Anim: turret
|
Anim: turret
|
||||||
Spread: 3,3
|
|
||||||
Speed: 6
|
|
||||||
AnimKey: turret
|
|
||||||
|
|
||||||
HTNK.Husk:
|
HTNK.Husk:
|
||||||
Inherits: ^Husk
|
Inherits: ^Husk
|
||||||
@@ -99,9 +93,6 @@ HTNK.Husk:
|
|||||||
Image: htnk
|
Image: htnk
|
||||||
ThrowsParticle@turret:
|
ThrowsParticle@turret:
|
||||||
Anim: turret
|
Anim: turret
|
||||||
Spread: 3,3
|
|
||||||
Speed: 6
|
|
||||||
AnimKey: turret
|
|
||||||
|
|
||||||
MSAM.Husk:
|
MSAM.Husk:
|
||||||
Inherits: ^Husk
|
Inherits: ^Husk
|
||||||
@@ -112,9 +103,6 @@ MSAM.Husk:
|
|||||||
Image: msam
|
Image: msam
|
||||||
ThrowsParticle@turret:
|
ThrowsParticle@turret:
|
||||||
Anim: turret
|
Anim: turret
|
||||||
Spread: 3,3
|
|
||||||
Speed: 6
|
|
||||||
AnimKey: turret
|
|
||||||
|
|
||||||
MLRS.Husk:
|
MLRS.Husk:
|
||||||
Inherits: ^Husk
|
Inherits: ^Husk
|
||||||
@@ -125,9 +113,6 @@ MLRS.Husk:
|
|||||||
Image: mlrs
|
Image: mlrs
|
||||||
ThrowsParticle@turret:
|
ThrowsParticle@turret:
|
||||||
Anim: turret
|
Anim: turret
|
||||||
Spread: 3,3
|
|
||||||
Speed: 6
|
|
||||||
AnimKey: turret
|
|
||||||
|
|
||||||
STNK.Husk:
|
STNK.Husk:
|
||||||
Inherits: ^Husk
|
Inherits: ^Husk
|
||||||
|
|||||||
@@ -498,9 +498,6 @@ GUNTOWER.Husk:
|
|||||||
Image: GUNTOWER
|
Image: GUNTOWER
|
||||||
ThrowsParticle@turret:
|
ThrowsParticle@turret:
|
||||||
Anim: turret
|
Anim: turret
|
||||||
Spread: 4,4
|
|
||||||
Speed: 6
|
|
||||||
AnimKey: turret
|
|
||||||
|
|
||||||
ROCKETTOWER:
|
ROCKETTOWER:
|
||||||
Inherits: ^Building
|
Inherits: ^Building
|
||||||
@@ -559,9 +556,6 @@ ROCKETTOWER.Husk:
|
|||||||
Image: ROCKETTOWER
|
Image: ROCKETTOWER
|
||||||
ThrowsParticle@turret:
|
ThrowsParticle@turret:
|
||||||
Anim: turret
|
Anim: turret
|
||||||
Spread: 4,4
|
|
||||||
Speed: 6
|
|
||||||
AnimKey: turret
|
|
||||||
|
|
||||||
REPAIR:
|
REPAIR:
|
||||||
Inherits: ^Building
|
Inherits: ^Building
|
||||||
|
|||||||
@@ -242,9 +242,6 @@ QUAD.starport:
|
|||||||
HP: 100
|
HP: 100
|
||||||
ThrowsParticle@turret:
|
ThrowsParticle@turret:
|
||||||
Anim: turret
|
Anim: turret
|
||||||
Spread: 3,3
|
|
||||||
Speed: 6
|
|
||||||
AnimKey: turret
|
|
||||||
|
|
||||||
SIEGETANK:
|
SIEGETANK:
|
||||||
Inherits: ^Tank
|
Inherits: ^Tank
|
||||||
@@ -299,9 +296,6 @@ SIEGETANK.Husk:
|
|||||||
Icon: siegetankicon
|
Icon: siegetankicon
|
||||||
ThrowsParticle@turret:
|
ThrowsParticle@turret:
|
||||||
Anim: turret
|
Anim: turret
|
||||||
Spread: 3,3
|
|
||||||
Speed: 6
|
|
||||||
AnimKey: turret
|
|
||||||
RenderUnit:
|
RenderUnit:
|
||||||
Image: SIEGETANK
|
Image: SIEGETANK
|
||||||
|
|
||||||
|
|||||||
@@ -2602,9 +2602,6 @@ Rules:
|
|||||||
Image: 4TNK
|
Image: 4TNK
|
||||||
ThrowsParticle@turret:
|
ThrowsParticle@turret:
|
||||||
Anim: turret
|
Anim: turret
|
||||||
Spread: 3,3
|
|
||||||
Speed: 6
|
|
||||||
AnimKey: turret
|
|
||||||
Health:
|
Health:
|
||||||
HP: 2000
|
HP: 2000
|
||||||
SILO:
|
SILO:
|
||||||
|
|||||||
@@ -523,10 +523,7 @@ MGG.Husk:
|
|||||||
Image: mgg
|
Image: mgg
|
||||||
ThrowsParticle@spinner:
|
ThrowsParticle@spinner:
|
||||||
Anim: spinner-idle
|
Anim: spinner-idle
|
||||||
Spread: 3,3
|
Offset: -299,0,171
|
||||||
Speed: 6
|
|
||||||
AnimKey: spinner-idle
|
|
||||||
Offset: 0,6
|
|
||||||
|
|
||||||
MRJ:
|
MRJ:
|
||||||
Inherits: ^Vehicle
|
Inherits: ^Vehicle
|
||||||
@@ -564,9 +561,6 @@ MRJ:
|
|||||||
Image: 1tnk
|
Image: 1tnk
|
||||||
ThrowsParticle@turret:
|
ThrowsParticle@turret:
|
||||||
Anim: turret
|
Anim: turret
|
||||||
Spread: 3,3
|
|
||||||
Speed: 6
|
|
||||||
AnimKey: turret
|
|
||||||
|
|
||||||
2TNK.Husk:
|
2TNK.Husk:
|
||||||
Inherits: ^Husk
|
Inherits: ^Husk
|
||||||
@@ -576,9 +570,6 @@ MRJ:
|
|||||||
Image: 2tnk
|
Image: 2tnk
|
||||||
ThrowsParticle@turret:
|
ThrowsParticle@turret:
|
||||||
Anim: turret
|
Anim: turret
|
||||||
Spread: 3,3
|
|
||||||
Speed: 6
|
|
||||||
AnimKey: turret
|
|
||||||
|
|
||||||
3TNK.Husk:
|
3TNK.Husk:
|
||||||
Inherits: ^Husk
|
Inherits: ^Husk
|
||||||
@@ -588,9 +579,6 @@ MRJ:
|
|||||||
Image: 3tnk
|
Image: 3tnk
|
||||||
ThrowsParticle@turret:
|
ThrowsParticle@turret:
|
||||||
Anim: turret
|
Anim: turret
|
||||||
Spread: 3,3
|
|
||||||
Speed: 6
|
|
||||||
AnimKey: turret
|
|
||||||
|
|
||||||
4TNK.Husk:
|
4TNK.Husk:
|
||||||
Inherits: ^Husk
|
Inherits: ^Husk
|
||||||
@@ -600,9 +588,6 @@ MRJ:
|
|||||||
Image: 4tnk
|
Image: 4tnk
|
||||||
ThrowsParticle@turret:
|
ThrowsParticle@turret:
|
||||||
Anim: turret
|
Anim: turret
|
||||||
Spread: 3,3
|
|
||||||
Speed: 6
|
|
||||||
AnimKey: turret
|
|
||||||
|
|
||||||
HARV.FullHusk:
|
HARV.FullHusk:
|
||||||
Inherits: ^Husk
|
Inherits: ^Husk
|
||||||
|
|||||||
Reference in New Issue
Block a user