float4 float3x4::Transform(const float4 &vector) const { #ifdef MATH_SSE return float4(mat3x4_mul_sse(row, vector.v)); #else return float4(DOT4(v[0], vector), DOT4(v[1], vector), DOT4(v[2], vector), vector.w); #endif }
int main1 (int ia[][N]) { int i, j; int ib[N] = {0,3,6,9}; int ic[N][N]; for (i = 0; i < N; i++) { ic[0][i] = DOT4 (ia[i], ib); } /* check results: */ for (i = 0; i < N; i++) { if (ic[0][i] != DOT4 (ia[i], ib)) abort(); } return 0; }
float unitize4(float u[4]) /* * Same as unitize, except that arguments are 4-vectors. * Make u into a unit 4-vector. */ { float f; f = (float)_sqrt(DOT4(u,u)); if (f > 0) { f = 1.0f / f; u[0] *= f; u[1] *= f; u[2] *= f; u[3] *= f; } return(f); }
/** * Do texgen needed for glRasterPos. * \param ctx rendering context * \param vObj object-space vertex coordinate * \param vEye eye-space vertex coordinate * \param normal vertex normal * \param unit texture unit number * \param texcoord incoming texcoord and resulting texcoord */ static void compute_texgen(struct gl_context *ctx, const GLfloat vObj[4], const GLfloat vEye[4], const GLfloat normal[3], GLuint unit, GLfloat texcoord[4]) { const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; /* always compute sphere map terms, just in case */ GLfloat u[3], two_nu, rx, ry, rz, m, mInv; COPY_3V(u, vEye); NORMALIZE_3FV(u); two_nu = 2.0F * DOT3(normal, u); rx = u[0] - normal[0] * two_nu; ry = u[1] - normal[1] * two_nu; rz = u[2] - normal[2] * two_nu; m = rx * rx + ry * ry + (rz + 1.0F) * (rz + 1.0F); if (m > 0.0F) mInv = 0.5F * (1.0f / sqrtf(m)); else mInv = 0.0F; if (texUnit->TexGenEnabled & S_BIT) { switch (texUnit->GenS.Mode) { case GL_OBJECT_LINEAR: texcoord[0] = DOT4(vObj, texUnit->GenS.ObjectPlane); break; case GL_EYE_LINEAR: texcoord[0] = DOT4(vEye, texUnit->GenS.EyePlane); break; case GL_SPHERE_MAP: texcoord[0] = rx * mInv + 0.5F; break; case GL_REFLECTION_MAP: texcoord[0] = rx; break; case GL_NORMAL_MAP: texcoord[0] = normal[0]; break; default: _mesa_problem(ctx, "Bad S texgen in compute_texgen()"); return; } } if (texUnit->TexGenEnabled & T_BIT) { switch (texUnit->GenT.Mode) { case GL_OBJECT_LINEAR: texcoord[1] = DOT4(vObj, texUnit->GenT.ObjectPlane); break; case GL_EYE_LINEAR: texcoord[1] = DOT4(vEye, texUnit->GenT.EyePlane); break; case GL_SPHERE_MAP: texcoord[1] = ry * mInv + 0.5F; break; case GL_REFLECTION_MAP: texcoord[1] = ry; break; case GL_NORMAL_MAP: texcoord[1] = normal[1]; break; default: _mesa_problem(ctx, "Bad T texgen in compute_texgen()"); return; } } if (texUnit->TexGenEnabled & R_BIT) { switch (texUnit->GenR.Mode) { case GL_OBJECT_LINEAR: texcoord[2] = DOT4(vObj, texUnit->GenR.ObjectPlane); break; case GL_EYE_LINEAR: texcoord[2] = DOT4(vEye, texUnit->GenR.EyePlane); break; case GL_REFLECTION_MAP: texcoord[2] = rz; break; case GL_NORMAL_MAP: texcoord[2] = normal[2]; break; default: _mesa_problem(ctx, "Bad R texgen in compute_texgen()"); return; } } if (texUnit->TexGenEnabled & Q_BIT) { switch (texUnit->GenQ.Mode) { case GL_OBJECT_LINEAR: texcoord[3] = DOT4(vObj, texUnit->GenQ.ObjectPlane); break; case GL_EYE_LINEAR: texcoord[3] = DOT4(vEye, texUnit->GenQ.EyePlane); break; default: _mesa_problem(ctx, "Bad Q texgen in compute_texgen()"); return; } } }
void opengl_light_apply_all(struct opengl_vertex_t *vtx, struct opengl_light_attrib_t *lgt_attrb) { int i; struct opengl_light_t *lgt; struct opengl_material_t *mtrl; struct opengl_light_model_t *mdl; GLfloat color_final[4] = {0.0f, 0.0f, 0.0f, 0.0f}; GLfloat color_const[4] = {0.0f, 0.0f, 0.0f, 0.0f}; GLfloat color_accum[4] = {0.0f, 0.0f, 0.0f, 0.0f}; GLfloat *acm; GLfloat *dcm; GLfloat *scm; GLfloat *ecm; GLfloat srm; GLfloat *acs; GLfloat atti; GLfloat spoti; GLfloat atti_mul_spoti; GLfloat *acli; GLfloat acm_mul_acli[4]; GLfloat *dcli; GLfloat dcm_mul_dcli[4]; GLfloat unit_v_to_ppli[4]; GLfloat *normal; GLfloat dcm_mul_dcli_factor; GLfloat fi; GLfloat hi[4]; GLfloat pe[4] = { 0.0f, 0.0f, 0.0f, 1.0f}; GLboolean vbs; GLfloat direction; GLfloat scm_mul_scli[4]; GLfloat scm_mul_scli_factor; GLfloat *scli; /* Apply lights */ /* Constant part comes from material itself */ /* Get Materal and Model information */ mtrl = lgt_attrb->Material; mdl = lgt_attrb->Model; ecm = mtrl->Attrib[MAT_ATTRIB_FRONT_EMISSION]; acm = mtrl->Attrib[MAT_ATTRIB_FRONT_AMBIENT]; dcm = mtrl->Attrib[MAT_ATTRIB_FRONT_DIFFUSE]; scm = mtrl->Attrib[MAT_ATTRIB_FRONT_SPECULAR]; srm = mtrl->Attrib[MAT_ATTRIB_FRONT_SHININESS][0]; acs = mdl->Ambient; normal = vtx->normal; /* color_const = ecm + acm * acs */ ACC_SCALE_4V(color_const, acm, acs); ACC_4V(color_const, ecm); opengl_debug("\t\tMaterial Emission = ["); for (i = 0; i < 4; ++i) opengl_debug("%f ", ecm[i]); opengl_debug("]\n"); opengl_debug("\t\tMaterial Ambient = ["); for (i = 0; i < 4; ++i) opengl_debug("%f ", acm[i]); opengl_debug("]\n"); opengl_debug("\t\tModel Ambient of scene = ["); for (i = 0; i < 4; ++i) opengl_debug("%f ", acs[i]); opengl_debug("]\n"); opengl_debug("\t\tColor const = ["); for (i = 0; i < 4; ++i) opengl_debug("%f ", color_const[i]); opengl_debug("]\n"); /* Accumulation part comes from 8 lights */ for (i = 0; i < MAX_LIGHTS; ++i) { lgt = lgt_attrb->Light[i]; vbs = lgt_attrb->Model->LocalViewer; GLfloat intermidiate_color[4] = {0.0f, 0.0f, 0.0f, 0.0f}; if (lgt->Enabled) { /* Calculate the 1st part in lighting equation */ opengl_debug("\t\tLight position= ["); for (i = 0; i < 4; ++i) opengl_debug("%f ", lgt->EyePosition[i]); opengl_debug("]\n"); atti = opengl_light_attenuation(lgt->ConstantAttenuation, lgt->LinearAttenuation, lgt->QuadraticAttenuation, vtx->pos, lgt->EyePosition); opengl_debug("\t\tAtti = %f\n", atti); spoti = opengl_light_spot(lgt->EyePosition, vtx->pos, lgt->SpotDirection, lgt->SpotExponent, lgt->SpotCutoff); opengl_debug("\t\tSpoti = %f\n", spoti); atti_mul_spoti = atti * spoti; opengl_debug("\t\tAtti * Spoti = %f\n", atti_mul_spoti); /* Calculate the 2nd part in lighting equation */ acli = lgt->Ambient; SCALE_4V(acm_mul_acli, acm, acli); COPY_4V(intermidiate_color, acm_mul_acli); opengl_debug("\t\tAcm * Acli = ["); for (i = 0; i < 4; ++i) opengl_debug("%f ", acm_mul_acli[i]); opengl_debug("]\n"); /* Calculate the 3rd part in lighting equation */ dcli = lgt->Diffuse; opengl_debug("\t\tDcli = ["); SCALE_4V(dcm_mul_dcli, dcm, dcli); for (i = 0; i < 4; ++i) opengl_debug("%f ", dcli[i]); opengl_debug("]\n"); opengl_debug("\t\tDcm = ["); for (i = 0; i < 4; ++i) opengl_debug("%f ", dcm[i]); opengl_debug("]\n"); opengl_debug("\t\tDcm * Dcli = ["); for (i = 0; i < 4; ++i) opengl_debug("%f ", dcm_mul_dcli[i]); opengl_debug("]\n"); opengl_vector_unit(unit_v_to_ppli, vtx->pos, lgt->EyePosition); opengl_debug("\t\tV -> Ppli = ["); for (i = 0; i < 4; ++i) opengl_debug("%f ", unit_v_to_ppli[i]); opengl_debug("]\n"); dcm_mul_dcli_factor = DOT4(normal, unit_v_to_ppli); opengl_debug("\t\tNormal = ["); for (i = 0; i < 4; ++i) opengl_debug("%f ", normal[i]); opengl_debug("]\n"); opengl_debug("\t\tFactor = %f\n" , dcm_mul_dcli_factor); SELF_SCALE_SCALAR_4V(dcm_mul_dcli, dcm_mul_dcli_factor); ACC_4V(intermidiate_color, dcm_mul_dcli); /* Calculate the 4th part in lighting equation */ scli = lgt->Specular; SCALE_4V(scm_mul_scli, scm, scli); opengl_debug("\t\tScm * Scli = ["); for (i = 0; i < 4; ++i) opengl_debug("%f ", dcm_mul_dcli[i]); opengl_debug("]\n"); fi = opengl_light_fi(normal, vtx->pos, lgt->EyePosition); opengl_light_hi(hi, vtx->pos, lgt->EyePosition, pe, vbs); direction = opengl_direction_mul(vtx->normal, hi); scm_mul_scli_factor = pow(direction, srm); scm_mul_scli_factor *= fi; opengl_debug("\t\tScm * Scli factor = %f\n", scm_mul_scli_factor); SELF_SCALE_SCALAR_4V(scm_mul_scli, scm_mul_scli_factor); ACC_4V(intermidiate_color, scm_mul_scli); SELF_SCALE_SCALAR_4V(intermidiate_color, atti_mul_spoti); } ACC_4V(color_accum, intermidiate_color); } ADD_4V(color_final, color_const, color_accum); opengl_debug("\t\tFinal Vertex Color = ["); for (int i = 0; i < 4; ++i) opengl_debug("%f ", color_final[i]); opengl_debug("]\n"); for (i = 0; i < 4; ++i) { vtx->color[i] = 255*color_final[i]; } }