void CEntityMiscModel::UpdateCachedData(){ aabb_t aabb_temp; m4x4_identity( m_transform ); m4x4_pivoted_transform_by_vec3( m_transform, m_translate, m_euler, eXYZ, m_scale, m_pivot ); memcpy( m_inverse_transform, m_transform, sizeof( m4x4_t ) ); m4x4_invert( m_inverse_transform ); aabb_clear( &aabb_temp ); if ( m_model && m_model->pRender ) { aabb_extend_by_aabb( &aabb_temp, m_model->pRender->GetAABB() ); } else{ VectorSet( aabb_temp.extents, 8, 8, 8 ); } aabb_for_transformed_aabb( &m_BBox, &aabb_temp, m_transform ); }
void CEntityEclassModel::UpdateCachedData() { aabb_t aabb_temp; aabb_clear(&aabb_temp); m4x4_identity(m_transform); m4x4_pivoted_transform_by_vec3(m_transform, m_translate, m_euler, eXYZ, m_scale, m_pivot); memcpy(m_inverse_transform, m_transform, sizeof(m4x4_t)); if(m4x4_invert(m_inverse_transform) == 1) { Sys_Printf("ERROR: Singular Matrix, cannot invert"); } if(m_eclass) aabb_construct_for_vec3(&aabb_temp, m_eclass->mins, m_eclass->maxs); else VectorSet(aabb_temp.extents, 8, 8, 8); aabb_for_transformed_aabb(&m_BBox, &aabb_temp, m_transform); }
/** * Draws a gear in GLES 2 mode. * * @param gear the gear to draw * @param transform the current transformation matrix * @param x the x position to draw the gear at * @param y the y position to draw the gear at * @param angle the rotation angle of the gear * @param color the color of the gear */ static void draw_gearGLES2(gear_t *gear, GLfloat *transform, GLfloat x, GLfloat y, GLfloat angle) { // The direction of the directional light for the scene */ static const GLfloat LightSourcePosition[4] = { 5.0, 5.0, 10.0, 1.0}; GLfloat model_view[16]; GLfloat normal_matrix[16]; GLfloat model_view_projection[16]; /* Translate and rotate the gear */ m4x4_copy(model_view, transform); m4x4_translate(model_view, x, y, 0); m4x4_rotate(model_view, angle, 0, 0, 1); /* Create and set the ModelViewProjectionMatrix */ m4x4_copy(model_view_projection, state->ProjectionMatrix); m4x4_multiply(model_view_projection, model_view); glUniformMatrix4fv(state->ModelViewProjectionMatrix_location, 1, GL_FALSE, model_view_projection); glUniformMatrix4fv(state->ModelViewMatrix_location, 1, GL_FALSE, model_view); /* Set the LightSourcePosition uniform in relation to the object */ glUniform4fv(state->LightSourcePosition_location, 1, LightSourcePosition); glUniform1i(state->DiffuseMap_location, 0); /* * Create and set the NormalMatrix. It's the inverse transpose of the * ModelView matrix. */ m4x4_copy(normal_matrix, model_view); m4x4_invert(normal_matrix); m4x4_transpose(normal_matrix); glUniformMatrix4fv(state->NormalMatrix_location, 1, GL_FALSE, normal_matrix); /* Set the gear color */ glUniform4fv(state->MaterialColor_location, 1, gear->color); if (state->useVBO) { glBindBuffer(GL_ARRAY_BUFFER, gear->vboId); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gear->iboId); } /* Set up the position of the attributes in the vertex buffer object */ // setup where vertex data is glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(vertex_t), gear->vertex_p); // setup where normal data is glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(vertex_t), gear->normal_p); // setup where uv data is glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(vertex_t), gear->texCoords_p); /* Enable the attributes */ glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glEnableVertexAttribArray(2); // Bind texture surface to current vertices glBindTexture(GL_TEXTURE_2D, state->texId); glDrawElements(state->drawMode, gear->tricount, GL_UNSIGNED_SHORT, gear->index_p); /* Disable the attributes */ glDisableVertexAttribArray(2); glDisableVertexAttribArray(1); glDisableVertexAttribArray(0); }
static void ExtrapolateTexcoords( const float *axyz, const float *ast, const float *bxyz, const float *bst, const float *cxyz, const float *cst, const float *axyz_new, float *ast_out, const float *bxyz_new, float *bst_out, const float *cxyz_new, float *cst_out ){ vec4_t scoeffs, tcoeffs; float md; m4x4_t solvematrix; vec3_t norm; vec3_t dab, dac; VectorSubtract( bxyz, axyz, dab ); VectorSubtract( cxyz, axyz, dac ); CrossProduct( dab, dac, norm ); // assume: // s = f(x, y, z) // s(v + norm) = s(v) when n ortho xyz // s(v) = DotProduct(v, scoeffs) + scoeffs[3] // solve: // scoeffs * (axyz, 1) == ast[0] // scoeffs * (bxyz, 1) == bst[0] // scoeffs * (cxyz, 1) == cst[0] // scoeffs * (norm, 0) == 0 // scoeffs * [axyz, 1 | bxyz, 1 | cxyz, 1 | norm, 0] = [ast[0], bst[0], cst[0], 0] solvematrix[0] = axyz[0]; solvematrix[4] = axyz[1]; solvematrix[8] = axyz[2]; solvematrix[12] = 1; solvematrix[1] = bxyz[0]; solvematrix[5] = bxyz[1]; solvematrix[9] = bxyz[2]; solvematrix[13] = 1; solvematrix[2] = cxyz[0]; solvematrix[6] = cxyz[1]; solvematrix[10] = cxyz[2]; solvematrix[14] = 1; solvematrix[3] = norm[0]; solvematrix[7] = norm[1]; solvematrix[11] = norm[2]; solvematrix[15] = 0; md = m4_det( solvematrix ); if ( md * md < 1e-10 ) { Sys_Printf( "Cannot invert some matrix, some texcoords aren't extrapolated!" ); return; } m4x4_invert( solvematrix ); scoeffs[0] = ast[0]; scoeffs[1] = bst[0]; scoeffs[2] = cst[0]; scoeffs[3] = 0; m4x4_transform_vec4( solvematrix, scoeffs ); tcoeffs[0] = ast[1]; tcoeffs[1] = bst[1]; tcoeffs[2] = cst[1]; tcoeffs[3] = 0; m4x4_transform_vec4( solvematrix, tcoeffs ); ast_out[0] = scoeffs[0] * axyz_new[0] + scoeffs[1] * axyz_new[1] + scoeffs[2] * axyz_new[2] + scoeffs[3]; ast_out[1] = tcoeffs[0] * axyz_new[0] + tcoeffs[1] * axyz_new[1] + tcoeffs[2] * axyz_new[2] + tcoeffs[3]; bst_out[0] = scoeffs[0] * bxyz_new[0] + scoeffs[1] * bxyz_new[1] + scoeffs[2] * bxyz_new[2] + scoeffs[3]; bst_out[1] = tcoeffs[0] * bxyz_new[0] + tcoeffs[1] * bxyz_new[1] + tcoeffs[2] * bxyz_new[2] + tcoeffs[3]; cst_out[0] = scoeffs[0] * cxyz_new[0] + scoeffs[1] * cxyz_new[1] + scoeffs[2] * cxyz_new[2] + scoeffs[3]; cst_out[1] = tcoeffs[0] * cxyz_new[0] + tcoeffs[1] * cxyz_new[1] + tcoeffs[2] * cxyz_new[2] + tcoeffs[3]; }