Package crazypants.enderio.conduit.redstone

Source Code of crazypants.enderio.conduit.redstone.RedstoneSwitchBounds

package crazypants.enderio.conduit.redstone;

import crazypants.enderio.config.Config;
import crazypants.render.BoundingBox;
import crazypants.render.VertexRotation;
import crazypants.render.VertexTransform;
import crazypants.vecmath.Vector3d;

public class RedstoneSwitchBounds {

  private static RedstoneSwitchBounds instance;

  public static final RedstoneSwitchBounds getInstance() {
    if(instance == null) {
      instance = new RedstoneSwitchBounds();
    }
    return instance;
  }

  final VertexTransform[] xForms;
  final BoundingBox switchBounds;
  final BoundingBox connectorBounds;

  private final BoundingBox[] aabb;

  RedstoneSwitchBounds() {

    float conduitScale = (float) Config.conduitScale;

    float size = Math.max(0.2f, conduitScale * 0.5f);
    float halfWidth = size / 3;
    float halfHeight = size / 2;

    //float DEPTH = 0.05f;
    float halfDepth = 0.025f;
    float distance = Math.max(0.25f, conduitScale * 0.3f);

    BoundingBox bb = new BoundingBox(0.5 - halfWidth, 0.5 - halfHeight, 0.5 - halfDepth, 0.5 + halfWidth, 0.5 + halfHeight, 0.5 + halfDepth);
    switchBounds = bb.translate(0, 0, distance);

    float connectorHalfWidth = (float) Math.max(0.015, conduitScale * 0.05);
    connectorBounds = new BoundingBox(0.5 - connectorHalfWidth, 0.5 - connectorHalfWidth, 0.5 - connectorHalfWidth, 0.5 + connectorHalfWidth,
        0.5 + connectorHalfWidth, 0.5 + distance);

    Vector3d axis = new Vector3d(0, 1, 0);
    Vector3d p = new Vector3d(0.5, 0.5, 0.5);
    xForms = new VertexTransform[4];
    double angle = Math.toRadians(45);
    for (int i = 0; i < xForms.length; i++) {
      xForms[i] = new VertexRotation(angle, axis, p);
      angle += Math.toRadians(90);
    }

    aabb = new BoundingBox[xForms.length];
    for (int i = 0; i < xForms.length; i++) {
      aabb[i] = switchBounds.transform(xForms[i]);
    }
  }

  public BoundingBox[] getAABB() {
    return aabb;
  }

}
TOP

Related Classes of crazypants.enderio.conduit.redstone.RedstoneSwitchBounds

TOP
Copyright © 2018 www.massapi.com. 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.