Android Open Source - jmini3d Sprite Geometry






From Project

Back to project page jmini3d.

License

The source code is released under:

Copyright 2012 Mobialia http://www.mobialia.com/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to ...

If you think the Android project jmini3d 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

package jmini3d.geometry;
/*from  w  ww. j  a v  a 2s .  c o m*/
import jmini3d.GpuObjectStatus;

public class SpriteGeometry extends Geometry {
  float[] vertex;
  float[] uvs;
  short[] faces;

  int vertexPointer = 0;
  int facePointer = 0;

  public SpriteGeometry(int spriteCount) {
    vertex = new float[3 * 4 * spriteCount];
    uvs = new float[2 * 4 * spriteCount];
    faces = new short[3 * 2 * spriteCount];
  }

  public short addVertex(float x, float y, float z, float u, float v) {
    vertex[vertexPointer * 3] = x;
    vertex[vertexPointer * 3 + 1] = y;
    vertex[vertexPointer * 3 + 2] = z;

    uvs[vertexPointer * 2] = u;
    uvs[vertexPointer * 2 + 1] = v;

    vertexPointer++;
    return (short) (vertexPointer - 1);
  }

  public void addFace(short a, short b, short c) {
    faces[facePointer * 3] = a;
    faces[facePointer * 3 + 1] = b;
    faces[facePointer * 3 + 2] = c;

    facePointer++;
  }

  public void addSprite(float x1, float y1, float x2, float y2) {
    addSprite(x1, y1, x2, y2, 0, 0, 1, 1);
  }

  public void addSprite(float x1, float y1, float x2, float y2, float uvx1, float uvy1, float uvx2, float uvy2) {
    short _leftBack = addVertex(x1, y1, 0, uvx1, uvy1);
    short _rightBack = addVertex(x2, y1, 0, uvx2, uvy1);
    short _leftFront = addVertex(x1, y2, 0, uvx1, uvy2);
    short _rightFront = addVertex(x2, y2, 0, uvx2, uvy2);

    addFace(_leftBack, _leftFront, _rightBack);
    addFace(_rightBack, _leftFront, _rightFront);
  }

  public void setSpritePosition(int index, float x1, float y1, float x2, float y2) {
    vertex[index * 12] = x1;
    vertex[(index * 12) + 1] = y1;
    vertex[(index * 12) + 3] = x2;
    vertex[(index * 12) + 4] = y1;
    vertex[(index * 12) + 6] = x1;
    vertex[(index * 12) + 7] = y2;
    vertex[(index * 12) + 9] = x2;
    vertex[(index * 12) + 10] = y2;

    status &= ~GpuObjectStatus.VERTICES_UPLOADED;
  }

  public void setUv(int index, float u, float v) {
    uvs[index << 1] = u;
    uvs[(index << 1) + 1] = v;

    status &= ~GpuObjectStatus.UVS_UPLOADED;
  }

  public float[] vertex() {
    return vertex;
  }

  public float[] normals() {
    return null;
  }

  public float[] uvs() {
    return uvs;
  }

  public short[] faces() {
    return faces;
  }
}




Java Source Code List

cocoonjs.CocoonJsLinker.java
jmini3d.Blending.java
jmini3d.Camera.java
jmini3d.Color4.java
jmini3d.CubeMapTexture.java
jmini3d.Font.java
jmini3d.GpuObjectStatus.java
jmini3d.MatrixUtils.java
jmini3d.Object3d.java
jmini3d.Rect.java
jmini3d.SceneController.java
jmini3d.Scene.java
jmini3d.Texture.java
jmini3d.Utils.java
jmini3d.Vector3.java
jmini3d.android.Activity3d.java
jmini3d.android.GeometryBuffers.java
jmini3d.android.GlSurfaceView3d.java
jmini3d.android.GpuUploader.java
jmini3d.android.Program.java
jmini3d.android.Renderer3d.java
jmini3d.android.ResourceLoader.java
jmini3d.android.compat.CompatibilityWrapper5.java
jmini3d.android.demo.DemoActivity.java
jmini3d.android.input.InputController.java
jmini3d.demo.ArialFont.java
jmini3d.demo.CubeScene.java
jmini3d.demo.CubesScene.java
jmini3d.demo.DemoSceneController.java
jmini3d.demo.EnvMapCubeScene.java
jmini3d.demo.NormalMapScene.java
jmini3d.demo.ParentScene.java
jmini3d.demo.TeapotGeometry.java
jmini3d.demo.TeapotScene.java
jmini3d.geometry.BoxGeometry.java
jmini3d.geometry.Geometry.java
jmini3d.geometry.PlaneGeometry.java
jmini3d.geometry.SkyboxGeometry.java
jmini3d.geometry.SpriteGeometry.java
jmini3d.geometry.VariableGeometry.java
jmini3d.gwt.Canvas3d.java
jmini3d.gwt.EngineResources.java
jmini3d.gwt.EntryPoint3d.java
jmini3d.gwt.GeometryBuffers.java
jmini3d.gwt.GpuUploader.java
jmini3d.gwt.MyInt16Array.java
jmini3d.gwt.Program.java
jmini3d.gwt.Renderer3d.java
jmini3d.gwt.ResourceLoader.java
jmini3d.gwt.TextureLoadedListener.java
jmini3d.gwt.demo.DemoEntryPoint.java
jmini3d.gwt.input.InputController.java
jmini3d.input.KeyListener.java
jmini3d.input.TouchListener.java
jmini3d.input.TouchPointer.java
jmini3d.light.AmbientLight.java
jmini3d.light.DirectionalLight.java
jmini3d.light.Light.java
jmini3d.light.PointLight.java
jmini3d.material.Material.java
jmini3d.material.PhongMaterial.java
jmini3d.material.SpriteMaterial.java
jmini3d.utils.Fnt2Class.java
jmini3d.utils.Obj2Class.java