本文整理汇总了Java中javax.media.j3d.Transform3D.setTranslation方法的典型用法代码示例。如果您正苦于以下问题:Java Transform3D.setTranslation方法的具体用法?Java Transform3D.setTranslation怎么用?Java Transform3D.setTranslation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.media.j3d.Transform3D
的用法示例。
在下文中一共展示了Transform3D.setTranslation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createCompass
import javax.media.j3d.Transform3D; //导入方法依赖的package包/类
public static Group createCompass() {
Appearance ap = Compass.generateAppearance(Color.pink, 0.5, true);
Cone c = new Cone(1f, 5f, ap);
Transform3D tf = new Transform3D();
tf.rotX(Math.PI / 2);
Transform3D tf1 = new Transform3D();
tf1.setTranslation(new Vector3d(10, 15, -40));
TransformGroup tg = new TransformGroup(tf);
tg.addChild(c);
TransformGroup tg2 = new TransformGroup(tf1);
tg2.addChild(tg);
return tg2;
}
示例2: updateViewPlatformTransform
import javax.media.j3d.Transform3D; //导入方法依赖的package包/类
/**
* Updates <code>viewPlatformTransform</code> transform from camera angles and location.
*/
private void updateViewPlatformTransform(Transform3D transform, float cameraX, float cameraY, float cameraZ,
float cameraYaw, float cameraPitch)
{
Transform3D yawRotation = new Transform3D();
yawRotation.rotY(-cameraYaw + Math.PI);
Transform3D pitchRotation = new Transform3D();
pitchRotation.rotX(-cameraPitch);
yawRotation.mul(pitchRotation);
transform.setIdentity();
transform.setTranslation(new Vector3f(cameraX, cameraZ, cameraY));
transform.mul(yawRotation);
this.camera = new Camera(cameraX, cameraY, cameraZ, cameraYaw, cameraPitch, 0);
}
示例3: updateViewPlatformTransform
import javax.media.j3d.Transform3D; //导入方法依赖的package包/类
/**
* Updates the given view platform transformation from yaw angle, pitch angle and scale.
*/
private void updateViewPlatformTransform(TransformGroup viewPlatformTransform, float viewYaw, float viewPitch,
float viewScale)
{
// Default distance used to view a 2 unit wide scene
double nominalDistanceToCenter = 1.4 / Math.tan(Math.PI / 8);
// We don't use a TransformGroup in scene tree to be able to share the same scene
// in the different views displayed by OrientationPreviewComponent class
Transform3D translation = new Transform3D();
translation.setTranslation(new Vector3d(0, 0, nominalDistanceToCenter));
Transform3D pitchRotation = new Transform3D();
pitchRotation.rotX(viewPitch);
Transform3D yawRotation = new Transform3D();
yawRotation.rotY(viewYaw);
Transform3D scale = new Transform3D();
scale.setScale(viewScale);
pitchRotation.mul(translation);
yawRotation.mul(pitchRotation);
scale.mul(yawRotation);
viewPlatformTransform.setTransform(scale);
}
示例4: testOBJWriter
import javax.media.j3d.Transform3D; //导入方法依赖的package包/类
/**
* Simple test of OBJWriter class with Java 3D objects.
*/
public void testOBJWriter() throws IOException {
// 1. Open the OBJ file "Test.obj"
OBJWriter writer = new OBJWriter("[email protected]#.obj", "Test", 3);
assertTrue("[email protected]#.obj not created", new File("[email protected]#.obj").exists());
// 2. Write a box at center
writer.writeNode(new Box());
// Write a sphere centered at (2, 0, 2)
Transform3D translation = new Transform3D();
translation.setTranslation(new Vector3f(2f, 0, 2f));
TransformGroup translationGroup = new TransformGroup(translation);
translationGroup.addChild(new Sphere());
writer.writeNode(translationGroup);
// 3. Close file
writer.close();
assertTrue("[email protected]#.mtl not created", new File("[email protected]#.mtl").exists());
if (!new File("[email protected]#.obj").delete()
|| !new File("[email protected]#.mtl").delete()) {
fail("Couldn't delete test files");
}
}
示例5: makeSpin
import javax.media.j3d.Transform3D; //导入方法依赖的package包/类
private RotationInterpolator makeSpin(TransformGroup spinner) {
//Alpha alpha = new Alpha(1, Alpha.DECREASING_ENABLE, 0, 10000, 5000, 0, 1000, 5000, 0, 1000);
Alpha alpha = new Alpha(1, 3000);//new Alpha(-1, 10000) set speed here
alpha.setAlphaAtOneDuration(3000);
alpha.setIncreasingAlphaRampDuration(500);
alpha.setMode(Alpha.INCREASING_ENABLE);
rotator = new RotationInterpolator(alpha, spinner);
double rot = Math.toRadians(90);
Transform3D rotate1 = new Transform3D();
rotate1.rotX(rot);
rotate1.setTranslation(new Vector3f(0.3f, 0.3f, 0.0f));
rotator.setTransformAxis(rotate1);
rotator.setSchedulingBounds(bounds);
return rotator;
}
示例6: initPerspective
import javax.media.j3d.Transform3D; //导入方法依赖的package包/类
/**
* Position: X/Y: zentriert, Z: so, dass der Parcours
* vollstaendig im Blick ist
* @param w Welt
*/
private void initPerspective(World w) {
double centerX = w.getWidthInM() / 2;
double centerY = w.getHeightInM() / 2;
double longerSide = Math.max(
w.getWidthInM(), w.getHeightInM());
// Winkel im Bogenmass
double field = universe.getViewer().getView().getFieldOfView();
Transform3D targetTfm = new Transform3D();
TransformGroup tg =
universe.getViewingPlatform().getViewPlatformTransform();
tg.getTransform(targetTfm);
targetTfm.setTranslation(new Vector3d(centerX, centerY,
(longerSide/2) / Math.tan(field/2)));
tg.setTransform(targetTfm);
}
示例7: setPosition
import javax.media.j3d.Transform3D; //导入方法依赖的package包/类
/**
* @param posInWorldCoord Die Position, an die der Bot gesetzt werden soll
*/
public final synchronized void setPosition(Point3d posInWorldCoord) {
// Optimierung (Transform-Kram ist teuer)
if (this.posInWorldCoord.equals(posInWorldCoord)) {
return;
}
this.posInWorldCoord = posInWorldCoord;
Transform3D t = new Transform3D();
transformgrp.getTransform(t);
t.setTranslation(new Vector3d(posInWorldCoord));
transformgrp.setTransform(t);
if (! is(COLLIDED) && ! is(IN_HOLE)) {
lastSafePos.set(posInWorldCoord);
}
}
示例8: createSceneGraph
import javax.media.j3d.Transform3D; //导入方法依赖的package包/类
/**
* Creates a scene graph for the 3D model, translates the model on the
* y-axis by {@code MODEL_Y_POSITION} and sets the rotation.
*
* @return a BranchGroup for the 3D model.
*/
private BranchGroup createSceneGraph() {
BranchGroup objRoot = new BranchGroup();
TransformGroup objTrans = new TransformGroup();
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objRoot.addChild(objTrans);
// Move the shape down on the y-axis
TransformGroup moveDownGroup = new TransformGroup();
Transform3D moveDownTrans = new Transform3D();
moveDownTrans.setTranslation(new Vector3f(0, MODEL_Y_POSITION, 0));
moveDownGroup.setTransform(moveDownTrans);
objTrans.addChild(moveDownGroup);
moveDownGroup.addChild(this.shape3d);
// Rotate the shape
Transform3D yAxis = new Transform3D();
Alpha rotationAlpha = new Alpha(-1, ROTATION_ALPHA_DURATION);
RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0, (float) Math.PI * 2.0f);
BoundingSphere bounds = new BoundingSphere(new Point3d(0, 0, 0), ROTATOR_SPHERE_RADIUS);
rotator.setSchedulingBounds(bounds);
objRoot.addChild(rotator);
objRoot.compile();
return objRoot;
}
示例9: doPreview
import javax.media.j3d.Transform3D; //导入方法依赖的package包/类
@Override
public void doPreview() {
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
Canvas3D canvas = new Canvas3D(config);
canvas.setPreferredSize(new Dimension(CANVAS_PREFERRED_WIDTH, CANVAS_PREFERRED_HEIGHT));
BranchGroup scene = createSceneGraph();
this.universe = new SimpleUniverse(canvas);
// Move the camera back on the z-axis
Transform3D cameraTransform = new Transform3D();
TransformGroup viewPlatformGroup = this.universe.getViewingPlatform().getViewPlatformTransform();
cameraTransform.setTranslation(new Vector3f(0, 0, CAMERA_Z_POSITION));
viewPlatformGroup.setTransform(cameraTransform);
// Necessary to see the whole model
this.universe.getViewer().getView().setBackClipDistance(BACK_CLIP_DISTANCE);
this.universe.addBranchGraph(scene);
super.preview.setCanvas(canvas, true);
}
示例10: Main
import javax.media.j3d.Transform3D; //导入方法依赖的package包/类
public Main() {
setLayout(new BorderLayout());
GraphicsConfiguration config = SimpleUniverse
.getPreferredConfiguration();
Canvas3D canvas = new Canvas3D(config);
add(canvas, BorderLayout.CENTER);
universe = new SimpleUniverse(canvas);
// �V�[�����\�z
BranchGroup scene = createSceneGraph();
scene.compile();
// ���_���Z�b�g
Transform3D viewPlatformTransform = new Transform3D();
viewPlatformTransform.setTranslation(new Vector3d(0.0, 0.0, 10.0));
universe.getViewingPlatform().getViewPlatformTransform().setTransform(viewPlatformTransform);
// �}�E�X����
orbitControls(canvas);
universe.addBranchGraph(scene);
}
示例11: drawTrace
import javax.media.j3d.Transform3D; //导入方法依赖的package包/类
/**
* Called to place ghost bodies
* (uses a lot of ressources)
*/
private void drawTrace() {
for (int i = 0; i < this.nbBodies; i++) {
for (int j = 0; j < (this.MAX_HISTO_SIZE - 1); j++) {
double x = this.bodies[i].getX(j + 1) - this.baseX;
double y = this.bodies[i].getY(j + 1) - this.baseY;
double z = this.bodies[i].getZ(j + 1) - this.baseZ;
//this.tracesTransformation[i][j].setTranslation(new Vector3d(x,y,z));
//this.tracesGroup[i][j].setTransform(tracesTransformation[i][j]);
Transform3D t = new Transform3D();
t.setTranslation(new Vector3d(x, y, z));
this.tracesGroup[i][j].setTransform(t);
//System.out.println("["+i+"]["+j+"]: ("+x+","+y+","+z+")");
}
}
}
示例12: addElementAt
import javax.media.j3d.Transform3D; //导入方法依赖的package包/类
public static BranchGroup addElementAt(Node aShape, Vector3f aTranslation, float aScale) {
BranchGroup theGroup = new BranchGroup();
theGroup.setCapability(BranchGroup.ALLOW_DETACH);
Transform3D theTransform = new Transform3D();
theTransform.setTranslation(aTranslation);
theTransform.setScale(aScale);
TransformGroup theTransformGroup = new TransformGroup(theTransform);
theTransformGroup.addChild(aShape);
theGroup.addChild(theTransformGroup);
return theGroup;
}
示例13: getNormalizedTransform
import javax.media.j3d.Transform3D; //导入方法依赖的package包/类
/**
* Returns a transform that will transform the model <code>node</code>
* to let it fill a box of the given <code>width</code> centered on the origin.
* @param node the root of a model with any size and location
* @param modelRotation the rotation applied to the model before normalization
* or <code>null</code> if no transformation should be applied to node.
* @param width the width of the box
*/
public Transform3D getNormalizedTransform(Node node, float[][] modelRotation, float width)
{
// Get model bounding box size
BoundingBox modelBounds = getBounds(node);
Point3d lower = new Point3d();
modelBounds.getLower(lower);
Point3d upper = new Point3d();
modelBounds.getUpper(upper);
// Translate model to its center
Transform3D translation = new Transform3D();
translation.setTranslation(new Vector3d(-lower.x - (upper.x - lower.x) / 2, -lower.y - (upper.y - lower.y) / 2,
-lower.z - (upper.z - lower.z) / 2));
Transform3D modelTransform;
if (modelRotation != null)
{
// Get model bounding box size with model rotation
modelTransform = getRotationTransformation(modelRotation);
modelTransform.mul(translation);
BoundingBox rotatedModelBounds = getBounds(node, modelTransform);
rotatedModelBounds.getLower(lower);
rotatedModelBounds.getUpper(upper);
}
else
{
modelTransform = translation;
}
// Scale model to make it fill a 1 unit wide box
Transform3D scaleOneTransform = new Transform3D();
scaleOneTransform.setScale(new Vector3d(width / Math.max(getMinimumSize(), upper.x - lower.x),
width / Math.max(getMinimumSize(), upper.y - lower.y),
width / Math.max(getMinimumSize(), upper.z - lower.z)));
scaleOneTransform.mul(modelTransform);
return scaleOneTransform;
}
示例14: getPieceOFFurnitureNormalizedModelTransformation
import javax.media.j3d.Transform3D; //导入方法依赖的package包/类
/**
* Returns a transformation able to place in the scene the normalized model
* of the given <code>piece</code>.
*/
Transform3D getPieceOFFurnitureNormalizedModelTransformation(HomePieceOfFurniture piece)
{
// Set piece size
Transform3D scale = new Transform3D();
float pieceWidth = piece.getWidth();
// If piece model is mirrored, inverse its width
if (piece.isModelMirrored())
{
pieceWidth *= -1;
}
scale.setScale(new Vector3d(pieceWidth, piece.getHeight(), piece.getDepth()));
// Change its angle around y axis
Transform3D orientation = new Transform3D();
orientation.rotY(-piece.getAngle());
orientation.mul(scale);
// Translate it to its location
Transform3D pieceTransform = new Transform3D();
float z = piece.getElevation() + piece.getHeight() / 2;
if (piece.getLevel() != null)
{
z += piece.getLevel().getElevation();
}
pieceTransform.setTranslation(new Vector3f(piece.getX(), z, piece.getY()));
pieceTransform.mul(orientation);
return pieceTransform;
}
示例15: addPointsShape
import javax.media.j3d.Transform3D; //导入方法依赖的package包/类
/**
* This is the only method different from the Checkers3D example in Chapter
* 15 of "Killer Game Programming in Java"
* (http://fivedots.coe.psu.ac.th/~ad/jg/ch8/).
*
* All the hard work is done inside the PointsShape object. The transform
* group is used to position (and perhaps scale) the points cloud.
*/
private void addPointsShape(PointsShape ptsShape) {
// scale and move start position to (-4,0,0) // change later
TransformGroup posnTG = new TransformGroup();
Transform3D t3d = new Transform3D();
// t3d.setScale(0.5);
// t3d.setTranslation(new Vector3d(-3.2f, 2.4f, 0.0f));// 6.40 / 2
t3d.setTranslation(new Vector3d(0f, 0f, 0.0f));// 6.40 / 2
posnTG.setTransform(t3d);
posnTG.addChild(ptsShape);
sceneBG.addChild(posnTG);
}