2 * Copyright (c) 2003-2009 jMonkeyEngine
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 package jmetest.awt.applet;
35 import com.jme.bounding.BoundingBox;
36 import com.jme.light.PointLight;
37 import com.jme.math.FastMath;
38 import com.jme.math.Quaternion;
39 import com.jme.math.Vector3f;
40 import com.jme.renderer.ColorRGBA;
41 import com.jme.renderer.pass.ShadowedRenderPass;
42 import com.jme.scene.shape.PQTorus;
43 import com.jme.scene.shape.Quad;
44 import com.jmex.awt.applet.SimpleJMEPassApplet;
46 public class AppletTestShadows extends SimpleJMEPassApplet {
47 private static final long serialVersionUID = 1L;
49 private float rps = .5f;
50 private float angle = 0;
51 private float elapsed = 0;
52 private float throttle = 1/30f; // only update 30 times per frame
53 private Quaternion rotQuat = new Quaternion();
56 public AppletTestShadows() {
60 public void simpleAppletUpdate() {
61 elapsed += getTimePerFrame();
62 if (elapsed >= throttle) {
63 angle = elapsed * rps * FastMath.TWO_PI;
65 rotQuat.fromAngleNormalAxis(angle, Vector3f.UNIT_Y);
66 rotQuat.mult(p.getLocation(), p.getLocation());
71 public void simpleAppletSetup() {
72 getCamera().setLocation(new Vector3f(0, 50, -100));
73 getCamera().lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);
74 ShadowedRenderPass srp = new ShadowedRenderPass();
75 srp.setLightingMethod(ShadowedRenderPass.LightingMethod.Modulative);
76 getManager().clearAll();
77 getManager().add(srp);
79 getLightState().detachAll();
81 p.setDiffuse(new ColorRGBA(1f, 1f, 1f, 1f));
82 p.setAmbient(new ColorRGBA(.8f, .8f, .8f, .4f));
83 p.getLocation().set(10, 10, -10);
84 p.setShadowCaster(true);
85 getLightState().attach(p);
87 PQTorus pqt = new PQTorus("actor", 3, 2, 2.0f, 1.0f, 128, 16);
88 pqt.setModelBound(new BoundingBox());
89 pqt.updateModelBound();
91 Quad floor = new Quad("floor", 100, 100);
92 floor.setModelBound(new BoundingBox());
93 floor.updateModelBound();
95 Quaternion rotateDown = new Quaternion(new float[] {90*FastMath.DEG_TO_RAD,0,0});
96 floor.setLocalRotation(rotateDown);
97 floor.getLocalTranslation().y-=2;
99 getRootNode().attachChild(pqt);
100 getRootNode().attachChild(floor);
101 srp.add(getRootNode());
102 srp.addOccluder(pqt);