Skip to content

Commit

Permalink
辅助坐标系添加3D模式
Browse files Browse the repository at this point in the history
  • Loading branch information
GcsSloop committed Sep 4, 2016
1 parent 9f8361c commit 1358354
Showing 1 changed file with 64 additions and 10 deletions.
74 changes: 64 additions & 10 deletions Library/src/main/java/com/gcssloop/view/utils/CanvasAidUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ public class CanvasAidUtils {
private static int LEN_NX = 0;
private static int LEN_Y = 700;
private static int LEN_NY = 0;
private static int LEN_Z = 400;
private static int LEN_NZ = 0;

private static int LINE_WIDTH = 5;
private static int LINE_COLOR = Color.GRAY;

private static int Cap_Axis_Distance = 15;
private static int Cap_Head_Distance = 30;

private static Point XHead, XTail, YHead, YTail;
private static Point XCap1, XCap2, YCap1, YCap2;
private static Point XHead, XTail, YHead, YTail, ZHead, ZTail;
private static Point XCap1, XCap2, YCap1, YCap2, ZCap1, ZCap2;


private CanvasAidUtils() {
Expand All @@ -62,11 +64,12 @@ public static void setDrawAid(boolean isDraw) {

/**
* 标注为废弃
* @param lenX x坐标轴长度
* @param lenY y坐标轴长度
*
* @param lenX x坐标轴长度
* @param lenY y坐标轴长度
* @param lineWidth 坐标轴宽度
* @param lineColor 坐标轴颜色
* @deprecated 标注为废弃,后续版本中可能移除该方法,请使用 {@link #setCoordinateLen(int, int, int, int)}. {@link #setLineWidth(int)} 和 {@link #setLineColor(int)} 来代替.
* @deprecated 标注为废弃, 后续版本中可能移除该方法, 请使用 {@link #setCoordinateLen(int, int, int, int)}. {@link #setLineWidth(int)} 和 {@link #setLineColor(int)} 来代替.
*/
@Deprecated
public static void setStyle(int lenX, int lenY, int lineWidth, int lineColor) {
Expand All @@ -80,6 +83,7 @@ public static void setStyle(int lenX, int lenY, int lineWidth, int lineColor) {

/**
* 设置坐标轴长度
*
* @param lenX x坐标轴长度
* @param lenY y坐标轴长度
* @deprecated 被标记为删除, 后续版本中可能移除该方法, 请使用 {@link #setCoordinateLen(int, int, int, int)}代替
Expand All @@ -93,16 +97,36 @@ public static void setLen(int lenX, int lenY) {

/**
* 设置坐标轴长度
*
* @param lenX x正坐标轴长度.
* @param lenNX x负坐标轴长度.
* @param lenY y正坐标轴长度.
* @param lenNY y负坐标轴长度.
*/
public static void setCoordinateLen(int lenX, int lenNX, int lenY, int lenNY) {
LEN_X = lenX;
LEN_Y = lenY;
LEN_NX = lenNX;
LEN_NY = lenNY;
}

/**
* 设置3D坐标轴长度
*
* @param lenX x正坐标轴长度.
* @param lenNX x负坐标轴长度.
* @param lenY y正坐标轴长度.
* @param lenNY y负坐标轴长度.
* @param lenZ z正坐标轴长度.
* @param lenNZ z负坐标轴长度.
*/
public static void setCoordinateLen(int lenX, int lenNX, int lenY, int lenNY){
public static void set3DCoordinateLen(int lenX, int lenNX, int lenY, int lenNY, int lenZ, int lenNZ) {
LEN_X = lenX;
LEN_Y = lenY;
LEN_Z = lenZ;
LEN_NX = lenNX;
LEN_NY = lenNY;
LEN_NZ = lenNZ;
}

public static void setLineWidth(int lineWidth) {
Expand All @@ -116,8 +140,9 @@ public static void setLineColor(int lineColor) {
/**
* 绘制坐标系.
* 修复名称,标记为删除,可能在几个版本后移除该方法.
*
* @param canvas 画布
* @deprecated 被标记为删除,后续版本中可能移除该方法,请使用 {@link #drawCoordinateSpace(Canvas)}代替
* @deprecated 被标记为删除, 后续版本中可能移除该方法, 请使用 {@link #drawCoordinateSpace(Canvas)}代替
*/
@Deprecated
public static void drawCoordinateSystem(Canvas canvas) {
Expand All @@ -144,12 +169,10 @@ public static void drawCoordinateSystem(Canvas canvas) {

/**
* 绘制坐标空间.
*
* @param canvas 画布
*/
public static void drawCoordinateSpace(Canvas canvas) {
if (!isDrawAid) {
return;
}

initPaint();
initPoint();
Expand All @@ -167,6 +190,24 @@ public static void drawCoordinateSpace(Canvas canvas) {
canvas.restore();
}

/**
* 绘制3D坐标空间
*
* @param canvas 画布
*/
public static void draw3DCoordinateSpace(Canvas canvas) {

drawCoordinateSpace(canvas);

canvas.save();

CanvasUtils.drawLine(ZHead, ZTail, canvas, mPaint);
CanvasUtils.drawLine(ZHead, ZCap1, canvas, mPaint);
CanvasUtils.drawLine(ZHead, ZCap2, canvas, mPaint);

canvas.restore();
}

private static void initPaint() {
mPaint = new Paint();
mPaint.setAntiAlias(true);
Expand All @@ -187,5 +228,18 @@ private static void initPoint() {
YTail = new Point(0, -LEN_NY);
YCap1 = new Point(+Cap_Axis_Distance, LEN_Y - Cap_Head_Distance);
YCap2 = new Point(-Cap_Axis_Distance, LEN_Y - Cap_Head_Distance);

int zl = convert_3D_to_2D(LEN_Z);
int nzl = convert_3D_to_2D(LEN_NZ);
int CAD = convert_3D_to_2D(Cap_Axis_Distance);
int CHD = convert_3D_to_2D(Cap_Head_Distance);
ZHead = new Point(-zl, zl);
ZTail = new Point(nzl, -nzl);
ZCap1 = new Point(ZHead.x + CHD - CAD, ZHead.y - CHD - CAD);
ZCap2 = new Point(ZHead.x + CHD + CAD, ZHead.y - CHD + CAD);
}

private static int convert_3D_to_2D(int l) {
return l * 3 / 4;
}
}

0 comments on commit 1358354

Please sign in to comment.