Revision: 47010
          http://brlcad.svn.sourceforge.net/brlcad/?rev=47010&view=rev
Author:   abhi2011
Date:     2011-10-01 19:47:23 +0000 (Sat, 01 Oct 2011)
Log Message:
-----------
Trying to pass contact manifolds via a linked list back to libged

Modified Paths:
--------------
    brlcad/trunk/src/libged/simulate/simcollisionalgo.cpp
    brlcad/trunk/src/libged/simulate/simulate.c
    brlcad/trunk/src/libged/simulate/simulate.h

Modified: brlcad/trunk/src/libged/simulate/simcollisionalgo.cpp
===================================================================
--- brlcad/trunk/src/libged/simulate/simcollisionalgo.cpp       2011-10-01 
13:20:43 UTC (rev 47009)
+++ brlcad/trunk/src/libged/simulate/simcollisionalgo.cpp       2011-10-01 
19:47:23 UTC (rev 47010)
@@ -99,33 +99,57 @@
        //------------------- DEBUG ---------------------------
 
     //Get the user pointers to struct rigid_body, for printing the body name
-       struct rigid_body *upA = (struct rigid_body *)col0->getUserPointer();
-       struct rigid_body *upB = (struct rigid_body *)col1->getUserPointer();
+       struct rigid_body *rbA = (struct rigid_body *)col0->getUserPointer();
+       struct rigid_body *rbB = (struct rigid_body *)col1->getUserPointer();
 
