svn merge -r 12856:12937 https://svn.blender.org/svnroot/bf-blender/trunk/blender
[blender.git] / source / blender / src / editparticle.c
index 411a45d0a538875326123e664fb69be681cb476e..4a9bd8998c7d09348999a478b71de91306e4e8c2 100644 (file)
@@ -157,7 +157,7 @@ void PE_change_act(void *ob_v, void *act_v)
                if((psys=BLI_findlink(&ob->particlesystem,act))) {
                        psys->flag |= PSYS_CURRENT;
 
-                       if(psys->flag & PSYS_ENABLED) {
+                       if(psys_check_enabled(ob, psys)) {
                                if(G.f & G_PARTICLEEDIT && !psys->edit)
                                        PE_create_particle_edit(ob, psys);
                                PE_recalc_world_cos(ob, psys);
@@ -186,7 +186,7 @@ ParticleSystem *PE_get_current(Object *ob)
                psys->flag |= PSYS_CURRENT;
        }
 
-       if(psys && (psys->flag & PSYS_ENABLED) && ob == OBACT && (G.f & G_PARTICLEEDIT))
+       if(psys && psys_check_enabled(ob, psys) && ob == OBACT && (G.f & G_PARTICLEEDIT))
                if(psys->part->type == PART_HAIR && psys->flag & PSYS_EDITED)
                        if(psys->edit == NULL)
                                PE_create_particle_edit(ob, psys);
@@ -1102,7 +1102,7 @@ void PE_set_particle_edit(void)
 
        if((G.f & G_PARTICLEEDIT)==0){
                if(psys && psys->part->type == PART_HAIR && psys->flag & PSYS_EDITED) {
-                       if(psys->flag & PSYS_ENABLED) {
+                       if(psys_check_enabled(ob, psys)) {
                                if(psys->edit==0)
                                        PE_create_particle_edit(ob, psys);
                                PE_recalc_world_cos(ob, psys);
@@ -2121,7 +2121,7 @@ static void brush_add(Object *ob, ParticleSystem *psys, short *mval, short numbe
        int i, k, n = 0, totpart = psys->totpart;
        short dmx = 0, dmy = 0;
        short mx = mval[0] - curarea->winx / 2, my = mval[1] - curarea->winy / 2;
-       float co1[3], co2[3], vec[4], min_d, imat[4][4], dx, dy;
+       float co1[3], co2[3], vec[4], min_d, imat[4][4];
        float framestep, timestep = psys_get_timestep(psys->part);
        short size = pset->brush[PE_BRUSH_ADD].size;
        short size2 = size*size;
@@ -2151,20 +2151,22 @@ static void brush_add(Object *ob, ParticleSystem *psys, short *mval, short numbe
                /* create intersection coordinates in view Z direction at mouse coordinates */
                /* Thanks to who ever wrote the "Mouse Location 3D Space" tutorial in "Blender 3D: Blending Into Python/Cookbook". */
                if(G.vd->persp){
-                       dx = G.vd->persmat[3][3] * (2.0f*(mx+dmx)/curarea->winx) - G.vd->persmat[3][0];
-                       dy = G.vd->persmat[3][3] * (2.0f*(my+dmy)/curarea->winy) - G.vd->persmat[3][1];
+                       vec[0]= (2.0f*(mx+dmx)/curarea->winx);
+                       vec[1]= (2.0f*(my+dmy)/curarea->winy);
+                       vec[2]= -1.0f;
+                       vec[3]= 1.0f;
 
-                       co2[0]=G.vd->persinv[0][0]*dx + G.vd->persinv[1][0]*dy;
-                       co2[1]=G.vd->persinv[0][1]*dx + G.vd->persinv[1][1]*dy;
-                       co2[2]=G.vd->persinv[0][2]*dx + G.vd->persinv[1][2]*dy;
+                       Mat4MulVec4fl(G.vd->persinv, vec);
+                       VecMulf(vec, 1.0f/vec[3]);
 
-                       VECCOPY(co1,G.vd->viewinv[3]);
+                       VECCOPY(co1, G.vd->viewinv[3]);
+                       VECSUB(vec, vec, co1);
+                       Normalize(vec);
 
-                       VECSUB(vec,co2,co1)
-
-                       VECADDFAC(co2,co1,vec,1000.0f);
+                       VECADDFAC(co1, G.vd->viewinv[3], vec, G.vd->near);
+                       VECADDFAC(co2, G.vd->viewinv[3], vec, G.vd->far);
                }
-               else{
+               else {
                        vec[0] = 2.0f*(mx+dmx)/curarea->winx;
                        vec[1] = 2.0f*(my+dmy)/curarea->winy;
                        vec[2] = 0.0f;