/// <summary> /// Draw a 2d arrow. This function can be wrapped by ImmBegin()/ImmEnd(), /// if you need to draw several arrows but want to limit the number of /// draw calls. Each arrow consumes at most 9 vertices. /// </summary> /// <param name="start_point">Arrow's start point.</param> /// <param name="end_point">Arrow's tip.</param> /// <param name="ap">Arrow geometry parameters.</param> public void DrawArrow( Vector2 start_point, Vector2 end_point, ArrowParams ap ) { Vector2 x = end_point - start_point; Vector2 x1 = x.Normalize(); Vector2 y1 = Math.Perp( x1 ); start_point += y1 * ap.Offset; end_point += y1 * ap.Offset; ap.BodyRadius *= ap.Scale; ap.HeadRadius *= ap.Scale; ap.HeadLen *= ap.Scale; float r2p = ap.HeadRadius; float r2n = ap.HeadRadius; float r1p = ap.BodyRadius; float r1n = ap.BodyRadius; if ( ( ap.HalfMask & 1 ) == 0 ) { r2n=0.0f; r1n=0.0f; } if ( ( ap.HalfMask & 2 ) == 0 ) { r2p=0.0f; r1p=0.0f; } ShaderPush(); bool imm_was_active = m_imm.ImmActive; if ( ap.BodyRadius == 0.0f && !imm_was_active ) { ImmBegin( DrawMode.Lines, 2 ); ImmVertex( start_point ); ImmVertex( end_point ); ImmEnd(); } if ( !imm_was_active ) ImmBegin( DrawMode.Triangles, 9 ); if ( ap.BodyRadius != 0.0f ) { Vector2 p01 = start_point + r1p * y1; Vector2 p00 = start_point - r1n * y1; Vector2 p11 = end_point - x1 * ap.HeadLen + r1p * y1; Vector2 p10 = end_point - x1 * ap.HeadLen - r1n * y1; ImmVertex( p01 ); ImmVertex( p00 ); ImmVertex( p11 ); ImmVertex( p00 ); ImmVertex( p10 ); ImmVertex( p11 ); } ImmVertex( end_point - x1 * ap.HeadLen - r2n * y1 ); ImmVertex( end_point ); ImmVertex( end_point - x1 * ap.HeadLen + r2p * y1 ); if ( !imm_was_active ) ImmEnd(); ShaderPop(); }
/// <summary> /// Draw the coordinate system represented by a transformation matrix /// using arrows. The x vector is represented by a red arrow, and the y /// vector is represented by a green arrow. /// </summary> public void DrawCoordinateSystem2D( Matrix3 mat, ArrowParams ap = null ) { if ( ap == null ) ap = new ArrowParams(); ShaderPush(); ImmBegin( DrawMode.Triangles, 9 * 2 ); SetColor( Colors.Red ); DrawArrow( mat.Z.Xy, mat.Z.Xy + mat.X.Xy, ap ); SetColor( Colors.Green ); DrawArrow( mat.Z.Xy, mat.Z.Xy + mat.Y.Xy, ap ); ImmEnd(); ShaderPop(); }