Tweaks to the Vector package, and finalized the Model structure. So I hope.

This commit is contained in:
Caspian Rychlik-Prince 2004-04-19 21:54:58 +00:00
parent f33a019675
commit c41ac67aae
12 changed files with 385 additions and 106 deletions

View File

@ -45,11 +45,15 @@ public class Frame implements Serializable {
/** The new transformations for each Bone in the Skeleton */
private final Matrix4f[] bone;
/** Frame time */
private final float time;
/**
* C'tor
* @param bone[]
*/
public Frame(Matrix4f[] bone) {
public Frame(float time, Matrix4f[] bone) {
this.time = time;
this.bone = bone;
}
@ -59,4 +63,11 @@ public class Frame implements Serializable {
public Matrix4f[] getBone() {
return bone;
}
/**
* @return the frame time
*/
public float getTime() {
return time;
}
}

View File

@ -51,23 +51,34 @@ public class Model implements Serializable {
public static final long serialVersionUID = 1L;
/** The Mesh */
private final Mesh mesh;
/** Material */
private final String material;
/** Vertices */
private final Vertex[] vertex;
/** Triangles */
private final Triangle[] triangle;
/** The animations: a Map of string names to Frame[] arrays */
private final Map animation;
/**
* C'tor
* @param mesh
* @param frame
* @param material
* @param vertex
* @param triangle
* @param animation
*/
public Model(Mesh mesh, Map animation) {
this.mesh = mesh;
public Model(String material, Vertex[] vertex, Triangle[] triangle, Map animation) {
this.material = material;
this.vertex = vertex;
this.triangle = triangle;
this.animation = animation;
}
/**
* Get a named animation from the Model
* @param name The name of the animation
* @return the Frames of an animation (or null, if no such animation exists)
*/
@ -76,10 +87,25 @@ public class Model implements Serializable {
}
/**
* @return the Mesh
* @return Returns the material.
*/
public Mesh getMesh() {
return mesh;
public String getMaterial() {
return material;
}
/**
* @return Returns the triangles.
*/
public Triangle[] getTriangle() {
return triangle;
}
/**
* @return Returns the vertices
*/
public Vertex[] getVertex() {
return vertex;
}
}

View File

@ -35,58 +35,39 @@ import java.io.Serializable;
/**
* $Id$
*
* A Mesh is a collection of Triangles that all share the same material (ie. rendering
* state).
*
* Describes how a bone influences a vertex.
* @author $Author$
* @version $Revision$
*/
public class Mesh implements Serializable {
public class Skin implements Serializable {
public static final long serialVersionUID = 1L;
/** Material */
private final String material;
/** Vertices */
private final Vertex[] vertex;
/** Triangles */
private final Triangle[] triangle;
/** Bone index */
private final int bone;
/** Weight */
private final float weight;
/**
* C'tor
* @param material
* @param vertex
* @param triangle
*/
public Mesh(String material, Vertex[] vertex, Triangle[] triangle) {
this.material = material;
this.vertex = vertex;
this.triangle = triangle;
public Skin(int bone, float weight) {
this.bone = bone;
this.weight = weight;
}
/**
* @return Returns the material.
* @return Returns the bone index.
*/
public String getMaterial() {
return material;
public int getBone() {
return bone;
}
/**
* @return Returns the triangles.
* @return Returns the weight.
*/
public Triangle[] getTriangle() {
return triangle;
public float getWeight() {
return weight;
}
/**
* @return Returns the vertices
*/
public Vertex[] getVertex() {
return vertex;
}
}

View File

@ -31,24 +31,59 @@
*/
package org.lwjgl.util.model;
import java.io.Serializable;
/**
* $Id$
* @author $Author$
* @version $Revision$
*/
public class Triangle {
public class Triangle implements Serializable {
public static final long serialVersionUID = 1L;
/** Vertex indices: these look up into the parent Mesh's vertex array */
private int a, b, c;
private final int a, b, c;
/** Adjacency, for stripification */
private int adjacency;
private final int adjacency;
/**
* C'tor
* @param a
* @param b
* @param c
* @param adjacency
*/
public Triangle() {
public Triangle(int a, int b, int c, int adjacency) {
this.a = a;
this.b = b;
this.c = c;
this.adjacency = adjacency;
}
/**
* @return Returns the 'a' vertex index
*/
public int getA() {
return a;
}
/**
* @return Returns the 'b' vertex index
*/
public int getB() {
return b;
}
/**
* @return Returns the 'c' vertex index
*/
public int getC() {
return c;
}
/**
* @return Returns the adjacency.
*/
public int getAdjacency() {
return adjacency;
}
}

View File

@ -33,10 +33,13 @@ package org.lwjgl.util.model;
import java.io.Serializable;
import org.lwjgl.util.vector.ReadableVector2f;
import org.lwjgl.util.vector.ReadableVector3f;
/**
* $Id$
*
* A single vertex in a Triangle
* A single vertex in a mesh.
*
* @author $Author$
* @version $Revision$
@ -46,44 +49,56 @@ public class Vertex implements Serializable {
public static final long serialVersionUID = 1L;
/** Coordinates */
private final float x, y, z;
private final ReadableVector3f coords;
/** Normal */
private final float nx, ny, nz;
private final ReadableVector3f normal;
/** Texture coordinates */
private final float u, v;
/** Bone indices: these look up into the current Frame's bone array */
private final int[] bone;
/** Bone weights (always sum to 1.0f) */
private final float[] weight;
private final ReadableVector2f texCoords;
/** Skin */
private final Skin[] skin;
/**
* C'tor
* @param x
* @param y
* @param z
* @param nx
* @param ny
* @param nz
* @param u
* @param v
* @param bone
* @param weight
* @param coords
* @param normal
* @param texCoords
* @param skin
*/
public Vertex(float x, float y, float z, float nx, float ny, float nz,
float u, float v, int[] bone, float[] weight) {
this.x = x;
this.y = y;
this.z = z;
this.nx = nx;
this.ny = ny;
this.nz = nz;
this.u = u;
this.v = v;
this.bone = bone;
this.weight = weight;
public Vertex(ReadableVector3f coords, ReadableVector3f normal, ReadableVector2f texCoords, Skin[] skin) {
this.coords = coords;
this.normal = normal;
this.texCoords = texCoords;
this.skin = skin;
}
/**
* @return Returns the coords.
*/
public ReadableVector3f getCoords() {
return coords;
}
/**
* @return Returns the normal.
*/
public ReadableVector3f getNormal() {
return normal;
}
/**
* @return Returns the skin.
*/
public Skin[] getSkin() {
return skin;
}
/**
* @return Returns the texCoords.
*/
public ReadableVector2f getTexCoords() {
return texCoords;
}
}

View File

@ -34,6 +34,7 @@ package org.lwjgl.util.model.renderer;
import java.util.HashMap;
import java.util.Map;
import org.lwjgl.util.model.Frame;
import org.lwjgl.util.model.Model;
/**
@ -63,11 +64,24 @@ public class Renderer {
/**
* Render a Model
* @param model The model to render
* @param animation The name of the animation
* @param time The time for the animation
*/
public void render(Model model) {
public void render(Model model, String animation, float time) {
// 1. Set up GL state from the Model's material
Renderable material = (Renderable) materials.get(model.getMesh().getMaterial());
Renderable material = (Renderable) materials.get(model.getMaterial());
if (material != null) {
material.render();
}
// 2. Get the animation
Frame[] frame = model.getAnimation(animation);
if (frame == null) {
return;
}
// 3. Work out what the nearest frame is to the specified time
}

View File

@ -43,7 +43,7 @@ import java.nio.FloatBuffer;
* @version $Revision$
*/
public class Vector2f extends Vector implements Serializable, ReadableVector2f {
public class Vector2f extends Vector implements Serializable, ReadableVector2f, WritableVector2f {
public float x, y;
@ -68,14 +68,12 @@ public class Vector2f extends Vector implements Serializable, ReadableVector2f {
set(x, y);
}
/**
* Set values
* @return this
/* (non-Javadoc)
* @see org.lwjgl.util.vector.WritableVector2f#set(float, float)
*/
public Vector2f set(float x, float y) {
public void set(float x, float y) {
this.x = x;
this.y = y;
return this;
}
/**
@ -188,7 +186,8 @@ public class Vector2f extends Vector implements Serializable, ReadableVector2f {
if (dest == null)
return new Vector2f(left.x + right.x, left.y + right.y);
else {
return dest.set(left.x + right.x, left.y + right.y);
dest.set(left.x + right.x, left.y + right.y);
return dest;
}
}
@ -204,7 +203,8 @@ public class Vector2f extends Vector implements Serializable, ReadableVector2f {
if (dest == null)
return new Vector2f(left.x - right.x, left.y - right.y);
else {
return dest.set(left.x - right.x, left.y - right.y);
dest.set(left.x - right.x, left.y - right.y);
return dest;
}
}

View File

@ -43,7 +43,7 @@ import java.nio.FloatBuffer;
* @version $Revision$
*/
public class Vector3f extends Vector implements Serializable, ReadableVector3f {
public class Vector3f extends Vector implements Serializable, ReadableVector3f, WritableVector3f {
public float x, y, z;
@ -68,15 +68,21 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f {
set(x, y, z);
}
/**
* Set values
* @return this
/* (non-Javadoc)
* @see org.lwjgl.util.vector.WritableVector2f#set(float, float)
*/
public Vector3f set(float x, float y, float z) {
public void set(float x, float y) {
this.x = x;
this.y = y;
}
/* (non-Javadoc)
* @see org.lwjgl.util.vector.WritableVector3f#set(float, float, float)
*/
public void set(float x, float y, float z) {
this.x = x;
this.y = y;
this.z = z;
return this;
}
/**
@ -123,7 +129,8 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f {
if (dest == null)
return new Vector3f(left.x + right.x, left.y + right.y, left.z + right.z);
else {
return dest.set(left.x + right.x, left.y + right.y, left.z + right.z);
dest.set(left.x + right.x, left.y + right.y, left.z + right.z);
return dest;
}
}
@ -139,7 +146,8 @@ public class Vector3f extends Vector implements Serializable, ReadableVector3f {
if (dest == null)
return new Vector3f(left.x - right.x, left.y - right.y, left.z - right.z);
else {
return dest.set(left.x - right.x, left.y - right.y, left.z - right.z);
dest.set(left.x - right.x, left.y - right.y, left.z - right.z);
return dest;
}
}

View File

@ -43,7 +43,7 @@ import java.nio.FloatBuffer;
* @version $Revision$
*/
public class Vector4f extends Vector implements Serializable, ReadableVector4f {
public class Vector4f extends Vector implements Serializable, ReadableVector4f, WritableVector4f {
public float x, y, z, w;
@ -68,16 +68,31 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f {
set(x, y, z, w);
}
/**
* Set values
* @return this
/* (non-Javadoc)
* @see org.lwjgl.util.vector.WritableVector2f#set(float, float)
*/
public Vector4f set(float x, float y, float z, float w) {
public void set(float x, float y) {
this.x = x;
this.y = y;
}
/* (non-Javadoc)
* @see org.lwjgl.util.vector.WritableVector3f#set(float, float, float)
*/
public void set(float x, float y, float z) {
this.x = x;
this.y = y;
this.z = z;
}
/* (non-Javadoc)
* @see org.lwjgl.util.vector.WritableVector4f#set(float, float, float, float)
*/
public void set(float x, float y, float z, float w) {
this.x = x;
this.y = y;
this.z = z;
this.w = w;
return this;
}
/**
@ -126,7 +141,8 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f {
if (dest == null)
return new Vector4f(left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w);
else {
return dest.set(left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w);
dest.set(left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w);
return dest;
}
}
@ -142,7 +158,8 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f {
if (dest == null)
return new Vector4f(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w);
else {
return dest.set(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w);
dest.set(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w);
return dest;
}
}
@ -294,6 +311,7 @@ public class Vector4f extends Vector implements Serializable, ReadableVector4f {
this.z = z;
}
/* (Overrides)
* @see org.lwjgl.vector.ReadableVector3f#getZ()
*/

View File

@ -0,0 +1,61 @@
/*
* Copyright (c) 2003 Shaven Puppy Ltd
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'Shaven Puppy' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl.util.vector;
/**
* $Id$
* Writable interface to Vector2fs
* @author $author$
* @version $revision$
*/
public interface WritableVector2f {
/**
* Set the X value
* @param x
*/
public void setX(float x);
/**
* Set the Y value
* @param y
*/
public void setY(float y);
/**
* Set the X,Y values
* @param x, y
*/
public void set(float x, float y);
}

View File

@ -0,0 +1,55 @@
/*
* Copyright (c) 2003 Shaven Puppy Ltd
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'Shaven Puppy' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl.util.vector;
/**
* $Id$
* Writable interface to Vector3fs
* @author $author$
* @version $revision$
*/
public interface WritableVector3f extends WritableVector2f {
/**
* Set the Z value
* @param z
*/
public void setZ(float z);
/**
* Set the X,Y,Z values
* @param x, y, z
*/
public void set(float x, float y, float z);
}

View File

@ -0,0 +1,55 @@
/*
* Copyright (c) 2003 Shaven Puppy Ltd
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'Shaven Puppy' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl.util.vector;
/**
* $Id$
* Writable interface to Vector4fs
* @author $author$
* @version $revision$
*/
public interface WritableVector4f extends WritableVector3f {
/**
* Set the W value
* @param w
*/
public void setW(float w);
/**
* Set the X,Y,Z,W values
* @param x, y, z, w
*/
public void set(float x, float y, float z, float w);
}