2016-03-26 13:51:42 +11:00
|
|
|
|
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
|
|
|
|
|
using System;
|
2016-06-22 18:50:47 +10:00
|
|
|
|
using ClassicalSharp.GraphicsAPI;
|
2016-05-11 19:37:31 +10:00
|
|
|
|
using ClassicalSharp.Map;
|
2015-06-24 19:48:12 +10:00
|
|
|
|
using OpenTK;
|
|
|
|
|
|
|
|
|
|
namespace ClassicalSharp.Particles {
|
|
|
|
|
|
2015-11-22 23:58:10 +11:00
|
|
|
|
public abstract class Particle {
|
2015-06-24 19:48:12 +10:00
|
|
|
|
|
|
|
|
|
public Vector3 Position;
|
|
|
|
|
public Vector3 Velocity;
|
2015-09-19 16:54:48 +10:00
|
|
|
|
public float Lifetime;
|
2015-06-24 19:48:12 +10:00
|
|
|
|
protected Vector3 lastPos, nextPos;
|
|
|
|
|
|
2016-01-31 23:54:45 +11:00
|
|
|
|
public abstract int Get1DBatch( Game game );
|
2015-06-24 19:48:12 +10:00
|
|
|
|
|
2016-01-31 23:54:45 +11:00
|
|
|
|
public abstract void Render( Game game, double delta, float t,
|
2016-03-29 20:45:52 +11:00
|
|
|
|
VertexP3fT2fC4b[] vertices, ref int index );
|
2015-06-24 19:48:12 +10:00
|
|
|
|
|
2016-05-11 19:37:31 +10:00
|
|
|
|
protected void DoRender( Game game, ref Vector2 size, ref TextureRec rec,
|
2016-08-01 23:29:29 +10:00
|
|
|
|
int col, VertexP3fT2fC4b[] vertices, ref int index ) {
|
2016-05-11 19:37:31 +10:00
|
|
|
|
Vector3 p111, p121, p212, p222;
|
|
|
|
|
Utils.CalcBillboardPoints( size, Position, ref game.View,
|
|
|
|
|
out p111, out p121, out p212, out p222 );
|
2016-08-01 23:29:29 +10:00
|
|
|
|
|
2016-07-10 11:23:20 +10:00
|
|
|
|
vertices[index++] = new VertexP3fT2fC4b( ref p111, rec.U1, rec.V2, col );
|
|
|
|
|
vertices[index++] = new VertexP3fT2fC4b( ref p121, rec.U1, rec.V1, col );
|
|
|
|
|
vertices[index++] = new VertexP3fT2fC4b( ref p222, rec.U2, rec.V1, col );
|
|
|
|
|
vertices[index++] = new VertexP3fT2fC4b( ref p212, rec.U2, rec.V2, col );
|
2016-05-11 19:37:31 +10:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-31 22:53:42 +11:00
|
|
|
|
public virtual bool Tick( Game game, double delta ) {
|
2015-09-19 16:54:48 +10:00
|
|
|
|
Lifetime -= (float)delta;
|
2015-06-24 19:48:12 +10:00
|
|
|
|
return Lifetime < 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-11 19:37:31 +10:00
|
|
|
|
|
|
|
|
|
public sealed class RainParticle : CollidableParticle {
|
|
|
|
|
|
|
|
|
|
static Vector2 bigSize = new Vector2( 1/16f, 1/16f );
|
|
|
|
|
static Vector2 smallSize = new Vector2( 0.75f/16f, 0.75f/16f );
|
|
|
|
|
static Vector2 tinySize = new Vector2( 0.5f/16f, 0.5f/16f );
|
|
|
|
|
static TextureRec rec = new TextureRec( 2/128f, 14/128f, 3/128f, 2/128f );
|
|
|
|
|
|
|
|
|
|
public RainParticle() { throughLiquids = false; }
|
|
|
|
|
|
|
|
|
|
public bool Big, Tiny;
|
|
|
|
|
|
|
|
|
|
public override bool Tick( Game game, double delta ) {
|
|
|
|
|
bool dies = Tick( game, 3.5f, delta );
|
|
|
|
|
return hitTerrain ? true : dies;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int Get1DBatch( Game game ) { return 0; }
|
|
|
|
|
|
|
|
|
|
public override void Render( Game game, double delta, float t,
|
|
|
|
|
VertexP3fT2fC4b[] vertices, ref int index ) {
|
|
|
|
|
Position = Vector3.Lerp( lastPos, nextPos, t );
|
|
|
|
|
Vector2 size = Big ? bigSize : (Tiny ? tinySize : smallSize);
|
2016-08-01 23:29:29 +10:00
|
|
|
|
|
|
|
|
|
World map = game.World;
|
|
|
|
|
int col = map.IsLit( Position ) ? map.Env.Sun : map.Env.Shadow;
|
|
|
|
|
DoRender( game, ref size, ref rec, col, vertices, ref index );
|
2016-05-11 19:37:31 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public sealed class TerrainParticle : CollidableParticle {
|
|
|
|
|
|
|
|
|
|
static Vector2 terrainSize = new Vector2( 1/8f, 1/8f );
|
|
|
|
|
internal TextureRec rec;
|
2016-08-01 23:29:29 +10:00
|
|
|
|
internal ushort flags; // lower 8 bits for tex location, next bit for fullbright
|
2016-05-11 19:37:31 +10:00
|
|
|
|
|
|
|
|
|
public override bool Tick( Game game, double delta ) {
|
|
|
|
|
return Tick( game, 5.4f, delta );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int Get1DBatch( Game game ) {
|
2016-08-01 23:29:29 +10:00
|
|
|
|
return game.TerrainAtlas1D.Get1DIndex( flags & 0xFF );
|
2016-05-11 19:37:31 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Render( Game game, double delta, float t,
|
|
|
|
|
VertexP3fT2fC4b[] vertices, ref int index ) {
|
|
|
|
|
Position = Vector3.Lerp( lastPos, nextPos, t );
|
2016-08-01 23:29:29 +10:00
|
|
|
|
|
|
|
|
|
World map = game.World;
|
|
|
|
|
bool fullBright = (flags & 0x100) != 0;
|
|
|
|
|
int col = fullBright ? FastColour.WhitePacked
|
2016-09-24 13:52:59 -07:00
|
|
|
|
: (map.IsLit( Position ) ? map.Env.SunZSide : map.Env.ShadowZSide);
|
2016-08-01 23:29:29 +10:00
|
|
|
|
DoRender( game, ref terrainSize, ref rec, col, vertices, ref index );
|
2016-05-11 19:37:31 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-06-24 19:48:12 +10:00
|
|
|
|
}
|