Moar progress, fixed shadow/los/submarine misalignment issues

This commit is contained in:
Regalis
2015-12-09 19:29:53 +02:00
parent beecfe60ac
commit 78bccca4af
43 changed files with 396 additions and 383 deletions
+21 -29
View File
@@ -10,8 +10,6 @@ namespace Barotrauma
{
class Explosion
{
private Vector2 position;
private Attack attack;
private float force;
@@ -32,58 +30,52 @@ namespace Barotrauma
shockwave = ToolBox.GetAttributeBool(element, "shockwave", true);
flames = ToolBox.GetAttributeBool(element, "flames", true);
CameraShake = ToolBox.GetAttributeFloat(element, "camerashake", attack.Range*10.0f);
CameraShake = ToolBox.GetAttributeFloat(element, "camerashake", attack.Range);
}
public void Explode()
public void Explode(Vector2 worldPosition)
{
Explode(position);
}
public void Explode(Vector2 simPosition)
{
Vector2 displayPosition = ConvertUnits.ToDisplayUnits(simPosition);
Hull hull = Hull.FindHull(displayPosition);
Hull hull = Hull.FindHull(worldPosition);
if (shockwave)
{
GameMain.ParticleManager.CreateParticle("shockwave", displayPosition,
GameMain.ParticleManager.CreateParticle("shockwave", worldPosition,
Vector2.Zero, 0.0f, hull);
}
for (int i = 0; i < attack.Range * 10; i++)
for (int i = 0; i < attack.Range * 0.1f; i++)
{
if (sparks)
{
GameMain.ParticleManager.CreateParticle("spark", displayPosition,
GameMain.ParticleManager.CreateParticle("spark", worldPosition,
Rand.Vector(Rand.Range(500.0f, 800.0f)), 0.0f, hull);
}
if (flames)
{
GameMain.ParticleManager.CreateParticle("explosionfire", displayPosition + Rand.Vector(50f),
GameMain.ParticleManager.CreateParticle("explosionfire", worldPosition + Rand.Vector(50f),
Rand.Vector(Rand.Range(50f, 100.0f)), 0.0f, hull);
}
}
float displayRange = ConvertUnits.ToDisplayUnits(attack.Range);
float displayRange = attack.Range;
if (displayRange < 0.1f) return;
light = new LightSource(displayPosition, displayRange, Color.LightYellow, hull != null ? hull.Submarine : null);
light = new LightSource(worldPosition, displayRange, Color.LightYellow, hull != null ? hull.Submarine : null);
CoroutineManager.StartCoroutine(DimLight());
float cameraDist = Vector2.Distance(GameMain.GameScreen.Cam.Position, displayPosition)/2.0f;
GameMain.GameScreen.Cam.Shake = CameraShake * Math.Max((displayRange - cameraDist)/displayRange, 0.0f);
float cameraDist = Vector2.Distance(GameMain.GameScreen.Cam.Position, worldPosition)/2.0f;
GameMain.GameScreen.Cam.Shake = CameraShake * Math.Max((displayRange - cameraDist) / displayRange, 0.0f);
if (attack.GetStructureDamage(1.0f) > 0.0f)
{
RangedStructureDamage(displayPosition, displayRange, attack.GetStructureDamage(1.0f));
RangedStructureDamage(worldPosition, displayRange, attack.GetStructureDamage(1.0f));
}
if (force == 0.0f && attack.Stun == 0.0f && attack.GetDamage(1.0f) == 0.0f) return;
foreach (Character c in Character.CharacterList)
{
float dist = Vector2.Distance(c.SimPosition, simPosition);
float dist = Vector2.Distance(c.WorldPosition, worldPosition);
if (dist > attack.Range) continue;
@@ -91,14 +83,14 @@ namespace Barotrauma
foreach (Limb limb in c.AnimController.Limbs)
{
if (limb.SimPosition == simPosition) continue;
distFactor = 1.0f - Vector2.Distance(limb.SimPosition, simPosition)/attack.Range;
if (limb.WorldPosition == worldPosition) continue;
distFactor = 1.0f - Vector2.Distance(limb.WorldPosition, worldPosition)/attack.Range;
c.AddDamage(limb.SimPosition, DamageType.None,
attack.GetDamage(1.0f) / c.AnimController.Limbs.Length * distFactor, 0.0f, attack.Stun * distFactor, false);
if (force>0.0f)
if (force > 0.0f)
{
limb.body.ApplyLinearImpulse(Vector2.Normalize(limb.SimPosition - simPosition) * distFactor * force);
limb.body.ApplyLinearImpulse(Vector2.Normalize(limb.WorldPosition - worldPosition) * distFactor * force);
}
}
}
@@ -124,7 +116,7 @@ namespace Barotrauma
yield return CoroutineStatus.Success;
}
public static void RangedStructureDamage(Vector2 displayPosition, float displayRange, float damage)
public static void RangedStructureDamage(Vector2 worldPosition, float worldRange, float damage)
{
List<Structure> structureList = new List<Structure>();
@@ -137,7 +129,7 @@ namespace Barotrauma
if (structure.HasBody &&
!structure.IsPlatform &&
Vector2.Distance(structure.Position, displayPosition) < dist * 3.0f)
Vector2.Distance(structure.WorldPosition, worldPosition) < dist * 3.0f)
{
structureList.Add(structure);
}
@@ -147,7 +139,7 @@ namespace Barotrauma
{
for (int i = 0; i < structure.SectionCount; i++)
{
float distFactor = 1.0f - (Vector2.Distance(structure.SectionPosition(i), displayPosition) / displayRange);
float distFactor = 1.0f - (Vector2.Distance(structure.SectionPosition(i, true), worldPosition) / worldRange);
if (distFactor > 0.0f) structure.AddDamage(i, damage * distFactor);
}
}
+4 -4
View File
@@ -39,9 +39,9 @@ namespace Barotrauma
get { return size; }
}
public FireSource(Vector2 position, Hull spawningHull = null, bool networkEvent=false)
public FireSource(Vector2 worldPosition, Hull spawningHull = null, bool networkEvent=false)
{
hull = Hull.FindHull(position, spawningHull);
hull = Hull.FindHull(worldPosition, spawningHull);
if (hull == null || (!networkEvent && GameMain.Client!=null)) return;
if (fireSoundBasic==null)
@@ -50,11 +50,11 @@ namespace Barotrauma
fireSoundLarge = Sound.Load("Content/Sounds/firelarge.ogg");
}
lightSource = new LightSource(position, 50.0f, new Color(1.0f, 0.9f, 0.6f), hull == null ? null : hull.Submarine);
lightSource = new LightSource(worldPosition, 50.0f, new Color(1.0f, 0.9f, 0.6f), hull == null ? null : hull.Submarine);
hull.AddFireSource(this, !networkEvent);
this.position = position - new Vector2(-5.0f, 5.0f);
this.position = worldPosition - new Vector2(-5.0f, 5.0f);
//this.position.Y = hull.Rect.Y - hull.Rect.Height;
+1 -1
View File
@@ -229,7 +229,7 @@ namespace Barotrauma
{
pos.X += Math.Sign(flowForce.X);
pos.Y = MathHelper.Clamp((higherSurface+lowerSurface)/2.0f, rect.Y - rect.Height, rect.Y);
Vector2 velocity = new Vector2(
MathHelper.Clamp(flowForce.X, -5000.0f, 5000.0f) * Rand.Range(0.5f, 0.7f),
flowForce.Y * Rand.Range(0.5f, 0.7f));
+10 -7
View File
@@ -270,8 +270,11 @@ namespace Barotrauma
float maxDelta = Math.Max(Math.Abs(rightDelta[i]), Math.Abs(leftDelta[i]));
if (maxDelta > Rand.Range(1.0f,10.0f))
{
Vector2 particlePos = new Vector2(rect.X + WaveWidth * i, surface + waveY[i]);
if (Submarine != null) particlePos += Submarine.Position;
GameMain.ParticleManager.CreateParticle("mist",
new Vector2(rect.X + WaveWidth * i,surface + waveY[i]),
particlePos,
new Vector2(0.0f, -50.0f), 0.0f, this);
}
@@ -473,21 +476,21 @@ namespace Barotrauma
}
//returns the water block which contains the point (or null if it isn't inside any)
public static Hull FindHull(Vector2 position, Hull guess = null)
public static Hull FindHull(Vector2 worldPosition, Hull guess = null)
{
return FindHull(position, hullList, guess);
return FindHull(worldPosition, hullList, guess);
}
public static Hull FindHull(Vector2 position, List<Hull> hulls, Hull guess = null)
public static Hull FindHull(Vector2 worldPosition, List<Hull> hulls, Hull guess = null)
{
if (guess != null && hulls.Contains(guess))
{
if (Submarine.RectContains(guess.rect, position)) return guess;
if (Submarine.RectContains(guess.WorldRect, worldPosition)) return guess;
}
foreach (Hull w in hulls)
foreach (Hull hull in hulls)
{
if (Submarine.RectContains(w.rect, position)) return w;
if (Submarine.RectContains(hull.WorldRect, worldPosition)) return hull;
}
return null;
+5
View File
@@ -9,6 +9,11 @@ namespace Barotrauma
get;
}
Vector2 WorldPosition
{
get;
}
float Health
{
get;
@@ -35,18 +35,18 @@ namespace Barotrauma
public void Draw(SpriteBatch spriteBatch)
{
Vector2 pos = Vector2.Zero;// level.EndPosition;
Vector2 pos = new Vector2(0.0f, -level.StartPosition.Y);// level.EndPosition;
//pos.Y = -pos.Y - level.Position.Y;
if (GameMain.GameScreen.Cam.WorldView.Y < -pos.Y - 512) return;
pos.X = GameMain.GameScreen.Cam.WorldView.X - 512.0f;
pos.X = GameMain.GameScreen.Cam.WorldView.X -512.0f;
//pos.X += Position.X % 512;
int width = (int)(Math.Ceiling(GameMain.GameScreen.Cam.WorldView.Width / 512.0f + 2.0f) * 512.0f);
spriteBatch.Draw(shaftTexture,
new Rectangle((int)(MathUtils.Round(pos.X, 512.0f) - Submarine.Loaded.Position.X % 512), (int)pos.Y, width, 512),
new Rectangle((int)(MathUtils.Round(pos.X, 512.0f)), (int)pos.Y, width, 512),
new Rectangle(0, 0, width, 256),
Color.White, 0.0f,
Vector2.Zero,
+15 -17
View File
@@ -30,7 +30,6 @@ namespace Barotrauma.Lights
private Dictionary<LightSource, CachedShadow> cachedShadows;
private Vector2[] worldVertices;
private Vector2[] vertices;
private int primitiveCount;
@@ -75,7 +74,6 @@ namespace Barotrauma.Lights
cachedShadows = new Dictionary<LightSource, CachedShadow>();
vertices = points;
worldVertices = new Vector2[vertices.Length];
primitiveCount = vertices.Length;
CalculateDimensions();
@@ -115,7 +113,6 @@ namespace Barotrauma.Lights
for (int i = 0; i < vertices.Count(); i++)
{
vertices[i] += amount;
worldVertices[i] += amount;
}
CalculateDimensions();
@@ -125,26 +122,17 @@ namespace Barotrauma.Lights
{
cachedShadows.Clear();
worldVertices = points;
vertices = points;
}
private void CalculateShadowVertices(Vector2 lightSourcePos, bool los = true)
{
for (int i = 0; i < vertices.Length; i++)
{
worldVertices[i] = vertices[i];
if (parentEntity != null && parentEntity.Submarine != null)
{
worldVertices[i] += parentEntity.Submarine.Position;
}
}
//compute facing of each edge, using N*L
for (int i = 0; i < primitiveCount; i++)
{
Vector2 firstVertex = new Vector2(worldVertices[i].X, worldVertices[i].Y);
Vector2 firstVertex = new Vector2(vertices[i].X, vertices[i].Y);
int secondIndex = (i + 1) % primitiveCount;
Vector2 secondVertex = new Vector2(worldVertices[secondIndex].X, worldVertices[secondIndex].Y);
Vector2 secondVertex = new Vector2(vertices[secondIndex].X, vertices[secondIndex].Y);
Vector2 middle = (firstVertex + secondVertex) / 2;
Vector2 L = lightSourcePos - middle;
@@ -187,7 +175,7 @@ namespace Barotrauma.Lights
int svCount = 0;
while (svCount != shadowVertexCount * 2)
{
Vector3 vertexPos = new Vector3(worldVertices[currentIndex], 0.0f);
Vector3 vertexPos = new Vector3(vertices[currentIndex], 0.0f);
//one vertex on the hull
shadowVertices[svCount] = new VertexPositionColor();
@@ -217,7 +205,7 @@ namespace Barotrauma.Lights
for (int n = 0; n < 4; n += 3)
{
Vector3 penumbraStart = new Vector3((n == 0) ? worldVertices[startingIndex] : worldVertices[endingIndex], 0.0f);
Vector3 penumbraStart = new Vector3((n == 0) ? vertices[startingIndex] : vertices[endingIndex], 0.0f);
penumbraVertices[n] = new VertexPositionTexture();
penumbraVertices[n].Position = penumbraStart;
@@ -293,6 +281,8 @@ namespace Barotrauma.Lights
{
if (!Enabled) return;
if (parentEntity != null && parentEntity.Submarine != null) lightSourcePos -= parentEntity.Submarine.Position;
CalculateShadowVertices(lightSourcePos, los);
DrawShadows(graphicsDevice, cam, transform, los);
@@ -300,7 +290,15 @@ namespace Barotrauma.Lights
private void DrawShadows(GraphicsDevice graphicsDevice, Camera cam, Matrix transform, bool los = true)
{
shadowEffect.World = transform;
Vector3 offset = Vector3.Zero;
if (parentEntity != null && parentEntity.Submarine != null)
{
offset = new Vector3(parentEntity.Submarine.DrawPosition.X, parentEntity.Submarine.DrawPosition.Y, 0.0f);
}
shadowEffect.World = Matrix.CreateTranslation(offset) * transform;
shadowEffect.CurrentTechnique.Passes[0].Apply();
graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, shadowVertices, 0, shadowVertices.Length - 2);
+1 -1
View File
@@ -128,7 +128,7 @@ namespace Barotrauma.Lights
//draw the light shape
//where Alpha is 0, nothing will be written
spriteBatch.Begin(SpriteSortMode.Deferred, CustomBlendStates.MultiplyWithAlpha, null, null, null, null, Matrix.CreateTranslation(new Vector3(Submarine.Loaded.Position.X, -Submarine.Loaded.Position.Y, 0.0f)) * cam.Transform);
spriteBatch.Begin(SpriteSortMode.Deferred, CustomBlendStates.MultiplyWithAlpha, null, null, null, null, Matrix.CreateTranslation(new Vector3(Submarine.Loaded.DrawPosition.X, -Submarine.Loaded.DrawPosition.Y, 0.0f)) * cam.Transform);
light.Draw(spriteBatch);
spriteBatch.End();
}
+14 -5
View File
@@ -70,7 +70,12 @@ namespace Barotrauma
public virtual Rectangle Rect {
get { return rect; }
set { rect = value; }
}
}
public Rectangle WorldRect
{
get { return Submarine == null ? rect : new Rectangle((int)(Submarine.Position.X + rect.X), (int)(Submarine.Position.Y + rect.Y), rect.Width, rect.Height); }
}
public virtual Sprite Sprite
{
@@ -505,12 +510,16 @@ namespace Barotrauma
foreach (MapEntity e in mapEntityList)
{
e.OnMapLoaded();
if (e.Submarine != null) e.Move(Submarine.HiddenSubPosition);
}
//mapEntityList.Sort((x, y) =>
//{
// return x.Name.CompareTo(y.Name);
//});
mapEntityList.Sort((x, y) =>
{
return x.Name.CompareTo(y.Name);
});
}
+15 -8
View File
@@ -292,16 +292,16 @@ namespace Barotrauma
Color color = (isHighlighted) ? Color.Green : Color.White;
if (isSelected && editing) color = Color.Red;
Vector2 drawPos = Submarine == null ? new Vector2(rect.X, -rect.Y) : new Vector2(rect.X + Submarine.DrawPosition.X, -(rect.Y + Submarine.DrawPosition.Y));
prefab.sprite.DrawTiled(spriteBatch, drawPos, new Vector2(rect.Width, rect.Height), Vector2.Zero, color);
Vector2 drawOffset = Submarine == null ? Vector2.Zero : Submarine.DrawPosition;
prefab.sprite.DrawTiled(spriteBatch, new Vector2(rect.X + drawOffset.X, -(rect.Y + drawOffset.Y)), new Vector2(rect.Width, rect.Height), Vector2.Zero, color);
foreach (WallSection s in sections)
{
if (s.isHighLighted)
{
GUI.DrawRectangle(spriteBatch,
drawPos, new Vector2(rect.Width, rect.Height),
new Vector2(s.rect.X + drawOffset.X, -(s.rect.Y + drawOffset.Y)), new Vector2(s.rect.Width, s.rect.Height),
new Color((s.damage / prefab.MaxHealth), 1.0f - (s.damage / prefab.MaxHealth), 0.0f, 1.0f), true);
}
@@ -310,7 +310,7 @@ namespace Barotrauma
if (s.damage < 0.01f) continue;
GUI.DrawRectangle(spriteBatch,
drawPos, new Vector2(rect.Width, rect.Height),
new Vector2(s.rect.X + drawOffset.X, -(s.rect.Y + drawOffset.Y)), new Vector2(s.rect.Width, s.rect.Height),
Color.Black * (s.damage / prefab.MaxHealth), true);
}
@@ -413,13 +413,17 @@ namespace Barotrauma
return sections[sectionIndex].damage;
}
public Vector2 SectionPosition(int sectionIndex)
public Vector2 SectionPosition(int sectionIndex, bool world = false)
{
if (sectionIndex < 0 || sectionIndex >= sections.Length) return Vector2.Zero;
return new Vector2(
Vector2 sectionPos = new Vector2(
sections[sectionIndex].rect.X + sections[sectionIndex].rect.Width / 2.0f,
sections[sectionIndex].rect.Y - sections[sectionIndex].rect.Height / 2.0f);
if (world && Submarine != null) sectionPos += Submarine.Position;
return sectionPos;
}
public AttackResult AddDamage(IDamageable attacker, Vector2 position, Attack attack, float deltaTime, bool playSound = false)
@@ -427,7 +431,10 @@ namespace Barotrauma
if (Submarine.Loaded != null && Submarine.Loaded.GodMode) return new AttackResult(0.0f, 0.0f);
if (!prefab.HasBody || prefab.IsPlatform) return new AttackResult(0.0f, 0.0f);
int i = FindSectionIndex(ConvertUnits.ToDisplayUnits(position));
Vector2 transformedPos = ConvertUnits.ToDisplayUnits(position);
if (Submarine != null) transformedPos -= Submarine.Position;
int i = FindSectionIndex(transformedPos);
if (i == -1) return new AttackResult(0.0f, 0.0f);
GameMain.ParticleManager.CreateParticle("dustcloud", SectionPosition(i), 0.0f, 0.0f);
+22 -15
View File
@@ -25,6 +25,10 @@ namespace Barotrauma
{
public static string SavePath = "Data" + System.IO.Path.DirectorySeparatorChar + "SavedSubs";
//position of the "actual submarine" which is rendered wherever the SubmarineBody is
//should be in an unreachable place
public static readonly Vector2 HiddenSubPosition = new Vector2(0.0f, 50000.0f);
public static List<Submarine> SavedSubmarines = new List<Submarine>();
public static readonly Vector2 GridSize = new Vector2(16.0f, 16.0f);
@@ -97,7 +101,7 @@ namespace Barotrauma
public override Vector2 Position
{
get { return subBody.Position; }
get { return subBody.Position - HiddenSubPosition; }
}
public new Vector2 DrawPosition
@@ -106,13 +110,13 @@ namespace Barotrauma
private set;
}
public Vector2 Speed
public Vector2 Velocity
{
get { return subBody==null ? Vector2.Zero : subBody.Speed; }
set
get { return subBody==null ? Vector2.Zero : subBody.Velocity; }
set
{
if (subBody == null) return;
subBody.Speed = value;
subBody.Velocity = value;
}
}
@@ -185,10 +189,6 @@ namespace Barotrauma
MapEntity.mapEntityList[i].Draw(spriteBatch, editing);
}
if (Submarine.Loaded!=null)
{
Submarine.Loaded.DrawPosition = Physics.Interpolate(Submarine.Loaded.prevPosition, Submarine.Loaded.Position);
}
if (loaded == null) return;
@@ -214,6 +214,11 @@ namespace Barotrauma
}
}
public void UpdateTransform()
{
DrawPosition = Physics.Interpolate(prevPosition, Position);
}
//math/physics stuff ----------------------------------------------------
public static Vector2 MouseToWorldGrid(Camera cam)
@@ -414,8 +419,8 @@ namespace Barotrauma
message.Write(Position.X);
message.Write(Position.Y);
message.Write(Speed.X);
message.Write(Speed.Y);
message.Write(Velocity.X);
message.Write(Velocity.Y);
return true;
}
@@ -446,7 +451,7 @@ namespace Barotrauma
//newTargetPosition = newTargetPosition + newSpeed * (float)(NetTime.Now - sendingTime);
subBody.TargetPosition = newTargetPosition;
subBody.Speed = newSpeed;
subBody.Velocity = newSpeed;
lastNetworkUpdate = sendingTime;
}
@@ -611,6 +616,8 @@ namespace Barotrauma
XDocument doc = OpenDoc(filePath);
if (doc == null) return;
subBody = new SubmarineBody(this);
foreach (XElement element in doc.Root.Elements())
{
string typeName = element.Name.ToString();
@@ -643,7 +650,7 @@ namespace Barotrauma
}
subBody = new SubmarineBody(this);
subBody.SetPosition(HiddenSubPosition);
loaded = this;
@@ -694,10 +701,10 @@ namespace Barotrauma
{
if (GameMain.GameScreen.Cam != null) GameMain.GameScreen.Cam.TargetPos = Vector2.Zero;
subBody = null;
Entity.RemoveAll();
subBody = null;
PhysicsBody.list.Clear();
Ragdoll.list.Clear();
+124 -166
View File
@@ -35,14 +35,12 @@ namespace Barotrauma
private Body body;
private Vector2 speed;
private Vector2 targetPosition;
float mass = 10000.0f;
private Vector2? lastContactPoint;
private VoronoiCell lastContactCell;
//private Vector2? lastContactPoint;
//private VoronoiCell lastContactCell;
public Rectangle Borders
{
@@ -50,13 +48,13 @@ namespace Barotrauma
private set;
}
public Vector2 Speed
public Vector2 Velocity
{
get { return speed; }
set
get { return body.LinearVelocity; }
set
{
if (!MathUtils.IsValid(value)) return;
speed = value;
body.LinearVelocity = value;
}
}
@@ -117,15 +115,16 @@ namespace Barotrauma
body = BodyFactory.CreateCompoundPolygon(GameMain.World, triangulatedVertices, 5.0f);
body.BodyType = BodyType.Dynamic;
body.CollisionCategories = Physics.CollisionMisc;
body.CollisionCategories = Physics.CollisionMisc | Physics.CollisionWall;
body.CollidesWith = Physics.CollisionLevel | Physics.CollisionCharacter;
body.Restitution = 0.0f;
body.Restitution = Restitution;
body.Friction = Friction;
body.FixedRotation = true;
body.Mass = mass;
body.Awake = true;
body.SleepingAllowed = false;
body.IgnoreGravity = true;
body.OnCollision += OnCollision;
body.OnSeparation += OnSeparation;
body.UserData = this;
}
@@ -224,14 +223,14 @@ namespace Barotrauma
Vector2 totalForce = CalculateBuoyancy();
if (speed.LengthSquared() > 0.000001f)
if (body.LinearVelocity.LengthSquared() > 0.000001f)
{
float dragCoefficient = 0.00001f;
float speedLength = (speed == Vector2.Zero) ? 0.0f : speed.Length();
float speedLength = (body.LinearVelocity == Vector2.Zero) ? 0.0f : body.LinearVelocity.Length();
float drag = speedLength * speedLength * dragCoefficient * mass;
totalForce += -Vector2.Normalize(speed) * drag;
totalForce += -Vector2.Normalize(body.LinearVelocity) * drag;
}
ApplyForce(totalForce);
@@ -267,7 +266,7 @@ namespace Barotrauma
public void ApplyForce(Vector2 force)
{
body.ApplyForce(force/100.0f);
body.ApplyForce(force);
}
public void SetPosition(Vector2 position)
@@ -317,31 +316,121 @@ namespace Barotrauma
depthDamageTimer = 10.0f;
}
private void UpdateColliding()
//private void UpdateColliding()
//{
// return;
// if (body.Position.LengthSquared()<0.00001f) return;
// Vector2 normal = Vector2.Normalize(body.Position);
// Vector2 simSpeed = ConvertUnits.ToSimUnits(body.LinearVelocity);
// float impact = Vector2.Dot(simSpeed, -normal);
// if (impact < 0.0f) return;
// Vector2 u = Vector2.Dot(simSpeed, -normal) * normal;
// Vector2 w = (simSpeed + u);
// //speed = ConvertUnits.ToDisplayUnits(w * (1.0f - Friction) + u * Restitution);
// if (lastContactPoint == null || lastContactCell==null || impact < 3.0f) return;
// SoundPlayer.PlayDamageSound(DamageSoundType.StructureBlunt, impact * 10.0f, ConvertUnits.ToDisplayUnits((Vector2)lastContactPoint));
// GameMain.GameScreen.Cam.Shake = impact * 2.0f;
// Vector2 limbForce = -normal * impact*0.5f;
// float length = limbForce.Length();
// if (length > 10.0f) limbForce = (limbForce / length) * 10.0f;
// foreach (Character c in Character.CharacterList)
// {
// if (c.AnimController.CurrentHull == null) continue;
// if (impact > 2.0f) c.AnimController.StunTimer = (impact - 2.0f) * 0.1f;
// foreach (Limb limb in c.AnimController.Limbs)
// {
// if (c.AnimController.LowestLimb == limb) continue;
// limb.body.ApplyLinearImpulse(limb.Mass * limbForce);
// }
// }
// Explosion.RangedStructureDamage(ConvertUnits.ToDisplayUnits((Vector2)lastContactPoint), impact*50.0f, impact*DamageMultiplier);
// //Body wallBody = Submarine.PickBody(
// // (Vector2)lastContactPoint - body.Position,
// // (Vector2)lastContactPoint + body.Position * 10.0f,
// // new List<Body>() { lastContactCell.body });
// //if (wallBody == null || wallBody.UserData == null) return;
// //var damageable = wallBody.UserData as IDamageable;
// //Structure structure = wallBody.UserData as Structure;
// //if (structure == null) return;
// //int sectionIndex = structure.FindSectionIndex(ConvertUnits.ToDisplayUnits(Submarine.LastPickedPosition));
// //for (int i = sectionIndex - (int)(impact / 5.0f); i < sectionIndex + (int)(impact / 5.0f); i++)
// //{
// // structure.AddDamage(i, impact * DamageMultiplier);
// //}
//}
public bool OnCollision(Fixture f1, Fixture f2, Contact contact)
{
return;
if (body.Position.LengthSquared()<0.00001f) return;
Vector2 normal = Vector2.Normalize(body.Position);
Vector2 simSpeed = ConvertUnits.ToSimUnits(speed);
float impact = Vector2.Dot(simSpeed, -normal);
if (impact < 0.0f) return;
Vector2 u = Vector2.Dot(simSpeed, -normal) * normal;
Vector2 w = (simSpeed + u);
speed = ConvertUnits.ToDisplayUnits(w * (1.0f - Friction) + u * Restitution);
VoronoiCell cell = f2.Body.UserData as VoronoiCell;
if (lastContactPoint == null || lastContactCell==null || impact < 3.0f) return;
SoundPlayer.PlayDamageSound(DamageSoundType.StructureBlunt, impact * 10.0f, ConvertUnits.ToDisplayUnits((Vector2)lastContactPoint));
if (cell == null)
{
Limb limb = f2.Body.UserData as Limb;
if (limb!=null && limb.character.Submarine==null)
{
Vector2 normal2;
FixedArray2<Vector2> points;
contact.GetWorldManifold(out normal2, out points);
if (Submarine.PickBody(points[0] - ConvertUnits.ToSimUnits(submarine.Position) + normal2, points[0] - ConvertUnits.ToSimUnits(submarine.Position) - normal2, null, Physics.CollisionWall) != null)
{
return true;
}
var ragdoll = limb.character.AnimController;
ragdoll.FindHull();
return false;
}
return true;
}
Vector2 normal;
FarseerPhysics.Common.FixedArray2<Vector2> worldPoints;
contact.GetWorldManifold(out normal, out worldPoints);
Vector2 lastContactPoint = worldPoints[0];
float impact = Vector2.Dot(Velocity, -normal);
//Vector2 u = Vector2.Dot(Velocity, -normal) * normal;
//Vector2 w = (Velocity + u);
//speed = ConvertUnits.ToDisplayUnits(w * (1.0f - Friction) + u * Restitution);
if (impact < 3.0f) return true;
SoundPlayer.PlayDamageSound(DamageSoundType.StructureBlunt, impact * 10.0f, ConvertUnits.ToDisplayUnits(lastContactPoint));
GameMain.GameScreen.Cam.Shake = impact * 2.0f;
Vector2 limbForce = -normal * impact*0.5f;
Vector2 limbForce = -normal * impact * 0.5f;
float length = limbForce.Length();
if (length > 10.0f) limbForce = (limbForce / length) * 10.0f;
@@ -359,141 +448,10 @@ namespace Barotrauma
}
}
Explosion.RangedStructureDamage(ConvertUnits.ToDisplayUnits((Vector2)lastContactPoint), impact*50.0f, impact*DamageMultiplier);
//Body wallBody = Submarine.PickBody(
// (Vector2)lastContactPoint - body.Position,
// (Vector2)lastContactPoint + body.Position * 10.0f,
// new List<Body>() { lastContactCell.body });
//if (wallBody == null || wallBody.UserData == null) return;
//var damageable = wallBody.UserData as IDamageable;
//Structure structure = wallBody.UserData as Structure;
//if (structure == null) return;
//int sectionIndex = structure.FindSectionIndex(ConvertUnits.ToDisplayUnits(Submarine.LastPickedPosition));
//for (int i = sectionIndex - (int)(impact / 5.0f); i < sectionIndex + (int)(impact / 5.0f); i++)
//{
// structure.AddDamage(i, impact * DamageMultiplier);
//}
}
public bool OnCollision(Fixture f1, Fixture f2, Contact contact)
{
VoronoiCell cell = f2.Body.UserData as VoronoiCell;
if (cell == null)
{
Limb limb = f2.Body.UserData as Limb;
if (limb!=null && limb.character.Submarine==null)
{
Vector2 normal2;
FixedArray2<Vector2> points;
contact.GetWorldManifold(out normal2, out points);
if (Submarine.PickBody(points[0] - ConvertUnits.ToSimUnits(submarine.Position), points[0] - ConvertUnits.ToSimUnits(submarine.Position) - normal2, null, Physics.CollisionWall) != null)
{
return true;
}
return false;
//var ragdoll = limb.character.AnimController;
//ragdoll.SetPosition(ragdoll.RefLimb.Position - body.Position);
//limb.character.Submarine = submarine;
}
return true;
}
lastContactCell = cell;
Vector2 normal;
FarseerPhysics.Common.FixedArray2<Vector2> worldPoints;
contact.GetWorldManifold(out normal, out worldPoints);
lastContactPoint = worldPoints[0];
Explosion.RangedStructureDamage(ConvertUnits.ToDisplayUnits(lastContactPoint), impact * 50.0f, impact * DamageMultiplier);
return true;
//Vector2 normal = contact.Manifold.LocalNormal;
//Vector2 simSpeed = ConvertUnits.ToSimUnits(speed);
//float impact = Vector2.Dot(-simSpeed, normal);
////Vector2 u = Vector2.Dot(simSpeed, -normal) * -normal;
////Vector2 w = simSpeed - u;
//Vector2 limbForce = normal * impact;
////float length = limbForce.Length();
////if (length > 10.0f) limbForce = (limbForce / length) * 10.0f;
////foreach (Character c in Character.CharacterList)
////{
//// if (c.AnimController.CurrentHull == null) continue;
//// if (impact > 2.0f) c.AnimController.StunTimer = (impact - 2.0f) * 0.1f;
//// foreach (Limb limb in c.AnimController.Limbs)
//// {
//// if (c.AnimController.LowestLimb == limb) continue;
//// limb.body.ApplyLinearImpulse(limb.Mass * limbForce);
//// }
////}
//System.Diagnostics.Debug.WriteLine("IMPACT: " + impact + " normal: " + normal + " simspeed: " + simSpeed);
//if (impact > 1.0f)
//{
// contact.GetWorldManifold(out normal, out worldPoints);
// lastContactPoint = worldPoints[0];
// AmbientSoundManager.PlayDamageSound(DamageSoundType.StructureBlunt, impact * 10.0f, ConvertUnits.ToDisplayUnits(worldPoints[0]));
// GameMain.GameScreen.Cam.Shake = impact * 2.0f;
// //speed = ConvertUnits.ToDisplayUnits(w * 0.9f + u * 0.5f);
// //FixedArray2<Vector2> worldPoints;
// //contact.GetWorldManifold(out normal, out worldPoints);
// //if (contact.Manifold.PointCount >= 1)
// //{
// // Vector2 contactPoint = worldPoints[0];
// // Body wallBody = Submarine.PickBody(contactPoint, contactPoint + normal, new List<Body>() { cell.body });
// // if (wallBody!=null && wallBody.UserData!=null)
// // {
// // Structure s = wallBody.UserData as Structure;
// // }
// //}
// //foreach (GraphEdge ge in cell.edges)
// //{
// // Body wallBody = Submarine.PickBody(
// // ConvertUnits.ToSimUnits(ge.point1 + GameMain.GameSession.Level.Position + normal),
// // ConvertUnits.ToSimUnits(ge.point2 + GameMain.GameSession.Level.Position + normal), new List<Body>() { cell.body });
// // if (wallBody == null || wallBody.UserData == null) continue;
// // Structure structure = wallBody.UserData as Structure;
// // if (structure == null) continue;
// // structure.AddDamage(
// // structure.FindSectionIndex(ConvertUnits.ToDisplayUnits(Submarine.LastPickedPosition)), impact*50.0f);
// //}
//}
//collisionRigidness = 0.8f;
//return true;
}
public void OnSeparation(Fixture f1, Fixture f2)
{
lastContactPoint = null;
}
}
}
+1 -1
View File
@@ -403,7 +403,7 @@ namespace Barotrauma
public override void OnMapLoaded()
{
currentHull = Hull.FindHull(this.Position);
currentHull = Hull.FindHull(WorldPosition);
}
public override XElement Save(XDocument doc)