Made gluProject to use one result FloatBuffer, javadoc corrections

This commit is contained in:
Ioannis Tsakpinis 2004-02-29 23:42:51 +00:00
parent e1e6ea2093
commit 7dc7337396
7 changed files with 91 additions and 98 deletions

View File

@ -8,8 +8,8 @@ import org.lwjgl.opengl.GL11;
/** /**
* GLU.java * GLU.java
* *
* *
* Created 23-dec-2003 * Created 23-dec-2003
* @author Erik Duijs * @author Erik Duijs
*/ */
@ -53,7 +53,7 @@ public class GLU implements GLUConstants {
float right, float right,
float bottom, float bottom,
float top) { float top) {
GL11.glOrtho(left, right, bottom, top, -1.0, 1.0); GL11.glOrtho(left, right, bottom, top, -1.0, 1.0);
} }
@ -81,18 +81,16 @@ public class GLU implements GLUConstants {
* @param modelMatrix * @param modelMatrix
* @param projMatrix * @param projMatrix
* @param viewport * @param viewport
* @param winx * @param win_pos
* @param winy
* @param winz
* @return * @return
*/ */
public static boolean gluProject(float objx, float objy, float objz, public static boolean gluProject(float objx, float objy, float objz,
FloatBuffer modelMatrix, FloatBuffer modelMatrix,
FloatBuffer projMatrix, FloatBuffer projMatrix,
IntBuffer viewport, IntBuffer viewport,
FloatBuffer winx, FloatBuffer winy, FloatBuffer winz) FloatBuffer win_pos)
{ {
return Project.gluProject(objx, objy, objz, modelMatrix, projMatrix, viewport, winx, winy, winz); return Project.gluProject(objx, objy, objz, modelMatrix, projMatrix, viewport, win_pos);
} }
/** /**
@ -107,7 +105,7 @@ public class GLU implements GLUConstants {
* @return * @return
*/ */
public static boolean gluUnProject(float winx, float winy, float winz, public static boolean gluUnProject(float winx, float winy, float winz,
FloatBuffer modelMatrix, FloatBuffer modelMatrix,
FloatBuffer projMatrix, FloatBuffer projMatrix,
IntBuffer viewport, IntBuffer viewport,
FloatBuffer obj_pos) FloatBuffer obj_pos)
@ -129,7 +127,7 @@ public class GLU implements GLUConstants {
float width, float width,
float height, float height,
IntBuffer viewport) { IntBuffer viewport) {
Project.gluPickMatrix(x, y, width, height, viewport); Project.gluPickMatrix(x, y, width, height, viewport);
} }
@ -141,11 +139,11 @@ public class GLU implements GLUConstants {
public static String gluGetString(int name) { public static String gluGetString(int name) {
return Registry.gluGetString(name); return Registry.gluGetString(name);
} }
/** /**
* Method gluCheckExtension. * Method gluCheckExtension.
* @param string * @param extName
* @param string1 * @param extString
* @return boolean * @return boolean
*/ */
public static boolean gluCheckExtension(String extName, String extString) { public static boolean gluCheckExtension(String extName, String extString) {
@ -171,21 +169,21 @@ public class GLU implements GLUConstants {
int format, int format,
int type, int type,
ByteBuffer data) { ByteBuffer data) {
return MipMap.gluBuild2DMipmaps(target, components, width, height, format, type, data); return MipMap.gluBuild2DMipmaps(target, components, width, height, format, type, data);
} }
/** /**
* Method gluScaleImage. * Method gluScaleImage.
* @param format * @param format
* @param width * @param widthIn
* @param height * @param heightIn
* @param type * @param typeIn
* @param data * @param dataIn
* @param w * @param widthOut
* @param h * @param heightOut
* @param type1 * @param typeOut
* @param image * @param dataOut
* @return int * @return int
*/ */
public static int gluScaleImage( public static int gluScaleImage(
@ -198,7 +196,7 @@ public class GLU implements GLUConstants {
int heightOut, int heightOut,
int typeOut, int typeOut,
ByteBuffer dataOut) { ByteBuffer dataOut) {
return MipMap.gluScaleImage(format, widthIn, heightIn, typeIn, dataIn, widthOut, heightOut, typeOut, dataOut); return MipMap.gluScaleImage(format, widthIn, heightIn, typeIn, dataIn, widthOut, heightOut, typeOut, dataOut);
} }

View File

@ -6,8 +6,8 @@ import org.lwjgl.opengl.GL11;
/** /**
* MipMap.java * MipMap.java
* *
* *
* Created 11-jan-2004 * Created 11-jan-2004
* @author Erik Duijs * @author Erik Duijs
*/ */
@ -15,7 +15,7 @@ public class MipMap extends Util implements GLUConstants {
/** /**
* Method gluBuild2DMipmaps * Method gluBuild2DMipmaps
* *
* @param target * @param target
* @param components * @param components
* @param width * @param width
@ -123,14 +123,14 @@ public class MipMap extends Util implements GLUConstants {
/** /**
* Method gluScaleImage. * Method gluScaleImage.
* @param format * @param format
* @param width * @param widthIn
* @param height * @param heightIn
* @param type * @param typein
* @param data * @param dataIn
* @param w * @param widthOut
* @param h * @param heightOut
* @param type1 * @param typeOut
* @param image * @param dataOut
* @return int * @return int
*/ */
public static int gluScaleImage( public static int gluScaleImage(
@ -149,7 +149,7 @@ public class MipMap extends Util implements GLUConstants {
float sx, sy; float sx, sy;
int sizein, sizeout; int sizein, sizeout;
int rowstride, rowlen; int rowstride, rowlen;
components = compPerPix(format); components = compPerPix(format);
if (components == -1) { if (components == -1) {
return GLU_INVALID_ENUM; return GLU_INVALID_ENUM;
@ -253,7 +253,7 @@ public class MipMap extends Util implements GLUConstants {
} }
} }
// Convert temp output // Convert temp output
if (pss.packRowLength > 0) { if (pss.packRowLength > 0) {
rowlen = pss.packRowLength; rowlen = pss.packRowLength;

View File

@ -4,8 +4,8 @@ import org.lwjgl.opengl.GL11;
/** /**
* PixelStoreState.java * PixelStoreState.java
* *
* *
* Created 11-jan-2004 * Created 11-jan-2004
* @author Erik Duijs * @author Erik Duijs
*/ */
@ -19,15 +19,15 @@ class PixelStoreState extends Util implements GLUConstants {
public int packAlignment = glGetIntegerv(GL11.GL_PACK_ALIGNMENT); public int packAlignment = glGetIntegerv(GL11.GL_PACK_ALIGNMENT);
public int packSkipRows = glGetIntegerv(GL11.GL_PACK_SKIP_ROWS); public int packSkipRows = glGetIntegerv(GL11.GL_PACK_SKIP_ROWS);
public int packSkipPixels = glGetIntegerv(GL11.GL_PACK_SKIP_PIXELS); public int packSkipPixels = glGetIntegerv(GL11.GL_PACK_SKIP_PIXELS);
/** /**
* Constructor for PixelStoreState. * Constructor for PixelStoreState.
*/ */
public PixelStoreState() { PixelStoreState() {
super(); super();
load(); load();
} }
public void load() { public void load() {
unpackRowLength = glGetIntegerv(GL11.GL_UNPACK_ROW_LENGTH); unpackRowLength = glGetIntegerv(GL11.GL_UNPACK_ROW_LENGTH);
unpackAlignment = glGetIntegerv(GL11.GL_UNPACK_ALIGNMENT); unpackAlignment = glGetIntegerv(GL11.GL_UNPACK_ALIGNMENT);

View File

@ -7,8 +7,8 @@ import org.lwjgl.opengl.GL11;
/** /**
* Project.java * Project.java
* *
* *
* Created 11-jan-2004 * Created 11-jan-2004
* @author Erik Duijs * @author Erik Duijs
*/ */
@ -48,7 +48,7 @@ public class Project extends Util implements GLUConstants {
private static void __gluMultMatrixVecf(FloatBuffer finalMatrix, float[] in, float[] out) { private static void __gluMultMatrixVecf(FloatBuffer finalMatrix, float[] in, float[] out) {
for (int i=0; i<4; i++) { for (int i=0; i<4; i++) {
out[i] = out[i] =
in[0] * finalMatrix.get(0*4+i) + in[0] * finalMatrix.get(0*4+i) +
in[1] * finalMatrix.get(1*4+i) + in[1] * finalMatrix.get(1*4+i) +
in[2] * finalMatrix.get(2*4+i) + in[2] * finalMatrix.get(2*4+i) +
@ -57,8 +57,8 @@ public class Project extends Util implements GLUConstants {
} }
/** /**
* @param finalMatrix * @param src
* @param finalMatrix2 * @param inverse
* @return * @return
*/ */
private static boolean __gluInvertMatrixf(FloatBuffer src, FloatBuffer inverse) { private static boolean __gluInvertMatrixf(FloatBuffer src, FloatBuffer inverse) {
@ -129,23 +129,23 @@ public class Project extends Util implements GLUConstants {
} }
/** /**
* @param modelMatrix * @param a
* @param projMatrix * @param b
* @param finalMatrix * @param r
*/ */
private static void __gluMultMatricesf(FloatBuffer a, FloatBuffer b, FloatBuffer r) { private static void __gluMultMatricesf(FloatBuffer a, FloatBuffer b, FloatBuffer r) {
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) { for (int j = 0; j < 4; j++) {
r.put(i*4+j, r.put(i*4+j,
a.get(i*4+0)*b.get(0*4+j) + a.get(i*4+0)*b.get(0*4+j) +
a.get(i*4+1)*b.get(1*4+j) + a.get(i*4+1)*b.get(1*4+j) +
a.get(i*4+2)*b.get(2*4+j) + a.get(i*4+2)*b.get(2*4+j) +
a.get(i*4+3)*b.get(3*4+j)); a.get(i*4+3)*b.get(3*4+j));
} }
} }
} }
/** /**
* Method gluPerspective. * Method gluPerspective.
* @param fovy * @param fovy
@ -199,7 +199,6 @@ public class Project extends Util implements GLUConstants {
float upy, float upy,
float upz) { float upz) {
int i;
float[] forward = new float[3]; float[] forward = new float[3];
float[] side = new float[3]; float[] side = new float[3];
float[] up = new float[3]; float[] up = new float[3];
@ -246,16 +245,14 @@ public class Project extends Util implements GLUConstants {
* @param modelMatrix * @param modelMatrix
* @param projMatrix * @param projMatrix
* @param viewport * @param viewport
* @param winx * @param win_pos
* @param winy
* @param winz
* @return * @return
*/ */
public static boolean gluProject(float objx, float objy, float objz, public static boolean gluProject(float objx, float objy, float objz,
FloatBuffer modelMatrix, FloatBuffer modelMatrix,
FloatBuffer projMatrix, FloatBuffer projMatrix,
IntBuffer viewport, IntBuffer viewport,
FloatBuffer winx, FloatBuffer winy, FloatBuffer winz) FloatBuffer win_pos)
{ {
float[] in = new float[4]; float[] in = new float[4];
float[] out = new float[4]; float[] out = new float[4];
@ -279,9 +276,12 @@ public class Project extends Util implements GLUConstants {
in[0] = in[0] * viewport.get(2) + viewport.get(0); in[0] = in[0] * viewport.get(2) + viewport.get(0);
in[1] = in[1] * viewport.get(3) + viewport.get(1); in[1] = in[1] * viewport.get(3) + viewport.get(1);
winx.put(0, in[0]); int pos = win_pos.position();
winy.put(0, in[1]);
winz.put(0, in[2]); win_pos.put(pos++, in[0]);
win_pos.put(pos++, in[1]);
win_pos.put(pos, in[2]);
return true; return true;
} }
@ -293,13 +293,11 @@ public class Project extends Util implements GLUConstants {
* @param modelMatrix * @param modelMatrix
* @param projMatrix * @param projMatrix
* @param viewport * @param viewport
* @param objx * @param obj_pos
* @param objy
* @param objz
* @return * @return
*/ */
public static boolean gluUnProject(float winx, float winy, float winz, public static boolean gluUnProject(float winx, float winy, float winz,
FloatBuffer modelMatrix, FloatBuffer modelMatrix,
FloatBuffer projMatrix, FloatBuffer projMatrix,
IntBuffer viewport, IntBuffer viewport,
FloatBuffer obj_pos) FloatBuffer obj_pos)
@ -329,9 +327,13 @@ public class Project extends Util implements GLUConstants {
out[0] /= out[3]; out[0] /= out[3];
out[1] /= out[3]; out[1] /= out[3];
out[2] /= out[3]; out[2] /= out[3];
obj_pos.put(0, out[0]);
obj_pos.put(1, out[1]); int pos = obj_pos.position();
obj_pos.put(2, out[2]);
obj_pos.put(pos++, out[0]);
obj_pos.put(pos++, out[1]);
obj_pos.put(pos, out[2]);
return true; return true;
} }

View File

@ -2,8 +2,8 @@ package org.lwjgl.opengl.glu;
/** /**
* Registry.java * Registry.java
* *
* *
* Created 11-jan-2004 * Created 11-jan-2004
* @author Erik Duijs * @author Erik Duijs
*/ */
@ -30,17 +30,15 @@ public class Registry extends Util implements GLUConstants {
/** /**
* Method gluCheckExtension * Method gluCheckExtension
* *
* @param extName is an extension name. * @param extName is an extension name.
* @param extString is a string of extensions separated by blank(s). There may or * @param extString is a string of extensions separated by blank(s). There may or
* may not be leading or trailing blank(s) in extString. * may not be leading or trailing blank(s) in extString.
* This works in cases of extensions being prefixes of another like * This works in cases of extensions being prefixes of another like
* GL_EXT_texture and GL_EXT_texture3D. * GL_EXT_texture and GL_EXT_texture3D.
* @return boolean true if extName is found otherwise it returns false. * @return boolean true if extName is found otherwise it returns false.
*/ */
public static boolean gluCheckExtension(String extName, String extString) { public static boolean gluCheckExtension(String extName, String extString) {
boolean flag = false;
if (extString == null || extName == null) if (extString == null || extName == null)
return false; return false;

View File

@ -5,8 +5,8 @@ import org.lwjgl.opengl.GL11;
/** /**
* Sphere.java * Sphere.java
* *
* *
* Created 23-dec-2003 * Created 23-dec-2003
* @author Erik Duijs * @author Erik Duijs
*/ */
@ -27,7 +27,7 @@ public class Sphere extends Quadric implements GLUConstants {
* If the orientation is set to GLU.OUTSIDE (with glu.quadricOrientation), then * If the orientation is set to GLU.OUTSIDE (with glu.quadricOrientation), then
* any normals generated point away from the center of the sphere. Otherwise, * any normals generated point away from the center of the sphere. Otherwise,
* they point toward the center of the sphere. * they point toward the center of the sphere.
* If texturing is turned on (with glu.quadricTexture), then texture * If texturing is turned on (with glu.quadricTexture), then texture
* coordinates are generated so that t ranges from 0.0 at z=-radius to 1.0 at * coordinates are generated so that t ranges from 0.0 at z=-radius to 1.0 at
* z=radius (t increases linearly along longitudinal lines), and s ranges from * z=radius (t increases linearly along longitudinal lines), and s ranges from
@ -44,11 +44,7 @@ public class Sphere extends Quadric implements GLUConstants {
boolean normals; boolean normals;
float nsign; float nsign;
if (super.normals == GLU_NONE) { normals = super.normals != GLU_NONE;
normals = false;
} else {
normals = true;
}
if (super.orientation == GLU_INSIDE) { if (super.orientation == GLU_INSIDE) {
nsign = -1.0f; nsign = -1.0f;
@ -125,7 +121,6 @@ public class Sphere extends Quadric implements GLUConstants {
GL11.glVertex3f(0.0f, 0.0f, -radius * nsign); GL11.glVertex3f(0.0f, 0.0f, -radius * nsign);
rho = PI - drho; rho = PI - drho;
s = 1.0f; s = 1.0f;
t = dt;
for (j = slices; j >= 0; j--) { for (j = slices; j >= 0; j--) {
theta = (j == slices) ? 0.0f : j * dtheta; theta = (j == slices) ? 0.0f : j * dtheta;
x = -sin(theta) * sin(rho); x = -sin(theta) * sin(rho);
@ -141,7 +136,7 @@ public class Sphere extends Quadric implements GLUConstants {
} else if ( } else if (
super.drawStyle == GLU_LINE super.drawStyle == GLU_LINE
|| super.drawStyle == GLU_SILHOUETTE) { || super.drawStyle == GLU_SILHOUETTE) {
// draw stack lines // draw stack lines
for (i = 1; for (i = 1;
i < stacks; i < stacks;
i++) { // stack line at i==stacks-1 was missing here i++) { // stack line at i==stacks-1 was missing here

View File

@ -10,8 +10,8 @@ import org.lwjgl.opengl.GL12;
/** /**
* Util.java * Util.java
* *
* *
* Created 7-jan-2004 * Created 7-jan-2004
* @author Erik Duijs * @author Erik Duijs
*/ */
@ -60,7 +60,7 @@ public class Util {
result[1] = v1[2] * v2[0] - v1[0] * v2[2]; result[1] = v1[2] * v2[0] - v1[0] * v2[2];
result[2] = v1[0] * v2[1] - v1[1] * v2[0]; result[2] = v1[0] * v2[1] - v1[1] * v2[0];
} }
/** /**
* Method compPerPix. * Method compPerPix.
* @param format * @param format
@ -93,11 +93,11 @@ public class Util {
/** /**
* Method nearestPower. * Method nearestPower.
* *
* Compute the nearest power of 2 number. This algorithm is a little * Compute the nearest power of 2 number. This algorithm is a little
* strange, but it works quite well. * strange, but it works quite well.
* *
* @param width * @param value
* @return int * @return int
*/ */
protected static int nearestPower(int value) { protected static int nearestPower(int value) {
@ -115,8 +115,8 @@ public class Util {
} else if (value == 3) { } else if (value == 3) {
return i * 4; return i * 4;
} }
value = value >> 1; value >>= 1;
i *= 2; i <<= 1;
} }
} }
@ -186,7 +186,7 @@ public class Util {
return n * m; return n * m;
} }
/** /**
* Create a FloatBuffer of specified size. * Create a FloatBuffer of specified size.
* @param size * @param size
@ -214,7 +214,7 @@ public class Util {
/** /**
* Convenience method for returning an int, * Convenience method for returning an int,
* rather than getting it out of a buffer yourself. * rather than getting it out of a buffer yourself.
* *
* @param what * @param what
* @return int * @return int
*/ */