本文整理汇总了C++中VectorInverse函数的典型用法代码示例。如果您正苦于以下问题:C++ VectorInverse函数的具体用法?C++ VectorInverse怎么用?C++ VectorInverse使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了VectorInverse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: G_InvulnerabilityEffect
/*
================
G_InvulnerabilityEffect
================
*/
int G_InvulnerabilityEffect(gentity_t * targ, vec3_t dir, vec3_t point, vec3_t impactpoint, vec3_t bouncedir)
{
gentity_t *impact;
vec3_t intersections[2], vec;
int n;
if(!targ->client)
{
return qfalse;
}
VectorCopy(dir, vec);
VectorInverse(vec);
// sphere model radius = 42 units
n = RaySphereIntersections(targ->client->ps.origin, 42, point, vec, intersections);
if(n > 0)
{
impact = G_TempEntity(targ->client->ps.origin, EV_INVUL_IMPACT);
VectorSubtract(intersections[0], targ->client->ps.origin, vec);
VectorToAngles(vec, impact->s.angles);
impact->s.angles[0] += 90;
if(impact->s.angles[0] > 360)
impact->s.angles[0] -= 360;
if(impactpoint)
{
VectorCopy(intersections[0], impactpoint);
}
if(bouncedir)
{
VectorCopy(vec, bouncedir);
VectorNormalize(bouncedir);
}
return qtrue;
}
else
{
return qfalse;
}
}
示例2: CG_MissileHitEntity
/*
=================
CG_MissileHitEntity
=================
*/
void CG_MissileHitEntity( weapon_t weaponNum, weaponMode_t weaponMode,
vec3_t origin, vec3_t dir, int entityNum, int charge )
{
vec3_t normal;
weaponInfo_t *weapon = &cg_weapons[ weaponNum ];
VectorCopy( dir, normal );
VectorInverse( normal );
CG_Bleed( origin, normal, entityNum );
if( weaponMode <= WPM_NONE || weaponMode >= WPM_NUM_WEAPONMODES )
weaponMode = WPM_PRIMARY;
// always impact!
//if( weapon->wim[ weaponMode ].alwaysImpact )
{
int sound;
if( cg_entities[ entityNum ].currentState.eType == ET_PLAYER )
{
// Players
sound = IMPACTSOUND_FLESH;
}
else if( cg_entities[ entityNum ].currentState.eType == ET_BUILDABLE &&
BG_Buildable( cg_entities[ entityNum ].currentState.modelindex, NULL )->team == TEAM_ALIENS )
{
// Alien buildables
sound = IMPACTSOUND_FLESH;
}
else
sound = IMPACTSOUND_DEFAULT;
CG_MissileHitWall( weaponNum, weaponMode, 0, origin, dir, sound, charge );
}
}
示例3: R_TraceAgainstSurface
/*
* R_TraceAgainstSurface
*/
static bool R_TraceAgainstSurface( msurface_t *surf ) {
int i;
mesh_t *mesh = &surf->mesh;
elem_t *elem = mesh->elems;
vec4_t *verts = mesh->xyzArray;
float old_frac = trace_fraction;
bool isPlanar = ( surf->facetype == FACETYPE_PLANAR ) ? true : false;
// clip each triangle individually
for( i = 0; i < mesh->numElems; i += 3, elem += 3 ) {
R_TraceAgainstTriangle( verts[elem[0]], verts[elem[1]], verts[elem[2]] );
if( old_frac > trace_fraction ) {
// flip normal is we are on the backside (does it really happen?)...
if( isPlanar ) {
if( DotProduct( trace_plane.normal, surf->plane ) < 0 ) {
VectorInverse( trace_plane.normal );
}
}
return true;
}
}
return false;
}
示例4: R_AliasSetUpTransform
/*
================
R_AliasSetUpTransform
================
*/
void R_AliasSetUpTransform(int trivial_accept)
{
int i;
float rotationmatrix[3][4], t2matrix[3][4];
static float tmatrix[3][4];
static float viewmatrix[3][4];
vec3_t angles;
// TODO: should really be stored with the entity instead of being reconstructed
// TODO: should use a look-up table
// TODO: could cache lazily, stored in the entity
angles[ROLL] = currententity->angles[ROLL];
angles[PITCH] = -currententity->angles[PITCH];
angles[YAW] = currententity->angles[YAW];
AngleVectors(angles, alias_forward, alias_right, alias_up);
tmatrix[0][0] = pmdl->scale[0];
tmatrix[1][1] = pmdl->scale[1];
tmatrix[2][2] = pmdl->scale[2];
tmatrix[0][3] = pmdl->scale_origin[0];
tmatrix[1][3] = pmdl->scale_origin[1];
tmatrix[2][3] = pmdl->scale_origin[2];
// TODO: can do this with simple matrix rearrangement
for (i=0 ; i<3 ; i++)
{
t2matrix[i][0] = alias_forward[i];
t2matrix[i][1] = -alias_right[i];
t2matrix[i][2] = alias_up[i];
}
t2matrix[0][3] = -modelorg[0];
t2matrix[1][3] = -modelorg[1];
t2matrix[2][3] = -modelorg[2];
// FIXME: can do more efficiently than full concatenation
R_ConcatTransforms(t2matrix, tmatrix, rotationmatrix);
// TODO: should be global, set when vright, etc., set
VectorCopy(vright, viewmatrix[0]);
VectorCopy(vup, viewmatrix[1]);
VectorInverse(viewmatrix[1]);
VectorCopy(vpn, viewmatrix[2]);
// viewmatrix[0][3] = 0;
// viewmatrix[1][3] = 0;
// viewmatrix[2][3] = 0;
R_ConcatTransforms(viewmatrix, rotationmatrix, aliastransform);
// do the scaling up of x and y to screen coordinates as part of the transform
// for the unclipped case (it would mess up clipping in the clipped case).
// Also scale down z, so 1/z is scaled 31 bits for free, and scale down x and y
// correspondingly so the projected x and y come out right
// FIXME: make this work for clipped case too?
if (trivial_accept)
{
for (i=0 ; i<4 ; i++)
{
aliastransform[0][i] *= aliasxscale *
(1.0 / ((float)0x8000 * 0x10000));
aliastransform[1][i] *= aliasyscale *
(1.0 / ((float)0x8000 * 0x10000));
aliastransform[2][i] *= 1.0 / ((float)0x8000 * 0x10000);
}
}
}
示例5: VectorCopy
//.........这里部分代码省略.........
// NOTE: Because we need to interpolate multiplayer characters, the interpolation time limit
// was increased to 1.0 s., which is 2x the max lag we are accounting for.
if ( ( m_clTime < m_pCurrentEntity->curstate.animtime + 1.0f ) &&
( m_pCurrentEntity->curstate.animtime != m_pCurrentEntity->latched.prevanimtime ) )
{
f = (m_clTime - m_pCurrentEntity->curstate.animtime) / (m_pCurrentEntity->curstate.animtime - m_pCurrentEntity->latched.prevanimtime);
//Con_DPrintf("%4.2f %.2f %.2f\n", f, m_pCurrentEntity->curstate.animtime, m_clTime);
}
if (m_fDoInterp)
{
// ugly hack to interpolate angle, position. current is reached 0.1 seconds after being set
f = f - 1.0;
}
else
{
f = 0;
}
for (i = 0; i < 3; i++)
{
modelpos[i] += (m_pCurrentEntity->origin[i] - m_pCurrentEntity->latched.prevorigin[i]) * f;
}
// NOTE: Because multiplayer lag can be relatively large, we don't want to cap
// f at 1.5 anymore.
//if (f > -1.0 && f < 1.5) {}
// Con_DPrintf("%.0f %.0f\n",m_pCurrentEntity->msg_angles[0][YAW], m_pCurrentEntity->msg_angles[1][YAW] );
for (i = 0; i < 3; i++)
{
float ang1, ang2;
ang1 = m_pCurrentEntity->angles[i];
ang2 = m_pCurrentEntity->latched.prevangles[i];
d = ang1 - ang2;
if (d > 180)
{
d -= 360;
}
else if (d < -180)
{
d += 360;
}
angles[i] += d * f;
}
//Con_DPrintf("%.3f \n", f );
}
else if ( m_pCurrentEntity->curstate.movetype != MOVETYPE_NONE )
{
VectorCopy( m_pCurrentEntity->angles, angles );
}
//Con_DPrintf("%.0f %0.f %0.f\n", modelpos[0], modelpos[1], modelpos[2] );
//Con_DPrintf("%.0f %0.f %0.f\n", angles[0], angles[1], angles[2] );
angles[PITCH] = -angles[PITCH];
AngleMatrix (angles, (*m_protationmatrix));
if ( !IEngineStudio.IsHardware() )
{
static float viewmatrix[3][4];
VectorCopy (m_vRight, viewmatrix[0]);
VectorCopy (m_vUp, viewmatrix[1]);
VectorInverse (viewmatrix[1]);
VectorCopy (m_vNormal, viewmatrix[2]);
(*m_protationmatrix)[0][3] = modelpos[0] - m_vRenderOrigin[0];
(*m_protationmatrix)[1][3] = modelpos[1] - m_vRenderOrigin[1];
(*m_protationmatrix)[2][3] = modelpos[2] - m_vRenderOrigin[2];
ConcatTransforms (viewmatrix, (*m_protationmatrix), (*m_paliastransform));
// do the scaling up of x and y to screen coordinates as part of the transform
// for the unclipped case (it would mess up clipping in the clipped case).
// Also scale down z, so 1/z is scaled 31 bits for free, and scale down x and y
// correspondingly so the projected x and y come out right
// FIXME: make this work for clipped case too?
if (trivial_accept)
{
for (i=0 ; i<4 ; i++)
{
(*m_paliastransform)[0][i] *= m_fSoftwareXScale *
(1.0 / (ZISCALE * 0x10000));
(*m_paliastransform)[1][i] *= m_fSoftwareYScale *
(1.0 / (ZISCALE * 0x10000));
(*m_paliastransform)[2][i] *= 1.0 / (ZISCALE * 0x10000);
}
}
}
(*m_protationmatrix)[0][3] = modelpos[0];
(*m_protationmatrix)[1][3] = modelpos[1];
(*m_protationmatrix)[2][3] = modelpos[2];
}
示例6: AAS_FindBestAreaSplitPlane
//===========================================================================
//
// Parameter: -
// Returns: -
// Changes Globals: -
//===========================================================================
int AAS_FindBestAreaSplitPlane( tmp_area_t *tmparea, vec3_t normal, float *dist ) {
int side1, side2;
int foundsplitter, facesplits, groundsplits, epsilonfaces, bestepsilonfaces;
float bestvalue, value;
tmp_face_t *face1, *face2;
vec3_t tmpnormal, invgravity;
float tmpdist;
vec3_t points[4];
//get inverse of gravity direction
VectorCopy( cfg.phys_gravitydirection, invgravity );
VectorInverse( invgravity );
foundsplitter = false;
bestvalue = -999999;
bestepsilonfaces = 0;
//
#ifdef AW_DEBUG
Log_Print( "finding split plane for area %d\n", tmparea->areanum );
#endif //AW_DEBUG
for ( face1 = tmparea->tmpfaces; face1; face1 = face1->next[side1] ) {
//side of the face the area is on
side1 = face1->frontarea != tmparea;
if ( WindingIsTiny( face1->winding ) ) {
Log_Write( "gsubdiv: area %d has a tiny winding\r\n", tmparea->areanum );
continue;
}
//if the face isn't a gap or ground there's no split edge
if ( !( face1->faceflags & FACE_GROUND ) && !AAS_GapFace( face1, side1 ) ) {
continue;
}
for ( face2 = face1->next[side1]; face2; face2 = face2->next[side2] ) {
//side of the face the area is on
side2 = face2->frontarea != tmparea;
if ( WindingIsTiny( face1->winding ) ) {
Log_Write( "gsubdiv: area %d has a tiny winding\r\n", tmparea->areanum );
continue;
}
//if the face isn't a gap or ground there's no split edge
if ( !( face2->faceflags & FACE_GROUND ) && !AAS_GapFace( face2, side2 ) ) {
continue;
}
//only split between gaps and ground
if ( !( ( ( face1->faceflags & FACE_GROUND ) && AAS_GapFace( face2, side2 ) ) || ( ( face2->faceflags & FACE_GROUND ) && AAS_GapFace( face1, side1 ) ) ) ) {
continue;
}
//find a plane seperating the windings of the faces
if ( !FindPlaneSeperatingWindings( face1->winding, face2->winding, invgravity, tmpnormal, &tmpdist, points ) ) {
continue;
}
#ifdef AW_DEBUG
Log_Print( "normal = \'%f %f %f\', dist = %f\n", tmpnormal[0], tmpnormal[1], tmpnormal[2], tmpdist );
#endif //AW_DEBUG
//get metrics for this vertical plane
if ( !AAS_TestSplitPlane( tmparea, tmpnormal, tmpdist, &facesplits, &groundsplits, &epsilonfaces, points ) ) {
continue;
} //end if
#ifdef AW_DEBUG
Log_Print( "face splits = %d\nground splits = %d\n", facesplits, groundsplits );
#endif //AW_DEBUG
value = 100 - facesplits - 2 * groundsplits;
//avoid epsilon faces
value += epsilonfaces * -1000;
if ( value > bestvalue ) {
VectorCopy( tmpnormal, normal );
*dist = tmpdist;
bestvalue = value;
bestepsilonfaces = epsilonfaces;
foundsplitter = true;
}
}
}
if ( bestepsilonfaces ) {
Log_Write( "found %d epsilon faces trying to split area %d\r\n", epsilonfaces, tmparea->areanum );
}
return foundsplitter;
} //end of the function AAS_FindBestAreaSplitPlane
示例7: CG_AddClientCritter
//.........这里部分代码省略.........
// make sure we are not heading away from the enemy too much
VectorNormalize2( le->pos.trDelta, v2 );
if (DotProduct( v, v2 ) > 0.7) {
// avoid world geometry
backup = *le;
le->bounceFactor = (1.0 - trace.fraction)*10.0*(float)step/1000.0; // tracking and avoidance factor
// reflect the velocity on the trace plane
VectorMA( le->pos.trDelta, le->bounceFactor*oldSpeed, trace.plane.normal, le->pos.trDelta );
if (VectorLength(le->pos.trDelta) < 1) {
CG_FreeLocalEntity( le );
return;
}
// the intersection is a fraction of the frametime
le->pos.trTime = time;
VectorCopy( le->refEntity.origin, le->pos.trBase );
VectorNormalize( le->pos.trDelta );
VectorScale( le->pos.trDelta, oldSpeed, le->pos.trDelta );
//
// double check end velocity
VectorNormalize2( le->pos.trDelta, v2 );
if (DotProduct( v, v2 ) <= 0.2) {
// restore
*le = backup;
}
}
}
}
}
// set the angles
VectorNormalize2( le->pos.trDelta, v );
// HACK!!! skull model is back-to-front, need to fix
if (le->leType == LE_ZOMBIE_SPIRIT)
VectorInverse( v );
vectoangles( v, ang );
AnglesToAxis( ang, le->refEntity.axis );
// lean when turning
if (le->leType == LE_ZOMBIE_BAT) {
VectorSubtract( le->pos.trDelta, oDelta, v2 );
ang[ROLL] = -5.0 * DotProduct( le->refEntity.axis[1], v2 );
if (fabs(ang[ROLL]) > 80) {
if (ang[ROLL] > 80) ang[ROLL] = 80;
else ang[ROLL] = -80;
}
}
AnglesToAxis( ang, le->refEntity.axis );
// HACK: the skull is slightly higher than the origin
if (le->leType == LE_ZOMBIE_SPIRIT) {
// set the size scale
for (i=0; i<3; i++)
VectorScale( le->refEntity.axis[i], 0.35, le->refEntity.axis[i] );
VectorMA( le->refEntity.origin, -10, le->refEntity.axis[2], le->refEntity.origin );
}
le->lastTrailTime = time;
time += step;
}
// Bats, set the frame
if (le->leType == LE_ZOMBIE_BAT) {
#define BAT_ANIM_FRAMETIME 30
le->refEntity.frame = (cg.time/BAT_ANIM_FRAMETIME+1)%19;
le->refEntity.oldframe = (cg.time/BAT_ANIM_FRAMETIME)%19;
le->refEntity.backlerp = 1.0 - ((float)(cg.time%BAT_ANIM_FRAMETIME)/(float)BAT_ANIM_FRAMETIME);
}
示例8: R_DrawSprite
/*
** R_DrawSprite
**
** Draw currententity / currentmodel as a single texture
** mapped polygon
*/
void R_DrawSprite (void)
{
vec5_t *pverts;
vec3_t left, up, right, down;
dsprite_t *s_psprite;
dsprframe_t *s_psprframe;
s_psprite = (dsprite_t *)currentmodel->extradata;
#if 0
if (currententity->frame >= s_psprite->numframes
|| currententity->frame < 0)
{
Com_Printf ("No such sprite frame %i\n",
currententity->frame);
currententity->frame = 0;
}
#endif
currententity->frame %= s_psprite->numframes;
s_psprframe = &s_psprite->frames[currententity->frame];
r_polydesc.pixels = currentmodel->skins[currententity->frame]->pixels[0];
r_polydesc.pixel_width = s_psprframe->width;
r_polydesc.pixel_height = s_psprframe->height;
r_polydesc.dist = 0;
// generate the sprite's axes, completely parallel to the viewplane.
VectorCopy (vup, r_polydesc.vup);
VectorCopy (vright, r_polydesc.vright);
VectorCopy (vpn, r_polydesc.vpn);
// build the sprite poster in worldspace
VectorScale (r_polydesc.vright,
s_psprframe->width - s_psprframe->origin_x, right);
VectorScale (r_polydesc.vup,
s_psprframe->height - s_psprframe->origin_y, up);
VectorScale (r_polydesc.vright,
-s_psprframe->origin_x, left);
VectorScale (r_polydesc.vup,
-s_psprframe->origin_y, down);
// invert UP vector for sprites
VectorInverse( r_polydesc.vup );
pverts = r_clip_verts[0];
pverts[0][0] = r_entorigin[0] + up[0] + left[0];
pverts[0][1] = r_entorigin[1] + up[1] + left[1];
pverts[0][2] = r_entorigin[2] + up[2] + left[2];
pverts[0][3] = 0;
pverts[0][4] = 0;
pverts[1][0] = r_entorigin[0] + up[0] + right[0];
pverts[1][1] = r_entorigin[1] + up[1] + right[1];
pverts[1][2] = r_entorigin[2] + up[2] + right[2];
pverts[1][3] = s_psprframe->width;
pverts[1][4] = 0;
pverts[2][0] = r_entorigin[0] + down[0] + right[0];
pverts[2][1] = r_entorigin[1] + down[1] + right[1];
pverts[2][2] = r_entorigin[2] + down[2] + right[2];
pverts[2][3] = s_psprframe->width;
pverts[2][4] = s_psprframe->height;
pverts[3][0] = r_entorigin[0] + down[0] + left[0];
pverts[3][1] = r_entorigin[1] + down[1] + left[1];
pverts[3][2] = r_entorigin[2] + down[2] + left[2];
pverts[3][3] = 0;
pverts[3][4] = s_psprframe->height;
r_polydesc.nump = 4;
r_polydesc.s_offset = ( r_polydesc.pixel_width >> 1);
r_polydesc.t_offset = ( r_polydesc.pixel_height >> 1);
VectorCopy( modelorg, r_polydesc.viewer_position );
r_polydesc.stipple_parity = 1;
if ( currententity->flags & RF_TRANSLUCENT )
R_ClipAndDrawPoly ( currententity->alpha, false, true );
else
R_ClipAndDrawPoly ( 1.0F, false, true );
r_polydesc.stipple_parity = 0;
}
示例9: R_PlantGrass
static void R_PlantGrass (Clump& clump)
{
if (clumpTriangleCount + TRIS_PER_CLUMP >= MAX_CLUMP_TRIS) {
clump.firstTriangle = clumpTriangleCount;
clump.numTriangles = 0;
return;
}
clump.firstTriangle = clumpTriangleCount;
clump.numTriangles = 0; /* safeguard */
vec3_t rot[3]; /* rotation matrix for the plant */
#define xt (rot[0])
#define yt (rot[1])
#define zt (rot[2])
#if 0
/* horisontal planting */
VectorSet(xt, 1, 0, 0);
VectorSet(zt, 0, 0, 1);
#else
/* normal-based planting */
/* we can calculate the downslope vector and use it instead;
* a bit more of math, but call allow us to create plants that interact with the slope in various ways */
VectorCopy(clump.normal, zt);
VectorSet(xt, zt[2], 0.0, -zt[0]); /* short-circuit CrossProduct(yaxis, normal, xt) since it degenerates to a simple shuffle */
VectorNormalizeFast(xt);
#endif
/* generate geometry */
#if 0
/* prebuilt mesh or debug grass marker */
/* randomly rotate plant around the base */
RotatePointAroundVector(yt, zt, xt, frand() * 360);
CrossProduct(yt, zt, xt);
/* randomly mirror the plant, too */
if (rand() & 1)
VectorInverse(yt);
/* marker */
vec_t* ptr = gfv_pos[clumpTriangleCount * 3];
VectorMA(clump.position, 1, zt, ptr);
VectorMA(ptr, 16, yt, ptr + 3);
VectorMA(ptr, 16, xt, ptr + 6);
vec_t* texc = gfv_texcoord[clumpTriangleCount * 3];
Vector2Set(texc, 0, 0);
Vector2Set(texc + 2, 1, 0);
Vector2Set(texc + 4, 0, 1);
clumpTriangleCount++;
#else
/* programmatically generated clump */
CrossProduct(zt, xt, yt);
for (int i = 0; i < TRIS_PER_CLUMP; i += 2) {
vec3_t sdir, tdir;
vec2_t sprrot;
vec3_t tmp;
sprrot[0] = frand() * 360;
sprrot[1] = frand() * 60 + 15;
PolarToVec(sprrot, tmp);
VectorRotate(rot, tmp, tdir);
sprrot[0] += 90;
sprrot[1] = 0;
PolarToVec(sprrot, tmp);
VectorRotate(rot, tmp, sdir);
#if 0
/* debug marker */
vec_t* ptr = gfv_pos[clumpTriangleCount * 3];
VectorCopy(clump.position, ptr);
VectorMA(ptr, 16, sdir, ptr + 3);
VectorMA(ptr, 16, tdir, ptr + 6);
vec_t* texc = gfv_texcoord[clumpTriangleCount * 3];
Vector2Set(texc, 0, 0);
Vector2Set(texc + 2, 1, 0);
Vector2Set(texc + 4, 0, 1);
clumpTriangleCount++;
#else
/* billboard sprite */
vec_t* ptr = gfv_pos[clumpTriangleCount * 3];
VectorCopy(clump.position, ptr);
/** @todo use UNIT_SIZE and co defines here */
VectorMA(clump.position, -24, sdir, ptr); /* quad vertex 0 */
VectorMA(ptr, 32, tdir, ptr + 3); /* quad vertex 1 */
VectorMA(ptr + 3, 48, sdir, ptr + 6); /* quad vertex 2 */
VectorCopy(ptr, ptr + 9); /* quad vertex 0 */
VectorCopy(ptr + 6, ptr + 12); /* quad vertex 2 */
VectorMA(ptr + 6, -32, tdir, ptr + 15); /* quad vertex 3 */
vec_t* texc = gfv_texcoord[clumpTriangleCount * 3];
//.........这里部分代码省略.........
示例10: R_MarkFragments
int R_MarkFragments( int numPoints, const vec3_t* points, const vec3_t projection,
int maxPoints, vec3_t pointBuffer, int maxFragments, markFragment_t* fragmentBuffer ) {
//increment view count for double check prevention
tr.viewCount++;
vec3_t projectionDir;
VectorNormalize2( projection, projectionDir );
// find all the brushes that are to be considered
vec3_t mins, maxs;
ClearBounds( mins, maxs );
for ( int i = 0; i < numPoints; i++ ) {
AddPointToBounds( points[ i ], mins, maxs );
vec3_t temp;
VectorAdd( points[ i ], projection, temp );
AddPointToBounds( temp, mins, maxs );
// make sure we get all the leafs (also the one(s) in front of the hit surface)
VectorMA( points[ i ], -20, projectionDir, temp );
AddPointToBounds( temp, mins, maxs );
}
if ( numPoints > MAX_VERTS_ON_POLY ) {
numPoints = MAX_VERTS_ON_POLY;
}
// create the bounding planes for the to be projected polygon
vec3_t normals[ MAX_VERTS_ON_POLY + 2 ];
float dists[ MAX_VERTS_ON_POLY + 2 ];
for ( int i = 0; i < numPoints; i++ ) {
vec3_t v1, v2;
VectorSubtract( points[ ( i + 1 ) % numPoints ], points[ i ], v1 );
VectorAdd( points[ i ], projection, v2 );
VectorSubtract( points[ i ], v2, v2 );
CrossProduct( v1, v2, normals[ i ] );
VectorNormalizeFast( normals[ i ] );
dists[ i ] = DotProduct( normals[ i ], points[ i ] );
}
// add near and far clipping planes for projection
VectorCopy( projectionDir, normals[ numPoints ] );
dists[ numPoints ] = DotProduct( normals[ numPoints ], points[ 0 ] ) - 32;
VectorCopy( projectionDir, normals[ numPoints + 1 ] );
VectorInverse( normals[ numPoints + 1 ] );
dists[ numPoints + 1 ] = DotProduct( normals[ numPoints + 1 ], points[ 0 ] ) - 20;
int numPlanes = numPoints + 2;
int numsurfaces = 0;
idWorldSurface* surfaces[ 64 ];
R_BoxSurfaces_r( tr.world->nodes, mins, maxs, surfaces, 64, &numsurfaces, projectionDir );
//assert(numsurfaces <= 64);
//assert(numsurfaces != 64);
int returnedPoints = 0;
int returnedFragments = 0;
for ( int i = 0; i < numsurfaces; i++ ) {
surfaces[ i ]->MarkFragments( projectionDir,
numPlanes, normals, dists,
maxPoints, pointBuffer,
maxFragments, fragmentBuffer,
&returnedPoints, &returnedFragments, mins, maxs );
if ( returnedFragments == maxFragments ) {
break; // not enough space for more fragments
}
}
return returnedFragments;
}
示例11: if
//.........这里部分代码省略.........
infox += INFO_WIDTH * flPercent;
}
}
// Done sliding and radar is off, disable
if(!m_blRadar && !m_blSliding)
{ return 1;
}
// Draw Radar
SPR_Set(gHUD.GetSprite(m_HUD_radar), 255, 255, 255);
SPR_DrawHoles(0, x,y, &gHUD.GetSpriteRect(m_HUD_radar));
// Draw info box
SPR_Set(gHUD.GetSprite(m_HUD_radar_info), 255,255,255);
SPR_DrawHoles(0, infox,infoy, &gHUD.GetSpriteRect(m_HUD_radar_info));
if(m_blSliding)
m_iyBottomRadar = y + iRadarHeight;
else
m_iyBottomRadar = infoy + infoheight;
// Sliding or radar is just off, dont display information
if(m_blSliding || !m_blRadar)
{ return 1;
}
/*
* Get Player Angles
*/
// Setting player angles
gEngfuncs.GetViewAngles((float *)vecViewAngles);
AngleVectors(vecViewAngles, NULL, v_right, NULL );
// Inverse vector
VectorInverse(v_right);
v_right.z = 0;
// Get angles
VectorAngles(v_right,vecAngles);
flPlayerAngles = vecAngles.y;
// strictly 0 to 360
if(flPlayerAngles < 0)
flPlayerAngles += 360;
// Move x and y to the middle of the radar
x += OFFSET_RAD_WIDTH;
y += OFFSET_RAD_HEIGHT;
/*
* Loop and draw dots
*/
for(int i=0; i<MAX_PLAYERS; i++)
{ int r=255,g=255,b=255;
bool blDrawInfo = false;
cl_entity_t *pPlayer = gEngfuncs.GetEntityByIndex(i);
// Invalid
if(!pPlayer)
{ continue;
}
// Not player
if(!pPlayer->player)
{ continue;
}
// Render check, make sure player is being rendered
示例12: CG_BuildableHealthBar
/*
==================
CG_BuildableHealthBar
==================
*/
static void CG_BuildableHealthBar( centity_t *cent )
{
vec3_t origin, origin2, down, right, back, downLength, rightLength;
float rimWidth = HEALTH_BAR_HEIGHT / 15.0f;
float doneWidth, leftWidth, progress;
int health;
qhandle_t shader;
entityState_t *es;
vec3_t mins, maxs;
es = ¢->currentState;
health = es->generic1 & ~( B_POWERED_TOGGLEBIT | B_DCCED_TOGGLEBIT | B_SPAWNED_TOGGLEBIT );
progress = (float)health / B_HEALTH_SCALE;
if( progress < 0.0f )
progress = 0.0f;
else if( progress > 1.0f )
progress = 1.0f;
if( progress < 0.33f )
shader = cgs.media.redBuildShader;
else
shader = cgs.media.greenBuildShader;
doneWidth = ( HEALTH_BAR_WIDTH - 2 * rimWidth ) * progress;
leftWidth = ( HEALTH_BAR_WIDTH - 2 * rimWidth ) - doneWidth;
VectorCopy( cg.refdef.viewaxis[ 2 ], down );
VectorInverse( down );
VectorCopy( cg.refdef.viewaxis[ 1 ], right );
VectorInverse( right );
VectorSubtract( cg.refdef.vieworg, cent->lerpOrigin, back );
VectorNormalize( back );
VectorCopy( cent->lerpOrigin, origin );
BG_FindBBoxForBuildable( es->modelindex, mins, maxs );
VectorMA( origin, 48.0f, es->origin2, origin );
VectorMA( origin, -HEALTH_BAR_WIDTH / 2.0f, right, origin );
VectorMA( origin, maxs[ 0 ] + 8.0f, back, origin );
VectorCopy( origin, origin2 );
VectorScale( right, rimWidth + doneWidth, rightLength );
VectorScale( down, HEALTH_BAR_HEIGHT, downLength );
CG_DrawPlane( origin2, downLength, rightLength, shader );
VectorMA( origin, rimWidth + doneWidth, right, origin2 );
VectorScale( right, leftWidth, rightLength );
VectorScale( down, rimWidth, downLength );
CG_DrawPlane( origin2, downLength, rightLength, shader );
VectorMA( origin, rimWidth + doneWidth, right, origin2 );
VectorMA( origin2, HEALTH_BAR_HEIGHT - rimWidth, down, origin2 );
VectorScale( right, leftWidth, rightLength );
VectorScale( down, rimWidth, downLength );
CG_DrawPlane( origin2, downLength, rightLength, shader );
VectorMA( origin, HEALTH_BAR_WIDTH - rimWidth, right, origin2 );
VectorScale( right, rimWidth, rightLength );
VectorScale( down, HEALTH_BAR_HEIGHT, downLength );
CG_DrawPlane( origin2, downLength, rightLength, shader );
if( !( es->generic1 & B_POWERED_TOGGLEBIT ) &&
BG_FindTeamForBuildable( es->modelindex ) == BIT_HUMANS )
{
VectorMA( origin, 15.0f, right, origin2 );
VectorMA( origin2, HEALTH_BAR_HEIGHT + 5.0f, down, origin2 );
VectorScale( right, HEALTH_BAR_WIDTH / 2.0f - 5.0f, rightLength );
VectorScale( down, HEALTH_BAR_WIDTH / 2.0f - 5.0f, downLength );
CG_DrawPlane( origin2, downLength, rightLength, cgs.media.noPowerShader );
}
}
示例13: Get_AimAngle
//======================================================================
//aim決定
//ent entity
//aim aimスキル
//yaw dist
//wep weapon
void Get_AimAngle(edict_t *ent,float aim,float dist,int weapon)
{
edict_t *target;
vec3_t targaim,v;
trace_t rs_trace;
target = ent->client->zc.first_target;
switch(weapon)
{
//即判定
case WEAP_SHOTGUN:
case WEAP_SUPERSHOTGUN:
case WEAP_RAILGUN:
if(target != ent->client->zc.last_target)
{
if(target->bot_client)
{
VectorSubtract(target->s.old_origin,target->s.origin,targaim);
}
else
{
VectorCopy(target->velocity,targaim);
VectorInverse (targaim);
}
VectorNormalize(targaim);
VectorMA(target->s.origin,random() * aim * AIMING_POSGAP * random(),targaim,targaim);
}
else
{
VectorSubtract(ent->client->zc.last_pos,target->s.origin,targaim);
// VectorScale (targaim, vec_t scale, vec3_t out)
VectorMA(target->s.origin,aim * /*VectorLength(targaim)**/ random(),targaim,targaim);
}
VectorSubtract(targaim,ent->s.origin,targaim);
ent->s.angles[YAW] = Get_yaw(targaim);
ent->s.angles[PITCH] = Get_pitch(targaim);
ent->s.angles[YAW] += aim * AIMING_ANGLEGAP_S * (random() - 0.5) *2;
if(ent->s.angles[YAW] > 180) ent->s.angles[YAW] -= 360;
else if(ent->s.angles[YAW] < -180) ent->s.angles[YAW] += 360;
ent->s.angles[PITCH] += (aim * AIMING_ANGLEGAP_S * (random() - 0.5) * 2);
if(ent->s.angles[PITCH] > 90) ent->s.angles[PITCH] = 90;
else if(ent->s.angles[PITCH] < -90) ent->s.angles[PITCH] = -90;
break;
case WEAP_MACHINEGUN:
case WEAP_CHAINGUN:
if(target != ent->client->zc.last_target)
{
if(target->bot_client)
{
VectorSubtract(target->s.old_origin,target->s.origin,targaim);
}
else
{
VectorCopy(target->velocity,targaim);
VectorInverse (targaim);
}
VectorNormalize(targaim);
VectorMA(target->s.origin,random() * aim * AIMING_POSGAP,targaim,targaim);
}
else
{
VectorSubtract(ent->client->zc.last_pos,target->s.origin,targaim);
VectorMA(target->s.origin,random() * aim /** VectorLength(targaim)*/,targaim,targaim);
}
VectorSubtract(targaim,ent->s.origin,targaim);
ent->s.angles[YAW] = Get_yaw(targaim);
ent->s.angles[PITCH] = Get_pitch(targaim);
ent->s.angles[YAW] += aim * AIMING_ANGLEGAP_M * (random() - 0.5) *2;
if(ent->s.angles[YAW] > 180) ent->s.angles[YAW] -= 360;
else if(ent->s.angles[YAW] < -180) ent->s.angles[YAW] += 360;
ent->s.angles[PITCH] += (aim * AIMING_ANGLEGAP_M * (random() - 0.5) * 2);
if(ent->s.angles[PITCH] > 90) ent->s.angles[PITCH] = 90;
else if(ent->s.angles[PITCH] < -90) ent->s.angles[PITCH] = -90;
break;
case WEAP_BLASTER:
case WEAP_GRENADES:
case WEAP_GRENADELAUNCHER:
case WEAP_ROCKETLAUNCHER:
if(target != ent->client->zc.last_target)
{
if(target->bot_client)
{
VectorSubtract(target->s.origin,target->s.old_origin,targaim);
}
else
//.........这里部分代码省略.........
示例14: R_LoadMD5
//.........这里部分代码省略.........
dv[k]->tangent[0] = bary[0] * dv[0]->position[0] + bary[1] * dv[1]->position[0] + bary[2] * dv[2]->position[0];
dv[k]->tangent[1] = bary[0] * dv[0]->position[1] + bary[1] * dv[1]->position[1] + bary[2] * dv[2]->position[1];
dv[k]->tangent[2] = bary[0] * dv[0]->position[2] + bary[1] * dv[1]->position[2] + bary[2] * dv[2]->position[2];
VectorSubtract(dv[k]->tangent, dv[k]->position, dv[k]->tangent);
VectorNormalize(dv[k]->tangent);
// calculate t tangent vector (binormal)
s = dv[k]->texCoords[0];
t = dv[k]->texCoords[1] + 10.0f;
bary[0] = ((dv[1]->texCoords[0] - s) * (dv[2]->texCoords[1] - t) - (dv[2]->texCoords[0] - s) * (dv[1]->texCoords[1] - t)) / bb;
bary[1] = ((dv[2]->texCoords[0] - s) * (dv[0]->texCoords[1] - t) - (dv[0]->texCoords[0] - s) * (dv[2]->texCoords[1] - t)) / bb;
bary[2] = ((dv[0]->texCoords[0] - s) * (dv[1]->texCoords[1] - t) - (dv[1]->texCoords[0] - s) * (dv[0]->texCoords[1] - t)) / bb;
dv[k]->binormal[0] = bary[0] * dv[0]->position[0] + bary[1] * dv[1]->position[0] + bary[2] * dv[2]->position[0];
dv[k]->binormal[1] = bary[0] * dv[0]->position[1] + bary[1] * dv[1]->position[1] + bary[2] * dv[2]->position[1];
dv[k]->binormal[2] = bary[0] * dv[0]->position[2] + bary[1] * dv[1]->position[2] + bary[2] * dv[2]->position[2];
VectorSubtract(dv[k]->binormal, dv[k]->position, dv[k]->binormal);
VectorNormalize(dv[k]->binormal);
// calculate the normal as cross product N=TxB
#if 0
CrossProduct(dv[k]->tangent, dv[k]->binormal, dv[k]->normal);
VectorNormalize(dv[k]->normal);
// Gram-Schmidt orthogonalization process for B
// compute the cross product B=NxT to obtain
// an orthogonal basis
CrossProduct(dv[k]->normal, dv[k]->tangent, dv[k]->binormal);
if (DotProduct(dv[k]->normal, faceNormal) < 0)
{
VectorInverse(dv[k]->normal);
//VectorInverse(dv[k]->tangent);
//VectorInverse(dv[k]->binormal);
}
#else
VectorAdd(dv[k]->normal, faceNormal, dv[k]->normal);
#endif
}
}
#if 1
for (j = 0, v = surf->verts; j < surf->numVerts; j++, v++)
{
//VectorNormalize(v->tangent);
//VectorNormalize(v->binormal);
VectorNormalize(v->normal);
}
#endif
}
#endif
#if 0
// do another extra smoothing for normals to avoid flat shading
for (j = 0; j < surf->numVerts; j++)
{
for (k = 0; k < surf->numVerts; k++)
{
if (j == k)
{
continue;
}
示例15: CreateRotationMatrix
/*
================
CreateRotationMatrix
================
*/
void CreateRotationMatrix(const vec3_t angles, matrix3_t matrix) {
AngleVectors(angles, matrix[0], matrix[1], matrix[2]);
VectorInverse(matrix[1]);
}