[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [804] branches/ivygen: - almost completed the collision detection

Florian Meyer florianfelix at web.de
Sat Jul 17 02:58:24 CEST 2010


Revision: 804
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=804
Author:   testscreenings
Date:     2010-07-17 02:58:24 +0200 (Sat, 17 Jul 2010)

Log Message:
-----------
- almost completed the collision detection
- need to figure out how exactly he wants to modify new_pos
- very rich with comments, explanation and backround info and links

Modified Paths:
--------------
    branches/ivygen/ivy_functions.py
    branches/ivygen/ivy_test.py

Modified: branches/ivygen/ivy_functions.py
===================================================================
--- branches/ivygen/ivy_functions.py	2010-07-16 23:50:23 UTC (rev 803)
+++ branches/ivygen/ivy_functions.py	2010-07-17 00:58:24 UTC (rev 804)
@@ -3,25 +3,101 @@
     
     
     
-def computeCollision(mesh, old_pos, new_pos, climbing):
-
+def computeCollision(obj, old_pos, new_pos, climbing):
+    '''basic steps:
+        thought: maybe implement and octree for the faces
+                 to efficently discard the one too far away?
+    
+        ### http://www.flipcode.com/archives/Basic_Collision_Detection.shtml
+        
+        
+    - test if old_pos --> new_pos is passing through the hyperplane of the polygon
+                                                not sure about this one (below)
+        direction = new_pos.dot(facee.normal) + (old_pos - face.center).length
+        if direcion > 0:
+            new_pos_placement = 'plane_front'
+        else:
+            new_pos_placement = 'plane_back'
+        return new_pos_placement
+        
+    - test if the path old_pos --> new_pos passes through the bounderies of the polygon
+        --> find the intersectionpoint():
+        ray_vector = (old_pos - new_pos).normalize()
+        t = -(face.normal.dot(old_pos) + (old_pos - face.center).length) /
+            face.normal.dot(ray_vector)
+            ### check if face.normal.dot(ray_vector) is zero: if yes: do something ###
+        intersectPoint = old_pos + ray_vector * t
+        return intersectPoint
+        
+        --> test if intersectPoint is on the polygon():
+            ### An Efficient Ray-Polygon Intersection
+            ### by Didier Badouel from Graphics Gems I :
+            ### http://graphics.stanford.edu/courses/cs348b-98/gg/intersect.html
+    
+    ###################################################
+    if you have read all of the above: nice
+    actuall i remembered we have this whole rayintersection test
+    as a function of objects. much simpler.
+    obj.ray_cast(old_pos, new_pos)
+    returns [hitlocation, hitnormal at face, faceindex]
+    
+    ####################################################
+    now: what do i think does the original function do:
+    it tests if the new_pos is intersecting some part of the mesh (doh)
+    if yes it adjusts the new_pos as to move it out of the mesh again
+    it also sets the climbingState of the RootNode:
+        if it intersects the climbing is set to true
+        if not climbing is set to false
+        not sure about the following:
+            the climbing is imortant for the adhesion i think
+            the longer the chain of nonclimbing RootNodes
+                --> something should be done i think (?)
+                - suggestions? (mabye look elsewhere better :) )
+        
+    '''
     #reset climbing state
     climbing = false # why this, not clear yet
     
     intersection = False
     
-    for fa in mesh.faces:
+    #test for intersections with all faces of the mesh
+    intersect_faces = []
+    for fa in obj.data.faces:
+        ray_result = obj.ray_cast(old_pos, new_pos)
+        if ray_result[2] == -1:
+            continue
+        else:
+            intersect_faces.append(ray_result)
+
+    # set climbing_bool if we have intersections
+    if intersect_faces:
+        climbing = True
+            
+    # now we have to determine which face was intersected first
+    shortest_dist = None
+    faceOfInterest = None
+    if intersect_faces: #if there are intersections at all
+        for fa in intersect_faces: #go through the intersecting faces
+            dist = (fa[0] - old_pos).length #distance from old_pos to interection on face
+
+            # save the face with the closest intersection point
+            if not shortest_dist:
+                shortest_dist = dist
+            else:
+                if dist < shortest_dist:
+                    shortest_dist = dist
+                    faceOfInterest = fa
         
-        #compute intersection with triangle plane parametrically:
-        #intersectionPoint = oldPos + (newPos - oldPos) * t0
-        fa0 = 0
+        #now modifiy new_pos
+        #project newPos to triangle plane --> don't know yet what he did here
+        # Vector3d p0 = newPos - t->norm * Vector3d::dotProduct(t->norm, newPos - t->v0->pos)
         
+        #mirror newPos at triangle plane --> don't know yet what he did here
+        # newPos += 2.0f * (p0 - newPos)
         
         
         
-        
-        
-def computeAdhesion(): #tmp, needs toaiff be filled :)
+def computeAdhesion(): #tmp, needs to be filled :)
     pass
         
         

Modified: branches/ivygen/ivy_test.py
===================================================================
--- branches/ivygen/ivy_test.py	2010-07-16 23:50:23 UTC (rev 803)
+++ branches/ivygen/ivy_test.py	2010-07-17 00:58:24 UTC (rev 804)
@@ -88,7 +88,7 @@
                                     randomVector * randomWeight *
                                     adhesionVector * adhesionWeight)'''
         
-        #set position of new RootNode
+        #set position of new RootNode --> replace with growVector
         tmpRoot.position = (self.ivy_Roots[-1].position +           #just using the randomVector for now
                             randomVector * props.ivyRandomWeight)   #
 
@@ -120,7 +120,7 @@
 
 
 def main(context, props):
-    seedPoint = context.scene.cursor_location  #start the Ivy atexit the cursor
+    seedPoint = context.scene.cursor_location  #start the Ivy at the cursor
     gravity = mathutils.Vector((0,0,-1))  #not used yet
     upVector = mathutils.Vector((0,0,1))  #not used yet
     random.seed(props.ivySeed)  #controlling the random seed




More information about the Bf-extensions-cvs mailing list