[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14915] branches/apricot/source/blender/ src/transform_snap.c: Snaping
Martin Poirier
theeth at yahoo.com
Wed May 21 18:43:41 CEST 2008
Revision: 14915
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14915
Author: theeth
Date: 2008-05-21 18:42:46 +0200 (Wed, 21 May 2008)
Log Message:
-----------
Snaping
Bypass boundbox test if camera is inside bounding box
Modified Paths:
--------------
branches/apricot/source/blender/src/transform_snap.c
Modified: branches/apricot/source/blender/src/transform_snap.c
===================================================================
--- branches/apricot/source/blender/src/transform_snap.c 2008-05-21 13:43:39 UTC (rev 14914)
+++ branches/apricot/source/blender/src/transform_snap.c 2008-05-21 16:42:46 UTC (rev 14915)
@@ -890,56 +890,76 @@
int totvert = dm->getNumVerts(dm);
if (totvert > 0) {
+ float imat[4][4];
int test = 1;
+
+ Mat4Invert(imat, obmat);
/* If number of vert is more than an arbitrary limit,
* test against boundbox first
* */
if (totvert > 16) {
struct BoundBox *bb = object_get_boundbox(ob);
+ float camera[3];
+ int outside = 1;
- int minx = 0, miny = 0, maxx = 0, maxy = 0;
- int i;
+ VECCOPY(camera, G.vd->viewinv[3]);
+ Mat4MulVecfl(imat, camera);
+
+ /* If we're inside the bounding box, projection is screwy, so test for that */
+ if (bb->vec[0][0] <= camera[0] && camera[0] <= bb->vec[4][0] &&
+ bb->vec[0][1] <= camera[1] && camera[1] <= bb->vec[2][1] &&
+ bb->vec[0][2] <= camera[2] && camera[2] <= bb->vec[1][2])
+ {
+ outside = 0;
+ }
- for (i = 0; i < 8; i++) {
- float gloc[3];
- int sloc[2];
+ /* only test if camera is outside of the bounding box */
+ if (outside)
+ {
+ float minx = 0, miny = 0, maxx = 0, maxy = 0;
+ int i;
- VECCOPY(gloc, bb->vec[i]);
- Mat4MulVecfl(obmat, gloc);
- project_int(gloc, sloc);
+ for (i = 0; i < 8; i++) {
+ float gloc[3];
+ float sloc[2];
+
+ VECCOPY(gloc, bb->vec[i]);
+ Mat4MulVecfl(obmat, gloc);
+
+ project_float(gloc, sloc);
+
+ if (i == 0) {
+ minx = maxx = sloc[0];
+ miny = maxy = sloc[1];
+ }
+ else {
+ if (minx > sloc[0]) minx = sloc[0];
+ else if (maxx < sloc[0]) maxx = sloc[0];
+
+ if (miny > sloc[1]) miny = sloc[1];
+ else if (maxy < sloc[1]) maxy = sloc[1];
+ }
+ }
- if (i == 0) {
- minx = maxx = sloc[0];
- miny = maxy = sloc[1];
- }
- else {
- if (minx > sloc[0]) minx = sloc[0];
- else if (maxx < sloc[0]) maxx = sloc[0];
+ /* Pad with distance */
+
+ minx -= *dist;
+ miny -= *dist;
+ maxx += *dist;
+ maxy += *dist;
+
+ if (mval[0] > maxx || mval[0] < minx ||
+ mval[1] > maxy || mval[1] < miny) {
- if (miny > sloc[1]) miny = sloc[1];
- else if (maxy < sloc[1]) maxy = sloc[1];
+ test = 0;
}
}
-
- /* Pad with distance */
-
- minx -= *dist;
- miny -= *dist;
- maxx += *dist;
- maxy += *dist;
-
- if (mval[0] > maxx || mval[0] < minx ||
- mval[1] > maxy || mval[1] < miny) {
-
- test = 0;
- }
}
if (test == 1) {
MVert *verts = dm->getVertArray(dm);
MFace *faces = dm->getFaceArray(dm);
- float imat[4][4];
float ray_start_local[3], ray_normal_local[3];
int totface = dm->getNumFaces(dm);
int i;
@@ -947,8 +967,6 @@
VECCOPY(ray_start_local, ray_start);
VECCOPY(ray_normal_local, ray_normal);
- Mat4Invert(imat, obmat);
-
Mat4MulVecfl(imat, ray_start_local);
Mat4Mul3Vecfl(imat, ray_normal_local);
@@ -1036,7 +1054,7 @@
}
}
}
-
+
return retval;
}
@@ -1079,6 +1097,7 @@
for(dupli_ob = lb->first; dupli_ob; dupli_ob = dupli_ob->next)
{
Object *ob = dupli_ob->ob;
+
if (ob->type == OB_MESH) {
DerivedMesh *dm = mesh_get_derived_final(ob, CD_MASK_BAREMESH);
int val;
More information about the Bf-blender-cvs
mailing list