当前位置: 首页>>代码示例>>Java>>正文


Java Ellipse2D.getHeight方法代码示例

本文整理汇总了Java中java.awt.geom.Ellipse2D.getHeight方法的典型用法代码示例。如果您正苦于以下问题:Java Ellipse2D.getHeight方法的具体用法?Java Ellipse2D.getHeight怎么用?Java Ellipse2D.getHeight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.geom.Ellipse2D的用法示例。


在下文中一共展示了Ellipse2D.getHeight方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getObstructedVisionArea

import java.awt.geom.Ellipse2D; //导入方法依赖的package包/类
/**
 * Gets the obstructed vision area.
 *
 * @param mob
 *          the mob
 * @param center
 *          the center
 * @return the obstructed vision area
 */
private Area getObstructedVisionArea(final IEntity mob, final Point2D center) {
  final Polygon shadowPolygon = new Polygon();

  final Ellipse2D shadowEllipse = getShadowEllipse(mob);

  final Rectangle2D bounds = shadowEllipse.getBounds2D();

  // radius of Entity's bounding circle
  final float r = (float) bounds.getWidth() / 2f;
  final float ry = (float) bounds.getHeight() / 2f;

  // get relative center of entity
  final Point2D relativeCenter = Game.getCamera().getViewPortLocation(new Point((int) (bounds.getX() + r), (int) (bounds.getY() + ry)));
  final double cx = relativeCenter.getX();
  final double cy = relativeCenter.getY();

  // get direction from light to entity center
  final double dx = cx - center.getX();
  final double dy = cy - center.getY();

  // get euclidean distance from entity to center
  final double distSq = dx * dx + dy * dy; // avoid sqrt for performance

  // normalize the direction to a unit vector
  final float len = (float) Math.sqrt(distSq);
  double nx = dx;
  double ny = dy;
  if (len != 0) { // avoid division by 0
    nx /= len;
    ny /= len;
  }

  // get perpendicular of unit vector
  final double px = -ny;
  final double py = nx;

  // our perpendicular points in either direction from radius
  final Point2D.Double pointA = new Point2D.Double(cx - px * r, cy - py * ry);
  final Point2D.Double pointB = new Point2D.Double(cx + px * r, cy + py * ry);

  // project the points by our SHADOW_EXTRUDE amount
  final Point2D pointC = GeometricUtilities.project(center, pointA, OBSTRUCTED_VISION_RADIUS);
  final Point2D pointD = GeometricUtilities.project(center, pointB, OBSTRUCTED_VISION_RADIUS);

  // construct a polygon from our points
  shadowPolygon.reset();
  shadowPolygon.addPoint((int) pointA.getX(), (int) pointA.getY());
  shadowPolygon.addPoint((int) pointB.getX(), (int) pointB.getY());
  shadowPolygon.addPoint((int) pointD.getX(), (int) pointD.getY());
  shadowPolygon.addPoint((int) pointC.getX(), (int) pointC.getY());

  final Point2D shadowRenderLocation = Game.getCamera().getViewPortLocation(new Point2D.Double(shadowEllipse.getX(), shadowEllipse.getY()));
  final Ellipse2D relativeEllipse = new Ellipse2D.Double(shadowRenderLocation.getX(), shadowRenderLocation.getY(), shadowEllipse.getWidth(), shadowEllipse.getHeight());

  final Area ellipseArea = new Area(relativeEllipse);
  final Area shadowArea = new Area(shadowPolygon);
  shadowArea.add(ellipseArea);
  return shadowArea;
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:69,代码来源:LightSource.java


注:本文中的java.awt.geom.Ellipse2D.getHeight方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。