本文整理汇总了C++中Vector4Copy函数的典型用法代码示例。如果您正苦于以下问题:C++ Vector4Copy函数的具体用法?C++ Vector4Copy怎么用?C++ Vector4Copy使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Vector4Copy函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CG_AddBlobShadow
/*
* CG_AddBlobShadow
*
* Ok, to not use decals space we need these arrays to store the
* polygons info. We do not need the linked list nor registration
*/
static void CG_AddBlobShadow( vec3_t origin, vec3_t dir, float orient, float radius,
float r, float g, float b, float a, cgshadebox_t *shadeBox )
{
int i, j, c, nverts;
vec3_t axis[3];
byte_vec4_t color;
fragment_t *fr, fragments[MAX_BLOBSHADOW_FRAGMENTS];
int numfragments;
poly_t poly;
vec4_t verts[MAX_BLOBSHADOW_VERTS];
if( radius <= 0 || VectorCompare( dir, vec3_origin ) )
return; // invalid
// calculate orientation matrix
VectorNormalize2( dir, axis[0] );
PerpendicularVector( axis[1], axis[0] );
RotatePointAroundVector( axis[2], axis[0], axis[1], orient );
CrossProduct( axis[0], axis[2], axis[1] );
numfragments = trap_R_GetClippedFragments( origin, radius, axis, // clip it
MAX_BLOBSHADOW_VERTS, verts, MAX_BLOBSHADOW_FRAGMENTS, fragments );
// no valid fragments
if( !numfragments )
return;
// clamp and scale colors
if( r < 0 ) r = 0;else if( r > 1 ) r = 255;else r *= 255;
if( g < 0 ) g = 0;else if( g > 1 ) g = 255;else g *= 255;
if( b < 0 ) b = 0;else if( b > 1 ) b = 255;else b *= 255;
if( a < 0 ) a = 0;else if( a > 1 ) a = 255;else a *= 255;
color[0] = ( qbyte )( r );
color[1] = ( qbyte )( g );
color[2] = ( qbyte )( b );
color[3] = ( qbyte )( a );
c = *( int * )color;
radius = 0.5f / radius;
VectorScale( axis[1], radius, axis[1] );
VectorScale( axis[2], radius, axis[2] );
memset( &poly, 0, sizeof( poly ) );
for( i = 0, nverts = 0, fr = fragments; i < numfragments; i++, fr++ )
{
if( nverts+fr->numverts > MAX_BLOBSHADOW_VERTS )
return;
if( fr->numverts <= 0 )
continue;
poly.shader = shadeBox->shader;
poly.verts = &shadeBox->verts[nverts];
poly.normals = &shadeBox->norms[nverts];
poly.stcoords = &shadeBox->stcoords[nverts];
poly.colors = &shadeBox->colors[nverts];
poly.numverts = fr->numverts;
poly.fognum = fr->fognum;
nverts += fr->numverts;
for( j = 0; j < fr->numverts; j++ )
{
vec3_t v;
Vector4Copy( verts[fr->firstvert+j], poly.verts[j] );
VectorCopy( axis[0], poly.normals[j] ); poly.normals[j][3] = 0;
VectorSubtract( poly.verts[j], origin, v );
poly.stcoords[j][0] = DotProduct( v, axis[1] ) + 0.5f;
poly.stcoords[j][1] = DotProduct( v, axis[2] ) + 0.5f;
*( int * )poly.colors[j] = c;
}
trap_R_AddPolyToScene( &poly );
}
}
示例2: CG_BuildableStatusDisplay
/*
==================
CG_BuildableStatusDisplay
==================
*/
static void CG_BuildableStatusDisplay( centity_t *cent )
{
entityState_t *es = ¢->currentState;
vec3_t origin;
float healthScale;
int health;
float x, y;
vec4_t color;
qboolean powered, marked;
trace_t tr;
float d;
buildStat_t *bs;
int i, j;
int entNum;
vec3_t trOrigin;
vec3_t right;
qboolean visible = qfalse;
vec3_t mins, maxs;
entityState_t *hit;
if( BG_FindTeamForBuildable( es->modelindex ) == BIT_ALIENS )
bs = &cgs.alienBuildStat;
else
bs = &cgs.humanBuildStat;
if( !bs->loaded )
return;
d = Distance( cent->lerpOrigin, cg.refdef.vieworg );
if( d > STATUS_MAX_VIEW_DIST )
return;
Vector4Copy( bs->foreColor, color );
// trace for center point
BG_FindBBoxForBuildable( es->modelindex, mins, maxs );
VectorCopy( cent->lerpOrigin, origin );
// center point
origin[ 2 ] += mins[ 2 ];
origin[ 2 ] += ( abs( mins[ 2 ] ) + abs( maxs[ 2 ] ) ) / 2;
entNum = cg.predictedPlayerState.clientNum;
// if first try fails, step left, step right
for( j = 0; j < 3; j++ )
{
VectorCopy( cg.refdef.vieworg, trOrigin );
switch( j )
{
case 1:
// step right
AngleVectors( cg.refdefViewAngles, NULL, right, NULL );
VectorMA( trOrigin, STATUS_PEEK_DIST, right, trOrigin );
break;
case 2:
// step left
AngleVectors( cg.refdefViewAngles, NULL, right, NULL );
VectorMA( trOrigin, -STATUS_PEEK_DIST, right, trOrigin );
break;
default:
break;
}
// look through up to 3 players and/or transparent buildables
for( i = 0; i < 3; i++ )
{
CG_Trace( &tr, trOrigin, NULL, NULL, origin, entNum, MASK_SHOT );
if( tr.entityNum == cent->currentState.number )
{
visible = qtrue;
break;
}
if( tr.entityNum == ENTITYNUM_WORLD )
break;
hit = &cg_entities[ tr.entityNum ].currentState;
if( tr.entityNum < MAX_CLIENTS || ( hit->eType == ET_BUILDABLE &&
( !( es->generic1 & B_SPAWNED_TOGGLEBIT ) ||
BG_FindTransparentTestForBuildable( hit->modelindex ) ) ) )
{
entNum = tr.entityNum;
VectorCopy( tr.endpos, trOrigin );
}
else
break;
}
}
// hack to make the kit obscure view
if( cg_drawGun.integer && visible &&
cg.predictedPlayerState.stats[ STAT_PTEAM ] == PTE_HUMANS &&
CG_WorldToScreen( origin, &x, &y ) )
{
//.........这里部分代码省略.........
示例3: UI_SPLevelMenu_MenuDraw
static void UI_SPLevelMenu_MenuDraw( void ) {
int n, i;
int x, y;
vec4_t color;
int level;
// int fraglimit;
int pad;
char buf[MAX_INFO_VALUE];
char string[64];
if( levelMenuInfo.reinit ) {
UI_PopMenu();
UI_SPLevelMenu();
return;
}
// draw player name
trap_Cvar_VariableStringBuffer( "name", string, 32 );
Q_CleanStr( string );
UI_DrawProportionalString( 320, PLAYER_Y, string, UI_CENTER|UI_SMALLFONT, color_orange );
// check for model changes
trap_Cvar_VariableStringBuffer( "model", buf, sizeof(buf) );
if( Q_stricmp( buf, levelMenuInfo.playerModel ) != 0 ) {
Q_strncpyz( levelMenuInfo.playerModel, buf, sizeof(levelMenuInfo.playerModel) );
PlayerIcon( levelMenuInfo.playerModel, levelMenuInfo.playerPicName, sizeof(levelMenuInfo.playerPicName) );
levelMenuInfo.item_player.shader = 0;
}
// standard menu drawing
Menu_Draw( &levelMenuInfo.menu );
// draw player award levels
y = AWARDS_Y;
i = 0;
for( n = 0; n < 6; n++ ) {
level = levelMenuInfo.awardLevels[n];
if( level > 0 ) {
if( i & 1 ) {
x = 224 - (i - 1 ) / 2 * (48 + 16);
}
else {
x = 368 + i / 2 * (48 + 16);
}
i++;
if( level == 1 ) {
continue;
}
if( level >= 1000000 ) {
Com_sprintf( string, sizeof(string), "%im", level / 1000000 );
}
else if( level >= 1000 ) {
Com_sprintf( string, sizeof(string), "%ik", level / 1000 );
}
else {
Com_sprintf( string, sizeof(string), "%i", level );
}
UI_DrawString( x + 24, y + 48, string, UI_CENTER, color_yellow );
}
}
UI_DrawProportionalString( 18, 38, va( "Tier %i", selectedArenaSet + 1 ), UI_LEFT|UI_SMALLFONT, color_orange );
for ( n = 0; n < levelMenuInfo.numMaps; n++ ) {
x = levelMenuInfo.item_maps[n].generic.x;
y = levelMenuInfo.item_maps[n].generic.y;
UI_FillRect( x, y + 96, 128, 18, color_black );
}
if ( selectedArenaSet > currentSet ) {
UI_DrawProportionalString( 320, 216, "ACCESS DENIED", UI_CENTER|UI_BIGFONT, color_red );
return;
}
// show levelshots for levels of current tier
Vector4Copy( color_white, color );
color[3] = 0.5+0.5*sin(uis.realtime/PULSE_DIVISOR);
for ( n = 0; n < levelMenuInfo.numMaps; n++ ) {
x = levelMenuInfo.item_maps[n].generic.x;
y = levelMenuInfo.item_maps[n].generic.y;
UI_DrawString( x + 64, y + 96, levelMenuInfo.levelNames[n], UI_CENTER|UI_SMALLFONT, color_orange );
if( levelMenuInfo.levelScores[n] == 1 ) {
UI_DrawHandlePic( x, y, 128, 96, levelMenuInfo.levelCompletePic[levelMenuInfo.levelScoresSkill[n] - 1] );
}
if ( n == selectedArena ) {
if( Menu_ItemAtCursor( &levelMenuInfo.menu ) == &levelMenuInfo.item_maps[n] ) {
trap_R_SetColor( color );
}
UI_DrawHandlePic( x-1, y-1, 130, 130 - 14, levelMenuInfo.levelSelectedPic );
trap_R_SetColor( NULL );
}
else if( Menu_ItemAtCursor( &levelMenuInfo.menu ) == &levelMenuInfo.item_maps[n] ) {
trap_R_SetColor( color );
UI_DrawHandlePic( x-31, y-30, 256, 256-27, levelMenuInfo.levelFocusPic);
//.........这里部分代码省略.........
示例4: RE_RenderScene
//.........这里部分代码省略.........
tr.refdef.numInteractions = r_firstSceneInteraction;
tr.refdef.interactions = backEndData[ tr.smpFrame ]->interactions;
tr.refdef.numEntities = r_numEntities - r_firstSceneEntity;
tr.refdef.entities = &backEndData[ tr.smpFrame ]->entities[ r_firstSceneEntity ];
tr.refdef.numLights = r_numLights - r_firstSceneLight;
tr.refdef.lights = &backEndData[ tr.smpFrame ]->lights[ r_firstSceneLight ];
tr.refdef.numPolys = r_numPolys - r_firstScenePoly;
tr.refdef.polys = &backEndData[ tr.smpFrame ]->polys[ r_firstScenePoly ];
tr.refdef.numPolybuffers = r_numPolybuffers - r_firstScenePolybuffer;
tr.refdef.polybuffers = &backEndData[ tr.smpFrame ]->polybuffers[ r_firstScenePolybuffer ];
tr.refdef.numDecalProjectors = r_numDecalProjectors - r_firstSceneDecalProjector;
tr.refdef.decalProjectors = &backEndData[ tr.smpFrame ]->decalProjectors[ r_firstSceneDecalProjector ];
tr.refdef.numDecals = r_numDecals - r_firstSceneDecal;
tr.refdef.decals = &backEndData[ tr.smpFrame ]->decals[ r_firstSceneDecal ];
tr.refdef.numVisTests = r_numVisTests - r_firstSceneVisTest;
tr.refdef.visTests = &backEndData[ tr.smpFrame ]->visTests[ r_firstSceneVisTest ];
// a single frame may have multiple scenes draw inside it --
// a 3D game view, 3D status bar renderings, 3D menus, etc.
// They need to be distinguished by the light flare code, because
// the visibility state for a given surface may be different in
// each scene / view.
tr.frameSceneNum++;
tr.sceneCount++;
// Tr3B: a scene can have multiple views caused by mirrors or portals
// the number of views is restricted so we can use hardware occlusion queries
// and put them into the BSP nodes for each view
tr.viewCount = -1;
// setup view parms for the initial view
//
// set up viewport
// The refdef takes 0-at-the-top y coordinates, so
// convert to GL's 0-at-the-bottom space
//
Com_Memset( &parms, 0, sizeof( parms ) );
if ( tr.refdef.pixelTarget == nullptr )
{
parms.viewportX = tr.refdef.x;
parms.viewportY = glConfig.vidHeight - ( tr.refdef.y + tr.refdef.height );
}
else
{
//Driver bug, if we try and do pixel target work along the top edge of a window
//we can end up capturing part of the status bar. (see screenshot corruption..)
//Soooo.. use the middle.
parms.viewportX = glConfig.vidWidth / 2;
parms.viewportY = glConfig.vidHeight / 2;
}
parms.viewportWidth = tr.refdef.width;
parms.viewportHeight = tr.refdef.height;
parms.scissorX = parms.viewportX;
parms.scissorY = parms.viewportY;
parms.scissorWidth = parms.viewportWidth;
parms.scissorHeight = parms.viewportHeight;
Vector4Set( parms.viewportVerts[ 0 ], parms.viewportX, parms.viewportY, 0, 1 );
Vector4Set( parms.viewportVerts[ 1 ], parms.viewportX + parms.viewportWidth, parms.viewportY, 0, 1 );
Vector4Set( parms.viewportVerts[ 2 ], parms.viewportX + parms.viewportWidth, parms.viewportY + parms.viewportHeight, 0, 1 );
Vector4Set( parms.viewportVerts[ 3 ], parms.viewportX, parms.viewportY + parms.viewportHeight, 0, 1 );
parms.isPortal = false;
parms.fovX = tr.refdef.fov_x;
parms.fovY = tr.refdef.fov_y;
VectorCopy( fd->vieworg, parms.orientation.origin );
VectorCopy( fd->viewaxis[ 0 ], parms.orientation.axis[ 0 ] );
VectorCopy( fd->viewaxis[ 1 ], parms.orientation.axis[ 1 ] );
VectorCopy( fd->viewaxis[ 2 ], parms.orientation.axis[ 2 ] );
VectorCopy( fd->vieworg, parms.pvsOrigin );
Vector4Copy( fd->gradingWeights, parms.gradingWeights );
R_RenderView( &parms );
R_RenderPostProcess();
// the next scene rendered in this frame will tack on after this one
r_firstSceneDrawSurf = tr.refdef.numDrawSurfs;
r_firstSceneInteraction = tr.refdef.numInteractions;
r_firstSceneEntity = r_numEntities;
r_firstSceneLight = r_numLights;
r_firstScenePoly = r_numPolys;
r_firstScenePolybuffer = r_numPolybuffers;
r_firstSceneVisTest = r_numVisTests;
tr.frontEndMsec += ri.Milliseconds() - startTime;
}
示例5: R_RenderMeshGLSL_Shadowmap
/*
* R_RenderMeshGLSL_Shadowmap
*/
static void R_RenderMeshGLSL_Shadowmap( r_glslfeat_t programFeatures )
{
int i;
int state;
int scissor[4], old_scissor[4];
int program, object;
vec3_t tdir, lightDir;
shaderpass_t *pass = r_back.accumPasses[0];
if( r_shadows_pcf->integer )
programFeatures |= GLSL_SHADOWMAP_APPLY_PCF;
if( r_shadows_dither->integer )
programFeatures |= GLSL_SHADOWMAP_APPLY_DITHER;
// update uniforms
program = R_RegisterGLSLProgram( pass->program_type, pass->program, NULL, NULL, NULL, 0, programFeatures );
object = R_GetProgramObject( program );
if( !object )
return;
Vector4Copy( ri.scissor, old_scissor );
for( i = 0, r_back.currentCastGroup = r_shadowGroups; i < r_numShadowGroups; i++, r_back.currentCastGroup++ )
{
if( !( r_back.currentShadowBits & r_back.currentCastGroup->bit ) )
continue;
// project the bounding box on to screen then use scissor test
// so that fragment shader isn't run for unshadowed regions
if( !R_ScissorForBounds( r_back.currentCastGroup->visCorners,
&scissor[0], &scissor[1], &scissor[2], &scissor[3] ) )
continue;
GL_Scissor( ri.refdef.x + scissor[0], ri.refdef.y + scissor[1], scissor[2], scissor[3] );
R_BindShaderpass( pass, r_back.currentCastGroup->depthTexture, 0, NULL );
GL_TexEnv( GL_MODULATE );
qglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB );
qglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL );
// calculate the fragment color
R_ModifyColor( pass, qfalse, qfalse );
// set shaderpass state (blending, depthwrite, etc)
state = r_back.currentShaderState | ( pass->flags & r_back.currentShaderPassMask ) | GLSTATE_BLEND_MTEX;
GL_SetState( state );
qglUseProgramObjectARB( object );
VectorCopy( r_back.currentCastGroup->direction, tdir );
Matrix_TransformVector( ri.currententity->axis, tdir, lightDir );
R_UpdateProgramUniforms( program, ri.viewOrigin, vec3_origin, lightDir,
r_back.currentCastGroup->lightAmbient, NULL, NULL, qtrue,
r_back.currentCastGroup->depthTexture->upload_width, r_back.currentCastGroup->depthTexture->upload_height,
r_back.currentCastGroup->projDist,
0, 0,
colorArrayCopy[0], r_back.overBrightBits, r_back.currentShaderTime, r_back.entityColor );
R_FlushArrays();
qglUseProgramObjectARB( 0 );
qglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_NONE );
}
GL_Scissor( old_scissor[0], old_scissor[1], old_scissor[2], old_scissor[3] );
}
示例6: FTLIB_DrawRawString
/*
* FTLIB_DrawRawString - Doesn't care about aligning. Returns drawn len.
* It can stop when reaching maximum width when a value has been parsed.
*/
size_t FTLIB_DrawRawString( int x, int y, const char *str, size_t maxwidth, int *width, qfontface_t *font, vec4_t color, int flags )
{
unsigned int xoffset = 0;
vec4_t scolor;
const char *s, *olds;
int gc, colorindex;
wchar_t num, prev_num = 0;
qglyph_t *glyph, *prev_glyph = NULL;
renderString_f renderString;
getKerning_f getKerning;
bool hasKerning;
if( !str || !font )
return 0;
Vector4Copy( color, scolor );
renderString = font->f->renderString;
getKerning = font->f->getKerning;
hasKerning = ( flags & TEXTDRAWFLAG_KERNING ) && font->hasKerning;
for( s = str; s; )
{
olds = s;
gc = FTLIB_GrabChar( &s, &num, &colorindex, flags );
if( gc == GRABCHAR_CHAR )
{
if( num == '\n' )
break;
if( num < ' ' )
continue;
glyph = FTLIB_GetGlyph( font, num );
if( !glyph )
{
num = FTLIB_REPLACEMENT_GLYPH;
glyph = FTLIB_GetGlyph( font, num );
}
if( !glyph->shader )
renderString( font, olds );
// ignore kerning at this point so the full width of the previous character will always be returned
if( maxwidth && ( ( xoffset + glyph->x_advance ) > maxwidth ) )
{
s = olds;
break;
}
if( hasKerning && prev_num )
xoffset += getKerning( font, prev_glyph, glyph );
FTLIB_DrawRawChar( x + xoffset, y, num, font, scolor );
xoffset += glyph->x_advance;
prev_num = num;
prev_glyph = glyph;
}
else if( gc == GRABCHAR_COLOR )
{
assert( ( unsigned )colorindex < MAX_S_COLORS );
VectorCopy( color_table[colorindex], scolor );
}
else if( gc == GRABCHAR_END )
break;
else
assert( 0 );
}
if( width )
*width = xoffset;
return ( s - str );
}
示例7: CM_AddFacetBevels
void CM_AddFacetBevels( facet_t *facet ) {
int i, j, k, l;
int axis, dir, order, flipped;
float plane[4], d, minBack, newplane[4];
winding_t *w, *w2;
vec3_t mins, maxs, vec, vec2;
#ifndef ADDBEVELS
return;
#endif
Vector4Copy( planes[ facet->surfacePlane ].plane, plane );
w = BaseWindingForPlane( plane, plane[3] );
for ( j = 0 ; j < facet->numBorders && w ; j++ ) {
if ( facet->borderPlanes[j] == facet->surfacePlane ) {
continue;
}
Vector4Copy( planes[ facet->borderPlanes[j] ].plane, plane );
if ( !facet->borderInward[j] ) {
VectorSubtract( vec3_origin, plane, plane );
plane[3] = -plane[3];
}
ChopWindingInPlace( &w, plane, plane[3], 0.1f );
}
if ( !w ) {
return;
}
WindingBounds( w, mins, maxs );
// add the axial planes
order = 0;
for ( axis = 0; axis < 3; axis++ ) {
for ( dir = -1; dir <= 1; dir += 2, order++ ) {
VectorClear( plane );
plane[axis] = dir;
if ( dir == 1 ) {
plane[3] = maxs[axis];
} else {
plane[3] = -mins[axis];
}
//if it's the surface plane
if ( CM_PlaneEqual( &planes[facet->surfacePlane], plane, &flipped ) ) {
continue;
}
// see if the plane is allready present
for ( i = 0; i < facet->numBorders; i++ ) {
if ( dir > 0 ) {
if ( planes[facet->borderPlanes[i]].plane[axis] >= 0.9999f ) {
break;
}
} else {
if ( planes[facet->borderPlanes[i]].plane[axis] <= -0.9999f ) {
break;
}
}
}
if ( i == facet->numBorders ) {
if ( facet->numBorders > 4 + 6 + 16 ) {
Com_Printf( "ERROR: too many bevels\n" );
}
facet->borderPlanes[facet->numBorders] = CM_FindPlane2( plane, &flipped );
facet->borderNoAdjust[facet->numBorders] = 0;
facet->borderInward[facet->numBorders] = flipped;
facet->numBorders++;
}
}
}
//
// add the edge bevels
//
// test the non-axial plane edges
for ( j = 0; j < w->numpoints; j++ )
{
k = ( j + 1 ) % w->numpoints;
VectorSubtract( w->p[j], w->p[k], vec );
//if it's a degenerate edge
if ( VectorNormalize( vec ) < 0.5f ) {
continue;
}
CM_SnapVector( vec );
for ( k = 0; k < 3; k++ ) {
if ( vec[k] == -1.0f || vec[k] == 1.0f || ( vec[k] == 0.0f && vec[( k + 1 ) % 3] == 0.0f ) ) {
break; // axial
}
}
if ( k < 3 ) {
continue; // only test non-axial edges
}
// try the six possible slanted axials from this edge
for ( axis = 0 ; axis < 3 ; axis++ )
{
for ( dir = -1 ; dir <= 1 ; dir += 2 )
{
//.........这里部分代码省略.........
示例8: CM_ValidateFacet
/*
==================
CM_ValidateFacet
If the facet isn't bounded by its borders, we screwed up.
==================
*/
static qboolean CM_ValidateFacet( cFacet_t *facet )
{
float plane[ 4 ];
int j;
winding_t *w;
vec3_t bounds[ 2 ];
if ( facet->surfacePlane == -1 )
{
return qfalse;
}
Vector4Copy( planes[ facet->surfacePlane ].plane, plane );
w = BaseWindingForPlane( plane, plane[ 3 ] );
for ( j = 0; j < facet->numBorders && w; j++ )
{
if ( facet->borderPlanes[ j ] == -1 )
{
FreeWinding( w );
return qfalse;
}
Vector4Copy( planes[ facet->borderPlanes[ j ] ].plane, plane );
if ( !facet->borderInward[ j ] )
{
VectorSubtract( vec3_origin, plane, plane );
plane[ 3 ] = -plane[ 3 ];
}
ChopWindingInPlace( &w, plane, plane[ 3 ], 0.1f );
}
if ( !w )
{
return qfalse; // winding was completely chopped away
}
// see if the facet is unreasonably large
WindingBounds( w, bounds[ 0 ], bounds[ 1 ] );
FreeWinding( w );
for ( j = 0; j < 3; j++ )
{
if ( bounds[ 1 ][ j ] - bounds[ 0 ][ j ] > MAX_WORLD_COORD )
{
return qfalse; // we must be missing a plane
}
if ( bounds[ 0 ][ j ] >= MAX_WORLD_COORD )
{
return qfalse;
}
if ( bounds[ 1 ][ j ] <= MIN_WORLD_COORD )
{
return qfalse;
}
}
return qtrue; // winding is fine
}
示例9: FilterTraceWindingIntoNodes_r
static void FilterTraceWindingIntoNodes_r(traceWinding_t * tw, int nodeNum)
{
int num;
vec4_t plane1, plane2, reverse;
traceNode_t *node;
traceWinding_t front, back;
/* don't filter if passed a bogus node (solid, etc) */
if(nodeNum < 0 || nodeNum >= numTraceNodes)
return;
/* get node */
node = &traceNodes[nodeNum];
/* is this a decision node? */
if(node->type >= 0)
{
/* create winding plane if necessary, filtering out bogus windings as well */
if(nodeNum == headNodeNum)
{
if(!PlaneFromPoints(tw->plane, tw->v[0].xyz, tw->v[1].xyz, tw->v[2].xyz, qtrue))
return;
}
/* validate the node */
if(node->children[0] == 0 || node->children[1] == 0)
Error("Invalid tracenode: %d", nodeNum);
/* get node plane */
Vector4Copy(node->plane, plane1);
/* get winding plane */
Vector4Copy(tw->plane, plane2);
/* invert surface plane */
VectorSubtract(vec3_origin, plane2, reverse);
reverse[3] = -plane2[3];
/* front only */
if(DotProduct(plane1, plane2) > 0.999f && fabs(plane1[3] - plane2[3]) < 0.001f)
{
FilterTraceWindingIntoNodes_r(tw, node->children[0]);
return;
}
/* back only */
if(DotProduct(plane1, reverse) > 0.999f && fabs(plane1[3] - reverse[3]) < 0.001f)
{
FilterTraceWindingIntoNodes_r(tw, node->children[1]);
return;
}
/* clip the winding by node plane */
ClipTraceWinding(tw, plane1, &front, &back);
/* filter by node plane */
if(front.numVerts >= 3)
FilterTraceWindingIntoNodes_r(&front, node->children[0]);
if(back.numVerts >= 3)
FilterTraceWindingIntoNodes_r(&back, node->children[1]);
/* return to caller */
return;
}
/* add winding to leaf node */
num = AddTraceWinding(tw);
AddItemToTraceNode(node, num);
}
示例10: Tess_AddQuadStampExt2
/*
==============
Tess_AddQuadStampExt2
==============
*/
void Tess_AddQuadStampExt2( vec4_t quadVerts[ 4 ], const vec4_t color, float s1, float t1, float s2, float t2 )
{
int i;
vec3_t normal, tangent, binormal;
int ndx;
GLimp_LogComment( "--- Tess_AddQuadStampExt2 ---\n" );
Tess_CheckOverflow( 4, 6 );
ndx = tess.numVertexes;
// triangle indexes for a simple quad
tess.indexes[ tess.numIndexes ] = ndx;
tess.indexes[ tess.numIndexes + 1 ] = ndx + 1;
tess.indexes[ tess.numIndexes + 2 ] = ndx + 3;
tess.indexes[ tess.numIndexes + 3 ] = ndx + 3;
tess.indexes[ tess.numIndexes + 4 ] = ndx + 1;
tess.indexes[ tess.numIndexes + 5 ] = ndx + 2;
VectorCopy( quadVerts[ 0 ], tess.verts[ ndx + 0 ].xyz );
VectorCopy( quadVerts[ 1 ], tess.verts[ ndx + 1 ].xyz );
VectorCopy( quadVerts[ 2 ], tess.verts[ ndx + 2 ].xyz );
VectorCopy( quadVerts[ 3 ], tess.verts[ ndx + 3 ].xyz );
tess.attribsSet |= ATTR_POSITION | ATTR_COLOR | ATTR_TEXCOORD | ATTR_QTANGENT;
// constant normal all the way around
vec2_t st[ 3 ] = { { s1, t1 }, { s2, t1 }, { s2, t2 } };
R_CalcFaceNormal( normal, quadVerts[ 0 ], quadVerts[ 1 ], quadVerts[ 2 ] );
R_CalcTangents( tangent, binormal,
quadVerts[ 0 ], quadVerts[ 1 ], quadVerts[ 2 ],
st[ 0 ], st[ 1 ], st[ 2 ] );
//if ( !calcNormals )
//{
// VectorNegate( backEnd.viewParms.orientation.axis[ 0 ], normal );
//}
R_TBNtoQtangents( tangent, binormal, normal, tess.verts[ ndx ].qtangents );
Vector4Copy( tess.verts[ ndx ].qtangents, tess.verts[ ndx + 1 ].qtangents );
Vector4Copy( tess.verts[ ndx ].qtangents, tess.verts[ ndx + 2 ].qtangents );
Vector4Copy( tess.verts[ ndx ].qtangents, tess.verts[ ndx + 3 ].qtangents );
// standard square texture coordinates
tess.verts[ ndx ].texCoords[ 0 ] = floatToHalf( s1 );
tess.verts[ ndx ].texCoords[ 1 ] = floatToHalf( t1 );
tess.verts[ ndx + 1 ].texCoords[ 0 ] = floatToHalf( s2 );
tess.verts[ ndx + 1 ].texCoords[ 1 ] = floatToHalf( t1 );
tess.verts[ ndx + 2 ].texCoords[ 0 ] = floatToHalf( s2 );
tess.verts[ ndx + 2 ].texCoords[ 1 ] = floatToHalf( t2 );
tess.verts[ ndx + 3 ].texCoords[ 0 ] = floatToHalf( s1 );
tess.verts[ ndx + 3 ].texCoords[ 1 ] = floatToHalf( t2 );
// constant color all the way around
// should this be identity and let the shader specify from entity?
u8vec4_t iColor;
floatToUnorm8( color, iColor );
for ( i = 0; i < 4; i++ )
{
Vector4Copy( iColor, tess.verts[ ndx + i ].color );
}
tess.numVertexes += 4;
tess.numIndexes += 6;
}
示例11: Tess_SurfacePolychain
/*
=============
Tess_SurfacePolychain
=============
*/
static void Tess_SurfacePolychain( srfPoly_t *p )
{
int i, j;
int numVertexes;
int numIndexes;
GLimp_LogComment( "--- Tess_SurfacePolychain ---\n" );
Tess_CheckOverflow( p->numVerts, 3 * ( p->numVerts - 2 ) );
// fan triangles into the tess array
numVertexes = 0;
for ( i = 0; i < p->numVerts; i++ )
{
VectorCopy( p->verts[ i ].xyz, tess.verts[ tess.numVertexes + i ].xyz );
tess.verts[ tess.numVertexes + i ].texCoords[ 0 ] = floatToHalf( p->verts[ i ].st[ 0 ] );
tess.verts[ tess.numVertexes + i ].texCoords[ 1 ] = floatToHalf( p->verts[ i ].st[ 1 ] );
Vector4Copy( p->verts[ i ].modulate, tess.verts[ tess.numVertexes + i ].color );
numVertexes++;
}
// generate fan indexes into the tess array
numIndexes = 0;
for ( i = 0; i < p->numVerts - 2; i++ )
{
tess.indexes[ tess.numIndexes + i * 3 + 0 ] = tess.numVertexes;
tess.indexes[ tess.numIndexes + i * 3 + 1 ] = tess.numVertexes + i + 1;
tess.indexes[ tess.numIndexes + i * 3 + 2 ] = tess.numVertexes + i + 2;
numIndexes += 3;
}
tess.attribsSet |= ATTR_POSITION | ATTR_TEXCOORD | ATTR_COLOR;
// calc tangent spaces
if ( tess.surfaceShader->interactLight && !tess.skipTangentSpaces )
{
int i;
float *v;
const float *v0, *v1, *v2;
const int16_t *t0, *t1, *t2;
vec3_t tangent, *tangents;
vec3_t binormal, *binormals;
vec3_t normal, *normals;
glIndex_t *indices;
tangents = (vec3_t *)ri.Hunk_AllocateTempMemory( numVertexes * sizeof( vec3_t ) );
binormals = (vec3_t *)ri.Hunk_AllocateTempMemory( numVertexes * sizeof( vec3_t ) );
normals = (vec3_t *)ri.Hunk_AllocateTempMemory( numVertexes * sizeof( vec3_t ) );
for ( i = 0; i < numVertexes; i++ )
{
VectorClear( tangents[ i ] );
VectorClear( binormals[ i ] );
VectorClear( normals[ i ] );
}
for ( i = 0, indices = tess.indexes + tess.numIndexes; i < numIndexes; i += 3, indices += 3 )
{
v0 = tess.verts[ indices[ 0 ] ].xyz;
v1 = tess.verts[ indices[ 1 ] ].xyz;
v2 = tess.verts[ indices[ 2 ] ].xyz;
t0 = tess.verts[ indices[ 0 ] ].texCoords;
t1 = tess.verts[ indices[ 1 ] ].texCoords;
t2 = tess.verts[ indices[ 2 ] ].texCoords;
R_CalcFaceNormal( normal, v0, v1, v2 );
R_CalcTangents( tangent, binormal, v0, v1, v2, t0, t1, t2 );
for ( j = 0; j < 3; j++ )
{
v = tangents[ indices[ j ] - tess.numVertexes ];
VectorAdd( v, tangent, v );
v = binormals[ indices[ j ] - tess.numVertexes ];
VectorAdd( v, binormal, v );
v = normals[ indices[ j ] - tess.numVertexes ];
VectorAdd( v, normal, v );
}
}
for ( i = 0; i < numVertexes; i++ )
{
VectorNormalizeFast( normals[ i ] );
R_TBNtoQtangents( tangents[ i ], binormals[ i ],
normals[ i ], tess.verts[ tess.numVertexes + i ].qtangents );
}
ri.Hunk_FreeTempMemory( normals );
ri.Hunk_FreeTempMemory( binormals );
ri.Hunk_FreeTempMemory( tangents );
//.........这里部分代码省略.........
示例12: Tess_AddQuadStampExt
/*
==============
Tess_AddQuadStampExt
==============
*/
void Tess_AddQuadStampExt( vec3_t origin, vec3_t left, vec3_t up, const vec4_t color, float s1, float t1, float s2, float t2 )
{
int i;
vec3_t normal;
int ndx;
GLimp_LogComment( "--- Tess_AddQuadStampExt ---\n" );
Tess_CheckOverflow( 4, 6 );
ndx = tess.numVertexes;
// triangle indexes for a simple quad
tess.indexes[ tess.numIndexes ] = ndx;
tess.indexes[ tess.numIndexes + 1 ] = ndx + 1;
tess.indexes[ tess.numIndexes + 2 ] = ndx + 3;
tess.indexes[ tess.numIndexes + 3 ] = ndx + 3;
tess.indexes[ tess.numIndexes + 4 ] = ndx + 1;
tess.indexes[ tess.numIndexes + 5 ] = ndx + 2;
tess.verts[ ndx ].xyz[ 0 ] = origin[ 0 ] + left[ 0 ] + up[ 0 ];
tess.verts[ ndx ].xyz[ 1 ] = origin[ 1 ] + left[ 1 ] + up[ 1 ];
tess.verts[ ndx ].xyz[ 2 ] = origin[ 2 ] + left[ 2 ] + up[ 2 ];
tess.verts[ ndx + 1 ].xyz[ 0 ] = origin[ 0 ] - left[ 0 ] + up[ 0 ];
tess.verts[ ndx + 1 ].xyz[ 1 ] = origin[ 1 ] - left[ 1 ] + up[ 1 ];
tess.verts[ ndx + 1 ].xyz[ 2 ] = origin[ 2 ] - left[ 2 ] + up[ 2 ];
tess.verts[ ndx + 2 ].xyz[ 0 ] = origin[ 0 ] - left[ 0 ] - up[ 0 ];
tess.verts[ ndx + 2 ].xyz[ 1 ] = origin[ 1 ] - left[ 1 ] - up[ 1 ];
tess.verts[ ndx + 2 ].xyz[ 2 ] = origin[ 2 ] - left[ 2 ] - up[ 2 ];
tess.verts[ ndx + 3 ].xyz[ 0 ] = origin[ 0 ] + left[ 0 ] - up[ 0 ];
tess.verts[ ndx + 3 ].xyz[ 1 ] = origin[ 1 ] + left[ 1 ] - up[ 1 ];
tess.verts[ ndx + 3 ].xyz[ 2 ] = origin[ 2 ] + left[ 2 ] - up[ 2 ];
// constant normal all the way around
VectorSubtract( vec3_origin, backEnd.viewParms.orientation.axis[ 0 ], normal );
R_TBNtoQtangents( left, up, normal, tess.verts[ ndx ].qtangents );
Vector4Copy( tess.verts[ ndx ].qtangents, tess.verts[ ndx + 1 ].qtangents );
Vector4Copy( tess.verts[ ndx ].qtangents, tess.verts[ ndx + 2 ].qtangents );
Vector4Copy( tess.verts[ ndx ].qtangents, tess.verts[ ndx + 3 ].qtangents );
// standard square texture coordinates
tess.verts[ ndx ].texCoords[ 0 ] = floatToHalf( s1 );
tess.verts[ ndx ].texCoords[ 1 ] = floatToHalf( t1 );
tess.verts[ ndx + 1 ].texCoords[ 0 ] = floatToHalf( s2 );
tess.verts[ ndx + 1 ].texCoords[ 1 ] = floatToHalf( t1 );
tess.verts[ ndx + 2 ].texCoords[ 0 ] = floatToHalf( s2 );
tess.verts[ ndx + 2 ].texCoords[ 1 ] = floatToHalf( t2 );
tess.verts[ ndx + 3 ].texCoords[ 0 ] = floatToHalf( s1 );
tess.verts[ ndx + 3 ].texCoords[ 1 ] = floatToHalf( t2 );
// constant color all the way around
// should this be identity and let the shader specify from entity?
u8vec4_t iColor;
floatToUnorm8( color, iColor );
for ( i = 0; i < 4; i++ )
{
Vector4Copy( iColor, tess.verts[ ndx + i ].color );
}
tess.numVertexes += 4;
tess.numIndexes += 6;
tess.attribsSet |= ATTR_POSITION | ATTR_QTANGENT | ATTR_COLOR | ATTR_TEXCOORD;
}
示例13: CM_AddFacetBevels
/*
==================
CM_AddFacetBevels
==================
*/
static void CM_AddFacetBevels( cfacet_t *facet )
{
int i, j, k, l;
int axis, dir, order, flipped;
float plane[4], d, newplane[4];
vec3_t mins, maxs, vec, vec2;
cwinding_t *w, *w2;
Vector4Copy( planes[facet->surfacePlane].plane, plane );
w = CM_BaseWindingForPlane( plane, plane[3] );
for( j = 0; j < facet->numBorders && w; j++ )
{
if( facet->borderPlanes[j] == facet->surfacePlane )
continue;
Vector4Copy( planes[facet->borderPlanes[j]].plane, plane );
if( !facet->borderInward[j] )
{
VectorNegate( plane, plane );
plane[3] = -plane[3];
}
CM_ChopWindingInPlace( &w, plane, plane[3], ON_EPSILON );
}
if( !w ) return;
CM_WindingBounds( w, mins, maxs );
//
// add the axial planes
//
order = 0;
for( axis = 0; axis < 3; axis++ )
{
for( dir = -1; dir <= 1; dir += 2, order++ )
{
VectorClear( plane );
plane[axis] = dir;
if( dir == 1 ) plane[3] = maxs[axis];
else plane[3] = -mins[axis];
// if it's the surface plane
if( CM_PlaneEqual( &planes[facet->surfacePlane], plane, &flipped ))
continue;
// see if the plane is allready present
for( i = 0; i < facet->numBorders; i++ )
{
if( CM_PlaneEqual( &planes[facet->borderPlanes[i]], plane, &flipped ))
break;
}
if( i == facet->numBorders )
{
if( facet->numBorders > MAX_FACET_BEVELS )
MsgDev( D_ERROR, "CM_AddFacetBevels: too many bevels\n" );
facet->borderPlanes[facet->numBorders] = CM_FindPlane2(plane, &flipped);
facet->borderNoAdjust[facet->numBorders] = 0;
facet->borderInward[facet->numBorders] = flipped;
facet->numBorders++;
}
}
}
//
// add the edge bevels
//
// test the non-axial plane edges
for( j = 0; j < w->numpoints; j++ )
{
k = (j + 1) % w->numpoints;
VectorSubtract( w->p[j], w->p[k], vec );
// if it's a degenerate edge
if( VectorNormalizeLength( vec ) < 0.5f )
continue;
CM_SnapVector( vec );
for( k = 0; k < 3; k++ )
{
if( vec[k] == -1 || vec[k] == 1 )
break; // axial
}
if( k < 3 ) continue; // only test non-axial edges
// try the six possible slanted axials from this edge
for( axis = 0; axis < 3; axis++ )
{
//.........这里部分代码省略.........
示例14: CG_ImpactMark
/**
origin should be a point within a unit of the plane
dir should be the plane normal
temporary marks will not be stored or randomly oriented, but immediately
passed to the renderer.
*/
void CG_ImpactMark(qhandle_t markShader, const vec3_t origin, const vec3_t dir, float orientation,
vec4_t color, qboolean alphaFade, float radius, qboolean temporary)
{
vec3_t axis[3];
float texCoordScale;
vec3_t originalPoints[4];
int i, j;
int numFragments;
markFragment_t markFragments[MAX_MARK_FRAGMENTS], *mf;
vec3_t markPoints[MAX_MARK_POINTS];
vec3_t projection;
if (!cg_marks.integer) {
return;
}
if (radius <= 0) {
CG_Error("CG_ImpactMark called with <= 0 radius");
}
// create the texture axis
VectorNormalize2(dir, axis[0]);
PerpendicularVector(axis[1], axis[0]);
RotatePointAroundVector(axis[2], axis[0], axis[1], orientation);
CrossProduct(axis[0], axis[2], axis[1]);
texCoordScale = 0.5 * 1.0 / radius;
// create the full polygon
for (i = 0; i < 3; i++) {
originalPoints[0][i] = origin[i] - radius * axis[1][i] - radius * axis[2][i];
originalPoints[1][i] = origin[i] + radius * axis[1][i] - radius * axis[2][i];
originalPoints[2][i] = origin[i] + radius * axis[1][i] + radius * axis[2][i];
originalPoints[3][i] = origin[i] - radius * axis[1][i] + radius * axis[2][i];
}
// get the fragments
VectorScale(dir, -20, projection);
numFragments = trap_CM_MarkFragments(4, (void *)originalPoints,
projection, MAX_MARK_POINTS, markPoints[0],
MAX_MARK_FRAGMENTS, markFragments);
for (i = 0, mf = markFragments; i < numFragments; i++, mf++) {
polyVert_t *v;
polyVert_t verts[MAX_VERTS_ON_POLY];
markPoly_t *mark;
// we have an upper limit on the complexity of polygons
// that we store persistantly
if (mf->numPoints > MAX_VERTS_ON_POLY) {
mf->numPoints = MAX_VERTS_ON_POLY;
}
for (j = 0, v = verts; j < mf->numPoints; j++, v++) {
vec3_t delta;
VectorCopy(markPoints[mf->firstPoint + j], v->xyz);
VectorSubtract(v->xyz, origin, delta);
v->st[0] = 0.5 + DotProduct(delta, axis[1]) * texCoordScale;
v->st[1] = 0.5 + DotProduct(delta, axis[2]) * texCoordScale;
SCR_SetRGBA(v->modulate, color);
}
// if it is a temporary (shadow) mark, add it immediately and forget about it
if (temporary) {
trap_R_AddPolyToScene(markShader, mf->numPoints, verts);
continue;
}
// otherwise save it persistantly
mark = CG_AllocMark();
mark->time = cg.time;
mark->alphaFade = alphaFade;
mark->markShader = markShader;
mark->poly.numVerts = mf->numPoints;
Vector4Copy(color, mark->color);
memcpy(mark->verts, verts, mf->numPoints * sizeof(verts[0]));
markTotal++;
}
}
示例15: VectorSubtract
/*
* CG_SpawnPolyBeam
* Spawns a polygon from start to end points length and given width.
* shaderlenght makes reference to size of the texture it will draw, so it can be tiled.
*/
static cpoly_t *CG_SpawnPolyBeam( const vec3_t start, const vec3_t end, const vec4_t color, int width, unsigned int dietime, unsigned int fadetime, struct shader_s *shader, int shaderlength, int tag )
{
cpoly_t *cgpoly;
poly_t *poly;
vec3_t angles, dir;
int i;
float xmin, ymin, xmax, ymax;
float stx = 1.0f, sty = 1.0f;
// find out beam polygon sizes
VectorSubtract( end, start, dir );
VecToAngles( dir, angles );
xmin = 0;
xmax = VectorNormalize( dir );
ymin = -( width*0.5 );
ymax = width*0.5;
if( shaderlength && xmax > shaderlength )
stx = xmax / (float)shaderlength;
if( xmax - xmin < ymax - ymin ) {
// do not render polybeams which have width longer than their length
return NULL;
}
cgpoly = CG_SpawnPolygon( 1.0, 1.0, 1.0, 1.0, dietime ? dietime : cgs.snapFrameTime, fadetime, shader, tag );
VectorCopy( angles, cgpoly->angles );
VectorCopy( start, cgpoly->origin );
if( color )
Vector4Copy( color, cgpoly->color );
// create the polygon inside the cgpolygon
poly = cgpoly->poly;
poly->shader = cgpoly->shader;
poly->numverts = 0;
// Vic: I think it's safe to assume there should be no fog applied to beams...
poly->fognum = 0;
// A
Vector4Set( poly->verts[poly->numverts], xmin, 0, ymin, 1 );
poly->stcoords[poly->numverts][0] = 0;
poly->stcoords[poly->numverts][1] = 0;
poly->colors[poly->numverts][0] = ( uint8_t )( cgpoly->color[0] * 255 );
poly->colors[poly->numverts][1] = ( uint8_t )( cgpoly->color[1] * 255 );
poly->colors[poly->numverts][2] = ( uint8_t )( cgpoly->color[2] * 255 );
poly->colors[poly->numverts][3] = ( uint8_t )( cgpoly->color[3] * 255 );
poly->numverts++;
// B
Vector4Set( poly->verts[poly->numverts], xmin, 0, ymax, 1 );
poly->stcoords[poly->numverts][0] = 0;
poly->stcoords[poly->numverts][1] = sty;
poly->colors[poly->numverts][0] = ( uint8_t )( cgpoly->color[0] * 255 );
poly->colors[poly->numverts][1] = ( uint8_t )( cgpoly->color[1] * 255 );
poly->colors[poly->numverts][2] = ( uint8_t )( cgpoly->color[2] * 255 );
poly->colors[poly->numverts][3] = ( uint8_t )( cgpoly->color[3] * 255 );
poly->numverts++;
// C
Vector4Set( poly->verts[poly->numverts], xmax, 0, ymax, 1 );
poly->stcoords[poly->numverts][0] = stx;
poly->stcoords[poly->numverts][1] = sty;
poly->colors[poly->numverts][0] = ( uint8_t )( cgpoly->color[0] * 255 );
poly->colors[poly->numverts][1] = ( uint8_t )( cgpoly->color[1] * 255 );
poly->colors[poly->numverts][2] = ( uint8_t )( cgpoly->color[2] * 255 );
poly->colors[poly->numverts][3] = ( uint8_t )( cgpoly->color[3] * 255 );
poly->numverts++;
// D
Vector4Set( poly->verts[poly->numverts], xmax, 0, ymin, 1 );
poly->stcoords[poly->numverts][0] = stx;
poly->stcoords[poly->numverts][1] = 0;
poly->colors[poly->numverts][0] = ( uint8_t )( cgpoly->color[0] * 255 );
poly->colors[poly->numverts][1] = ( uint8_t )( cgpoly->color[1] * 255 );
poly->colors[poly->numverts][2] = ( uint8_t )( cgpoly->color[2] * 255 );
poly->colors[poly->numverts][3] = ( uint8_t )( cgpoly->color[3] * 255 );
poly->numverts++;
// the verts data is stored inside cgpoly, cause it can be moved later
for( i = 0; i < poly->numverts; i++ )
Vector4Copy( poly->verts[i], cgpoly->verts[i] );
return cgpoly;
}