-       if(upA != NULL && upB != NULL){
+       if(rbA != NULL && rbB != NULL){
 
                btPersistentManifold* contactManifold = 
resultOut->getPersistentManifold();
 
-               bu_log("processCollision(box/box): %s & %s \n", upA->rb_namep, 
upB->rb_namep);
+               struct sim_manifold *current_manifold =
+                       (struct sim_manifold *)bu_malloc(sizeof(struct 
sim_manifold), "sim_manifold: current_manifold");
+               current_manifold->next = NULL;
 
+               if(rbB->first_manifold == NULL){
+                       rbB->first_manifold = current_manifold;
+               }
+               else{
+                       //Go upto the last manifold, keeping a ptr 1 node behind
+                       struct sim_manifold *p1 = rbB->first_manifold, *p2;
+                       while(p1 != NULL){
+                               p2 = p1;
+                               p1 = p1->next;
+                       }
+
+                       p2->next = current_manifold;
+                       //print_manifold_list(rb->first_manifold);
+               }
+               rbB->num_manifolds++;
+
+               bu_log("processCollision(box/box): %s & %s \n", rbA->rb_namep, 
rbB->rb_namep);
+
                //Get the number of points in this manifold
-               int numContacts = contactManifold->getNumContacts();
-               int j;
+               current_manifold->num_contacts = 
contactManifold->getNumContacts();
+               int i;
 
-               bu_log("processCollision : Manifold contacts : %d\n", 
numContacts);
+               bu_log("processCollision : Manifold contacts : %d\n", 
current_manifold->num_contacts);
 
                //Iterate over the points for this manifold
-               for (j=0;j<numContacts;j++){
-                       btManifoldPoint& pt = 
contactManifold->getContactPoint(j);
+               for (i=0; i<current_manifold->num_contacts; i++){
+                       btManifoldPoint& pt = 
contactManifold->getContactPoint(i);
 
                        btVector3 ptA = pt.getPositionWorldOnA();
                        btVector3 ptB = pt.getPositionWorldOnB();
 
+                       VMOVE(ptA, current_manifold->rb_contacts[i].ptA);
+                       VMOVE(ptB, current_manifold->rb_contacts[i].ptB);
+                       VMOVE(pt.m_normalWorldOnB, 
current_manifold->rb_contacts[i].normalWorldOnB);
+
                        bu_log("processCollision: contact %d of %d, %s(%f, %f, 
%f) , %s(%f, %f, %f) \
                                        n(%f, %f, %f)\n",
-                                       j+1, numContacts,
-                                       upA->rb_namep, ptA[0], ptA[1], ptA[2],
-                                       upB->rb_namep, ptB[0], ptB[1], ptB[2],
+                                       i+1, current_manifold->num_contacts,
+                                       rbA->rb_namep, ptA[0], ptA[1], ptA[2],
+                                       rbB->rb_namep, ptB[0], ptB[1], ptB[2],
                                        pt.m_normalWorldOnB[0], 
pt.m_normalWorldOnB[1], pt.m_normalWorldOnB[2]);
 
                }

Modified: brlcad/trunk/src/libged/simulate/simulate.c
===================================================================
--- brlcad/trunk/src/libged/simulate/simulate.c 2011-10-01 13:20:43 UTC (rev 
47009)
+++ brlcad/trunk/src/libged/simulate/simulate.c 2011-10-01 19:47:23 UTC (rev 
47010)
@@ -91,10 +91,35 @@
  */
 void print_rigid_body(struct rigid_body *rb)
 {
-    bu_log("Rigid Body : \"%s\", state = %d\n", rb->rb_namep, rb->state);
+    bu_log("print_rigid_body : \"%s\", state = %d\n", rb->rb_namep, rb->state);
 }
 
 
+void print_manifold_list(struct rigid_body *rb)
+{
+    struct sim_manifold *current_manifold;
+    int i;
+
+       for (current_manifold = rb->first_manifold; current_manifold != NULL;
+                       current_manifold = current_manifold->next) {
+               for (i=0; i<current_manifold->num_contacts; i++) {
+                       bu_log("print_manifold_list: contact %d of %d, (%f, %f, 
%f) , (%f, %f, %f) \
+                                       n(%f, %f, %f)\n",
+                                       i+1, current_manifold->num_contacts,
+                                       current_manifold->rb_contacts[i].ptA[0],
+                                       current_manifold->rb_contacts[i].ptA[1],
+                                       current_manifold->rb_contacts[i].ptA[2],
+                                       current_manifold->rb_contacts[i].ptB[0],
+                                       current_manifold->rb_contacts[i].ptB[1],
+                                       current_manifold->rb_contacts[i].ptB[2],
+                                       
current_manifold->rb_contacts[i].normalWorldOnB[0],
+                                       
current_manifold->rb_contacts[i].normalWorldOnB[1],
+                                       
current_manifold->rb_contacts[i].normalWorldOnB[2]);
+               }
+       }
+}
+
+
 /**
  * Deletes a prim/comb if it exists
  * TODO : lower to librt
@@ -179,6 +204,9 @@
 {
        VSETALL(current_node->linear_velocity, 0.0f);
        VSETALL(current_node->angular_velocity, 0.0f);
+
+       current_node->num_manifolds = 0;
+       current_node->first_manifold = NULL;
        return GED_OK;
 }
 
@@ -601,13 +629,36 @@
 
                insertAABB(gedp, sim_params, current_node);
 
+               print_manifold_list(current_node);
 
+
        }
 
     return GED_OK;
 }
 
 
+int free_manifold_lists(struct simulation_params *sim_params)
+{
+       /* Free memory in manifold list */
+    struct sim_manifold *current_manifold, *next_manifold;
+    struct rigid_body *current_node;
+
+    for (current_node = sim_params->head_node; current_node != NULL;
+               current_node = current_node->next) {
+
+               for (current_manifold = current_node->first_manifold; 
current_manifold != NULL; ) {
+                       next_manifold = current_manifold->next;
+                       bu_free(current_manifold, "simulate : 
current_manifold");
+                       current_manifold = next_manifold;
+                       current_node->num_manifolds--;
+               }
+       }
+
+    return GED_OK;
+}
+
+
 /**
  * The libged physics simulation function :
  * Check flags, adds regions to simulation parameters, runs the simulation
@@ -677,6 +728,8 @@
                        bu_vls_printf(gedp->ged_result_str, "%s: ERROR while 
applying transforms\n", argv[0]);
                        return GED_ERROR;
                }
+
+               free_manifold_lists(&sim_params);
     }
 
 

Modified: brlcad/trunk/src/libged/simulate/simulate.h
===================================================================
--- brlcad/trunk/src/libged/simulate/simulate.h 2011-10-01 13:20:43 UTC (rev 
47009)
+++ brlcad/trunk/src/libged/simulate/simulate.h 2011-10-01 19:47:23 UTC (rev 
47010)
@@ -41,12 +41,13 @@
 
 struct sim_contact {
        vect_t ptA, ptB;
-       vect_t normalB;
+       vect_t normalWorldOnB;
 };
 
 struct sim_manifold {
        int num_contacts;
        struct sim_contact rb_contacts[MAX_CONTACTS_PER_MANIFOLD];
+       struct sim_manifold *next;
 };
 
 /* Contains information about a single rigid body constructed from a BRL-CAD 
region.

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2dcopy2
_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to