Package javax.vecmath

Examples of javax.vecmath.Color3f


  //the SimpleUniverse.
  public void createSceneGraph(SimpleUniverse su)
  {

    //A blue Appearance for the cube.
    Color3f ambientColourBox = new Color3f(0.0f,0.0f,0.7f);
    Color3f emissiveColourBox = new Color3f(0.0f,0.0f,0.0f);
    Color3f diffuseColourBox = new Color3f(0.0f,0.0f,0.7f);
    Color3f specularColourBox = new Color3f(0.0f,0.0f,0.8f);
    float shininessBox = 128.0f;

    Appearance boxApp = new Appearance();

    boxApp.setMaterial(new Material(ambientColourBox,emissiveColourBox,
                           diffuseColourBox,specularColourBox,shininessBox));


    //Generate the cube.
    float cubeHalfLength = 0.1f;
    Box moveBox = new Box(cubeHalfLength,cubeHalfLength,cubeHalfLength,boxApp);


    //The CollisionBounds for the cube.
    moveBox.setCollisionBounds(new BoundingBox(new Point3d(0.0,0.0,0.0),
                                               new Point3d(cubeHalfLength,
                                                           cubeHalfLength,
                                                           cubeHalfLength)));

    moveBox.setCollidable(true);

    //Position the cube and assign it to a transformation group.
    Transform3D tfBox = new Transform3D();
    tfBox.rotY(Math.PI/6);
    Transform3D rotationX = new Transform3D();
    rotationX.rotX(-Math.PI/5);
    tfBox.mul(rotationX);
    TransformGroup tgBox = new TransformGroup(tfBox);
    tgBox.addChild(moveBox);


    //These properties are needed to allow the cube to moved around the scene.
    tgBox.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    tgBox.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    tgBox.setCapability(TransformGroup.ENABLE_PICK_REPORTING);



    //Generate a golden Appearance for the cylinder.
    Color3f ambientColourCylinder = new Color3f(0.0f,0.0f,0.0f);
    Color3f emissiveColourCylinder = new Color3f(0.0f,0.0f,0.0f);
    Color3f diffuseColourCylinder = new Color3f(0.8f,0.4f,0.0f);
    Color3f specularColourCylinder = new Color3f(0.8f,0.8f,0.0f);
    float shininessCylinder = 100.0f;

    Appearance yellowCylinderApp = new Appearance();

    yellowCylinderApp.setMaterial(new Material(ambientColourCylinder,
                                               emissiveColourCylinder,
                                               diffuseColourCylinder,
                                               specularColourCylinder,
                                               shininessCylinder));


    //Generate the cylinder.
    Cylinder cyli = new Cylinder(0.1f,0.3f,yellowCylinderApp);

    //The CollisionBounds for the cylinder.
    cyli.setCollisionBounds(new BoundingBox(new Point3d(0.0,-0.15,0.0),
                                            new Point3d(0.1,0.15,0.1)));
    cyli.setCollidable(true);

    //Position the cylinder and assign it to a transformation group.
    Transform3D tfCylinder = new Transform3D();
    tfCylinder.mul(rotationX);
    Transform3D positionCyl = new Transform3D();
    positionCyl.setTranslation(new Vector3f(-0.7f,0.0f,0.0f));
    tfCylinder.mul(positionCyl);

    TransformGroup tgCylinder = new TransformGroup(tfCylinder);
    tgCylinder.addChild(cyli);

    //This transformation group is needed for the movement of the cylinder.
    TransformGroup tgmCyl = new TransformGroup();
    tgmCyl.addChild(tgCylinder);

    //The movement from left to right.
    Transform3D escape = new Transform3D();
    Alpha cylAlphaR = new Alpha(1,2000);

    //The starting time is first postponed until "infinity".
    cylAlphaR.setStartTime(Long.MAX_VALUE);

    //The interpolator for the movement.
    float maxRight = 0.5f;
    PositionInterpolator cylMoveR = new PositionInterpolator(cylAlphaR,tgmCyl,
                                                             escape,0.0f,maxRight);

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),Double.MAX_VALUE);
    cylMoveR.setSchedulingBounds(bounds);


    //The same for the movement from right to left.
    Alpha cylAlphaL = new Alpha(1,2000);
    cylAlphaL.setStartTime(Long.MAX_VALUE);

    PositionInterpolator cylMoveL = new PositionInterpolator(cylAlphaL,tgmCyl,
                                                             escape,maxRight,0.0f);

    cylMoveL.setSchedulingBounds(bounds);


    //Add the movements to the transformation group.
    tgmCyl.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    tgmCyl.addChild(cylMoveR);
    tgmCyl.addChild(cylMoveL);


    //A Switch for the green and the red sphere.
    Switch colourSwitch = new Switch();
    colourSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);

    //An Appearance for the green sphere.
    Color3f ambientColourGSphere = new Color3f(0.0f,0.8f,0.0f);
    Color3f emissiveColourGSphere = new Color3f(0.0f,0.0f,0.0f);
    Color3f diffuseColourGSphere = new Color3f(0.0f,0.8f,0.0f);
    Color3f specularColourGSphere = new Color3f(0.0f,0.8f,0.0f);
    float shininessGSphere = 1.0f;

    Appearance greenSphereApp = new Appearance();
    greenSphereApp.setMaterial(new Material(ambientColourGSphere,
                                            emissiveColourGSphere,
                                            diffuseColourGSphere,
                                            specularColourGSphere,
                                            shininessGSphere));

    //Generate the green sphere.
    float radius = 0.1f;
    Sphere greenSphere = new Sphere(radius,greenSphereApp);



    //The same for the red sphere.
    Color3f ambientColourRSphere = new Color3f(0.6f,0.0f,0.0f);
    Color3f emissiveColourRSphere = new Color3f(0.0f,0.0f,0.0f);
    Color3f diffuseColourRSphere = new Color3f(0.6f,0.0f,0.0f);
    Color3f specularColourRSphere = new Color3f(0.8f,0.0f,0.0f);
    float shininessRSphere = 20.0f;

    Appearance redSphereApp = new Appearance();

    redSphereApp.setMaterial(new Material(ambientColourRSphere,emissiveColourRSphere,
View Full Code Here


  {

    BranchGroup bgLight = new BranchGroup();

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
    Color3f lightColour1 = new Color3f(1.0f,1.0f,1.0f);
    Vector3f lightDir1  = new Vector3f(-1.0f,0.0f,-0.5f);
    DirectionalLight light1 = new DirectionalLight(lightColour1, lightDir1);
    light1.setInfluencingBounds(bounds);

    bgLight.addChild(light1);
View Full Code Here

    //Generate a copy of the chosen part.
    Shape3D extractedObject = (Shape3D) partOfTheObject.cloneTree();

    //Paint the part in blue.
    Appearance lightBlueApp = new Appearance();
    setToMyDefaultAppearance(lightBlueApp,new Color3f(0.0f,0.1f,0.3f));
    extractedObject.setAppearance(lightBlueApp);

    //Assign the chosen part to a transformation group.
    Transform3D tfObject = new Transform3D();
    tfObject.rotZ(0.4*Math.PI);
    Transform3D xRotation = new Transform3D();
    xRotation.rotY(0.4*Math.PI);
    tfObject.mul(xRotation);
    TransformGroup tgObject = new TransformGroup(tfObject);

    tgObject.addChild(extractedObject);

    BranchGroup theScene = new BranchGroup();

    //Add the transformation group with the blue part to the scene.
    theScene.addChild(tgObject);


    //The following four lines generate a white background.
    Background bg = new Background(new Color3f(1.0f,1.0f,1.0f));
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),Double.MAX_VALUE);
    bg.setApplicationBounds(bounds);
    theScene.addChild(bg);


View Full Code Here

  {

    BranchGroup bgLight = new BranchGroup();

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
    Color3f lightColour1 = new Color3f(1.0f,1.0f,1.0f);
    Vector3f lightDir1  = new Vector3f(-1.0f,0.0f,-0.5f);
    DirectionalLight light1 = new DirectionalLight(lightColour1, lightDir1);
    light1.setInfluencingBounds(bounds);

    bgLight.addChild(light1);
View Full Code Here

  {

//*** Generate a cube. ***

    //Generate an Appearance for the cube.
    Color3f ambientColourBox = new Color3f(0.8f,0.0f,0.0f);
    Color3f emissiveColourBox = new Color3f(0.0f,0.0f,0.0f);
    Color3f diffuseColourBox = new Color3f(0.8f,0.0f,0.0f);
    Color3f specularColourBox = new Color3f(1.0f,0.0f,0.0f);
    float shininessBox = 10.0f;

    Appearance boxApp = new Appearance();


    boxApp.setMaterial(new Material(ambientColourBox,emissiveColourBox,
                          diffuseColourBox,specularColourBox,shininessBox));




    Box myBox = new Box(0.2f,0.2f,0.2f,boxApp);

    //Rotate and shift the cube slightly.
    Transform3D tfBox = new Transform3D();
    tfBox.rotY(Math.PI/6);
    tfBox.rotX(Math.PI/9);
    Transform3D shift = new Transform3D();
    shift.setTranslation(new Vector3f(-0.6f,-0.2f,0.1f));
    tfBox.mul(shift);
    TransformGroup tgBox = new TransformGroup(tfBox);
    tgBox.addChild(myBox);




//***Generate a sphere ***

    //Generate an Appearance for the sphere.
    Color3f ambientColourSphere = new Color3f(0.2f,0.2f,0.0f);
    Color3f emissiveColourSphere = new Color3f(0.0f,0.0f,0.0f);
    Color3f diffuseColourSphere = new Color3f(0.4f,0.4f,0.0f);
    Color3f specularColourSphere = new Color3f(0.8f,0.8f,0.0f);
    float shininessSphere = 120.0f;

    Appearance sphereApp = new Appearance();

    sphereApp.setMaterial(new Material(ambientColourSphere,emissiveColourSphere,
                           diffuseColourSphere,specularColourSphere,shininessSphere));



    Sphere mySphere = new Sphere(0.3f,Sphere.GENERATE_NORMALS,100,sphereApp);
    Transform3D tfSphere = new Transform3D();
    tfSphere.setTranslation(new Vector3f(0.0f,0.0f,-1.0f));

    TransformGroup tgSphere = new TransformGroup(tfSphere);
    tgSphere.addChild(mySphere);




    //*** Generate (the root of) the scenegraph. ***
    BranchGroup theScene = new BranchGroup();


    //Add the cube and the sphere to the scene.
    theScene.addChild(tgBox);
    theScene.addChild(tgSphere);


    //Generate a white background.
    Background bg = new Background(new Color3f(1.0f,1.0f,1.0f));
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),Double.MAX_VALUE);
    bg.setApplicationBounds(bounds);
    theScene.addChild(bg);


View Full Code Here




    //Light no. 1: directional light.
    Color3f lightColour1 = new Color3f(0.8f, 0.8f, 0.8f);
    Vector3f lightDir1  = new Vector3f(0.0f, 4.0f, -1.0f);
    DirectionalLight light1 = new DirectionalLight(lightColour1, lightDir1);
    light1.setInfluencingBounds(bounds);
    bgLight.addChild(light1);



    //Light no. 2: a point light.
    Color3f lightColour2 = new Color3f(0.3f, 0.3f, 0.3f);
    PointLight light2 = new PointLight(lightColour2,
                                       new Point3f(1.0f,1.0f,1.0f),
                                       new Point3f(0.2f,0.01f,0.01f));
    light2.setInfluencingBounds(bounds);
    bgLight.addChild(light2);


    //Light no. 3: a spotlight.
    Color3f lightColour3 = new Color3f(0.3f, 0.3f, 0.3f);
    SpotLight light3 = new SpotLight(lightColour3,
                                     new Point3f(0.0f,0.0f,1.0f),
                                     new Point3f(0.1f,0.1f,0.01f),
                                     new Vector3f(0.0f,0.0f,-1.0f),
                                     (float) (Math.PI/20),
                                     0.0f);

    light3.setInfluencingBounds(bounds);
    bgLight.addChild(light3);



    //Light no. 4: ambient light.
    Color3f lightColour4 = new Color3f(0.2f, 0.2f, 0.2f);
    AmbientLight light4 = new AmbientLight(lightColour4);
    light4.setInfluencingBounds(bounds);
    bgLight.addChild(light4);

View Full Code Here

            System.out.println("Name: " + name);
        }

        // Assign the colour blue to the part named "flugdeck".
        Appearance lightBlueApp = new Appearance();
        setToMyDefaultAppearance(lightBlueApp, new Color3f(0.0f, 0.1f, 0.3f));
        Shape3D partOfTheObject = (Shape3D) namedObjects.get("flugdeck");
        partOfTheObject.setAppearance(lightBlueApp);

        BranchGroup theScene = new BranchGroup();

        theScene.addChild(tgObject);

        // The following four lines generate a white background.
        Background bg = new Background(new Color3f(1.0f, 1.0f, 1.0f));
        BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0),
                Double.MAX_VALUE);
        bg.setApplicationBounds(bounds);
        theScene.addChild(bg);
