Android Open Source - Schooner-3D Vertex






From Project

Back to project page Schooner-3D.

License

The source code is released under:

Apache License

If you think the Android project Schooner-3D listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright 2012 Dan Mercer/* w ww .  j a  va2s.co m*/
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.supermercerbros.gameengine.collision;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

/**
 * Represents a Vertex on a mesh.
 */
public class Vertex extends Point implements Feature {
  /**
   * The edges that end or begin at this Vertex.
   */
  private final ArrayList<Edge> coboundary;

  /**
   * The voronoi region of this Vertex
   */
  private final LinkedList<Plane> voronoi;
  
  private final String debugID;
  private static int nextID = 0;
  
  @Override
  public String toString() {
    return debugID;
  }
  public static void resetIdCounter() {
    nextID = 0;
  }

  /**
   * Constructs a Vertex at the given point.
   * 
   * @param x
   *            The X-coordinate of the Vertex's location.
   * @param y
   *            The Y-coordinate of the Vertex's location.
   * @param z
   *            The Z-coordinate of the Vertex's location.
   */
  public Vertex(final float x, final float y, final float z) {
    super(x, y, z);
    coboundary = new ArrayList<Edge>();
    voronoi = new LinkedList<Plane>();
    
    this.debugID = "Vert " + nextID++;
  }

  /**
   * Adds an Edge to this vertex's coboundary. Fails with an
   * <code>IllegalStateException</code> if this vertex is locked.
   * 
   * @param edge
   *            The Edge to add to this vertex's coboundary
   * @param constraint
   *            The constraint plane between <code>edge</code> and this Vertex
   */
  protected void addEdge(Edge edge, Plane constraint) {
    coboundary.add(edge);
    voronoi.add(constraint);
  }

  /**
   * @return An <b>unmodifiable</b> List of the Vertex's edges.
   */
  public List<Edge> getEdges() {
    return Collections.unmodifiableList(coboundary);
  }

  @Override
  public Feature test(Feature other, Matrix matrix) throws Intersection,
      LocalDistMinimum {
    if (coboundary.isEmpty()){
      return null; //Nothing to check (such as in a SphereBounds)
    }
    
    if (other instanceof Face) {
      return testF((Face) other, matrix);
    } else if (other instanceof Edge) {
      return testE((Edge) other, matrix);
    } else if (other instanceof Vertex) {
      return testV((Vertex) other, matrix);
    } else {
      throw new IllegalArgumentException(
          "other is not a Face, Edge, or Vertex");
    }
  }

  private Feature testV(Vertex other, Matrix matrix) {
    final Point p = other.transform(matrix);
    return checkPoint(p);
  }

  private Edge testE(Edge e, Matrix matrix) {
    final Line tEdge = e.transform(matrix);
    final Vector vector = tEdge.vector, vectorInverse = vector.flip();
    final Vector fromHead = new Vector(tEdge.head, this, 1.0f);
    final Vector fromTail = new Vector(tEdge.tail, this, 1.0f);

    final Point closestPoint;
    if (vector.cos(fromTail) < Plane.TOLERANCE) {
      closestPoint = tEdge.tail;
    } else if (vectorInverse.cos(fromHead) < Plane.TOLERANCE) {
      closestPoint = tEdge.head;
    } else {
      closestPoint = tEdge.projectPoint(this);
    }
    return checkPoint(closestPoint);
  }

  private Edge testF(Face f, Matrix matrix) {
    final Point closestPoint = f.transform(matrix).projectPointOnto(
        this);
    return checkPoint(closestPoint);
  }

  private Edge checkPoint(final Point p) {
    double distance = CollisionDetector.CONSTRAINT_CHECK_TOLERANCE;
    Edge infringed = null;

    for (ListIterator<Plane> vIter = voronoi.listIterator(); vIter
        .hasNext();) {
      final int i = vIter.nextIndex();
      final Plane constraint = vIter.next();

      final double d = constraint.distanceTo(p);
      if (d < distance) {
        distance = d;
        infringed = coboundary.get(i);
      }
    }
    
    if (infringed == null) {
      CollisionDetector.setClosestPoint(p);
      return null;
    } else {
      return infringed;
    }
  }

}




Java Source Code List

