v Cloud to matrix
authorJens Ole Wund <bjornmose@gmx.net>
Thu, 26 Nov 2009 00:15:26 +0000 (00:15 +0000)
committerJens Ole Wund <bjornmose@gmx.net>
Thu, 26 Nov 2009 00:15:26 +0000 (00:15 +0000)
nice drawing for soft bodies
BTW could be used by any object by design

source/blender/editors/space_view3d/drawobject.c

index 41eab057d4029b5528c7c8080820ebb8a0295a33..51af31496f13c070020bb9662202ed7b3cb84c99 100644 (file)
@@ -4326,63 +4326,168 @@ static void draw_ptcache_edit(Scene *scene, View3D *v3d, RegionView3D *rv3d, Obj
 
        glPointSize(1.0);
 }
-static void draw_sb_motion(Scene *scene, Object *ob)
+//static void ob_draw_RE_motion(float com[3],float rotscale[3][3],float tw,float th)
+static void ob_draw_RE_motion(float com[3],float rotscale[3][3],float itw,float ith,float drw_size)
 {
-       SoftBody *sb = 0;
-       if ((sb= ob->soft)){
-               if(sb->solverflags & SBSO_MONITOR ||sb->solverflags & SBSO_ESTIMATEIPO){
-                       /* draw com */ 
-               float rt[3][3],sc[3][3],tr[3][3]; 
-                       /* looks like to swap a b in reverse */
-                       copy_m3_m3(sc,sb->lscale);
-                       copy_m3_m3(rt,sb->lrot);
-                       mul_m3_m3m3(tr,rt,sc); 
-                       if(1){
-                               float root[3],tip[3];
+       float tr[3][3];
+       float root[3],tip[3];
+       float tw,th;
+       /* take a copy for not spoiling original */
+       copy_m3_m3(tr,rotscale);
+       tw = itw * drw_size;
+       th = ith * drw_size;
+
+       glColor4ub(0x7F, 0x00, 0x00, 155);
+       glBegin(GL_LINES);
+       root[1] = root[2] = 0.0f;
+       root[0] = -drw_size;
+       mul_m3_v3(tr,root);
+       VECADD(root,root,com);
+       glVertex3fv(root); 
+       tip[1] = tip[2] = 0.0f;
+       tip[0] = drw_size;
+       mul_m3_v3(tr,tip);
+       VECADD(tip,tip,com);
+       glVertex3fv(tip); 
+       glEnd();
 
-                               glBegin(GL_LINES);
-                               root[1] = root[2] = 0.0f;
-                               root[0] = -1.0f;
-                               mul_m3_v3(tr,root);
-                               VECADD(root,root,sb->lcom);
-                               glVertex3fv(root); 
-                               tip[1] = tip[2] = 0.0f;
-                               tip[0] = 1.0f;
-                               mul_m3_v3(tr,tip);
-                               VECADD(tip,tip,sb->lcom);
-                               glVertex3fv(tip); 
-                               glEnd();
+       root[1] =0.0f; root[2] = tw;
+       root[0] = th;
+       glBegin(GL_LINES);
+       mul_m3_v3(tr,root);
+       VECADD(root,root,com);
+       glVertex3fv(root); 
+       glVertex3fv(tip); 
+       glEnd();
 
-                               glBegin(GL_LINES);
-                               root[0] = root[2] = 0.0f;
-                               root[1] = -1.0f;
-                               mul_m3_v3(tr,root);
-                               VECADD(root,root,sb->lcom);
-                               glVertex3fv(root); 
-                               tip[0] = tip[2] = 0.0f;
-                               tip[1] = 1.0f;
-                               mul_m3_v3(tr,tip);
-                               VECADD(tip,tip,sb->lcom);
-                               glVertex3fv(tip); 
-                               glEnd();
+       root[1] =0.0f; root[2] = -tw;
+       root[0] = th;
+       glBegin(GL_LINES);
+       mul_m3_v3(tr,root);
+       VECADD(root,root,com);
+       glVertex3fv(root); 
+       glVertex3fv(tip); 
+       glEnd();
 
-                               glBegin(GL_LINES);
-                               root[0] = root[1] = 0.0f;
-                               root[2] = -1.0f;
-                               mul_m3_v3(tr,root);
-                               VECADD(root,root,sb->lcom);
-                               glVertex3fv(root); 
-                               tip[0] = tip[1] = 0.0f;
-                               tip[2] = 1.0f;
-                               mul_m3_v3(tr,tip);
-                               VECADD(tip,tip,sb->lcom);
-                               glVertex3fv(tip); 
-                               glEnd();
-                       }
+       root[1] =tw; root[2] = 0.0f;
+       root[0] =th;
+       glBegin(GL_LINES);
+       mul_m3_v3(tr,root);
+       VECADD(root,root,com);
+       glVertex3fv(root); 
+       glVertex3fv(tip); 
+       glEnd();
 
-               }
-       }
-};
+       root[1] =-tw; root[2] = 0.0f;
+       root[0] = th;
+       glBegin(GL_LINES);
+       mul_m3_v3(tr,root);
+       VECADD(root,root,com);
+       glVertex3fv(root); 
+       glVertex3fv(tip); 
+       glEnd();
+
+       glColor4ub(0x00, 0x7F, 0x00, 155);
+
+       glBegin(GL_LINES);
+       root[0] = root[2] = 0.0f;
+       root[1] = -drw_size;
+       mul_m3_v3(tr,root);
+       VECADD(root,root,com);
+       glVertex3fv(root); 
+       tip[0] = tip[2] = 0.0f;
+       tip[1] = drw_size;
+       mul_m3_v3(tr,tip);
+       VECADD(tip,tip,com);
+       glVertex3fv(tip); 
+       glEnd();
+
+       root[0] =0.0f; root[2] = tw;
+       root[1] = th;
+       glBegin(GL_LINES);
+       mul_m3_v3(tr,root);
+       VECADD(root,root,com);
+       glVertex3fv(root); 
+       glVertex3fv(tip); 
+       glEnd();
+
+       root[0] =0.0f; root[2] = -tw;
+       root[1] = th;
+       glBegin(GL_LINES);
+       mul_m3_v3(tr,root);
+       VECADD(root,root,com);
+       glVertex3fv(root); 
+       glVertex3fv(tip); 
+       glEnd();
+
+       root[0] =tw; root[2] = 0.0f;
+       root[1] =th;
+       glBegin(GL_LINES);
+       mul_m3_v3(tr,root);
+       VECADD(root,root,com);
+       glVertex3fv(root); 
+       glVertex3fv(tip); 
+       glEnd();
+
+       root[0] =-tw; root[2] = 0.0f;
+       root[1] = th;
+       glBegin(GL_LINES);
+       mul_m3_v3(tr,root);
+       VECADD(root,root,com);
+       glVertex3fv(root); 
+       glVertex3fv(tip); 
+       glEnd();
+
+       glColor4ub(0x00, 0x00, 0x7F, 155);
+       glBegin(GL_LINES);
+       root[0] = root[1] = 0.0f;
+       root[2] = -drw_size;
+       mul_m3_v3(tr,root);
+       VECADD(root,root,com);
+       glVertex3fv(root); 
+       tip[0] = tip[1] = 0.0f;
+       tip[2] = drw_size;
+       mul_m3_v3(tr,tip);
+       VECADD(tip,tip,com);
+       glVertex3fv(tip); 
+       glEnd();
+
+       root[0] =0.0f; root[1] = tw;
+       root[2] = th;
+       glBegin(GL_LINES);
+       mul_m3_v3(tr,root);
+       VECADD(root,root,com);
+       glVertex3fv(root); 
+       glVertex3fv(tip); 
+       glEnd();
+
+       root[0] =0.0f; root[1] = -tw;
+       root[2] = th;
+       glBegin(GL_LINES);
+       mul_m3_v3(tr,root);
+       VECADD(root,root,com);
+       glVertex3fv(root); 
+       glVertex3fv(tip); 
+       glEnd();
+
+       root[0] = tw; root[1] = 0.0f;
+       root[2] = th;
+       glBegin(GL_LINES);
+       mul_m3_v3(tr,root);
+       VECADD(root,root,com);
+       glVertex3fv(root); 
+       glVertex3fv(tip); 
+       glEnd();
+
+       root[0] = -tw; root[1] = 0.0f;
+       root[2] = th;
+       glBegin(GL_LINES);
+       mul_m3_v3(tr,root);
+       VECADD(root,root,com);
+       glVertex3fv(root); 
+       glVertex3fv(tip); 
+       glEnd();
+}
 
 /*place to add drawers */
 unsigned int nurbcol[8]= {
@@ -5779,7 +5884,22 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                default:
                        drawaxes(1.0, flag, OB_ARROWS);
        }
-    if(ob->soft /*&& flag & OB_SBMOTION*/) draw_sb_motion(scene, ob);
+       if(ob->soft /*&& flag & OB_SBMOTION*/){
+               float mrt[3][3],msc[3][3],mtr[3][3]; 
+               SoftBody *sb = 0;
+               float tipw = 0.5f, tiph = 0.5f,drawsize = 4.0f;
+               if ((sb= ob->soft)){
+                       if(sb->solverflags & SBSO_MONITOR ||sb->solverflags & SBSO_ESTIMATEIPO){
+
+                               wmLoadMatrix(rv3d->viewmat);
+                               copy_m3_m3(msc,sb->lscale);
+                               copy_m3_m3(mrt,sb->lrot);
+                               mul_m3_m3m3(mtr,mrt,msc); 
+                               ob_draw_RE_motion(sb->lcom,mtr,tipw,tiph,drawsize);
+                               wmMultMatrix(ob->obmat);
+                       }
+               }
+       }
 
        if(ob->pd && ob->pd->forcefield) draw_forcefield(scene, ob);