- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在经历这个tutorial
每当我的鼠标悬停在用这个 code 创建的立方体上时(下面是我的版本),大气层和星星消失了。
正常情况下是这样的:
这是我将鼠标悬停在立方体上时的样子(看看大气层):
我不确定这里发生了什么。
/*
* Copyright (C) 2012 United States Government as represented by the Administrator of the
* National Aeronautics and Space Administration.
* All Rights Reserved.
*/
package gov.nasa.worldwindx.examples.tutorial;
import gov.nasa.worldwind.Configuration;
import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.geom.*;
import gov.nasa.worldwind.layers.RenderableLayer;
import gov.nasa.worldwind.pick.PickSupport;
import gov.nasa.worldwind.render.*;
import gov.nasa.worldwind.util.OGLUtil;
import gov.nasa.worldwindx.examples.ApplicationTemplate;
import javax.media.opengl.*;
import java.awt.*;
/**
* Example of a custom {@link Renderable} that draws a cube at a geographic position. This class shows the simplest
* possible example of a custom Renderable, while still following World Wind best practices. See
* http://goworldwind.org/developers-guide/how-to-build-a-custom-renderable/ for a complete description of this
* example.
*
* @author pabercrombie
* @version $Id: Cube.java 691 2012-07-12 19:17:17Z pabercrombie $
*/
public class Cube extends ApplicationTemplate implements Renderable
{
/** Geographic position of the cube. */
protected Position position;
/** Length of each face, in meters. */
protected double size;
/** Support object to help with pick resolution. */
protected PickSupport pickSupport = new PickSupport();
// Determined each frame
protected long frameTimestamp = -1L;
protected OrderedCube currentFramesOrderedCube;
/**
* This class holds the Cube's Cartesian coordinates. An instance of it is added to the scene controller's ordered
* renderable queue during picking and rendering.
*/
protected class OrderedCube implements OrderedRenderable
{
/** Cartesian position of the cube, computed from
* {@link gov.nasa.worldwindx.examples.tutorial.Cube#position}. */
protected Vec4 placePoint;
/** Distance from the eye point to the cube. */
protected double eyeDistance;
/**
* The cube's Cartesian bounding extent.
*/
protected Extent extent;
public double getDistanceFromEye()
{
return this.eyeDistance;
}
public void pick(DrawContext dc, Point pickPoint)
{
// Use same code for rendering and picking.
this.render(dc);
}
public void render(DrawContext dc)
{
Cube.this.drawOrderedRenderable(dc, Cube.this.pickSupport);
}
}
public Cube(Position position, double sizeInMeters)
{
this.position = position;
this.size = sizeInMeters;
}
public void render(DrawContext dc)
{
// Render is called twice, once for picking and once for rendering. In both cases an OrderedCube is added to
// the ordered renderable queue.
OrderedCube orderedCube = this.makeOrderedRenderable(dc);
if (orderedCube.extent != null)
{
if (!this.intersectsFrustum(dc, orderedCube))
return;
// If the shape is less that a pixel in size, don't render it.
if (dc.isSmall(orderedCube.extent, 1))
return;
}
// Add the cube to the ordered renderable queue. The SceneController sorts the ordered renderables by eye
// distance, and then renders them back to front.
dc.addOrderedRenderable(orderedCube);
}
/**
* Determines whether the cube intersects the view frustum.
*
* @param dc the current draw context.
*
* @return true if this cube intersects the frustum, otherwise false.
*/
protected boolean intersectsFrustum(DrawContext dc, OrderedCube orderedCube)
{
if (dc.isPickingMode())
return dc.getPickFrustums().intersectsAny(orderedCube.extent);
return dc.getView().getFrustumInModelCoordinates().intersects(orderedCube.extent);
}
/**
* Compute per-frame attributes, and add the ordered renderable to the ordered renderable list.
*
* @param dc Current draw context.
*/
protected OrderedCube makeOrderedRenderable(DrawContext dc)
{
// This method is called twice each frame: once during picking and once during rendering. We only need to
// compute the placePoint, eye distance and extent once per frame, so check the frame timestamp to see if
// this is a new frame. However, we can't use this optimization for 2D continuous globes because the
// Cartesian coordinates of the cube are different for each 2D globe drawn during the current frame.
if (dc.getFrameTimeStamp() != this.frameTimestamp || dc.isContinuous2DGlobe())
{
OrderedCube orderedCube = new OrderedCube();
// Convert the cube's geographic position to a position in Cartesian coordinates. If drawing to a 2D
// globe ignore the shape's altitude.
if (dc.is2DGlobe())
{
orderedCube.placePoint = dc.getGlobe().computePointFromPosition(this.position.getLatitude(),
this.position.getLongitude(), 0);
}
else
{
orderedCube.placePoint = dc.getGlobe().computePointFromPosition(this.position);
}
// Compute the distance from the eye to the cube's position.
orderedCube.eyeDistance = dc.getView().getEyePoint().distanceTo3(orderedCube.placePoint);
// Compute a sphere that encloses the cube. We'll use this sphere for intersection calculations to determine
// if the cube is actually visible.
orderedCube.extent = new Sphere(orderedCube.placePoint, Math.sqrt(3.0) * this.size / 2.0);
// Keep track of the timestamp we used to compute the ordered renderable.
this.frameTimestamp = dc.getFrameTimeStamp();
this.currentFramesOrderedCube = orderedCube;
return orderedCube;
}
else
{
return this.currentFramesOrderedCube;
}
}
/**
* Set up drawing state, and draw the cube. This method is called when the cube is rendered in ordered rendering
* mode.
*
* @param dc Current draw context.
*/
protected void drawOrderedRenderable(DrawContext dc, PickSupport pickCandidates)
{
this.beginDrawing(dc);
try
{
GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.
if (dc.isPickingMode())
{
Color pickColor = dc.getUniquePickColor();
pickCandidates.addPickableObject(pickColor.getRGB(), this, this.position);
gl.glColor3ub((byte) pickColor.getRed(), (byte) pickColor.getGreen(), (byte) pickColor.getBlue());
}
// Render a unit cube and apply a scaling factor to scale the cube to the appropriate size.
gl.glScaled(this.size, this.size, this.size);
this.drawUnitCube(dc);
}
finally
{
this.endDrawing(dc);
}
}
/**
* Setup drawing state in preparation for drawing the cube. State changed by this method must be restored in
* endDrawing.
*
* @param dc Active draw context.
*/
protected void beginDrawing(DrawContext dc)
{
GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.
int attrMask = GL2.GL_CURRENT_BIT | GL2.GL_COLOR_BUFFER_BIT;
gl.glPushAttrib(attrMask);
if (!dc.isPickingMode())
{
dc.beginStandardLighting();
gl.glEnable(GL.GL_BLEND);
OGLUtil.applyBlending(gl, false);
// Were applying a scale transform on the modelview matrix, so the normal vectors must be re-normalized
// before lighting is computed.
gl.glEnable(GL2.GL_NORMALIZE);
}
// Multiply the modelview matrix by a surface orientation matrix to set up a local coordinate system with the
// origin at the cube's center position, the Y axis pointing North, the X axis pointing East, and the Z axis
// normal to the globe.
gl.glMatrixMode(GL2.GL_MODELVIEW);
Matrix matrix = dc.getGlobe().computeSurfaceOrientationAtPosition(this.position);
matrix = dc.getView().getModelviewMatrix().multiply(matrix);
double[] matrixArray = new double[16];
matrix.toArray(matrixArray, 0, false);
gl.glLoadMatrixd(matrixArray, 0);
}
/**
* Restore drawing state changed in beginDrawing to the default.
*
* @param dc Active draw context.
*/
protected void endDrawing(DrawContext dc)
{
GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.
if (!dc.isPickingMode())
dc.endStandardLighting();
gl.glPopAttrib();
}
/**
* Draw a unit cube, using the active modelview matrix to orient the shape.
*
* @param dc Current draw context.
*/
protected void drawUnitCube(DrawContext dc)
{
// Vertices of a unit cube, centered on the origin.
float[][] v = {{-0.5f, 0.5f, -0.5f}, {-0.5f, 0.5f, 0.5f}, {0.5f, 0.5f, 0.5f}, {0.5f, 0.5f, -0.5f},
{-0.5f, -0.5f, 0.5f}, {0.5f, -0.5f, 0.5f}, {0.5f, -0.5f, -0.5f}, {-0.5f, -0.5f, -0.5f}};
// Array to group vertices into faces
int[][] faces = {{0, 1, 2, 3}, {2, 5, 6, 3}, {1, 4, 5, 2}, {0, 7, 4, 1}, {0, 7, 6, 3}, {4, 7, 6, 5}};
// Normal vectors for each face
float[][] n = {{0, 1, 0}, {1, 0, 0}, {0, 0, 1}, {-1, 0, 0}, {0, 0, -1}, {0, -1, 0}};
// Note: draw the cube in OpenGL immediate mode for simplicity. Real applications should use vertex arrays
// or vertex buffer objects to achieve better performance.
GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.
gl.glBegin(GL2.GL_QUADS);
try
{
for (int i = 0; i < faces.length; i++)
{
gl.glNormal3f(n[i][0], n[i][1], n[i][2]);
for (int j = 0; j < faces[0].length; j++)
{
gl.glVertex3f(v[faces[i][j]][0], v[faces[i][j]][1], v[faces[i][j]][2]);
}
}
}
finally
{
gl.glEnd();
}
}
protected static class AppFrame extends ApplicationTemplate.AppFrame
{
public AppFrame()
{
super(true, true, false);
RenderableLayer layer = new RenderableLayer();
Cube cube = new Cube(Position.fromDegrees(35.0, -120.0, 3000), 100000);
layer.addRenderable(cube);
getWwd().getModel().getLayers().add(layer);
}
}
public static void main(String[] args)
{
Configuration.setValue(AVKey.INITIAL_LATITUDE, 35.0);
Configuration.setValue(AVKey.INITIAL_LONGITUDE, -120.0);
Configuration.setValue(AVKey.INITIAL_ALTITUDE, 2550000);
Configuration.setValue(AVKey.INITIAL_PITCH, 45);
Configuration.setValue(AVKey.INITIAL_HEADING, 45);
ApplicationTemplate.start("World Wind Custom Renderable Tutorial", AppFrame.class);
}
}
最佳答案
我已经重现了这个问题,包括在 worldwind.jar
中的教程 Cube
类和你的 Cube
类有用的更大的立方体。
我已经追踪到大气层消失的点是当 GLCanvas
的隐藏缓冲区在 WorldWind 渲染代码中被交换时,所以问题是由于某种原因大气层和星星层是在使用您的代码以拾取模式呈现期间未在隐藏缓冲区上绘制。
然后我发现包含圆柱体的示例作为 gov.nasa.worldwindx.examples.Cylinders.class
在地球上绘制了可拾取的 3D 形状(圆柱体)并且没有出现此问题(有其他 - 例如 Boxes
非常接近本教程)。
我认为问题在于本教程示例中 OrderedRenderable
的实现 - 在 Cylinders 示例中,实际的 Cylinder 类扩展了 RigidShape
,后者又扩展了 AbstractShape
,也就是实际实现OrderedRenderable
的类。这绝对是一个错误。也许您可以从 Boxes
示例开始工作以获得您需要的功能。
关于java - Worldwind 自定义可渲染拾取问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36698801/
我正在编写一个具有以下签名的 Java 方法。 void Logger(Method method, Object[] args); 如果一个方法(例如 ABC() )调用此方法 Logger,它应该
我是 Java 新手。 我的问题是我的 Java 程序找不到我试图用作的图像文件一个 JButton。 (目前这段代码什么也没做,因为我只是得到了想要的外观第一的)。这是我的主课 代码: packag
好的,今天我在接受采访,我已经编写 Java 代码多年了。采访中说“Java 垃圾收集是一个棘手的问题,我有几个 friend 一直在努力弄清楚。你在这方面做得怎么样?”。她是想骗我吗?还是我的一生都
我的 friend 给了我一个谜语让我解开。它是这样的: There are 100 people. Each one of them, in his turn, does the following
如果我将使用 Java 5 代码的应用程序编译成字节码,生成的 .class 文件是否能够在 Java 1.4 下运行? 如果后者可以工作并且我正在尝试在我的 Java 1.4 应用程序中使用 Jav
有关于why Java doesn't support unsigned types的问题以及一些关于处理无符号类型的问题。我做了一些搜索,似乎 Scala 也不支持无符号数据类型。限制是Java和S
我只是想知道在一个 java 版本中生成的字节码是否可以在其他 java 版本上运行 最佳答案 通常,字节码无需修改即可在 较新 版本的 Java 上运行。它不会在旧版本上运行,除非您使用特殊参数 (
我有一个关于在命令提示符下执行 java 程序的基本问题。 在某些机器上我们需要指定 -cp 。 (类路径)同时执行java程序 (test为java文件名与.class文件存在于同一目录下) jav
我已经阅读 StackOverflow 有一段时间了,现在我才鼓起勇气提出问题。我今年 20 岁,目前在我的家乡(罗马尼亚克卢日-纳波卡)就读 IT 大学。足以介绍:D。 基本上,我有一家提供簿记应用
我有 public JSONObject parseXML(String xml) { JSONObject jsonObject = XML.toJSONObject(xml); r
我已经在 Java 中实现了带有动态类型的简单解释语言。不幸的是我遇到了以下问题。测试时如下代码: def main() { def ks = Map[[1, 2]].keySet()
一直提示输入 1 到 10 的数字 - 结果应将 st、rd、th 和 nd 添加到数字中。编写一个程序,提示用户输入 1 到 10 之间的任意整数,然后以序数形式显示该整数并附加后缀。 public
我有这个 DownloadFile.java 并按预期下载该文件: import java.io.*; import java.net.URL; public class DownloadFile {
我想在 GUI 上添加延迟。我放置了 2 个 for 循环,然后重新绘制了一个标签,但这 2 个 for 循环一个接一个地执行,并且标签被重新绘制到最后一个。 我能做什么? for(int i=0;
我正在对对象 Student 的列表项进行一些测试,但是我更喜欢在 java 类对象中创建硬编码列表,然后从那里提取数据,而不是连接到数据库并在结果集中选择记录。然而,自从我这样做以来已经很长时间了,
我知道对象创建分为三个部分: 声明 实例化 初始化 classA{} classB extends classA{} classA obj = new classB(1,1); 实例化 它必须使用
我有兴趣使用 GPRS 构建车辆跟踪系统。但是,我有一些问题要问以前做过此操作的人: GPRS 是最好的技术吗?人们意识到任何问题吗? 我计划使用 Java/Java EE - 有更好的技术吗? 如果
我可以通过递归方法反转数组,例如:数组={1,2,3,4,5} 数组结果={5,4,3,2,1}但我的结果是相同的数组,我不知道为什么,请帮助我。 public class Recursion { p
有这样的标准方式吗? 包括 Java源代码-测试代码- Ant 或 Maven联合单元持续集成(可能是巡航控制)ClearCase 版本控制工具部署到应用服务器 最后我希望有一个自动构建和集成环境。
我什至不知道这是否可能,我非常怀疑它是否可能,但如果可以,您能告诉我怎么做吗?我只是想知道如何从打印机打印一些文本。 有什么想法吗? 最佳答案 这里有更简单的事情。 import javax.swin
我是一名优秀的程序员,十分优秀!