本文整理汇总了Java中javax.media.j3d.Transform3D类的典型用法代码示例。如果您正苦于以下问题:Java Transform3D类的具体用法?Java Transform3D怎么用?Java Transform3D使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Transform3D类属于javax.media.j3d包,在下文中一共展示了Transform3D类的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: zoomOn
import javax.media.j3d.Transform3D; //导入依赖的package包/类
/**
* Permet de déplacer de manière à centrer sur le point P(x y z )
* @param x
* @param y
* @param z
* @param direction
* Il s'agit de la direction dans laquelle est regardée le
* point. La caméra se trouvera à la translation vecteur appliqué à P
* La norme du vecteur indique la distance entre la caméra et le
* point
*/
public void zoomOn(double x, double y, double z, Vecteur direction) {
Transform3D viewTrans = new Transform3D();
if (direction == null) {
return;
}
if (direction.norme() == 0) {
return;
}
// point the view at the center of the object
Point3d center = new Point3d(x + this.translate.x, y + this.translate.y, z + this.translate.z);
Point3d eyePos = new Point3d(x + this.translate.x + direction.getX(), y + this.translate.y
+ direction.getY(), z + this.translate.z + direction.getZ());
viewTrans.setIdentity();
viewTrans.lookAt(eyePos, center, new Vector3d(0, 0, 1));
// set the view transform
viewTrans.invert();
InterfaceMap3D.tgvu.setTransform(viewTrans);
}
示例3: writeVertex
import javax.media.j3d.Transform3D; //导入依赖的package包/类
/**
* Applies to <code>vertex</code> the given transformation, and writes it in
* a line v at OBJ format, if the vertex wasn't written yet.
*/
private void writeVertex(Transform3D transformationToParent,
Point3f vertex, int index,
int [] vertexIndexSubstitutes) throws IOException {
transformationToParent.transform(vertex);
Integer vertexIndex = this.vertexIndices.get(vertex);
if (vertexIndex == null) {
vertexIndexSubstitutes [index] = this.vertexIndices.size() + 1;
this.vertexIndices.put(vertex, vertexIndexSubstitutes [index]);
// Write only once unique vertices
this.out.write("v " + format(vertex.x)
+ " " + format(vertex.y)
+ " " + format(vertex.z) + "\n");
} else {
vertexIndexSubstitutes [index] = vertexIndex;
}
}
示例4: isOrthogonalRotation
import javax.media.j3d.Transform3D; //导入依赖的package包/类
/**
* Returns <code>true</code> if the rotation matrix matches only rotations of
* a multiple of 90� degrees around x, y or z axis.
*/
private boolean isOrthogonalRotation(Transform3D transformation)
{
Matrix3f matrix = new Matrix3f();
transformation.get(matrix);
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
// Return false if the matrix contains a value different from 0 1 or -1
if (Math.abs(matrix.getElement(i, j)) > 1E-6 && Math.abs(matrix.getElement(i, j) - 1) > 1E-6
&& Math.abs(matrix.getElement(i, j) + 1) > 1E-6)
{
return false;
}
}
}
return true;
}
示例5: parseMatrix
import javax.media.j3d.Transform3D; //导入依赖的package包/类
/**
* Returns the matrix read from the current chunk.
*/
private Transform3D parseMatrix(ChunksInputStream in) throws IOException
{
float[] matrix = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
matrix[0] = in.readLittleEndianFloat();
matrix[4] = in.readLittleEndianFloat();
matrix[8] = in.readLittleEndianFloat();
matrix[1] = in.readLittleEndianFloat();
matrix[5] = in.readLittleEndianFloat();
matrix[9] = in.readLittleEndianFloat();
matrix[2] = in.readLittleEndianFloat();
matrix[6] = in.readLittleEndianFloat();
matrix[10] = in.readLittleEndianFloat();
matrix[3] = in.readLittleEndianFloat();
matrix[7] = in.readLittleEndianFloat();
matrix[11] = in.readLittleEndianFloat();
return new Transform3D(matrix);
}
示例6: writeVertex
import javax.media.j3d.Transform3D; //导入依赖的package包/类
/**
* Applies to <code>vertex</code> the given transformation, and writes it in
* a line v at OBJ format, if the vertex wasn't written yet.
*/
private void writeVertex(Transform3D transformationToParent, Point3f vertex, int index,
int[] vertexIndexSubstitutes) throws IOException
{
transformationToParent.transform(vertex);
Integer vertexIndex = this.vertexIndices.get(vertex);
if (vertexIndex == null)
{
vertexIndexSubstitutes[index] = this.vertexIndices.size() + 1;
this.vertexIndices.put(vertex, vertexIndexSubstitutes[index]);
// Write only once unique vertices
this.out.write("v " + format(vertex.x) + " " + format(vertex.y) + " " + format(vertex.z) + "\n");
}
else
{
vertexIndexSubstitutes[index] = vertexIndex;
}
}
示例7: updateViewPlatformTransform
import javax.media.j3d.Transform3D; //导入依赖的package包/类
/**
* Updates <code>viewPlatformTransform</code> transform from <code>camera</code> angles and location.
*/
private void updateViewPlatformTransform(TransformGroup viewPlatformTransform, Camera camera,
boolean updateWithAnimation)
{
if (updateWithAnimation)
{
// Get the camera interpolator
CameraInterpolator cameraInterpolator = (CameraInterpolator) viewPlatformTransform
.getChild(viewPlatformTransform.numChildren() - 1);
cameraInterpolator.moveCamera(camera);
}
else
{
Transform3D transform = new Transform3D();
updateViewPlatformTransform(transform, camera.getX(), camera.getY(), camera.getZ(), camera.getYaw(),
camera.getPitch());
viewPlatformTransform.setTransform(transform);
}
clearPrintedImageCache();
}
示例8: 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);
}
示例9: 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");
}
}
示例10: RangeSensorBelt
import javax.media.j3d.Transform3D; //导入依赖的package包/类
/**
* Constructs a RangeSensorBelt. The sensor type can be either
* TYPE_BUMPER,TYPE_SONAR,TYPE_IR or TYPE_LASER. Ranges are measured from
* the belt perimeter (not from the belt center).
*
* @param radius
* - the radius of the belt.
* @param minRange
* - the minimal range of each sensor ray. Not used for
* TYPE_BUMPER.
* @param maxRange
* - the maximal range of each sensor ray. Not used for
* TYPE_BUMPER.
* @param nbsensors
* - the number of sensors in the belt (typically 4,6,12,24 or
* 36).
* @param type
* - to specify the sensor behavior
*/
public RangeSensorBelt(float radius, float minRange, float maxRange, int nbsensors, int type, int flags) {
// compute angles ,positions , directions
positions = new Vector3d[nbsensors];
directions = new Vector3d[nbsensors];
Vector3d frontPos = new Vector3d(radius, 0, 0);
Vector3d frontDir = new Vector3d(maxRange, 0, 0);
angles = new double[nbsensors];
Transform3D transform = new Transform3D();
for (int i = 0; i < nbsensors; i++) {
angles[i] = i * 2 * Math.PI / nbsensors;
transform.setIdentity();
transform.rotY(angles[i]);
Vector3d pos = new Vector3d(frontPos);
transform.transform(pos);
positions[i] = pos;
Vector3d dir = new Vector3d(frontDir);
transform.transform(dir);
directions[i] = dir;
}
initialize(radius, maxRange, nbsensors, type, flags);
}
示例11: 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;
}
示例12: lookupTransform
import javax.media.j3d.Transform3D; //导入依赖的package包/类
public Transform lookupTransform(String target_frame, String source_frame,
long time) throws TransformerException {
synchronized (lock) {
if (target_frame == source_frame) {
long newTime = 0;
if (time == 0) {
int target_id = lookupFrameNumber(target_frame);
TransformCache cache = getFrame(target_id);
if (cache.isValid())
newTime = cache.getLatestTimestamp();
else
newTime = time;
} else
newTime = time;
Transform3D t = new Transform3D();
Transform identity = new Transform(t, target_frame,
source_frame, newTime);
return identity;
}
return lookupTransformNoLock(target_frame, source_frame, time);
}
}
示例13: lookupTransformNoLock
import javax.media.j3d.Transform3D; //导入依赖的package包/类
private Transform lookupTransformNoLock(String target_frame,
String source_frame, long time) throws TransformerException {
// Identify case does not need to be validated above
int target_id = validateFrameId(
"lookupTransform argument target_frame", target_frame);
int source_id = validateFrameId(
"lookupTransform argument source_frame", source_frame);
TransformAccumImpl accum = new TransformAccumImpl();
try {
walkToTopParent(accum, time, target_id, source_id);
} catch(TransformerException e) {
throw new TransformerException("No matching transform found", e);
}
Transform3D t3d = new Transform3D(accum.result_quat, accum.result_vec,
1.0);
Transform output_transform = new Transform(t3d, target_frame,
source_frame, accum.time);
return output_transform;
}
示例14: convertPbToTransform
import javax.media.j3d.Transform3D; //导入依赖的package包/类
private Transform convertPbToTransform(FrameTransform t) {
Timestamp time = t.getTime();
long timeUSec = time.getTime();
long timeMSec = timeUSec / 1000l;
Rotation rstRot = t.getTransform().getRotation();
Translation rstTrans = t.getTransform().getTranslation();
Quat4d quat = new Quat4d(rstRot.getQx(), rstRot.getQy(), rstRot.getQz(), rstRot.getQw());
Vector3d vec = new Vector3d(rstTrans.getX(), rstTrans.getY(), rstTrans.getZ());
Transform3D transform3d = new Transform3D(quat, vec, 1.0);
Transform newTrans = new Transform(transform3d, t.getFrameParent(), t.getFrameChild(),
timeMSec);
return newTrans;
}
示例15: 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);
}