mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-23 01:21:57 -05:00
Reduce code duplication of SelectionBox and AxisLinesRenderer.
This commit is contained in:
parent
344688ca8d
commit
01cdeee0eb
2 changed files with 26 additions and 53 deletions
|
@ -10,19 +10,14 @@ namespace ClassicalSharp.Selections {
|
|||
VertexP3fC4b[] vertices;
|
||||
int vb;
|
||||
Game game;
|
||||
const float size = 1/32f;
|
||||
|
||||
public void Init( Game game ) {
|
||||
this.game = game;
|
||||
}
|
||||
|
||||
public void Init( Game game ) { this.game = game; }
|
||||
public void Ready( Game game ) { }
|
||||
public void Reset( Game game ) { }
|
||||
public void OnNewMap( Game game ) { }
|
||||
public void OnNewMapLoaded( Game game ) { }
|
||||
|
||||
public void Dispose() {
|
||||
game.Graphics.DeleteDynamicVb( vb );
|
||||
}
|
||||
public void Dispose() { game.Graphics.DeleteDynamicVb( vb ); }
|
||||
|
||||
public void Render( double delta ) {
|
||||
if( !game.ShowAxisLines ) return;
|
||||
|
@ -31,33 +26,19 @@ namespace ClassicalSharp.Selections {
|
|||
vb = game.Graphics.CreateDynamicVb( VertexFormat.P3fC4b, vertices.Length );
|
||||
}
|
||||
game.Graphics.Texturing = false;
|
||||
Vector3 pos = game.LocalPlayer.Position; pos.Y += 0.05f;
|
||||
Vector3 P = game.LocalPlayer.Position; P.Y += 0.05f;
|
||||
int index = 0;
|
||||
const float size = 1/32f;
|
||||
|
||||
HorQuad( ref index, pos.X, pos.Z - size, pos.X + 3, pos.Z + size, pos.Y, FastColour.Red );
|
||||
HorQuad( ref index, pos.X - size, pos.Z, pos.X + size, pos.Z + 3, pos.Y, FastColour.Blue );
|
||||
SelectionBox.HorQuad( vertices, ref index, FastColour.Red.Pack(),
|
||||
P.X, P.Z - size, P.X + 3, P.Z + size, P.Y );
|
||||
SelectionBox.HorQuad( vertices, ref index, FastColour.Blue.Pack(),
|
||||
P.X - size, P.Z, P.X + size, P.Z + 3, P.Y );
|
||||
if( game.Camera.IsThirdPerson )
|
||||
VerQuad( ref index, pos.X - size, pos.Y, pos.Z + size, pos.X + size, pos.Y + 3, pos.Z - size, FastColour.Green );
|
||||
SelectionBox.VerQuad( vertices, ref index, FastColour.Green.Pack(),
|
||||
P.X - size, P.Y, P.Z + size, P.X + size, P.Y + 3, P.Z - size );
|
||||
|
||||
game.Graphics.SetBatchFormat( VertexFormat.P3fC4b );
|
||||
game.Graphics.UpdateDynamicIndexedVb( DrawMode.Triangles, vb, vertices, index, index * 6 / 4 );
|
||||
}
|
||||
|
||||
void VerQuad( ref int index, float x1, float y1, float z1, float x2, float y2, float z2, FastColour col ) {
|
||||
int c = col.Pack();
|
||||
vertices[index++] = new VertexP3fC4b( x1, y1, z1, c );
|
||||
vertices[index++] = new VertexP3fC4b( x1, y2, z1, c );
|
||||
vertices[index++] = new VertexP3fC4b( x2, y2, z2, c );
|
||||
vertices[index++] = new VertexP3fC4b( x2, y1, z2, c );
|
||||
}
|
||||
|
||||
void HorQuad( ref int index, float x1, float z1, float x2, float z2, float y, FastColour col ) {
|
||||
int c = col.Pack();
|
||||
vertices[index++] = new VertexP3fC4b( x1, y, z1, c );
|
||||
vertices[index++] = new VertexP3fC4b( x1, y, z2, c );
|
||||
vertices[index++] = new VertexP3fC4b( x2, y, z2, c );
|
||||
vertices[index++] = new VertexP3fC4b( x2, y, z1, c );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,12 +25,12 @@ namespace ClassicalSharp.Selections {
|
|||
Vector3 p2 = (Vector3)Max + new Vector3( offset, offset, offset );
|
||||
int col = Colour.Pack();
|
||||
|
||||
YQuad( vertices, ref index, p1.X, p1.Z, p2.X, p2.Z, p1.Y, col ); // bottom
|
||||
YQuad( vertices, ref index, p1.X, p1.Z, p2.X, p2.Z, p2.Y, col ); // top
|
||||
XQuad( vertices, ref index, p1.X, p1.Y, p2.X, p2.Y, p1.Z, col ); // sides
|
||||
XQuad( vertices, ref index, p1.X, p1.Y, p2.X, p2.Y, p2.Z, col );
|
||||
ZQuad( vertices, ref index, p1.Z, p1.Y, p2.Z, p2.Y, p1.X, col );
|
||||
ZQuad( vertices, ref index, p1.Z, p1.Y, p2.Z, p2.Y, p2.X, col );
|
||||
HorQuad( vertices, ref index, col, p1.X, p1.Z, p2.X, p2.Z, p1.Y ); // bottom
|
||||
HorQuad( vertices, ref index, col, p1.X, p1.Z, p2.X, p2.Z, p2.Y ); // top
|
||||
VerQuad( vertices, ref index, col, p1.X, p1.Y, p1.Z, p2.X, p2.Y, p1.Z ); // sides
|
||||
VerQuad( vertices, ref index, col, p1.X, p1.Y, p2.Z, p2.X, p2.Y, p2.Z );
|
||||
VerQuad( vertices, ref index, col, p1.X, p1.Y, p1.Z, p1.X, p2.Y, p2.Z );
|
||||
VerQuad( vertices, ref index, col, p2.X, p1.Y, p1.Z, p2.X, p2.Y, p2.Z );
|
||||
|
||||
col = new FastColour( (byte)~Colour.R, (byte)~Colour.G, (byte)~Colour.B ).Pack();
|
||||
// bottom face
|
||||
|
@ -50,24 +50,16 @@ namespace ClassicalSharp.Selections {
|
|||
Line( lineVertices, ref lineIndex, p1.X, p1.Y, p2.Z, p1.X, p2.Y, p2.Z, col );
|
||||
}
|
||||
|
||||
static void ZQuad( VertexP3fC4b[] vertices, ref int index, float z1, float y1,
|
||||
float z2, float y2, float x, int col ) {
|
||||
vertices[index++] = new VertexP3fC4b( x, y1, z1, col );
|
||||
vertices[index++] = new VertexP3fC4b( x, y2, z1, col );
|
||||
vertices[index++] = new VertexP3fC4b( x, y2, z2, col );
|
||||
vertices[index++] = new VertexP3fC4b( x, y1, z2, col );
|
||||
internal static void VerQuad( VertexP3fC4b[] vertices, ref int index, int col,
|
||||
float x1, float y1, float z1, float x2, float y2, float z2 ) {
|
||||
vertices[index++] = new VertexP3fC4b( x1, y1, z1, col );
|
||||
vertices[index++] = new VertexP3fC4b( x1, y2, z1, col );
|
||||
vertices[index++] = new VertexP3fC4b( x2, y2, z2, col );
|
||||
vertices[index++] = new VertexP3fC4b( x2, y1, z2, col );
|
||||
}
|
||||
|
||||
static void XQuad( VertexP3fC4b[] vertices, ref int index, float x1, float y1,
|
||||
float x2, float y2, float z, int col ) {
|
||||
vertices[index++] = new VertexP3fC4b( x1, y1, z, col );
|
||||
vertices[index++] = new VertexP3fC4b( x1, y2, z, col );
|
||||
vertices[index++] = new VertexP3fC4b( x2, y2, z, col );
|
||||
vertices[index++] = new VertexP3fC4b( x2, y1, z, col );
|
||||
}
|
||||
|
||||
static void YQuad( VertexP3fC4b[] vertices, ref int index, float x1, float z1,
|
||||
float x2, float z2, float y, int col ) {
|
||||
internal static void HorQuad( VertexP3fC4b[] vertices, ref int index, int col,
|
||||
float x1, float z1, float x2, float z2, float y ) {
|
||||
vertices[index++] = new VertexP3fC4b( x1, y, z1, col );
|
||||
vertices[index++] = new VertexP3fC4b( x1, y, z2, col );
|
||||
vertices[index++] = new VertexP3fC4b( x2, y, z2, col );
|
||||
|
|
Loading…
Reference in a new issue