[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11868] trunk/blender/source/blender: Patch #7081:

Joshua Leung aligorith at gmail.com
Tue Aug 28 13:29:54 CEST 2007


Revision: 11868
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11868
Author:   aligorith
Date:     2007-08-28 13:29:54 +0200 (Tue, 28 Aug 2007)

Log Message:
-----------
Patch #7081:
Submitted by: David Bryant

This patch adds 2 new drawtypes for empties (circle draws a 2d-circle on the x-z plane, and cube draws a regular cube), and allows empties to be used as custom bone shapes.

I've modified the patch a bit to fix up weird formatting, optimising the circle-drawing method, but the cube-drawing function has been maintained. In the process, I also moved the mesh-specific code in draw_object_instance to draw_object_mesh_instance so that empties can be used by whatever else might use draw_object_instance too.

Modified Paths:
--------------
    trunk/blender/source/blender/makesdna/DNA_object_types.h
    trunk/blender/source/blender/src/buttons_editing.c
    trunk/blender/source/blender/src/drawarmature.c
    trunk/blender/source/blender/src/drawobject.c

Modified: trunk/blender/source/blender/makesdna/DNA_object_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_object_types.h	2007-08-28 11:11:07 UTC (rev 11867)
+++ trunk/blender/source/blender/makesdna/DNA_object_types.h	2007-08-28 11:29:54 UTC (rev 11868)
@@ -325,6 +325,7 @@
 #define OB_PLAINAXES	2
 #define OB_CIRCLE		3
 #define OB_SINGLE_ARROW	4
+#define OB_CUBE			5
 
 /* boundtype */
 #define OB_BOUND_BOX		0

Modified: trunk/blender/source/blender/src/buttons_editing.c
===================================================================
--- trunk/blender/source/blender/src/buttons_editing.c	2007-08-28 11:11:07 UTC (rev 11867)
+++ trunk/blender/source/blender/src/buttons_editing.c	2007-08-28 11:29:54 UTC (rev 11868)
@@ -4521,7 +4521,7 @@
 				xco, 154, 130,20, 0, 0, 0, 0, 0, "");
 		
 		uiBlockBeginAlign(block);
