Android Open Source - Schooner-3D Test Objects






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//from w ww.  ja v a  2 s.  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;

import java.util.ArrayList;
import java.util.LinkedList;

import com.supermercerbros.gameengine.animation.Keyframe;
import com.supermercerbros.gameengine.animation.MeshAnimation;
import com.supermercerbros.gameengine.collision.Bounds;
import com.supermercerbros.gameengine.collision.Polyhedron;
import com.supermercerbros.gameengine.engine.shaders.Material;
import com.supermercerbros.gameengine.material.TexturedMaterial;
import com.supermercerbros.gameengine.objects.AnimatedMeshObject;
import com.supermercerbros.gameengine.objects.BasicMaterial;
import com.supermercerbros.gameengine.objects.GameObject;
import com.supermercerbros.gameengine.texture.Texture;

/**
 * Contains methods to create test objects.
 */
public class TestObjects {
  /**
   * Creates an animated tetrahedron.
   * 
   * @return An animated tetrahedron.
   */
  public static GameObject tetra() {
    ArrayList<Keyframe> keyframesA = new ArrayList<Keyframe>();
    //@formatter:off
    short[] indices = { 
        0, 1, 2, 
        0, 1, 3, 
        0, 2, 3, 
        1, 2, 3, };
    float[] colors = { 
        1.0f, 0.0f, 0.0f,
        0.0f, 1.0f, 0.0f, 
        0.0f, 0.0f, 1.0f,
        1.0f, 1.0f, 1.0f, };
    float[] normals = new float[12];

    float[] frameA1 = { 
        1.0f, 0.0f, 0.0f, 
        0.0f, 1.0f, 0.0f, 
        0.0f, 0.0f, 1.0f,
        0.0f, 0.0f, 0.0f, };
    float[] frameA2 = { 
        3.0f, 0.0f, 0.0f, 
        0.0f, 3.0f, 0.0f, 
        0.0f, 0.0f, 3.0f, 
        0.0f, 0.0f, 0.0f, };
    //@formatter:on
    
    keyframesA.add(new Keyframe(frameA1));
    keyframesA.add(new Keyframe(frameA2));
    float[] times = { 0, 3000 };
    MeshAnimation anim1 = new MeshAnimation(keyframesA, times, null);
    AnimatedMeshObject tetra = new AnimatedMeshObject(frameA1.clone(),
        indices, colors, normals, new BasicMaterial(), null);
    tetra.setAnimation(anim1, System.currentTimeMillis() + 1000, 3000, 1);
    return tetra;
  }
  
  /**
   * Creates a textured cube.
   * 
   * @param tex
   *            The Texture to apply.
   * @return A textured cube.
   */
  public static GameObject cube(Material mtl) {
    final Material material;
    if (mtl == null) {
      material = new BasicMaterial();
    } else {
      material = mtl;
    }
    
    //@formatter:off
    final float[] verts = { 
        1.0f, 1.0f, 1.0f, 
        1.0f, 0.0f, 1.0f, 
        0.0f, 1.0f, 1.0f, 
        0.0f, 0.0f, 1.0f, 
        1.0f, 1.0f, 0.0f, 
        1.0f, 0.0f, 0.0f, 
        0.0f, 1.0f, 0.0f,
        0.0f, 0.0f, 0.0f, };
    final float[] uvs;
    if (material instanceof TexturedMaterial) {
      uvs = new float[] { 
          0.0f, 0.0f, 
          0.0f, 1.0f, 
          1.0f, 0.0f, 
          1.0f, 1.0f,
          1.0f, 0.0f, 
          1.0f, 1.0f, 
          1.0f, 1.0f, 
          0.0f, 0.0f, };
    } else {
      uvs = new float[] { 
          1.0f, 1.0f, 1.0f, 
          1.0f, 0.0f, 0.0f, 
          0.0f, 1.0f, 0.0f,
          0.0f, 0.0f, 1.0f,
          1.0f, 1.0f, 0.0f, 
          1.0f, 0.0f, 1.0f, 
          0.0f, 1.0f, 1.0f,
          0.0f, 0.0f, 0.0f
      };
    }
    final short[] indices = { 
        3, 1, 0, 
        2, 3, 0, 
        0, 1, 5,
        0, 5, 4, 
        2, 0, 6, 
        6, 0, 4, 
        1, 3, 5, 
        3, 7, 5, 
        3, 2, 6, 
        3, 6, 7, 
        4, 5, 6, 
        5, 7, 6, };
    float[] normals = null;
    //@formatter:on
    
    GameObject cube = new GameObject(verts, indices, normals, uvs, null,
        material);
    material.makeProgram();
    return cube;
  }
  
  /**
   * Creates a textured quadrangle.
   * 
   * @param tex
   *            The Texture to apply.
   * @return A textured quad.
   */
  public static GameObject quad(Texture tex) {
    float depth = -2.84f;
    //@formatter:off
    float[] verts = { 
        .5f, .5f, depth, 
        .5f, -.5f, depth, 
        -.5f, .5f, depth,
        -.5f, -.5f, depth, };
    float[] uvs = { 
        0.0f, 0.0f, 
        0.0f, 1.0f, 
        1.0f, 0.0f, 
        1.0f, 1.0f };

    short[] indices = { 
        0, 1, 2, 
        1, 2, 3 };
    float[] normals = null;
    //@formatter:on
    
    GameObject obj = new GameObject(verts, indices, normals, uvs, null,
        new TexturedMaterial(tex));
    return obj;
  }
  
  /**
   * Creates a vertex-colored triangle.
   * 
   * @param mtl
   *            The Material to use. If null, will be replaced by a new
   *            {@link BasicMaterial}
   * 
   * @return A colored triangle.
   */
  public static GameObject tri(Material mtl) {
    //@formatter:off
    
    float[] verts = { 
        0.0f, 0.0f, -1.0f, 
        -0.6f, -0.6f, -1.0f, 
        -0.6f, 0.6f, -1.0f };
    float[] colors = { 
        1, 1, 0, 
        0, 1, 1, 
        1, 0, 1 };
    short[] indices = { 
        0, 2, 1 
        };
    float[] normals = null;
    
    //@formatter:on
    
    final Material material;
    if (mtl == null) {
      material = new BasicMaterial();
    } else {
      material = mtl;
    }
    GameObject tri = new GameObject(verts, indices, normals, colors, null,
        material);
    material.makeProgram();
    return tri;
  }
  
  public static Bounds cubeBounds() {
    //@formatter:off
    final float[] cubeV = { 
      0.0f, 0.0f, 0.0f, 
      1.0f, 0.0f, 0.0f,
      0.0f, 1.0f, 0.0f, 
      1.0f, 1.0f, 0.0f, 
      0.0f, 0.0f, 1.0f, 
      1.0f, 0.0f, 1.0f, 
      0.0f, 1.0f, 1.0f, 
      1.0f, 1.0f, 1.0f, };
    final short[] cubeI = { 
      0, 2, 3, 1, // Z
      4, 5, 7, 6, // Z one

      0, 1, 5, 4, // Y
      2, 6, 7, 3, // Y one

      1, 3, 7, 5, // X
      2, 0, 4, 6, // X one
    };
    //@formatter:on
    
    final LinkedList<Polyhedron> parts = new LinkedList<Polyhedron>();
    final Polyhedron poly = new Polyhedron(Polyhedron.featureMesh(cubeV,
        cubeI));
    parts.add(poly);
    return new Bounds(parts, 0.0);
  }
  
}




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