public Wall( Maze maze, Line2 line, float height, Texture2D texture ) { Maze = maze; Line = line; Height = height; Texture = texture; SetUpVertices( line, height ); }
private void SetUpVertices( Line2 line, float height ) { Vector3[] vertex = new Vector3[ 6 ]; // top left vertex[ 0 ] = new Vector3( line.X0, height, line.Y0 ); // bottom left vertex[ 1 ] = new Vector3( line.X0, 0, line.Y0 ); // top right vertex[ 2 ] = new Vector3( line.X1, height, line.Y1 ); // bottom left vertex[ 3 ] = new Vector3( line.X0, 0, line.Y0 ); // bottom right vertex[ 4 ] = new Vector3( line.X1, 0, line.Y1 ); // top right vertex[ 5 ] = new Vector3( line.X1, height, line.Y1 ); Vector2 texTopLeft = Vector2.Zero; Vector2 texTopRight = Vector2.UnitX; Vector2 texBottomLeft = Vector2.UnitY; Vector2 texBottomRight = Vector2.One; Vector3 normal = Vector3.Cross( new Vector3( line.Direction.X, 0, line.Direction.Y ), Vector3.UnitY ); Color color = Color.White; mVertexData[ 0 ] = new VertexPositionNormalColorTexture( vertex[ 0 ], normal, color, texTopLeft ); mVertexData[ 1 ] = new VertexPositionNormalColorTexture( vertex[ 1 ], normal, color, texBottomLeft ); mVertexData[ 2 ] = new VertexPositionNormalColorTexture( vertex[ 2 ], normal, color, texTopRight ); mVertexData[ 3 ] = new VertexPositionNormalColorTexture( vertex[ 3 ], normal, color, texBottomLeft ); mVertexData[ 4 ] = new VertexPositionNormalColorTexture( vertex[ 4 ], normal, color, texBottomRight ); mVertexData[ 5 ] = new VertexPositionNormalColorTexture( vertex[ 5 ], normal, color, texTopRight ); }
public void Reverse( out Line2 outLine ) { outLine.P0 = P1; outLine.P1 = P0; }
public Vector2? Intersection( Line2 l ) { var p = P0; var r = P1 - P0; var q = l.P0; var s = l.P1 - l.P0; var qp_s = (float) Math.Round( Utils.Cross( q - p, s ), 3 ); var qp_r = (float) Math.Round( Utils.Cross( q - p, r ), 3 ); var r_s = (float) Math.Round( Utils.Cross( r, s ), 3 ); float t = qp_s / r_s; float u = qp_r / r_s; if ( r_s == 0 ) { if ( qp_r == 0 ) { var t0 = Vector2.Dot( q - p, r ) / Vector2.Dot( r, r ); var t1 = t0 + Vector2.Dot( s, r ) / Vector2.Dot( r, r ); if ( Vector2.Dot( s, r ) >= 0 ) { if ( t0 <= 1 && t1 >= 0 ) return q; } else if ( t1 <= 1 && t0 >= 0 ) { return q; } } else { return null; } } else if ( (0 <= t && t <= 1) && (0 <= u && u <= 1) ) { return p + t*r; } return null; }