Java3D-对象基本变换
一个球体与三个圆柱体形成一个组合体,在该组合体中,球体的透明度属性是由全透明到不透明之间变换,而且包括:旋转、平移等变换。
package com.vfsd.test0621;
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.GraphicsConfiguration;
import javax.media.j3d.Alpha;
import javax.media.j3d.Appearance;
import javax.media.j3d.Background;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.DirectionalLight;
import javax.media.j3d.Material;
import javax.media.j3d.RotPosPathInterpolator;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.media.j3d.TransparencyAttributes;
import javax.media.j3d.TransparencyInterpolator;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import javax.vecmath.Point3f;
import javax.vecmath.Quat4f;
import javax.vecmath.Vector3f;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.behaviors.mouse.MouseRotate;
import com.sun.j3d.utils.geometry.Cylinder;
import com.sun.j3d.utils.geometry.Sphere;
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.javafx.sg.prism.NGPhongMaterial;
/*******************************************************************************************************
* Copyright: vc1.0 2018. All rights reserved. <br>
* The whole package including this class is licensed under <br>
* <br>
* @ClassName: <br>
* @Directory: <br>
* @author: luozhubang <br>
* @version: v1.0.0 <br>
* @date: <br>
* @Description: <br>
* 1、 <br>
* 2、 <br>
* @Others: 暂无说明 <br>
* @Modification History: <br>
* 1、 <br>
* Date: <br>
* Author: <br>
* Modification: <br>
* <br>
* 2、 <br>
* Date: <br>
* Author: <br>
* Modification: <br>
*
* @Statement: If you are using the package or parts of it in any commercial way, a commercial license is required. <br>
* Visit <a href='http://www.bim-times.com'>http://www.bim-times.com</a> for more information.<br>
*
*********************************************************************************************************/
public class RotPosPathInterpolatorC extends Applet{
public BranchGroup createBranchGroupSceneGraph() {
BranchGroup branchGroupRoot = new BranchGroup();
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),100);
Color3f bgColor = new Color3f(1.0f,1.0f,1.0f);
Background bg = new Background(bgColor);
bg.setApplicationBounds(bounds);
branchGroupRoot.addChild(bg);
//定义平行光
Color3f directionalColor = new Color3f(1.0f,1.0f,0.9f);
Vector3f vec = new Vector3f(4.0f,-7.0f,-12.0f);
DirectionalLight directionalLight = new DirectionalLight(directionalColor,vec);
directionalLight.setInfluencingBounds(bounds);
branchGroupRoot.addChild(directionalLight);
//定义总变换
Transform3D t1 = new Transform3D();
TransformGroup group1 = new TransformGroup(t1);
group1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
group1.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
branchGroupRoot.addChild(group1);
//定义鼠标旋转对象
MouseRotate mouseR = new MouseRotate();
mouseR.setTransformGroup(group1);
branchGroupRoot.addChild(mouseR);
mouseR.setSchedulingBounds(bounds);
//定义Apperance类的对象及TransparencyAttributes类
Appearance app1 = new Appearance();
TransparencyAttributes transparency = new TransparencyAttributes(1,1.0f);
transparency.setCapability(TransparencyAttributes.ALLOW_VALUE_READ);
transparency.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE);
app1.setTransparencyAttributes(transparency);
app1.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_READ);
app1.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
Material material1 = new Material();
material1.setDiffuseColor(new Color3f(1.0f,0.0f,0.0f));
app1.setMaterial(material1);
//外观2
Appearance app2 = new Appearance();
Material material2 = new Material();
material2.setDiffuseColor(new Color3f(0.0f,1.0f,0.0f));
app2.setMaterial(material2);
//外观3
Appearance app3 = new Appearance();
Material material3 = new Material();
material3.setDiffuseColor(new Color3f(0.0f,0.0f,1.0f));
app3.setMaterial(material3);
//外观4
Appearance app4 = new Appearance();
Material material4 = new Material();
material4.setDiffuseColor(new Color3f(1.0f,1.0f,0.0f));
app4.setMaterial(material4);
//定义基本体积外观属性与坐标变换
Transform3D t2 = new Transform3D();
t2.setScale(1.8);
TransformGroup group2 = new TransformGroup(t2);
group2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
group2.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
group2.addChild(new Sphere(0.2f,Sphere.GENERATE_NORMALS,100,app1));//装载
//定义TransparencyInterpolator
Alpha alpha1 = new Alpha(-1,Alpha.INCREASING_ENABLE|Alpha.DECREASING_ENABLE,0,0,3000,0,0,3000,0,0);
TransparencyInterpolator transparency1 = new TransparencyInterpolator(alpha1, transparency,0.0f,1.0f);
transparency1.setSchedulingBounds(bounds);
group2.addChild(transparency1);
t2 = new Transform3D();
t2.setScale(1.8);
TransformGroup group3 = new TransformGroup(t2);
group3.addChild(new Cylinder(0.1f,0.5f,Cylinder.GENERATE_NORMALS,120,120,app2));//装载
t2 = new Transform3D();
t2.rotX(Math.PI*0.5);
t2.setScale(1.8);
TransformGroup group4 = new TransformGroup(t2);
group4.addChild(new Cylinder(0.1f,0.5f,Cylinder.GENERATE_NORMALS,120,120,app3));//装载
t2 = new Transform3D();
t2.rotZ(Math.PI*0.5);
t2.setScale(1.8);
TransformGroup group5 = new TransformGroup(t2);
group5.addChild(new Cylinder(0.1f,0.5f,Cylinder.GENERATE_NORMALS,120,120,app4));//装载
//定义节点knots数组
float[] knots = {0.0f,0.2f,0.4f,0.6f,0.8f,1.0f};
//定义位置坐标pos数组
Point3f[] pos = new Point3f[6];
pos[0] = new Point3f(-0.4f,-0.4f,-0.5f);
pos[1] = new Point3f(-0.3f,0.3f,0.3f);
pos[2] = new Point3f(-0.0f,0.4f,-0.2f);
pos[3] = new Point3f(-0.2f,-0.35f,0.3f);
pos[4] = new Point3f(-0.3f,-0.3f,-0.15f);
pos[5] = new Point3f(-0.4f,0.3f,0.4f);
//定义标识旋转方向方向和角度的quat数组
Quat4f[] quat = new Quat4f[6];
quat[0] = new Quat4f(1.0f,1.0f,1.0f,0.0f);
quat[1] = new Quat4f(0.0f,1.0f,1.0f,1.0f);
quat[2] = new Quat4f(1.0f,1.0f,1.0f,1.0f);
quat[3] = new Quat4f(0.0f,0.0f,1.0f,0.0f);
quat[4] = new Quat4f(1.0f,0.0f,1.0f,1.0f);
quat[5] = new Quat4f(01.0f,0.0f,1.0f,1.0f);
//创建RotPosPathInterpolator类机器Alpha
Alpha alpha2 = new Alpha(-1,Alpha.INCREASING_ENABLE|Alpha.DECREASING_ENABLE,0,0,8000,0,0,8000,0,0);
RotPosPathInterpolator rotpos2 = new RotPosPathInterpolator(alpha2,group1,t1,knots,quat,pos);
rotpos2.setSchedulingBounds(bounds);
group1.addChild(rotpos2);
group1.addChild(group2);
group1.addChild(group3);
group1.addChild(group4);
group1.addChild(group5);
branchGroupRoot.compile();
return branchGroupRoot;
}
public RotPosPathInterpolatorC() {
setLayout(new BorderLayout());
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
Canvas3D canvas = new Canvas3D(config);
add("Center",canvas);
BranchGroup groupS = createBranchGroupSceneGraph();
SimpleUniverse u1 = new SimpleUniverse(canvas);
u1.getViewingPlatform().setNominalViewingTransform();
u1.addBranchGraph(groupS);
}
public static void main(String[] args) {
new MainFrame(new RotPosPathInterpolatorC(),780,730);
}
}
Java3D-对象基本变换的更多相关文章
- Java3D读取3DMax模型并实现鼠标拖拽、旋转、滚轮缩放等功能
/**-------------------------------------------------代码区--------------------------------------------- ...
- Java3d 案例程序
今天偶尔翻出了很久以前写的java3d程序,很怀念曾经探索java3d解析.渲染ifc数据的日子 package com.vfsd.test0621; import java.applet.Apple ...
- 如何一步一步用DDD设计一个电商网站(九)—— 小心陷入值对象持久化的坑
阅读目录 前言 场景1的思考 场景2的思考 避坑方式 实践 结语 一.前言 在上一篇中(如何一步一步用DDD设计一个电商网站(八)—— 会员价的集成),有一行注释的代码: public interfa ...
- javascript中的Array对象 —— 数组的合并、转换、迭代、排序、堆栈
Array 是javascript中经常用到的数据类型.javascript 的数组其他语言中数组的最大的区别是其每个数组项都可以保存任何类型的数据.本文主要讨论javascript中数组的声明.转换 ...
- 探究javascript对象和数组的异同,及函数变量缓存技巧
javascript中最经典也最受非议的一句话就是:javascript中一切皆是对象.这篇重点要提到的,就是任何jser都不陌生的Object和Array. 有段时间曾经很诧异,到底两种数据类型用来 ...
- Asp.Net WebApi核心对象解析(下篇)
在接着写Asp.Net WebApi核心对象解析(下篇)之前,还是一如既往的扯扯淡,元旦刚过,整个人还是处于晕的状态,一大早就来处理系统BUG,简直是坑爹(好在没让我元旦赶过来该BUG),队友挖的坑, ...
- JS核心系列:浅谈原型对象和原型链
在Javascript中,万物皆对象,但对象也有区别,大致可以分为两类,即:普通对象(Object)和函数对象(Function). 一般而言,通过new Function产生的对象是函数对象,其他对 ...
- Chrome出了个小bug:论如何在Chrome下劫持原生只读对象
Chrome出了个小bug:论如何在Chrome下劫持原生只读对象 概述 众所周知,虽然JavaScript是个很灵活的语言,浏览器里很多原生的方法都可以随意覆盖或者重写,比如alert.但是为了保证 ...
- XStream将java对象转换为xml时,对象字段中的下划线“_”,转换后变成了两个的解决办法
在前几天的一个项目中,由于数据库字段的命名原因 其中有两项:一项叫做"市场价格"一项叫做"商店价格" 为了便于区分,遂分别将其命名为market ...
- ASP.NET内置对象的总结
1. Response对象可形象的称之为响应对象,用于将数据从服务器发送回浏览器. 实例源码:链接: http://pan.baidu.com/s/1dDCKQ8x 密码: ihq0 2. Requ ...
随机推荐
- KMSpico软件下载:激活Windows系统和Office工具
每次都为激活Windows系统 和 Microsoft Offilce 工具头疼,为此特意记录并分享一下激活工具. 上资源:https://pan.baidu.com/s/1kI5YpCO2aYl-r ...
- Data、String、Long三种日期类型之间的相互转换
// date类型转换为String类型 // formatType格式为yyyy-MM-dd HH:mm:ss//yyyy年MM月dd日 HH时mm分ss秒 // data Date类型的时间 pu ...
- redis实战之事务与持久化
1. 事务描述 (1)什么是事务 事务,就是把一堆事情绑在一起,按顺序的执行,都成功了才算完成,否则恢复之前的样子 事务必须服从ACID原则,ACID原则分别是原子性(atomicity).一致性(c ...
- LeetCode Target Sum
原题链接在这里:https://leetcode.com/problems/target-sum/description/ 题目: You are given a list of non-negati ...
- NOIp2018集训test-10-24(am&pm)
李巨连续AK三场了,我跟南瓜打赌李巨连续AK七场,南瓜赌李巨连续AK五场. DAY1 T1 qu 按题意拿stack,queue和priority_que模拟即可.特判没有元素却要取出的情况. T2 ...
- 将非Maven管理的jar打包到Maven本地资源库
这里有2个案例,需要手动发出Maven命令包括一个 jar 到 Maven 的本地资源库. 要使用的 jar 不存在于 Maven 的中心储存库中. 您创建了一个自定义的 jar ,而另一个 Mave ...
- ubuntu nfs server config
(1)#sudo apt-get install nfs-kernel-server 打开/etc/exports文件,在末尾加入: /home/hyq *(rw,sync,no_root_squas ...
- 正确安全清空在线慢查询日志slow log的流程 (转)
1, see the slow log status; mysql> show variables like '%slow%'; +---------------------+--------- ...
- SVN 服务器端的搭建-及多仓库管理-OK
1.首先安装SVN这个软件 apt-get install subversion 2.在home目录下创建一个名为svn的文件夹(文件夹的名字随便起) mkdir /kk/svn/rda8501_co ...
- Attribute注解(用于判断权限)
一 Attribute原理: Attribute注解,是附加上方法.属性.类等上面的标签,可以通过方法的GetCustomAttribute获得粘贴的这个Attribute对象通过反射调用到粘贴到属 ...