Removed bad physics

This commit is contained in:
Ziver Koc 2009-03-10 12:59:02 +00:00
parent 309f612982
commit 5f797d9046
5 changed files with 251 additions and 1 deletions

View file

@ -21,6 +21,5 @@
<classpathentry kind="lib" path="lib/lwjgl_util_applet.jar"/>
<classpathentry kind="lib" path="lib/lwjgl_util.jar"/>
<classpathentry kind="lib" path="lib/lwjgl.jar"/>
<classpathentry kind="lib" path="lib/jme-physics.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

Binary file not shown.

5
src/sg/env/Envoriment.java vendored Normal file
View file

@ -0,0 +1,5 @@
package sg.env;
public class Envoriment {
}

148
src/sg/util/FileFinder.java Normal file
View file

@ -0,0 +1,148 @@
package sg.util;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.regex.Matcher;
/**
* File path utilities
*
* @author Ziver
*/
public class FileFinder {
/**
* Returns a String with a relative path from the given path
*
* @param file The file to get a relative path from
* @param path The path
* @return A String with a relative path
*/
public static String relativePath(File file, String path){
String absolute = file.getAbsolutePath();
String tmpPath = path.replaceAll(
"[/\\\\]",
Matcher.quoteReplacement(File.separator));
String relative = absolute.substring(
absolute.indexOf(tmpPath)+path.length(),
absolute.length());
return relative;
}
/**
* Returns the File object for the given file
*
* @param path The path to the file (no / if not absolute path)
* @return A File object for the file
* @throws URISyntaxException
*/
public static File find(String path){
try {
File file = new File(path);
if(file!=null && file.exists()){
return file;
}
return new File(findURL(path).toURI());
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* Reads and returns the content of a file as a String.
* Or use FileUtils.readFileToString(file);
*
* @param file The file to read
* @return The file content
* @throws IOException
*/
public static String getFileContent(File file) throws IOException{
BufferedReader in = new BufferedReader(new FileReader(file));
StringBuffer ret = new StringBuffer();
int tmp;
while((tmp=in.read()) != -1){
ret.append((char)tmp);
}
in.close();
return ret.toString();
}
/**
* Returns the URL to the given file
*
* @param path The path to the file (no / if not absolute path)
* @return A URL object for the file
* @throws URISyntaxException
*/
public static URL findURL(String path){
return FileFinder.class.getClassLoader().getResource(path);
}
/**
* Returns a ArrayList with all the files in a folder and sub folders
*
* @param dir The directory to search in
* @return The ArrayList with the files
*/
public static ArrayList<File> search(File dir){
return search(dir, new ArrayList<File>());
}
/**
* Returns a ArrayList with all the files in a folder and sub folders
*
* @param dir The directory to search in
* @param fileList The ArrayList to add the files to
* @return The ArrayList with the files
*/
public static ArrayList<File> search(File dir, ArrayList<File> fileList){
String[] temp = dir.list();
File file;
if(temp != null){
for(int i=0; i<temp.length ;i++){
file = new File(dir.getPath()+File.separator+temp[i]);
if(file.isDirectory()){
search(new File(dir.getPath()+File.separator+temp[i]+File.separator),fileList);
}
else if(file.isFile()){
System.out.println("File Found: "+file);
fileList.add(file);
}
}
}
return fileList;
}
/**
* Returns the extension of the file
* @param file The file
* @return The extension
*/
public static String fileExtension(File file){
return fileExtension(file.getName());
}
/**
* Returns the extension of the file
* @param file The file
* @return The extension
*/
public static String fileExtension(String file){
if(file.lastIndexOf(".")==-1)
return "";
return file.substring(file.lastIndexOf(".")+1,file.length());
}
}

98
src/sg/util/Util.java Normal file
View file

@ -0,0 +1,98 @@
package sg.util;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import com.jme.bounding.BoundingBox;
import com.jme.scene.Node;
import com.jme.scene.Spatial;
import com.jme.util.export.binary.BinaryImporter;
import com.jme.util.resource.ResourceLocatorTool;
import com.jme.util.resource.SimpleResourceLocator;
import com.jmex.model.converters.AseToJme;
import com.jmex.model.converters.MaxToJme;
import com.jmex.model.converters.Md2ToJme;
import com.jmex.model.converters.Md3ToJme;
import com.jmex.model.converters.MilkToJme;
import com.jmex.model.converters.ObjToJme;
/**
* Helper class for loading models and other stuff. Currently only loads JME
* binary models, but it's easily customizable for loading other types.
*
* @author Erick B Passos
*
*/
public class Util {
// So JME can find the model textures easily.
private static URL textureSearchPath;
static {
textureSearchPath = Util.class.getClassLoader().getResource("tancz/test/physics/vehicle/data/");
try {
ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE, new SimpleResourceLocator(textureSearchPath));
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
/**
* Loads a model from file, creating a bounding box for it.
* @param path Path to jme file.
* @return loaded model
* @throws IOException
*/
public static Node loadModel(String path) {
try {
Node node = new Node();
BufferedInputStream in = new BufferedInputStream(FileFinder.findURL(path).openStream());
String ext = FileFinder.fileExtension(path);
if(ext.equalsIgnoreCase("jme")){
node.attachChild((Spatial)BinaryImporter.getInstance().load(in));
}
else{
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); //For loading the raw file
// Converts the file into a jme usable file
if(ext.equalsIgnoreCase("3ds")) new MaxToJme().convert(in, byteArrayOutputStream);
else if(ext.equalsIgnoreCase("ase")) new AseToJme().convert(in, byteArrayOutputStream);
else if(ext.equalsIgnoreCase("md2")) new Md2ToJme().convert(in, byteArrayOutputStream);
else if(ext.equalsIgnoreCase("md3")) new Md3ToJme().convert(in, byteArrayOutputStream);
else if(ext.equalsIgnoreCase("ms3d")) new MilkToJme().convert(in, byteArrayOutputStream);
else if(ext.equalsIgnoreCase("obj")) new ObjToJme().convert(in, byteArrayOutputStream);
// Used to convert the jme usable file to a TriMesh
ByteArrayInputStream bridge = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
//importer returns a Loadable, cast to Node
node.attachChild((Spatial)BinaryImporter.getInstance().load(bridge));
}
node.setModelBound(new BoundingBox());
node.updateModelBound();
return node;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
/**
* Helper method to apply a ZBufferState to a node.
* @param node
*/
/*
public static void applyZBuffer(Node node) {
ZBufferState zbuf = DisplaySystem.getDisplaySystem().getRenderer().createZBufferState();
zbuf.setWritable(false);
zbuf.setEnabled(true);
zbuf.setFunction(ZBufferState.CF_LEQUAL);
node.setRenderState(zbuf);
}*/
}