[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15176] trunk/blender/source/blender: Revision 14894 merged from apricot

Martin Poirier theeth at yahoo.com
Mon Jun 9 19:16:20 CEST 2008


Revision: 15176
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15176
Author:   theeth
Date:     2008-06-09 19:16:20 +0200 (Mon, 09 Jun 2008)

Log Message:
-----------
Revision 14894 merged from apricot
----------------------------------
Arith:
	- axis angle to quat conversion function
	- short to float / float to short normals conversion function (eventually, we could go over the go and replace copy/pasted code everywhere)
	- ray triangle intersection (to complement the line triangle intersection function)
	
View:
	- viewray / viewline (get near plane point under mouse and ray normal/far point)


Particles:
	- extract viewline from brush_add function

Revision Links:
--------------
    http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14894

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_arithb.h
    trunk/blender/source/blender/blenlib/intern/arithb.c
    trunk/blender/source/blender/include/BSE_view.h
    trunk/blender/source/blender/src/editparticle.c
    trunk/blender/source/blender/src/view.c

Modified: trunk/blender/source/blender/blenlib/BLI_arithb.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_arithb.h	2008-06-09 16:54:54 UTC (rev 15175)
+++ trunk/blender/source/blender/blenlib/BLI_arithb.h	2008-06-09 17:16:20 UTC (rev 15176)
@@ -258,6 +258,7 @@
 void Vec2Subf(float *v, float *v1, float *v2);
 void Vec2Copyf(float *v1, float *v2);
 
+void AxisAngleToQuat(float *q, float *axis, float angle);
 void vectoquat(float *vec, short axis, short upflag, float *q);
 
 float VecAngle2(float *v1, float *v2);
@@ -269,6 +270,8 @@
 
 void euler_rot(float *beul, float ang, char axis);
 	
+void NormalShortToFloat(float *out, short *in);
+void NormalFloatToShort(short *out, float *in);
 
 float DistVL2Dfl(float *v1, float *v2, float *v3);
 float PdistVL2Dfl(float *v1, float *v2, float *v3);
@@ -372,6 +375,7 @@
 void spheremap(float x, float y, float z, float *u, float *v);
 
 int LineIntersectsTriangle(float p1[3], float p2[3], float v0[3], float v1[3], float v2[3], float *lambda, float *uv);
+int RayIntersectsTriangle(float p1[3], float d[3], float v0[3], float v1[3], float v2[3], float *lambda, float *uv);
 int SweepingSphereIntersectsTriangleUV(float p1[3], float p2[3], float radius, float v0[3], float v1[3], float v2[3], float *lambda, float *ipoint);
 int AxialLineIntersectsTriangle(int axis, float co1[3], float co2[3], float v0[3], float v1[3], float v2[3], float *lambda);
 int AabbIntersectAabb(float min1[3], float max1[3], float min2[3], float max2[3]);

Modified: trunk/blender/source/blender/blenlib/intern/arithb.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/arithb.c	2008-06-09 16:54:54 UTC (rev 15175)
+++ trunk/blender/source/blender/blenlib/intern/arithb.c	2008-06-09 17:16:20 UTC (rev 15176)
@@ -1335,6 +1335,22 @@
 	}
 }
 
+void AxisAngleToQuat(float *q, float *axis, float angle)
+{
+	float nor[3];
+	float si;
+	
+	VecCopyf(nor, axis);
+	Normalize(nor);
+	
+	angle /= 2;
+	si = (float)sin(angle);
+	q[0] = (float)cos(angle);
+	q[1] = nor[0] * si;
+	q[2] = nor[1] * si;
+	q[3] = nor[2] * si;	
+}
+
 void vectoquat(float *vec, short axis, short upflag, float *q)
 {
 	float q2[4], nor[3], *fp, mat[3][3], angle, si, co, x2, y2, z2, len1;
@@ -2258,6 +2274,20 @@
 	else return exp(log(d)/3);
 }
 
+void NormalShortToFloat(float *out, short *in)
+{
+	out[0] = in[0] / 32767.0;
+	out[1] = in[1] / 32767.0;
+	out[2] = in[2] / 32767.0;
+}
+
+void NormalFloatToShort(short *out, float *in)
+{
+	out[0] = (short)(in[0] * 32767.0);
+	out[1] = (short)(in[1] * 32767.0);
+	out[2] = (short)(in[2] * 32767.0);
+}
+
 /* distance v1 to line v2-v3 */
 /* using Hesse formula, NO LINE PIECE! */
 float DistVL2Dfl( float *v1, float *v2, float *v3)  {
@@ -3671,6 +3701,43 @@
 	return 1;
 }
 
+/* moved from effect.c
+   test if the ray starting at p1 going in d direction intersects the triangle v0..v2
+   return non zero if it does 
+*/
+int RayIntersectsTriangle(float p1[3], float d[3], float v0[3], float v1[3], float v2[3], float *lambda, float *uv)
+{
+	float p[3], s[3], e1[3], e2[3], q[3];
+	float a, f, u, v;
+	
+	VecSubf(e1, v1, v0);
+	VecSubf(e2, v2, v0);
+	
+	Crossf(p, d, e2);
+	a = Inpf(e1, p);
+	if ((a > -0.000001) && (a < 0.000001)) return 0;
+	f = 1.0f/a;
+	
+	VecSubf(s, p1, v0);
+	
+	Crossf(q, s, e1);
+	*lambda = f * Inpf(e2, q);
+	if ((*lambda < 0.0)) return 0;
+	
+	u = f * Inpf(s, p);
+	if ((u < 0.0)||(u > 1.0)) return 0;
+	
+	v = f * Inpf(d, q);
+	if ((v < 0.0)||((u + v) > 1.0)) return 0;
+
+	if(uv) {
+		uv[0]= u;
+		uv[1]= v;
+	}
+	
+	return 1;
+}
+
 /* Adapted from the paper by Kasper Fauerby */
 /* "Improved Collision detection and Response" */
 int SweepingSphereIntersectsTriangleUV(float p1[3], float p2[3], float radius, float v0[3], float v1[3], float v2[3], float *lambda, float *ipoint)

