NASA Worldwind:我如何更改战术符号速度指示器的颜色?

10
在NASA WorldWind中,可以将“行进方向”的速度领导者分配给Milstd-2525符号。然而,这个速度领导者是黑色的,在深蓝色海洋背景下很难看到。我尝试过更改TacticalSymbolAttributes中的内部颜色材料,但似乎没有任何效果(对任何东西)。不幸的是,文档没有提供有关如何更改线条颜色的任何提示。
在Worldwind中,是否可能更改Milstd-2525 Tactical Symbol的速度领导者线的颜色?如果可以,如何操作?

你使用的是哪个版本的WorldWind?例如1.X,2.0,2.0-986,2.1。 - Igor
2.1.0. 我基本上一直跟着主 git 分支更新。 - stix
2个回答

5

github 上的 WorldWindJava 源代码 基础上,MilStd2525TacticalSymbol 类重写了名为 layoutDynamicModifiers 的方法。在这个方法中,你可以看到只有对于 DIRECTION_OF_MOVEMENT 最终调用了 addLine(...) 方法(该方法是在超类 AbstractTacticalSymbol 中实现的,它仅将一行添加到名为 currentLines 的列表中),并且只有可以设置 SPEED_LEADER_SCALE 和其他方向属性无法在外部更改。

@Override
protected void layoutDynamicModifiers(DrawContext dc, AVList modifiers, OrderedSymbol osym)
{
    this.currentLines.clear();

    if (!this.isShowGraphicModifiers())
        return;

    // Direction of Movement indicator. Placed either at the center of the icon or at the bottom of the symbol
    // layout.
    Object o = this.getModifier(SymbologyConstants.DIRECTION_OF_MOVEMENT);
    if (o != null && o instanceof Angle)
    {
        // The length of the direction of movement line is equal to the height of the symbol frame. See
        // MIL-STD-2525C section 5.3.4.1.c, page 33.
        double length = this.iconRect.getHeight();
        Object d = this.getModifier(SymbologyConstants.SPEED_LEADER_SCALE);
        if (d != null && d instanceof Number)
            length *= ((Number) d).doubleValue();

        if (this.useGroundHeadingIndicator)
        {
            List<? extends Point2D> points = MilStd2525Util.computeGroundHeadingIndicatorPoints(dc, osym.placePoint,
                (Angle) o, length, this.iconRect.getHeight());
            this.addLine(dc, Offset.BOTTOM_CENTER, points, LAYOUT_RELATIVE, points.size() - 1, osym);
        }
        else
        {
            List<? extends Point2D> points = MilStd2525Util.computeCenterHeadingIndicatorPoints(dc,
                osym.placePoint, (Angle) o, length);
            this.addLine(dc, Offset.CENTER, points, null, 0, osym);
        }
    }
}

在超类 AbstractTacticalSymbol 中,字段 currentLines(其中包含移动方向的线条)在名为 drawLines(...) 的方法中使用,该方法将添加的线条绘制到所提到的列表中(类的第2366行)。在第2364行中,可以看到颜色设置为黑色。
gl.glColor4f(0f, 0f, 0f, opacity.floatValue()); 

现在我建议您扩展 MilStd2525TacticalSymbol 并执行以下操作:

  1. 扩展类 AbstractTacticalSymbol.Line 并定义一些字段以存储颜色。
  2. 覆盖方法 layoutDynamicModifiers 并获取您自己的键(例如 DIRECTION_OF_MOVEMENT_COLOR)以从修饰符中获取颜色,并使用此给定的颜色创建您自己的线条并将其添加到 currentLines 列表中(您可以为此目的覆盖方法 addLine)。
  3. 最后,覆盖 drawLines 以在您自己的 Line 类中使用存储的颜色,并在绘制线条之前更改 gl 的颜色(您可以在绘制移动方向后将颜色改回黑色)。

1

我正在使用早期版本的Worldwind,但是请尝试查看AbstractTacticalSymbol.java文件中的drawLines()方法。

在绘制线条之前,它将glColor默认为黑色。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接