Created
November 26, 2014 20:14
-
-
Save zzuegg/cce676cf10ddccfa1a12 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.jme3.app.SimpleApplication; | |
import com.jme3.material.Material; | |
import com.jme3.material.RenderState; | |
import com.jme3.math.FastMath; | |
import com.jme3.math.Vector3f; | |
import com.jme3.renderer.RenderManager; | |
import com.jme3.renderer.ViewPort; | |
import com.jme3.scene.Geometry; | |
import com.jme3.scene.Node; | |
import com.jme3.scene.control.AbstractControl; | |
import com.jme3.scene.shape.Quad; | |
/** | |
* Created by MichaelZuegg on 26.11.2014. | |
*/ | |
public class TransparentTest extends SimpleApplication { | |
@Override | |
public void simpleInitApp() { | |
flyCam.setMoveSpeed(10f); | |
cam.setLocation(Vector3f.UNIT_Z.mult(10)); | |
cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y.clone()); | |
final Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); | |
final Geometry head = new Geometry("Head", new Quad(10, 10)); | |
head.setMaterial(material.clone()); | |
head.getMaterial().setTexture("ColorMap", assetManager.loadTexture("sprite_head.png")); | |
head.getMaterial().getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha); | |
final Geometry body = new Geometry("Head", new Quad(20, 40)); | |
body.setMaterial(material.clone()); | |
body.getMaterial().setTexture("ColorMap", assetManager.loadTexture("sprite_body.png")); | |
body.getMaterial().getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha); | |
Node headNode = new Node(); | |
Node bodyNode = new Node(); | |
headNode.attachChild(head); | |
headNode.addControl(new AbstractControl() { | |
@Override | |
protected void controlUpdate(float tpf) { | |
spatial.rotate(0, 0, 50 * tpf * FastMath.DEG_TO_RAD); | |
} | |
@Override | |
protected void controlRender(RenderManager rm, ViewPort vp) { | |
} | |
}); | |
head.setLocalTranslation(-5, -5, 0.001f); //z fighting offset | |
bodyNode.attachChild(body); | |
bodyNode.addControl(new AbstractControl() { | |
@Override | |
protected void controlUpdate(float tpf) { | |
spatial.rotate(0, 0, -50 * tpf * FastMath.DEG_TO_RAD); | |
} | |
@Override | |
protected void controlRender(RenderManager rm, ViewPort vp) { | |
} | |
}); | |
body.setLocalTranslation(-10, -35, 0); | |
rootNode.attachChild(headNode); | |
rootNode.attachChild(bodyNode); | |
rootNode.setLocalScale(0.1f); | |
} | |
public static void main(String[] args) { | |
final TransparentTest transparentTest = new TransparentTest(); | |
transparentTest.setShowSettings(false); | |
transparentTest.start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment