/* ================= R_DrawSpriteModel ================= */ EXPORT void R_DrawSpriteModel (entity_t *e, entity_t *currententity, double cltime, vec3_t vup, vec3_t vright) { vec3_t point; mspriteframe_t *frame; float *up, *right; vec3_t v_forward, v_right, v_up; msprite_t *psprite; // don't even bother culling, because it's just a single // polygon without a surface cache frame = R_GetSpriteFrame( e, cltime ); psprite = currententity->model->cache.data; if (psprite->type == SPR_ORIENTED) { // bullet marks on walls dr_AngleVectors (currententity->angles, v_forward, v_right, v_up); up = v_up; right = v_right; } else { // normal sprite up = vup; right = vright; } glColor3f (1,1,1); dr_GL_DisableMultitexture(); dr_GL_Bind(frame->gl_texturenum); glEnable (GL_ALPHA_TEST); glBegin (GL_QUADS); glTexCoord2f (0, 1); dr_VectorMA (e->origin, frame->down, up, point); dr_VectorMA (point, frame->left, right, point); glVertex3fv (point); glTexCoord2f (0, 0); dr_VectorMA (e->origin, frame->up, up, point); dr_VectorMA (point, frame->left, right, point); glVertex3fv (point); glTexCoord2f (1, 0); dr_VectorMA (e->origin, frame->up, up, point); dr_VectorMA (point, frame->right, right, point); glVertex3fv (point); glTexCoord2f (1, 1); dr_VectorMA (e->origin, frame->down, up, point); dr_VectorMA (point, frame->right, right, point); glVertex3fv (point); glEnd (); glDisable (GL_ALPHA_TEST); }
int R_GetSpriteTexture( const model_t *m_pSpriteModel, int frame ) { if( !m_pSpriteModel || m_pSpriteModel->type != mod_sprite || !m_pSpriteModel->cache.data ) return 0; return R_GetSpriteFrame( m_pSpriteModel, frame, 0.0f )->gl_texturenum; }
/* ============= R_GetSpriteParms same as GetImageParms but used for sprite models ============= */ void R_GetSpriteParms( int *frameWidth, int *frameHeight, int *numFrames, int currentFrame, const model_t *pSprite ) { mspriteframe_t *pFrame; if( !pSprite || pSprite->type != mod_sprite ) return; // bad model ? pFrame = R_GetSpriteFrame( pSprite, currentFrame, 0.0f ); if( frameWidth ) *frameWidth = pFrame->width; if( frameHeight ) *frameHeight = pFrame->height; if( numFrames ) *numFrames = pSprite->numframes; }
/* ================= R_DrawSpriteModel ================= */ void R_DrawSpriteModel (entity_t *e) { vec3_t point; mspriteframe_t *frame; float *up, *right; vec3_t v_forward, v_right, v_up; msprite_t *psprite; // 2001-12-15 Oriented sprites fix by Atomizer start vec3_t fixed_origin; vec3_t temp; // 2001-12-15 Oriented sprites fix by Atomizer end // don't even bother culling, because it's just a single // polygon without a surface cache frame = R_GetSpriteFrame (e); psprite = currententity->model->cache.data; VectorCopy(e->origin,fixed_origin); // 2001-12-15 Oriented sprites fix by Atomizer if (psprite->type == SPR_ORIENTED) { // bullet marks on walls AngleVectors (currententity->angles, v_forward, v_right, v_up); // 2001-12-15 Oriented sprites fix by Atomizer start VectorScalarMult(v_forward,-2,temp); VectorAdd(temp,fixed_origin,fixed_origin); // 2001-12-15 Oriented sprites fix by Atomizer end up = v_up; right = v_right; } else { // normal sprite up = vup; right = vright; } glColor3f (1,1,1); GL_DisableMultitexture(); GL_Bind(frame->gl_texturenum); glEnable (GL_ALPHA_TEST); glBegin (GL_QUADS); glTexCoord2f (0, 1); // 2001-12-15 Oriented sprites fix by Atomizer start // VectorMA (e->origin, frame->down, up, point); VectorMA (fixed_origin, frame->down, up, point); // 2001-12-15 Oriented sprites fix by Atomizer end VectorMA (point, frame->left, right, point); glVertex3fv (point); glTexCoord2f (0, 0); // 2001-12-15 Oriented sprites fix by Atomizer start // VectorMA (e->origin, frame->up, up, point); VectorMA (fixed_origin, frame->up, up, point); // 2001-12-15 Oriented sprites fix by Atomizer end VectorMA (point, frame->left, right, point); glVertex3fv (point); glTexCoord2f (1, 0); // 2001-12-15 Oriented sprites fix by Atomizer start // VectorMA (e->origin, frame->up, up, point); VectorMA (fixed_origin, frame->up, up, point); // 2001-12-15 Oriented sprites fix by Atomizer end VectorMA (point, frame->right, right, point); glVertex3fv (point); glTexCoord2f (1, 1); // 2001-12-15 Oriented sprites fix by Atomizer start // VectorMA (e->origin, frame->down, up, point); VectorMA (fixed_origin, frame->down, up, point); // 2001-12-15 Oriented sprites fix by Atomizer end VectorMA (point, frame->right, right, point); glVertex3fv (point); glEnd (); glDisable (GL_ALPHA_TEST); }
/* ================= R_DrawSpriteModel ================= */ void R_DrawSpriteModel (entity_t *e) { //vec3_t point; mspriteframe_t *frame; float *up, *right; vec3_t v_forward, v_right, v_up; msprite_t *psprite; // don't even bother culling, because it's just a single // polygon without a surface cache frame = R_GetSpriteFrame (e); psprite = currententity->model->cache.data; if (psprite->type == SPR_ORIENTED) { // bullet marks on walls AngleVectors (currententity->angles, v_forward, v_right, v_up); up = v_up; right = v_right; } else { // normal sprite up = vup; right = vright; } glColor4ub (255,255,255,255); GL_DisableMultitexture(); GL_Bind(frame->gl_texturenum); glEnable (GL_ALPHA_TEST); #ifdef ESQUAKE float quadTexCoord[] = { 0, 1, 0, 0, 1, 0, 1, 1 }; float quadVertices3[3*4]; vec_t * pVec = quadVertices3; VectorMA (e->origin, frame->down, up, pVec); VectorMA (pVec, frame->left, right, pVec); pVec += 3; VectorMA (e->origin, frame->up, up, pVec); VectorMA (pVec, frame->left, right, pVec); pVec += 3; VectorMA (e->origin, frame->up, up, pVec); VectorMA (pVec, frame->right, right, pVec); pVec += 3; VectorMA (e->origin, frame->down, up, pVec); VectorMA (pVec, frame->right, right, pVec); glTexCoordPointer(2, GL_FLOAT, sizeof(GLfloat)*2, quadTexCoord); glVertexPointer(3, GL_FLOAT, sizeof(GLfloat)*3, quadVertices3); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); #else glBegin (GL_QUADS); glTexCoord2f (0, 1); VectorMA (e->origin, frame->down, up, point); VectorMA (point, frame->left, right, point); glVertex3fv (point); glTexCoord2f (0, 0); VectorMA (e->origin, frame->up, up, point); VectorMA (point, frame->left, right, point); glVertex3fv (point); glTexCoord2f (1, 0); VectorMA (e->origin, frame->up, up, point); VectorMA (point, frame->right, right, point); glVertex3fv (point); glTexCoord2f (1, 1); VectorMA (e->origin, frame->down, up, point); VectorMA (point, frame->right, right, point); glVertex3fv (point); glEnd (); #endif glDisable (GL_ALPHA_TEST); }
/* ================= R_DrawSpriteModel -- johnfitz -- rewritten: now supports all orientations ================= */ void R_DrawSpriteModel (entity_t *e) { vec3_t point, v_forward, v_right, v_up; msprite_t *psprite; mspriteframe_t *frame; float *s_up, *s_right; float angle, sr, cr; //TODO: frustum cull it? frame = R_GetSpriteFrame (e); psprite = (msprite_t *) currententity->model->cache.data; switch(psprite->type) { case SPR_VP_PARALLEL_UPRIGHT: //faces view plane, up is towards the heavens v_up[0] = 0; v_up[1] = 0; v_up[2] = 1; s_up = v_up; s_right = vright; break; case SPR_FACING_UPRIGHT: //faces camera origin, up is towards the heavens VectorSubtract(currententity->origin, r_origin, v_forward); v_forward[2] = 0; VectorNormalizeFast(v_forward); v_right[0] = v_forward[1]; v_right[1] = -v_forward[0]; v_right[2] = 0; v_up[0] = 0; v_up[1] = 0; v_up[2] = 1; s_up = v_up; s_right = v_right; break; case SPR_VP_PARALLEL: //faces view plane, up is towards the top of the screen s_up = vup; s_right = vright; break; case SPR_ORIENTED: //pitch yaw roll are independent of camera AngleVectors (currententity->angles, v_forward, v_right, v_up); s_up = v_up; s_right = v_right; break; case SPR_VP_PARALLEL_ORIENTED: //faces view plane, but obeys roll value angle = currententity->angles[ROLL] * M_PI_DIV_180; sr = sin(angle); cr = cos(angle); v_right[0] = vright[0] * cr + vup[0] * sr; v_right[1] = vright[1] * cr + vup[1] * sr; v_right[2] = vright[2] * cr + vup[2] * sr; v_up[0] = vright[0] * -sr + vup[0] * cr; v_up[1] = vright[1] * -sr + vup[1] * cr; v_up[2] = vright[2] * -sr + vup[2] * cr; s_up = v_up; s_right = v_right; break; default: return; } //johnfitz: offset decals if (psprite->type == SPR_ORIENTED) GL_PolygonOffset (OFFSET_DECAL); glColor3f (1,1,1); GL_DisableMultitexture(); GL_Bind(frame->gltexture); glEnable (GL_ALPHA_TEST); glBegin (GL_TRIANGLE_FAN); //was GL_QUADS, but changed to support r_showtris glTexCoord2f (0, frame->tmax); VectorMA (e->origin, frame->down, s_up, point); VectorMA (point, frame->left, s_right, point); glVertex3fv (point); glTexCoord2f (0, 0); VectorMA (e->origin, frame->up, s_up, point); VectorMA (point, frame->left, s_right, point); glVertex3fv (point); glTexCoord2f (frame->smax, 0); VectorMA (e->origin, frame->up, s_up, point); VectorMA (point, frame->right, s_right, point); glVertex3fv (point); glTexCoord2f (frame->smax, frame->tmax); VectorMA (e->origin, frame->down, s_up, point); VectorMA (point, frame->right, s_right, point); glVertex3fv (point); glEnd (); glDisable (GL_ALPHA_TEST); //johnfitz: offset decals if (psprite->type == SPR_ORIENTED) GL_PolygonOffset (OFFSET_NONE); }
/* ================= R_DrawSpriteModel ================= */ void R_DrawSpriteModel (entity_t *e) { vec3_t point; mspriteframe_t *frame; float *up, *right; vec3_t v_forward, v_right, v_up; msprite_t *psprite; // don't even bother culling, because it's just a single // polygon without a surface cache frame = R_GetSpriteFrame (e); psprite = (msprite_t*) currententity->model->cache.data; if (psprite->type == SPR_ORIENTED) { // bullet marks on walls AngleVectors (currententity->angles, v_forward, v_right, v_up); up = v_up; right = v_right; } else { // normal sprite up = vup; right = vright; } glColor3f (1,1,1); GL_DisableMultitexture(); GL_Bind(frame->gl_texturenum); glEnable (GL_ALPHA_TEST); #ifdef USE_OPENGLES { float* pPoint = gVertexBuffer; float texCoords[] = { 0, 1, 0, 0, 1, 0, 1, 1 }; VectorMA (e->origin, frame->down, up, point); VectorMA (point, frame->left, right, pPoint); pPoint += 3; VectorMA (e->origin, frame->up, up, point); VectorMA (point, frame->left, right, pPoint); pPoint += 3; VectorMA (e->origin, frame->up, up, point); VectorMA (point, frame->right, right, pPoint); pPoint += 3; VectorMA (e->origin, frame->down, up, point); VectorMA (point, frame->right, right, pPoint); glVertexPointer(3, GL_FLOAT, 0, gVertexBuffer); glTexCoordPointer(2, GL_FLOAT, 0, texCoords); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); } #else glBegin (GL_QUADS); glTexCoord2f (0, 1); VectorMA (e->origin, frame->down, up, point); VectorMA (point, frame->left, right, point); glVertex3fv (point); glTexCoord2f (0, 0); VectorMA (e->origin, frame->up, up, point); VectorMA (point, frame->left, right, point); glVertex3fv (point); glTexCoord2f (1, 0); VectorMA (e->origin, frame->up, up, point); VectorMA (point, frame->right, right, point); glVertex3fv (point); glTexCoord2f (1, 1); VectorMA (e->origin, frame->down, up, point); VectorMA (point, frame->right, right, point); glVertex3fv (point); glEnd (); #endif glDisable (GL_ALPHA_TEST); }