javax.media.j3d.Transform3D Java Examples

The following examples show how to use javax.media.j3d.Transform3D. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainPanel.java    From javagame with MIT License 6 votes vote down vote up
/**
 * ���[�U�̎��_��������
 */
private void initUserPosition() {
    ViewingPlatform vp = universe.getViewingPlatform(); // SimpleUniverse�̃f�t�H���g���擾
    TransformGroup steerTG = vp.getViewPlatformTransform(); // vp��TG���擾

    Transform3D t3d = new Transform3D(); // ���_�ivp�j�ړ��p��T3D
    steerTG.getTransform(t3d); // ���݂̎��_���擾

    // �V�������_��ݒ�
    // ���[�U�̈ʒu�A������̍��W�A�������w��
    // ���_�̐�͌��_
    t3d.lookAt(USER_POS, new Point3d(0, 0, 0), new Vector3d(0, 1, 0));
    t3d.invert();

    steerTG.setTransform(t3d); // �ύX�������_��ݒ�
}
 
Example #2
Source File: MainPanel.java    From javagame with MIT License 6 votes vote down vote up
/**
 * ���[�U�̎��_��������
 */
private void initUserPosition() {
    ViewingPlatform vp = universe.getViewingPlatform(); // SimpleUniverse�̃f�t�H���g���擾
    TransformGroup steerTG = vp.getViewPlatformTransform(); // vp��TG���擾

    Transform3D t3d = new Transform3D(); // ���_�ivp�j�ړ��p��T3D
    steerTG.getTransform(t3d); // ���݂̎��_���擾

    // �V�������_��ݒ�
    // ���[�U�̈ʒu�A������̍��W�A�������w��
    // ���_�̐�͌��_
    t3d.lookAt(USER_POS, new Point3d(0, 0, 0), new Vector3d(0, 1, 0));
    t3d.invert();

    steerTG.setTransform(t3d); // �ύX�������_��ݒ�
}
 
Example #3
Source File: Main.java    From javagame with MIT License 6 votes vote down vote up
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);
}
 
Example #4
Source File: MainPanel.java    From javagame with MIT License 6 votes vote down vote up
/**
 * ���[�U�̎��_��������
 */
private void initUserPosition() {
    ViewingPlatform vp = universe.getViewingPlatform(); // SimpleUniverse�̃f�t�H���g���擾
    TransformGroup steerTG = vp.getViewPlatformTransform(); // vp��TG���擾

    Transform3D t3d = new Transform3D(); // ���_�ivp�j�ړ��p��T3D
    steerTG.getTransform(t3d); // ���݂̎��_���擾

    // �V�������_��ݒ�
    // ���[�U�̈ʒu�A������̍��W�A�������w��
    // ���_�̐�͌��_
    t3d.lookAt(USER_POS, new Point3d(0, 0, 0), new Vector3d(0, 1, 0));
    t3d.invert();

    steerTG.setTransform(t3d); // �ύX�������_��ݒ�
}
 
Example #5
Source File: Helper.java    From MogwaiERDesignerNG with GNU General Public License v3.0 5 votes vote down vote up
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;
    }
 
Example #6
Source File: Java3DWindow.java    From GpsPrune with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a ball at the given point
 * @param inPosition scaled position of point
 * @param inSphere sphere object
 * @param inMaterial material object
 * @return Group containing sphere
 */
private static Group createBall(Point3d inPosition, Sphere inSphere, Material inMaterial)
{
	Group group = new Group();
	// Create ball and add to group
	Transform3D ballShift = new Transform3D();
	ballShift.setTranslation(new Vector3d(inPosition));
	TransformGroup ballShiftTrans = new TransformGroup(ballShift);
	inMaterial.setLightingEnable(true);
	Appearance ballApp = new Appearance();
	ballApp.setMaterial(inMaterial);
	inSphere.setAppearance(ballApp);
	ballShiftTrans.addChild(inSphere);
	group.addChild(ballShiftTrans);
	// Also create rod for ball to sit on
	Cylinder rod = new Cylinder(0.1f, (float) inPosition.y);
	Material rodMat = new Material(new Color3f(0.2f, 0.2f, 0.2f),
		new Color3f(0.0f, 0.0f, 0.0f), new Color3f(0.2f, 0.2f, 0.2f),
		new Color3f(0.05f, 0.05f, 0.05f), 0.4f);
	rodMat.setLightingEnable(true);
	Appearance rodApp = new Appearance();
	rodApp.setMaterial(rodMat);
	rod.setAppearance(rodApp);
	Transform3D rodShift = new Transform3D();
	rodShift.setTranslation(new Vector3d(inPosition.x, inPosition.y/2.0, inPosition.z));
	TransformGroup rodShiftTrans = new TransformGroup(rodShift);
	rodShiftTrans.addChild(rod);
	group.addChild(rodShiftTrans);
	// return the pair
	return group;
}
 
Example #7
Source File: Java3DWindow.java    From GpsPrune with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Calculate the angles and call them back to the app
 * @param inFunction function to call for export
 */
