RE: [Plib-devel] Bug with sign of pitch?
Brought to you by:
sjbaker
From: Dave M. <Dav...@dy...> - 2000-07-18 14:54:55
|
rather than translate into an ssg XYZ - HPR coord structure why not just set the camera matrix? i hacked this from LookAt in Mesa-3.2/src-glu/glu.c but i haven't tested it yet void ssgLookAt( GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy, GLdouble upz ) { sgMat4 m; GLdouble x[3], y[3], z[3]; GLdouble mag; /* Make rotation matrix */ /* Z vector */ z[0] = eyex - centerx; z[1] = eyey - centery; z[2] = eyez - centerz; mag = sqrt( z[0]*z[0] + z[1]*z[1] + z[2]*z[2] ); if (mag) { /* mpichler, 19950515 */ z[0] /= mag; z[1] /= mag; z[2] /= mag; } /* Y vector */ y[0] = upx; y[1] = upy; y[2] = upz; /* X vector = Y cross Z */ x[0] = y[1]*z[2] - y[2]*z[1]; x[1] = -y[0]*z[2] + y[2]*z[0]; x[2] = y[0]*z[1] - y[1]*z[0]; /* Recompute Y = Z cross X */ y[0] = z[1]*x[2] - z[2]*x[1]; y[1] = -z[0]*x[2] + z[2]*x[0]; y[2] = z[0]*x[1] - z[1]*x[0]; /* mpichler, 19950515 */ /* cross product gives area of parallelogram, which is < 1.0 for * non-perpendicular unit-length vectors; so normalize x, y here */ mag = sqrt( x[0]*x[0] + x[1]*x[1] + x[2]*x[2] ); if (mag) { x[0] /= mag; x[1] /= mag; x[2] /= mag; } mag = sqrt( y[0]*y[0] + y[1]*y[1] + y[2]*y[2] ); if (mag) { y[0] /= mag; y[1] /= mag; y[2] /= mag; } #define M(row,col) m[row][col] M(0,0) = x[0]; M(0,1) = x[1]; M(0,2) = x[2]; M(0,3) = 0.0; M(1,0) = y[0]; M(1,1) = y[1]; M(1,2) = y[2]; M(1,3) = 0.0; M(2,0) = z[0]; M(2,1) = z[1]; M(2,2) = z[2]; M(2,3) = 0.0; M(3,0) = -eyex; M(3,1) = -eyey; M(3,2) = -eyez; M(3,3) = 1.0; #undef M ssgSetCamera( m ) ; } > Last I looked I didn't see anything like this, but what I would really > like is some code that would take a directional vector and an up > vector and translate this into an ssg XYZ - HPR coord structure. > > What I'd like to use this for is given I know my camera position, and > the position of something I want centered on the screen, I want to > look directly at it (with control over the up direction.) For > example, a chase plane view in a flight sim. > > It's probably a simple thing to impliment, but I just haven't had a > chance to sit down and think it through ... and if someone has already > done the work I'd happily use that. :-) > > Regards, > > Curt. |