本文整理汇总了C++中idPlane::Distance方法的典型用法代码示例。如果您正苦于以下问题:C++ idPlane::Distance方法的具体用法?C++ idPlane::Distance怎么用?C++ idPlane::Distance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类idPlane
的用法示例。
在下文中一共展示了idPlane::Distance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BrushMostlyOnSide
/*
==================
BrushMostlyOnSide
==================
*/
int BrushMostlyOnSide( uBrush_t *brush, idPlane &plane )
{
int i, j;
idWinding *w;
float d, max = 0;
int side = PSIDE_FRONT;
for( i = 0; i < brush->numsides; i++ )
{
w = brush->sides[i].winding;
if( !w )
{
continue;
}
for( j = 0; j < w->GetNumPoints(); j++ )
{
d = plane.Distance( ( *w ) [j].ToVec3() );
if( d > max )
{
max = d;
side = PSIDE_FRONT;
}
if( -d > max )
{
max = -d;
side = PSIDE_BACK;
}
}
}
return side;
}
示例2: Cull
/*
===================
Cull
cull points against given shadow frustum.
Return true of all points are outside the frustum.
===================
*/
bool shadowMapFrustum_t::Cull( const idVec3 points[8] ) const {
bool outsidePlane[6];
for (int i = 0; i < numPlanes; i++) {
bool pointsCulled[8] = { true };
const idPlane plane = planes[i];
for (int j = 0; j < 8; j++) {
const float distance = plane.Distance( points[j] );
pointsCulled[j] = distance < 0;
}
outsidePlane[i] = true;
for (int j = 0; j < 8; j++) {
if (!pointsCulled[j]) {
outsidePlane[i] = false;
}
}
}
for (int i = 0; i < numPlanes; i++) {
if (outsidePlane[i])
return true;
}
return false;
}
示例3: R_CalcInteractionFacing
/*
================
R_CalcInteractionFacing
Determines which triangles of the surface are facing towards the light origin.
The facing array should be allocated with one extra index than
the number of surface triangles, which will be used to handle dangling
edge silhouettes.
================
*/
void R_CalcInteractionFacing( const idRenderEntityLocal *ent, const srfTriangles_t *tri, const idRenderLightLocal *light, srfCullInfo_t &cullInfo ) {
SCOPED_PROFILE_EVENT( "R_CalcInteractionFacing" );
if ( cullInfo.facing != NULL ) {
return;
}
idVec3 localLightOrigin;
R_GlobalPointToLocal( ent->modelMatrix, light->globalLightOrigin, localLightOrigin );
const int numFaces = tri->numIndexes / 3;
cullInfo.facing = (byte *) R_StaticAlloc( ( numFaces + 1 ) * sizeof( cullInfo.facing[0] ), TAG_RENDER_INTERACTION );
// exact geometric cull against face
for ( int i = 0, face = 0; i < tri->numIndexes; i += 3, face++ ) {
const idDrawVert & v0 = tri->verts[tri->indexes[i + 0]];
const idDrawVert & v1 = tri->verts[tri->indexes[i + 1]];
const idDrawVert & v2 = tri->verts[tri->indexes[i + 2]];
const idPlane plane( v0.xyz, v1.xyz, v2.xyz );
const float d = plane.Distance( localLightOrigin );
cullInfo.facing[face] = ( d >= 0.0f );
}
cullInfo.facing[numFaces] = 1; // for dangling edges to reference
}
示例4: IsLedgeSide_r
/*
============
idAASBuild::IsLedgeSide_r
============
*/
bool idAASBuild::IsLedgeSide_r( idBrushBSPNode *node, idFixedWinding *w, const idPlane &plane, const idVec3 &normal, const idVec3 &origin, const float radius ) {
int res, i;
idFixedWinding back;
float dist;
if ( !node ) {
return false;
}
while ( node->GetChild(0) && node->GetChild(1) ) {
dist = node->GetPlane().Distance( origin );
if ( dist > radius ) {
res = SIDE_FRONT;
}
else if ( dist < -radius ) {
res = SIDE_BACK;
}
else {
res = w->Split( &back, node->GetPlane(), LEDGE_EPSILON );
}
if ( res == SIDE_FRONT ) {
node = node->GetChild(0);
}
else if ( res == SIDE_BACK ) {
node = node->GetChild(1);
}
else if ( res == SIDE_ON ) {
// continue with the side the winding faces
if ( node->GetPlane().Normal() * normal > 0.0f ) {
node = node->GetChild(0);
}
else {
node = node->GetChild(1);
}
}
else {
if ( IsLedgeSide_r( node->GetChild(1), &back, plane, normal, origin, radius ) ) {
return true;
}
node = node->GetChild(0);
}
}
if ( node->GetContents() & AREACONTENTS_SOLID ) {
return false;
}
for ( i = 0; i < w->GetNumPoints(); i++ ) {
if ( plane.Distance( (*w)[i].ToVec3() ) > 0.0f ) {
return true;
}
}
return false;
}
示例5: PlaneSide
/*
================
idSphere::PlaneSide
================
*/
int idSphere::PlaneSide( const idPlane &plane, const float epsilon ) const {
float d;
d = plane.Distance( origin );
if ( d > radius + epsilon ) {
return PLANESIDE_FRONT;
}
if ( d < -radius - epsilon ) {
return PLANESIDE_BACK;
}
return PLANESIDE_CROSS;
}
示例6: PlaneDistance
/*
================
idSphere::PlaneDistance
================
*/
float idSphere::PlaneDistance( const idPlane &plane ) const {
float d;
d = plane.Distance( origin );
if ( d > radius ) {
return d - radius;
}
if ( d < -radius ) {
return d + radius;
}
return 0.0f;
}
示例7: FloorEdgeSplitPoint
/*
============
idAASLocal::FloorEdgeSplitPoint
calculates either the closest or furthest point on the floor of the area which also lies on the pathPlane
the point has to be on the front side of the frontPlane to be valid
============
*/
bool idAASLocal::FloorEdgeSplitPoint( idVec3 &bestSplit, int areaNum, const idPlane &pathPlane, const idPlane &frontPlane, bool closest ) const {
int i, j, faceNum, edgeNum;
const aasArea_t *area;
const aasFace_t *face;
idVec3 split;
float dist, bestDist;
if ( closest ) {
bestDist = maxWalkPathDistance;
} else {
bestDist = -0.1f;
}
area = &file->GetArea( areaNum );
for ( i = 0; i < area->numFaces; i++ ) {
faceNum = file->GetFaceIndex( area->firstFace + i );
face = &file->GetFace( abs(faceNum) );
if ( !(face->flags & FACE_FLOOR ) ) {
continue;
}
for ( j = 0; j < face->numEdges; j++ ) {
edgeNum = file->GetEdgeIndex( face->firstEdge + j );
if ( !EdgeSplitPoint( split, abs( edgeNum ), pathPlane ) ) {
continue;
}
dist = frontPlane.Distance( split );
if ( closest ) {
if ( dist >= -0.1f && dist < bestDist ) {
bestDist = dist;
bestSplit = split;
}
} else {
if ( dist > bestDist ) {
bestDist = dist;
bestSplit = split;
}
}
}
}
if ( closest ) {
return ( bestDist < maxWalkPathDistance );
} else {
return ( bestDist > -0.1f );
}
}
示例8: PlaneSide
/*
================
idBox::PlaneSide
================
*/
int idBox::PlaneSide( const idPlane &plane, const float epsilon ) const {
float d1, d2;
d1 = plane.Distance( center );
d2 = idMath::Fabs( extents[0] * plane.Normal()[0] ) +
idMath::Fabs( extents[1] * plane.Normal()[1] ) +
idMath::Fabs( extents[2] * plane.Normal()[2] );
if ( d1 - d2 > epsilon ) {
return PLANESIDE_FRONT;
}
if ( d1 + d2 < -epsilon ) {
return PLANESIDE_BACK;
}
return PLANESIDE_CROSS;
}
示例9: PlaneDistance
/*
================
idBox::PlaneDistance
================
*/
float idBox::PlaneDistance( const idPlane &plane ) const {
float d1, d2;
d1 = plane.Distance( center );
d2 = idMath::Fabs( extents[0] * plane.Normal()[0] ) +
idMath::Fabs( extents[1] * plane.Normal()[1] ) +
idMath::Fabs( extents[2] * plane.Normal()[2] );
if ( d1 - d2 > 0.0f ) {
return d1 - d2;
}
if ( d1 + d2 < 0.0f ) {
return d1 + d2;
}
return 0.0f;
}
示例10: PlaneSide
/*
================
idBounds::PlaneSide
================
*/
int idBounds::PlaneSide( const idPlane &plane, const float epsilon ) const {
idVec3 center;
float d1, d2;
center = ( b[0] + b[1] ) * 0.5f;
d1 = plane.Distance( center );
d2 = idMath::Fabs( ( b[1][0] - center[0] ) * plane.Normal()[0] ) +
idMath::Fabs( ( b[1][1] - center[1] ) * plane.Normal()[1] ) +
idMath::Fabs( ( b[1][2] - center[2] ) * plane.Normal()[2] );
if ( d1 - d2 > epsilon ) {
return PLANESIDE_FRONT;
}
if ( d1 + d2 < -epsilon ) {
return PLANESIDE_BACK;
}
return PLANESIDE_CROSS;
}
示例11: PlaneDistance
/*
================
idBounds::PlaneDistance
================
*/
float idBounds::PlaneDistance( const idPlane &plane ) const {
idVec3 center;
float d1, d2;
center = ( b[0] + b[1] ) * 0.5f;
d1 = plane.Distance( center );
d2 = idMath::Fabs( ( b[1][0] - center[0] ) * plane.Normal()[0] ) +
idMath::Fabs( ( b[1][1] - center[1] ) * plane.Normal()[1] ) +
idMath::Fabs( ( b[1][2] - center[2] ) * plane.Normal()[2] );
if ( d1 - d2 > 0.0f ) {
return d1 - d2;
}
if ( d1 + d2 < 0.0f ) {
return d1 + d2;
}
return 0.0f;
}
示例12: R_ChopWinding
/*
=============
R_ChopWinding
Clips a triangle from one buffer to another, setting edge flags
The returned buffer may be the same as inNum if no clipping is done
If entirely clipped away, clipTris[returned].numVerts == 0
I have some worries about edge flag cases when polygons are clipped
multiple times near the epsilon.
=============
*/
static int R_ChopWinding( clipTri_t clipTris[2], int inNum, const idPlane &plane ) {
clipTri_t *in, *out;
float dists[MAX_CLIPPED_POINTS];
int sides[MAX_CLIPPED_POINTS];
int counts[3];
float dot;
int i, j;
idVec3 *p1, *p2;
idVec3 mid;
in = &clipTris[inNum];
out = &clipTris[inNum^1];
counts[0] = counts[1] = counts[2] = 0;
// determine sides for each point
for ( i = 0 ; i < in->numVerts ; i++ ) {
dot = plane.Distance( in->verts[i] );
dists[i] = dot;
if ( dot < -LIGHT_CLIP_EPSILON ) {
sides[i] = SIDE_BACK;
} else if ( dot > LIGHT_CLIP_EPSILON ) {
sides[i] = SIDE_FRONT;
} else {
sides[i] = SIDE_ON;
}
counts[sides[i]]++;
}
// if none in front, it is completely clipped away
if ( !counts[SIDE_FRONT] ) {
in->numVerts = 0;
return inNum;
}
if ( !counts[SIDE_BACK] ) {
return inNum; // inout stays the same
}
// avoid wrapping checks by duplicating first value to end
sides[i] = sides[0];
dists[i] = dists[0];
in->verts[in->numVerts] = in->verts[0];
in->edgeFlags[in->numVerts] = in->edgeFlags[0];
out->numVerts = 0;
for ( i = 0 ; i < in->numVerts ; i++ ) {
p1 = &in->verts[i];
if ( sides[i] != SIDE_BACK ) {
out->verts[out->numVerts] = *p1;
if ( sides[i] == SIDE_ON && sides[i+1] == SIDE_BACK ) {
out->edgeFlags[out->numVerts] = 1;
} else {
out->edgeFlags[out->numVerts] = in->edgeFlags[i];
}
out->numVerts++;
}
if ( (sides[i] == SIDE_FRONT && sides[i+1] == SIDE_BACK)
|| (sides[i] == SIDE_BACK && sides[i+1] == SIDE_FRONT) ) {
// generate a split point
p2 = &in->verts[i+1];
dot = dists[i] / (dists[i]-dists[i+1]);
for ( j=0 ; j<3 ; j++ ) {
mid[j] = (*p1)[j] + dot*((*p2)[j]-(*p1)[j]);
}
out->verts[out->numVerts] = mid;
// set the edge flag
if ( sides[i+1] != SIDE_FRONT ) {
out->edgeFlags[out->numVerts] = 1;
} else {
out->edgeFlags[out->numVerts] = in->edgeFlags[i];
}
out->numVerts++;
}
}
return inNum ^ 1;
}
示例13: Split
/*
=================
idSurface::Split
=================
*/
int idSurface::Split( const idPlane &plane, const float epsilon, idSurface **front, idSurface **back, int *frontOnPlaneEdges, int *backOnPlaneEdges ) const {
float * dists;
float f;
byte * sides;
int counts[3];
int * edgeSplitVertex;
int numEdgeSplitVertexes;
int * vertexRemap[2];
int vertexIndexNum[2][2];
int * vertexCopyIndex[2];
int * indexPtr[2];
int indexNum[2];
int * index;
int * onPlaneEdges[2];
int numOnPlaneEdges[2];
int maxOnPlaneEdges;
int i;
idSurface * surface[2];
idDrawVert v;
dists = (float *) _alloca( verts.Num() * sizeof( float ) );
sides = (byte *) _alloca( verts.Num() * sizeof( byte ) );
counts[0] = counts[1] = counts[2] = 0;
// determine side for each vertex
for ( i = 0; i < verts.Num(); i++ ) {
dists[i] = f = plane.Distance( verts[i].xyz );
if ( f > epsilon ) {
sides[i] = SIDE_FRONT;
} else if ( f < -epsilon ) {
sides[i] = SIDE_BACK;
} else {
sides[i] = SIDE_ON;
}
counts[sides[i]]++;
}
*front = *back = NULL;
// if coplanar, put on the front side if the normals match
if ( !counts[SIDE_FRONT] && !counts[SIDE_BACK] ) {
f = ( verts[indexes[1]].xyz - verts[indexes[0]].xyz ).Cross( verts[indexes[0]].xyz - verts[indexes[2]].xyz ) * plane.Normal();
if ( FLOATSIGNBITSET( f ) ) {
*back = new idSurface( *this );
return SIDE_BACK;
} else {
*front = new idSurface( *this );
return SIDE_FRONT;
}
}
// if nothing at the front of the clipping plane
if ( !counts[SIDE_FRONT] ) {
*back = new idSurface( *this );
return SIDE_BACK;
}
// if nothing at the back of the clipping plane
if ( !counts[SIDE_BACK] ) {
*front = new idSurface( *this );
return SIDE_FRONT;
}
// allocate front and back surface
*front = surface[0] = new idSurface();
*back = surface[1] = new idSurface();
edgeSplitVertex = (int *) _alloca( edges.Num() * sizeof( int ) );
numEdgeSplitVertexes = 0;
maxOnPlaneEdges = 4 * counts[SIDE_ON];
counts[SIDE_FRONT] = counts[SIDE_BACK] = counts[SIDE_ON] = 0;
// split edges
for ( i = 0; i < edges.Num(); i++ ) {
int v0 = edges[i].verts[0];
int v1 = edges[i].verts[1];
int sidesOr = ( sides[v0] | sides[v1] );
// if both vertexes are on the same side or one is on the clipping plane
if ( !( sides[v0] ^ sides[v1] ) || ( sidesOr & SIDE_ON ) ) {
edgeSplitVertex[i] = -1;
counts[sidesOr & SIDE_BACK]++;
counts[SIDE_ON] += ( sidesOr & SIDE_ON ) >> 1;
} else {
示例14: Split
/*
============
idBrush::Split
============
*/
int idBrush::Split( const idPlane& plane, int planeNum, idBrush** front, idBrush** back ) const
{
int res, i, j;
idBrushSide* side, *frontSide, *backSide;
float dist, maxBack, maxFront, *maxBackWinding, *maxFrontWinding;
idWinding* w, *mid;
assert( windingsValid );
if( front )
{
*front = NULL;
}
if( back )
{
*back = NULL;
}
res = bounds.PlaneSide( plane, -BRUSH_EPSILON );
if( res == PLANESIDE_FRONT )
{
if( front )
{
*front = Copy();
}
return res;
}
if( res == PLANESIDE_BACK )
{
if( back )
{
*back = Copy();
}
return res;
}
maxBackWinding = ( float* ) _alloca16( sides.Num() * sizeof( float ) );
maxFrontWinding = ( float* ) _alloca16( sides.Num() * sizeof( float ) );
maxFront = maxBack = 0.0f;
for( i = 0; i < sides.Num(); i++ )
{
side = sides[i];
w = side->winding;
if( !w )
{
continue;
}
maxBackWinding[i] = 10.0f;
maxFrontWinding[i] = -10.0f;
for( j = 0; j < w->GetNumPoints(); j++ )
{
dist = plane.Distance( ( *w )[j].ToVec3() );
if( dist > maxFrontWinding[i] )
{
maxFrontWinding[i] = dist;
}
if( dist < maxBackWinding[i] )
{
maxBackWinding[i] = dist;
}
}
if( maxFrontWinding[i] > maxFront )
{
maxFront = maxFrontWinding[i];
}
if( maxBackWinding[i] < maxBack )
{
maxBack = maxBackWinding[i];
}
}
if( maxFront < BRUSH_EPSILON )
{
if( back )
{
*back = Copy();
}
return PLANESIDE_BACK;
}
if( maxBack > -BRUSH_EPSILON )
{
if( front )
{
*front = Copy();
}
return PLANESIDE_FRONT;
}
//.........这里部分代码省略.........
示例15: FloorEdgeSplitPoint
/*
============
idAASLocal::FloorEdgeSplitPoint
calculates either the closest or furthest point on the floor of the area which also lies on the pathPlane
the point has to be on the front side of the frontPlane to be valid
============
*/
bool idAASLocal::FloorEdgeSplitPoint( idVec3 &bestSplit, int areaNum, const idPlane &pathPlane, const idPlane &frontPlane, bool closest ) const {
int i, j, faceNum, edgeNum;
const aasArea_t *area;
const aasFace_t *face;
idVec3 split;
float dist, bestDist;
const aasEdge_t *edge;
idVec3 v1, v2;
float d1, d2;
area = &file->GetArea( areaNum );
if ( closest ) {
bestDist = maxWalkPathDistance;
for ( i = area->numFaces-1; i >= 0; i-- ) {
faceNum = file->GetFaceIndex( area->firstFace + i );
face = &file->GetFace( abs(faceNum) );
if ( !(face->flags & FACE_FLOOR ) ) {
continue;
}
for ( j = face->numEdges-1; j >= 0; j-- ) {
edgeNum = file->GetEdgeIndex( face->firstEdge + j );
edge = &file->GetEdge( abs( edgeNum ) );
v1 = file->GetVertex( edge->vertexNum[0] );
v2 = file->GetVertex( edge->vertexNum[1] );
d1 = v1 * pathPlane.Normal() - pathPlane.Dist();
d2 = v2 * pathPlane.Normal() - pathPlane.Dist();
//if ( (d1 < CM_CLIP_EPSILON && d2 < CM_CLIP_EPSILON) || (d1 > -CM_CLIP_EPSILON && d2 > -CM_CLIP_EPSILON) ) {
if ( FLOATSIGNBITSET( d1 ) == FLOATSIGNBITSET( d2 ) ) {
continue;
}
split = v1 + (d1 / (d1 - d2)) * (v2 - v1);
dist = frontPlane.Distance( split );
if ( dist >= -0.1f && dist < bestDist ) {
bestDist = dist;
bestSplit = split;
}
}
}
return ( bestDist < maxWalkPathDistance );
} else {
bestDist = -0.1f;
for ( i = area->numFaces-1; i >= 0; i-- ) {
faceNum = file->GetFaceIndex( area->firstFace + i );
face = &file->GetFace( abs(faceNum) );
if ( !(face->flags & FACE_FLOOR ) ) {
continue;
}
for ( j = face->numEdges-1; j >= 0; j-- ) {
edgeNum = file->GetEdgeIndex( face->firstEdge + j );
edge = &file->GetEdge( abs( edgeNum ) );
v1 = file->GetVertex( edge->vertexNum[0] );
v2 = file->GetVertex( edge->vertexNum[1] );
d1 = v1 * pathPlane.Normal() - pathPlane.Dist();
d2 = v2 * pathPlane.Normal() - pathPlane.Dist();
//if ( (d1 < CM_CLIP_EPSILON && d2 < CM_CLIP_EPSILON) || (d1 > -CM_CLIP_EPSILON && d2 > -CM_CLIP_EPSILON) ) {
if ( FLOATSIGNBITSET( d1 ) == FLOATSIGNBITSET( d2 ) ) {
continue;
}
split = v1 + (d1 / (d1 - d2)) * (v2 - v1);
dist = frontPlane.Distance( split );
if ( dist > bestDist ) {
bestDist = dist;
bestSplit = split;
}
}
}
return ( bestDist > -0.1f );
}
}