View Full Code Here

        BranchGroup bgLight = new BranchGroup();

        BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0),
                100.0);
        Color3f lightColour1 = new Color3f(1.0f, 1.0f, 1.0f);
        Vector3f lightDir1 = new Vector3f(-1.0f, 0.0f, -0.5f);
        DirectionalLight light1 = new DirectionalLight(lightColour1, lightDir1);
        light1.setInfluencingBounds(bounds);

        bgLight.addChild(light1);
View Full Code Here

    float sphereBackShift = -2.5f;//Shift of the spheres (forward/backward).
    float transparencyCoefficient = 0.8f;//Transparency coefficient.


    //The colours for the Appearance of the two cubes.
    Color3f ambientColourFBox = new Color3f(0.3f,0.0f,0.0f);
    Color3f emissiveColourFBox = new Color3f(0.0f,0.0f,0.0f);
    Color3f diffuseColourFBox = new Color3f(0.6f,0.0f,0.0f);
    Color3f specularColourFBox = new Color3f(0.8f,0.0f,0.0f);
    float shininessFBox = 128.0f;


    //The Appearance for the left cube.
    Appearance fBoxApp1 = new Appearance();

    fBoxApp1.setMaterial(new Material(ambientColourFBox,emissiveColourFBox,
                          diffuseColourFBox,specularColourFBox,shininessFBox));

    //Generate interpolated transparency.
    TransparencyAttributes ta1 = new TransparencyAttributes();
    ta1.setTransparencyMode(TransparencyAttributes.BLENDED);
    ta1.setTransparency(transparencyCoefficient);

    fBoxApp1.setTransparencyAttributes(ta1);


    //Generate a cube with interpolated transparency.
    Box fBox1 = new Box(cubeEdge,cubeEdge,cubeEdge,fBoxApp1);


    //Position the cube.
    Transform3D tfFBox1 = new Transform3D();
    Transform3D rotationX = new Transform3D();
    rotationX.rotX(-Math.PI/5);
    tfFBox1.mul(rotationX);

    //The transformation group for the cube.
    TransformGroup tgFBox1 = new TransformGroup(tfFBox1);
    tgFBox1.addChild(fBox1);



    //Generate a nontransparent Appearance for the spheres.
    Color3f ambientColourBSphere = new Color3f(0.0f,0.7f,0.0f);
    Color3f emissiveColourBSphere = new Color3f(0.0f,0.0f,0.0f);
    Color3f diffuseColourBSphere = new Color3f(0.0f,0.7f,0.0f);
    Color3f specularColourBSphere = new Color3f(0.0f,0.9f,0.0f);
    float shininessBSphere = 120.0f;

    Appearance bSphereApp = new Appearance();

    bSphereApp.setMaterial(new Material(ambientColourBSphere,emissiveColourBSphere,
                          diffuseColourBSphere,specularColourBSphere,shininessBSphere));

    //The left sphere and its transformation group.
    Sphere bSphere1 = new Sphere(radius,bSphereApp);

    Transform3D tfBSphere1 = new Transform3D();
    tfBSphere1.setTranslation(new Vector3f(xShiftSphere,sphereLift,sphereBackShift));
    TransformGroup tgBSphere1 = new TransformGroup(tfBSphere1);
    tgBSphere1.addChild(bSphere1);


    //The left cube and the left sphere are combined in one transformation group
    //in order to position them jointly.
    Transform3D tf1 = new Transform3D();
    tf1.setTranslation(new Vector3f(-xShift,0.0f,0.0f));
    TransformGroup tg1 = new TransformGroup(tf1);
    tg1.addChild(tgFBox1);
    tg1.addChild(tgBSphere1);


    //The right cube with sreen door transparency.
    Appearance fBoxApp2 = new Appearance();
    fBoxApp2.setMaterial(new Material(ambientColourFBox,emissiveColourFBox,
                          diffuseColourFBox,specularColourFBox,shininessFBox));

    //Generate screen door transparency.
    TransparencyAttributes ta2 = new TransparencyAttributes();
    ta2.setTransparencyMode(TransparencyAttributes.SCREEN_DOOR);
    ta2.setTransparency(transparencyCoefficient);

    fBoxApp2.setTransparencyAttributes(ta2);

    Box fBox2 = new Box(cubeEdge,cubeEdge,cubeEdge,fBoxApp2);


    //Position the cube.
    Transform3D tfFBox2 = new Transform3D();
    tfFBox2.mul(rotationX);
    TransformGroup tgFBox2 = new TransformGroup(tfFBox2);

    //The transformation group for the right cube.
    tgFBox2.addChild(fBox2);


    //The right sphere and its transformation group.
    Sphere bSphere2 = new Sphere(radius,bSphereApp);
    Transform3D tfBSphere2 = new Transform3D();
    tfBSphere2.setTranslation(new Vector3f(-xShiftSphere,sphereLift,sphereBackShift));
    TransformGroup tgBSphere2 = new TransformGroup(tfBSphere2);
    tgBSphere2.addChild(bSphere2);



    //The right cube and the right sphere are combined in one transformation group
    //in order to position them jointly.
    Transform3D tf2 = new Transform3D();
    tf2.setTranslation(new Vector3f(xShift,0.0f,0.0f));
    TransformGroup tg2 = new TransformGroup(tf2);
    tg2.addChild(tgFBox2);
    tg2.addChild(tgBSphere2);




    //Add everything to the scene.
    BranchGroup theScene = new BranchGroup();;
    theScene.addChild(tg1);
    theScene.addChild(tg2);


    //Generate a white background.
    Background bg = new Background(new Color3f(1.0f,1.0f,1.0f));
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),Double.MAX_VALUE);
    bg.setApplicationBounds(bounds);
    theScene.addChild(bg);

View Full Code Here

    BranchGroup bgLight = new BranchGroup();

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),Double.MAX_VALUE);

    //Directional light.
    Color3f lightColour1 = new Color3f(1.0f,1.0f,1.0f);
    Vector3f lightDir1  = new Vector3f(0.0f,0.0f,-0.1f);
    DirectionalLight light1 = new DirectionalLight(lightColour1, lightDir1);
    light1.setInfluencingBounds(bounds);

    bgLight.addChild(light1);


    //Ambient light.
    Color3f lightColour2 = new Color3f(0.5f, 0.5f, 0.5f);
    AmbientLight light2 = new AmbientLight(lightColour2);
    light2.setInfluencingBounds(bounds);
    bgLight.addChild(light2);

View Full Code Here

TOP

Related Classes of javax.vecmath.Color3f

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.