Modified: trunk/blender/source/blender/include/BSE_view.h
===================================================================
--- trunk/blender/source/blender/include/BSE_view.h	2008-06-09 16:54:54 UTC (rev 15175)
+++ trunk/blender/source/blender/include/BSE_view.h	2008-06-09 17:16:20 UTC (rev 15176)
@@ -66,6 +66,8 @@
 void project_int_noclip(float *vec, int *adr);
 void project_float(float *vec, float *adr);
 void project_float_noclip(float *vec, float *adr);
+void viewray(short mval[2], float ray_start[3], float ray_normal[3]);
+void viewline(short mval[2], float ray_start[3], float ray_end[3]);
 
 int boundbox_clip(float obmat[][4], struct BoundBox *bb);
 void fdrawline(float x1, float y1, float x2, float y2);

Modified: trunk/blender/source/blender/src/editparticle.c
===================================================================
--- trunk/blender/source/blender/src/editparticle.c	2008-06-09 16:54:54 UTC (rev 15175)
+++ trunk/blender/source/blender/src/editparticle.c	2008-06-09 17:16:20 UTC (rev 15176)
@@ -2273,9 +2273,9 @@
 	ParticleEditSettings *pset= PE_settings();
 	ParticleEdit *edit = psys->edit;
 	int i, k, n = 0, totpart = psys->totpart;
+	short mco[2];
 	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];
+	float co1[3], co2[3], 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;
@@ -2302,36 +2302,10 @@
 			}
 		}
 
-		/* 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 != V3D_ORTHO){
-			vec[0]= (2.0f*(mx+dmx)/curarea->winx);
-			vec[1]= (2.0f*(my+dmy)/curarea->winy);
-			vec[2]= -1.0f;
-			vec[3]= 1.0f;
+		mco[0] = mval[0] + dmx;
+		mco[1] = mval[1] + dmy;
+		viewline(mco, co1, co2);
 
-			Mat4MulVec4fl(G.vd->persinv, vec);
-			VecMulf(vec, 1.0f/vec[3]);
-
-			VECCOPY(co1, G.vd->viewinv[3]);
-			VECSUB(vec, vec, co1);
-			Normalize(vec);
-
-			VECADDFAC(co1, G.vd->viewinv[3], vec, G.vd->near);
-			VECADDFAC(co2, G.vd->viewinv[3], vec, G.vd->far);
-		}
-		else {
-			vec[0] = 2.0f*(mx+dmx)/curarea->winx;
-			vec[1] = 2.0f*(my+dmy)/curarea->winy;
-			vec[2] = 0.0f;
-			vec[3] = 1.0f;
-
-			Mat4MulVec4fl(G.vd->persinv,vec);
-
-			VECADDFAC(co1,vec,G.vd->viewinv[2],1000.0f);
-			VECADDFAC(co2,vec,G.vd->viewinv[2],-1000.0f);
-		}
-
 		Mat4MulVecfl(imat,co1);
 		Mat4MulVecfl(imat,co2);
 		min_d=2.0;

Modified: trunk/blender/source/blender/src/view.c
===================================================================
--- trunk/blender/source/blender/src/view.c	2008-06-09 16:54:54 UTC (rev 15175)
+++ trunk/blender/source/blender/src/view.c	2008-06-09 17:16:20 UTC (rev 15176)
@@ -144,7 +144,49 @@
 	}
 }
 
+/* create intersection ray in view Z direction at mouse coordinates */
+void viewray(short mval[2], float ray_start[3], float ray_normal[3])
+{
+	float ray_end[3];
+	viewline(mval, ray_start, ray_end);
+	VecSubf(ray_normal, ray_end, ray_start);
+	Normalize(ray_normal);
+}
 
+/* create intersection coordinates in view Z direction at mouse coordinates */
+void viewline(short mval[2], float ray_start[3], float ray_end[3])
+{
+	float vec[3];
+	
+	if(G.vd->persp != V3D_ORTHO){
+		vec[0]= 2.0f * mval[0] / curarea->winx - 1;
+		vec[1]= 2.0f * mval[1] / curarea->winy - 1;
+		vec[2]= -1.0f;
+		vec[3]= 1.0f;
+
+		Mat4MulVec4fl(G.vd->persinv, vec);
+		VecMulf(vec, 1.0f / vec[3]);
+
+		VECCOPY(ray_start, G.vd->viewinv[3]);
+		VECSUB(vec, vec, ray_start);
+		Normalize(vec);
+
+		VECADDFAC(ray_start, G.vd->viewinv[3], vec, G.vd->near);
+		VECADDFAC(ray_end, G.vd->viewinv[3], vec, G.vd->far);
+	}
+	else {
+		vec[0] = 2.0f * mval[0] / curarea->winx - 1;
+		vec[1] = 2.0f * mval[1] / curarea->winy - 1;
+		vec[2] = 0.0f;
+		vec[3] = 1.0f;
+
+		Mat4MulVec4fl(G.vd->persinv, vec);
+
+		VECADDFAC(ray_start, vec, G.vd->viewinv[2],  1000.0f);
+		VECADDFAC(ray_end, vec, G.vd->viewinv[2], -1000.0f);
+	}
+}
+
 void initgrabz(float x, float y, float z)
 {
 	if(G.vd==NULL) return;





More information about the Bf-blender-cvs mailing list