-		uiDefButC(block, MENU, REDRAWVIEW3D, "Empty Drawtype%t|Arrows%x1|Single Arrow%x4|Plain Axes%x2",
+		uiDefButC(block, MENU, REDRAWVIEW3D, "Empty Drawtype%t|Arrows%x1|Single Arrow%x4|Plain Axes%x2|Circle%x3|Cube%x5",
 				xco, 128, 140, 20, &ob->empty_drawtype, 0, 0, 0, 0, "The Empty 3D View display style");
 		uiDefButF(block, NUM, REDRAWVIEW3D, "Size:",
 				xco, 108, 140, 21, &ob->empty_drawsize, 0.01, 10.0, 1, 0, "The size to display the Empty");

Modified: trunk/blender/source/blender/src/drawarmature.c
===================================================================
--- trunk/blender/source/blender/src/drawarmature.c	2007-08-28 11:11:07 UTC (rev 11867)
+++ trunk/blender/source/blender/src/drawarmature.c	2007-08-28 11:29:54 UTC (rev 11868)
@@ -1074,7 +1074,7 @@
 static void draw_custom_bone(Object *ob, int dt, int armflag, int boneflag, unsigned int id, float length)
 {
 	
-	if(ob==NULL || ob->type!=OB_MESH) return;
+	if(ob==NULL) return;
 	
 	glScalef(length, length, length);
 	

Modified: trunk/blender/source/blender/src/drawobject.c
===================================================================
--- trunk/blender/source/blender/src/drawobject.c	2007-08-28 11:11:07 UTC (rev 11867)
+++ trunk/blender/source/blender/src/drawobject.c	2007-08-28 11:29:54 UTC (rev 11868)
@@ -135,6 +135,9 @@
 
 static void draw_bounding_volume(Object *ob);
 
+static void drawcube_size(float size);
+static void drawcircle_size(float size);
+
 /* ************* Setting OpenGL Material ************ */
 
 // Materials start counting at # one....
@@ -264,6 +267,79 @@
 	{ 1.0,  1.0, -1.0},
 };
 
+/* ----------------- OpenGL Circle Drawing - Tables for Optimised Drawing Speed ------------------ */
+/* 32 values of sin function (still same result!) */
+static float sinval[32] = {
+	0.00000000,
+	0.20129852,
+	0.39435585,
+	0.57126821,
+	0.72479278,
+	0.84864425,
+	0.93775213,
+	0.98846832,
+	0.99871650,
+	0.96807711,
+	0.89780453,
+	0.79077573,
+	0.65137248,
+	0.48530196,
+	0.29936312,
+	0.10116832,
+	-0.10116832,
+	-0.29936312,
+	-0.48530196,
+	-0.65137248,
+	-0.79077573,
+	-0.89780453,
+	-0.96807711,
+	-0.99871650,
+	-0.98846832,
+	-0.93775213,
+	-0.84864425,
+	-0.72479278,
+	-0.57126821,
+	-0.39435585,
+	-0.20129852,
+	0.00000000
+};
+
+/* 32 values of cos function (still same result!) */
+static float cosval[32] ={
+	1.00000000,
+	0.97952994,
+	0.91895781,
+	0.82076344,
+	0.68896691,
+	0.52896401,
+	0.34730525,
+	0.15142777,
+	-0.05064916,
+	-0.25065253,
+	-0.44039415,
+	-0.61210598,
+	-0.75875812,
+	-0.87434661,
+	-0.95413925,
+	-0.99486932,
+	-0.99486932,
+	-0.95413925,
+	-0.87434661,
+	-0.75875812,
+	-0.61210598,
+	-0.44039415,
+	-0.25065253,
+	-0.05064916,
+	0.15142777,
+	0.34730525,
+	0.52896401,
+	0.68896691,
+	0.82076344,
+	0.91895781,
+	0.97952994,
+	1.00000000
+};
+
 /* flag is same as for draw_object */
 void drawaxes(float size, int flag, char drawtype)
 {
@@ -322,6 +398,14 @@
 		glEnd();
 		
 		break;
+	case OB_CUBE:
+		drawcube_size(size);
+		break;
+		
+	case OB_CIRCLE:
+		drawcircle_size(size);
+		break;
+	
 	case OB_ARROWS:
 	default:
 		for (axis=0; axis<3; axis++) {
@@ -475,6 +559,31 @@
 	glEnd();
 }
 
+/* draws a cube on given the scaling of the cube, assuming that 
+ * all required matrices have been set (used for drawing empties)
+ */
+static void drawcube_size(float size)
+{
+	glBegin(GL_LINE_STRIP);
+		glVertex3f(-size,-size,-size); glVertex3f(-size,-size,size);glVertex3f(-size,size,size); glVertex3f(-size,size,-size);
+		glVertex3f(-size,-size,-size); glVertex3f(size,-size,-size);glVertex3f(size,-size,size); glVertex3f(size,size,size);
+		glVertex3f(size,size,-size); glVertex3f(size,-size,-size);
+	glEnd();
+
+	glBegin(GL_LINE_STRIP);
+		glVertex3f(-size,-size,size); glVertex3f(size,-size,size);
+	glEnd();
+
+	glBegin(GL_LINE_STRIP);
+		glVertex3f(-size,size,size); glVertex3f(size,size,size);
+	glEnd();
+
+	glBegin(GL_LINE_STRIP);
+		glVertex3f(-size,size,-size); glVertex3f(size,size,-size);
+	glEnd();
+}
+
+/* this is an unused (old) cube-drawing function based on a given size */
 #if 0
 static void drawcube_size(float *size)
 {
@@ -3056,72 +3165,6 @@
 	float vec[3], vx[3], vy[3];
 	int a, tot=32;
 	char inverse=0;
-	/* 32 values of sin function (still same result!) */
-	static float si[32] = {0.00000000,
-		0.20129852,
-		0.39435585,
-		0.57126821,
-		0.72479278,
-		0.84864425,
-		0.93775213,
-		0.98846832,
-		0.99871650,
-		0.96807711,
-		0.89780453,
-		0.79077573,
-		0.65137248,
-		0.48530196,
-		0.29936312,
-		0.10116832,
-		-0.10116832,
-                -0.29936312,
-                -0.48530196,
-                -0.65137248,
-                -0.79077573,
-                -0.89780453,
-                -0.96807711,
-                -0.99871650,
-                -0.98846832,
-                -0.93775213,
-                -0.84864425,
-                -0.72479278,
-                -0.57126821,
-                -0.39435585,
-                -0.20129852,
-		0.00000000};
-	/* 32 values of cos function (still same result!) */
-	static float co[32] ={1.00000000,
-                0.97952994,
-                0.91895781,
-                0.82076344,
-                0.68896691,
-                0.52896401,
-                0.34730525,
-                0.15142777,
-                -0.05064916,
-                -0.25065253,
-                -0.44039415,
-                -0.61210598,
-                -0.75875812,
-                -0.87434661,
-                -0.95413925,
-                -0.99486932,
-                -0.99486932,
-                -0.95413925,
-                -0.87434661,
-                -0.75875812,
-                -0.61210598,
-                -0.44039415,
-                -0.25065253,
-                -0.05064916,
-                0.15142777,
-                0.34730525,
-                0.52896401,
-                0.68896691,
-                0.82076344,
-                0.91895781,
-                0.97952994,
-                1.00000000};
 		
 	if (start < 0) {
 		inverse = 1;
@@ -3141,103 +3184,58 @@
 				start=-a + 1;
 			glBegin(GL_LINES);							
 			glVertex3fv(vec);
-			vec[0]= cent[0] + *(si+a+start) * (vx[0] * (float)a/(float)tot) + *(co+a+start) * (vy[0] * (float)a/(float)tot);
-			vec[1]= cent[1] + *(si+a+start) * (vx[1] * (float)a/(float)tot) + *(co+a+start) * (vy[1] * (float)a/(float)tot);
-			vec[2]= cent[2] + *(si+a+start) * (vx[2] * (float)a/(float)tot) + *(co+a+start) * (vy[2] * (float)a/(float)tot);
+			vec[0]= cent[0] + *(sinval+a+start) * (vx[0] * (float)a/(float)tot) + *(cosval+a+start) * (vy[0] * (float)a/(float)tot);
+			vec[1]= cent[1] + *(sinval+a+start) * (vx[1] * (float)a/(float)tot) + *(cosval+a+start) * (vy[1] * (float)a/(float)tot);
+			vec[2]= cent[2] + *(sinval+a+start) * (vx[2] * (float)a/(float)tot) + *(cosval+a+start) * (vy[2] * (float)a/(float)tot);
 			glVertex3fv(vec);
 			glEnd();
 		}
 	}
 	else {
 		a=0;
-		vec[0]= cent[0] + *(si+a+start) * (vx[0] * (float)(-a+31)/(float)tot) + *(co+a+start) * (vy[0] * (float)(-a+31)/(float)tot);
-		vec[1]= cent[1] + *(si+a+start) * (vx[1] * (float)(-a+31)/(float)tot) + *(co+a+start) * (vy[1] * (float)(-a+31)/(float)tot);
-		vec[2]= cent[2] + *(si+a+start) * (vx[2] * (float)(-a+31)/(float)tot) + *(co+a+start) * (vy[2] * (float)(-a+31)/(float)tot);
+		vec[0]= cent[0] + *(sinval+a+start) * (vx[0] * (float)(-a+31)/(float)tot) + *(cosval+a+start) * (vy[0] * (float)(-a+31)/(float)tot);
+		vec[1]= cent[1] + *(sinval+a+start) * (vx[1] * (float)(-a+31)/(float)tot) + *(cosval+a+start) * (vy[1] * (float)(-a+31)/(float)tot);
+		vec[2]= cent[2] + *(sinval+a+start) * (vx[2] * (float)(-a+31)/(float)tot) + *(cosval+a+start) * (vy[2] * (float)(-a+31)/(float)tot);
 		for(a=0; a<tot; a++) {
 			if (a+start>31)
 				start=-a + 1;
 			glBegin(GL_LINES);							
 			glVertex3fv(vec);
-			vec[0]= cent[0] + *(si+a+start) * (vx[0] * (float)(-a+31)/(float)tot) + *(co+a+start) * (vy[0] * (float)(-a+31)/(float)tot);
-			vec[1]= cent[1] + *(si+a+start) * (vx[1] * (float)(-a+31)/(float)tot) + *(co+a+start) * (vy[1] * (float)(-a+31)/(float)tot);
-			vec[2]= cent[2] + *(si+a+start) * (vx[2] * (float)(-a+31)/(float)tot) + *(co+a+start) * (vy[2] * (float)(-a+31)/(float)tot);
+			vec[0]= cent[0] + *(sinval+a+start) * (vx[0] * (float)(-a+31)/(float)tot) + *(cosval+a+start) * (vy[0] * (float)(-a+31)/(float)tot);
+			vec[1]= cent[1] + *(sinval+a+start) * (vx[1] * (float)(-a+31)/(float)tot) + *(cosval+a+start) * (vy[1] * (float)(-a+31)/(float)tot);
+			vec[2]= cent[2] + *(sinval+a+start) * (vx[2] * (float)(-a+31)/(float)tot) + *(cosval+a+start) * (vy[2] * (float)(-a+31)/(float)tot);
 			glVertex3fv(vec);
 			glEnd();
 		}
 	}
 }
 
+/* draws a circle on x-z plane given the scaling of the circle, assuming that 
+ * all required matrices have been set (used for drawing empties)
+ */
+static void drawcircle_size(float size)
+{
+    float x, y;
+	short degrees;
+
+	glBegin(GL_LINE_LOOP);
+    
+	/* coordinates are: cos(degrees*11.25)=x, sin(degrees*11.25)=y, 0.0f=z */
+	for (degrees=0; degrees<32; degrees++) {
+		x= *(cosval + degrees);
+		y= *(sinval + degrees);
+		
+		glVertex3f(x*size, 0.0f, y*size);
+	}
+	
+	glEnd();
+
+}
+
 void drawcircball(int mode, float *cent, float rad, float tmat[][4])
 {
 	float vec[3], vx[3], vy[3];
 	int a, tot=32;
-
-	/* 32 values of sin function (still same result!) */
-	static float si[32] = {0.00000000,
-		0.20129852,
-		0.39435585,
-		0.57126821,
-		0.72479278,
-		0.84864425,
-		0.93775213,
-		0.98846832,
-		0.99871650,
-		0.96807711,
-		0.89780453,
-		0.79077573,
-		0.65137248,
-		0.48530196,
-		0.29936312,
-		0.10116832,
-		-0.10116832,
-                -0.29936312,
-                -0.48530196,

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list