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.renderer;
35 import com.jme.app.SimpleGame;
36 import com.jme.bounding.BoundingSphere;
37 import com.jme.image.Texture;
38 import com.jme.light.LightNode;
39 import com.jme.light.PointLight;
40 import com.jme.math.FastMath;
41 import com.jme.math.Quaternion;
42 import com.jme.math.Vector3f;
43 import com.jme.renderer.ColorRGBA;
44 import com.jme.scene.BezierMesh;
45 import com.jme.scene.BezierPatch;
46 import com.jme.scene.Spatial;
47 import com.jme.scene.shape.Box;
48 import com.jme.scene.state.MaterialState;
49 import com.jme.scene.state.TextureState;
50 import com.jme.util.TextureManager;
53 * <code>TestLightState</code>
55 * @version $Id: TestBezierMesh.java,v 1.26 2006/05/12 21:29:20 nca Exp $
57 public class TestBezierMesh extends SimpleGame {
58 private BezierMesh bez;
59 private PointLight pl;
60 private LightNode lightNode;
61 private Vector3f currentPos;
62 private Vector3f newPos;
65 * Entry point for the test,
68 public static void main(String[] args) {
69 TestBezierMesh app = new TestBezierMesh();
70 app.setConfigShowMode(ConfigShowMode.AlwaysShow);
75 protected void simpleUpdate() {
77 if ( (int) currentPos.x == (int) newPos.x
78 && (int) currentPos.y == (int) newPos.y
79 && (int) currentPos.z == (int) newPos.z) {
80 newPos.x = (float) Math.random() * 10 - 5;
81 newPos.y = (float) Math.random() * 10 - 5;
82 newPos.z = (float) Math.random() * 10 - 5;
85 currentPos.x -= (currentPos.x - newPos.x)
86 / (timer.getFrameRate() / 2);
87 currentPos.y -= (currentPos.y - newPos.y)
88 / (timer.getFrameRate() / 2);
89 currentPos.z -= (currentPos.z - newPos.z)
90 / (timer.getFrameRate() / 2);
92 lightNode.setLocalTranslation(currentPos);
95 protected void simpleInitGame() {
96 display.setTitle("Bezier Mesh Test");
97 cam.setLocation(new Vector3f(0, 0, 5));
99 currentPos = new Vector3f();
100 newPos = new Vector3f();
102 BezierPatch bp = new BezierPatch();
103 bp.setAnchor(0, 0, new Vector3f( -0.75f, -0.75f, -0.5f));
104 bp.setAnchor(0, 1, new Vector3f( -0.25f, -0.75f, 0.0f));
105 bp.setAnchor(0, 2, new Vector3f(0.25f, -0.75f, 0.5f));
106 bp.setAnchor(0, 3, new Vector3f(0.75f, -0.75f, 0.5f));
107 bp.setAnchor(1, 0, new Vector3f( -0.75f, -0.25f, -0.75f));
108 bp.setAnchor(1, 1, new Vector3f( -0.25f, -0.25f, 0.5f));
109 bp.setAnchor(1, 2, new Vector3f(0.25f, -0.25f, 0.5f));
110 bp.setAnchor(1, 3, new Vector3f(0.75f, -0.25f, 0.75f));
111 bp.setAnchor(2, 0, new Vector3f( -0.75f, 0.25f, -0.5f));
112 bp.setAnchor(2, 1, new Vector3f( -0.25f, 0.25f, -0.5f));
113 bp.setAnchor(2, 2, new Vector3f(0.25f, 0.25f, -0.5f));
114 bp.setAnchor(2, 3, new Vector3f(0.75f, 0.25f, 0.0f));
115 bp.setAnchor(3, 0, new Vector3f( -0.75f, 0.75f, -0.5f));
116 bp.setAnchor(3, 1, new Vector3f( -0.25f, 0.75f, -1.0f));
117 bp.setAnchor(3, 2, new Vector3f(0.25f, 0.75f, -1.0f));
118 bp.setAnchor(3, 3, new Vector3f(0.75f, 0.75f, -0.5f));
119 bp.setDetailLevel(64);
121 bez = new BezierMesh("Bezier Mesh");
123 Quaternion rot = new Quaternion();
124 rot.fromAngleAxis(FastMath.PI, new Vector3f(0,0,1));
125 bez.setLocalRotation(rot);
126 bez.setModelBound(new BoundingSphere());
127 bez.updateModelBound();
128 rootNode.attachChild(bez);
130 MaterialState ms = display.getRenderer().createMaterialState();
131 ms.setEmissive(new ColorRGBA(0.1f, 0.1f, 0.1f, 1.0f));
132 // ms.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
133 // ms.setDiffuse(new ColorRGBA(1.0f, 0.85f, 0.75f, 1.0f));
134 // ms.setSpecular(new ColorRGBA(0.8f, 0.8f, 0.8f, 1.0f));
135 ms.setShininess(128.0f);
137 bez.setRenderState(ms);
139 pl = new PointLight();
140 pl.setAmbient(new ColorRGBA(0, 0, 0, 1));
141 pl.setDiffuse(new ColorRGBA(1, 1, 1, 1));
142 pl.setSpecular(new ColorRGBA(.2f, .2f, .2f, 1));
145 lightState.detachAll();
146 lightState.attach(pl);
148 lightState.setTwoSidedLighting(true);
149 lightNode = new LightNode("Light Node");
150 lightNode.setLight(pl);
151 bez.setRenderState(lightState);
153 Vector3f min = new Vector3f( -0.15f, -0.15f, -0.15f);
154 Vector3f max = new Vector3f(0.15f, 0.15f, 0.15f);
155 Box lightBox = new Box("box", min, max);
156 lightBox.setLightCombineMode(Spatial.LightCombineMode.Off);
157 lightBox.setModelBound(new BoundingSphere());
158 lightBox.updateModelBound();
160 lightNode.attachChild(lightBox);
161 lightNode.setCullHint(Spatial.CullHint.Never);
163 rootNode.attachChild(lightNode);
165 TextureState ts = display.getRenderer().createTextureState();
168 TextureManager.loadTexture(
169 TestBezierMesh.class.getClassLoader().getResource(
170 "jmetest/data/images/Monkey.jpg"),
171 Texture.MinificationFilter.BilinearNearestMipMap,
172 Texture.MagnificationFilter.Bilinear));
174 bez.setRenderState(ts);