MD2 loader

Hello guys i’m trying to implementing a md2 loader in java, inspired in this tutorial:

http://tfc.duke.free.fr/old/models/md2.htm

its in c++ and i´m trying to convert to java.

So the question is to verify if is a md2 file
i need to check the ident which is “IDP2”
and i´m doing in the following way:

private static boolean isMD2File(MD2Header header) {
		if ((String.valueOf(header.ident) != MD2_IDENT)
				&& (header.version != MD2_VERSION)) {
			System.err.println("Not a MD2 file");
			return false;
		}
		return true;
	}

I defined the contant:

private static final String MD2_IDENT = "IPD2";

So after reading the header i transform the header.ident to a string then i compare with my constant.
i want to know if it’s the right way to do this.
Thanks.

Don’t compare String by using == or !=, use http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#equals(java.lang.Object) instead.

thank you

updated:

	private static boolean isMD2File(MD2Header header) {
		if ((!String.valueOf(header.ident).equalsIgnoreCase( MD2_IDENT))
				&& (header.version != MD2_VERSION)) {
			System.err.println("Not a MD2 file");
			return false;
		}
		return true;
	}

Don’t reinvent the wheel:
https://github.com/gouessej/Ardor3D/blob/master/ardor3d-extras/src/main/java/com/ardor3d/extension/model/md2/Md2Importer.java#L121

This importer has already been ported to Java several times…

Also see http://sourceforge.net/p/jagatoo/code/HEAD/tree/trunk/src/org/jagatoo/loaders/models/

What does this operation?

('2' << 24) + ('P' << 16) + ('D' << 8) + 'I')

It puts the String “IDP2” into a 32bit integer. (Lookup http://en.wikipedia.org/wiki/Endianness)

Thank you very much ;D