在java3d中画线

发布于 2024-10-15 10:29:09 字数 94 浏览 2 评论 0原文

我想在 java 3d 中画一条线来指定点。

我该怎么做?

例如,为了绘制一个立方体,我们编写 colorcube。

请帮我。

I want draw a line between to specify point in java 3d.

how can i do it?

for example for draw a cube we write colorcube.

please help me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

孤凫 2024-10-22 10:29:09

使用LineArray 类。为其创建一个具有两个顶点的对象(无论您希望它们在哪里),并将其添加到 Shape3D 对象。即 new Shape3D(lineArr)
对于线阵列:

LineArray lineArr=new LineArray(2,LineArray.COORDINATES);

然后:

lineArr.setCoordinate(0,new Point3f());...

对另一个顶点执行相同的操作。

然后将 shape3D 对象添加到场景图或 Branchgroup 中。

那应该可以解决问题。

Use the LineArray class. Create an object for it with two vertices( wherever you want them to be) and add this to a Shape3D object.i.e. new Shape3D(lineArr).
For line array:

LineArray lineArr=new LineArray(2,LineArray.COORDINATES);

then:

lineArr.setCoordinate(0,new Point3f());...

do the same for the other vertex.

Then add the shape3D object to a scene graph or Branchgroup.

That should do the trick.

乖乖 2024-10-22 10:29:09

这篇文章可能对您有帮助: 如何用Java3D画线[java-tips.org]

梦里兽 2024-10-22 10:29:09

下面的 Java 代码可以在 3D 屏幕上生成线条:

首先,构建一个主类(即:tuval1),然后构建一个公共类(即 tuval7),如下所示。

另请参阅此链接:http://www.itk356/java3d/geometry.htm#3.4.2" itk.ilstu.edu/faculty/javila/ITk356/Java3D/geometry.htm#3.4.2 点* 类:

import javax.media.j3d.Appearance;

import javax.media.j3d.BranchGroup;

import javax.media.j3d.GeometryArray;

import javax.media.j3d.LineStripArray;

import javax.media.j3d.Shape3D;

import javax.vecmath.Point3d;

import com.sun.j3d.utils.universe.SimpleUniverse;


public class tuval7 {

    public tuval7(){

     SimpleUniverse u=new SimpleUniverse(); 

    BranchGroup group=new BranchGroup();

    Point3d coords[] = new Point3d[4];

Appearance app=new Appearance();

     coords[0] = new Point3d(-0.5d, -0.2d, 0.1d);
     coords[1] = new Point3d(-0.2d, 0.1d, 0.0d);
     coords[2] = new Point3d(0.2d, -0.3d, 0.1d);
     coords[3] = new Point3d(0.3d, 0.5d, 0.10d);

     int vertexCounts[] = {4};

     LineStripArray lines = new LineStripArray(4,
     GeometryArray.COORDINATES, vertexCounts);

     lines.setCoordinates(0, coords);

    Shape3D shape=new Shape3D(lines , app);

    group.addChild(shape);

    u.addBranchGraph(group);

    u.getViewingPlatform().setNominalViewingTransform();

    }

}

public class tuval1 {

    public static void main(String[] args) {

        // TODO Auto-generated method stub

new tuval7();
    }

}

The Java code below can generate lines on your 3D screen:

First, build a main class (i.e :tuval1) and second a public class (i.e tuval7) as below.

Also see this link: http://www.itk.ilstu.edu/faculty/javila/ITk356/Java3D/geometry.htm#3.4.2 Point* Classes:

import javax.media.j3d.Appearance;

import javax.media.j3d.BranchGroup;

import javax.media.j3d.GeometryArray;

import javax.media.j3d.LineStripArray;

import javax.media.j3d.Shape3D;

import javax.vecmath.Point3d;

import com.sun.j3d.utils.universe.SimpleUniverse;


public class tuval7 {

    public tuval7(){

     SimpleUniverse u=new SimpleUniverse(); 

    BranchGroup group=new BranchGroup();

    Point3d coords[] = new Point3d[4];

Appearance app=new Appearance();

     coords[0] = new Point3d(-0.5d, -0.2d, 0.1d);
     coords[1] = new Point3d(-0.2d, 0.1d, 0.0d);
     coords[2] = new Point3d(0.2d, -0.3d, 0.1d);
     coords[3] = new Point3d(0.3d, 0.5d, 0.10d);

     int vertexCounts[] = {4};

     LineStripArray lines = new LineStripArray(4,
     GeometryArray.COORDINATES, vertexCounts);

     lines.setCoordinates(0, coords);

    Shape3D shape=new Shape3D(lines , app);

    group.addChild(shape);

    u.addBranchGraph(group);

    u.getViewingPlatform().setNominalViewingTransform();

    }

}

public class tuval1 {

    public static void main(String[] args) {

        // TODO Auto-generated method stub

new tuval7();
    }

}
榕城若虚 2024-10-22 10:29:09

这对我有用,它绘制了 x 轴:

LineArray lineX = new LineArray(2, LineArray.COORDINATES);
lineX.setCoordinate(0, new Point3f(-100.0f, 0.0f, 0.0f));
lineX.setCoordinate(1, new Point3f(100.0f, 0.0f, 0.0f));
scene.addChild(new Shape3D(lineX));

可以像这样绘制彩色线

Appearance appearanceGreen = new Appearance();
ColoringAttributes coloringAttributesGreen = new ColoringAttributes();
coloringAttributesGreen.setColor(new Color3f(Color.green));
appearanceGreen.setColoringAttributes(coloringAttributesGreen);
Shape3D shapeLine = new Shape3D(lineX, appearanceGreen);
scene.addChild(shapeLine);

This worked for me it draws the x-axis:

LineArray lineX = new LineArray(2, LineArray.COORDINATES);
lineX.setCoordinate(0, new Point3f(-100.0f, 0.0f, 0.0f));
lineX.setCoordinate(1, new Point3f(100.0f, 0.0f, 0.0f));
scene.addChild(new Shape3D(lineX));

a colored line can be drawn like this

Appearance appearanceGreen = new Appearance();
ColoringAttributes coloringAttributesGreen = new ColoringAttributes();
coloringAttributesGreen.setColor(new Color3f(Color.green));
appearanceGreen.setColoringAttributes(coloringAttributesGreen);
Shape3D shapeLine = new Shape3D(lineX, appearanceGreen);
scene.addChild(shapeLine);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文