[Bf-blender-cvs] [cae29a0d9d0] functions: transform collision rays to object space

Jacques Lucke noreply at git.blender.org
Fri Jun 21 13:29:43 CEST 2019


Commit: cae29a0d9d06c4b2b43af000bf2d52951adeac28
Author: Jacques Lucke
Date:   Fri Jun 21 13:23:55 2019 +0200
Branches: functions
https://developer.blender.org/rBcae29a0d9d06c4b2b43af000bf2d52951adeac28

transform collision rays to object space

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

M	source/blender/blenlib/BLI_math.hpp
M	source/blender/simulations/bparticles/c_wrapper.cpp
M	source/blender/simulations/bparticles/events.cpp
M	source/blender/simulations/bparticles/events.hpp

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

diff --git a/source/blender/blenlib/BLI_math.hpp b/source/blender/blenlib/BLI_math.hpp
index 3917eeb9f55..dd21053975b 100644
--- a/source/blender/blenlib/BLI_math.hpp
+++ b/source/blender/blenlib/BLI_math.hpp
@@ -102,11 +102,29 @@ struct float4x4 {
     return (float *)this;
   }
 
+  float4x4 inverted() const
+  {
+    float result[4][4];
+    invert_m4_m4(result, (float(*)[4])this);
+    return result;
+  }
+
+  float4x4 inverted__LocRotScale() const
+  {
+    return this->inverted();
+  }
+
   float3 transform_position(float3 position)
   {
     mul_m4_v3((float(*)[4])this, position);
     return position;
   }
+
+  float3 transform_direction(float3 direction)
+  {
+    mul_mat3_m4_v3((float(*)[4])this, direction);
+    return direction;
+  }
 };
 
 }  // namespace BLI
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index b347c8cae5a..7ccf8b0fb2c 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -134,7 +134,8 @@ void BParticles_simulate_modifier(NodeParticlesModifierData *npmd,
   if (npmd->collision_object) {
     BKE_bvhtree_from_mesh_get(
         &treedata, (Mesh *)npmd->collision_object->data, BVHTREE_FROM_LOOPTRI, 4);
-    description.m_influences.m_events.append(EVENT_mesh_collection(&treedata).release());
+    description.m_influences.m_events.append(
+        EVENT_mesh_collection(&treedata, npmd->collision_object->obmat).release());
     description.m_influences.m_actions.append(ACTION_kill().release());
   }
   description.m_influences.m_forces.append(FORCE_directional({0, 0, -2}).release());
diff --git a/source/blender/simulations/bparticles/events.cpp b/source/blender/simulations/bparticles/events.cpp
index 1f9b950c606..a4c9503a400 100644
--- a/source/blender/simulations/bparticles/events.cpp
+++ b/source/blender/simulations/bparticles/events.cpp
@@ -42,9 +42,11 @@ class AgeReachedEvent : public Event {
 class MeshCollisionEvent : public Event {
  private:
   BVHTreeFromMesh *m_treedata;
+  float4x4 m_ray_transform;
 
  public:
-  MeshCollisionEvent(BVHTreeFromMesh *treedata) : m_treedata(treedata)
+  MeshCollisionEvent(BVHTreeFromMesh *treedata, float4x4 transform)
+      : m_treedata(treedata), m_ray_transform(transform.inverted__LocRotScale())
   {
   }
 
@@ -62,8 +64,8 @@ class MeshCollisionEvent : public Event {
     for (uint i = 0; i < particle_indices.size(); i++) {
       uint pindex = particle_indices[i];
 
-      float3 start_position = positions[pindex];
-      float3 direction = position_offsets[i];
+      float3 start_position = m_ray_transform.transform_position(positions[pindex]);
+      float3 direction = m_ray_transform.transform_direction(position_offsets[i]);
       float length = direction.normalize_and_get_length();
 
       BVHTreeRayHit hit;
@@ -92,9 +94,9 @@ std::unique_ptr<Event> EVENT_age_reached(float age)
   return std::unique_ptr<Event>(event);
 }
 
-std::unique_ptr<Event> EVENT_mesh_collection(BVHTreeFromMesh *treedata)
+std::unique_ptr<Event> EVENT_mesh_collection(BVHTreeFromMesh *treedata, const float4x4 &transform)
 {
-  Event *event = new MeshCollisionEvent(treedata);
+  Event *event = new MeshCollisionEvent(treedata, transform);
   return std::unique_ptr<Event>(event);
 }
 
diff --git a/source/blender/simulations/bparticles/events.hpp b/source/blender/simulations/bparticles/events.hpp
index 3115e4e6821..297900ba340 100644
--- a/source/blender/simulations/bparticles/events.hpp
+++ b/source/blender/simulations/bparticles/events.hpp
@@ -7,6 +7,7 @@ struct BVHTreeFromMesh;
 namespace BParticles {
 
 std::unique_ptr<Event> EVENT_age_reached(float age);
-std::unique_ptr<Event> EVENT_mesh_collection(struct BVHTreeFromMesh *treedata);
+std::unique_ptr<Event> EVENT_mesh_collection(struct BVHTreeFromMesh *treedata,
+                                             const float4x4 &transform);
 
 }  // namespace BParticles



More information about the Bf-blender-cvs mailing list