// // returns false if the triangle is not within the frustum // bool TriInFrustum( CVec3 vTri[3], CVec3 Normals[4], CVec3 Points[8] ) { int i; // If all 3 points are to one side any frustum plane return false for( int x = 0; x < 4; x++ ) { for ( i = 0; i < 3; i++ ) { if ( Normals[x].Dot( vTri[i] - Points[x*2] ) < 0 ) break; } if ( i >= 3 ) return false; } // If any point is in the frustum, return true for ( i = 0; i < 3; i++ ) { if ( PointInFrustum( vTri[i], Normals, Points ) ) return true; } // If we didn't get quick result, do a slower but accurate test. // If any of the lines of the triangle are in the frustum, the triangle is in the frustum if ( LineInFrustum( vTri[0], vTri[1], Points ) ) return true; if ( LineInFrustum( vTri[1], vTri[2], Points ) ) return true; if ( LineInFrustum( vTri[2], vTri[0], Points ) ) return true; // If the frustum is completely inside the triangle, any frustum line into the screen will intersect the triangle CVec3 HitP; if ( CheckLineTri( Points[0], Points[1], vTri[0], vTri[1], vTri[2], HitP ) ) return true; return false; }
FORCEINLINE void DrawText(UCanvas* Canvas, UFont* Font, const FString& TextToDraw, const FVector& WorldLocation) { if (PointInFrustum(Canvas, WorldLocation)) { const FVector ScreenLocation = Canvas->Project(WorldLocation); Canvas->DrawText(Font, *TextToDraw, ScreenLocation.X, ScreenLocation.Y); } }
void Frustum::Clip(int plane,int vertexCount,TexturesPSPVertex * in,int i,TexturesPSPVertex * out,int &outCount) { //for each vertex outCount = 0; bool ins[5]; float dist[5]; int index = 0; for(int v = i; v < (i + vertexCount);v++) { ins[index] = PointInFrustum(plane,Vector3(in[v].x,in[v].y,in[v].z),dist[index]); index++; } index = 0; for(int v = i; v < (i + vertexCount) - 1;v++) { if(ins[index]) { if(ins[index+1]) { out[outCount++] = in[v+1]; }else { out[outCount++] = vertexIntersection(in[v],dist[index],in[v+1],dist[index+1]); } }else { if(ins[index+1]) { out[outCount++] = vertexIntersection(in[v],dist[index],in[v+1],dist[index+1]); out[outCount++] = in[v+1]; } } index++; } //last and first if(ins[index]) { if(ins[0]) { out[outCount++] = in[i]; }else { out[outCount++] = vertexIntersection(in[(i + vertexCount) - 1],dist[index],in[i],dist[0]); } }else { if(ins[0]) { out[outCount++] = vertexIntersection(in[(i + vertexCount) - 1],dist[index],in[i],dist[0]); out[outCount++] = in[i]; } } }
FORCEINLINE void DrawTextCentered(UCanvas* Canvas, UFont* Font, const FString& TextToDraw, const FVector& WorldLocation) { if (PointInFrustum(Canvas, WorldLocation)) { const FVector ScreenLocation = Canvas->Project(WorldLocation); float TextXL = 0.f; float TextYL = 0.f; Canvas->StrLen(Font, TextToDraw, TextXL, TextYL); Canvas->DrawText(Font, *TextToDraw, ScreenLocation.X - TextXL / 2.0f, ScreenLocation.Y - TextYL / 2.0f); } }
bool AABBoxInFrustum(const irr::scene::SViewFrustum * Frustum, const irr::core::aabbox3df & Box) { //loop through each box point. if(PointInFrustum(Frustum, irr::core::vector3df(Box.MinEdge.X, Box.MinEdge.Y, Box.MinEdge.Z))) return true; if(PointInFrustum(Frustum, irr::core::vector3df(Box.MaxEdge.X, Box.MinEdge.Y, Box.MinEdge.Z))) return true; if(PointInFrustum(Frustum, irr::core::vector3df(Box.MinEdge.X, Box.MaxEdge.Y, Box.MinEdge.Z))) return true; if(PointInFrustum(Frustum, irr::core::vector3df(Box.MinEdge.X, Box.MinEdge.Y, Box.MaxEdge.Z))) return true; if(PointInFrustum(Frustum, irr::core::vector3df(Box.MaxEdge.X, Box.MaxEdge.Y, Box.MinEdge.Z))) return true; if(PointInFrustum(Frustum, irr::core::vector3df(Box.MaxEdge.X, Box.MinEdge.Y, Box.MaxEdge.Z))) return true; if(PointInFrustum(Frustum, irr::core::vector3df(Box.MinEdge.X, Box.MaxEdge.Y, Box.MaxEdge.Z))) return true; if(PointInFrustum(Frustum, irr::core::vector3df(Box.MaxEdge.X, Box.MaxEdge.Y, Box.MaxEdge.Z))) return true; return false; }
bool FrustumPlanes::BoxInFrustum(const BOX &Box) const { // Ka¿dy punkt AABB musi le¿eæ w jego wnêtrzu if (!PointInFrustum(Box.v1)) return false; if (!PointInFrustum(Box.v2)) return false; if (!PointInFrustum(D3DXVECTOR3(Box.v2.x, Box.v1.y, Box.v1.z))) return false; if (!PointInFrustum(D3DXVECTOR3(Box.v1.x, Box.v2.y, Box.v1.z))) return false; if (!PointInFrustum(D3DXVECTOR3(Box.v2.x, Box.v2.y, Box.v1.z))) return false; if (!PointInFrustum(D3DXVECTOR3(Box.v1.x, Box.v1.y, Box.v2.z))) return false; if (!PointInFrustum(D3DXVECTOR3(Box.v2.x, Box.v1.y, Box.v2.z))) return false; if (!PointInFrustum(D3DXVECTOR3(Box.v1.x, Box.v2.y, Box.v2.z))) return false; return true; }
bool CFrustum::ShapeInFrustum( float x, float y, float z, Shape *shape ) { float w = ( shape->getWidth() ) * MUL; float d = ( shape->getDepth() ) * MUL; float h = ( shape->getHeight() ) * MUL; return ( PointInFrustum( x , y , z ) || PointInFrustum( x + w, y , z ) || PointInFrustum( x + w, y + d, z ) || PointInFrustum( x , y + d, z ) || PointInFrustum( x , y , z + h ) || PointInFrustum( x + w, y , z + h ) || PointInFrustum( x + w, y + d, z + h ) || PointInFrustum( x , y + d, z + h ) ); }
FORCEINLINE void DrawTextShadowed(UCanvas* Canvas, UFont* Font, const FString& TextToDraw, const FVector& WorldLocation) { if (PointInFrustum(Canvas, WorldLocation)) { const FVector ScreenLocation = Canvas->Project(WorldLocation); float TextXL = 0.f; float TextYL = 0.f; Canvas->StrLen(Font, TextToDraw, TextXL, TextYL); Canvas->SetDrawColor(FColor::Black); Canvas->DrawText(Font, *TextToDraw, 1 + ScreenLocation.X - TextXL / 2.0f, 1 + ScreenLocation.Y - TextYL / 2.0f); Canvas->SetDrawColor(FColor::White); Canvas->DrawText(Font, *TextToDraw, ScreenLocation.X - TextXL / 2.0f, ScreenLocation.Y - TextYL / 2.0f); } }
void TextureMain::draw2DCalibrationFull() { ExtractFrustum(); GLuint queries[textureModel->TotalFaces]; GLuint sampleCount; glGenQueriesARB(textureModel->TotalFaces, queries); glDisable(GL_BLEND); glDepthFunc(GL_LESS); glDepthMask(GL_TRUE); for (int i = 0; i < textureModel->TotalFaces; i++) { int index = i * 3; if (PointInFrustum(textureModel->Faces_Triangles[index * 3], textureModel->Faces_Triangles[index * 3 + 1], textureModel->Faces_Triangles[index * 3 + 2])) { glBeginQueryARB(GL_SAMPLES_PASSED_ARB, queries[i]); draw2DElement(i); glEndQueryARB(GL_SAMPLES_PASSED_ARB); } } glEnable(GL_BLEND); glDepthFunc(GL_EQUAL); glDepthMask(GL_FALSE); for (int i = 0; i < textureModel->TotalFaces; i++) { int index = i * 3; if (PointInFrustum(textureModel->Faces_Triangles[index * 3], textureModel->Faces_Triangles[index * 3 + 1], textureModel->Faces_Triangles[index * 3 + 2])) { glGetQueryObjectuivARB(queries[i], GL_QUERY_RESULT_ARB, &sampleCount); if (sampleCount > 0) { if (textureIndex > 0) { faces[textureIndex][i] = sampleCount; } draw2DElement(i); } } } glDisable(GL_BLEND); glDepthFunc(GL_LESS); glDepthMask(GL_TRUE); }
bool CFrustum::PointInFrustum( const Vector3D & point ) const { return PointInFrustum(point.x, point.y, point.z ); }
short BranchInFrustum (float x1, float y1, float z1 ,float x2, float y2, float z2 ) { return PointInFrustum(x1, y1, z1) || PointInFrustum(x2, y2, z2); }