I have a C++ class that loads the data from a MD2 model into memory. I am trying to convert this into Java, but since I am not as familiar with java as I am with C++, I am having a bit of difficulty at one point. Instead of pasting the entire C++ code (it is rather lengthy), I will just supply the relevant parts:
first off, I have a few structs that look like this:
Using c Syntax Highlighting
- typedef struct
- {
- float[] point = new float[3];
- } Vector;
- typedef struct
- {
- int ident; //identifies as MD2 file "IDP2"
- int version; //should be equal to 8
- int skinWidth; //width of the texture
- int skinHeight; //height of the texture
- int frameSize; //number of bytes per frame
- int numSkins; //number of textures
- int numXYZ; //number of vertices
- int numST; //number of texture coordinates
- int numTris; //number of triangles
- int numGLcmds; //number of OpenGL command types
- int numFrames; //total number of frames;
- int offsetSkins; //offset of skin names (64 bytes each)
- int offsetST; //offset of texture coordinate pairs
- int offsetTris; //offset of triangle mesh
- int offsetFrames; //offset of frame data (points)
- int offsetGLcmds; //offset of type of OpenGL cmds to use
- int offsetEnd; //end of file;
- } ModelHeader;
- typedef struct
- {
- unsigned char v[3]; //point info
- unsigned char normalIndex; // normal index
- } FramePoint;
- typedef struct
- {
- float scale[3]; //scaling for frame vertices
- float translate[3]; //translation for frame vertices
- char name[16]; //name of model;
- FramePoint fp[1]; //beginning of frame vertex list;
- } Frame;
Parsed in 0.007 seconds, using GeSHi 1.0.8.4
then I have a seperate class called Model that contains a private variable like this:
Using c Syntax Highlighting
- private:
- ...
- Vector *vertexList; //Vertex list
Parsed in 0.001 seconds, using GeSHi 1.0.8.4
and then the C++ code I am stuck on is in a method called LoadModel():
Using c Syntax Highlighting
- Frame *frame; // Pointer to frame data
- Vector *vertexListPtr; //Pointer to vertex list
- ModelHeader *modelHeader; //Pointer to model header
- ...
- vertexList = new Vector[modelHeader->numXYZ * modelHeader->numFrames];
- ...
- numVertices = modelHeader->numXYZ;
- numFrames = modelHeader->numFrames;
- frameSize = modelHeader->frameSize;
- for(int j = 0; j < numFrames; j++)
- {
- ...
- vertexListPtr = (Vector*)&vertexList[numVertices * j];
- for(int i = 0; i < numVertices; i++)
- {
- vertexListPtr[i].point[0] = frame->scale[0] * frame->fp[i].v[0] + frame->translate[0];
- vertexListPtr[i].point[1] = frame>scale[1] * frame->fp[i].v[1] + frame->translate[1];
- vertexListPtr[i].point[2] = frame->scale[2] * frame->fp[i].v[2] + frame->translate[2];
- }
- }
Parsed in 0.005 seconds, using GeSHi 1.0.8.4
I can't for the life of me get this much converted to Java. Everything else in the method I can get working, but if I convert the structures and variables to how I THINK they should be represented in java, the loop at the end becomes impossible to wrap my head around... Any help on this?
Also, should I just use native code for this instead?





