Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - Hmm

#1
Support / Re: Quaternion?
May 20, 2007, 08:37:19 PM
Thanks! :D

After reading a Math paper I ended up with the following code, which works quite nicely and solved my larger problem interfacing with OdeJava:

protected Matrix Quat4fToMatrix(javax.vecmath.Quat4f input)
{
float[] MatrixDump = new float[16];
float xx = input.x * input.x;
float xy = input.x * input.y;
float xz = input.x * input.z;
float xw = input.x * input.w;
float yy = input.y * input.y;
float yz = input.y * input.z;
float yw = input.y * input.w;
float zz = input.z * input.z;
float zw = input.z * input.w;

MatrixDump[0] = 1 - 2 * ( yy + zz );
MatrixDump[4] = 2 * ( xy - zw );
MatrixDump[8] = 2 * ( xz + yw );
MatrixDump[1] = 2 * ( xy + zw );
MatrixDump[5] = 1 - 2 * ( xx + zz );
MatrixDump[9] = 2 * ( yz - xw );
MatrixDump[2] = 2 * ( xz - yw );
MatrixDump[6] = 2 * ( yz + xw );
MatrixDump[10] = 1 - 2 * ( xx + yy );
MatrixDump[15] = 1;

Matrix buffer = new Matrix();
buffer.setDump(MatrixDump);
return buffer;
}
#2
Support / Quaternion?
May 18, 2007, 05:42:37 PM
Hi,

The physics library which I am using returns rotations as Quaternions.  I have very little experience in 3D math, and cannot see any obvious way to move that over to jPCT.  Given a Quaternion as a javax.vecmath.Quat4f object, how can I use that to set an Object3D's rotation?

Thanks for any help!  :D
#3
Support / Re: Matrix3f
May 13, 2007, 06:18:21 PM
Here's the code I ended up with for copying a Matrix3f into the format for a rotation Matrix:

protected Matrix Matrix3fToMatrix(Matrix3f input)
{
//Declare variables
float[] insertDump = new float[16]; //The array holding the values in the new Matrix
float[] rowDump = new float[3];     //The array for temporarily holding values from the rows of the Matrix3f
int targetElement = 0;              //Points to the next location in the insertDump to add data

//Loop through the rows of the Matrix3f
for (int sourceRow = 0; sourceRow < 3; sourceRow++)
{
//Grab the row from the Matrix3f
input.getRow(sourceRow, rowDump);

//Insert the 3 elements from the Matrix3f into the Matrix.  The fourth element has been initialized to 0.0f.
insertDump[targetElement] = rowDump[0];
insertDump[targetElement + 1] = rowDump[1];
insertDump[targetElement + 2] = rowDump[2];

//Move the target ahead by four spaces
targetElement += 4;
}

//The final row consists of { 0.0f, 0.0f, 0.0f, 1.0f }, since this is a rotation matrix
insertDump[15] = 1.0f;

//Create the new Matrix and load in the values
Matrix output = new Matrix();
output.setDump(insertDump);

//Return
return output;
}
#4
Support / Matrix3f
May 13, 2007, 03:24:08 AM
Hello,

I have a rotation stored as a Matrix3f object, and need to use that to set the rotation of an Object3D.  Unfortunately, I don't quite understand how rotations are represented in this format, so I'm having trouble making the conversion to the Matrix object needed for the setRotationMatrix() method of the Object3D.

Is there any simple way to convert from a Matrix3f to a Matrix?

Thank you for any help! :)
#5
Support / Re: Making a pair of dice
April 25, 2007, 07:10:17 PM
Alright, it appears that environment mapping was on, so I removed the code that set it.  :-[

Unfortunately, now the textures don't appear at all.

Anyway, here's the (very primative) object which will eventually become the die.  I create an object of this class after the world has been set up, and it rotates properly, but displays no textures:

protected class die extends Object3D
{
public die()
{
super (Primitives.getCube(1.0f));
PolygonManager myPolygons = this.getPolygonManager();
myPolygons.setPolygonTexture(0, dice.myTexMan.getTextureID("face1"));
myPolygons.setPolygonTexture(2, dice.myTexMan.getTextureID("face1"));
myPolygons.setPolygonTexture(4, dice.myTexMan.getTextureID("face1"));
myPolygons.setPolygonTexture(6, dice.myTexMan.getTextureID("face1"));
myPolygons.setPolygonTexture(1, dice.myTexMan.getTextureID("face6"));
myPolygons.setPolygonTexture(3, dice.myTexMan.getTextureID("face6"));
myPolygons.setPolygonTexture(5, dice.myTexMan.getTextureID("face6"));
myPolygons.setPolygonTexture(7, dice.myTexMan.getTextureID("face6"));

build();
}
}


The textures are already loaded correctly (since they worked before removing the environment mapping statement), and dice.myTexMan is a valid TextureManager for the current world.

Thanks again for your help :)
#6
Support / Making a pair of dice
April 25, 2007, 06:16:49 PM
Hi,

I'm currently trying to create a simple die with jPCT (6 sided cube with a number on each side, represented by circles).  I've currently set up the cube, and loaded the textures into the texture manager.  I've set the cube up so that it rotates around over and over again in order to show it's sides.  How can I apply the 128x128 textures to the sides of the cube?  As I understand it, each side is actually made up of 4 polygons, so I've tried applying the same square texture to each of the four polygons on each side.  However, when I rotate the cube like this:

dice.dieOne.rotateX(0.05f);

...the circles appear to "slide" across the surface of the cube as it rotates.  Am I supposed to set the textures to lock or something?

Thanks for any help!