Thanks for any help!
EDIT:
After some further investigation I think this is a problem with my camera and/or modelview matrix.
Manually editing the matrix back to an identity matrix, completely removes the wobble/jitter effect. Ive tried checking through the camera rotation code to make sure everything is normalized, but the problem remains.
The camera originally updated the modelview matrix every frame, regardless of any changes or not, ive stopped this, it now changes a few times after the input and then stops, this has no effect. The position of the obj file remains the same for every frame, so if I dont alter the camera, the camera and the obj should be in exactly the same position for every frame.
The only other thing I thought of to try was to round the vertex coordinates for the obj to whole numbers, this still doesnt have an effect.
Im completely out of ideas for trying to fix this, ive had the camera code around for sometime, its never really had much use though. This little project has got quite far for me but this problem is ruining everything.
Here is the camera code in case any one can see anything obvious.
//
// Camera
//
// Camera
//
using Tao.OpenGl;
using System;
using System.Diagnostics;
using MyMathLib;
namespace Engine
{
/// <summary>
/// WalkCamera
///
/// A camera system designed to replicate a person walking through a scene.
/// </summary>
public class WalkCamera : ICamera
{
bool mAutoLevelX = true;
public WalkCamera()
{
mCamPos = new Vector3_D();
mCamX = new Vector3_D();
mCamY = new Vector3_D();
mCamZ = new Vector3_D();
mMatrix = new Matrix_D();
mCamRot = new Quaternion_D();
mCamRot.make(0.0, 0.0, 1.0, 0.0);
}
//
// transform()
//
// Transforms the camera rotation and position.
//
// Rotates first then transforms along camera axis using transform inout vals.
//
public void transform(double theta, Vector3_D axis, Vector3_D transform)
{
Quaternion_D rotation = new Quaternion_D();
rotation.make(MathUtil.degToRad(theta), axis[0], axis[1], axis[2]);
rotation.normalize();
Quaternion_D newQuaternion = new Quaternion_D();
newQuaternion.mult(rotation, mCamRot);
newQuaternion.normalize();
mCamRot.copy(newQuaternion);
mCamRot.normalize();
newQuaternion.inverse();
newQuaternion.normalize();
newQuaternion.toMatrix(ref mMatrix);
mCamX[0] = mMatrix[0];
mCamX[1] = mMatrix[1];
mCamX[2] = mMatrix[2];
mCamY[0] = mMatrix[4];
mCamY[1] = mMatrix[5];
mCamY[2] = mMatrix[6];
mCamZ[0] = mMatrix[8];
mCamZ[1] = mMatrix[9];
mCamZ[2] = mMatrix[10];
Vector3_D vec = new Vector3_D();
vec = mCamX.scale(transform[0]);
mCamPos[0] += vec[0];
mCamPos[1] += vec[1];
mCamPos[2] += vec[2];
vec = mCamY.scale(transform[1]);
mCamPos[0] += vec[0];
mCamPos[1] += vec[1];
mCamPos[2] += vec[2];
vec = mCamZ.scale(transform[2]);
mCamPos[0] += vec[0];
mCamPos[1] += vec[1];
mCamPos[2] += vec[2];
//if (mAutoLevelX)
// levelXAxis();
}
public void levelXAxis()
{
Vector3_D vecTrueUp = new Vector3_D();
vecTrueUp[0] = 0.0;
vecTrueUp[1] = 1.0;
vecTrueUp[2] = 0.0;
Vector3_D newXAxis;
newXAxis = mCamZ.cross(vecTrueUp);
float angle = (float)Math.Cos(newXAxis.dot(mCamX));
Vector3_D rotAxis = newXAxis.cross(mCamX);
Quaternion_D newQuat = new Quaternion_D();
newQuat.make(angle, rotAxis[0], rotAxis[1], rotAxis[2]);
Quaternion_D newCamQuat = new Quaternion_D();
newCamQuat.mult(newQuat, mCamRot);
mCamRot.copy(newCamQuat);
mCamRot.normalize();
newCamQuat.inverse();
newCamQuat.normalize();
newCamQuat.toMatrix(ref mMatrix);
mCamX[0] = mMatrix[0];
mCamX[1] = mMatrix[1];
mCamX[2] = mMatrix[2];
mCamY[0] = mMatrix[4];
mCamY[1] = mMatrix[5];
mCamY[2] = mMatrix[6];
mCamZ[0] = mMatrix[8];
mCamZ[1] = mMatrix[9];
mCamZ[2] = mMatrix[10];
}
public void levelYAxis()
{
throw new NotImplementedException("WalkCamera::levelYAxis() Not implemented");
}
public void levelZAxis()
{
throw new NotImplementedException("WalkCamera::levelZAxis() Not implemented");
}
public void toOpenGLMatrix(ref double[] oglArray)
{
if (mRemainingUpdates > 0)
{
Matrix_D mtx = new Matrix_D();
mtx.copy(mMatrix);
mtx.transposeRot();
Matrix_D mtxPos = new Matrix_D();
mtxPos[12] = mCamPos[0];
mtxPos[13] = mCamPos[1];
mtxPos[14] = mCamPos[2];
Matrix_D newMatrix = new Matrix_D();
newMatrix.mult(mtx, mtxPos);
for (int i = 0; i < 16; i++)
{
oglArray = newMatrix;
}
}
}
public void applyCamera()
{
Gl.glMatrixMode(Gl.GL_PROJECTION);
Gl.glLoadIdentity();
Glu.gluPerspective(30.0, 16.0f / 9.0f, 1.0f, 1500.0f);
//Gl.glOrtho(0.0f, 100.0f, 0.0f, 100.0f, 1.0f, 5000.0f);
Gl.glMatrixMode(Gl.GL_MODELVIEW);
Gl.glLoadIdentity();
double[] array = new double[16];
toOpenGLMatrix(ref array);
Gl.glMultMatrixd(array);
}
public void getCamZ(ref Vector3_D vec)
{
vec[0] = mCamZ[0];
vec[1] = mCamZ[1];
vec[2] = mCamZ[2];
}
public Vector3_D getCamX()
{
return mCamX;
}
public Vector3_D getCamY()
{
return mCamY;
}
public Vector3_D getCamZ()
{
return mCamZ;
}
public Vector3_D getCamPos()
{
return mCamPos;
}
public Matrix_D getMatrix()
{
return mMatrix;
}
public void setRemainingUpdates(int numUpdates)
{
mRemainingUpdates = numUpdates;
}
int mRemainingUpdates = 10;
Vector3_D mCamPos;
Vector3_D mCamX;
Vector3_D mCamY;
Vector3_D mCamZ;
Matrix_D mMatrix;
Quaternion_D mCamRot;
}
}