From 66f008be9b269495cd15f0e0339b32820956a142 Mon Sep 17 00:00:00 2001 From: sajt Date: Sun, 12 Apr 2009 04:44:34 +0000 Subject: [PATCH] drawrotpic: - 'org' is the point on the image to rotate around ('0 0' is top-left) - 'angle' is in degrees, counter-clockwise git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8904 d7cf8633-e32d-0410-b094-e92efae38249 --- clvm_cmds.c | 2 +- draw.h | 2 ++ gl_draw.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ mvm_cmds.c | 2 +- prvm_cmds.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ prvm_cmds.h | 1 + 6 files changed, 103 insertions(+), 2 deletions(-) diff --git a/clvm_cmds.c b/clvm_cmds.c index 1bd88363..bf8ae0a1 100644 --- a/clvm_cmds.c +++ b/clvm_cmds.c @@ -3424,7 +3424,7 @@ VM_drawresetcliparea, // #325 void(void) drawresetcliparea VM_drawcolorcodedstring, // #326 float drawcolorcodedstring(vector position, string text, vector scale, vector rgb, float alpha, float flag) (EXT_CSQC) VM_stringwidth, // #327 // FIXME is this okay? VM_drawsubpic, // #328 // FIXME is this okay? -NULL, // #329 +VM_drawrotpic, // #329 // FIXME is this okay? VM_CL_getstatf, // #330 float(float stnum) getstatf (EXT_CSQC) VM_CL_getstati, // #331 float(float stnum) getstati (EXT_CSQC) VM_CL_getstats, // #332 string(float firststnum) getstats (EXT_CSQC) diff --git a/draw.h b/draw.h index f2c9f7a8..f0af80c6 100644 --- a/draw.h +++ b/draw.h @@ -117,6 +117,8 @@ extern dp_font_t dp_fonts[MAX_FONTS]; // draw an image (or a filled rectangle if pic == NULL) void DrawQ_Pic(float x, float y, cachepic_t *pic, float width, float height, float red, float green, float blue, float alpha, int flags); +// draw a rotated image +void DrawQ_RotPic(float x, float y, cachepic_t *pic, float width, float height, float org_x, float org_y, float angle, float red, float green, float blue, float alpha, int flags); // draw a filled rectangle (slightly faster than DrawQ_Pic with pic = NULL) void DrawQ_Fill(float x, float y, float width, float height, float red, float green, float blue, float alpha, int flags); // draw a text string, diff --git a/gl_draw.c b/gl_draw.c index 91d866d3..0ddb11c0 100644 --- a/gl_draw.c +++ b/gl_draw.c @@ -867,6 +867,59 @@ void DrawQ_Pic(float x, float y, cachepic_t *pic, float width, float height, flo R_Mesh_Draw(0, 4, 0, 2, NULL, polygonelements, 0, 0); } +void DrawQ_RotPic(float x, float y, cachepic_t *pic, float width, float height, float org_x, float org_y, float angle, float red, float green, float blue, float alpha, int flags) +{ + float floats[20]; + float af = DEG2RAD(-angle); // forward + float ar = DEG2RAD(-angle + 90); // right + float sinaf = sin(af); + float cosaf = cos(af); + float sinar = sin(ar); + float cosar = cos(ar); + + _DrawQ_ProcessDrawFlag(flags); + GL_Color(red, green, blue, alpha); + + R_Mesh_VertexPointer(floats, 0, 0); + R_Mesh_ColorPointer(NULL, 0, 0); + R_Mesh_ResetTextureState(); + R_SetupGenericShader(pic != NULL); + if (pic) + { + if (width == 0) + width = pic->width; + if (height == 0) + height = pic->height; + R_Mesh_TexBind(0, R_GetTexture(pic->tex)); + R_Mesh_TexCoordPointer(0, 2, floats + 12, 0, 0); + + floats[12] = 0.0f;floats[13] = 0.0f; + floats[14] = 1.0f;floats[15] = 0.0f; + floats[16] = 1.0f;floats[17] = 1.0f; + floats[18] = 0.0f;floats[19] = 1.0f; + } + + floats[2] = floats[5] = floats[8] = floats[11] = 0; + +// top left + floats[0] = x - cosaf*org_x - cosar*org_y; + floats[1] = y - sinaf*org_x - sinar*org_y; + +// top right + floats[3] = x + cosaf*(width-org_x) - cosar*org_y; + floats[4] = y + sinaf*(width-org_x) - sinar*org_y; + +// bottom right + floats[6] = x + cosaf*(width-org_x) + cosar*(height-org_y); + floats[7] = y + sinaf*(width-org_x) + sinar*(height-org_y); + +// bottom left + floats[9] = x - cosaf*org_x + cosar*(height-org_y); + floats[10] = y - sinaf*org_x + sinar*(height-org_y); + + R_Mesh_Draw(0, 4, 0, 2, NULL, polygonelements, 0, 0); +} + void DrawQ_Fill(float x, float y, float width, float height, float red, float green, float blue, float alpha, int flags) { float floats[12]; diff --git a/mvm_cmds.c b/mvm_cmds.c index 982a02d0..4e909a3b 100644 --- a/mvm_cmds.c +++ b/mvm_cmds.c @@ -1292,7 +1292,7 @@ VM_drawline, // #466 VM_drawcolorcodedstring, // #467 VM_stringwidth, // #468 VM_drawsubpic, // #469 -NULL, // #470 +VM_drawrotpic, // #470 VM_asin, // #471 float(float s) VM_asin (DP_QC_ASINACOSATANATAN2TAN) VM_acos, // #472 float(float c) VM_acos (DP_QC_ASINACOSATANATAN2TAN) VM_atan, // #473 float(float t) VM_atan (DP_QC_ASINACOSATANATAN2TAN) diff --git a/prvm_cmds.c b/prvm_cmds.c index f792d63f..a82c0179 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -3173,6 +3173,51 @@ void VM_drawpic(void) } /* ========= +VM_drawrotpic + +float drawrotpic(vector position, string pic, vector size, vector org, float angle, vector rgb, float alpha, float flag) +========= +*/ +void VM_drawrotpic(void) +{ + const char *picname; + float *size, *pos, *org, *rgb; + int flag; + + VM_SAFEPARMCOUNT(8,VM_drawrotpic); + + picname = PRVM_G_STRING(OFS_PARM1); + VM_CheckEmptyString (picname); + + // is pic cached ? no function yet for that + if(!1) + { + PRVM_G_FLOAT(OFS_RETURN) = -4; + VM_Warning("VM_drawrotpic: %s: %s not cached !\n", PRVM_NAME, picname); + return; + } + + pos = PRVM_G_VECTOR(OFS_PARM0); + size = PRVM_G_VECTOR(OFS_PARM2); + org = PRVM_G_VECTOR(OFS_PARM3); + rgb = PRVM_G_VECTOR(OFS_PARM5); + flag = (int) PRVM_G_FLOAT(OFS_PARM7); + + if(flag < DRAWFLAG_NORMAL || flag >=DRAWFLAG_NUMFLAGS) + { + PRVM_G_FLOAT(OFS_RETURN) = -2; + VM_Warning("VM_drawrotpic: %s: wrong DRAWFLAG %i !\n",PRVM_NAME,flag); + return; + } + + if(pos[2] || size[2] || org[2]) + Con_Printf("VM_drawrotpic: z value from pos/size/org discarded\n"); + + DrawQ_RotPic(pos[0], pos[1], Draw_CachePic(picname), size[0], size[1], org[0], org[1], PRVM_G_FLOAT(OFS_PARM4), rgb[0], rgb[1], rgb[2], PRVM_G_FLOAT(OFS_PARM6), flag); + PRVM_G_FLOAT(OFS_RETURN) = 1; +} +/* +========= VM_drawsubpic float drawsubpic(vector position, vector size, string pic, vector srcPos, vector srcSize, vector rgb, float alpha, float flag) diff --git a/prvm_cmds.h b/prvm_cmds.h index 16785039..b0ad650a 100644 --- a/prvm_cmds.h +++ b/prvm_cmds.h @@ -349,6 +349,7 @@ void VM_drawstring(void); void VM_drawcolorcodedstring(void); void VM_stringwidth(void); void VM_drawpic(void); +void VM_drawrotpic(void); void VM_drawsubpic(void); void VM_drawfill(void); void VM_drawsetcliparea(void); -- 2.39.2