void CqTeapot::Bound(CqBound* bound) const { CqVector3D vecMin( -3.000, -2.0, 0.0 ); CqVector3D vecMax( 3.525, 2.0, ( m_CrowBase ? 3.15 : 3.15 - 0.15 /* remove bottom */ ) ); bound->vecMin() = vecMin; bound->vecMax() = vecMax; bound->Transform( m_matTx ); AdjustBoundForTransformationMotion( bound ); }
void Mesh_Bounds(Model *pModel, Vec4 &vecBound) { i32 i; i32 j; Vec3 vecMax(0.f,0.f,0.f); Vec3 vecMin(0.f,0.f,0.f); float *pVert=pModel->p_fVerts; for(j=0;j<pModel->iMeshes;j++) { for(i=0;i<pModel->pMesh[j]->iNumVerts;i++) { if(vecMax.GetX()<pVert[0]) { vecMax.SetX(pVert[0]); } if(vecMax.GetY()<pVert[1]) { vecMax.SetY(pVert[1]); } if(vecMax.GetZ()<pVert[2]) { vecMax.SetZ(pVert[2]); } if(vecMin.GetX()>pVert[0]) { vecMin.SetX(pVert[0]); } if(vecMin.GetY()>pVert[1]) { vecMin.SetY(pVert[1]); } if(vecMin.GetZ()>pVert[2]) { vecMin.SetZ(pVert[2]); } pVert+=3; } } vecBound.SetX(vecMax.GetX()-vecMin.GetX()); vecBound.SetY(vecMax.GetY()-vecMin.GetY()); vecBound.SetZ(vecMax.GetZ()-vecMin.GetZ()); vecBound.SetW(vecBound.Length()/2.f); }
//----------------------------------------------------------------------------- // Purpose: // Input : *pPatch - // *pPoints - // &vecNormal - // flArea - //----------------------------------------------------------------------------- bool CVRADDispColl::InitPatch( int iPatch, int iParentPatch, int iChild, Vector *pPoints, int *pIndices, float &flArea ) { // Get the current patch. CPatch *pPatch = &g_Patches[iPatch]; if ( !pPatch ) return false; // Clear the patch data. memset( pPatch, 0, sizeof( CPatch ) ); // Setup the parent if we are not the parent. CPatch *pParentPatch = NULL; if ( iParentPatch != g_Patches.InvalidIndex() ) { // Get the parent patch. pParentPatch = &g_Patches[iParentPatch]; if ( !pParentPatch ) return false; } // Attach the face to the correct lists. if ( !pParentPatch ) { // This is a parent. pPatch->ndxNext = g_FacePatches.Element( GetParentIndex() ); g_FacePatches[GetParentIndex()] = iPatch; pPatch->faceNumber = GetParentIndex(); } else { pPatch->ndxNext = g_Patches.InvalidIndex(); pPatch->faceNumber = pParentPatch->faceNumber; // Attach to the parent patch. if ( iChild == 0 ) { pParentPatch->child1 = iPatch; } else { pParentPatch->child2 = iPatch; } } // Initialize parent and children indices. pPatch->child1 = g_Patches.InvalidIndex(); pPatch->child2 = g_Patches.InvalidIndex(); pPatch->ndxNextClusterChild = g_Patches.InvalidIndex(); pPatch->ndxNextParent = g_Patches.InvalidIndex(); pPatch->parent = iParentPatch; // Get triangle edges. Vector vecEdges[3]; vecEdges[0] = pPoints[1] - pPoints[0]; vecEdges[1] = pPoints[2] - pPoints[0]; vecEdges[2] = pPoints[2] - pPoints[1]; // Find the longest edge. // float flEdgeLength = 0.0f; // for ( int iEdge = 0; iEdge < 3; ++iEdge ) // { // if ( flEdgeLength < vecEdges[iEdge].Length() ) // { // flEdgeLength = vecEdges[iEdge].Length(); // } // } // Calculate the triangle normal and area. Vector vecNormal = vecEdges[1].Cross( vecEdges[0] ); flArea = VectorNormalize( vecNormal ); flArea *= 0.5f; // Initialize the patch scale. pPatch->scale[0] = pPatch->scale[1] = 1.0f; // Set the patch chop - minchop (that is what the minimum area is based on). pPatch->chop = dispchop; // Displacements are not sky! pPatch->sky = false; // Copy the winding. Vector vecCenter( 0.0f, 0.0f, 0.0f ); pPatch->winding = AllocWinding( 3 ); pPatch->winding->numpoints = 3; for ( int iPoint = 0; iPoint < 3; ++iPoint ) { VectorCopy( pPoints[iPoint], pPatch->winding->p[iPoint] ); VectorAdd( pPoints[iPoint], vecCenter, vecCenter ); pPatch->indices[iPoint] = static_cast<short>( pIndices[iPoint] ); } // Set the origin and normal. VectorScale( vecCenter, ( 1.0f / 3.0f ), vecCenter ); VectorCopy( vecCenter, pPatch->origin ); VectorCopy( vecNormal, pPatch->normal ); // Create the plane. pPatch->plane = new dplane_t; if ( !pPatch->plane ) return false; VectorCopy( vecNormal, pPatch->plane->normal ); pPatch->plane->dist = vecNormal.Dot( pPoints[0] ); pPatch->plane->type = PlaneTypeForNormal( pPatch->plane->normal ); pPatch->planeDist = pPatch->plane->dist; // Set the area. pPatch->area = flArea; // Calculate the mins/maxs. Vector vecMin( FLT_MAX, FLT_MAX, FLT_MAX ); Vector vecMax( FLT_MIN, FLT_MIN, FLT_MIN ); for ( int iPoint = 0; iPoint < 3; ++iPoint ) { for ( int iAxis = 0; iAxis < 3; ++iAxis ) { vecMin[iAxis] = MIN( vecMin[iAxis], pPoints[iPoint][iAxis] ); vecMax[iAxis] = MAX( vecMax[iAxis], pPoints[iPoint][iAxis] ); } } VectorCopy( vecMin, pPatch->mins ); VectorCopy( vecMax, pPatch->maxs ); if ( !pParentPatch ) { VectorCopy( vecMin, pPatch->face_mins ); VectorCopy( vecMax, pPatch->face_maxs ); } else { VectorCopy( pParentPatch->face_mins, pPatch->face_mins ); VectorCopy( pParentPatch->face_maxs, pPatch->face_maxs ); } // Check for bumpmap. dface_t *pFace = dfaces + pPatch->faceNumber; texinfo_t *pTexInfo = &texinfo[pFace->texinfo]; pPatch->needsBumpmap = pTexInfo->flags & SURF_BUMPLIGHT ? true : false; // Misc... pPatch->m_IterationKey = 0; // Get the base light for the face. if ( !pParentPatch ) { BaseLightForFace( &g_pFaces[pPatch->faceNumber], pPatch->baselight, &pPatch->basearea, pPatch->reflectivity ); } else { VectorCopy( pParentPatch->baselight, pPatch->baselight ); pPatch->basearea = pParentPatch->basearea; pPatch->reflectivity = pParentPatch->reflectivity; } return true; }
//----------------------------------------------------------------------------- // Purpose: // Input : iPatch - // iParentPatch - // iChild - // *pPoints - // *pIndices - // &flArea - // Output : Returns true on success, false on failure. //----------------------------------------------------------------------------- bool CVRADDispColl::InitParentPatch( int iPatch, Vector *pPoints, float &flArea ) { // Get the current patch. CPatch *pPatch = &g_Patches[iPatch]; if ( !pPatch ) return false; // Clear the patch data. memset( pPatch, 0, sizeof( CPatch ) ); // This is a parent. pPatch->ndxNext = g_FacePatches.Element( GetParentIndex() ); g_FacePatches[GetParentIndex()] = iPatch; pPatch->faceNumber = GetParentIndex(); // Initialize parent and children indices. pPatch->child1 = g_Patches.InvalidIndex(); pPatch->child2 = g_Patches.InvalidIndex(); pPatch->parent = g_Patches.InvalidIndex(); pPatch->ndxNextClusterChild = g_Patches.InvalidIndex(); pPatch->ndxNextParent = g_Patches.InvalidIndex(); Vector vecEdges[2]; vecEdges[0] = pPoints[1] - pPoints[0]; vecEdges[1] = pPoints[3] - pPoints[0]; // Calculate the triangle normal and area. Vector vecNormal = vecEdges[1].Cross( vecEdges[0] ); flArea = VectorNormalize( vecNormal ); // Initialize the patch scale. pPatch->scale[0] = pPatch->scale[1] = 1.0f; // Set the patch chop - minchop (that is what the minimum area is based on). pPatch->chop = dispchop; // Displacements are not sky! pPatch->sky = false; // Copy the winding. Vector vecCenter( 0.0f, 0.0f, 0.0f ); pPatch->winding = AllocWinding( 4 ); pPatch->winding->numpoints = 4; for ( int iPoint = 0; iPoint < 4; ++iPoint ) { VectorCopy( pPoints[iPoint], pPatch->winding->p[iPoint] ); VectorAdd( pPoints[iPoint], vecCenter, vecCenter ); } // Set the origin and normal. VectorScale( vecCenter, ( 1.0f / 4.0f ), vecCenter ); VectorCopy( vecCenter, pPatch->origin ); VectorCopy( vecNormal, pPatch->normal ); // Create the plane. pPatch->plane = new dplane_t; if ( !pPatch->plane ) return false; VectorCopy( vecNormal, pPatch->plane->normal ); pPatch->plane->dist = vecNormal.Dot( pPoints[0] ); pPatch->plane->type = PlaneTypeForNormal( pPatch->plane->normal ); pPatch->planeDist = pPatch->plane->dist; // Set the area. pPatch->area = flArea; // Calculate the mins/maxs. Vector vecMin( FLT_MAX, FLT_MAX, FLT_MAX ); Vector vecMax( FLT_MIN, FLT_MIN, FLT_MIN ); for ( int iPoint = 0; iPoint < 4; ++iPoint ) { for ( int iAxis = 0; iAxis < 3; ++iAxis ) { vecMin[iAxis] = MIN( vecMin[iAxis], pPoints[iPoint][iAxis] ); vecMax[iAxis] = MAX( vecMax[iAxis], pPoints[iPoint][iAxis] ); } } VectorCopy( vecMin, pPatch->mins ); VectorCopy( vecMax, pPatch->maxs ); VectorCopy( vecMin, pPatch->face_mins ); VectorCopy( vecMax, pPatch->face_maxs ); // Check for bumpmap. dface_t *pFace = dfaces + pPatch->faceNumber; texinfo_t *pTexInfo = &texinfo[pFace->texinfo]; pPatch->needsBumpmap = pTexInfo->flags & SURF_BUMPLIGHT ? true : false; // Misc... pPatch->m_IterationKey = 0; // Calculate the base light, area, and reflectivity. BaseLightForFace( &g_pFaces[pPatch->faceNumber], pPatch->baselight, &pPatch->basearea, pPatch->reflectivity ); return true; }