diff options
Diffstat (limited to 'source/blender/blenlib/intern/math_geom.c')
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index a80f999cdbb..8fb7a0e1a55 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -1730,6 +1730,43 @@ void lookat_m4(float mat[][4],float vx, float vy, float vz, float px, float py, translate_m4(mat,-vx,-vy,-vz); /* translate viewpoint to origin */ } +int box_clip_bounds_m4(float boundbox[2][3], float bounds[4], float winmat[4][4]) +{ + float mat[4][4], vec[4]; + int a, fl, flag= -1; + + copy_m4_m4(mat, winmat); + + for(a=0; a<8; a++) { + vec[0]= (a & 1)? boundbox[0][0]: boundbox[1][0]; + vec[1]= (a & 2)? boundbox[0][1]: boundbox[1][1]; + vec[2]= (a & 4)? boundbox[0][2]: boundbox[1][2]; + vec[3]= 1.0; + mul_m4_v4(mat, vec); + + fl= 0; + if(bounds) { + if(vec[0] > bounds[1]*vec[3]) fl |= 1; + if(vec[0]< bounds[0]*vec[3]) fl |= 2; + if(vec[1] > bounds[3]*vec[3]) fl |= 4; + if(vec[1]< bounds[2]*vec[3]) fl |= 8; + } + else { + if(vec[0] < -vec[3]) fl |= 1; + if(vec[0] > vec[3]) fl |= 2; + if(vec[1] < -vec[3]) fl |= 4; + if(vec[1] > vec[3]) fl |= 8; + } + if(vec[2] < -vec[3]) fl |= 16; + if(vec[2] > vec[3]) fl |= 32; + + flag &= fl; + if(flag==0) return 0; + } + + return flag; +} + /********************************** Mapping **********************************/ void map_to_tube(float *u, float *v,float x, float y, float z) |