Different matrix mulP results on client vs server?
by SeanB · in Torque Game Engine · 01/06/2008 (8:14 pm) · 1 replies
I am having a really odd problem with my code which I am having no luck figuring out. I have a piece of code where I multiple a vector and a matrix. I was getting some odd results sometimes so I started adding code to debug the problem. That's when I realized that a call to mulP on the server is returning a different resulting vector than on the client. I put together a simplified version which is below. This piece of code is being called from within Projectile.cc.
I won't waste space with all of the print output. Suffice it to say that the printouts for the server and client are the same except for the res vec
client resVec: 0.000932, 0.5000, 10927.51562
server resVec: 0.000932, -15154534289(really big number).0, 10927.51562
Any ideas on what could be going on?
I won't waste space with all of the print output. Suffice it to say that the printouts for the server and client are the same except for the res vec
client resVec: 0.000932, 0.5000, 10927.51562
server resVec: 0.000932, -15154534289(really big number).0, 10927.51562
Any ideas on what could be going on?
MatrixF mat;
Point3F vec1, resVec, row;
row.set(0.98, 0, -0.19);
mat.setRow(0,row);
row.set(.1, 1, .1);
mat.setRow(1,row);
row.set(0.19, -0, 0.98);
mat.setRow(2,row);
vec1.set(0.0009, 0.001, 50.0);
if(isClientObject()) {
Con::printf("client mat:");
#define idx(r,c) (r*4 + c)
for (S32 r=0;r<3;r++) {
Con::printf(" %f %f %f", mat[idx(r,0)], mat[idx(r,1)], mat[idx(r,2)]);
}
Con::printf("client vec1: %f, %f, %f",vec1.x, vec1.y, vec1.z);
T_c_N.mulP(vec1, &resVec);
Con::printf("client resVec: %f, %f, %f", resVec.x, resVec.y, resVec.z);
}
if(isServerObject()) {
Con::printf("server mat:");
#define idx(r,c) (r*4 + c)
for (S32 r=0;r<3;r++) {
Con::printf(" %g %g %g", mat[idx(r,0)], mat[idx(r,1)], mat[idx(r,2)]);
}
Con::printf("server vec1: %f, %f, %f",vec1.x, vec1.y, vec1.z);
T_c_N.mulP(vec1, &resVec);
Con::printf("server resVec: %f, %f, %f", resVec.x, resVec.y, resVec.z);
}
Associate Orion Elenzil
Real Life Plus
and it looks to me like you're only setting the 3x3 sub-matrix portion of it,
meaning the fourth row and column may be uninitialized (aka random) data.
this would be fine if you were using mulV() (mulVector), which ignores the fourth row & column,
but you're using mulP() (mulPoint), which converts the 3-component vector to a 4-component point and then does a 4-component multiply against the 4x4 matrix.
i would recommend doing one of:
* initializing the matrix to identity before setting the rows
* set all four rows with four-component points instead of three-component vectors
* use mulV() instead of mulP().