本文整理汇总了C++中CrossProduct函数的典型用法代码示例。如果您正苦于以下问题:C++ CrossProduct函数的具体用法?C++ CrossProduct怎么用?C++ CrossProduct使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CrossProduct函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CG_ImpactMark
void CG_ImpactMark( qhandle_t markShader, const vec3_t origin, const vec3_t dir,
float orientation, float red, float green, float blue, float alpha,
qboolean alphaFade, float radius, qboolean temporary ) {
vec3_t axis[3];
float texCoordScale;
vec3_t originalPoints[4];
byte colors[4];
int i, j;
int numFragments;
markFragment_t markFragments[MAX_MARK_FRAGMENTS], *mf;
vec3_t markPoints[MAX_MARK_POINTS];
vec3_t projection;
if(markShader == 0) return;
assert(markShader);
if ( !cg_addMarks.integer ) {
return;
}
else if (cg_addMarks.integer == 2)
{
trap_R_AddDecalToScene(markShader, origin, dir, orientation, red, green, blue, alpha,
alphaFade, radius, temporary);
return;
}
if ( radius <= 0 ) {
CG_Error( "CG_ImpactMark called with <= 0 radius" );
}
//if ( markTotal >= MAX_MARK_POLYS ) {
// return;
//}
// 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, (const vec3_t *) originalPoints,
projection, MAX_MARK_POINTS, markPoints[0],
MAX_MARK_FRAGMENTS, markFragments );
colors[0] = red * 255;
colors[1] = green * 255;
colors[2] = blue * 255;
colors[3] = alpha * 255;
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;
*(int *)v->modulate = *(int *)colors;
}
// 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;
mark->color[0] = red;
mark->color[1] = green;
mark->color[2] = blue;
mark->color[3] = alpha;
memcpy( mark->verts, verts, mf->numPoints * sizeof( verts[0] ) );
markTotal++;
//.........这里部分代码省略.........
示例2: CM_AddFacetBevels
void CM_AddFacetBevels( facet_t *facet ) {
int i, j, k, l;
int axis, dir, order, flipped;
float plane[4], d, 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 (CM_PlaneEqual(&planes[facet->borderPlanes[i]], plane, &flipped))
break;
}
if ( i == facet->numBorders ) {
if (facet->numBorders > 4 + 6 + 16) {
Com_Printf("ERROR: too many bevels\n");
continue;
}
facet->borderPlanes[facet->numBorders] = CM_FindPlane2(plane, &flipped);
facet->borderNoAdjust[facet->numBorders] = qfalse;
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 || 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++ )
{
for ( dir = -1 ; dir <= 1 ; dir += 2 )
{
// construct a plane
VectorClear (vec2);
vec2[axis] = dir;
CrossProduct (vec, vec2, plane);
if (VectorNormalize (plane) < 0.5f)
continue;
plane[3] = DotProduct (w->p[j], plane);
// if all the points of the facet winding are
//.........这里部分代码省略.........
示例3: PM_SlideMove
//.........这里部分代码省略.........
// if this is the same plane we hit before, nudge velocity
// out along it, which fixes some epsilon issues with
// non-axial planes
//
for ( i = 0 ; i < numplanes ; i++ ) {
if ( DotProduct( trace.plane.normal, planes[i] ) > 0.99 ) {
VectorAdd( trace.plane.normal, pm->ps->velocity, pm->ps->velocity );
break;
}
}
if ( i < numplanes ) {
continue;
}
VectorCopy (trace.plane.normal, planes[numplanes]);
numplanes++;
//
// modify velocity so it parallels all of the clip planes
//
// find a plane that it enters
for ( i = 0 ; i < numplanes ; i++ ) {
into = DotProduct( pm->ps->velocity, planes[i] );
if ( into >= 0.1 ) {
continue; // move doesn't interact with the plane
}
// see how hard we are hitting things
if ( -into > pml.impactSpeed ) {
pml.impactSpeed = -into;
}
// slide along the plane
PM_ClipVelocity (pm->ps->velocity, planes[i], clipVelocity, OVERCLIP );
// slide along the plane
PM_ClipVelocity (endVelocity, planes[i], endClipVelocity, OVERCLIP );
// see if there is a second plane that the new move enters
for ( j = 0 ; j < numplanes ; j++ ) {
if ( j == i ) {
continue;
}
if ( DotProduct( clipVelocity, planes[j] ) >= 0.1 ) {
continue; // move doesn't interact with the plane
}
// try clipping the move to the plane
PM_ClipVelocity( clipVelocity, planes[j], clipVelocity, OVERCLIP );
PM_ClipVelocity( endClipVelocity, planes[j], endClipVelocity, OVERCLIP );
// see if it goes back into the first clip plane
if ( DotProduct( clipVelocity, planes[i] ) >= 0 ) {
continue;
}
// slide the original velocity along the crease
CrossProduct (planes[i], planes[j], dir);
VectorNormalize( dir );
d = DotProduct( dir, pm->ps->velocity );
VectorScale( dir, d, clipVelocity );
CrossProduct (planes[i], planes[j], dir);
VectorNormalize( dir );
d = DotProduct( dir, endVelocity );
VectorScale( dir, d, endClipVelocity );
// see if there is a third plane the the new move enters
for ( k = 0 ; k < numplanes ; k++ ) {
if ( k == i || k == j ) {
continue;
}
if ( DotProduct( clipVelocity, planes[k] ) >= 0.1 ) {
continue; // move doesn't interact with the plane
}
// stop dead at a tripple plane interaction
VectorClear( pm->ps->velocity );
return qtrue;
}
}
// if we have fixed all interactions, try another move
VectorCopy( clipVelocity, pm->ps->velocity );
VectorCopy( endClipVelocity, endVelocity );
break;
}
}
if ( gravity ) {
VectorCopy( endVelocity, pm->ps->velocity );
}
// don't change velocity if in a timer (FIXME: is this correct?)
if ( pm->ps->pm_time ) {
VectorCopy( primal_velocity, pm->ps->velocity );
}
return ( bumpcount != 0 );
}
示例4: R_GetPortalOrientations
/*
=================
R_GetPortalOrientation
entityNum is the entity that the portal surface is a part of, which may
be moving and rotating.
Returns qtrue if it should be mirrored
=================
*/
qboolean R_GetPortalOrientations( drawSurf_t *drawSurf, int entityNum,
orientation_t *surface, orientation_t *camera,
vec3_t pvsOrigin, qboolean *mirror ) {
int i;
cplane_t originalPlane, plane;
trRefEntity_t *e;
float d;
vec3_t transformed;
// create plane axis for the portal we are seeing
R_PlaneForSurface( drawSurf->surface, &originalPlane );
// rotate the plane if necessary
if ( entityNum != REFENTITYNUM_WORLD ) {
tr.currentEntityNum = entityNum;
tr.currentEntity = &tr.refdef.entities[entityNum];
// get the orientation of the entity
R_RotateForEntity( tr.currentEntity, &tr.viewParms, &tr.or );
// rotate the plane, but keep the non-rotated version for matching
// against the portalSurface entities
R_LocalNormalToWorld( originalPlane.normal, plane.normal );
plane.dist = originalPlane.dist + DotProduct( plane.normal, tr.or.origin );
// translate the original plane
originalPlane.dist = originalPlane.dist + DotProduct( originalPlane.normal, tr.or.origin );
} else {
plane = originalPlane;
}
VectorCopy( plane.normal, surface->axis[0] );
PerpendicularVector( surface->axis[1], surface->axis[0] );
CrossProduct( surface->axis[0], surface->axis[1], surface->axis[2] );
// locate the portal entity closest to this plane.
// origin will be the origin of the portal, origin2 will be
// the origin of the camera
for ( i = 0 ; i < tr.refdef.num_entities ; i++ ) {
e = &tr.refdef.entities[i];
if ( e->e.reType != RT_PORTALSURFACE ) {
continue;
}
d = DotProduct( e->e.origin, originalPlane.normal ) - originalPlane.dist;
if ( d > 64 || d < -64) {
continue;
}
// get the pvsOrigin from the entity
VectorCopy( e->e.oldorigin, pvsOrigin );
// if the entity is just a mirror, don't use as a camera point
if ( e->e.oldorigin[0] == e->e.origin[0] &&
e->e.oldorigin[1] == e->e.origin[1] &&
e->e.oldorigin[2] == e->e.origin[2] ) {
VectorScale( plane.normal, plane.dist, surface->origin );
VectorCopy( surface->origin, camera->origin );
VectorSubtract( vec3_origin, surface->axis[0], camera->axis[0] );
VectorCopy( surface->axis[1], camera->axis[1] );
VectorCopy( surface->axis[2], camera->axis[2] );
*mirror = qtrue;
return qtrue;
}
// project the origin onto the surface plane to get
// an origin point we can rotate around
d = DotProduct( e->e.origin, plane.normal ) - plane.dist;
VectorMA( e->e.origin, -d, surface->axis[0], surface->origin );
// now get the camera origin and orientation
VectorCopy( e->e.oldorigin, camera->origin );
AxisCopy( e->e.axis, camera->axis );
VectorSubtract( vec3_origin, camera->axis[0], camera->axis[0] );
VectorSubtract( vec3_origin, camera->axis[1], camera->axis[1] );
// optionally rotate
if ( e->e.oldframe ) {
// if a speed is specified
if ( e->e.frame ) {
// continuous rotate
d = (tr.refdef.time/1000.0f) * e->e.frame;
VectorCopy( camera->axis[1], transformed );
RotatePointAroundVector( camera->axis[1], camera->axis[0], transformed, d );
CrossProduct( camera->axis[0], camera->axis[1], camera->axis[2] );
} else {
// bobbing rotate, with skinNum being the rotation offset
d = sin( tr.refdef.time * 0.003f );
d = e->e.skinNum + d * 4;
//.........这里部分代码省略.........
示例5: GenerateTerrain
Model* GenerateTerrain(TextureData *tex)
{
int vertexCount = tex->width * tex->height;
int triangleCount = (tex->width-1) * (tex->height-1) * 2;
int x, z;
GLfloat *vertexArray = malloc(sizeof(GLfloat) * 3 * vertexCount);
GLfloat *normalArray = malloc(sizeof(GLfloat) * 3 * vertexCount);
GLfloat *texCoordArray = malloc(sizeof(GLfloat) * 2 * vertexCount);
GLuint *indexArray = malloc(sizeof(GLuint) * triangleCount*3);
vec3 u, v;
printf("bpp %d\n", tex->bpp);
for (x = 0; x < tex->width; x++)
for (z = 0; z < tex->height; z++)
{
// Vertex array. You need to scale this properly
vertexArray[(x + z * tex->width)*3 + 0] = x / 5.0;
vertexArray[(x + z * tex->width)*3 + 1] = tex->imageData[(x + z * tex->width) * (tex->bpp/8)] / 100.0;
vertexArray[(x + z * tex->width)*3 + 2] = z / 5.0;
// Normal vectors. You need to calculate these.
normalArray[(x + z * tex->width)*3 + 0] = 0.0;
normalArray[(x + z * tex->width)*3 + 1] = 1.0;
normalArray[(x + z * tex->width)*3 + 2] = 0.0;
// Texture coordinates. You may want to scale them.
texCoordArray[(x + z * tex->width)*2 + 0] = x; // (float)x / tex->width;
texCoordArray[(x + z * tex->width)*2 + 1] = z; // (float)z / tex->height;
}
for (x = 0; x < tex->width-1; x++)
for (z = 0; z < tex->height-1; z++)
{
// Triangle 1
indexArray[(x + z * (tex->width-1))*6 + 0] = x + z * tex->width;
indexArray[(x + z * (tex->width-1))*6 + 1] = x + (z+1) * tex->width;
indexArray[(x + z * (tex->width-1))*6 + 2] = x+1 + z * tex->width;
// Triangle 2
indexArray[(x + z * (tex->width-1))*6 + 3] = x+1 + z * tex->width;
indexArray[(x + z * (tex->width-1))*6 + 4] = x + (z+1) * tex->width;
indexArray[(x + z * (tex->width-1))*6 + 5] = x+1 + (z+1) * tex->width;
// beräkna normalvectorer
if(x>=1 && z>= 1){
u.x =vertexArray[(x+1 + z * tex->width)*3+0] - vertexArray[(x-1 + (z-1) * tex->width)*3+0];
u.y = vertexArray[(x+1 + z * tex->width)*3+1] - vertexArray[(x-1 + (z-1) * tex->width)*3+1];
u.z =vertexArray[(x+1 + z * tex->width)*3+2] - vertexArray[(x-1 + (z-1) * tex->width)*3+2];
v.x= vertexArray[(x + (z+1) * tex->width)*3+0] - vertexArray[(x-1 + (z-1) * tex->width)*3+0];
v.y=vertexArray[(x + (z+1) * tex->width)*3+1] - vertexArray[(x-1 + (z-1) * tex->width)*3+1];
v.z=vertexArray[(x + (z+1) * tex->width)*3+2] - vertexArray[(x-1 + (z-1) * tex->width)*3+2];
vec3 normal= CrossProduct(v,u);
normalArray[(x + z * tex->width)*3+ 0] = normal.x;
normalArray[(x + z * tex->width)*3+ 1] = normal.y;
normalArray[(x + z * tex->width)*3+ 2] = normal.z;
}
}
// End of terrain generation
// Create Model and upload to GPU:
Model* model = LoadDataToModel(
vertexArray,
normalArray,
texCoordArray,
NULL,
indexArray,
vertexCount,
triangleCount*3);
return model;
}
示例6: edge
/*
=================
RB_ShadowTessEnd
triangleFromEdge[ v1 ][ v2 ]
set triangle from edge( v1, v2, tri )
if ( facing[ triangleFromEdge[ v1 ][ v2 ] ] && !facing[ triangleFromEdge[ v2 ][ v1 ] ) {
}
=================
*/
void RB_ShadowTessEnd( void ) {
int i;
int numTris;
vec3_t lightDir;
GLboolean rgba[4];
// we can only do this if we have enough space in the vertex buffers
if ( tess.numVertexes >= SHADER_MAX_VERTEXES / 2 ) {
return;
}
if ( glConfig.stencilBits < 4 ) {
return;
}
VectorCopy( backEnd.currentEntity->lightDir, lightDir );
// project vertexes away from light direction
for ( i = 0 ; i < tess.numVertexes ; i++ ) {
VectorMA( tess.xyz[i], -512, lightDir, tess.xyz[i+tess.numVertexes] );
}
// decide which triangles face the light
Com_Memset( numEdgeDefs, 0, 4 * tess.numVertexes );
numTris = tess.numIndexes / 3;
for ( i = 0 ; i < numTris ; i++ ) {
int i1, i2, i3;
vec3_t d1, d2, normal;
float *v1, *v2, *v3;
float d;
i1 = tess.indexes[ i*3 + 0 ];
i2 = tess.indexes[ i*3 + 1 ];
i3 = tess.indexes[ i*3 + 2 ];
v1 = tess.xyz[ i1 ];
v2 = tess.xyz[ i2 ];
v3 = tess.xyz[ i3 ];
VectorSubtract( v2, v1, d1 );
VectorSubtract( v3, v1, d2 );
CrossProduct( d1, d2, normal );
d = DotProduct( normal, lightDir );
if ( d > 0 ) {
facing[ i ] = 1;
} else {
facing[ i ] = 0;
}
// create the edges
R_AddEdgeDef( i1, i2, facing[ i ] );
R_AddEdgeDef( i2, i3, facing[ i ] );
R_AddEdgeDef( i3, i1, facing[ i ] );
}
// draw the silhouette edges
GL_Bind( tr.whiteImage );
qglEnable( GL_CULL_FACE );
GL_State( GLS_SRCBLEND_ONE | GLS_DSTBLEND_ZERO );
qglColor3f( 0.2f, 0.2f, 0.2f );
// don't write to the color buffer
qglGetBooleanv(GL_COLOR_WRITEMASK, rgba);
qglColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
qglEnable( GL_STENCIL_TEST );
qglStencilFunc( GL_ALWAYS, 1, 255 );
// mirrors have the culling order reversed
if ( backEnd.viewParms.isMirror ) {
qglCullFace( GL_FRONT );
qglStencilOp( GL_KEEP, GL_KEEP, GL_INCR );
R_RenderShadowEdges();
qglCullFace( GL_BACK );
qglStencilOp( GL_KEEP, GL_KEEP, GL_DECR );
R_RenderShadowEdges();
} else {
qglCullFace( GL_BACK );
qglStencilOp( GL_KEEP, GL_KEEP, GL_INCR );
R_RenderShadowEdges();
//.........这里部分代码省略.........
示例7: AbsoluteToLocal
void AbsoluteToLocal(plane_t normal2, face_t* f, vec3_t& p1, vec3_t& p2, vec3_t& p3)
{
vec3_t ex,ey,ez;
#ifdef _DEBUG
if (g_qeglobals.m_bBrushPrimitMode)
Sys_Printf("Warning : illegal call of AbsoluteToLocal in brush primitive mode\n");
#endif
// computing new local axis base
TextureAxisFromPlane(&normal2, ex, ey);
CrossProduct(ex, ey, ez);
// projecting back on (ex,ey)
Back(ez,p1);
Back(ez,p2);
Back(ez,p3);
vec3_t aux;
// rotation
VectorCopy(p2, aux);
VectorSubtract(aux, p1,aux);
float x = DotProduct(aux,ex);
float y = DotProduct(aux,ey);
f->texdef.rotate = 180 * atan2(y,x) / Q_PI;
vec3_t rex,rey;
// computing rotated local axis base
VectorCopy(ez, aux);
VectorScale(aux, f->texdef.rotate, aux);
VectorCopy(ex, rex);
VectorRotate(rex, aux, rex);
VectorCopy(ey, rey);
VectorRotate(rey, aux, rey);
// scale
VectorCopy(p2, aux);
VectorSubtract(aux, p1, aux);
f->texdef.scale[0] = DotProduct(aux, rex);
VectorCopy(p3, aux);
VectorSubtract(aux, p1, aux);
f->texdef.scale[1] = DotProduct(aux, rey);
// shift
// only using p1
x = DotProduct(rex,p1);
y = DotProduct(rey,p1);
x /= f->texdef.scale[0];
y /= f->texdef.scale[1];
VectorCopy(rex, p1);
VectorScale(p1, x, p1);
VectorCopy(rey, aux);
VectorScale(aux, y, aux);
VectorAdd(p1, aux, p1);
VectorCopy(ez, aux);
VectorScale(aux, -f->texdef.rotate, aux);
VectorRotate(p1, aux, p1);
f->texdef.shift[0] = -DotProduct(p1, ex);
f->texdef.shift[1] = -DotProduct(p1, ey);
// stored rot is good considering local axis base
// change it if necessary
f->texdef.rotate = -f->texdef.rotate;
Clamp(f->texdef.shift[0], f->d_texture->width);
Clamp(f->texdef.shift[1], f->d_texture->height);
Clamp(f->texdef.rotate, 360);
}
示例8:
void FVMesh3D::complete_data()
{
// initialize the list of cell for each vertex
for(size_t i=0;i<_nb_vertex;i++)
{
_vertex[i].nb_cell=0;
}
// we have to determine the list of neighbor cell for each vertex further
// compute the centroid and length of edge
for(size_t i=0;i<_nb_edge;i++)
{
_edge[i].centroid=(_edge[i].firstVertex->coord+_edge[i].secondVertex->coord)*(double)0.5;
FVPoint3D<double> u;
u=_edge[i].firstVertex->coord-_edge[i].secondVertex->coord;
_edge[i].length=Norm(u);
}
// We have completly finish with the edge
// compute geometric stuff for the face
for(size_t i=0;i<_nb_face;i++)
{
_face[i].perimeter=0.;
_face[i].area=0.;
_face[i].centroid=0.;
// conpute perimeter or the face
for(size_t j=0;j<_face[i].nb_edge;j++)
{
_face[i].perimeter+=_face[i].edge[j]->length;
_face[i].centroid+=_face[i].edge[j]->centroid*_face[i].edge[j]->length;
}
// compute the centroid of the face
_face[i].centroid/=_face[i].perimeter;
// compute the area of the face
for(size_t j=0;j<_face[i].nb_edge;j++)
{
FVPoint3D<double> u,v,w;
u=_face[i].edge[j]->firstVertex->coord-_face[i].centroid;
v=_face[i].edge[j]->secondVertex->coord-_face[i].centroid;
w=CrossProduct(u,v);
_face[i].area+=Norm(w)*0.5;
}
// build the list of vertex pointer for the face
pos_v=0;
for(size_t j=0;j<_face[i].nb_edge;j++)
{
bool _still_exist;
_still_exist=false;
for(size_t k=0;k<pos_v;k++)
if(_face[i].edge[j]->firstVertex==_face[i].vertex[k]) _still_exist=true;
if(!_still_exist) {_face[i].vertex[pos_v]=_face[i].edge[j]->firstVertex;pos_v++;}
_still_exist=false;
for(size_t k=0;k<pos_v;k++)
if(_face[i].edge[j]->secondVertex==_face[i].vertex[k]) _still_exist=true;
if(!_still_exist) {_face[i].vertex[pos_v]=_face[i].edge[j]->secondVertex;pos_v++;}
}
_face[i].nb_vertex=pos_v;
}
// left and right cell, normal vector will be determined after the loop on cells
// end loop on the faces
for(size_t i=0;i<_nb_cell;i++)
{
_cell[i].surface=0.;
_cell[i].volume=0.;
_cell[i].centroid=0.;
// conpute surface of the cell
// determine the left and right cell for the face
for(size_t j=0;j<_cell[i].nb_face;j++)
{
size_t pos;
_cell[i].surface+=_cell[i].face[j]->area;
_cell[i].centroid+=_cell[i].face[j]->centroid*_cell[i].face[j]->area;
pos=_cell[i].face[j]->label-1;
if(!(_face[pos].leftCell) )
_face[pos].leftCell=&(_cell[i]);
else
_face[pos].rightCell=&(_cell[i]);
}
// compute the centroid of the cell
_cell[i].centroid/=_cell[i].surface;
// compute the cell2face vector
// compute the volume of the cell
for(size_t j=0;j<_cell[i].nb_face;j++)
{
_cell[i].cell2face[j]= _cell[i].face[j]->centroid-_cell[i].centroid;
for(size_t k=0;k<_cell[i].face[j]->nb_edge;k++)
{
FVPoint3D<double> u,v,w;
u=_cell[i].cell2face[j];
v=_cell[i].face[j]->edge[k]->firstVertex->coord-_cell[i].centroid;
w=_cell[i].face[j]->edge[k]->secondVertex->coord-_cell[i].centroid;
_cell[i].volume+=fabs(Det(u,v,w))/6;
}
}
// build the list of the vertex pointer for a cell
pos_v=0;
for(size_t j=0;j<_cell[i].nb_face;j++)
for(size_t k=0;k<_cell[i].face[j]->nb_edge;k++)
{
bool _still_exist;
//.........这里部分代码省略.........
示例9: displayRollerCoaster
void displayRollerCoaster()
{
//DISPLAY THE ROLLER COASTER
float a=0.01,f=0.1;
texture = LoadTexture("wood.jpg",256, 256);
glEnable(GL_TEXTURE_2D);
for(float r=0;r<2;r++){
glBegin(GL_QUADS);
for (int j = 0; j < g_iNumOfSplines; j++) {
for(int i=-2;i<g_Splines[j].numControlPoints-1;i++)
{
for(float u=0.0;u<1.0;u+=0.02){
//Point
p.x= CatmullRom(u, g_Splines[j].points[i].x, g_Splines[j].points[i+1].x, g_Splines[j].points[i+2].x, g_Splines[j].points[i+3].x);
p.y= CatmullRom(u, g_Splines[j].points[i].y, g_Splines[j].points[i+1].y, g_Splines[j].points[i+2].y, g_Splines[j].points[i+3].y);
p.z= CatmullRom(u, g_Splines[j].points[i].z, g_Splines[j].points[i+1].z, g_Splines[j].points[i+2].z, g_Splines[j].points[i+3].z);
//Tangent
t.x= CatmullRomTangent(u, g_Splines[j].points[i].x, g_Splines[j].points[i+1].x, g_Splines[j].points[i+2].x, g_Splines[j].points[i+3].x);
t.y= CatmullRomTangent(u, g_Splines[j].points[i].y, g_Splines[j].points[i+1].y, g_Splines[j].points[i+2].y, g_Splines[j].points[i+3].y);
t.z= CatmullRomTangent(u, g_Splines[j].points[i].z, g_Splines[j].points[i+1].z, g_Splines[j].points[i+2].z, g_Splines[j].points[i+3].z);
t = normalize(t);
//Normal
n = CrossProduct(t, v);
n = normalize(n);
//Binormal
b = CrossProduct(t, n);
b = normalize(b);
p1.x= CatmullRom(u+0.02, g_Splines[j].points[i].x, g_Splines[j].points[i+1].x, g_Splines[j].points[i+2].x, g_Splines[j].points[i+3].x);
p1.y= CatmullRom(u+0.02, g_Splines[j].points[i].y, g_Splines[j].points[i+1].y, g_Splines[j].points[i+2].y, g_Splines[j].points[i+3].y);
p1.z= CatmullRom(u+0.02, g_Splines[j].points[i].z, g_Splines[j].points[i+1].z, g_Splines[j].points[i+2].z, g_Splines[j].points[i+3].z);
t1.x= CatmullRomTangent(u+0.02, g_Splines[j].points[i].x, g_Splines[j].points[i+1].x, g_Splines[j].points[i+2].x, g_Splines[j].points[i+3].x);
t1.y= CatmullRomTangent(u+0.02, g_Splines[j].points[i].y, g_Splines[j].points[i+1].y, g_Splines[j].points[i+2].y, g_Splines[j].points[i+3].y);
t1.z= CatmullRomTangent(u+0.02, g_Splines[j].points[i].z, g_Splines[j].points[i+1].z, g_Splines[j].points[i+2].z, g_Splines[j].points[i+3].z);
t1 = normalize(t1);
n1 = CrossProduct(t1, v);
n1 = normalize(n1);
b1 = CrossProduct(t1, n1);
b1 = normalize(b1);
if(r==1)
{
p.x+=f*n.x;
p.y+=f*n.y;
p.z+=f*n.z;
p1.x+=f*n1.x;
p1.y+=f*n1.y;
p1.z+=f*n1.z;
}
glColor3f(1.0, 0.0, 0.0);
//V1
glTexCoord2d(0.0,0.0);glVertex3f(p.x+a*(n.x-b.x),p.y+a*(n.y-b.y),p.z+a*(n.z-b.z));
//V2
glTexCoord2d(1.0,0.0);glVertex3f(p.x+a*(n.x+b.x),p.y+a*(n.y+b.y),p.z+a*(n.z+b.z));
//V3
glTexCoord2d(1.0,1.0);glVertex3f(p.x+a*(-n.x+b.x),p.y+a*(-n.y+b.y),p.z+a*(-n.z+b.z));
//V4
glTexCoord2d(0.0,1.0);glVertex3f(p.x+a*(-n.x-b.x),p.y+a*(-n.y-b.y),p.z+a*(-n.z-b.z));
//V5
glTexCoord2d(0.0,0.0);glVertex3f(p1.x+a*(n1.x-b1.x),p1.y+a*(n1.y-b1.y),p1.z+a*(n1.z-b1.z));
//V6
glTexCoord2d(1.0,0.0);glVertex3f(p1.x+a*(n1.x+b1.x),p1.y+a*(n1.y+b1.y),p1.z+a*(n1.z+b1.z));
//V7
glTexCoord2d(1.0,1.0);glVertex3f(p1.x+a*(-n1.x+b1.x),p1.y+a*(-n1.y+b1.y),p1.z+a*(-n1.z+b1.z));
//V8
glTexCoord2d(0.0,1.0);glVertex3f(p1.x+a*(-n1.x-b1.x),p1.y+a*(-n1.y-b1.y),p1.z+a*(-n1.z-b1.z));
//V1
glTexCoord2d(0.0,0.0);glVertex3f(p.x+a*(n.x-b.x),p.y+a*(n.y-b.y),p.z+a*(n.z-b.z));
//V4
glTexCoord2d(0.0,1.0);glVertex3f(p.x+a*(-n.x-b.x),p.y+a*(-n.y-b.y),p.z+a*(-n.z-b.z));
//V8
glTexCoord2d(0.0,1.0);glVertex3f(p1.x+a*(-n1.x-b1.x),p1.y+a*(-n1.y-b1.y),p1.z+a*(-n1.z-b1.z));
//V5
glTexCoord2d(0.0,0.0);glVertex3f(p1.x+a*(n1.x-b1.x),p1.y+a*(n1.y-b1.y),p1.z+a*(n1.z-b1.z));
//V3
glTexCoord2d(1.0,1.0);glVertex3f(p.x+a*(-n.x+b.x),p.y+a*(-n.y+b.y),p.z+a*(-n.z+b.z));
//V4
glTexCoord2d(0.0,1.0);glVertex3f(p.x+a*(-n.x-b.x),p.y+a*(-n.y-b.y),p.z+a*(-n.z-b.z));
//V8
glTexCoord2d(0.0,1.0);glVertex3f(p1.x+a*(-n1.x-b1.x),p1.y+a*(-n1.y-b1.y),p1.z+a*(-n1.z-b1.z));
//V7
glTexCoord2d(1.0,1.0);glVertex3f(p1.x+a*(-n1.x+b1.x),p1.y+a*(-n1.y+b1.y),p1.z+a*(-n1.z+b1.z));
//V2
glTexCoord2d(1.0,0.0);glVertex3f(p.x+a*(n.x+b.x),p.y+a*(n.y+b.y),p.z+a*(n.z+b.z));
//V3
glTexCoord2d(1.0,1.0);glVertex3f(p.x+a*(-n.x+b.x),p.y+a*(-n.y+b.y),p.z+a*(-n.z+b.z));
//V7
glTexCoord2d(1.0,1.0);glVertex3f(p1.x+a*(-n1.x+b1.x),p1.y+a*(-n1.y+b1.y),p1.z+a*(-n1.z+b1.z));
//V6
glTexCoord2d(1.0,0.0);glVertex3f(p1.x+a*(n1.x+b1.x),p1.y+a*(n1.y+b1.y),p1.z+a*(n1.z+b1.z));
//.........这里部分代码省略.........
示例10: displayRails
void displayRails()
{
//DISPLAY RAILS ON ROLLER COASTER
glColor3f(1.0, 1.0, 1.0);
texture = LoadTexture("wood.jpg",256, 256);
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
for (int j = 0; j < g_iNumOfSplines; j++) {
for(int i=-2;i<g_Splines[j].numControlPoints-1;i++)
{
for(float u=0.0;u<1.0;u+=0.05){
point p,t,n,v,n1,t1,p1;
v.x=0.0;v.y=0.0;v.z=-1.0;
float f=0.1;
//Point
p.x= CatmullRom(u, g_Splines[j].points[i].x, g_Splines[j].points[i+1].x, g_Splines[j].points[i+2].x, g_Splines[j].points[i+3].x);
p.y= CatmullRom(u, g_Splines[j].points[i].y, g_Splines[j].points[i+1].y, g_Splines[j].points[i+2].y, g_Splines[j].points[i+3].y);
p.z= CatmullRom(u, g_Splines[j].points[i].z, g_Splines[j].points[i+1].z, g_Splines[j].points[i+2].z, g_Splines[j].points[i+3].z);
//Tangent
t.x= CatmullRomTangent(u, g_Splines[j].points[i].x, g_Splines[j].points[i+1].x, g_Splines[j].points[i+2].x, g_Splines[j].points[i+3].x);
t.y= CatmullRomTangent(u, g_Splines[j].points[i].y, g_Splines[j].points[i+1].y, g_Splines[j].points[i+2].y, g_Splines[j].points[i+3].y);
t.z= CatmullRomTangent(u, g_Splines[j].points[i].z, g_Splines[j].points[i+1].z, g_Splines[j].points[i+2].z, g_Splines[j].points[i+3].z);
t = normalize(t);
//Normal
n = CrossProduct(t, v);
n = normalize(n);
p1.x= CatmullRom(u+0.01, g_Splines[j].points[i].x, g_Splines[j].points[i+1].x, g_Splines[j].points[i+2].x, g_Splines[j].points[i+3].x);
p1.y= CatmullRom(u+0.01, g_Splines[j].points[i].y, g_Splines[j].points[i+1].y, g_Splines[j].points[i+2].y, g_Splines[j].points[i+3].y);
p1.z= CatmullRom(u+0.01, g_Splines[j].points[i].z, g_Splines[j].points[i+1].z, g_Splines[j].points[i+2].z, g_Splines[j].points[i+3].z);
t1.x= CatmullRomTangent(u+0.01, g_Splines[j].points[i].x, g_Splines[j].points[i+1].x, g_Splines[j].points[i+2].x, g_Splines[j].points[i+3].x);
t1.y= CatmullRomTangent(u+0.01, g_Splines[j].points[i].y, g_Splines[j].points[i+1].y, g_Splines[j].points[i+2].y, g_Splines[j].points[i+3].y);
t1.z= CatmullRomTangent(u+0.01, g_Splines[j].points[i].z, g_Splines[j].points[i+1].z, g_Splines[j].points[i+2].z, g_Splines[j].points[i+3].z);
t1 = normalize(t1);
n1 = CrossProduct(t1, v);
n1 = normalize(n1);
glColor3f(1.0, 1.0, 1.0);
glTexCoord2d(0.0,0.0);glVertex3f(p.x,p.y,p.z);
glTexCoord2d(3,0.0);glVertex3f(p.x+f*(n.x),p.y+f*(n.y),p.z+f*(n.z));
glTexCoord2d(3,1);glVertex3f(p1.x+f*(n1.x),p1.y+f*(n1.y),p1.z+f*(n1.z));
glTexCoord2d(0.0,1);glVertex3f(p1.x,p1.y,p1.z);
glColor3f(1.0, 1.0, 1.0);
glTexCoord2d(0.0,0.0);glVertex3f(p.x,p.y,p.z-0.003);
glTexCoord2d(3.0,0.0);glVertex3f(p.x+f*(n.x),p.y+f*(n.y),p.z+f*(n.z)-0.003);
glTexCoord2d(3.0,1.0);glVertex3f(p1.x+f*(n1.x),p1.y+f*(n1.y),p1.z+f*(n1.z)-0.003);
glTexCoord2d(0.0,1.0);glVertex3f(p1.x,p1.y,p1.z-0.003);
glColor3f(0.8, 0.5, 0.0);
glTexCoord2d(0.0,0.0);glVertex3f(p.x,p.y,p.z);
glTexCoord2d(3.0,0.0);glVertex3f(p.x+f*(n.x),p.y+f*(n.y),p.z+f*(n.z));
glTexCoord2d(3.0,1.0);glVertex3f(p.x+f*(n.x),p.y+f*(n.y),p.z+f*(n.z)-0.003);
glTexCoord2d(0.0,1.0);glVertex3f(p.x,p.y,p.z-0.003);
glColor3f(1.0, 1.0, 1.0);
glTexCoord2d(0.0,0.0);glVertex3f(p1.x,p1.y,p1.z);
glTexCoord2d(3.0,0.0);glVertex3f(p1.x+f*(n1.x),p1.y+f*(n1.y),p1.z+f*(n1.z));
glTexCoord2d(3.0,1.0);glVertex3f(p1.x+f*(n1.x),p1.y+f*(n1.y),p1.z+f*(n1.z)-0.003);
glTexCoord2d(0.0,1.0);glVertex3f(p1.x,p1.y,p1.z-0.003);
}
}
}
glEnd();
glDisable(GL_TEXTURE_2D);
}
示例11: DrawBoingBallBand
/*****************************************************************************
* Draw a faceted latitude band of the Boing ball.
*
* Parms: long_lo, long_hi
* Low and high longitudes of slice, resp.
*****************************************************************************/
void DrawBoingBallBand( GLfloat long_lo,
GLfloat long_hi )
{
vertex_t vert_ne; /* "ne" means south-east, so on */
vertex_t vert_nw;
vertex_t vert_sw;
vertex_t vert_se;
vertex_t vert_norm;
GLfloat lat_deg;
static int colorToggle = 0;
/*
* Iterate thru the points of a latitude circle.
* A latitude circle is a 2D set of X,Z points.
*/
for ( lat_deg = 0;
lat_deg <= (360 - STEP_LATITUDE);
lat_deg += STEP_LATITUDE )
{
/*
* Color this polygon with red or white.
*/
if ( colorToggle )
glColor3f( 0.8f, 0.1f, 0.1f );
else
glColor3f( 0.95f, 0.95f, 0.95f );
#if 0
if ( lat_deg >= 180 )
if ( colorToggle )
glColor3f( 0.1f, 0.8f, 0.1f );
else
glColor3f( 0.5f, 0.5f, 0.95f );
#endif
colorToggle = ! colorToggle;
/*
* Change color if drawing shadow.
*/
if ( drawBallHow == DRAW_BALL_SHADOW )
glColor3f( 0.35f, 0.35f, 0.35f );
/*
* Assign each Y.
*/
vert_ne.y = vert_nw.y = (float) cos_deg(long_hi) * RADIUS;
vert_sw.y = vert_se.y = (float) cos_deg(long_lo) * RADIUS;
/*
* Assign each X,Z with sin,cos values scaled by latitude radius indexed by longitude.
* Eg, long=0 and long=180 are at the poles, so zero scale is sin(longitude),
* while long=90 (sin(90)=1) is at equator.
*/
vert_ne.x = (float) cos_deg( lat_deg ) * (RADIUS * (float) sin_deg( long_lo + STEP_LONGITUDE ));
vert_se.x = (float) cos_deg( lat_deg ) * (RADIUS * (float) sin_deg( long_lo ));
vert_nw.x = (float) cos_deg( lat_deg + STEP_LATITUDE ) * (RADIUS * (float) sin_deg( long_lo + STEP_LONGITUDE ));
vert_sw.x = (float) cos_deg( lat_deg + STEP_LATITUDE ) * (RADIUS * (float) sin_deg( long_lo ));
vert_ne.z = (float) sin_deg( lat_deg ) * (RADIUS * (float) sin_deg( long_lo + STEP_LONGITUDE ));
vert_se.z = (float) sin_deg( lat_deg ) * (RADIUS * (float) sin_deg( long_lo ));
vert_nw.z = (float) sin_deg( lat_deg + STEP_LATITUDE ) * (RADIUS * (float) sin_deg( long_lo + STEP_LONGITUDE ));
vert_sw.z = (float) sin_deg( lat_deg + STEP_LATITUDE ) * (RADIUS * (float) sin_deg( long_lo ));
/*
* Draw the facet.
*/
glBegin( GL_POLYGON );
CrossProduct( vert_ne, vert_nw, vert_sw, &vert_norm );
glNormal3f( vert_norm.x, vert_norm.y, vert_norm.z );
glVertex3f( vert_ne.x, vert_ne.y, vert_ne.z );
glVertex3f( vert_nw.x, vert_nw.y, vert_nw.z );
glVertex3f( vert_sw.x, vert_sw.y, vert_sw.z );
glVertex3f( vert_se.x, vert_se.y, vert_se.z );
glEnd();
#if BOING_DEBUG
printf( "----------------------------------------------------------- \n" );
printf( "lat = %f long_lo = %f long_hi = %f \n", lat_deg, long_lo, long_hi );
printf( "vert_ne x = %.8f y = %.8f z = %.8f \n", vert_ne.x, vert_ne.y, vert_ne.z );
printf( "vert_nw x = %.8f y = %.8f z = %.8f \n", vert_nw.x, vert_nw.y, vert_nw.z );
printf( "vert_se x = %.8f y = %.8f z = %.8f \n", vert_se.x, vert_se.y, vert_se.z );
printf( "vert_sw x = %.8f y = %.8f z = %.8f \n", vert_sw.x, vert_sw.y, vert_sw.z );
#endif
}
/*
* Toggle color so that next band will opposite red/white colors than this one.
*/
colorToggle = ! colorToggle;
/*
//.........这里部分代码省略.........
示例12: RB_DrawSun
/*
==============
RB_DrawSun
FIXME: sun should render behind clouds, so passing dark areas cover it up
==============
*/
void RB_DrawSun(void)
{
float size;
float dist;
vec3_t origin, vec1, vec2;
byte color[4];
if (!tr.sunShader)
{
return;
}
if (!backEnd.skyRenderedThisView)
{
return;
}
if (!r_drawSun->integer)
{
return;
}
qglPushMatrix();
qglLoadMatrixf(backEnd.viewParms.world.modelMatrix);
qglTranslatef(backEnd.viewParms.orientation.origin[0], backEnd.viewParms.orientation.origin[1], backEnd.viewParms.orientation.origin[2]);
dist = backEnd.viewParms.zFar / 1.75; // div sqrt(3)
// shrunk the size of the sun
size = dist * 0.2;
VectorScale(tr.sunDirection, dist, origin);
PerpendicularVector(vec1, tr.sunDirection);
CrossProduct(tr.sunDirection, vec1, vec2);
VectorScale(vec1, size, vec1);
VectorScale(vec2, size, vec2);
// farthest depth range
qglDepthRange(1.0, 1.0);
color[0] = color[1] = color[2] = color[3] = 255;
// simpler sun drawing
RB_BeginSurface(tr.sunShader, tess.fogNum);
RB_AddQuadStamp(origin, vec1, vec2, color);
/*
// vec3_t temp; init moved down
VectorCopy( origin, temp );
VectorSubtract( temp, vec1, temp );
VectorSubtract( temp, vec2, temp );
VectorCopy( temp, tess.xyz[tess.numVertexes].v );
tess.texCoords0[tess.numVertexes].v[0] = 0;
tess.texCoords0[tess.numVertexes].v[1] = 0;
tess.vertexColors[tess.numVertexes].v[0] = 255;
tess.vertexColors[tess.numVertexes].v[1] = 255;
tess.vertexColors[tess.numVertexes].v[2] = 255;
tess.numVertexes++;
VectorCopy( origin, temp );
VectorAdd( temp, vec1, temp );
VectorSubtract( temp, vec2, temp );
VectorCopy( temp, tess.xyz[tess.numVertexes].v );
tess.texCoords0[tess.numVertexes].v[0] = 0;
tess.texCoords0[tess.numVertexes].v[1] = 1;
tess.vertexColors[tess.numVertexes].v[0] = 255;
tess.vertexColors[tess.numVertexes].v[1] = 255;
tess.vertexColors[tess.numVertexes].v[2] = 255;
tess.numVertexes++;
VectorCopy( origin, temp );
VectorAdd( temp, vec1, temp );
VectorAdd( temp, vec2, temp );
VectorCopy( temp, tess.xyz[tess.numVertexes].v );
tess.texCoords0[tess.numVertexes].v[0] = 1;
tess.texCoords0[tess.numVertexes].v[1] = 1;
tess.vertexColors[tess.numVertexes].v[0] = 255;
tess.vertexColors[tess.numVertexes].v[1] = 255;
tess.vertexColors[tess.numVertexes].v[2] = 255;
tess.numVertexes++;
VectorCopy( origin, temp );
VectorSubtract( temp, vec1, temp );
VectorAdd( temp, vec2, temp );
VectorCopy( temp, tess.xyz[tess.numVertexes].v );
tess.texCoords0[tess.numVertexes].v[0] = 1;
tess.texCoords0[tess.numVertexes].v[1] = 0;
tess.vertexColors[tess.numVertexes].v[0] = 255;
tess.vertexColors[tess.numVertexes].v[1] = 255;
tess.vertexColors[tess.numVertexes].v[2] = 255;
tess.numVertexes++;
tess.indexes[tess.numIndexes++] = 0;
tess.indexes[tess.numIndexes++] = 1;
tess.indexes[tess.numIndexes++] = 2;
//.........这里部分代码省略.........
示例13: DrawSprite
//-----------------------------------------------------------------------------
// Assumes the material has already been bound
//-----------------------------------------------------------------------------
void DrawSprite( const Vector &vecOrigin, float flWidth, float flHeight, color32 color )
{
unsigned char pColor[4] = { color.r, color.g, color.b, color.a };
// Generate half-widths
flWidth *= 0.5f;
flHeight *= 0.5f;
// Compute direction vectors for the sprite
Vector fwd, right( 1, 0, 0 ), up( 0, 1, 0 );
VectorSubtract( CurrentViewOrigin(), vecOrigin, fwd );
float flDist = VectorNormalize( fwd );
if (flDist >= 1e-3)
{
CrossProduct( CurrentViewUp(), fwd, right );
flDist = VectorNormalize( right );
if (flDist >= 1e-3)
{
CrossProduct( fwd, right, up );
}
else
{
// In this case, fwd == g_vecVUp, it's right above or
// below us in screen space
CrossProduct( fwd, CurrentViewRight(), up );
VectorNormalize( up );
CrossProduct( up, fwd, right );
}
}
CMeshBuilder meshBuilder;
Vector point;
CMatRenderContextPtr pRenderContext( materials );
IMesh* pMesh = pRenderContext->GetDynamicMesh( );
meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 );
meshBuilder.Color4ubv (pColor);
meshBuilder.TexCoord2f (0, 0, 1);
VectorMA (vecOrigin, -flHeight, up, point);
VectorMA (point, -flWidth, right, point);
meshBuilder.Position3fv (point.Base());
meshBuilder.AdvanceVertex();
meshBuilder.Color4ubv (pColor);
meshBuilder.TexCoord2f (0, 0, 0);
VectorMA (vecOrigin, flHeight, up, point);
VectorMA (point, -flWidth, right, point);
meshBuilder.Position3fv (point.Base());
meshBuilder.AdvanceVertex();
meshBuilder.Color4ubv (pColor);
meshBuilder.TexCoord2f (0, 1, 0);
VectorMA (vecOrigin, flHeight, up, point);
VectorMA (point, flWidth, right, point);
meshBuilder.Position3fv (point.Base());
meshBuilder.AdvanceVertex();
meshBuilder.Color4ubv (pColor);
meshBuilder.TexCoord2f (0, 1, 1);
VectorMA (vecOrigin, -flHeight, up, point);
VectorMA (point, flWidth, right, point);
meshBuilder.Position3fv (point.Base());
meshBuilder.AdvanceVertex();
meshBuilder.End();
pMesh->Draw();
}
示例14: RB_DrawSun
/*
** RB_DrawSun
*/
void RB_DrawSun( void ) {
float size;
float dist;
vec3_t origin, vec1, vec2;
vec3_t temp;
if ( !backEnd.skyRenderedThisView ) {
return;
}
if ( !r_drawSun->integer ) {
return;
}
qglLoadMatrixf( backEnd.viewParms.world.modelMatrix );
qglTranslatef (backEnd.viewParms.ori.origin[0], backEnd.viewParms.ori.origin[1], backEnd.viewParms.ori.origin[2]);
dist = backEnd.viewParms.zFar / 1.75; // div sqrt(3)
size = dist * 0.4;
VectorScale( tr.sunDirection, dist, origin );
PerpendicularVector( vec1, tr.sunDirection );
CrossProduct( tr.sunDirection, vec1, vec2 );
VectorScale( vec1, size, vec1 );
VectorScale( vec2, size, vec2 );
// farthest depth range
qglDepthRange( 1.0, 1.0 );
// FIXME: use quad stamp
RB_BeginSurface( tr.sunShader, tess.fogNum );
VectorCopy( origin, temp );
VectorSubtract( temp, vec1, temp );
VectorSubtract( temp, vec2, temp );
VectorCopy( temp, tess.xyz[tess.numVertexes] );
tess.texCoords[tess.numVertexes][0][0] = 0;
tess.texCoords[tess.numVertexes][0][1] = 0;
tess.vertexColors[tess.numVertexes][0] = 255;
tess.vertexColors[tess.numVertexes][1] = 255;
tess.vertexColors[tess.numVertexes][2] = 255;
tess.numVertexes++;
VectorCopy( origin, temp );
VectorAdd( temp, vec1, temp );
VectorSubtract( temp, vec2, temp );
VectorCopy( temp, tess.xyz[tess.numVertexes] );
tess.texCoords[tess.numVertexes][0][0] = 0;
tess.texCoords[tess.numVertexes][0][1] = 1;
tess.vertexColors[tess.numVertexes][0] = 255;
tess.vertexColors[tess.numVertexes][1] = 255;
tess.vertexColors[tess.numVertexes][2] = 255;
tess.numVertexes++;
VectorCopy( origin, temp );
VectorAdd( temp, vec1, temp );
VectorAdd( temp, vec2, temp );
VectorCopy( temp, tess.xyz[tess.numVertexes] );
tess.texCoords[tess.numVertexes][0][0] = 1;
tess.texCoords[tess.numVertexes][0][1] = 1;
tess.vertexColors[tess.numVertexes][0] = 255;
tess.vertexColors[tess.numVertexes][1] = 255;
tess.vertexColors[tess.numVertexes][2] = 255;
tess.numVertexes++;
VectorCopy( origin, temp );
VectorSubtract( temp, vec1, temp );
VectorAdd( temp, vec2, temp );
VectorCopy( temp, tess.xyz[tess.numVertexes] );
tess.texCoords[tess.numVertexes][0][0] = 1;
tess.texCoords[tess.numVertexes][0][1] = 0;
tess.vertexColors[tess.numVertexes][0] = 255;
tess.vertexColors[tess.numVertexes][1] = 255;
tess.vertexColors[tess.numVertexes][2] = 255;
tess.numVertexes++;
tess.indexes[tess.numIndexes++] = 0;
tess.indexes[tess.numIndexes++] = 1;
tess.indexes[tess.numIndexes++] = 2;
tess.indexes[tess.numIndexes++] = 0;
tess.indexes[tess.numIndexes++] = 2;
tess.indexes[tess.numIndexes++] = 3;
RB_EndSurface();
// back to normal depth range
qglDepthRange( 0.0, 1.0 );
}
示例15: SV_FlyMove
//.........这里部分代码省略.........
}
if (trace.fraction == 1)
{
break; /* moved the entire distance */
}
hit = trace.ent;
if (trace.plane.normal[2] > 0.7)
{
blocked |= 1; /* floor */
if (hit->solid == SOLID_BSP)
{
ent->groundentity = hit;
ent->groundentity_linkcount = hit->linkcount;
}
}
if (!trace.plane.normal[2])
{
blocked |= 2; /* step */
}
/* run the impact function */
SV_Impact(ent, &trace);
if (!ent->inuse)
{
break; /* removed by the impact function */
}
time_left -= time_left * trace.fraction;
/* cliped to another plane */
if (numplanes >= MAX_CLIP_PLANES)
{
/* this shouldn't really happen */
VectorCopy(vec3_origin, ent->velocity);
return 3;
}
VectorCopy(trace.plane.normal, planes[numplanes]);
numplanes++;
/* modify original_velocity so it
parallels all of the clip planes */
for (i = 0; i < numplanes; i++)
{
ClipVelocity(original_velocity, planes[i], new_velocity, 1);
for (j = 0; j < numplanes; j++)
{
if ((j != i) && !VectorCompare(planes[i], planes[j]))
{
if (DotProduct(new_velocity, planes[j]) < 0)
{
break; /* not ok */
}
}
}
if (j == numplanes)
{
break;
}
}
if (i != numplanes)
{
/* go along this plane */
VectorCopy(new_velocity, ent->velocity);
}
else
{
/* go along the crease */
if (numplanes != 2)
{
VectorCopy(vec3_origin, ent->velocity);
return 7;
}
CrossProduct(planes[0], planes[1], dir);
d = DotProduct(dir, ent->velocity);
VectorScale(dir, d, ent->velocity);
}
/* If original velocity is against the original
velocity, stop dead to avoid tiny occilations
in sloping corners */
if (DotProduct(ent->velocity, primal_velocity) <= 0)
{
VectorCopy(vec3_origin, ent->velocity);
return blocked;
}
}
return blocked;
}