java3d构造一个三棱柱模型

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java3d构造一个三棱柱模型相关的知识,希望对你有一定的参考价值。

package yhb;

import javax.vecmath.*;

import java.awt.*;
import java.awt.event.*;
import java.net.*;

import javax.media.j3d.*;

import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.image.*;

import java.applet.*;
import com.sun.j3d.utils.applet.MainFrame;

public class building extends Applet

public static void main(String[] args)

new MainFrame(new building(),640,480);

public void init()

GraphicsConfiguration gc= SimpleUniverse.getPreferredConfiguration();
Canvas3D cv=new Canvas3D(gc);
setLayout(new BorderLayout());
add(cv,BorderLayout.CENTER);
BranchGroup bg=createSceneGraph();
bg.compile();
SimpleUniverse su=new SimpleUniverse(cv);
su.getViewingPlatform().setNominalViewingTransform();
su.addBranchGraph(bg);

private BranchGroup createSceneGraph()

BranchGroup root=new BranchGroup();
TransformGroup spin=new TransformGroup();
spin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
root.addChild(spin);

//生成形体
Appearance ap=new Appearance();
ap.setMaterial(new Material());
Shape3D shape=new Shape3D(createGeometry(),ap);
//形体变换
Transform3D tr=new Transform3D();
tr.setScale(0.2);
TransformGroup tg=new TransformGroup(tr);
spin.addChild(tg);
tg.addChild(shape);

//Alpha alpha=new Alpha(-1,12000);
//RotationInterpolator rotator=new RotationInterpolator(alpha,spin);
BoundingSphere bounds=new BoundingSphere();
//rotator.setSchedulingBounds(bounds);
//spin.addChild(rotator);

//设置背景和光照
Background background=new Background(1.0f,1.0f,1.0f);
background.setApplicationBounds(bounds);
root.addChild(background);
AmbientLight light=new AmbientLight(true,new Color3f(Color.red));
light.setInfluencingBounds(bounds);
root.addChild(light);
PointLight ptlight=new PointLight(new Color3f(Color.darkGray),
new Point3f(3f,3f,3f),new Point3f(1f,0f,0f));
ptlight.setInfluencingBounds(bounds);
root.addChild(ptlight);
PointLight ptlight2=new PointLight(new Color3f(Color.blue),
new Point3f(-2f,2f,2f),new Point3f(1f,0f,0f));
ptlight2.setInfluencingBounds(bounds);
root.addChild(ptlight2);
return root;

private Geometry createGeometry()

Point3f[] pts=new Point3f(-0.5f,2f,-0.5f),new Point3f(2.5f,2f,-0.5f),
new Point3f(-0.5f,2f,1.5f),new Point3f(2.5f,2f,1.5f),
new Point3f(-0.5f,2.5f,0.5f),new Point3f(2.5f,2.5f,0.5f);
int[] indices=0,2,4, 2,4,5, 2,3,5, 0,4,5, 0,1,5, 0,1,3, 0,2,3,
1,3,5;
int[] stripCounts=3,3,3,3,3,3,3,3;
GeometryInfo gi=new GeometryInfo(GeometryInfo.TRIANGLE_STRIP_ARRAY);
gi.setCoordinates(pts);
gi.setCoordinateIndices(indices);
gi.setStripCounts(stripCounts);
NormalGenerator ng=new NormalGenerator();
ng.generateNormals(gi);
return gi.getGeometryArray();



这是我的源码,,,显示出来的不是一个三棱柱,,,望高手指点 ,满意的追加200

我的天,我研究半天了,差不多。只不过是把 Point3f[] pts=new Point3f(-0.5f,2f,-0.5f),new Point3f(2.5f,2f,-0.5f),
new Point3f(-0.5f,2f,1.5f),new Point3f(2.5f,2f,1.5f),
new Point3f(-0.5f,2.5f,0.5f),new Point3f(2.5f,2.5f,0.5f);
int[] indices=0,2,4, 2,4,5, 2,3,5, 0,4,5, 0,1,5, 0,1,3, 0,2,3,
1,3,5;
int[] stripCounts=3,3,3,3,3,3,3,3;中的座标数值进行一下调整,三棱柱就会出现了。祝你工作愉快。满意吗。再是这太专业了,一般人不会。
参考技术A 你可以结题了呢……

[Beego模型] 构造查询

[Beego模型] 一、ORM 使用方法

[Beego模型] 二、CRUD 操作

[Beego模型] 三、高级查询

[Beego模型] 四、使用SQL语句进行查询

[Beego模型] 五、构造查询

[Beego模型] 六、事务处理

 

QueryBuilder 提供了一个简便,流畅的 SQL 查询构造器。在不影响代码可读性的前提下用来快速的建立 SQL 语句。

QueryBuilder 在功能上与 ORM 重合, 但是各有利弊。ORM 更适用于简单的 CRUD 操作,而 QueryBuilder 则更适用于复杂的查询,例如查询中包含子查询和多重联结。

使用方法:

// User 包装了下面的查询结果
type User struct {
    Name string
    Age  int
}
var users []User

// 获取 QueryBuilder 对象. 需要指定数据库驱动参数。
// 第二个返回值是错误对象,在这里略过
qb, _ := orm.NewQueryBuilder("mysql")

// 构建查询对象
qb.Select("user.name",
    "profile.age").
    From("user").
    InnerJoin("profile").On("user.id_user = profile.fk_user").
    Where("age > ?").
    OrderBy("name").Desc().
    Limit(10).Offset(0)

// 导出 SQL 语句
sql := qb.String()

// 执行 SQL 语句
o := orm.NewOrm()
o.Raw(sql, 20).QueryRows(&users)

完整 API 接口:

type QueryBuilder interface {
    Select(fields ...string) QueryBuilder
    From(tables ...string) QueryBuilder
    InnerJoin(table string) QueryBuilder
    LeftJoin(table string) QueryBuilder
    RightJoin(table string) QueryBuilder
    On(cond string) QueryBuilder
    Where(cond string) QueryBuilder
    And(cond string) QueryBuilder
    Or(cond string) QueryBuilder
    In(vals ...string) QueryBuilder
    OrderBy(fields ...string) QueryBuilder
    Asc() QueryBuilder
    Desc() QueryBuilder
    Limit(limit int) QueryBuilder
    Offset(offset int) QueryBuilder
    GroupBy(fields ...string) QueryBuilder
    Having(cond string) QueryBuilder
    Subquery(sub string, alias string) string
    String() string
}

 

 

 

摘自:https://beego.me/docs/mvc/model/querybuilder.md

以上是关于java3d构造一个三棱柱模型的主要内容,如果未能解决你的问题,请参考以下文章

为什么三棱锥体积是三棱柱的三分之一?

[Beego模型] 构造查询

JavaSE视频学习阶段性总结 三(类的组成,定义,构造方法;对象的创建,内存模型,参数传递)

多项式回归(Polynomial Regression)

[Beego模型] 高级查询

使用方向和轴旋转 3D 对象