Rotating lights and overridden textures
The flashlight has the correct texture now, but something still seems off about the UV coordinates. Scaling is probably incorrect.
This commit is contained in:
@@ -62,10 +62,18 @@ namespace Barotrauma.Lights
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private float rotation;
|
||||||
public float Rotation
|
public float Rotation
|
||||||
{
|
{
|
||||||
get;
|
get { return rotation; }
|
||||||
set;
|
set
|
||||||
|
{
|
||||||
|
if (rotation == value) return;
|
||||||
|
rotation = value;
|
||||||
|
|
||||||
|
NeedsHullCheck = true;
|
||||||
|
NeedsRecalculation = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector2 WorldPosition
|
public Vector2 WorldPosition
|
||||||
@@ -395,18 +403,41 @@ namespace Barotrauma.Lights
|
|||||||
Vector2 drawPos = position;
|
Vector2 drawPos = position;
|
||||||
if (ParentSub != null) drawPos += ParentSub.DrawPosition;
|
if (ParentSub != null) drawPos += ParentSub.DrawPosition;
|
||||||
|
|
||||||
|
float cosAngle = (float)Math.Cos(Rotation);
|
||||||
|
float sinAngle = -(float)Math.Sin(Rotation);
|
||||||
|
|
||||||
|
Vector2 uvOffset = Vector2.Zero;
|
||||||
|
Vector2 overrideTextureDims = Vector2.One;
|
||||||
|
if (overrideLightTexture != null)
|
||||||
|
{
|
||||||
|
overrideTextureDims = new Vector2(overrideLightTexture.SourceRect.Width, overrideLightTexture.SourceRect.Height);
|
||||||
|
uvOffset = (overrideLightTexture.Origin / overrideLightTexture.size) - new Vector2(0.5f, 0.5f);
|
||||||
|
}
|
||||||
|
|
||||||
// Add a vertex for the center of the mesh
|
// Add a vertex for the center of the mesh
|
||||||
vertices.Add(new VertexPositionTexture(new Vector3(position.X, position.Y, 0),
|
vertices.Add(new VertexPositionTexture(new Vector3(position.X, position.Y, 0),
|
||||||
new Vector2(0.5f, 0.5f)));
|
new Vector2(0.5f, 0.5f) + uvOffset));
|
||||||
|
|
||||||
// Add all the other encounter points as vertices
|
// Add all the other encounter points as vertices
|
||||||
// storing their world position as UV coordinates
|
// storing their world position as UV coordinates
|
||||||
foreach (Vector2 vertex in rayCastHits)
|
foreach (Vector2 vertex in rayCastHits)
|
||||||
{
|
{
|
||||||
Vector2 diff = vertex - drawPos;
|
Vector2 rawDiff = vertex - drawPos;
|
||||||
|
Vector2 diff = rawDiff;
|
||||||
|
diff /= range*2.0f;
|
||||||
|
if (overrideLightTexture != null)
|
||||||
|
{
|
||||||
|
diff /= (overrideLightTexture.size / overrideTextureDims);
|
||||||
|
Vector2 originDiff = diff;
|
||||||
|
|
||||||
vertices.Add(new VertexPositionTexture(new Vector3(position.X + diff.X, position.Y + diff.Y, 0),
|
diff.X = originDiff.X * cosAngle - originDiff.Y * sinAngle;
|
||||||
new Vector2(0.5f, 0.5f) + diff / range / 2));
|
diff.Y = originDiff.X * sinAngle + originDiff.Y * cosAngle;
|
||||||
|
|
||||||
|
diff += uvOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
vertices.Add(new VertexPositionTexture(new Vector3(position.X + rawDiff.X, position.Y + rawDiff.Y, 0),
|
||||||
|
new Vector2(0.5f, 0.5f) + diff));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute the indices to form triangles
|
// Compute the indices to form triangles
|
||||||
@@ -495,6 +526,14 @@ namespace Barotrauma.Lights
|
|||||||
if (vertexCount == 0) return;
|
if (vertexCount == 0) return;
|
||||||
|
|
||||||
lightEffect.DiffuseColor = (new Vector3(color.R, color.G, color.B) * (color.A / 255.0f)) / 255.0f;// color.ToVector3();
|
lightEffect.DiffuseColor = (new Vector3(color.R, color.G, color.B) * (color.A / 255.0f)) / 255.0f;// color.ToVector3();
|
||||||
|
if (overrideLightTexture != null)
|
||||||
|
{
|
||||||
|
lightEffect.Texture = overrideLightTexture.Texture;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lightEffect.Texture = LightTexture;
|
||||||
|
}
|
||||||
lightEffect.CurrentTechnique.Passes[0].Apply();
|
lightEffect.CurrentTechnique.Passes[0].Apply();
|
||||||
|
|
||||||
GameMain.CurrGraphicsDevice.SetVertexBuffer(lightVolumeBuffer);
|
GameMain.CurrGraphicsDevice.SetVertexBuffer(lightVolumeBuffer);
|
||||||
|
|||||||
Reference in New Issue
Block a user