Skip to content

Commit

Permalink
Fixed drawing of PFT_PATCH textured Pic anims and began work on combi…
Browse files Browse the repository at this point in the history
…ning the logic branches of FIData_PicDrawer.
  • Loading branch information
danij-deng committed Jul 18, 2010
1 parent fa6daac commit a1aa98c
Show file tree
Hide file tree
Showing 3 changed files with 274 additions and 73 deletions.
26 changes: 20 additions & 6 deletions doomsday/engine/portable/include/m_vector.h
Expand Up @@ -3,8 +3,8 @@
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2004-2009 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2006-2009 Daniel Swanson <danij@dengine.net>
*\author Copyright © 2004-2010 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2006-2010 Daniel Swanson <danij@dengine.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -34,10 +34,14 @@ typedef vectorcomp_t vec2_t[2];
typedef const float const_pvec2_t[2];
typedef vectorcomp_t vec3_t[3];
typedef const float const_pvec3_t[3];
typedef vectorcomp_t vec4_t[4];
typedef const float const_pvec4_t[4];
typedef vectorcomp_t *pvec2_t;
typedef vectorcomp_t *pvec3_t;
typedef vectorcomp_t *pvec4_t;
typedef vec2_t *arvec2_t;
typedef vec3_t *arvec3_t;
typedef vec4_t *arvec4_t;

// 2-dimensions:
void V2_Set(pvec2_t vec, vectorcomp_t x, vectorcomp_t y);
Expand Down Expand Up @@ -70,8 +74,7 @@ void V2_InitBox(arvec2_t box, const pvec2_t point);
void V2_AddToBox(arvec2_t box, const pvec2_t point);

// 3-dimensions:
void V3_Set(pvec3_t vec, vectorcomp_t x, vectorcomp_t y,
vectorcomp_t z);
void V3_Set(pvec3_t vec, vectorcomp_t x, vectorcomp_t y, vectorcomp_t z);
void V3_SetFixed(pvec3_t vec, fixed_t x, fixed_t y, fixed_t z);
float V3_Length(const pvec3_t vec);
float V3_Distance(const pvec3_t a, const pvec3_t b);
Expand All @@ -92,7 +95,18 @@ float V3_ClosestPointOnPlane(pvec3_t dest,
const pvec3_t arbPoint);
int V3_MajorAxis(const pvec3_t vec);
boolean V3_IsZero(const pvec3_t vec);
void V3_Lerp(pvec3_t dest, const pvec3_t a, const pvec3_t b,
float c);
void V3_Lerp(pvec3_t dest, const pvec3_t a, const pvec3_t b, float c);

