void CTriMenu::UpdatePosition( vec2_t vStart, float flHeight, float flWidth ) { m_vPos[0] = vStart; m_vPos[1] = vStart + vec2_t( 0, flHeight ); m_vPos[2] = vStart + vec2_t( flWidth, flHeight ); m_vPos[3] = vStart + vec2_t( flWidth, 0 ); }
void CTeamMenu::Initialize( void ) { Reset( ); m_TriMenu.UpdateTexture( "team3" ); m_TriMenu.UpdatePosition( vec2_t( .5f, 0 ), .5f, .5f ); m_TriMenu1.UpdateTexture( "team4" ); m_TriMenu1.UpdatePosition( vec2_t( 0, 0 ), .5f, .5f ); m_TriMenu2.UpdateTexture( "team1" ); m_TriMenu2.UpdatePosition( vec2_t( 0, .5f ), .5f, .5f ); m_TriMenu3.UpdateTexture( "team2" ); m_TriMenu3.UpdatePosition( vec2_t( .5f, .5f ), .5f, .5f ); }
void CClassMenu::Initialize( void ) { Reset( ); m_TriMenu.UpdateTexture( "class3" ); m_TriMenu.UpdatePosition( vec2_t( .5f, 0 ), .5f, .5f ); m_TriMenu1.UpdateTexture( "class4" ); m_TriMenu1.UpdatePosition( vec2_t( 0, 0 ), .5f, .5f ); m_TriMenu2.UpdateTexture( "class1" ); m_TriMenu2.UpdatePosition( vec2_t( 0, .5f ), .5f, .5f ); m_TriMenu3.UpdateTexture( "class2" ); m_TriMenu3.UpdatePosition( vec2_t( .5f, .5f ), .5f, .5f ); }
vec2_t operator*(matrix2x2<value_t> const& lhs, vec2_t const& rhs) { return vec2_t(lhs[0] * rhs[0] + lhs[2] * rhs[1], lhs[1] * rhs[0] + lhs[3] * rhs[1]); }
vec2_t projectVectorOnPlane(vec3_t V,vec3_t i,vec3_t j) { if(i.abs2()==0) EG_BUG; if(j.abs2()==0) EG_BUG; double x = V*i/i.abs2(); double y = V*j/j.abs2(); return vec2_t(x,y); }
bool intersectEdgeAndTriangle(const vec3_t& a, const vec3_t& b, const vec3_t& c, const vec3_t& x1, const vec3_t& x2, vec3_t& xi, vec3_t& ri, double tol) { // triangle base vec3_t g1 = b - a; vec3_t g2 = c - a; vec3_t g3 = g1.cross(g2); g3.normalise(); // direction of the edge vec3_t v = x2 - x1; // parallel? if (fabs(g3*v) < 1e-6) { return false; } // compute intersection between straight and triangular plane double k = intersection(x1, v, a, g3); xi = x1 + k*v; // transform xi to triangular base mat3_t G; G.column(0, g1); G.column(1, g2); G.column(2, g3); mat3_t GI = G.inverse(); ri = xi - a; ri = GI*ri; /* { vec3_t b = xi-a; linsolve(G, b, ri); } */ // intersection outside of edge range? if (k < 0 - tol) { return false; } if (k > 1 + tol) { return false; } // intersection outside of triangle? if (!isInsideTriangle(vec2_t(ri[0],ri[1]),tol)) { return false; } return true; }
CTriMenu::CTriMenu( void ) { m_pTex = NULL; m_vPos[0] = m_vPos[1] = m_vPos[2] = m_vPos[3] = vec2_t( 0, 0 ); m_strTex.erase( ); }
/* ================= RB_AddIQMSurfaces Compute vertices for this model surface ================= */ void RB_IQMSurfaceAnim(surfaceType_t* surface) { srfIQModel_t* surf = (srfIQModel_t*)surface; iqmData_t* data = surf->data; float jointMats[IQM_MAX_JOINTS * 12]; int i; vec4_t* outXYZ = &tess.xyz[tess.numVertexes]; vec4_t* outNormal = &tess.normal[tess.numVertexes]; vec2_t (*outTexCoord)[2] = &tess.texCoords[tess.numVertexes]; color4ub_t* outColor = &tess.vertexColors[tess.numVertexes]; int frame = backEnd.currentEntity->e.frame % data->num_frames; int oldframe = backEnd.currentEntity->e.oldframe % data->num_frames; float backlerp = backEnd.currentEntity->e.backlerp; int* tri; glIndex_t* ptr; glIndex_t base; RB_CHECKOVERFLOW(surf->num_vertexes, surf->num_triangles * 3); // compute interpolated joint matrices ComputeJointMats(data, frame, oldframe, backlerp, jointMats); // transform vertexes and fill other data for (i = 0; i < surf->num_vertexes; i++, outXYZ++, outNormal++, outTexCoord++, outColor++) { int j, k; float vtxMat[12]; float nrmMat[9]; int vtx = i + surf->first_vertex; // compute the vertex matrix by blending the up to // four blend weights for (k = 0; k < 12; k++) vtxMat[k] = data->blendWeights[4 * vtx] * jointMats[12 * data->blendIndexes[4 * vtx] + k]; for (j = 1; j < 4; j++) { if (data->blendWeights[4 * vtx + j] <= 0) break; for (k = 0; k < 12; k++) vtxMat[k] += data->blendWeights[4 * vtx + j] * jointMats[12 * data->blendIndexes[4 * vtx + j] + k]; } for (k = 0; k < 12; k++) vtxMat[k] *= 1.0f / 255.0f; // compute the normal matrix as transpose of the adjoint // of the vertex matrix nrmMat[ 0] = vtxMat[ 5] * vtxMat[10] - vtxMat[ 6] * vtxMat[ 9]; nrmMat[ 1] = vtxMat[ 6] * vtxMat[ 8] - vtxMat[ 4] * vtxMat[10]; nrmMat[ 2] = vtxMat[ 4] * vtxMat[ 9] - vtxMat[ 5] * vtxMat[ 8]; nrmMat[ 3] = vtxMat[ 2] * vtxMat[ 9] - vtxMat[ 1] * vtxMat[10]; nrmMat[ 4] = vtxMat[ 0] * vtxMat[10] - vtxMat[ 2] * vtxMat[ 8]; nrmMat[ 5] = vtxMat[ 1] * vtxMat[ 8] - vtxMat[ 0] * vtxMat[ 9]; nrmMat[ 6] = vtxMat[ 1] * vtxMat[ 6] - vtxMat[ 2] * vtxMat[ 5]; nrmMat[ 7] = vtxMat[ 2] * vtxMat[ 4] - vtxMat[ 0] * vtxMat[ 6]; nrmMat[ 8] = vtxMat[ 0] * vtxMat[ 5] - vtxMat[ 1] * vtxMat[ 4]; (*outTexCoord)[0][0] = data->texcoords[2 * vtx + 0]; (*outTexCoord)[0][1] = data->texcoords[2 * vtx + 1]; (*outTexCoord)[1][0] = (*outTexCoord)[0][0]; (*outTexCoord)[1][1] = (*outTexCoord)[0][1]; (*outXYZ)[0] = vtxMat[ 0] * data->positions[3 * vtx + 0] + vtxMat[ 1] * data->positions[3 * vtx + 1] + vtxMat[ 2] * data->positions[3 * vtx + 2] + vtxMat[ 3]; (*outXYZ)[1] = vtxMat[ 4] * data->positions[3 * vtx + 0] + vtxMat[ 5] * data->positions[3 * vtx + 1] + vtxMat[ 6] * data->positions[3 * vtx + 2] + vtxMat[ 7]; (*outXYZ)[2] = vtxMat[ 8] * data->positions[3 * vtx + 0] + vtxMat[ 9] * data->positions[3 * vtx + 1] + vtxMat[10] * data->positions[3 * vtx + 2] + vtxMat[11]; (*outXYZ)[3] = 1.0f; (*outNormal)[0] = nrmMat[ 0] * data->normals[3 * vtx + 0] + nrmMat[ 1] * data->normals[3 * vtx + 1] + nrmMat[ 2] * data->normals[3 * vtx + 2]; (*outNormal)[1] = nrmMat[ 3] * data->normals[3 * vtx + 0] + nrmMat[ 4] * data->normals[3 * vtx + 1] + nrmMat[ 5] * data->normals[3 * vtx + 2]; (*outNormal)[2] = nrmMat[ 6] * data->normals[3 * vtx + 0] + nrmMat[ 7] * data->normals[3 * vtx + 1] + nrmMat[ 8] * data->normals[3 * vtx + 2]; (*outNormal)[3] = 0.0f; (*outColor)[0] = data->colors[4 * vtx + 0]; (*outColor)[1] = data->colors[4 * vtx + 1]; (*outColor)[2] = data->colors[4 * vtx + 2]; (*outColor)[3] = data->colors[4 * vtx + 3]; } tri = data->triangles + 3 * surf->first_triangle; ptr = &tess.indexes[tess.numIndexes]; base = tess.numVertexes; for (i = 0; i < surf->num_triangles; i++) { *ptr++ = base + (*tri++ - surf->first_vertex); *ptr++ = base + (*tri++ - surf->first_vertex); *ptr++ = base + (*tri++ - surf->first_vertex); } tess.numIndexes += 3 * surf->num_triangles; tess.numVertexes += surf->num_vertexes; }
/* ================= RB_AddIQMSurfaces Compute vertices for this model surface ================= */ void RB_IQMSurfaceAnim( surfaceType_t *surface ) { srfIQModel_t *surf = (srfIQModel_t *)surface; iqmData_t *data = surf->data; float jointMats[IQM_MAX_JOINTS * 12]; int i; vec4_t *outXYZ; uint32_t *outNormal; #ifdef USE_VERT_TANGENT_SPACE uint32_t *outTangent; #endif vec2_t (*outTexCoord)[2]; vec4_t *outColor; iqmData_t *skeleton = R_GetIQMModelDataByHandle( backEnd.currentEntity->e.frameModel, data ); iqmData_t *oldSkeleton = R_GetIQMModelDataByHandle( backEnd.currentEntity->e.oldframeModel, data ); int frame = skeleton->num_frames ? backEnd.currentEntity->e.frame % skeleton->num_frames : 0; int oldframe = oldSkeleton->num_frames ? backEnd.currentEntity->e.oldframe % oldSkeleton->num_frames : 0; float backlerp = backEnd.currentEntity->e.backlerp; int *tri; glIndex_t *ptr; glIndex_t base; if ( data != skeleton && data->num_joints != skeleton->num_poses ) { ri.Printf( PRINT_WARNING, "WARNING: frameModel '%s' for model '%s' has different number of joints\n", R_GetModelByHandle( backEnd.currentEntity->e.frameModel )->name, R_GetModelByHandle( backEnd.currentEntity->e.hModel )->name ); skeleton = data; } if ( data != oldSkeleton && data->num_joints != oldSkeleton->num_poses ) { ri.Printf( PRINT_WARNING, "WARNING: oldframeModel '%s' for model '%s' has different number of joints\n", R_GetModelByHandle( backEnd.currentEntity->e.oldframeModel )->name, R_GetModelByHandle( backEnd.currentEntity->e.hModel )->name ); oldSkeleton = data; } RB_CHECKOVERFLOW( surf->num_vertexes, surf->num_triangles * 3 ); outXYZ = &tess.xyz[tess.numVertexes]; outNormal = &tess.normal[tess.numVertexes]; #ifdef USE_VERT_TANGENT_SPACE outTangent = &tess.tangent[tess.numVertexes]; #endif outTexCoord = &tess.texCoords[tess.numVertexes]; outColor = &tess.vertexColors[tess.numVertexes]; // compute interpolated joint matrices if ( skeleton->num_poses > 0 ) { ComputePoseMats( data, skeleton, oldSkeleton, frame, oldframe, backlerp, jointMats ); } // transform vertexes and fill other data for( i = 0; i < surf->num_vertexes; i++, outXYZ++, outNormal++, outTexCoord++, outColor++ ) { int j, k; float vtxMat[12]; float nrmMat[9]; int vtx = i + surf->first_vertex; float blendWeights[4]; int numWeights; for ( numWeights = 0; numWeights < 4; numWeights++ ) { if ( data->blendWeightsType == IQM_FLOAT ) blendWeights[numWeights] = data->blendWeights.f[4*vtx + numWeights]; else blendWeights[numWeights] = (float)data->blendWeights.b[4*vtx + numWeights] / 255.0f; if ( blendWeights[numWeights] <= 0 ) break; } if ( skeleton->num_poses == 0 || numWeights == 0 ) { // no blend joint, use identity matrix. Com_Memcpy( vtxMat, identityMatrix, 12 * sizeof (float) ); } else { // compute the vertex matrix by blending the up to // four blend weights Com_Memset( vtxMat, 0, 12 * sizeof (float) ); for( j = 0; j < numWeights; j++ ) { for( k = 0; k < 12; k++ ) { vtxMat[k] += blendWeights[j] * jointMats[12*data->blendIndexes[4*vtx + j] + k]; } } } // compute the normal matrix as transpose of the adjoint // of the vertex matrix nrmMat[ 0] = vtxMat[ 5]*vtxMat[10] - vtxMat[ 6]*vtxMat[ 9]; nrmMat[ 1] = vtxMat[ 6]*vtxMat[ 8] - vtxMat[ 4]*vtxMat[10]; nrmMat[ 2] = vtxMat[ 4]*vtxMat[ 9] - vtxMat[ 5]*vtxMat[ 8]; nrmMat[ 3] = vtxMat[ 2]*vtxMat[ 9] - vtxMat[ 1]*vtxMat[10]; nrmMat[ 4] = vtxMat[ 0]*vtxMat[10] - vtxMat[ 2]*vtxMat[ 8]; nrmMat[ 5] = vtxMat[ 1]*vtxMat[ 8] - vtxMat[ 0]*vtxMat[ 9]; nrmMat[ 6] = vtxMat[ 1]*vtxMat[ 6] - vtxMat[ 2]*vtxMat[ 5]; nrmMat[ 7] = vtxMat[ 2]*vtxMat[ 4] - vtxMat[ 0]*vtxMat[ 6]; nrmMat[ 8] = vtxMat[ 0]*vtxMat[ 5] - vtxMat[ 1]*vtxMat[ 4]; (*outTexCoord)[0][0] = data->texcoords[2*vtx + 0]; (*outTexCoord)[0][1] = data->texcoords[2*vtx + 1]; (*outTexCoord)[1][0] = (*outTexCoord)[0][0]; (*outTexCoord)[1][1] = (*outTexCoord)[0][1]; (*outXYZ)[0] = vtxMat[ 0] * data->positions[3*vtx+0] + vtxMat[ 1] * data->positions[3*vtx+1] + vtxMat[ 2] * data->positions[3*vtx+2] + vtxMat[ 3]; (*outXYZ)[1] = vtxMat[ 4] * data->positions[3*vtx+0] + vtxMat[ 5] * data->positions[3*vtx+1] + vtxMat[ 6] * data->positions[3*vtx+2] + vtxMat[ 7]; (*outXYZ)[2] = vtxMat[ 8] * data->positions[3*vtx+0] + vtxMat[ 9] * data->positions[3*vtx+1] + vtxMat[10] * data->positions[3*vtx+2] + vtxMat[11]; (*outXYZ)[3] = 1.0f; { vec3_t normal; vec4_t tangent; normal[0] = DotProduct(&nrmMat[0], &data->normals[3*vtx]); normal[1] = DotProduct(&nrmMat[3], &data->normals[3*vtx]); normal[2] = DotProduct(&nrmMat[6], &data->normals[3*vtx]); *outNormal = R_VboPackNormal(normal); #ifdef USE_VERT_TANGENT_SPACE tangent[0] = DotProduct(&nrmMat[0], &data->tangents[4*vtx]); tangent[1] = DotProduct(&nrmMat[3], &data->tangents[4*vtx]); tangent[2] = DotProduct(&nrmMat[6], &data->tangents[4*vtx]); tangent[3] = data->tangents[4*vtx+3]; *outTangent++ = R_VboPackTangent(tangent); #endif } (*outColor)[0] = data->colors[4*vtx+0] / 255.0f; (*outColor)[1] = data->colors[4*vtx+1] / 255.0f; (*outColor)[2] = data->colors[4*vtx+2] / 255.0f; (*outColor)[3] = data->colors[4*vtx+3] / 255.0f; } tri = data->triangles + 3 * surf->first_triangle; ptr = &tess.indexes[tess.numIndexes]; base = tess.numVertexes; for( i = 0; i < surf->num_triangles; i++ ) { *ptr++ = base + (*tri++ - surf->first_vertex); *ptr++ = base + (*tri++ - surf->first_vertex); *ptr++ = base + (*tri++ - surf->first_vertex); } tess.numIndexes += 3 * surf->num_triangles; tess.numVertexes += surf->num_vertexes; }
/* ================= RB_AddIQMSurfaces Compute vertices for this model surface ================= */ void RB_IQMSurfaceAnim( surfaceType_t *surface ) { srfIQModel_t *surf = (srfIQModel_t *)surface; iqmData_t *data = surf->data; float jointMats[IQM_MAX_JOINTS * 12]; int i; vec4_t *outXYZ; vec4_t *outNormal; vec2_t (*outTexCoord)[2]; color4ub_t *outColor; int frame = data->num_frames ? backEnd.currentEntity->e.frame % data->num_frames : 0; int oldframe = data->num_frames ? backEnd.currentEntity->e.oldframe % data->num_frames : 0; float backlerp = backEnd.currentEntity->e.backlerp; int *tri; glIndex_t *ptr; glIndex_t base; RB_CHECKOVERFLOW( surf->num_vertexes, surf->num_triangles * 3 ); outXYZ = &tess.xyz[tess.numVertexes]; outNormal = &tess.normal[tess.numVertexes]; outTexCoord = &tess.texCoords[tess.numVertexes]; outColor = &tess.vertexColors[tess.numVertexes]; // compute interpolated joint matrices if ( data->num_poses > 0 ) { ComputePoseMats( data, frame, oldframe, backlerp, jointMats ); } // transform vertexes and fill other data for( i = 0; i < surf->num_vertexes; i++, outXYZ++, outNormal++, outTexCoord++, outColor++ ) { int j, k; float vtxMat[12]; float nrmMat[9]; int vtx = i + surf->first_vertex; float blendWeights[4]; int numWeights; for ( numWeights = 0; numWeights < 4; numWeights++ ) { if ( data->blendWeightsType == IQM_FLOAT ) blendWeights[numWeights] = data->blendWeights.f[4*vtx + numWeights]; else blendWeights[numWeights] = (float)data->blendWeights.b[4*vtx + numWeights] / 255.0f; if ( blendWeights[numWeights] <= 0 ) break; } if ( data->num_poses == 0 || numWeights == 0 ) { // no blend joint, use identity matrix. Com_Memcpy( vtxMat, identityMatrix, 12 * sizeof (float) ); } else { // compute the vertex matrix by blending the up to // four blend weights Com_Memset( vtxMat, 0, 12 * sizeof (float) ); for( j = 0; j < numWeights; j++ ) { for( k = 0; k < 12; k++ ) { vtxMat[k] += blendWeights[j] * jointMats[12*data->blendIndexes[4*vtx + j] + k]; } } } // compute the normal matrix as transpose of the adjoint // of the vertex matrix nrmMat[ 0] = vtxMat[ 5]*vtxMat[10] - vtxMat[ 6]*vtxMat[ 9]; nrmMat[ 1] = vtxMat[ 6]*vtxMat[ 8] - vtxMat[ 4]*vtxMat[10]; nrmMat[ 2] = vtxMat[ 4]*vtxMat[ 9] - vtxMat[ 5]*vtxMat[ 8]; nrmMat[ 3] = vtxMat[ 2]*vtxMat[ 9] - vtxMat[ 1]*vtxMat[10]; nrmMat[ 4] = vtxMat[ 0]*vtxMat[10] - vtxMat[ 2]*vtxMat[ 8]; nrmMat[ 5] = vtxMat[ 1]*vtxMat[ 8] - vtxMat[ 0]*vtxMat[ 9]; nrmMat[ 6] = vtxMat[ 1]*vtxMat[ 6] - vtxMat[ 2]*vtxMat[ 5]; nrmMat[ 7] = vtxMat[ 2]*vtxMat[ 4] - vtxMat[ 0]*vtxMat[ 6]; nrmMat[ 8] = vtxMat[ 0]*vtxMat[ 5] - vtxMat[ 1]*vtxMat[ 4]; (*outTexCoord)[0][0] = data->texcoords[2*vtx + 0]; (*outTexCoord)[0][1] = data->texcoords[2*vtx + 1]; (*outTexCoord)[1][0] = (*outTexCoord)[0][0]; (*outTexCoord)[1][1] = (*outTexCoord)[0][1]; (*outXYZ)[0] = vtxMat[ 0] * data->positions[3*vtx+0] + vtxMat[ 1] * data->positions[3*vtx+1] + vtxMat[ 2] * data->positions[3*vtx+2] + vtxMat[ 3]; (*outXYZ)[1] = vtxMat[ 4] * data->positions[3*vtx+0] + vtxMat[ 5] * data->positions[3*vtx+1] + vtxMat[ 6] * data->positions[3*vtx+2] + vtxMat[ 7]; (*outXYZ)[2] = vtxMat[ 8] * data->positions[3*vtx+0] + vtxMat[ 9] * data->positions[3*vtx+1] + vtxMat[10] * data->positions[3*vtx+2] + vtxMat[11]; (*outXYZ)[3] = 1.0f; (*outNormal)[0] = nrmMat[ 0] * data->normals[3*vtx+0] + nrmMat[ 1] * data->normals[3*vtx+1] + nrmMat[ 2] * data->normals[3*vtx+2]; (*outNormal)[1] = nrmMat[ 3] * data->normals[3*vtx+0] + nrmMat[ 4] * data->normals[3*vtx+1] + nrmMat[ 5] * data->normals[3*vtx+2]; (*outNormal)[2] = nrmMat[ 6] * data->normals[3*vtx+0] + nrmMat[ 7] * data->normals[3*vtx+1] + nrmMat[ 8] * data->normals[3*vtx+2]; (*outNormal)[3] = 0.0f; (*outColor)[0] = data->colors[4*vtx+0]; (*outColor)[1] = data->colors[4*vtx+1]; (*outColor)[2] = data->colors[4*vtx+2]; (*outColor)[3] = data->colors[4*vtx+3]; } tri = data->triangles + 3 * surf->first_triangle; ptr = &tess.indexes[tess.numIndexes]; base = tess.numVertexes; for( i = 0; i < surf->num_triangles; i++ ) { *ptr++ = base + (*tri++ - surf->first_vertex); *ptr++ = base + (*tri++ - surf->first_vertex); *ptr++ = base + (*tri++ - surf->first_vertex); } tess.numIndexes += 3 * surf->num_triangles; tess.numVertexes += surf->num_vertexes; }