[Bf-blender-cvs] [e2e49b9] hair_immediate_fixes: Fix for own misconception of fictitious forces in the moving hair root frames.

Lukas Tönne noreply at git.blender.org
Mon Sep 15 14:23:24 CEST 2014


Commit: e2e49b9a1169ecdc944953f281631dea74a80bf8
Author: Lukas Tönne
Date:   Mon Sep 15 12:51:18 2014 +0200
Branches: hair_immediate_fixes
https://developer.blender.org/rBe2e49b9a1169ecdc944953f281631dea74a80bf8

Fix for own misconception of fictitious forces in the moving hair root
frames.

These forces don't have to be calculated for each individual
contribution. Rather they can be split off and be calculated on top of
the basic force vector rotation (todo).

===================================================================

M	source/blender/physics/intern/implicit_blender.c

===================================================================

diff --git a/source/blender/physics/intern/implicit_blender.c b/source/blender/physics/intern/implicit_blender.c
index 49c617e..f493055 100644
--- a/source/blender/physics/intern/implicit_blender.c
+++ b/source/blender/physics/intern/implicit_blender.c
@@ -896,6 +896,34 @@ void BPH_mass_spring_solver_free(Implicit_Data *id)
  *   dwdt : angular acceleration of the root frame
  */
 
+BLI_INLINE void point_world_to_root(Implicit_Data *data, int index, float r[3], const float v[3])
+{
+	RootTransform *root = &data->root[index];
+	sub_v3_v3v3(r, v, root->loc);
+	mul_transposed_m3_v3(root->rot, r);
+}
+
+BLI_INLINE void point_root_to_world(Implicit_Data *data, int index, float r[3], const float v[3])
+{
+	RootTransform *root = &data->root[index];
+	mul_v3_m3v3(r, root->rot, v);
+	add_v3_v3(r, root->loc);
+}
+
+BLI_INLINE void direction_world_to_root(Implicit_Data *data, int index, float r[3], const float v[3])
+{
+	RootTransform *root = &data->root[index];
+	copy_v3_v3(r, v);
+	mul_transposed_m3_v3(root->rot, r);
+}
+
+BLI_INLINE void direction_root_to_world(Implicit_Data *data, int index, float r[3], const float v[3])
+{
+	RootTransform *root = &data->root[index];
+	mul_v3_m3v3(r, root->rot, v);
+}
+
+#if 0
 /* x_root = R^T * x_world */
 BLI_INLINE void loc_world_to_root(float r[3], const float v[3], const RootTransform *root)
 {
@@ -1116,6 +1144,7 @@ BLI_INLINE void dfdv_root_to_world(float m[3][3], float dfdv[3][3], float mass,
 	(void)root;
 #endif
 }
+#endif
 
 /* ================================ */
 
@@ -1575,28 +1604,24 @@ void BPH_mass_spring_set_root_motion(Implicit_Data *data, int index, const float
 
 void BPH_mass_spring_set_motion_state(Implicit_Data *data, int index, const float x[3], const float v[3])
 {
-	RootTransform *root = &data->root[index];
-	loc_world_to_root(data->X[index], x, root);
-	vel_world_to_root(data->V[index], data->X[index], v, root);
+	point_world_to_root(data, index, data->X[index], x);
+	direction_world_to_root(data, index, data->V[index], v);
 }
 
 void BPH_mass_spring_set_position(Implicit_Data *data, int index, const float x[3])
 {
-	RootTransform *root = &data->root[index];
-	loc_world_to_root(data->X[index], x, root);
+	point_world_to_root(data, index, data->X[index], x);
 }
 
 void BPH_mass_spring_set_velocity(Implicit_Data *data, int index, const float v[3])
 {
-	RootTransform *root = &data->root[index];
-	vel_world_to_root(data->V[index], data->X[index], v, root);
+	direction_world_to_root(data, index, data->V[index], v);
 }
 
 void BPH_mass_spring_get_motion_state(struct Implicit_Data *data, int index, float x[3], float v[3])
 {
-	RootTransform *root = &data->root[index];
-	if (x) loc_root_to_world(x, data->X[index], root);
-	if (v) vel_root_to_world(v, data->X[index], data->V[index], root);
+	if (x) point_root_to_world(data, index, x, data->X[index]);
+	if (v) direction_root_to_world(data, index, v, data->V[index]);
 }
 
 void BPH_mass_spring_set_vertex_mass(Implicit_Data *data, int index, float mass)
@@ -1698,7 +1723,7 @@ void BPH_mass_spring_force_gravity(Implicit_Data *data, const float g[3])
 	 */
 	for (i = 0; i < numverts; i++) {
 		float f[3];
-		acc_world_to_root(f, data->X[i], data->V[i], g, &data->root[i]);
+		direction_world_to_root(data, i, f, g);
 		mul_m3_v3(data->M[i].m, f);
 		
 		add_v3_v3(data->F[i], f);
@@ -1983,8 +2008,8 @@ bool BPH_mass_spring_force_spring_goal(Implicit_Data *data, int i, int UNUSED(sp
 	float f[3], dfdx[3][3], dfdv[3][3];
 	
 	/* goal is in world space */
-	loc_world_to_root(root_goal_x, goal_x, &data->root[i]);
-	vel_world_to_root(root_goal_v, root_goal_x, goal_v, &data->root[i]);
+	point_world_to_root(data, i, root_goal_x, goal_x);
+	direction_world_to_root(data, i, root_goal_v, goal_v);
 	
 	sub_v3_v3v3(extent, root_goal_x, data->X[i]);
 	sub_v3_v3v3(vel, root_goal_v, data->V[i]);




More information about the Bf-blender-cvs mailing list