com.supermercerbros.gameengine.GameActivity.java
com.supermercerbros.gameengine.GameView.java
com.supermercerbros.gameengine.Schooner3D.java
com.supermercerbros.gameengine.TestActivity.java
com.supermercerbros.gameengine.TestMaterials.java
com.supermercerbros.gameengine.TestObjects.java
com.supermercerbros.gameengine.animation.AnimationData.java
com.supermercerbros.gameengine.animation.Keyframe.java
com.supermercerbros.gameengine.animation.MeshAnimation.java
com.supermercerbros.gameengine.armature.ActionData.java
com.supermercerbros.gameengine.armature.Action.java
com.supermercerbros.gameengine.armature.BinarySkeletalVertexModifier.java
com.supermercerbros.gameengine.armature.Bone.java
com.supermercerbros.gameengine.armature.SkeletalVertexModifier.java
com.supermercerbros.gameengine.armature.Skeleton.java
com.supermercerbros.gameengine.collision.Bounds.java
com.supermercerbros.gameengine.collision.Collider.java
com.supermercerbros.gameengine.collision.CollisionDetector.java
com.supermercerbros.gameengine.collision.Collision.java
com.supermercerbros.gameengine.collision.DebugListener.java
com.supermercerbros.gameengine.collision.Edge.java
com.supermercerbros.gameengine.collision.Face.java
com.supermercerbros.gameengine.collision.Feature.java
com.supermercerbros.gameengine.collision.Intersection.java
com.supermercerbros.gameengine.collision.Line.java
com.supermercerbros.gameengine.collision.LocalDistMinimum.java
com.supermercerbros.gameengine.collision.Matrix.java
com.supermercerbros.gameengine.collision.OnCollisionCheckFinishedListener.java
com.supermercerbros.gameengine.collision.Plane.java
com.supermercerbros.gameengine.collision.Point.java
com.supermercerbros.gameengine.collision.Polyhedron.java
com.supermercerbros.gameengine.collision.SphereBounds.java
com.supermercerbros.gameengine.collision.Vector.java
com.supermercerbros.gameengine.collision.Vertex.java
com.supermercerbros.gameengine.debug.JankCatcher.java
com.supermercerbros.gameengine.debug.LoopLog.java
com.supermercerbros.gameengine.engine.Camera.java
com.supermercerbros.gameengine.engine.DataPipe.java
com.supermercerbros.gameengine.engine.EGLContextLostHandler.java
com.supermercerbros.gameengine.engine.Engine.java
com.supermercerbros.gameengine.engine.GameRenderer.java
com.supermercerbros.gameengine.engine.Light.java
com.supermercerbros.gameengine.engine.Normals.java
com.supermercerbros.gameengine.engine.RenderData.java
com.supermercerbros.gameengine.engine.Scene.java
com.supermercerbros.gameengine.engine.Time.java
com.supermercerbros.gameengine.engine.shaders.Material.java
com.supermercerbros.gameengine.engine.shaders.Program.java
com.supermercerbros.gameengine.engine.shaders.ShaderLib.java
com.supermercerbros.gameengine.engine.shaders.Shader.java
com.supermercerbros.gameengine.engine.shaders.VertexModifier.java
com.supermercerbros.gameengine.handlers.OnAnimationCompleteDispatcher.java
com.supermercerbros.gameengine.handlers.OnAnimationCompleteListener.java
com.supermercerbros.gameengine.hud.CoordsConverter.java
com.supermercerbros.gameengine.hud.GameHud.java
com.supermercerbros.gameengine.hud.HudElement.java
com.supermercerbros.gameengine.material.CelShadedMaterial.java
com.supermercerbros.gameengine.material.TexturedMaterial.java
com.supermercerbros.gameengine.math.BezierCurve.java
com.supermercerbros.gameengine.math.Curve.java
com.supermercerbros.gameengine.math.MatrixUtils.java
com.supermercerbros.gameengine.math.Quaternion.java
com.supermercerbros.gameengine.motion.CurveMovement.java
com.supermercerbros.gameengine.motion.MovementData.java
com.supermercerbros.gameengine.motion.Movement.java
com.supermercerbros.gameengine.objects.AnimatedMeshObject.java
com.supermercerbros.gameengine.objects.BasicMaterial.java
com.supermercerbros.gameengine.objects.BonedObject.java
com.supermercerbros.gameengine.objects.GameObject.java
com.supermercerbros.gameengine.objects.Metadata.java
com.supermercerbros.gameengine.parsers.ConstantCurve.java
com.supermercerbros.gameengine.parsers.GameFactory.java
com.supermercerbros.gameengine.parsers.PreBoneData.java
com.supermercerbros.gameengine.parsers.PreObjectData.java
com.supermercerbros.gameengine.parsers.Sch3D.java
com.supermercerbros.gameengine.render.Compositor.java
com.supermercerbros.gameengine.shaders.ProgramSource.java
com.supermercerbros.gameengine.texture.BitmapTexture.java
com.supermercerbros.gameengine.texture.ETC1CompressedTexture.java
com.supermercerbros.gameengine.texture.Texture.java
com.supermercerbros.gameengine.util.BetterDataInputStream.java
com.supermercerbros.gameengine.util.DelayedRunnable.java
com.supermercerbros.gameengine.util.GLES2.java
com.supermercerbros.gameengine.util.IPO.java
com.supermercerbros.gameengine.util.LoopingThread.java
com.supermercerbros.gameengine.util.Toggle.java
com.supermercerbros.gameengine.util.Utils.java