]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
drawrotpic:
authorsajt <sajt@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 12 Apr 2009 04:44:34 +0000 (04:44 +0000)
committersajt <sajt@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 12 Apr 2009 04:44:34 +0000 (04:44 +0000)
- '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
draw.h
gl_draw.c
mvm_cmds.c
prvm_cmds.c
prvm_cmds.h

index 1bd88363879ae731379cd9f84dcf790ffbec7168..bf8ae0a176cca4951ccdbd731d27b596218f966b 100644 (file)
@@ -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 f2c9f7a8810251bb62c4f68e0585674831ef4eb6..f0af80c681ea45f94268de39a2ca798bfddbd72d 100644 (file)
--- 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,
index 91d866d393a746c0afdd6fbc2e1fcb4e4f70fed5..0ddb11c09e4f6a4c7a838d2aef76fff9a0b8ac83 100644 (file)
--- 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];
index 982a02d00558058cafa4811177af5bf0f88f5f9f..4e909a3ba411468541783b6369c43dac505d09cb 100644 (file)
@@ -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)
index f792d63f9f43db73fa81484cfc9baea6cfb17906..a82c0179d02ebf1cdf2f44dac25fbaf69f5a6895 100644 (file)
@@ -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)
index 16785039b8bbffde3c020646ace109213c4798e1..b0ad650a566cf4e0e564981052e625a8b3f4cbcc 100644 (file)
@@ -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);