javax.media.j3d.TransformGroup Java Examples

The following examples show how to use javax.media.j3d.TransformGroup. 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: Java3DWindow.java    From GpsPrune with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a text object for compass point, N S E or W
 * @param inText text to display
 * @param inLocn position at which to display
 * @param inFont 3d font to use
 * @return compound object
 */
private TransformGroup createCompassPoint(String inText, Point3f inLocn, Font3D inFont)
{
	Text3D txt = new Text3D(inFont, inText, inLocn, Text3D.ALIGN_FIRST, Text3D.PATH_RIGHT);
	Material mat = new Material(new Color3f(0.5f, 0.5f, 0.55f),
		new Color3f(0.05f, 0.05f, 0.1f), new Color3f(0.3f, 0.4f, 0.5f),
		new Color3f(0.4f, 0.5f, 0.7f), 70.0f);
	mat.setLightingEnable(true);
	Appearance app = new Appearance();
	app.setMaterial(mat);
	Shape3D shape = new Shape3D(txt, app);

	// Make transform group with billboard behaviour
	TransformGroup subGroup = new TransformGroup();
	subGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
	subGroup.addChild(shape);
	Billboard billboard = new Billboard(subGroup, Billboard.ROTATE_ABOUT_POINT, inLocn);
	BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
	billboard.setSchedulingBounds(bounds);
	subGroup.addChild(billboard);
	return subGroup;
}
 
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: Ball.java    From javagame with MIT License 6 votes vote down vote up
public Ball(double x, double y, double z, double vx, double vy, double vz) {
    position = new Vector3d(x, y, z);
    speed = new Vector3d(vx, vy, vz);

    // �ړ��”\
    this.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    this.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    app = new Appearance();
    app.setTexture(loadTexture("carpet.jpg"));

    // �{�[����lj�
    this.addChild(new Sphere(radius, Sphere.GENERATE_TEXTURE_COORDS, 100, app));

    move();
}
 
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: Ball.java    From javagame with MIT License 6 votes vote down vote up
public Ball(double x, double y, double z) {
    position = new Vector3d(x, y, z);
    velocity = new Vector3d(0, 0, 0);
    acceleration = new Vector3d(0, -0.01, 0);  // �����x�͈��
    
    // �ړ��”\
    this.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    this.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    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.2f);
    app.setTransparencyAttributes(transAttr);

    // �{�[����lj�
    this.addChild(new Sphere(radius, Sphere.GENERATE_NORMALS, 100, app));

    move();
}
 
Example #6
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 #7
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 #8
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 #9
Source File: Main3D.java    From javagame with MIT License 5 votes vote down vote up
/**
 * �V�[�����\�z����
 * @return BG
 */
public BranchGroup createSceneGraph() {
    BranchGroup bg = new BranchGroup();

    // ��]�pTG
    TransformGroup spinTG = new TransformGroup();
    spinTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    // ��]�^��
    Alpha rotationAlpha = new Alpha(-1, 4000);
    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha,
            spinTG);

    // �͈͂��w��
    BoundingSphere bounds = new BoundingSphere();
    rotator.setSchedulingBounds(bounds);

    spinTG.addChild(rotator);

    // �g���C�t�H�[�X
    Triforce triforce = new Triforce();
    spinTG.addChild(triforce.getBG()); // spinTG�ɒlj��I

    bg.addChild(spinTG);

    return bg;
}
 
Example #10
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 #11
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 #12
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 #13
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;
}