blob: f4b988d9e3ce81cc78be8d37d3b69f7c56890563 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
using System;
using Sandbox;
namespace MurderGame;
// It's just a square with a material slapped onto it.
public class Footprint : RenderEntity
{
private readonly TimeSince TimeSinceCreated = 0;
public Material SpriteMaterial { get; set; }
public float SpriteScale { get; set; } = 18f;
public bool Enabled { get; set; } = true;
public Color Color { get; set; }
[GameEvent.Tick.Client]
public void OnTick()
{
if ( !(TimeSinceCreated > Math.Clamp( MurderGame.MaxFootprintTime, 0, 30 )) )
{
return;
}
Enabled = false;
Delete();
}
public override void DoRender( SceneObject obj )
{
if ( !Enabled )
{
return;
}
// Allow lights to affect the sprite
Graphics.SetupLighting( obj );
// Create the vertex buffer for the sprite
var vb = new VertexBuffer();
vb.Init( true );
// Vertex buffers are in local space, so we need the camera position in local space too
var normal = new Vector3( 0, 0.01f, 100 );
var w = normal.Cross( Vector3.Down ).Normal;
var h = normal.Cross( w ).Normal;
var halfSpriteSize = SpriteScale / 2;
// Add a single quad to our vertex buffer
vb.AddQuad( new Ray( default, normal ), halfSpriteSize * w, h * halfSpriteSize );
Graphics.Attributes.Set( "color", Color );
// Draw the sprite
vb.Draw( SpriteMaterial );
}
}
|