// 4-dimensions:
void V4_Set(pvec4_t vec, vectorcomp_t x, vectorcomp_t y, vectorcomp_t z, vectorcomp_t w);
void V4_SetFixed(pvec4_t vec, fixed_t x, fixed_t y, fixed_t z, fixed_t w);
float V4_Length(const pvec4_t vec);
float V4_Distance(const pvec4_t a, const pvec4_t b);
float V4_Normalize(pvec4_t vec);
void V4_Copy(pvec4_t dest, const_pvec4_t src);
void V4_Scale(pvec4_t vec, float scalar);
void V4_Sum(pvec4_t dest, const_pvec4_t src1, const_pvec4_t src2);
void V4_Subtract(pvec4_t dest, const_pvec4_t src1, const_pvec4_t src2);
boolean V4_IsZero(const pvec4_t vec);
void V4_Lerp(pvec4_t dest, const pvec4_t a, const pvec4_t b, float c);
#endif
198 changes: 131 additions & 67 deletions doomsday/engine/portable/src/fi_main.c
Expand Up @@ -1728,73 +1728,11 @@ static void drawPicFrame(fidata_pic_t* p, uint frame, float xOffset, float yOffs
if(p->numFrames && frame < p->numFrames)
{
fidata_pic_frame_t* f = p->frames[frame];
if(f->type == PFT_PATCH)
{
patchtex_t* patch;
if((patch = R_FindPatchTex(f->texRef.patch)))
{
DGLuint tex = GL_PreparePatch(patch);
float origin[3], toTopLeft[3], scale[3], angle;

// Calculate the offset to the top left of the patch, to center
// it at the offset as defined in the Patch definition.
toTopLeft[VX] = patch->width / 2 - patch->offX;
toTopLeft[VY] = patch->height / 2 - patch->offY;
toTopLeft[VZ] = 0;
if(patch->flags & PF_UPSCALE_AND_SHARPEN)
{
toTopLeft[VX] += -1;
toTopLeft[VY] += -1;
}

origin[VX] = p->pos[0].value + toTopLeft[VX] + xOffset;
origin[VY] = p->pos[1].value + toTopLeft[VY] + yOffset;
origin[VZ] = 0;

scale[VX] = (f->flags.flip ? -1 : 1) * p->scale[0].value;
scale[VY] = p->scale[1].value;
scale[VZ] = 0;

angle = p->angle.value;

glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (filterUI ? GL_LINEAR : GL_NEAREST));

// Setup the transformation.
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranslatef(origin[VX], origin[VY], origin[VZ]);

// Counter the VGA aspect ratio.
if(angle != 0)
{
glScalef(1, 200.0f / 240.0f, 1);
glRotatef(angle, 0, 0, 1);
glScalef(1, 240.0f / 200.0f, 1);
}

// Move to origin.
glTranslatef(-toTopLeft[VX], -toTopLeft[VY], -toTopLeft[VZ]);
glScalef(scale[VX], scale[VY], scale[VZ]);

/// \fixme we could use the color for tinting
/// useColor(p->color, 4);
GL_DrawRect(patch->offX, patch->offY, patch->width, patch->height, 1, 1, 1, 1);

// Restore original transformation.
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
}
return;
}

if(f->type == PFT_RAW)
{
float mid[2];

picRotationOrigin(p, p->curFrame, mid);
picRotationOrigin(p, frame, mid);

// Setup the transformation.
glMatrixMode(GL_MODELVIEW);
Expand All @@ -1806,7 +1744,7 @@ static void drawPicFrame(fidata_pic_t* p, uint frame, float xOffset, float yOffs

// Move to origin.
glTranslatef(-mid[VX], -mid[VY], 0);
glScalef((p->numFrames && p->frames[p->curFrame]->flags.flip ? -1 : 1) * p->scale[0].value, p->scale[1].value, 1);
glScalef((f->flags.flip ? -1 : 1) * p->scale[0].value, p->scale[1].value, 1);

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
Expand All @@ -1826,20 +1764,146 @@ static void drawPicFrame(fidata_pic_t* p, uint frame, float xOffset, float yOffs
glPopMatrix();
return;
}

if(f->type == PFT_PATCH)
{
patchtex_t* patch;
if((patch = R_FindPatchTex(f->texRef.patch)))
{
DGLuint tex = (renderTextures==1? GL_PreparePatch(patch) : 0);
float mid[2], rgba[4], angle = p->angle.value;
rvertex_t rvertices[4];
rcolor_t rcolors[4];
rtexcoord_t rcoords[4];

rgba[CR] = p->color[CR].value;
rgba[CG] = p->color[CG].value;
rgba[CB] = p->color[CB].value;
rgba[CA] = p->color[CA].value;

glBindTexture(GL_TEXTURE_2D, tex);
if(tex)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (filterUI ? GL_LINEAR : GL_NEAREST));
}

mid[VX] = patch->width / 2 - patch->offX;
mid[VY] = patch->height / 2 - patch->offY;

// Setup the transformation.
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranslatef(p->pos[0].value + xOffset, p->pos[1].value + yOffset, 0);
glTranslatef(mid[VX], mid[VY], 0);

// Counter the VGA aspect ratio.
if(angle != 0)
{
glScalef(1, 200.0f / 240.0f, 1);
glRotatef(angle, 0, 0, 1);
glScalef(1, 240.0f / 200.0f, 1);
}

// Move to origin.
glTranslatef(-mid[VX], -mid[VY], 0);
glScalef((f->flags.flip ? -1 : 1) * p->scale[0].value, p->scale[1].value, 1);

/**
* Vertex layout:
*
* 0 - 1
* | / |
* 2 - 3
*/

{
float x = patch->offX, y = patch->offY, w = patch->width, h = patch->height;

V3_Set(rvertices[0].pos, x, y, 0);
V3_Set(rvertices[1].pos, x+w, y, 0);
V3_Set(rvertices[2].pos, x, y+h, 0);
V3_Set(rvertices[3].pos, x+w, y+h, 0);
}

if(tex)
{
V2_Set(rcoords[0].st, 0, 0);
V2_Set(rcoords[1].st, 1, 0);
V2_Set(rcoords[2].st, 0, 1);
V2_Set(rcoords[3].st, 1, 1);
}

V4_Copy(rcolors[0].rgba, rgba);
V4_Copy(rcolors[1].rgba, rgba);
V4_Copy(rcolors[2].rgba, rgba);
V4_Copy(rcolors[3].rgba, rgba);

glBegin(GL_TRIANGLE_STRIP);
if(tex) glTexCoord2fv(rcoords[0].st);
glColor4fv(rcolors[0].rgba);
glVertex3fv(rvertices[0].pos);

if(tex) glTexCoord2fv(rcoords[1].st);
glColor4fv(rcolors[1].rgba);
glVertex3fv(rvertices[1].pos);

if(tex) glTexCoord2fv(rcoords[2].st);
glColor4fv(rcolors[2].rgba);
glVertex3fv(rvertices[2].pos);

if(tex) glTexCoord2fv(rcoords[3].st);
glColor4fv(rcolors[3].rgba);
glVertex3fv(rvertices[3].pos);
glEnd();

// Restore original transformation.
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
return;
}
}
}

// Setup the transformation.
{
float mid[2];

picRotationOrigin(p, p->curFrame, mid);
if(p->numFrames && frame < p->numFrames)
{
fidata_pic_frame_t* f = p->frames[frame];
switch(f->type)
{
case PFT_XIMAGE:
mid[VX] = SCREENWIDTH/2;
mid[VY] = SCREENHEIGHT/2;
break;
case PFT_MATERIAL:
mid[VX] = mid[VY] = 0;
break;
}
}
else
{
mid[VX] = mid[VY] = .5f;
}

mid[VX] *= p->scale[VX].value;
mid[VY] *= p->scale[VY].value;

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranslatef(p->pos[0].value + xOffset, p->pos[1].value + yOffset, 0);
glTranslatef(mid[VX], mid[VY], 0);

rotate(p->angle.value);
// Counter the VGA aspect ratio.
if(p->angle.value != 0)
{
glScalef(1, 200.0f / 240.0f, 1);
glRotatef(p->angle.value, 0, 0, 1);
glScalef(1, 240.0f / 200.0f, 1);
}

// Move to origin.
glTranslatef(-mid[VX], -mid[VY], 0);
Expand Down Expand Up @@ -1881,7 +1945,7 @@ void FIData_PicDraw(fidata_pic_t* p, float xOffset, float yOffset)
{
assert(p);
// Fully transparent pics will not be drawn.
if(p->color[3].value == 0)
if(!(p->color[CA].value > 0))
return;
drawPicFrame(p, p->curFrame, xOffset, yOffset);
}
Expand Down

0 comments on commit a1aa98c

Please sign in to comment.