Package javax.vecmath

Examples of javax.vecmath.Vector3f


      ((BoundingSphere)bounds).getCenter(center);
      Transform3D tr = new Transform3D();
      tr.setScale(10.0/((BoundingSphere)bounds).getRadius());
      Transform3D tr2 = new Transform3D();
      center.negate();
      tr2.setTranslation(new Vector3f(center));
      tr.mul(tr2);
      transformGroup.setTransform(tr);
    }

    // Cleanup file name, use it for this node
View Full Code Here


    public static class LightDirection extends Tuple3fData {
        static final long serialVersionUID = 8457451778478954317L;
        public void apply() {
            super.apply();
            Vector3f v=new Vector3f((float)params[0], (float)params[1], (float)params[2]);
            for (GraphObjectReference o : getReferences()) {
                if(o.getObject() instanceof DirectionalLight){
                    ((DirectionalLight)o.getObject()).setDirection(v);
                }
                else if(o.getObject() instanceof SpotLight){
View Full Code Here

            }
            points.add(new Point3f((float)x, (float)y, (float)z));
        }
       
        void setNormal(double x, double y, double z){
            normals.add(new Vector3f((float)x, (float)y, (float)z));
        }
View Full Code Here

     */
    public static float[] calculateNormals(float[] coord, int[] idx) {

        float normal[] = new float[coord.length];

        Vector3f v1 = new Vector3f();
        Vector3f v2 = new Vector3f();
        Vector3f faceNormal = new Vector3f();
        Point3f a = new Point3f();
        Point3f b = new Point3f();
        Point3f c = new Point3f();
        // step through all the faces
        for (int i=0; i<idx.length; i+=3) {

          int ja = idx[i] * 3;
            a.set(coord[ja],coord[ja+1],coord[ja+2]);
            int jb = idx[i+1] * 3;
            b.set(coord[jb],coord[jb+1],coord[jb+2]);
            int jc = idx[i+2] * 3;
            c.set(coord[jc],coord[jc+1],coord[jc+2]);

            v1.sub(b, a);
            v2.sub(c, a);
            faceNormal.cross(v1, v2);
            if (faceNormal.length()==0) continue;
            faceNormal.normalize();

            // suppose the faces are nearly flat, with small deflection
            // check the scalar product is >0, so each face is the same orientation
            // otherwise, reverse the normal
            float scalara = normal[ja] * faceNormal.x + normal[ja+1] * faceNormal.y + normal[ja+2] * faceNormal.z;
 
View Full Code Here

    // 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);
   
View Full Code Here

      if (tokenizer.nextToken() == StreamTokenizer.TT_EOL) {
        tokenizer.pushBack();
      }
    } else if ("vn".equals(tokenizer.sval)) {
      // Read normal vn x y z
      this.normals.add(new Vector3f(
          parseNumber(tokenizer), parseNumber(tokenizer), parseNumber(tokenizer)));     
    } else if ("vt".equals(tokenizer.sval)) {
      // Read texture coordinate vt x y
      //                       or vt x y z
      this.textureCoodinates.add(new TexCoord2f(
View Full Code Here

            }
            return;
          }
         
          BranchGroup model = null;
          Vector3f    modelSize = null;
          try {
            model = readModel(modelContent);
            modelSize = ModelManager.getInstance().getSize(model);
            // Copy model to a temporary OBJ content with materials and textures
            modelContent = copyToTemporaryOBJContent(model, modelName);
          } catch (IOException ex) {
            model = null;
          } catch (IllegalArgumentException ex) {
            // Model is empty
            model = null;
          }
         
          if (model == null) {
            try {
              // Copy model content to a temporary content
              modelContent = TemporaryURLContent.copyToTemporaryURLContent(modelContent);
            } catch (IOException ex2) {
              if (!ignoreException) {
                showModelChoiceError(modelName, preferences);
              }
              return;
            }
           
            // If content couldn't be loaded, try to load model as a zipped file
            ZipInputStream zipIn = null;
            try {
              URLContent urlContent = (URLContent)modelContent;
              // Open zipped stream
              zipIn = new ZipInputStream(urlContent.openStream());
              // Parse entries to see if one is readable
              for (ZipEntry entry; (entry = zipIn.getNextEntry()) != null; ) {
                try {
                  String entryName = entry.getName();
                  // Ignore directory entries and entries starting by a dot
                  if (!entryName.endsWith("/")) {
                    int slashIndex = entryName.lastIndexOf('/');
                    String entryFileName = entryName.substring(++slashIndex);
                    if (!entryFileName.startsWith(".")) {
                      URL entryUrl = new URL("jar:" + urlContent.getURL() + "!/"
                          + URLEncoder.encode(entryName, "UTF-8").replace("+", "%20").replace("%2F", "/"));
                      modelContent = new TemporaryURLContent(entryUrl);
                      model = readModel(modelContent);
                      modelSize = ModelManager.getInstance().getSize(model);
                      break;
                    }
                  }
                } catch (IOException ex3) {
                  // Ignore exception and try next entry
                  model = null;
                } catch (IllegalArgumentException ex3) {
                  // Model is empty
                  model = null;
                }
              }
            } catch (IOException ex2) {
              model = null;
            } finally {
              try {
                if (zipIn != null) {
                  zipIn.close();
                }
              } catch (IOException ex2) {
                // Ignore close exception
              }
            }
          }
         
          final BranchGroup readModel = model;
          final Vector3f    readModelSize = modelSize;
          final Content     readContent = modelContent;
          // Update components in dispatch thread
          EventQueue.invokeLater(new Runnable() {
              public void run() {
                if (readModel != null) {
View Full Code Here

    Transform3D pitchRotation = new Transform3D();
    pitchRotation.rotX(-cameraPitch);
    yawRotation.mul(pitchRotation);
   
    transform.setIdentity();
    transform.setTranslation(new Vector3f(cameraX, cameraZ, cameraY));
    transform.mul(yawRotation);
   
    this.camera = new Camera(cameraX, cameraY, cameraZ, cameraYaw, cameraPitch, 0);
  }
View Full Code Here

                                boolean listenToHomeUpdates,
                                boolean waitForLoading) {
    final Ground3D ground3D = new Ground3D(this.home,
        groundOriginX, groundOriginY, groundWidth, groundDepth, waitForLoading);
    Transform3D translation = new Transform3D();
    translation.setTranslation(new Vector3f(0, -0.2f, 0));
    TransformGroup transformGroup = new TransformGroup(translation);
    transformGroup.addChild(ground3D);
   
    if (listenToHomeUpdates) {
      // Add a listener on ground color and texture properties change
View Full Code Here

  /**
   * Returns the lights of the scene.
   */
  private Light [] createLights(boolean listenToHomeUpdates) {
    final Light [] lights = {
        new DirectionalLight(new Color3f(1, 1, 1), new Vector3f(1.5f, -0.8f, -1)),        
        new DirectionalLight(new Color3f(1, 1, 1), new Vector3f(-1.5f, -0.8f, -1)),
        new DirectionalLight(new Color3f(1, 1, 1), new Vector3f(0, -0.8f, 1)),
        new DirectionalLight(new Color3f(0.7f, 0.7f, 0.7f), new Vector3f(0, 1f, 0)),
        new AmbientLight(new Color3f(0.2f, 0.2f, 0.2f))};
    for (int i = 0; i < lights.length - 1; i++) {
      // Allow directional lights color to change
      lights [i].setCapability(DirectionalLight.ALLOW_COLOR_WRITE);
      // Store default color in user data
View Full Code Here

TOP

Related Classes of javax.vecmath.Vector3f

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.