⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 boundsscale.java

📁 Java 3D Desktop Environment旨在使用Java 3D来创建一个3D桌面环境。功能包括:分布式的应用程序
💻 JAVA
字号:
package org.j3de.ui.impl;

import javax.media.j3d.Bounds;
import javax.media.j3d.BoundingBox;
import javax.media.j3d.BoundingSphere;    

import javax.vecmath.Point3d;     
import javax.vecmath.Point3f;     

public class BoundsScale {
  
  private static double getSphereScale(BoundingSphere bs1, BoundingSphere bs2) {
    return bs2.getRadius() / bs1.getRadius();
  }

  private static Point3f getBoxAllScales(BoundingBox bb1, BoundingBox bb2) {       
    Point3d upper1 = new Point3d();
    Point3d lower1 = new Point3d();
    Point3d upper2 = new Point3d();
    Point3d lower2 = new Point3d();
    
    bb1.getUpper(upper1);
    bb1.getLower(lower1);
    upper1.sub(lower1);  
    upper1.absolute();
    
    bb2.getUpper(upper2);
    bb2.getLower(lower2);
    upper2.sub(lower2);
    upper2.absolute();
    
    return new Point3f((float)(upper2.x / upper1.x),
                       (float)(upper2.y / upper1.y),
                       (float)(upper2.z / upper1.z));
  }
 
  private static double getBoxScale(BoundingBox bb1, BoundingBox bb2) {       
    Point3f scale = getBoxAllScales(bb1, bb2);
    if (scale.x > scale.y) 
      return Math.max(scale.x, scale.z);
    else         
      return Math.max(scale.y, scale.z);
  }
  
  public static Point3f getAllScales(Bounds b1, Bounds b2) throws UnknownBoundsException { 
    if (b1 instanceof BoundingSphere) {    
      float scale = (float)getSphereScale((BoundingSphere)b1, new BoundingSphere(b2));
      return new Point3f(scale, scale, scale);
    } else if (b1 instanceof BoundingBox) {
      return getBoxAllScales((BoundingBox)b1, new BoundingBox(b2));
    } else
      throw new UnknownBoundsException(b1);     
  }
   
  /** This method returns a factor b1 must be scaled up, to include b2. */
  public static double getScale(Bounds b1, Bounds b2) throws UnknownBoundsException {    
    if (b1 instanceof BoundingSphere) {    
      return getSphereScale((BoundingSphere)b1, new BoundingSphere(b2));
    } else if (b1 instanceof BoundingBox) {
      return getBoxScale((BoundingBox)b1, new BoundingBox(b2));
    } else
      throw new UnknownBoundsException(b1);  
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -