本文整理汇总了Java中javax.media.j3d.Transform3D.setScale方法的典型用法代码示例。如果您正苦于以下问题:Java Transform3D.setScale方法的具体用法?Java Transform3D.setScale怎么用?Java Transform3D.setScale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.media.j3d.Transform3D
的用法示例。
在下文中一共展示了Transform3D.setScale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: setFacteurZ
import javax.media.j3d.Transform3D; //导入方法依赖的package包/类
/**
* Permet d'appliquer un facteur d'échelle en Z à la carte
* @param echelleZ
*/
public void setFacteurZ(double echelleZ) {
ConstantRepresentation.scaleFactorZ = echelleZ;
// Création d'une transformation pour permettre une mise à l'échelle
Transform3D tEchelleZ = new Transform3D();
tEchelleZ.setScale(new Vector3d(1.0, 1.0, ConstantRepresentation.scaleFactorZ));
InterfaceMap3D.tgScaleZ.setTransform(tEchelleZ);
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: setModelRotation
import javax.media.j3d.Transform3D; //导入方法依赖的package包/类
/**
* Updates the rotation of the 3D model displayed by this component.
* The model is shown at its default size.
*/
protected void setModelRotation(float[][] modelRotation)
{
BranchGroup modelNode = getModelNode();
if (modelNode != null && modelNode.numChildren() > 0)
{
// Check rotation isn't set on model node
if (this.internalRotationAndSize)
{
throw new IllegalStateException("Can't set rotation");
}
// Apply model rotation
Transform3D rotationTransform = new Transform3D();
if (modelRotation != null)
{
Matrix3f modelRotationMatrix = new Matrix3f(modelRotation[0][0], modelRotation[0][1],
modelRotation[0][2], modelRotation[1][0], modelRotation[1][1], modelRotation[1][2],
modelRotation[2][0], modelRotation[2][1], modelRotation[2][2]);
rotationTransform.setRotation(modelRotationMatrix);
}
// Scale model to make it fit in a 1.8 unit wide box
Transform3D modelTransform = new Transform3D();
Vector3f size = ModelManager.getInstance().getSize(modelNode);
modelTransform.setScale(1.8 / Math.max(Math.max(size.x, size.z), size.y));
modelTransform.mul(rotationTransform);
TransformGroup modelTransformGroup = (TransformGroup) this.sceneTree.getChild(0);
modelTransformGroup.setTransform(modelTransform);
}
}
示例7: setModelRotationAndSize
import javax.media.j3d.Transform3D; //导入方法依赖的package包/类
/**
* Updates the rotation and the size of the 3D model displayed by this component.
*/
protected void setModelRotationAndSize(float[][] modelRotation, float width, float depth, float height)
{
BranchGroup modelNode = getModelNode();
if (modelNode != null && modelNode.numChildren() > 0)
{
// Check rotation isn't set on model node
if (this.internalRotationAndSize)
{
throw new IllegalStateException("Can't set rotation and size");
}
Transform3D normalization = ModelManager.getInstance().getNormalizedTransform(modelNode, modelRotation, 1f);
// Scale model to its size
Transform3D scaleTransform = new Transform3D();
if (width != 0 && depth != 0 && height != 0)
{
scaleTransform.setScale(new Vector3d(width, height, depth));
}
scaleTransform.mul(normalization);
// Scale model to make it fit in a 1.8 unit wide box
Transform3D modelTransform = new Transform3D();
if (width != 0 && depth != 0 && height != 0)
{
modelTransform.setScale(1.8 / Math.max(Math.max(width, height), depth));
}
else
{
Vector3f size = ModelManager.getInstance().getSize(modelNode);
modelTransform.setScale(1.8 / Math.max(Math.max(size.x, size.z), size.y));
}
modelTransform.mul(scaleTransform);
TransformGroup modelTransformGroup = (TransformGroup) this.sceneTree.getChild(0);
modelTransformGroup.setTransform(modelTransform);
}
}
示例8: addScaleBarToSceneGraph
import javax.media.j3d.Transform3D; //导入方法依赖的package包/类
/**
* add a 100 µm scale bar to the BranchGroup
*
* @param scene
* the BranchGroup
*/
public static void addScaleBarToSceneGraph(TransformGroup scene, Point3f scaleBarPos, float scale) {
if (scaleBarPos == null) {
scaleBarPos = new Point3f();
}
float barPos = -150.0f * scale;
float hight = 100.0f * scale;
//logger.info("scaleBarPos: " + scaleBarPos.toString());
LineArray la = new LineArray(2, LineArray.COORDINATES | LineArray.COLOR_3);
//la.setCoordinate(0, new Point3f(scaleBarPos.x + 0.7f, scaleBarPos.y + 0.0f, scaleBarPos.z + 0.9f));
//la.setCoordinate(1, new Point3f(scaleBarPos.x + 0.7f, scaleBarPos.y + 0.0f, scaleBarPos.z + 1.0f));
la.setCoordinate(0, new Point3f(barPos, scaleBarPos.y, scaleBarPos.z));
la.setCoordinate(1, new Point3f(barPos, scaleBarPos.y, scaleBarPos.z + hight));
for (int i = 0; i < 2; ++i) {
la.setColor(i, grey);
}
scene.addChild(new Shape3D(la));
Text3D text3d = new Text3D(new Font3D(new Font("plain", java.awt.Font.PLAIN, 1), new FontExtrusion()), "100 µm");
text3d.setAlignment(Text3D.ALIGN_LAST);
Shape3D text3dShape3d = new Shape3D(text3d);
Appearance appearance = new Appearance();
ColoringAttributes ca = new ColoringAttributes();
ca.setColor(grey);
appearance.setColoringAttributes(ca);
text3dShape3d.setAppearance(appearance);
TransformGroup tg = new TransformGroup();
Transform3D t3d = new Transform3D();
t3d.rotX(Math.PI / 2);
float textScale = 30f * scale;
//t3d.setScale(0.025);
t3d.setScale(textScale);
t3d.setTranslation(new Vector3f((barPos + (barPos/10.0f)), scaleBarPos.y, scaleBarPos.z + hight/2.0f));
tg.setTransform(t3d);
tg.addChild(text3dShape3d);
scene.addChild(tg);
// scene.addChild(text3dShape3d);
}
示例9: addText3D
import javax.media.j3d.Transform3D; //导入方法依赖的package包/类
public static void addText3D(TransformGroup bg, String text, Vector3f vPos, float scale, Color3f color) {
Text3D text3d = new Text3D(new Font3D(new Font("plain", java.awt.Font.PLAIN, 1), new FontExtrusion()), text);
Shape3D text3dShape3d = new Shape3D(text3d);
Appearance appearance = new Appearance();
ColoringAttributes ca = new ColoringAttributes();
ca.setColor(color);
appearance.setColoringAttributes(ca);
TransparencyAttributes myTA = new TransparencyAttributes();
myTA.setTransparency(0.3f);
myTA.setTransparencyMode(TransparencyAttributes.NICEST);
appearance.setTransparencyAttributes(myTA);
text3dShape3d.setAppearance(appearance);
TransformGroup tg = new TransformGroup();
Transform3D t3d = new Transform3D();
t3d.rotX(Math.PI / 2);
t3d.setTranslation(vPos);
t3d.setScale(scale * 15.0f);
tg.setTransform(t3d);
tg.addChild(text3dShape3d);
bg.addChild(tg);
}
示例10: moveBack
import javax.media.j3d.Transform3D; //导入方法依赖的package包/类
private TransformGroup moveBack(Vector3f back, double scale) {
Transform3D transform3D = new Transform3D();
//transform3D.setTranslation(new Vector3f(0.0f, 0.0f, 0.0f));
//transform3D.setTranslation(new Vector3f(0f, -20f, 0f));
transform3D.setRotation(new AxisAngle4f(1.0f, 0.0f, 0.0f, (float) Math.toRadians(270)));
//new Vector3f(-0.3f, -0.8f, -3.0f)
transform3D.setTranslation(back);
transform3D.setScale(scale);
return new TransformGroup(transform3D);
}
示例11: writeLabel
import javax.media.j3d.Transform3D; //导入方法依赖的package包/类
/**
* Used to write a text next to the sphere representing a body
* @param i the body identification
* @param label the text to write
*/
private void writeLabel(int i, String label, double diameter) {
labels[i].removeAllChildren();
if (label.compareTo("") != 0) {
// Creating
BranchGroup bg = new BranchGroup();
bg.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
bg.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
bg.setCapability(BranchGroup.ALLOW_DETACH);
// Translating & scaling
TransformGroup labelGroup = new TransformGroup();
Transform3D scaling = new Transform3D();
scaling.setTranslation(new Vector3d(0.01 + ((0.005 * diameter) / MASS_RATIO),
0.01 + ((0.005 * diameter) / MASS_RATIO), 0.0));
//scaling.setTranslation(new Vector3d(0.15,0.15,0.0));
scaling.setScale(0.5);
labelGroup.setTransform(scaling);
// Assembling and creating the text2D
labelGroup.addChild(new Text2D(label, new Color3f(1.0f, 1.0f, 1.0f), "Arial", 14, Font.PLAIN));
bg.addChild(labelGroup);
bg.compile();
labels[i].addChild(bg);
}
}
示例12: setTraceVisible
import javax.media.j3d.Transform3D; //导入方法依赖的package包/类
/**
* Show or hide the ghosts
* @param b true: show the ghosts
* false: hide the ghosts
*/
private void setTraceVisible(boolean b) {
if (!b) {
// Hide Trace
Transform3D hide = new Transform3D();
hide.setScale(0.0);
for (int i = 0; i < this.nbBodies; i++) {
for (int j = 0; j < (this.MAX_HISTO_SIZE - 1); j++) {
this.tracesGroup[i][j].setTransform(hide);
}
}
}
this.mustDrawTraces = b;
}
示例13: generateLabel
import javax.media.j3d.Transform3D; //导入方法依赖的package包/类
/**
* Fonction permettant de créer un label
*
* @param x
* @param y
* @param text
* @param color
* @param distance distance d'apparition
* @param textSize taille du texte
* @return distance à partir de laquelle apparaitra l'objet
*/
private static Group generateLabel(double x, double y, String text,
Color color, float distance, int textSize) {
// On prend une font de type Arial
Font3D f3d = new Font3D(new Font("Arial", Font.PLAIN, 1),
new FontExtrusion());
// On crée le texte 3D
Text3D t = new Text3D(f3d, text, new Point3f(0, 0, 0), Text3D.ALIGN_CENTER,
Text3D.PATH_RIGHT);
// On le dimensionne
Transform3D trans1 = new Transform3D();
trans1.setScale(new Vector3d(textSize, textSize, textSize / 3));
TransformGroup tg = new TransformGroup(trans1);
// On le place au bon endroit
Transform3D trans = new Transform3D();
trans.setTranslation(new Vector3d(x, y, 0));
TransformGroup tg2 = new TransformGroup(trans);
// On lui applique une apparence
Appearance ap = Level.generateApparence(color, 1, true);
Shape3D s = new Shape3D(t, ap);
// Create the transformgroup used for the billboard
TransformGroup billBoardGroup = new TransformGroup();
// Set the access rights to the group
billBoardGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
// Add the cube to the group
billBoardGroup.addChild(s);
// Gestion du Billboard pour le voir toujours de face
Billboard myBillboard = new Billboard(billBoardGroup,
Billboard.ROTATE_ABOUT_POINT, new Vector3f());
myBillboard.setSchedulingBounds(billBoardGroup.getBounds());
tg.addChild(billBoardGroup);
tg.addChild(myBillboard);
// Création d'un switch permettant de gérer le LOD (disparition lorsque
// l'objet est trop loin)
Switch targetSwitch = new Switch();
targetSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);
// add visual objects to the target switch
targetSwitch.addChild(tg);
BoundingSphere bounds = new BoundingSphere();
// create DistanceLOD object
float[] distances = { distance };
DistanceLOD dLOD = new DistanceLOD(distances);
dLOD.setSchedulingBounds(bounds);
dLOD.addSwitch(targetSwitch);
tg2.addChild(targetSwitch);
tg2.addChild(dLOD);
return tg2;
}
示例14: endDocument
import javax.media.j3d.Transform3D; //导入方法依赖的package包/类
@Override
public void endDocument() throws SAXException
{
for (Runnable runnable : this.postProcessingBinders)
{
runnable.run();
}
if (this.visualScene != null)
{
Transform3D rootTransform = new Transform3D();
this.visualScene.getTransform(rootTransform);
BoundingBox bounds = new BoundingBox(
new Point3d(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY),
new Point3d(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY));
computeBounds(this.visualScene, bounds, new Transform3D());
// Translate model to its center
Point3d lower = new Point3d();
bounds.getLower(lower);
if (lower.x != Double.POSITIVE_INFINITY)
{
Point3d upper = new Point3d();
bounds.getUpper(upper);
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));
translation.mul(rootTransform);
rootTransform = translation;
}
// Scale model to cm
Transform3D scaleTransform = new Transform3D();
scaleTransform.setScale(this.meterScale * 100);
scaleTransform.mul(rootTransform);
// Set orientation to Y_UP
Transform3D axisTransform = new Transform3D();
if ("Z_UP".equals(axis))
{
axisTransform.rotX(-Math.PI / 2);
}
else if ("X_UP".equals(axis))
{
axisTransform.rotZ(Math.PI / 2);
}
axisTransform.mul(scaleTransform);
this.visualScene.setTransform(axisTransform);
BranchGroup sceneRoot = new BranchGroup();
this.scene.setSceneGroup(sceneRoot);
sceneRoot.addChild(this.visualScene);
}
}
示例15: createIcon
import javax.media.j3d.Transform3D; //导入方法依赖的package包/类
/**
* Returns an icon created and scaled from piece model content.
*/
private Icon createIcon(BranchGroup modelNode, float pieceWidth, float pieceDepth, float pieceHeight)
{
// Add piece model scene to a normalized transform group
Transform3D scaleTransform = new Transform3D();
scaleTransform.setScale(new Vector3d(2 / pieceWidth, 2 / pieceHeight, 2 / pieceDepth));
TransformGroup modelTransformGroup = new TransformGroup();
modelTransformGroup.setTransform(scaleTransform);
modelTransformGroup.addChild(modelNode);
// Replace model textures by clones because Java 3D doesn't accept all the time
// to share textures between offscreen and onscreen environments
cloneTexture(modelNode, new IdentityHashMap<Texture, Texture>());
BranchGroup model = new BranchGroup();
model.setCapability(BranchGroup.ALLOW_DETACH);
model.addChild(modelTransformGroup);
sceneRoot.addChild(model);
// Render scene with a white background
Background background = (Background) sceneRoot.getChild(0);
background.setColor(1, 1, 1);
canvas3D.renderOffScreenBuffer();
canvas3D.waitForOffScreenRendering();
BufferedImage imageWithWhiteBackgound = canvas3D.getOffScreenBuffer().getImage();
int[] imageWithWhiteBackgoundPixels = getImagePixels(imageWithWhiteBackgound);
// Render scene with a black background
background.setColor(0, 0, 0);
canvas3D.renderOffScreenBuffer();
canvas3D.waitForOffScreenRendering();
BufferedImage imageWithBlackBackgound = canvas3D.getOffScreenBuffer().getImage();
int[] imageWithBlackBackgoundPixels = getImagePixels(imageWithBlackBackgound);
// Create an image with transparent pixels where model isn't drawn
for (int i = 0; i < imageWithBlackBackgoundPixels.length; i++)
{
if (imageWithBlackBackgoundPixels[i] != imageWithWhiteBackgoundPixels[i]
&& imageWithBlackBackgoundPixels[i] == 0xFF000000
&& imageWithWhiteBackgoundPixels[i] == 0xFFFFFFFF)
{
imageWithWhiteBackgoundPixels[i] = 0;
}
}
sceneRoot.removeChild(model);
return new ImageIcon(Toolkit.getDefaultToolkit()
.createImage(new MemoryImageSource(imageWithWhiteBackgound.getWidth(),
imageWithWhiteBackgound.getHeight(), imageWithWhiteBackgoundPixels, 0,
imageWithWhiteBackgound.getWidth())));
}