📄 human.java
字号:
package cn.bz.branchGroup;
import java.text.NumberFormat;
import javax.media.j3d.Appearance;
import javax.media.j3d.Material;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.media.j3d.View;
import javax.swing.JLabel;
import javax.swing.JSlider;
import javax.swing.JTabbedPane;
import javax.vecmath.AxisAngle4f;
import javax.vecmath.Color3f;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3f;
import com.sun.j3d.utils.geometry.Cylinder;
import com.sun.j3d.utils.geometry.Sphere;
import com.sun.j3d.utils.universe.SimpleUniverse;
public class Human{
public static Human human;
Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
// These names correspond to the H-Anim names
TransformGroup Human_body;
TransformGroup Human_l_elbow;
TransformGroup Human_l_shoulder;
TransformGroup Human_r_elbow;
TransformGroup Human_r_shoulder;
TransformGroup Human_skullbase;
AxisAngle4f lElbowAA = new AxisAngle4f(0.0f, 0.0f, 1.0f, 0.0f);
int lElbowRot = 0;
JSlider lElbowSlider;
JLabel lElbowSliderLabel;
AxisAngle4f lShoulderAA = new AxisAngle4f(0.0f, 0.0f, 1.0f, 0.0f);
int lShoulderRot = 0;
JSlider lShoulderSlider;
JLabel lShoulderSliderLabel;
// NumberFormat to print out floats with only two digits 应该是精度为两位吧
NumberFormat nf;
float offScreenScale = 1.5f;
// geometric constant
Point3f origin = new Point3f();
String outFileBase = "human";
int outFileSeq = 0;
// colors for use in the cones
Color3f red = new Color3f(1.0f, 0.0f, 0.0f);
AxisAngle4f rElbowAA = new AxisAngle4f(0.0f, 0.0f, -1.0f, 0.0f);
int rElbowRot = 0;
JSlider rElbowSlider;
JLabel rElbowSliderLabel;
AxisAngle4f rShoulderAA = new AxisAngle4f(0.0f, 0.0f, -1.0f, 0.0f); //这东西不懂
// these set up the transformations
int rShoulderRot = 0;
JSlider rShoulderSlider;
JLabel rShoulderSliderLabel;
String snapImageString = "Snap Image";
// GUI elements
JTabbedPane tabbedPane;
AxisAngle4f tmpAxisAngle = new AxisAngle4f();
// These will be created, attached the scene graph and then the variable
// will be reused to initialize other sections of the scene graph.
Cylinder tmpCyl;
Sphere tmpSphere;
TransformGroup tmpTG;
// Temporaries that are reused
Transform3D tmpTrans = new Transform3D();
Vector3f tmpVector = new Vector3f();
SimpleUniverse u;
View view;
Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
Vector3f yAxis = new Vector3f(0.0f, 1.0f, 0.0f);
public TransformGroup createHuman() {
Human_body = new TransformGroup();
// center the body
tmpVector.set(0.0f, -1.5f, 0.0f);
tmpTrans.set(tmpVector);
Human_body.setTransform(tmpTrans);
Material material = new Material(red, black, red, white, 64);
Appearance appearance = new Appearance();
appearance.setMaterial(material);
// offset and place the cylinder for the body
tmpTG = new TransformGroup();
// offset the shape
tmpVector.set(0.0f, 1.5f, 0.0f);
tmpTrans.set(tmpVector);
tmpTG.setTransform(tmpTrans);
tmpCyl = new Cylinder(0.75f, 3.0f, appearance);
tmpTG.addChild(tmpCyl);
// add the shape to the body
Human_body.addChild(tmpTG);
// create the r_shoulder TransformGroup
Human_r_shoulder = new TransformGroup();
Human_r_shoulder.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
Human_r_shoulder.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
// translate from the waist
tmpVector.set(-0.95f, 2.9f, -0.2f);
tmpTrans.set(tmpVector);
Human_r_shoulder.setTransform(tmpTrans);
// place the sphere for the r_shoulder
tmpSphere = new Sphere(0.22f, appearance);
Human_r_shoulder.addChild(tmpSphere);
// offset and place the cylinder for the r_shoulder
tmpTG = new TransformGroup();
// offset the shape
tmpVector.set(0.0f, -0.5f, 0.0f);
tmpTrans.set(tmpVector);
tmpTG.setTransform(tmpTrans);
tmpCyl = new Cylinder(0.2f, 1.0f, appearance);
tmpTG.addChild(tmpCyl);
// add the shape to the r_shoulder
Human_r_shoulder.addChild(tmpTG);
// add the shoulder to the body group
Human_body.addChild(Human_r_shoulder);
// create the r_elbow TransformGroup
Human_r_elbow = new TransformGroup();
Human_r_elbow.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
Human_r_elbow.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
tmpVector.set(0.0f, -1.054f, 0.0f);
tmpTrans.set(tmpVector);
Human_r_elbow.setTransform(tmpTrans);
// place the sphere for the r_elbow
tmpSphere = new Sphere(0.22f, appearance);
Human_r_elbow.addChild(tmpSphere);
// offset and place the cylinder for the r_shoulder
tmpTG = new TransformGroup();
// offset the shape
tmpVector.set(0.0f, -0.5f, 0.0f);
tmpTrans.set(tmpVector);
tmpTG.setTransform(tmpTrans);
tmpCyl = new Cylinder(0.2f, 1.0f, appearance);
tmpTG.addChild(tmpCyl);
// add the shape to the r_shoulder
Human_r_elbow.addChild(tmpTG);
// add the elbow to the shoulder group
Human_r_shoulder.addChild(Human_r_elbow);
// create the l_shoulder TransformGroup
Human_l_shoulder = new TransformGroup();
Human_l_shoulder.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
Human_l_shoulder.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
tmpVector.set(0.95f, 2.9f, -0.2f);
tmpTrans.set(tmpVector);
Human_l_shoulder.setTransform(tmpTrans);
// place the sphere for the l_shoulder
tmpSphere = new Sphere(0.22f, appearance);
Human_l_shoulder.addChild(tmpSphere);
// offset and place the cylinder for the l_shoulder
tmpTG = new TransformGroup();
// offset the shape
tmpVector.set(0.0f, -0.5f, 0.0f);
tmpTrans.set(tmpVector);
tmpTG.setTransform(tmpTrans);
tmpCyl = new Cylinder(0.2f, 1.0f, appearance);
tmpTG.addChild(tmpCyl);
// add the shape to the l_shoulder
Human_l_shoulder.addChild(tmpTG);
// add the shoulder to the body group
Human_body.addChild(Human_l_shoulder);
// create the r_elbow TransformGroup
Human_l_elbow = new TransformGroup();
Human_l_elbow.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
Human_l_elbow.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
tmpVector.set(0.0f, -1.054f, 0.0f);
tmpTrans.set(tmpVector);
Human_l_elbow.setTransform(tmpTrans);
// place the sphere for the l_elbow
tmpSphere = new Sphere(0.22f, appearance);
Human_l_elbow.addChild(tmpSphere);
// offset and place the cylinder for the l_elbow
tmpTG = new TransformGroup();
// offset the shape
tmpVector.set(0.0f, -0.5f, 0.0f);
tmpTrans.set(tmpVector);
tmpTG.setTransform(tmpTrans);
tmpCyl = new Cylinder(0.2f, 1.0f, appearance);
tmpTG.addChild(tmpCyl);
// add the shape to the l_elbow
Human_l_elbow.addChild(tmpTG);
// add the shoulder to the body group
Human_l_shoulder.addChild(Human_l_elbow);
// create the skullbase TransformGroup
Human_skullbase = new TransformGroup();
tmpVector.set(0.0f, 3.632f, 0.0f);
tmpTrans.set(tmpVector);
Human_skullbase.setTransform(tmpTrans);
// offset and place the sphere for the skull
tmpSphere = new Sphere(0.5f, appearance);
// add the shape to the l_shoulder
Human_skullbase.addChild(tmpSphere);
// add the shoulder to the body group
Human_body.addChild(Human_skullbase);
return Human_body ;
}
public void setLElbowRot(int rotation) {
float angle = (float) Math.toRadians(rotation);
lElbowRot = rotation;
lElbowAA.angle = (float) Math.toRadians(lElbowRot);
Human_l_elbow.getTransform(tmpTrans);
tmpTrans.setRotation(lElbowAA);
Human_l_elbow.setTransform(tmpTrans);
}
public void setLShoulderRot(int rotation) {
lShoulderRot = rotation;
lShoulderAA.angle = (float) Math.toRadians(lShoulderRot);
Human_l_shoulder.getTransform(tmpTrans);
tmpTrans.setRotation(lShoulderAA);
Human_l_shoulder.setTransform(tmpTrans);
}
public void setRElbowRot(int rotation) {
float angle = (float) Math.toRadians(rotation);
rElbowRot = rotation;
rElbowAA.angle = (float) Math.toRadians(rElbowRot);
Human_r_elbow.getTransform(tmpTrans);
tmpTrans.setRotation(rElbowAA);
Human_r_elbow.setTransform(tmpTrans);
}
public void setRShoulderRot(int rotation) {
rShoulderRot = rotation;
rShoulderAA.angle = (float) Math.toRadians(rShoulderRot);
Human_r_shoulder.getTransform(tmpTrans);
tmpTrans.setRotation(rShoulderAA);
Human_r_shoulder.setTransform(tmpTrans);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -