diff options
Diffstat (limited to 'source/blender/editors/space_view3d')
-rw-r--r-- | source/blender/editors/space_view3d/drawarmature.c | 154 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/drawobject.c | 106 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/drawvolume.c | 46 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_draw.c | 337 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_edit.c | 46 |
5 files changed, 349 insertions, 340 deletions
diff --git a/source/blender/editors/space_view3d/drawarmature.c b/source/blender/editors/space_view3d/drawarmature.c index ecf5df4af7c..fc35ab93f70 100644 --- a/source/blender/editors/space_view3d/drawarmature.c +++ b/source/blender/editors/space_view3d/drawarmature.c @@ -85,7 +85,7 @@ enum { PCHAN_COLOR_SPHEREBONE_BASE, /* for the 'stick' of sphere (envelope) bones */ PCHAN_COLOR_SPHEREBONE_END, /* for the ends of sphere (envelope) bones */ PCHAN_COLOR_LINEBONE /* for the middle of line-bones */ -}; +}; /* This function sets the color-set for coloring a certain bone */ static void set_pchan_colorset (Object *ob, bPoseChannel *pchan) @@ -437,43 +437,64 @@ static void draw_bonevert_solid(void) glCallList(displist); } +static float bone_octahedral_verts[6][3]= { + { 0.0f, 0.0f, 0.0f}, + { 0.1f, 0.1f, 0.1f}, + { 0.1f, 0.1f, -0.1f}, + {-0.1f, 0.1f, -0.1f}, + {-0.1f, 0.1f, 0.1f}, + { 0.0f, 1.0f, 0.0f} +}; + +static unsigned int bone_octahedral_wire_sides[8]= {0, 1, 5, 3, 0, 4, 5, 2}; +static unsigned int bone_octahedral_wire_square[8]= {1, 2, 3, 4, 1}; + +static unsigned int bone_octahedral_solid_tris[8][3]= { + {2, 1, 0}, /* bottom */ + {3, 2, 0}, + {4, 3, 0}, + {1, 4, 0}, + + {5, 1, 2}, /* top */ + {5, 2, 3}, + {5, 3, 4}, + {5, 4, 1} +}; + +/* aligned with bone_octahedral_solid_tris */ +static float bone_octahedral_solid_normals[8][3]= { + { 0.70710683f, -0.70710683f, 0.00000000f}, + {-0.00000000f, -0.70710683f, -0.70710683f}, + {-0.70710683f, -0.70710683f, 0.00000000f}, + { 0.00000000f, -0.70710683f, 0.70710683f}, + { 0.99388373f, 0.11043154f, -0.00000000f}, + { 0.00000000f, 0.11043154f, -0.99388373f}, + {-0.99388373f, 0.11043154f, 0.00000000f}, + { 0.00000000f, 0.11043154f, 0.99388373f} +}; + static void draw_bone_octahedral(void) { static GLuint displist=0; if (displist == 0) { - float vec[6][3]; - displist= glGenLists(1); glNewList(displist, GL_COMPILE); - - vec[0][0]= vec[0][1]= vec[0][2]= 0.0f; - vec[5][0]= vec[5][2]= 0.0f; vec[5][1]= 1.0f; - - vec[1][0]= 0.1f; vec[1][2]= 0.1f; vec[1][1]= 0.1f; - vec[2][0]= 0.1f; vec[2][2]= -0.1f; vec[2][1]= 0.1f; - vec[3][0]= -0.1f; vec[3][2]= -0.1f; vec[3][1]= 0.1f; - vec[4][0]= -0.1f; vec[4][2]= 0.1f; vec[4][1]= 0.1f; - + /* Section 1, sides */ - glBegin(GL_LINE_LOOP); - glVertex3fv(vec[0]); - glVertex3fv(vec[1]); - glVertex3fv(vec[5]); - glVertex3fv(vec[3]); - glVertex3fv(vec[0]); - glVertex3fv(vec[4]); - glVertex3fv(vec[5]); - glVertex3fv(vec[2]); - glEnd(); - + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(3, GL_FLOAT, 0, bone_octahedral_verts); + glDrawElements(GL_LINE_LOOP, + sizeof(bone_octahedral_wire_sides)/sizeof(*bone_octahedral_wire_sides), + GL_UNSIGNED_INT, + bone_octahedral_wire_sides); + /* Section 1, square */ - glBegin(GL_LINE_LOOP); - glVertex3fv(vec[1]); - glVertex3fv(vec[2]); - glVertex3fv(vec[3]); - glVertex3fv(vec[4]); - glEnd(); + glDrawElements(GL_LINE_LOOP, + sizeof(bone_octahedral_wire_square)/sizeof(*bone_octahedral_wire_square), + GL_UNSIGNED_INT, + bone_octahedral_wire_square); + glDisableClientState(GL_VERTEX_ARRAY); glEndList(); } @@ -484,59 +505,34 @@ static void draw_bone_octahedral(void) static void draw_bone_solid_octahedral(void) { static GLuint displist=0; - + if (displist == 0) { - float vec[6][3], nor[3]; - + int i; + displist= glGenLists(1); glNewList(displist, GL_COMPILE); - - vec[0][0]= vec[0][1]= vec[0][2]= 0.0f; - vec[5][0]= vec[5][2]= 0.0f; vec[5][1]= 1.0f; - - vec[1][0]= 0.1f; vec[1][2]= 0.1f; vec[1][1]= 0.1f; - vec[2][0]= 0.1f; vec[2][2]= -0.1f; vec[2][1]= 0.1f; - vec[3][0]= -0.1f; vec[3][2]= -0.1f; vec[3][1]= 0.1f; - vec[4][0]= -0.1f; vec[4][2]= 0.1f; vec[4][1]= 0.1f; - - - glBegin(GL_TRIANGLES); - /* bottom */ - normal_tri_v3( nor,vec[2], vec[1], vec[0]); - glNormal3fv(nor); - glVertex3fv(vec[2]); glVertex3fv(vec[1]); glVertex3fv(vec[0]); - - normal_tri_v3( nor,vec[3], vec[2], vec[0]); - glNormal3fv(nor); - glVertex3fv(vec[3]); glVertex3fv(vec[2]); glVertex3fv(vec[0]); - - normal_tri_v3( nor,vec[4], vec[3], vec[0]); - glNormal3fv(nor); - glVertex3fv(vec[4]); glVertex3fv(vec[3]); glVertex3fv(vec[0]); - normal_tri_v3( nor,vec[1], vec[4], vec[0]); - glNormal3fv(nor); - glVertex3fv(vec[1]); glVertex3fv(vec[4]); glVertex3fv(vec[0]); +#if 1 + glBegin(GL_TRIANGLES); + for(i= 0; i < 8; i++) { + glNormal3fv(bone_octahedral_solid_normals[i]); + glVertex3fv(bone_octahedral_verts[bone_octahedral_solid_tris[i][0]]); + glVertex3fv(bone_octahedral_verts[bone_octahedral_solid_tris[i][1]]); + glVertex3fv(bone_octahedral_verts[bone_octahedral_solid_tris[i][2]]); + } - /* top */ - normal_tri_v3( nor,vec[5], vec[1], vec[2]); - glNormal3fv(nor); - glVertex3fv(vec[5]); glVertex3fv(vec[1]); glVertex3fv(vec[2]); - - normal_tri_v3( nor,vec[5], vec[2], vec[3]); - glNormal3fv(nor); - glVertex3fv(vec[5]); glVertex3fv(vec[2]); glVertex3fv(vec[3]); - - normal_tri_v3( nor,vec[5], vec[3], vec[4]); - glNormal3fv(nor); - glVertex3fv(vec[5]); glVertex3fv(vec[3]); glVertex3fv(vec[4]); - - normal_tri_v3( nor,vec[5], vec[4], vec[1]); - glNormal3fv(nor); - glVertex3fv(vec[5]); glVertex3fv(vec[4]); glVertex3fv(vec[1]); - glEnd(); - + +#else /* not working because each vert needs a different normal */ + glEnableClientState(GL_NORMAL_ARRAY); + glEnableClientState(GL_VERTEX_ARRAY); + glNormalPointer(GL_FLOAT, 0, bone_octahedral_solid_normals); + glVertexPointer(3, GL_FLOAT, 0, bone_octahedral_verts); + glDrawElements(GL_TRIANGLES, sizeof(bone_octahedral_solid_tris)/sizeof(unsigned int), GL_UNSIGNED_INT, bone_octahedral_solid_tris); + glDisableClientState(GL_NORMAL_ARRAY); + glDisableClientState(GL_VERTEX_ARRAY); +#endif + glEndList(); } @@ -831,7 +827,7 @@ static void draw_sphere_bone_wire(float smat[][4], float imat[][4], int armflag, if (0.0f != normalize_v3(dirvec)) { float norvech[3], norvect[3], vec[3]; - VECCOPY(vec, dirvec); + copy_v3_v3(vec, dirvec); mul_v3_fl(dirvec, head); cross_v3_v3v3(norvech, dirvec, imat[2]); @@ -1548,7 +1544,7 @@ static void draw_pose_dofs(Object *ob) /* in parent-bone pose, but own restspace */ glPushMatrix(); - VECCOPY(posetrans, pchan->pose_mat[3]); + copy_v3_v3(posetrans, pchan->pose_mat[3]); glTranslatef(posetrans[0], posetrans[1], posetrans[2]); if (pchan->parent) { @@ -1646,7 +1642,7 @@ static void bone_matrix_translate_y(float mat[][4], float y) { float trans[3]; - VECCOPY(trans, mat[1]); + copy_v3_v3(trans, mat[1]); mul_v3_fl(trans, y); add_v3_v3(mat[3], trans); } diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 459a07d03a4..81848b2f0d9 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -139,7 +139,7 @@ static int check_ob_drawface_dot(Scene *sce, View3D *vd, char dt) /* ************* only use while object drawing ************** * or after running ED_view3d_init_mats_rv3d * */ -static void view3d_project_short_clip(ARegion *ar, float *vec, short *adr, int local) +static void view3d_project_short_clip(ARegion *ar, const float vec[3], short *adr, int local) { RegionView3D *rv3d= ar->regiondata; float fx, fy, vec4[4]; @@ -174,7 +174,7 @@ static void view3d_project_short_clip(ARegion *ar, float *vec, short *adr, int l } /* only use while object drawing */ -static void view3d_project_short_noclip(ARegion *ar, float *vec, short *adr) +static void view3d_project_short_noclip(ARegion *ar, const float vec[3], short *adr) { RegionView3D *rv3d= ar->regiondata; float fx, fy, vec4[4]; @@ -837,7 +837,7 @@ static void drawcube_size(float size) /* this is an unused (old) cube-drawing function based on a given size */ #if 0 -static void drawcube_size(float *size) +static void drawcube_size(const float size[3]) { glPushMatrix(); @@ -891,7 +891,7 @@ static void drawshadbuflimits(Lamp *la, float mat[][4]) -static void spotvolume(float *lvec, float *vvec, float inp) +static void spotvolume(float lvec[3], float vvec[3], const float inp) { /* camera is at 0,0,0 */ float temp[3],plane[3],mat1[3][3],mat2[3][3],mat3[3][3],mat4[3][3],q[4],co,si,angle; @@ -920,8 +920,8 @@ static void spotvolume(float *lvec, float *vvec, float inp) normalize_v3(&q[1]); angle = saacos(plane[2])/2.0f; - co = cos(angle); - si = sqrt(1-co*co); + co = cosf(angle); + si = sqrtf(1-co*co); q[0] = co; q[1] *= si; @@ -935,7 +935,7 @@ static void spotvolume(float *lvec, float *vvec, float inp) unit_m3(mat2); co = inp; - si = sqrt(1-inp*inp); + si = sqrtf(1.0f-inp*inp); mat2[0][0] = co; mat2[1][0] = -si; @@ -5079,7 +5079,7 @@ static void draw_textcurs(float textcurs[][2]) set_inverted_drawing(0); } -static void drawspiral(float *cent, float rad, float tmat[][4], int start) +static void drawspiral(const float cent[3], float rad, float tmat[][4], int start) { float vec[3], vx[3], vy[3]; int a, tot=32; @@ -5150,7 +5150,7 @@ static void drawcircle_size(float size) } /* needs fixing if non-identity matrice used */ -static void drawtube(float *vec, float radius, float height, float tmat[][4]) +static void drawtube(const float vec[3], float radius, float height, float tmat[][4]) { float cur[3]; drawcircball(GL_LINE_LOOP, vec, radius, tmat); @@ -5172,7 +5172,7 @@ static void drawtube(float *vec, float radius, float height, float tmat[][4]) glEnd(); } /* needs fixing if non-identity matrice used */ -static void drawcone(float *vec, float radius, float height, float tmat[][4]) +static void drawcone(const float vec[3], float radius, float height, float tmat[][4]) { float cur[3]; @@ -5448,7 +5448,7 @@ static void draw_box(float vec[8][3]) /* uses boundbox, function used by Ketsji */ #if 0 -static void get_local_bounds(Object *ob, float *center, float *size) +static void get_local_bounds(Object *ob, float center[3], float size[3]) { BoundBox *bb= object_get_boundbox(ob); @@ -5885,46 +5885,68 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag) /* which wire color */ if((flag & DRAW_CONSTCOLOR) == 0) { + /* confusing logic here, there are 2 methods of setting the color + * 'colortab[colindex]' and 'theme_id', colindex overrides theme_id. + * + * note: no theme yet for 'colindex' */ + int theme_id= TH_WIRE; + int theme_shade= 0; + project_short(ar, ob->obmat[3], &base->sx); - if( (!scene->obedit) && (G.moving & G_TRANSFORM_OBJ) && (base->flag & (SELECT+BA_WAS_SEL))) UI_ThemeColor(TH_TRANSFORM); + if( (scene->obedit == NULL) && + (G.moving & G_TRANSFORM_OBJ) && + (base->flag & (SELECT+BA_WAS_SEL))) + { + theme_id= TH_TRANSFORM; + } else { - - if(ob->type==OB_LAMP) UI_ThemeColor(TH_LAMP); - else if(ob->type==OB_SPEAKER) UI_ThemeColor(TH_SPEAKER); - else UI_ThemeColor(TH_WIRE); - - if((scene->basact)==base) { - if(base->flag & (SELECT+BA_WAS_SEL)) UI_ThemeColor(TH_ACTIVE); - } - else { - if(base->flag & (SELECT+BA_WAS_SEL)) UI_ThemeColor(TH_SELECT); - } - - // no theme yet + /* Sets the 'colindex' */ if(ob->id.lib) { - if(base->flag & (SELECT+BA_WAS_SEL)) colindex = 4; - else colindex = 3; + colindex= (base->flag & (SELECT+BA_WAS_SEL)) ? 4 : 3; } else if(warning_recursive==1) { if(base->flag & (SELECT+BA_WAS_SEL)) { - if(scene->basact==base) colindex = 8; - else colindex= 7; + colindex= (scene->basact==base) ? 8 : 7; } - else colindex = 6; - } - else if(ob->flag & OB_FROMGROUP) { - if(base->flag & (SELECT+BA_WAS_SEL)) { - if(scene->basact==base) UI_ThemeColor(TH_GROUP_ACTIVE); - else UI_ThemeColorShade(TH_GROUP_ACTIVE, -16); + else { + colindex = 6; } - else UI_ThemeColor(TH_GROUP); - colindex= 0; } + /* Sets the 'theme_id' or fallback to wire */ + else { + if(ob->flag & OB_FROMGROUP) { + if(base->flag & (SELECT+BA_WAS_SEL)) { + /* uses darker active color for non-active + selected*/ + theme_id= TH_GROUP_ACTIVE; - } + if(scene->basact != base) { + theme_shade= -16; + } + } + else { + theme_id= TH_GROUP; + } + } + else { + if(base->flag & (SELECT+BA_WAS_SEL)) { + theme_id= scene->basact == base ? TH_ACTIVE : TH_SELECT; + } + else { + if(ob->type==OB_LAMP) theme_id= TH_LAMP; + else if(ob->type==OB_SPEAKER) theme_id= TH_SPEAKER; + /* fallback to TH_WIRE */ + } + } + } + } - if(colindex) { + /* finally set the color */ + if(colindex == 0) { + if(theme_shade == 0) UI_ThemeColor(theme_id); + else UI_ThemeColorShade(theme_id, theme_shade); + } + else { col= colortab[colindex]; cpack(col); } @@ -6009,7 +6031,6 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag) } if (cu->linewidth != 0.0f) { - cpack(0xff44ff); UI_ThemeColor(TH_WIRE); copy_v3_v3(vec1, ob->orig); copy_v3_v3(vec2, ob->orig); @@ -6028,10 +6049,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag) setlinestyle(3); for (i=0; i<cu->totbox; i++) { if (cu->tb[i].w != 0.0f) { - if (i == (cu->actbox-1)) - UI_ThemeColor(TH_ACTIVE); - else - UI_ThemeColor(TH_WIRE); + UI_ThemeColor(i == (cu->actbox-1) ? TH_ACTIVE : TH_WIRE); vec1[0] = (cu->xof * cu->fsize) + cu->tb[i].x; vec1[1] = (cu->yof * cu->fsize) + cu->tb[i].y + cu->fsize; vec1[2] = 0.001; diff --git a/source/blender/editors/space_view3d/drawvolume.c b/source/blender/editors/space_view3d/drawvolume.c index acdbcb0d06d..8da6f49e089 100644 --- a/source/blender/editors/space_view3d/drawvolume.c +++ b/source/blender/editors/space_view3d/drawvolume.c @@ -154,10 +154,10 @@ static int convex(float *p0, float *up, float *a, float *b) { // Vec3 va = a-p0, vb = b-p0; float va[3], vb[3], tmp[3]; - VECSUB(va, a, p0); - VECSUB(vb, b, p0); + sub_v3_v3v3(va, a, p0); + sub_v3_v3v3(vb, b, p0); cross_v3_v3v3(tmp, va, vb); - return INPR(up, tmp) >= 0; + return dot_v3v3(up, tmp) >= 0; } // copied from gpu_extension.c @@ -280,20 +280,20 @@ void draw_volume(ARegion *ar, GPUTexture *tex, float *min, float *max, int res[3 cv[7][1] = min[1]; cv[7][2] = min[2]; - VECCOPY(edges[0][0], cv[4]); // maxx, maxy, minz - VECCOPY(edges[1][0], cv[5]); // minx, maxy, minz - VECCOPY(edges[2][0], cv[6]); // minx, miny, minz - VECCOPY(edges[3][0], cv[7]); // maxx, miny, minz + copy_v3_v3(edges[0][0], cv[4]); // maxx, maxy, minz + copy_v3_v3(edges[1][0], cv[5]); // minx, maxy, minz + copy_v3_v3(edges[2][0], cv[6]); // minx, miny, minz + copy_v3_v3(edges[3][0], cv[7]); // maxx, miny, minz - VECCOPY(edges[4][0], cv[3]); // maxx, miny, maxz - VECCOPY(edges[5][0], cv[2]); // minx, miny, maxz - VECCOPY(edges[6][0], cv[6]); // minx, miny, minz - VECCOPY(edges[7][0], cv[7]); // maxx, miny, minz + copy_v3_v3(edges[4][0], cv[3]); // maxx, miny, maxz + copy_v3_v3(edges[5][0], cv[2]); // minx, miny, maxz + copy_v3_v3(edges[6][0], cv[6]); // minx, miny, minz + copy_v3_v3(edges[7][0], cv[7]); // maxx, miny, minz - VECCOPY(edges[8][0], cv[1]); // minx, maxy, maxz - VECCOPY(edges[9][0], cv[2]); // minx, miny, maxz - VECCOPY(edges[10][0], cv[6]); // minx, miny, minz - VECCOPY(edges[11][0], cv[5]); // minx, maxy, minz + copy_v3_v3(edges[8][0], cv[1]); // minx, maxy, maxz + copy_v3_v3(edges[9][0], cv[2]); // minx, miny, maxz + copy_v3_v3(edges[10][0], cv[6]); // minx, miny, minz + copy_v3_v3(edges[11][0], cv[5]); // minx, maxy, minz // printf("size x: %f, y: %f, z: %f\n", size[0], size[1], size[2]); // printf("min[2]: %f, max[2]: %f\n", min[2], max[2]); @@ -332,7 +332,7 @@ void draw_volume(ARegion *ar, GPUTexture *tex, float *min, float *max, int res[3 */ // get view vector - VECCOPY(viewnormal, rv3d->viewinv[2]); + copy_v3_v3(viewnormal, rv3d->viewinv[2]); normalize_v3(viewnormal); // find cube vertex that is closest to the viewer @@ -407,10 +407,10 @@ void draw_volume(ARegion *ar, GPUTexture *tex, float *min, float *max, int res[3 if(dd*(float)n > ds) break; - VECCOPY(tmp_point, viewnormal); + copy_v3_v3(tmp_point, viewnormal); mul_v3_fl(tmp_point, -dd*((ds/dd)-(float)n)); - VECADD(tmp_point2, cv[good_index], tmp_point); - d = INPR(tmp_point2, viewnormal); + add_v3_v3v3(tmp_point2, cv[good_index], tmp_point); + d = dot_v3v3(tmp_point2, viewnormal); // printf("my d: %f\n", d); @@ -421,7 +421,7 @@ void draw_volume(ARegion *ar, GPUTexture *tex, float *min, float *max, int res[3 // printf("points: %d\n", numpoints); if (numpoints > 2) { - VECCOPY(p0, points); + copy_v3_v3(p0, points); // sort points to get a convex polygon for(i = 1; i < numpoints - 1; i++) @@ -431,9 +431,9 @@ void draw_volume(ARegion *ar, GPUTexture *tex, float *min, float *max, int res[3 if(!convex(p0, viewnormal, &points[j * 3], &points[i * 3])) { float tmp2[3]; - VECCOPY(tmp2, &points[j * 3]); - VECCOPY(&points[j * 3], &points[i * 3]); - VECCOPY(&points[i * 3], tmp2); + copy_v3_v3(tmp2, &points[j * 3]); + copy_v3_v3(&points[j * 3], &points[i * 3]); + copy_v3_v3(&points[i * 3], tmp2); } } } diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 98768e369cb..ba9faf7682e 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -150,20 +150,22 @@ void circ(float x, float y, float rad) static void view3d_draw_clipping(RegionView3D *rv3d) { BoundBox *bb= rv3d->clipbb; - + if(bb) { + static unsigned int clipping_index[6][4]= {{0, 1, 2, 3}, + {0, 4, 5, 1}, + {4, 7, 6, 5}, + {7, 3, 2, 6}, + {1, 5, 6, 2}, + {7, 4, 0, 3}}; + UI_ThemeColorShade(TH_BACK, -8); - - glBegin(GL_QUADS); - - glVertex3fv(bb->vec[0]); glVertex3fv(bb->vec[1]); glVertex3fv(bb->vec[2]); glVertex3fv(bb->vec[3]); - glVertex3fv(bb->vec[0]); glVertex3fv(bb->vec[4]); glVertex3fv(bb->vec[5]); glVertex3fv(bb->vec[1]); - glVertex3fv(bb->vec[4]); glVertex3fv(bb->vec[7]); glVertex3fv(bb->vec[6]); glVertex3fv(bb->vec[5]); - glVertex3fv(bb->vec[7]); glVertex3fv(bb->vec[3]); glVertex3fv(bb->vec[2]); glVertex3fv(bb->vec[6]); - glVertex3fv(bb->vec[1]); glVertex3fv(bb->vec[5]); glVertex3fv(bb->vec[6]); glVertex3fv(bb->vec[2]); - glVertex3fv(bb->vec[7]); glVertex3fv(bb->vec[4]); glVertex3fv(bb->vec[0]); glVertex3fv(bb->vec[3]); - - glEnd(); + + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(3, GL_FLOAT, 0, bb->vec); + glDrawElements(GL_QUADS, sizeof(clipping_index)/sizeof(unsigned int), GL_UNSIGNED_INT, clipping_index); + glDisableClientState(GL_VERTEX_ARRAY); + } } @@ -194,11 +196,11 @@ static int test_clipping(const float vec[3], float clip[][4]) { float view[3]; copy_v3_v3(view, vec); - - if(0.0f < clip[0][3] + INPR(view, clip[0])) - if(0.0f < clip[1][3] + INPR(view, clip[1])) - if(0.0f < clip[2][3] + INPR(view, clip[2])) - if(0.0f < clip[3][3] + INPR(view, clip[3])) + + if(0.0f < clip[0][3] + dot_v3v3(view, clip[0])) + if(0.0f < clip[1][3] + dot_v3v3(view, clip[1])) + if(0.0f < clip[2][3] + dot_v3v3(view, clip[2])) + if(0.0f < clip[3][3] + dot_v3v3(view, clip[3])) return 0; return 1; @@ -216,36 +218,37 @@ int ED_view3d_test_clipping(RegionView3D *rv3d, const float vec[3], const int lo static void drawgrid_draw(ARegion *ar, float wx, float wy, float x, float y, float dx) { - float v1[2], v2[2]; + float verts[2][2]; x+= (wx); y+= (wy); - v1[1]= 0.0f; - v2[1]= (float)ar->winy; + /* set fixed 'Y' */ + verts[0][1]= 0.0f; + verts[1][1]= (float)ar->winy; - v1[0] = v2[0] = x-dx*floorf(x/dx); - - glBegin(GL_LINES); - - while(v1[0] < ar->winx) { - glVertex2fv(v1); - glVertex2fv(v2); - v1[0] = v2[0] = v1[0] + dx; - } + /* iter over 'X' */ + verts[0][0] = verts[1][0] = x-dx*floorf(x/dx); + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(2, GL_FLOAT, 0, verts); - v1[0]= 0.0f; - v2[0]= (float)ar->winx; + while(verts[0][0] < ar->winx) { + glDrawArrays(GL_LINES, 0, 2); + verts[0][0] = verts[1][0] = verts[0][0] + dx; + } - v1[1]= v2[1]= y-dx*floorf(y/dx); + /* set fixed 'X' */ + verts[0][0]= 0.0f; + verts[1][0]= (float)ar->winx; - while(v1[1] < ar->winy) { - glVertex2fv(v1); - glVertex2fv(v2); - v1[1] = v2[1] = v1[1] + dx; + /* iter over 'Y' */ + verts[0][1]= verts[1][1]= y-dx*floorf(y/dx); + while(verts[0][1] < ar->winy) { + glDrawArrays(GL_LINES, 0, 2); + verts[0][1] = verts[1][1] = verts[0][1] + dx; } - glEnd(); + glDisableClientState(GL_VERTEX_ARRAY); } #define GRID_MIN_PX 6.0f @@ -425,13 +428,10 @@ static void drawgrid(UnitSettings *unit, ARegion *ar, View3D *v3d, const char ** static void drawfloor(Scene *scene, View3D *v3d, const char **grid_unit) { - float vert[3], grid, grid_scale; - int a, gridlines, emphasise; - unsigned char col[3], col2[3]; - short draw_line = 0; - - vert[2]= 0.0; - + float grid, grid_scale; + unsigned char col_grid[3]; + const int gridlines= v3d->gridlines/2; + if(v3d->gridlines<3) return; grid_scale= v3d->grid; @@ -450,115 +450,81 @@ static void drawfloor(Scene *scene, View3D *v3d, const char **grid_unit) grid_scale = (grid_scale * (float)bUnit_GetScaler(usys, i)) / scene->unit.scale_length; } } - - if(v3d->zbuf && scene->obedit) glDepthMask(0); // for zbuffer-select - - gridlines= v3d->gridlines/2; + grid= gridlines * grid_scale; - UI_GetThemeColor3ubv(TH_GRID, col); - UI_GetThemeColor3ubv(TH_BACK, col2); - - /* emphasise division lines lighter instead of darker, if background is darker than grid */ - if ( ((col[0]+col[1]+col[2])/3+10) > (col2[0]+col2[1]+col2[2])/3 ) - emphasise = 20; - else - emphasise = -10; - + if(v3d->zbuf && scene->obedit) glDepthMask(0); // for zbuffer-select + + UI_GetThemeColor3ubv(TH_GRID, col_grid); + /* draw the Y axis and/or grid lines */ - for(a= -gridlines;a<=gridlines;a++) { - if(a==0) { - /* check for the 'show Y axis' preference */ - if (v3d->gridflag & V3D_SHOW_Y) { - UI_make_axis_color(col, col2, 'Y'); - glColor3ubv(col2); - - draw_line = 1; - } else if (v3d->gridflag & V3D_SHOW_FLOOR) { - UI_ThemeColorShade(TH_GRID, emphasise); - } else { - draw_line = 0; + if(v3d->gridflag & V3D_SHOW_FLOOR) { + float vert[4][3]= {{0.0f}}; + unsigned char col_bg[3]; + unsigned char col_grid_emphasise[3], col_grid_light[3]; + int a; + int prev_emphasise= -1; + + UI_GetThemeColor3ubv(TH_BACK, col_bg); + + /* emphasise division lines lighter instead of darker, if background is darker than grid */ + UI_GetColorPtrShade3ubv(col_grid, col_grid_light, 10); + UI_GetColorPtrShade3ubv(col_grid, col_grid_emphasise, + (((col_grid[0]+col_grid[1]+col_grid[2])+30) > (col_bg[0]+col_bg[1]+col_bg[2])) ? 20 : -10); + + /* set fixed axis */ + vert[0][0]= vert[2][1]= grid; + vert[1][0]= vert[3][1]= -grid; + + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(3, GL_FLOAT, 0, vert); + + for(a= -gridlines;a<=gridlines;a++) { + const float line= a * grid_scale; + const int is_emphasise= (a % 10) == 0; + + if(is_emphasise != prev_emphasise) { + glColor3ubv(is_emphasise ? col_grid_emphasise : col_grid_light); + prev_emphasise= is_emphasise; } - } else { - /* check for the 'show grid floor' preference */ - if (v3d->gridflag & V3D_SHOW_FLOOR) { - if( (a % 10)==0) { - UI_ThemeColorShade(TH_GRID, emphasise); - } - else UI_ThemeColorShade(TH_GRID, 10); - - draw_line = 1; - } else { - draw_line = 0; - } - } - - if (draw_line) { - glBegin(GL_LINE_STRIP); - vert[0]= a * grid_scale; - vert[1]= grid; - glVertex3fv(vert); - vert[1]= -grid; - glVertex3fv(vert); - glEnd(); + + /* set variable axis */ + vert[0][1]= vert[1][1]= + vert[2][0]= vert[3][0]= line; + + glDrawArrays(GL_LINES, 0, 4); } + + glDisableClientState(GL_VERTEX_ARRAY); + + GPU_print_error("sdsd"); } - /* draw the X axis and/or grid lines */ - for(a= -gridlines;a<=gridlines;a++) { - if(a==0) { - /* check for the 'show X axis' preference */ - if (v3d->gridflag & V3D_SHOW_X) { - UI_make_axis_color(col, col2, 'X'); - glColor3ubv(col2); - - draw_line = 1; - } else if (v3d->gridflag & V3D_SHOW_FLOOR) { - UI_ThemeColorShade(TH_GRID, emphasise); - } else { - draw_line = 0; - } - } else { - /* check for the 'show grid floor' preference */ - if (v3d->gridflag & V3D_SHOW_FLOOR) { - if( (a % 10)==0) { - UI_ThemeColorShade(TH_GRID, emphasise); - } - else UI_ThemeColorShade(TH_GRID, 10); - - draw_line = 1; - } else { - draw_line = 0; - } - } - - if (draw_line) { + /* draw the Z axis line */ + /* check for the 'show Z axis' preference */ + if (v3d->gridflag & (V3D_SHOW_X | V3D_SHOW_Y | V3D_SHOW_Z)) { + int axis; + for(axis= 0; axis < 3; axis++) + if (v3d->gridflag & (V3D_SHOW_X << axis)) { + float vert[3]; + unsigned char tcol[3]; + + UI_make_axis_color(col_grid, tcol, 'X' + axis); + glColor3ubv(tcol); + glBegin(GL_LINE_STRIP); - vert[1]= a * grid_scale; - vert[0]= grid; + zero_v3(vert); + vert[axis]= grid; glVertex3fv(vert ); - vert[0]= -grid; + vert[axis]= -grid; glVertex3fv(vert); glEnd(); } } - - /* draw the Z axis line */ - /* check for the 'show Z axis' preference */ - if (v3d->gridflag & V3D_SHOW_Z) { - UI_make_axis_color(col, col2, 'Z'); - glColor3ubv(col2); - - glBegin(GL_LINE_STRIP); - vert[0]= 0; - vert[1]= 0; - vert[2]= grid; - glVertex3fv(vert ); - vert[2]= -grid; - glVertex3fv(vert); - glEnd(); - } - + + + + if(v3d->zbuf && scene->obedit) glDepthMask(1); } @@ -697,60 +663,63 @@ static void draw_rotation_guide(RegionView3D *rv3d) float scaled_axis[3]; const float scale = rv3d->dist; mul_v3_v3fl(scaled_axis, rv3d->rot_axis, scale); - + + glBegin(GL_LINE_STRIP); - color[3] = 0.f; // more transparent toward the ends - glColor4fv(color); - add_v3_v3v3(end, o, scaled_axis); - glVertex3fv(end); - - // color[3] = 0.2f + fabsf(rv3d->rot_angle); // modulate opacity with angle - // ^^ neat idea, but angle is frame-rate dependent, so it's usually close to 0.2 + color[3] = 0.f; // more transparent toward the ends + glColor4fv(color); + add_v3_v3v3(end, o, scaled_axis); + glVertex3fv(end); - color[3] = 0.5f; // more opaque toward the center - glColor4fv(color); - glVertex3fv(o); - - color[3] = 0.f; - glColor4fv(color); - sub_v3_v3v3(end, o, scaled_axis); - glVertex3fv(end); + // color[3] = 0.2f + fabsf(rv3d->rot_angle); // modulate opacity with angle + // ^^ neat idea, but angle is frame-rate dependent, so it's usually close to 0.2 + + color[3] = 0.5f; // more opaque toward the center + glColor4fv(color); + glVertex3fv(o); + + color[3] = 0.f; + glColor4fv(color); + sub_v3_v3v3(end, o, scaled_axis); + glVertex3fv(end); glEnd(); // -- draw ring around rotation center -- { - #define ROT_AXIS_DETAIL 13 - const float s = 0.05f * scale; - const float step = 2.f * (float)(M_PI / ROT_AXIS_DETAIL); - float angle; - int i; - - float q[4]; // rotate ring so it's perpendicular to axis - const int upright = fabsf(rv3d->rot_axis[2]) >= 0.95f; - if (!upright) - { - const float up[3] = {0.f, 0.f, 1.f}; - float vis_angle, vis_axis[3]; - - cross_v3_v3v3(vis_axis, up, rv3d->rot_axis); - vis_angle = acosf(dot_v3v3(up, rv3d->rot_axis)); - axis_angle_to_quat(q, vis_axis, vis_angle); +#define ROT_AXIS_DETAIL 13 + + const float s = 0.05f * scale; + const float step = 2.f * (float)(M_PI / ROT_AXIS_DETAIL); + float angle; + int i; + + float q[4]; // rotate ring so it's perpendicular to axis + const int upright = fabsf(rv3d->rot_axis[2]) >= 0.95f; + if (!upright) { + const float up[3] = {0.f, 0.f, 1.f}; + float vis_angle, vis_axis[3]; + + cross_v3_v3v3(vis_axis, up, rv3d->rot_axis); + vis_angle = acosf(dot_v3v3(up, rv3d->rot_axis)); + axis_angle_to_quat(q, vis_axis, vis_angle); } - color[3] = 0.25f; // somewhat faint - glColor4fv(color); - glBegin(GL_LINE_LOOP); - for (i = 0, angle = 0.f; i < ROT_AXIS_DETAIL; ++i, angle += step) - { - float p[3] = { s * cosf(angle), s * sinf(angle), 0.f }; + color[3] = 0.25f; // somewhat faint + glColor4fv(color); + glBegin(GL_LINE_LOOP); + for (i = 0, angle = 0.f; i < ROT_AXIS_DETAIL; ++i, angle += step) { + float p[3] = {s * cosf(angle), s * sinf(angle), 0.0f}; - if (!upright) - mul_qt_v3(q, p); + if (!upright) { + mul_qt_v3(q, p); + } - add_v3_v3(p, o); - glVertex3fv(p); + add_v3_v3(p, o); + glVertex3fv(p); } - glEnd(); + glEnd(); + +#undef ROT_AXIS_DETAIL } color[3] = 1.f; // solid dot @@ -1237,7 +1206,7 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d) UI_ThemeColorBlendShade(TH_WIRE, TH_BACK, 0.25, 0); - uiSetRoundBox(15); + uiSetRoundBox(UI_CNR_ALL); uiDrawBox(GL_LINE_LOOP, x1, y1, x2, y2, 12.0); } } diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 19e8d42db2d..761de836cfb 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -1017,18 +1017,26 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event if (has_rotation) { - const int invert = U.ndof_flag & NDOF_ORBIT_INVERT_AXES; - rv3d->view = RV3D_VIEW_USER; if (U.flag & USER_TRACKBALL) { + const int invert_roll = U.ndof_flag & NDOF_ROLL_INVERT_AXIS; + const int invert_tilt = U.ndof_flag & NDOF_TILT_INVERT_AXIS; + const int invert_rot = U.ndof_flag & NDOF_ROTATE_INVERT_AXIS; + float rot[4]; float axis[3]; float angle = rot_sensitivity * ndof_to_axis_angle(ndof, axis); - - if (invert) - angle = -angle; - + + if (invert_roll) + axis[2] = -axis[2]; + + if (invert_tilt) + axis[0] = -axis[0]; + + if (invert_rot) + axis[1] = -axis[1]; + // transform rotation axis from view to world coordinates mul_qt_v3(view_inv, axis); @@ -1042,6 +1050,8 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot); } else { /* turntable view code by John Aughey, adapted for 3D mouse by [mce] */ + const int invert = U.ndof_flag & NDOF_ORBIT_INVERT_AXES; + float angle, rot[4]; float xvec[3] = {1,0,0}; @@ -1143,10 +1153,26 @@ static int ndof_pan_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event) const float vertical_sensitivity = 0.4f; const float lateral_sensitivity = 0.6f; - float pan_vec[3] = {lateral_sensitivity * ndof->tvec[0], - vertical_sensitivity * ndof->tvec[1], - forward_sensitivity * ndof->tvec[2] - }; + const int invert_panx = U.ndof_flag & NDOF_PANX_INVERT_AXIS; + const int invert_pany = U.ndof_flag & NDOF_PANY_INVERT_AXIS; + const int invert_panz = U.ndof_flag & NDOF_PANZ_INVERT_AXIS; + + float pan_vec[3]; + + if (invert_panx) + pan_vec[0] = -lateral_sensitivity * ndof->tvec[0]; + else + pan_vec[0] = lateral_sensitivity * ndof->tvec[0]; + + if (invert_panz) + pan_vec[1] = -vertical_sensitivity * ndof->tvec[1]; + else + pan_vec[1] = vertical_sensitivity * ndof->tvec[1]; + + if (invert_pany) + pan_vec[2] = -forward_sensitivity * ndof->tvec[2]; + else + pan_vec[2] = forward_sensitivity * ndof->tvec[2]; mul_v3_fl(pan_vec, speed * dt); #endif |