Split up my matrix library.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@555 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
738dfcab46
commit
a8db440abb
1 changed files with 107 additions and 68 deletions
|
@ -794,7 +794,7 @@ void Matrix4_Multiply(float *a, float *b, float *out)
|
|||
}
|
||||
|
||||
//transform 4d vector by a 4d matrix.
|
||||
void Matrix4_Transform(float *matrix, float *vector, float *product)
|
||||
void Matrix4_Transform4(float *matrix, float *vector, float *product)
|
||||
{
|
||||
product[0] = matrix[0]*vector[0] + matrix[4]*vector[1] + matrix[8]*vector[2] + matrix[12]*vector[3];
|
||||
product[1] = matrix[1]*vector[0] + matrix[5]*vector[1] + matrix[9]*vector[2] + matrix[13]*vector[3];
|
||||
|
@ -802,17 +802,18 @@ void Matrix4_Transform(float *matrix, float *vector, float *product)
|
|||
product[3] = matrix[3]*vector[0] + matrix[7]*vector[1] + matrix[11]*vector[2] + matrix[15]*vector[3];
|
||||
}
|
||||
|
||||
//returns fractions of screen.
|
||||
//uses GL style rotations and translations and stuff.
|
||||
void ML_Project (vec3_t in, vec3_t out, vec3_t viewangles, vec3_t vieworg, float wdivh, float fovy)
|
||||
void Matrix4_Transform3(float *matrix, float *vector, float *product)
|
||||
{
|
||||
float modelview[16];
|
||||
float proj[16];
|
||||
product[0] = matrix[0]*vector[0] + matrix[4]*vector[1] + matrix[8]*vector[2] + matrix[12]*vector[3];
|
||||
product[1] = matrix[1]*vector[0] + matrix[5]*vector[1] + matrix[9]*vector[2] + matrix[13]*vector[3];
|
||||
product[2] = matrix[2]*vector[0] + matrix[6]*vector[1] + matrix[10]*vector[2] + matrix[14]*vector[3];
|
||||
}
|
||||
|
||||
{
|
||||
void ML_ModelViewMatrix(float *modelview, vec3_t viewangles, vec3_t vieworg)
|
||||
{
|
||||
float tempmat[16];
|
||||
//load identity.
|
||||
memset(modelview, 0, sizeof(modelview));
|
||||
memset(modelview, 0, sizeof(*modelview)*16);
|
||||
#if FULLYGL
|
||||
modelview[0] = 1;
|
||||
modelview[5] = 1;
|
||||
|
@ -836,10 +837,10 @@ void ML_Project (vec3_t in, vec3_t out, vec3_t viewangles, vec3_t vieworg, float
|
|||
Matrix4_Multiply(modelview, Matrix4_NewRotation(-viewangles[1], 0, 0, 1), tempmat); // put Z going up
|
||||
|
||||
Matrix4_Multiply(tempmat, Matrix4_NewTranslation(-vieworg[0], -vieworg[1], -vieworg[2]), modelview); // put Z going up
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
void ML_ProjectionMatrix(float *proj, float wdivh, float fovy)
|
||||
{
|
||||
float xmin, xmax, ymin, ymax;
|
||||
float nudge = 1;
|
||||
|
||||
|
@ -869,10 +870,17 @@ void ML_Project (vec3_t in, vec3_t out, vec3_t viewangles, vec3_t vieworg, float
|
|||
proj[7] = 0;
|
||||
proj[11] = -1;
|
||||
proj[15] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//screen->3d
|
||||
/*
|
||||
void ML_UnProject(vec3_t in, vec3_t out, vec3_t viewangles, vec3_t vieworg, float wdivh, float fovy)
|
||||
{
|
||||
float modelview[16];
|
||||
float proj[16];
|
||||
|
||||
//we've got our two matricies now.
|
||||
ML_ModelViewMatrix(modelview, viewangles, vieworg);
|
||||
ML_ProjectionMatrix(proj, wdivh, fovy);
|
||||
|
||||
{
|
||||
float v[4], tempv[4];
|
||||
|
@ -888,6 +896,37 @@ void ML_Project (vec3_t in, vec3_t out, vec3_t viewangles, vec3_t vieworg, float
|
|||
v[1] /= v[3];
|
||||
v[2] /= v[3];
|
||||
|
||||
out[0] = (1+v[0])/2;
|
||||
out[1] = (1+v[1])/2;
|
||||
out[2] = (1+v[2])/2;
|
||||
}
|
||||
}*/
|
||||
|
||||
//returns fractions of screen.
|
||||
//uses GL style rotations and translations and stuff.
|
||||
//3d -> screen (fixme: offscreen return values needed)
|
||||
void ML_Project (vec3_t in, vec3_t out, vec3_t viewangles, vec3_t vieworg, float wdivh, float fovy)
|
||||
{
|
||||
float modelview[16];
|
||||
float proj[16];
|
||||
|
||||
ML_ModelViewMatrix(modelview, viewangles, vieworg);
|
||||
ML_ProjectionMatrix(proj, wdivh, fovy);
|
||||
|
||||
{
|
||||
float v[4], tempv[4];
|
||||
v[0] = in[0];
|
||||
v[1] = in[1];
|
||||
v[2] = in[2];
|
||||
v[3] = 1;
|
||||
|
||||
Matrix4_Transform4(modelview, v, tempv);
|
||||
Matrix4_Transform4(proj, tempv, v);
|
||||
|
||||
v[0] /= v[3];
|
||||
v[1] /= v[3];
|
||||
v[2] /= v[3];
|
||||
|
||||
out[0] = (1+v[0])/2;
|
||||
out[1] = (1+v[1])/2;
|
||||
out[2] = (1+v[2])/2;
|
||||
|
|
Loading…
Reference in a new issue