4

有向グラフの表示に使用される「Walrus」と呼ばれるJava3Dアプリケーションを使用しています。このコードには、ノードを強調表示し、画面座標を指定してグラフに隣接するラベルを描画する機能がすでにあります。

画面を回転すると、ノードは強調表示されなくなります。

私が持っているのは、3Dのノード座標です。それにラベルを描く必要があります。

3D座標を使用したハイライトのコード

Point3d p = new Point3d();
m_graph.getNodeCoordinates(node, p);

PointArray array = new PointArray(1, PointArray.COORDINATES);
array.setCoordinate(0, p);
m_parameters.putModelTransform(gc);
gc.setAppearance(m_parameters.getPickAppearance());
  1. 3D座標でラベルを描画するにはどうすればよいですか(ラスターグラフィックスはエラーレンダラーをスローします:即時モードCanvas3Dグラフィックスコンテキストの作成中にエラーが発生します)

  2. 3D座標を2D画面に変換し、既存のコードを使用して2D画面ポイントにラベルを描画するにはどうすればよいですか?

ありがとう、

ダクシナ

4

3 に答える 3

1

パラメータを使用して変換[x,y,z]するためのアルゴリズム/方法が[x,y]あります。depth

x値は次のとおりです。(int) (x - (z / depth * x))

y値は次のとおりです。(int) (y - (z / depth * y))

本質的に、深さは焦点です。消失点は になります[0,0,depth]

于 2015-08-24T02:58:11.617 に答える
0

これは、3D座標を透視2Dに変換するために使用したものです。x2とy2は2次元座標で、xyzは3D座標です。

次の式を使用します。

x2 = cos(30)*x - cos(30)*y

y2 = sin(30)*x + sin(30)*y + z

角度 30 を選んだのは、30 度を選んだのは、2D 用紙に 3D を描画するためのアイソメトリック グリッドでも使用されている遠近法の目的に適しているからです。z 軸は垂直軸になるため、x と y は左右から 60 度の軸になります。アイソ メトリック グリッド画像。

私はまだ回転に取り組んでいますが、軸を変更せずに、3D で回転を調整するだけです。楽しみ。

于 2013-05-07T20:02:39.637 に答える
-1

私は解決策を見つけました。画像2D座標でText3Dを表示する機能です

public void drawLabel(GraphicsContext3D gc, double x, double y, int zOffset, String s) {
boolean frontBufferRenderingState = gc.getFrontBufferRendering();
gc.setBufferOverride(true);
gc.setFrontBufferRendering(true);
Point3d eye = getEye();
double labelZ = zOffset * LABEL_Z_OFFSET_SCALE
+ LABEL_Z_SCALE * eye.z + LABEL_Z_OFFSET;

double xOffset = LABEL_X_OFFSET * m_pixelToMeterScale;
double yOffset = LABEL_Y_OFFSET * m_pixelToMeterScale;
Point3d p = new Point3d(x + xOffset, y + yOffset, 0.0);
{

// Project given (x, y) coordinates to the plane z=labelZ.

// Convert from image-plate to eye coordinates.
p.x -= eye.x;
p.y -= eye.y;

double inversePerspectiveScale = 1.0 - labelZ / eye.z;
p.x *= inversePerspectiveScale;
p.y *= inversePerspectiveScale;

// Convert from eye to image-plate coordinates.
p.x += eye.x;
p.y += eye.y;

}

Transform3D scale = new Transform3D();
scale.set(LABEL_SCALE);

Vector3d t = new Vector3d(p.x, p.y, labelZ);
Transform3D translation = new Transform3D();
translation.set(t);
translation.mul(scale);

Transform3D transform = new Transform3D(m_imageToVworld);
transform.mul(translation);

gc.setModelTransform(transform);

//-----------------
int fontSize=(int)(10*m_magnification);

if(fontSize>20)
fontSize=20;
//---------------

// XXX: Courier may not be available on all systems.
Text2D text = new Text2D(s, new Color3f(1.0f, 1.0f, 1.0f),
"Courier", fontSize, Font.BOLD);

gc.draw(text);

gc.flush(true);

// NOTE: Resetting the model transform here is very important.
// For some reason, not doing this causes the immediate
// following frame to render incorrectly (but subsequent
// frames will render correctly). In some ways, this
// makes sense, because most rendering code assumes that
// GraphicsContext3D has been set to some reasonable
// transform.
gc.setModelTransform(m_objectTransform);
gc.setFrontBufferRendering(frontBufferRenderingState);
}

これは、3D座標を取得し、それらを画像の2D座標に変換し、上記の関数を使用してレンダリングする関数です。

private boolean displayOnScreenLabel(int node, String label) {
boolean success = false;
try {
Transform3D transform = m_parameters.getObjectToEyeTransform();
Point3d nodeC = new Point3d();

m_graph.getNodeCoordinates(node, nodeC);
transform.transform(nodeC);

Point3d eye = m_parameters.getEye();

double perspectiveScale = 1.0 / (1.0 - nodeC.z / eye.z);

double centerX = eye.x + nodeC.x * perspectiveScale;
double centerY = eye.y + nodeC.y * perspectiveScale;

GraphicsContext3D gc = m_canvas.getGraphicsContext3D();

m_parameters.drawLabel(gc, centerX, centerY, m_labelZOffsetCounter++, label);

success = true;
} catch (final java.lang.OutOfMemoryError error) {
JOptionPane.showMessageDialog(m_frame, "The 3D Graphics is unable to find enough memory on your system. Kill the application!", "Out Of Memory!", JOptionPane.ERROR_MESSAGE);
} catch (Exception e) {
success = false;
}
return success;
}
于 2011-05-18T10:23:20.103 に答える