本文整理汇总了C++中idVec3::Cross方法的典型用法代码示例。如果您正苦于以下问题:C++ idVec3::Cross方法的具体用法?C++ idVec3::Cross怎么用?C++ idVec3::Cross使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类idVec3
的用法示例。
在下文中一共展示了idVec3::Cross方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DropShard
/*
================
idBrittleFracture::DropShard
================
*/
void idBrittleFracture::DropShard( shard_t* shard, const idVec3& point, const idVec3& dir, const float impulse, const int time )
{
int i, j, clipModelId;
float dist, f;
idVec3 dir2, origin;
idMat3 axis;
shard_t* neighbour;
// don't display decals on dropped shards
shard->decals.DeleteContents( true );
// remove neighbour pointers of neighbours pointing to this shard
for( i = 0; i < shard->neighbours.Num(); i++ )
{
neighbour = shard->neighbours[i];
for( j = 0; j < neighbour->neighbours.Num(); j++ )
{
if( neighbour->neighbours[j] == shard )
{
neighbour->neighbours.RemoveIndex( j );
break;
}
}
}
// remove neighbour pointers
shard->neighbours.Clear();
// remove the clip model from the static physics object
clipModelId = shard->clipModel->GetId();
physicsObj.SetClipModel( NULL, 1.0f, clipModelId, false );
origin = shard->clipModel->GetOrigin();
axis = shard->clipModel->GetAxis();
// set the dropped time for fading
shard->droppedTime = time;
dir2 = origin - point;
dist = dir2.Normalize();
f = dist > maxShatterRadius ? 1.0f : idMath::Sqrt( idMath::Fabs( dist - minShatterRadius ) ) * ( 1.0f / idMath::Sqrt( idMath::Fabs( maxShatterRadius - minShatterRadius ) ) );
// setup the physics
shard->physicsObj.SetSelf( this );
shard->physicsObj.SetClipModel( shard->clipModel, density );
shard->physicsObj.SetMass( shardMass );
shard->physicsObj.SetOrigin( origin );
shard->physicsObj.SetAxis( axis );
shard->physicsObj.SetBouncyness( bouncyness );
shard->physicsObj.SetFriction( 0.6f, 0.6f, friction );
shard->physicsObj.SetGravity( gameLocal.GetGravity() );
shard->physicsObj.SetContents( CONTENTS_RENDERMODEL );
shard->physicsObj.SetClipMask( MASK_SOLID | CONTENTS_MOVEABLECLIP );
shard->physicsObj.ApplyImpulse( 0, origin, impulse * linearVelocityScale * dir );
shard->physicsObj.SetAngularVelocity( dir.Cross( dir2 ) * ( f * angularVelocityScale ) );
shard->clipModel->SetId( clipModelId );
BecomeActive( TH_PHYSICS );
}
示例2: CollisionBetweenEdgeBounds
/*
================
idCollisionModelManagerLocal::CollisionBetweenEdgeBounds
verifies if the collision of two edges occurs between the edge bounds
also calculates the collision point and collision plane normal if the collision occurs between the bounds
================
*/
int idCollisionModelManagerLocal::CollisionBetweenEdgeBounds( cm_traceWork_t *tw, const idVec3 &va, const idVec3 &vb,
const idVec3 &vc, const idVec3 &vd, float tanHalfAngle,
idVec3 &collisionPoint, idVec3 &collisionNormal ) {
float d1, d2, d;
idVec3 at, bt, dir, dir1, dir2;
idPluecker pl1, pl2;
at = va;
bt = vb;
if ( tanHalfAngle != 0.0f ) {
CM_RotateEdge( at, bt, tw->origin, tw->axis, tanHalfAngle );
}
dir1 = (at - tw->origin).Cross( tw->axis );
dir2 = (bt - tw->origin).Cross( tw->axis );
if ( dir1 * dir1 > dir2 * dir2 ) {
dir = dir1;
}
else {
dir = dir2;
}
if ( tw->angle < 0.0f ) {
dir = -dir;
}
pl1.FromLine( at, bt );
pl2.FromRay( vc, dir );
d1 = pl1.PermutedInnerProduct( pl2 );
pl2.FromRay( vd, dir );
d2 = pl1.PermutedInnerProduct( pl2 );
if ( ( d1 > 0.0f && d2 > 0.0f ) || ( d1 < 0.0f && d2 < 0.0f ) ) {
return false;
}
pl1.FromLine( vc, vd );
pl2.FromRay( at, dir );
d1 = pl1.PermutedInnerProduct( pl2 );
pl2.FromRay( bt, dir );
d2 = pl1.PermutedInnerProduct( pl2 );
if ( ( d1 > 0.0f && d2 > 0.0f ) || ( d1 < 0.0f && d2 < 0.0f ) ) {
return false;
}
// collision point on the edge at-bt
dir1 = (vd - vc).Cross( dir );
d = dir1 * vc;
d1 = dir1 * at - d;
d2 = dir1 * bt - d;
if ( d1 == d2 ) {
return false;
}
collisionPoint = at + ( d1 / (d1 - d2) ) * ( bt - at );
// normal is cross product of the rotated edge va-vb and the edge vc-vd
collisionNormal.Cross( bt-at, vd-vc );
return true;
}
示例3: CM_RotateEdge
/*
================
CM_RotateEdge
rotates an edge about an arbitrary axis using the tangent of half the rotation angle
================
*/
void CM_RotateEdge( idVec3 &start, idVec3 &end, const idVec3 &origin, const idVec3 &axis, const float tanHalfAngle ) {
double d, t, s, c;
idVec3 proj, v1, v2;
// r = tan( a / 2 );
// sin(a) = 2*r/(1+r*r);
// cos(a) = (1-r*r)/(1+r*r);
t = tanHalfAngle * tanHalfAngle;
d = 1.0f / ( 1.0f + t );
s = 2.0f * tanHalfAngle * d;
c = ( 1.0f - t ) * d;
start -= origin;
proj = axis * ( start * axis );
v1 = start - proj;
v2 = axis.Cross( v1 );
start = v1 * c - v2 * s + proj + origin;
end -= origin;
proj = axis * ( end * axis );
v1 = end - proj;
v2 = axis.Cross( v1 );
end = v1 * c - v2 * s + proj + origin;
}
示例4: CM_RotatePoint
/*
================
CM_RotatePoint
rotates a point about an arbitrary axis using the tangent of half the rotation angle
================
*/
void CM_RotatePoint( idVec3 &point, const idVec3 &origin, const idVec3 &axis, const float tanHalfAngle ) {
double d, t, s, c;
idVec3 proj, v1, v2;
point -= origin;
proj = axis * ( point * axis );
v1 = point - proj;
v2 = axis.Cross( v1 );
// r = tan( a / 2 );
// sin(a) = 2*r/(1+r*r);
// cos(a) = (1-r*r)/(1+r*r);
t = tanHalfAngle * tanHalfAngle;
d = 1.0f / ( 1.0f + t );
s = 2.0f * tanHalfAngle * d;
c = ( 1.0f - t ) * d;
point = v1 * c - v2 * s + proj + origin;
}
示例5: DetermineIdealRotation
/*
================
hhCameraInterpolator::DetermineIdealRotation
================
*/
idQuat hhCameraInterpolator::DetermineIdealRotation( const idVec3& idealUpVector, const idVec3& viewDir, const idMat3& untransformedViewAxis ) {
idMat3 mat;
idVec3 newViewVector( viewDir );
newViewVector.ProjectOntoPlane( idealUpVector );
if( newViewVector.LengthSqr() < VECTOR_EPSILON ) {
newViewVector = -Sign( newViewVector * idealUpVector );
}
newViewVector.Normalize();
mat[0] = newViewVector;
mat[1] = idealUpVector.Cross( newViewVector );
mat[2] = idealUpVector;
mat = untransformedViewAxis.Transpose() * mat;
return mat.ToQuat();
}
示例6: CreateLookAtMatrix
fhRenderMatrix fhRenderMatrix::CreateLookAtMatrix( const idVec3& dir, const idVec3& up )
{
idVec3 zaxis = (dir * -1).Normalized();
idVec3 xaxis = up.Cross( zaxis ).Normalized();
idVec3 yaxis = zaxis.Cross( xaxis );
fhRenderMatrix m;
m[0] = xaxis.x;
m[1] = yaxis.x;
m[2] = zaxis.x;
m[4] = xaxis.y;
m[5] = yaxis.y;
m[6] = zaxis.y;
m[8] = xaxis.z;
m[9] = yaxis.z;
m[10] = zaxis.z;
return m;
}
示例7: R_SetLightProject
void R_SetLightProject(idPlane lightProject[4],
const idVec3 &origin,
const idVec3 &target,
idVec3 &right,
idVec3 &up,
const idVec3 &start,
const idVec3 &stop)
{
float dist;
float scale;
float rLen, uLen;
idVec3 normal;
float ofs;
idVec3 startGlobal;
idVec4 targetGlobal;
rLen = right.Normalize();
uLen = up.Normalize();
normal = up.Cross(right);
normal.Normalize();
dist = target * normal; // - (origin * normal);
if(dist < 0)
{
dist = -dist;
normal = -normal;
}
scale = (0.5f * dist) / rLen;
right *= scale;
scale = -(0.5f * dist) / uLen;
up *= scale;
lightProject[2] = normal;
lightProject[2][3] = -(origin * lightProject[2].Normal());
lightProject[0] = right;
lightProject[0][3] = -(origin * lightProject[0].Normal());
lightProject[1] = up;
lightProject[1][3] = -(origin * lightProject[1].Normal());
// now offset to center
targetGlobal.ToVec3() = target + origin;
targetGlobal[3] = 1;
ofs = 0.5f - (targetGlobal * lightProject[0].ToVec4()) / (targetGlobal * lightProject[2].ToVec4());
lightProject[0].ToVec4() += ofs * lightProject[2].ToVec4();
ofs = 0.5f - (targetGlobal * lightProject[1].ToVec4()) / (targetGlobal * lightProject[2].ToVec4());
lightProject[1].ToVec4() += ofs * lightProject[2].ToVec4();
// set the falloff vector
normal = stop - start;
dist = normal.Normalize();
if (dist <= 0)
{
dist = 1;
}
lightProject[3] = normal * (1.0f / dist);
startGlobal = start + origin;
lightProject[3][3] = -(startGlobal * lightProject[3].Normal());
}
示例8: Event_VecCrossProduct
/*
================
idThread::Event_VecCrossProduct
================
*/
void idThread::Event_VecCrossProduct( idVec3 &vec1, idVec3 &vec2 ) {
ReturnVector( vec1.Cross( vec2 ) );
}
示例9: R_PreciseCullSurface
/*
=========================
R_PreciseCullSurface
Check the surface for visibility on a per-triangle basis
for cases when it is going to be VERY expensive to draw (subviews)
If not culled, also returns the bounding box of the surface in
Normalized Device Coordinates, so it can be used to crop the scissor rect.
OPTIMIZE: we could also take exact portal passing into consideration
=========================
*/
bool R_PreciseCullSurface( const drawSurf_t* drawSurf, idBounds& ndcBounds )
{
const srfTriangles_t* tri = drawSurf->frontEndGeo;
unsigned int pointOr = 0;
unsigned int pointAnd = ( unsigned int )~0;
// get an exact bounds of the triangles for scissor cropping
ndcBounds.Clear();
const idJointMat* joints = ( tri->staticModelWithJoints != NULL && r_useGPUSkinning.GetBool() ) ? tri->staticModelWithJoints->jointsInverted : NULL;
for( int i = 0; i < tri->numVerts; i++ )
{
const idVec3 vXYZ = idDrawVert::GetSkinnedDrawVertPosition( tri->verts[i], joints );
idPlane eye, clip;
R_TransformModelToClip( vXYZ, drawSurf->space->modelViewMatrix, tr.viewDef->projectionMatrix, eye, clip );
unsigned int pointFlags = 0;
for( int j = 0; j < 3; j++ )
{
if( clip[j] >= clip[3] )
{
pointFlags |= ( 1 << ( j * 2 + 0 ) );
}
else if( clip[j] <= -clip[3] ) // FIXME: the D3D near clip plane is at zero instead of -1
{
pointFlags |= ( 1 << ( j * 2 + 1 ) );
}
}
pointAnd &= pointFlags;
pointOr |= pointFlags;
}
// trivially reject
if( pointAnd != 0 )
{
return true;
}
// backface and frustum cull
idVec3 localViewOrigin;
R_GlobalPointToLocal( drawSurf->space->modelMatrix, tr.viewDef->renderView.vieworg, localViewOrigin );
for( int i = 0; i < tri->numIndexes; i += 3 )
{
const idVec3 v1 = idDrawVert::GetSkinnedDrawVertPosition( tri->verts[ tri->indexes[ i + 0 ] ], joints );
const idVec3 v2 = idDrawVert::GetSkinnedDrawVertPosition( tri->verts[ tri->indexes[ i + 1 ] ], joints );
const idVec3 v3 = idDrawVert::GetSkinnedDrawVertPosition( tri->verts[ tri->indexes[ i + 2 ] ], joints );
// this is a hack, because R_GlobalPointToLocal doesn't work with the non-normalized
// axis that we get from the gui view transform. It doesn't hurt anything, because
// we know that all gui generated surfaces are front facing
if( tr.guiRecursionLevel == 0 )
{
// we don't care that it isn't normalized,
// all we want is the sign
const idVec3 d1 = v2 - v1;
const idVec3 d2 = v3 - v1;
const idVec3 normal = d2.Cross( d1 );
const idVec3 dir = v1 - localViewOrigin;
const float dot = normal * dir;
if( dot >= 0.0f )
{
return true;
}
}
// now find the exact screen bounds of the clipped triangle
idFixedWinding w;
w.SetNumPoints( 3 );
R_LocalPointToGlobal( drawSurf->space->modelMatrix, v1, w[0].ToVec3() );
R_LocalPointToGlobal( drawSurf->space->modelMatrix, v2, w[1].ToVec3() );
R_LocalPointToGlobal( drawSurf->space->modelMatrix, v3, w[2].ToVec3() );
w[0].s = w[0].t = w[1].s = w[1].t = w[2].s = w[2].t = 0.0f;
for( int j = 0; j < 4; j++ )
{
if( !w.ClipInPlace( -tr.viewDef->frustums[FRUSTUM_PRIMARY][j], 0.1f ) )
{
break;
}
}
//.........这里部分代码省略.........