Merge pull request #10520 from pchote/fix-voxel-z-offsets
Use height offset when rendering voxels.
This commit is contained in:
@@ -219,7 +219,7 @@ namespace OpenRA.Graphics
|
|||||||
public void ScreenVectorComponents(WVec vec, out float x, out float y, out float z)
|
public void ScreenVectorComponents(WVec vec, out float x, out float y, out float z)
|
||||||
{
|
{
|
||||||
x = TileSize.Width * vec.X / 1024f;
|
x = TileSize.Width * vec.X / 1024f;
|
||||||
y = TileSize.Height * vec.Y / 1024f;
|
y = TileSize.Height * (vec.Y - vec.Z) / 1024f;
|
||||||
z = TileSize.Height * vec.Z / 1024f;
|
z = TileSize.Height * vec.Z / 1024f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,7 +236,7 @@ namespace OpenRA.Graphics
|
|||||||
// Round to nearest pixel
|
// Round to nearest pixel
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
ScreenVectorComponents(vec, out x, out y, out z);
|
ScreenVectorComponents(vec, out x, out y, out z);
|
||||||
return new int2((int)Math.Round(x), (int)Math.Round(y - z));
|
return new int2((int)Math.Round(x), (int)Math.Round(y));
|
||||||
}
|
}
|
||||||
|
|
||||||
public float ScreenZPosition(WPos pos, int offset)
|
public float ScreenZPosition(WPos pos, int offset)
|
||||||
|
|||||||
@@ -44,20 +44,26 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
var turretFacing = Turreted.GetInitialTurretFacing(init, t.InitialFacing, t.Turret);
|
var turretFacing = Turreted.GetInitialTurretFacing(init, t.InitialFacing, t.Turret);
|
||||||
var turretOrientation = body.QuantizeOrientation(new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(turretFacing) - orientation.Yaw), facings);
|
var turretOrientation = body.QuantizeOrientation(new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(turretFacing) - orientation.Yaw), facings);
|
||||||
var turretOffset = body.LocalToWorld(t.Offset.Rotate(orientation));
|
|
||||||
|
|
||||||
yield return new VoxelAnimation(voxel, () => turretOffset, () => new[] { turretOrientation, orientation },
|
var quantizedTurret = body.QuantizeOrientation(turretOrientation, facings);
|
||||||
|
var quantizedBody = body.QuantizeOrientation(orientation, facings);
|
||||||
|
var barrelOffset = body.LocalToWorld((t.Offset + LocalOffset.Rotate(quantizedTurret)).Rotate(quantizedBody));
|
||||||
|
|
||||||
|
yield return new VoxelAnimation(voxel, () => barrelOffset, () => new[] { turretOrientation, orientation },
|
||||||
() => false, () => 0);
|
() => false, () => 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WithVoxelBarrel : UpgradableTrait<WithVoxelBarrelInfo>
|
public class WithVoxelBarrel : UpgradableTrait<WithVoxelBarrelInfo>, INotifyBuildComplete, INotifySold, INotifyTransform
|
||||||
{
|
{
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
readonly Armament armament;
|
readonly Armament armament;
|
||||||
readonly Turreted turreted;
|
readonly Turreted turreted;
|
||||||
readonly BodyOrientation body;
|
readonly BodyOrientation body;
|
||||||
|
|
||||||
|
// TODO: This should go away once https://github.com/OpenRA/OpenRA/issues/7035 is implemented
|
||||||
|
bool buildComplete;
|
||||||
|
|
||||||
public WithVoxelBarrel(Actor self, WithVoxelBarrelInfo info)
|
public WithVoxelBarrel(Actor self, WithVoxelBarrelInfo info)
|
||||||
: base(info)
|
: base(info)
|
||||||
{
|
{
|
||||||
@@ -68,21 +74,23 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
turreted = self.TraitsImplementing<Turreted>()
|
turreted = self.TraitsImplementing<Turreted>()
|
||||||
.First(tt => tt.Name == armament.Info.Turret);
|
.First(tt => tt.Name == armament.Info.Turret);
|
||||||
|
|
||||||
|
buildComplete = !self.Info.HasTraitInfo<BuildingInfo>(); // always render instantly for units
|
||||||
|
|
||||||
var rv = self.Trait<RenderVoxels>();
|
var rv = self.Trait<RenderVoxels>();
|
||||||
rv.Add(new VoxelAnimation(VoxelProvider.GetVoxel(rv.Image, Info.Sequence),
|
rv.Add(new VoxelAnimation(VoxelProvider.GetVoxel(rv.Image, Info.Sequence),
|
||||||
BarrelOffset, BarrelRotation,
|
BarrelOffset, BarrelRotation,
|
||||||
() => IsTraitDisabled, () => 0));
|
() => IsTraitDisabled || !buildComplete, () => 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
WVec BarrelOffset()
|
WVec BarrelOffset()
|
||||||
{
|
{
|
||||||
var localOffset = Info.LocalOffset + new WVec(-armament.Recoil, WDist.Zero, WDist.Zero);
|
var localOffset = Info.LocalOffset + new WVec(-armament.Recoil, WDist.Zero, WDist.Zero);
|
||||||
var turretOffset = turreted != null ? turreted.Position(self) : WVec.Zero;
|
var turretLocalOffset = turreted != null ? turreted.Offset : WVec.Zero;
|
||||||
var turretOrientation = turreted != null ? turreted.LocalOrientation(self) : WRot.Zero;
|
var turretOrientation = turreted != null ? turreted.LocalOrientation(self) : WRot.Zero;
|
||||||
|
|
||||||
var quantizedBody = body.QuantizeOrientation(self, self.Orientation);
|
var quantizedBody = body.QuantizeOrientation(self, self.Orientation);
|
||||||
var quantizedTurret = body.QuantizeOrientation(self, turretOrientation);
|
var quantizedTurret = body.QuantizeOrientation(self, turretOrientation);
|
||||||
return turretOffset + body.LocalToWorld(localOffset.Rotate(quantizedTurret).Rotate(quantizedBody));
|
return body.LocalToWorld((turretLocalOffset + localOffset.Rotate(quantizedTurret)).Rotate(quantizedBody));
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<WRot> BarrelRotation()
|
IEnumerable<WRot> BarrelRotation()
|
||||||
@@ -92,5 +100,12 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
yield return turreted.LocalOrientation(self) + WRot.FromYaw(b.Yaw - qb.Yaw);
|
yield return turreted.LocalOrientation(self) + WRot.FromYaw(b.Yaw - qb.Yaw);
|
||||||
yield return qb;
|
yield return qb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void INotifyBuildComplete.BuildingComplete(Actor self) { buildComplete = true; }
|
||||||
|
void INotifySold.Selling(Actor self) { buildComplete = false; }
|
||||||
|
void INotifySold.Sold(Actor self) { }
|
||||||
|
void INotifyTransform.BeforeTransform(Actor self) { buildComplete = false; }
|
||||||
|
void INotifyTransform.OnTransform(Actor self) { }
|
||||||
|
void INotifyTransform.AfterTransform(Actor toActor) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,17 +52,19 @@ NALASR:
|
|||||||
Turreted:
|
Turreted:
|
||||||
ROT: 10
|
ROT: 10
|
||||||
InitialFacing: 300
|
InitialFacing: 300
|
||||||
Offset: 298,-171,0
|
Offset: 298,-171,288
|
||||||
AttackTurreted:
|
AttackTurreted:
|
||||||
Armament:
|
Armament:
|
||||||
Weapon: TurretLaserFire
|
Weapon: TurretLaserFire
|
||||||
LocalOffset: 0, 0, 200
|
LocalOffset: 352, 0, 224
|
||||||
RenderVoxels:
|
RenderVoxels:
|
||||||
WithVoxelTurret:
|
WithVoxelTurret:
|
||||||
Power:
|
Power:
|
||||||
Amount: -40
|
Amount: -40
|
||||||
SelectionDecorations:
|
SelectionDecorations:
|
||||||
VisualBounds: 40, 36, -8, -8
|
VisualBounds: 40, 36, -8, -8
|
||||||
|
BodyOrientation:
|
||||||
|
QuantizedFacings: 0
|
||||||
|
|
||||||
NAOBEL:
|
NAOBEL:
|
||||||
Inherits: ^Defense
|
Inherits: ^Defense
|
||||||
@@ -149,7 +151,7 @@ GATICK:
|
|||||||
Valued:
|
Valued:
|
||||||
Cost: 800
|
Cost: 800
|
||||||
Tooltip:
|
Tooltip:
|
||||||
Name: Deployed Tick Tank
|
Name: Tick Tank
|
||||||
Health:
|
Health:
|
||||||
HP: 350
|
HP: 350
|
||||||
Armor:
|
Armor:
|
||||||
@@ -158,18 +160,18 @@ GATICK:
|
|||||||
Range: 5c0
|
Range: 5c0
|
||||||
Turreted:
|
Turreted:
|
||||||
ROT: 6
|
ROT: 6
|
||||||
InitialFacing: 128
|
InitialFacing: 224
|
||||||
Offset: 170,0,213
|
Offset: 0,96,224
|
||||||
Armament@PRIMARY:
|
Armament@PRIMARY:
|
||||||
Weapon: 90mm
|
Weapon: 90mm
|
||||||
LocalOffset: 384,0,128
|
LocalOffset: 448,0,348
|
||||||
UpgradeTypes: eliteweapon
|
UpgradeTypes: eliteweapon
|
||||||
UpgradeMaxEnabledLevel: 0
|
UpgradeMaxEnabledLevel: 0
|
||||||
UpgradeMaxAcceptedLevel: 1
|
UpgradeMaxAcceptedLevel: 1
|
||||||
MuzzleSequence: muzzle
|
MuzzleSequence: muzzle
|
||||||
Armament@ELITE:
|
Armament@ELITE:
|
||||||
Weapon: 120mmx
|
Weapon: 120mmx
|
||||||
LocalOffset: 384,0,128
|
LocalOffset: 448,0,348
|
||||||
UpgradeTypes: eliteweapon
|
UpgradeTypes: eliteweapon
|
||||||
UpgradeMinEnabledLevel: 1
|
UpgradeMinEnabledLevel: 1
|
||||||
MuzzleSequence: muzzle
|
MuzzleSequence: muzzle
|
||||||
@@ -177,7 +179,7 @@ GATICK:
|
|||||||
QuantizedFacings: 32
|
QuantizedFacings: 32
|
||||||
RenderVoxels:
|
RenderVoxels:
|
||||||
WithVoxelBarrel:
|
WithVoxelBarrel:
|
||||||
LocalOffset: 170,0,0
|
LocalOffset: 128,0,348
|
||||||
WithVoxelTurret:
|
WithVoxelTurret:
|
||||||
Transforms:
|
Transforms:
|
||||||
IntoActor: ttnk
|
IntoActor: ttnk
|
||||||
|
|||||||
Reference in New Issue
Block a user