mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-23 09:34:35 -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;
|
VertexP3fC4b[] vertices;
|
||||||
int vb;
|
int vb;
|
||||||
Game game;
|
Game game;
|
||||||
|
const float size = 1/32f;
|
||||||
|
|
||||||
public void Init( Game game ) {
|
public void Init( Game game ) { this.game = game; }
|
||||||
this.game = game;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Ready( Game game ) { }
|
public void Ready( Game game ) { }
|
||||||
public void Reset( Game game ) { }
|
public void Reset( Game game ) { }
|
||||||
public void OnNewMap( Game game ) { }
|
public void OnNewMap( Game game ) { }
|
||||||
public void OnNewMapLoaded( 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 ) {
|
public void Render( double delta ) {
|
||||||
if( !game.ShowAxisLines ) return;
|
if( !game.ShowAxisLines ) return;
|
||||||
|
@ -31,33 +26,19 @@ namespace ClassicalSharp.Selections {
|
||||||
vb = game.Graphics.CreateDynamicVb( VertexFormat.P3fC4b, vertices.Length );
|
vb = game.Graphics.CreateDynamicVb( VertexFormat.P3fC4b, vertices.Length );
|
||||||
}
|
}
|
||||||
game.Graphics.Texturing = false;
|
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;
|
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 );
|
SelectionBox.HorQuad( vertices, ref index, FastColour.Red.Pack(),
|
||||||
HorQuad( ref index, pos.X - size, pos.Z, pos.X + size, pos.Z + 3, pos.Y, FastColour.Blue );
|
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 )
|
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.SetBatchFormat( VertexFormat.P3fC4b );
|
||||||
game.Graphics.UpdateDynamicIndexedVb( DrawMode.Triangles, vb, vertices, index, index * 6 / 4 );
|
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 );
|
Vector3 p2 = (Vector3)Max + new Vector3( offset, offset, offset );
|
||||||
int col = Colour.Pack();
|
int col = Colour.Pack();
|
||||||
|
|
||||||
YQuad( vertices, ref index, p1.X, p1.Z, p2.X, p2.Z, p1.Y, col ); // bottom
|
HorQuad( vertices, ref index, col, p1.X, p1.Z, p2.X, p2.Z, p1.Y ); // bottom
|
||||||
YQuad( vertices, ref index, p1.X, p1.Z, p2.X, p2.Z, p2.Y, col ); // top
|
HorQuad( vertices, ref index, col, p1.X, p1.Z, p2.X, p2.Z, p2.Y ); // top
|
||||||
XQuad( vertices, ref index, p1.X, p1.Y, p2.X, p2.Y, p1.Z, col ); // sides
|
VerQuad( vertices, ref index, col, p1.X, p1.Y, p1.Z, p2.X, p2.Y, p1.Z ); // sides
|
||||||
XQuad( vertices, ref index, p1.X, p1.Y, p2.X, p2.Y, p2.Z, col );
|
VerQuad( vertices, ref index, col, p1.X, p1.Y, p2.Z, p2.X, p2.Y, p2.Z );
|
||||||
ZQuad( vertices, ref index, p1.Z, p1.Y, p2.Z, p2.Y, p1.X, col );
|
VerQuad( vertices, ref index, col, p1.X, p1.Y, p1.Z, p1.X, p2.Y, p2.Z );
|
||||||
ZQuad( vertices, ref index, p1.Z, p1.Y, p2.Z, p2.Y, p2.X, col );
|
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();
|
col = new FastColour( (byte)~Colour.R, (byte)~Colour.G, (byte)~Colour.B ).Pack();
|
||||||
// bottom face
|
// 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 );
|
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,
|
internal static void VerQuad( VertexP3fC4b[] vertices, ref int index, int col,
|
||||||
float z2, float y2, float x, int col ) {
|
float x1, float y1, float z1, float x2, float y2, float z2 ) {
|
||||||
vertices[index++] = new VertexP3fC4b( x, y1, z1, col );
|
vertices[index++] = new VertexP3fC4b( x1, y1, z1, col );
|
||||||
vertices[index++] = new VertexP3fC4b( x, y2, z1, col );
|
vertices[index++] = new VertexP3fC4b( x1, y2, z1, col );
|
||||||
vertices[index++] = new VertexP3fC4b( x, y2, z2, col );
|
vertices[index++] = new VertexP3fC4b( x2, y2, z2, col );
|
||||||
vertices[index++] = new VertexP3fC4b( x, y1, z2, col );
|
vertices[index++] = new VertexP3fC4b( x2, y1, z2, col );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void XQuad( VertexP3fC4b[] vertices, ref int index, float x1, float y1,
|
internal static void HorQuad( VertexP3fC4b[] vertices, ref int index, int col,
|
||||||
float x2, float y2, float z, int col ) {
|
float x1, float z1, float x2, float z2, float y ) {
|
||||||
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 ) {
|
|
||||||
vertices[index++] = new VertexP3fC4b( x1, y, z1, col );
|
vertices[index++] = new VertexP3fC4b( x1, y, z1, col );
|
||||||
vertices[index++] = new VertexP3fC4b( x1, y, z2, col );
|
vertices[index++] = new VertexP3fC4b( x1, y, z2, col );
|
||||||
vertices[index++] = new VertexP3fC4b( x2, y, z2, col );
|
vertices[index++] = new VertexP3fC4b( x2, y, z2, col );
|
||||||
|
|
Loading…
Add table
Reference in a new issue