Fixed the util class and Environment

This commit is contained in:
Ziver Koc 2009-03-10 16:32:33 +00:00
parent cbd89ddb05
commit 1bc2424920
6 changed files with 44 additions and 50 deletions

View file

@ -11,13 +11,13 @@
<classpathentry kind="lib" path="lib/jme-font.jar"/> <classpathentry kind="lib" path="lib/jme-font.jar"/>
<classpathentry kind="lib" path="lib/jme-gamestates.jar"/> <classpathentry kind="lib" path="lib/jme-gamestates.jar"/>
<classpathentry kind="lib" path="lib/jme-model.jar"/> <classpathentry kind="lib" path="lib/jme-model.jar"/>
<classpathentry kind="lib" path="lib/jme-physics.jar"/> <classpathentry kind="lib" path="lib/jme-physics.jar" sourcepath="C:/Users/Ziver/Documents/Programmering/Java/libs/jme/jME Physics 2/src"/>
<classpathentry kind="lib" path="lib/jme-scene.jar"/> <classpathentry kind="lib" path="lib/jme-scene.jar"/>
<classpathentry kind="lib" path="lib/jme-swt.jar"/> <classpathentry kind="lib" path="lib/jme-swt.jar"/>
<classpathentry kind="lib" path="lib/jme-terrain.jar"/> <classpathentry kind="lib" path="lib/jme-terrain.jar"/>
<classpathentry kind="lib" path="lib/jme-test.jar"/> <classpathentry kind="lib" path="lib/jme-test.jar"/>
<classpathentry kind="lib" path="lib/jme-xml.jar"/> <classpathentry kind="lib" path="lib/jme-xml.jar"/>
<classpathentry kind="lib" path="lib/jme.jar"/> <classpathentry kind="lib" path="lib/jme.jar" sourcepath="C:/Users/Ziver/Documents/Programmering/Java/libs/jme/jme/src"/>
<classpathentry kind="lib" path="lib/lwjgl_test.jar"/> <classpathentry kind="lib" path="lib/lwjgl_test.jar"/>
<classpathentry kind="lib" path="lib/lwjgl_util_applet.jar"/> <classpathentry kind="lib" path="lib/lwjgl_util_applet.jar"/>
<classpathentry kind="lib" path="lib/lwjgl_util.jar"/> <classpathentry kind="lib" path="lib/lwjgl_util.jar"/>

View file