private void callbackRender(Export3dFunction inFunction)
{
	Transform3D trans3d = new Transform3D();
	_orbit.getViewingPlatform().getViewPlatformTransform().getTransform(trans3d);
	Matrix3d matrix = new Matrix3d();
	trans3d.get(matrix);
	Point3d point = new Point3d(0.0, 0.0, 1.0);
	matrix.transform(point);
	// Set up initial rotations
	Transform3D firstTran = new Transform3D();
	firstTran.rotY(Math.toRadians(-INITIAL_Y_ROTATION));
	Transform3D secondTran = new Transform3D();
	secondTran.rotX(Math.toRadians(-INITIAL_X_ROTATION));
	// Apply inverse rotations in reverse order to the test point
	Point3d result = new Point3d();
	secondTran.transform(point, result);
	firstTran.transform(result);

	// Give the settings to the rendering function
	inFunction.setCameraCoordinates(result.x, result.y, result.z);
	inFunction.setAltitudeExaggeration(_altFactor);
	inFunction.setTerrainDefinition(_terrainDefinition);
	inFunction.setImageDefinition(_imageDefinition);

	inFunction.begin();
}
 
Example #8
Source File: MainPanel.java    From javagame with MIT License 5 votes vote down vote up
/**
 * ����sceneBG�ɒlj�
 */
private void addSphere() {
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f); // ��
    Color3f red = new Color3f(1.0f, 0.0f, 0.0f); // ��
    Color3f specular = new Color3f(0.9f, 0.9f, 0.9f); // �قڔ�

    // ���̍ގ��iMaterial�j
    Material blueMat = new Material(red, black, red, specular, 25.0f);
    blueMat.setLightingEnable(true);

    // ���̌����ځiAppearance�j
    Appearance blueApp = new Appearance();
    blueApp.setMaterial(blueMat);

    // ���̈ړ�
    Transform3D t3d = new Transform3D();
    t3d.set(new Vector3f(0, 0, 0));  // ���_�ֈړ�����T3D

    // �ړ����]�p�̃m�[�h��TG�iT3D���Z�b�g���Ďg���j
    TransformGroup tg = new TransformGroup(t3d);
    // �����쐬
    Sphere sphere = new Sphere(2.0f, Sphere.GENERATE_NORMALS, 100, blueApp);
    tg.addChild(sphere);  // �ړ��pTG�ɋ���ڑ�����I

    // sceneBG�ɋ����܂�TG��lj�
    sceneBG.addChild(tg);
}
 
Example #9
Source File: RotatingCube.java    From javagame with MIT License 5 votes vote down vote up
public BranchGroup createSceneGraph() {
    BranchGroup bg = new BranchGroup();

    // �L���[�u���X����
    Transform3D rotate = new Transform3D();
    Transform3D tempRotate = new Transform3D();

    rotate.rotX(Math.PI / 4.0);
    tempRotate.rotY(Math.PI / 4.0);
    rotate.mul(tempRotate);

    TransformGroup rotateTG = new TransformGroup(rotate);

    // �L���[�u����]����
    TransformGroup spinTG = new TransformGroup();
    spinTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    // �J���[�L���[�u���쐬����spinTG�ɒlj�
    ColorCube cube = new ColorCube(0.4);
    spinTG.addChild(cube);

    // ��]�^��
    Alpha rotationAlpha = new Alpha(-1, 4000);
    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, spinTG);
    // �͈͂��w��
    BoundingSphere bounds = new BoundingSphere();
    rotator.setSchedulingBounds(bounds);
    spinTG.addChild(rotator);

    rotateTG.addChild(spinTG);
    bg.addChild(rotateTG);

    return bg;
}
 
Example #10
Source File: KinematicObject.java    From jMAVSim with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public KinematicObject(World world) {
    super(world);
    rotation.setIdentity();
    transformGroup = new TransformGroup();
    transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    transform = new Transform3D();
    transformGroup.setTransform(transform);
    branchGroup = new BranchGroup();
    branchGroup.addChild(transformGroup);
}
 
Example #11
Source File: CrystalBall.java    From javagame with MIT License 4 votes vote down vote up
/**
 * �V�[�����\�z����
 * 
 * @return BG
 */
public BranchGroup createSceneGraph() {
    BranchGroup bg = new BranchGroup();

    // �O�~
    Appearance app = new Appearance();
    app.setTexture(loadTexture("carpet.jpg"));  // �O�~�̃e�N�X�`��
    Box floor = new Box(0.8f, 0.01f, 0.8f, Box.GENERATE_TEXTURE_COORDS, app);

    // ������
    app = new Appearance();
    Material mat = new Material();
    mat.setAmbientColor(new Color3f(0.0f, 0.0f, 1.0f));
    mat.setSpecularColor(new Color3f(1.0f, 1.0f, 1.0f));
    app.setMaterial(mat);

    TransparencyAttributes transAttr = new TransparencyAttributes(
            TransparencyAttributes.BLENDED, 0.5f);
    app.setTransparencyAttributes(transAttr);

    Sphere sphere = new Sphere(0.3f, Sphere.GENERATE_NORMALS, 100, app);

    // �������ړ��p
    Transform3D t3d = new Transform3D();
    t3d.set(new Vector3f(0.0f, 0.3f, 0.0f));
    TransformGroup tg = new TransformGroup(t3d);
    tg.addChild(sphere);

    bg.addChild(floor);
    bg.addChild(tg);
    
    // ����
    BoundingSphere bounds = new BoundingSphere();

    Light light = new AmbientLight();
    light.setInfluencingBounds(bounds);
    bg.addChild(light);

    light = new DirectionalLight(new Color3f(1.0f, 1.0f, 1.0f), new Vector3f(1.0f, -1.0f, -1.0f));
    light.setInfluencingBounds(bounds);
    bg.addChild(light);

    return bg;
}