@ -62,6 +62,6 @@ public class SpaceGame extends SimplePhysicsGame {
} }
public void simpleUpdate(){ public void simpleUpdate(){
environment.setLocalTranslation(cam.getLocation()); environment.update();
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 MiB

After

Width:  |  Height:  |  Size: 2.2 MiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 971 KiB

After

Width:  |  Height:  |  Size: 1.1 MiB

Before After
Before After

View file

@ -1,59 +1,38 @@
package sg.env; package sg.env;
import sg.SpaceGame; import sg.util.SGUtil;
import com.jme.image.Texture; import com.jme.image.Texture;
import com.jme.scene.Node; import com.jme.scene.Node;
import com.jme.scene.Skybox; import com.jme.scene.Skybox;
import com.jme.util.TextureManager; import com.jme.system.DisplaySystem;
public class Environment extends Node { public class Environment extends Node {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private Skybox space;
public Environment(){ public Environment(){
buildSkyBox(); buildSkyBox();
} }
private void buildSkyBox() { private void buildSkyBox() {
Skybox skybox = new Skybox("skybox", 500, 500, 500); space = new Skybox("space", 500, 500, 500);
Texture north = TextureManager.loadTexture( Texture north = SGUtil.loadTexture("sg/data/skybox/advanced/front.png");
SpaceGame.class.getClassLoader().getResource( Texture rest = SGUtil.loadTexture("sg/data/skybox/advanced/rest.png");
"sg/data/skybox/advanced/front.png"),
Texture.MinificationFilter.BilinearNearestMipMap, space.setTexture(Skybox.Face.North, north);
Texture.MagnificationFilter.Bilinear); space.setTexture(Skybox.Face.West, rest);
Texture south = TextureManager.loadTexture( space.setTexture(Skybox.Face.South, rest);
SpaceGame.class.getClassLoader().getResource( space.setTexture(Skybox.Face.East, rest);
"sg/data/skybox/advanced/rest.png"), space.setTexture(Skybox.Face.Up, rest);
Texture.MinificationFilter.BilinearNearestMipMap, space.setTexture(Skybox.Face.Down, rest);
Texture.MagnificationFilter.Bilinear); space.preloadTextures();
Texture east = TextureManager.loadTexture( space.updateRenderState();
SpaceGame.class.getClassLoader().getResource( this.attachChild(space);
"sg/data/skybox/advanced/rest.png"), }
Texture.MinificationFilter.BilinearNearestMipMap,
Texture.MagnificationFilter.Bilinear); public void update(){
Texture west = TextureManager.loadTexture( space.setLocalTranslation(DisplaySystem.getDisplaySystem().getRenderer().getCamera().getLocation());
SpaceGame.class.getClassLoader().getResource(
"sg/data/skybox/advanced/rest.png"),
Texture.MinificationFilter.BilinearNearestMipMap,
Texture.MagnificationFilter.Bilinear);
Texture up = TextureManager.loadTexture(
SpaceGame.class.getClassLoader().getResource(
"sg/data/skybox/advanced/rest.png"),
Texture.MinificationFilter.BilinearNearestMipMap,
Texture.MagnificationFilter.Bilinear);
Texture down = TextureManager.loadTexture(
SpaceGame.class.getClassLoader().getResource(
"sg/data/skybox/advanced/rest.png"),
Texture.MinificationFilter.BilinearNearestMipMap,
Texture.MagnificationFilter.Bilinear);
skybox.setTexture(Skybox.Face.North, north);
skybox.setTexture(Skybox.Face.West, west);
skybox.setTexture(Skybox.Face.South, south);
skybox.setTexture(Skybox.Face.East, east);
skybox.setTexture(Skybox.Face.Up, up);
skybox.setTexture(Skybox.Face.Down, down);
skybox.preloadTextures();
skybox.updateRenderState();
this.attachChild(skybox);
} }
} }

View file

@ -8,10 +8,10 @@ import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import com.jme.bounding.BoundingBox; import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.scene.Node; import com.jme.scene.Node;
import com.jme.scene.Spatial; import com.jme.scene.Spatial;
import com.jme.scene.state.ZBufferState; import com.jme.util.TextureManager;
import com.jme.system.DisplaySystem;
import com.jme.util.export.binary.BinaryImporter; import com.jme.util.export.binary.BinaryImporter;
import com.jme.util.resource.ResourceLocatorTool; import com.jme.util.resource.ResourceLocatorTool;
import com.jme.util.resource.SimpleResourceLocator; import com.jme.util.resource.SimpleResourceLocator;
@ -29,12 +29,12 @@ import com.jmex.model.converters.ObjToJme;
* @author Erick B Passos * @author Erick B Passos
* *
*/ */
public class Util { public class SGUtil {
// So JME can find the model textures easily. // So JME can find the model textures easily.
private static URL textureSearchPath; private static URL textureSearchPath;
static { static {
textureSearchPath = Util.class.getClassLoader().getResource("tancz/test/physics/vehicle/data/"); textureSearchPath = SGUtil.class.getClassLoader().getResource("sg/data/");
try { try {
ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, new SimpleResourceLocator(textureSearchPath)); ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, new SimpleResourceLocator(textureSearchPath));
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
@ -85,15 +85,30 @@ public class Util {
return null; return null;
} }
/**
* Loads textures
*
* @param url is the path to the texture
* @return an texture
*/
public static Texture loadTexture(String url){
return TextureManager.loadTexture(
FileFinder.findURL(url),
Texture.MinificationFilter.BilinearNearestMipMap,
Texture.MagnificationFilter.Bilinear);
}
/** /**
* Helper method to apply a ZBufferState to a node. * Helper method to apply a ZBufferState to a node.
* @param node * @param node
*/ */
/*
public static void applyZBuffer(Node node) { public static void applyZBuffer(Node node) {
ZBufferState zbuf = DisplaySystem.getDisplaySystem().getRenderer().createZBufferState(); ZBufferState zbuf = DisplaySystem.getDisplaySystem().getRenderer().createZBufferState();
zbuf.setWritable(false); zbuf.setWritable(false);
zbuf.setEnabled(true); zbuf.setEnabled(true);
zbuf.setFunction(ZBufferState.CF_LEQUAL); zbuf.setFunction(ZBufferState.CF_LEQUAL);
node.setRenderState(zbuf); node.setRenderState(zbuf);
} }*/
} }