Revision: 47092
          http://brlcad.svn.sourceforge.net/brlcad/?rev=47092&view=rev
Author:   abhi2011
Date:     2011-10-05 12:26:14 +0000 (Wed, 05 Oct 2011)
Log Message:
-----------
Modified simulate.c to use the the utils from the utility files now and some 
related cmake changes

Modified Paths:
--------------
    brlcad/trunk/src/libged/CMakeLists.txt
    brlcad/trunk/src/libged/simulate/simulate.c

Modified: brlcad/trunk/src/libged/CMakeLists.txt
===================================================================
--- brlcad/trunk/src/libged/CMakeLists.txt      2011-10-05 12:24:46 UTC (rev 
47091)
+++ brlcad/trunk/src/libged/CMakeLists.txt      2011-10-05 12:26:14 UTC (rev 
47092)
@@ -22,10 +22,10 @@
 # verification (sh/cmakecheck.sh) will fail on dist-hook.
 IF(BULLET_FOUND)
     GED_ADD_CMD(LIBGED_SIM_SOURCES BULLET_INCLUDE_DIR BULLET_LIBRARIES)
-    SET(SIM_SRCS simulate/simphysics.cpp simulate/simulate.c 
simulate/simcollisionalgo.cpp simulate/simcollisionalgo.h)
+    SET(SIM_SRCS simulate/simphysics.cpp simulate/simulate.c 
simulate/simcollisionalgo.cpp simulate/simutils.h simulate/simutils.c)
 ELSE(BULLET_FOUND)
     SET(SIM_SRCS "")
-    SET(ged_ignore_files simulate/simphysics.cpp simulate/simulate.c 
simulate/simcollisionalgo.cpp simulate/simcollisionalgo.h)
+    SET(ged_ignore_files simulate/simphysics.cpp simulate/simulate.c 
simulate/simcollisionalgo.cpp simulate/simcollisionalgo.h simulate/simutils.h 
simulate/simutils.c)
 ENDIF(BULLET_FOUND)
 
 set(LIBGED_SOURCES
@@ -349,6 +349,7 @@
     qray.h
     simulate/simulate.h
     simulate/simcollisionalgo.h
+    simulate/simutils.h
     wdb_qray.h
 )
 CMAKEFILES(${ged_ignore_files})

Modified: brlcad/trunk/src/libged/simulate/simulate.c
===================================================================
--- brlcad/trunk/src/libged/simulate/simulate.c 2011-10-05 12:24:46 UTC (rev 
47091)
+++ brlcad/trunk/src/libged/simulate/simulate.c 2011-10-05 12:26:14 UTC (rev 
47092)
@@ -28,446 +28,30 @@
 
 #ifdef HAVE_BULLET
 
+/* System Headers */
 #include <stdlib.h>
 #include <ctype.h>
 #include <math.h>
 #include <string.h>
 #include "bio.h"
 
+/* Public Headers */
 #include "vmath.h"
 #include "db.h"
 #include "bu.h"
 #include "raytrace.h"
+
+/* Private Headers */
 #include "../ged_private.h"
 #include "simulate.h"
+#include "simutils.h"
 
 
 /* The C++ simulation function */
 extern int run_simulation(struct simulation_params *sim_params);
 
-/* Some constants used to declare arrays */
-#define MAX_FLOATING_POINT_STRLEN 20
-#define NORMAL_SCALE_FACTOR 1
-#define ARROW_WIDTH 0.02
-#define ARROW_BASE_RADIUS 0.02
-#define ARROW_TIP_RADIUS  0.001
 
-
 /**
- * How to use simulate.Blissfully simple interface, more options will be added 
soon
- */
-static void
-print_usage(struct bu_vls *str)
-{
-    bu_vls_printf(str, "Usage: simulate <steps>\n\n");
-    bu_vls_printf(str, "Currently this command adds all regions in the model 
database to a \n\
-    simulation having only gravity as a force. The objects should fall towards 
the ground plane XY.\n");
-    bu_vls_printf(str, "The positions of the regions are set after <steps> 
number of simulation steps.\n");
-    bu_vls_printf(str, "-f <n> <x> <y> <z>\t- Specifies frequency of update(eg 
1/60 Hz)(WIP)\n");
-    bu_vls_printf(str, "-t <x> <y> <z>\t\t  - Specifies time for which to 
run(alternative to -n)(WIP)\n");
-    return;
-}
-
-
-/**
- * Prints a 16 by 16 transform matrix for debugging
- *
- */
-void
-print_matrix(char *rb_namep, mat_t t)
-{
-    int i, j;
-    struct bu_vls buffer = BU_VLS_INIT_ZERO;
-
-    bu_vls_sprintf(&buffer, "------------Transformation 
matrix(%s)--------------\n",
-                  rb_namep);
-
-    for (i=0 ; i<4 ; i++) {
-       for (j=0 ; j<4 ; j++) {
-           bu_vls_sprintf(&buffer, "t[%d]: %f\t", (i*4 + j), t[i*4 + j]);
-       }
-       bu_vls_strcat(&buffer, "\n");
-    }
-
-    bu_vls_strcat(&buffer, 
"-------------------------------------------------------\n");
-    bu_log("%V", &buffer);
-    bu_vls_free(&buffer);
-}
-
-
-/**
- * Prints a struct rigid_body for debugging, more members will be printed later
- */
-void
-print_rigid_body(struct rigid_body *rb)
-{
-    bu_log("print_rigid_body : \"%s\", state = %d\n", rb->rb_namep, rb->state);
-}
-
-
-/**
- * Prints the list of contacts in each manifold of a rigid body
- */
-void
-print_manifold_list(struct rigid_body *rb)
-{
-    struct sim_manifold *current_manifold;
-    int i;
-
-    bu_log("print_manifold_list: %s\n", rb->rb_namep);
-
-    for (current_manifold = rb->first_manifold; current_manifold != NULL;
-        current_manifold = current_manifold->next) {
-
-       bu_log("--Manifold between %s & %s has %d contacts--\n",
-              current_manifold->rbA->rb_namep,
-              current_manifold->rbB->rb_namep,
-              current_manifold->num_contacts);
-
-       for (i=0; i<current_manifold->num_contacts; i++) {
-           bu_log("%d, (%f, %f, %f):(%f, %f, %f), n(%f, %f, %f)\n",
-                  i+1,
-                  V3ARGS(current_manifold->rb_contacts[i].ptA),
-                  V3ARGS(current_manifold->rb_contacts[i].ptB),
-                  V3ARGS(current_manifold->rb_contacts[i].normalWorldOnB));
-       }
-    }
-}
-
-
-/**
- * Prints the args of a command to be executed using libged
- */
-void
-print_command(char* cmd_args[], int num_args)
-{
-    int i;
-    char buffer[500] = "";
-    for (i=0; i<num_args; i++) {
-       sprintf(buffer, "%s %s", buffer, cmd_args[i]);
-    }
-
-    bu_log(buffer);
-}
-
-
-/**
- * Used to prefix a name, requires memory to be freed by caller
- * TODO: Get rid of this, replace all calls to this with bu_vls
- * and prefix using bu functions
- */
-char*
-prefix_name(char *prefix, char *original)
-{
-    /* Prepare prefixed bounding box primitive name */
-    size_t prefix_len, prefixed_name_len;
-    char *prefixed_name;
-
-    prefix_len = strlen(prefix);
-    prefixed_name_len = strlen(prefix)+strlen(original) + 1;
-    prefixed_name = (char *)bu_malloc(prefixed_name_len, "Adding prefix");
-    bu_strlcpy(prefixed_name, prefix, prefix_len + 1);
-    bu_strlcat(prefixed_name + prefix_len, original,
-              prefixed_name_len - prefix_len);
-    return prefixed_name;
-}
-
-
-/**
- * Deletes a prim/comb if it exists.
- *
- * TODO: lower to librt
- */
-int
-kill(struct ged *gedp, char *name)
-{
-    char *cmd_args[5];
-
-    /* Check if the duplicate already exists, and kill it if so */
-    if (db_lookup(gedp->ged_wdbp->dbip, name, LOOKUP_QUIET) != RT_DIR_NULL) {
-       bu_log("kill: WARNING \"%s\" exists, deleting it\n", name);
-       cmd_args[0] = "kill";
-       cmd_args[1] = name;
-       cmd_args[2] = (char *)0;
-
-       if (ged_kill(gedp, 2, (const char **)cmd_args) != GED_OK) {
-           bu_log("kill: ERROR Could not delete existing \"%s\"\n", name);
-           return GED_ERROR;
-       }
-    }
-
-    return GED_OK;
-}
-
-
-/**
- * Deletes and duplicates the prim/comb passed in dp as new_name.
- *
- * TODO : lower to librt
- */
-int
-kill_copy(struct ged *gedp, struct directory *dp, char* new_name)
-{
-    char *cmd_args[5];
-    int rv;
-
-    if (kill(gedp, new_name) != GED_OK) {
-       bu_log("kill_copy: ERROR Could not delete existing \"%s\"\n", new_name);
-       return GED_ERROR;
-    }
-
-    /* Copy the passed prim/comb */
-    cmd_args[0] = "copy";
-    cmd_args[1] = dp->d_namep;
-    cmd_args[2] = new_name;
-    cmd_args[3] = (char *)0;
-    rv = ged_copy(gedp, 3, (const char **)cmd_args);
-    if (rv != GED_OK) {
-       bu_log("kill_copy: ERROR Could not copy \"%s\" to \"%s\"\n", 
dp->d_namep,
-              new_name);
-       return GED_ERROR;
-    }
-
-    return GED_OK;
-}
-
-
-/**
- * Adds a prim/comb to an existing comb or creates it if not existing.
- *
- * TODO: lower to librt
- */
-int
-add_to_comb(struct ged *gedp, char *target, char *add)
-{
-    char *cmd_args[5];
-    int rv;
-
-    cmd_args[0] = "comb";
-    cmd_args[1] = target;
-    cmd_args[2] = "u";
-    cmd_args[3] = add;
-    cmd_args[4] = (char *)0;
-    rv = ged_comb(gedp, 4, (const char **)cmd_args);
-    if (rv != GED_OK) {
-        bu_log("add_to_comb: ERROR Could not add \"%s\" to the combination 
\"%s\"\n",
-              add, target);
-        return GED_ERROR;
-    }
-
-    return GED_OK;
-}
-
-
-/**
- * Draws an arrow from, to using the BOT primitive & SPH
- * Used to draw manifold normals
- * TODO: surely there is a simpler way!
- */
-int
-arrow(struct ged *gedp, char* name, point_t from, point_t to)
-{
-    char *cmd_args[20];
-    int rv;
-    char buffer_str[MAX_FLOATING_POINT_STRLEN];
-    char *prefix_arrow_line = "arrow_line_";
-    char *prefix_arrow_head = "arrow_head_";
-    struct bu_vls arrow_line_vls = BU_VLS_INIT_ZERO, arrow_head_vls = 
BU_VLS_INIT_ZERO;
-    char *prefixed_arrow_line, *prefixed_arrow_head;
-    vect_t v;
-
-    /* Arrow line primitive name */
-    bu_vls_sprintf(&arrow_line_vls, "%s%s", prefix_arrow_line, name);
-    prefixed_arrow_line = bu_vls_addr(&arrow_line_vls);
-
-    /* Arrow line primitive name */
-    bu_vls_sprintf(&arrow_head_vls, "%s%s", prefix_arrow_head, name);
-    prefixed_arrow_head = bu_vls_addr(&arrow_head_vls);
-
-    if (kill(gedp, prefixed_arrow_line) != GED_OK) {
-       bu_log("line: ERROR Could not delete existing \"%s\"\n", 
prefixed_arrow_line);
-       return GED_ERROR;
-    }
-
-    if (kill(gedp, prefixed_arrow_head) != GED_OK) {
-       bu_log("line: ERROR Could not delete existing \"%s\"\n", 
prefixed_arrow_head);
-       return GED_ERROR;
-    }
-
-    cmd_args[0] = "in";
-    cmd_args[1] = prefixed_arrow_line;
-    cmd_args[2] = "bot";
-    cmd_args[3] = "3";
-    cmd_args[4] = "1";
-    cmd_args[5] = "1";
-    cmd_args[6] = "1";
-
-    sprintf(buffer_str, "%f", from[0]); cmd_args[7] = bu_strdup(buffer_str);
-    sprintf(buffer_str, "%f", from[1]); cmd_args[8] = bu_strdup(buffer_str);
-    sprintf(buffer_str, "%f", from[2]); cmd_args[9] = bu_strdup(buffer_str);
-
-    sprintf(buffer_str, "%f", to[0]); cmd_args[10] = bu_strdup(buffer_str);
-    sprintf(buffer_str, "%f", to[1]); cmd_args[11] = bu_strdup(buffer_str);
-    sprintf(buffer_str, "%f", to[2]); cmd_args[12] = bu_strdup(buffer_str);
-
-    sprintf(buffer_str, "%f", from[0]); cmd_args[13] = bu_strdup(buffer_str);
-    sprintf(buffer_str, "%f", from[1]); cmd_args[14] = bu_strdup(buffer_str);
-    sprintf(buffer_str, "%f", from[2]); cmd_args[15] = bu_strdup(buffer_str);
-
-    cmd_args[16] = "0";
-    cmd_args[17] = "1";
-    cmd_args[18] = "2";
-
-    cmd_args[19] = (char *)0;
-
-    print_command(cmd_args, 19);
-
-    rv = ged_in(gedp, 19, (const char **)cmd_args);
-    if (rv != GED_OK) {
-       bu_log("line: ERROR Could not draw arrow line \"%s\" 
(%f,%f,%f)-(%f,%f,%f) \n",
-              prefixed_arrow_line, V3ARGS(from), V3ARGS(to));
-       return GED_ERROR;
-    }
-
-    add_to_comb(gedp, name, prefixed_arrow_line);
-
-    VSUB2(v, to, from);
-    VUNITIZE(v);
-    VSCALE(v, v, 0.1);
-    bu_log("line: Unit vector (%f,%f,%f)\n", V3ARGS(v));
-
-    cmd_args[0] = "in";
-    cmd_args[1] = prefixed_arrow_head;
-    cmd_args[2] = "trc";
-
-    sprintf(buffer_str, "%f", to[0]); cmd_args[3] = bu_strdup(buffer_str);
-    sprintf(buffer_str, "%f", to[1]); cmd_args[4] = bu_strdup(buffer_str);
-    sprintf(buffer_str, "%f", to[2]); cmd_args[5] = bu_strdup(buffer_str);
-
-    sprintf(buffer_str, "%f", v[0]); cmd_args[6] = bu_strdup(buffer_str);
-    sprintf(buffer_str, "%f", v[1]); cmd_args[7] = bu_strdup(buffer_str);
-    sprintf(buffer_str, "%f", v[2]); cmd_args[8] = bu_strdup(buffer_str);
-
-
-    sprintf(buffer_str, "%f", ARROW_BASE_RADIUS); cmd_args[9] = 
bu_strdup(buffer_str);
-    sprintf(buffer_str, "%f", ARROW_TIP_RADIUS);  cmd_args[10] = 
bu_strdup(buffer_str);
-
-    cmd_args[11] = (char *)0;
-
-    print_command(cmd_args, 11);
-
-    rv = ged_in(gedp, 11, (const char **)cmd_args);
-    if (rv != GED_OK) {
-       bu_log("line: ERROR Could not draw arrow head \"%s\" 
(%f,%f,%f)-(%f,%f,%f) \n",
-              prefixed_arrow_head, V3ARGS(from), V3ARGS(to));
-       return GED_ERROR;
-    }
-
-    add_to_comb(gedp, name, prefixed_arrow_head);
-
-    return GED_OK;
-}
-
-
-/**
- * Applies a material to passed comb using libged
- * TODO: lower to librt
- */
-int
-apply_material(struct ged *gedp,
-              char* comb,
-              char* material,
-              unsigned char r,
-              unsigned char g,
-              unsigned char b)
-{
-    int rv;
-    char buffer_str[MAX_FLOATING_POINT_STRLEN];
-    char* cmd_args[28];
-
-    cmd_args[0] = "mater";
-    cmd_args[1] = comb;
-    cmd_args[2] = material;
-
-    sprintf(buffer_str, "%d", r); cmd_args[3] = bu_strdup(buffer_str);
-    sprintf(buffer_str, "%d", g); cmd_args[4] = bu_strdup(buffer_str);
-    sprintf(buffer_str, "%d", b); cmd_args[5] = bu_strdup(buffer_str);
-
-    cmd_args[6] = "0";
-    cmd_args[7] = (char *)0;
-
-    rv = ged_mater(gedp, 7, (const char **)cmd_args);
-    if (rv != GED_OK) {
-       bu_log("apply_material: WARNING Could not adjust the material to %s(%d, 
%d, %d) for \"%s\"\n",
-              material, r, g, b, comb);
-       return GED_ERROR;
-    }
-
-    return GED_OK;
-}
-
-
-/**
- * This function colors the passed comb. It's for showing the current
- * state of the object inside the physics engine.
- *
- * TODO : this should be used with a debugging flag
- */
-int
-apply_color(struct ged *gedp,
-           char* name,
-           unsigned char r,
-           unsigned char g,
-           unsigned char b)
-{
-    struct directory *dp = NULL;
-    struct rt_comb_internal *comb = NULL;
-    struct rt_db_internal intern;
-    struct bu_attribute_value_set avs;
-
-    /* Look up directory pointer for the passed comb name */
-    GED_DB_LOOKUP(gedp, dp, name, LOOKUP_NOISY, GED_ERROR);
-    GED_CHECK_COMB(gedp, dp, GED_ERROR);
-    GED_DB_GET_INTERNAL(gedp, &intern, dp, (fastf_t *)NULL, &rt_uniresource, 
GED_ERROR);
-
-    /* Get a comb from the internal format */
-    comb = (struct rt_comb_internal *)intern.idb_ptr;
-    RT_CK_COMB(comb);
-
-    /* Set the color related members */
-    comb->rgb[0] = r;
-    comb->rgb[1] = g;
-    comb->rgb[2] = b;
-    comb->rgb_valid = 1;
-    comb->inherit = 0;
-
-    /* Get the current attribute set of the comb from the db */
-    bu_avs_init_empty(&avs);
-    if (db5_get_attributes(gedp->ged_wdbp->dbip, &avs, dp)) {
-       bu_vls_printf(gedp->ged_result_str, "apply_transforms: ERROR Cannot get 
attributes for object %s\n", dp->d_namep);
-       bu_avs_free(&avs);
-       return GED_ERROR;
-    }
-
-    /* Sync the changed attributes with the old ones */
-    db5_standardize_avs(&avs);
-    db5_sync_comb_to_attr(&avs, comb);
-    db5_standardize_avs(&avs);
-
-    /* Put back in db to allow drawing */
-    GED_DB_PUT_INTERNAL(gedp, dp, &intern, &rt_uniresource, GED_ERROR);
-    if (db5_update_attributes(dp, &avs, gedp->ged_wdbp->dbip)) {
-       bu_vls_printf(gedp->ged_result_str, "apply_transforms: ERROR failed to 
update attributes\n");
-       bu_avs_free(&avs);
-       return GED_ERROR;
-    }
-
-    bu_avs_free(&avs);
-    return GED_OK;
-}
-
-
-/**
  * Adds physics specific attributes, will be used to add some more properties 
later
  */
 int
@@ -622,337 +206,6 @@
 
 
 /**
- * This function draws the bounding box around a comb as reported by
- * Bullet.
- *
- * TODO: this should be used with a debugging flag
- * TODO: this function will soon be lowered to librt
- */
-int
-insert_AABB(struct ged *gedp, struct simulation_params *sim_params, struct 
rigid_body *current_node)
-{
-    char* cmd_args[28];
-    char buffer[MAX_FLOATING_POINT_STRLEN];
-    int rv;
-    char *prefix = "bb_";
-    char *prefix_reg = "bb_reg_";
-    char *prefixed_name, *prefixed_reg_name;
-    point_t v;
-
-    /* Prepare prefixed bounding box primitive name */
-    prefixed_name = prefix_name(prefix, current_node->rb_namep);
-
-    /* Prepare prefixed bounding box region name */
-    prefixed_reg_name = prefix_name(prefix_reg, current_node->rb_namep);
-
-    /* Delete existing bb prim and region */
-    rv = kill(gedp, prefixed_name);
-    if (rv != GED_OK) {
-       bu_log("insertAABB: ERROR Could not delete existing bounding box arb8 : 
%s \
-               so NOT attempting to add new bounding box\n", prefixed_name);
-       return GED_ERROR;
-    }
-
-    rv = kill(gedp, prefixed_reg_name);
-    if (rv != GED_OK) {
-       bu_log("insertAABB: ERROR Could not delete existing bounding box region 
: %s \
-               so NOT attempting to add new region\n", prefixed_reg_name);
-       return GED_ERROR;
-    }
-
-    /* Setup the simulation result group union-ing the new objects */
-    cmd_args[0] = "in";
-    cmd_args[1] = bu_strdup(prefixed_name);
-    cmd_args[2] = "arb8";
-
-    /* Front face vertices */
-    /* v1 */
-    v[0] = current_node->btbb_center[0] + current_node->btbb_dims[0]/2;
-    v[1] = current_node->btbb_center[1] + current_node->btbb_dims[1]/2;
-    v[2] = current_node->btbb_center[2] - current_node->btbb_dims[2]/2;
-    sprintf(buffer, "%f", v[0]); cmd_args[3] = bu_strdup(buffer);
-    sprintf(buffer, "%f", v[1]); cmd_args[4] = bu_strdup(buffer);
-    sprintf(buffer, "%f", v[2]); cmd_args[5] = bu_strdup(buffer);
-
-    /* v2 */
-    v[0] = current_node->btbb_center[0] + current_node->btbb_dims[0]/2;
-    v[1] = current_node->btbb_center[1] + current_node->btbb_dims[1]/2;
-    v[2] = current_node->btbb_center[2] + current_node->btbb_dims[2]/2;
-    sprintf(buffer, "%f", v[0]); cmd_args[6] = bu_strdup(buffer);
-    sprintf(buffer, "%f", v[1]); cmd_args[7] = bu_strdup(buffer);
-    sprintf(buffer, "%f", v[2]); cmd_args[8] = bu_strdup(buffer);
-
-    /* v3 */
-    v[0] = current_node->btbb_center[0] + current_node->btbb_dims[0]/2;
-    v[1] = current_node->btbb_center[1] - current_node->btbb_dims[1]/2;
-    v[2] = current_node->btbb_center[2] + current_node->btbb_dims[2]/2;
-    sprintf(buffer, "%f", v[0]); cmd_args[9]  = bu_strdup(buffer);
-    sprintf(buffer, "%f", v[1]); cmd_args[10] = bu_strdup(buffer);
-    sprintf(buffer, "%f", v[2]); cmd_args[11] = bu_strdup(buffer);
-
-    /* v4 */
-    v[0] = current_node->btbb_center[0] + current_node->btbb_dims[0]/2;
-    v[1] = current_node->btbb_center[1] - current_node->btbb_dims[1]/2;
-    v[2] = current_node->btbb_center[2] - current_node->btbb_dims[2]/2;
-    sprintf(buffer, "%f", v[0]); cmd_args[12] = bu_strdup(buffer);
-    sprintf(buffer, "%f", v[1]); cmd_args[13] = bu_strdup(buffer);
-    sprintf(buffer, "%f", v[2]); cmd_args[14] = bu_strdup(buffer);
-
-    /* Back face vertices */
-    /* v5 */
-    v[0] = current_node->btbb_center[0] - current_node->btbb_dims[0]/2;
-    v[1] = current_node->btbb_center[1] + current_node->btbb_dims[1]/2;
-    v[2] = current_node->btbb_center[2] - current_node->btbb_dims[2]/2;
-    sprintf(buffer, "%f", v[0]); cmd_args[15] = bu_strdup(buffer);
-    sprintf(buffer, "%f", v[1]); cmd_args[16] = bu_strdup(buffer);
-    sprintf(buffer, "%f", v[2]); cmd_args[17] = bu_strdup(buffer);
-
-    /* v6 */
-    v[0] = current_node->btbb_center[0] - current_node->btbb_dims[0]/2;
-    v[1] = current_node->btbb_center[1] + current_node->btbb_dims[1]/2;
-    v[2] = current_node->btbb_center[2] + current_node->btbb_dims[2]/2;
-    sprintf(buffer, "%f", v[0]); cmd_args[18] = bu_strdup(buffer);
-    sprintf(buffer, "%f", v[1]); cmd_args[19] = bu_strdup(buffer);
-    sprintf(buffer, "%f", v[2]); cmd_args[20] = bu_strdup(buffer);
-
-    /* v7 */
-    v[0] = current_node->btbb_center[0] - current_node->btbb_dims[0]/2;
-    v[1] = current_node->btbb_center[1] - current_node->btbb_dims[1]/2;
-    v[2] = current_node->btbb_center[2] + current_node->btbb_dims[2]/2;
-    sprintf(buffer, "%f", v[0]); cmd_args[21] = bu_strdup(buffer);
-    sprintf(buffer, "%f", v[1]); cmd_args[22] = bu_strdup(buffer);
-    sprintf(buffer, "%f", v[2]); cmd_args[23] = bu_strdup(buffer);
-
-    /* v8 */
-    v[0] = current_node->btbb_center[0] - current_node->btbb_dims[0]/2;
-    v[1] = current_node->btbb_center[1] - current_node->btbb_dims[1]/2;
-    v[2] = current_node->btbb_center[2] - current_node->btbb_dims[2]/2;
-    sprintf(buffer, "%f", v[0]); cmd_args[24] = bu_strdup(buffer);
-    sprintf(buffer, "%f", v[1]); cmd_args[25] = bu_strdup(buffer);
-    sprintf(buffer, "%f", v[2]); cmd_args[26] = bu_strdup(buffer);
-
-    /* Finally make the bb primitive, phew ! */
-    cmd_args[27] = (char *)0;
-    rv = ged_in(gedp, 27, (const char **)cmd_args);
-    if (rv != GED_OK) {
-       bu_log("insertAABB: WARNING Could not draw bounding box for \"%s\"\n",
-              current_node->rb_namep);
-    }
-
-    /* Make the region for the bb primitive */
-    add_to_comb(gedp, prefixed_reg_name, prefixed_name);
-
-    /* Adjust the material for region to be almost transparent */
-    apply_material(gedp, prefixed_reg_name, "plastic tr 0.9", 210, 0, 100);
-
-
-    /* Add the region to the result of the sim so it will be drawn too */
-    add_to_comb(gedp, sim_params->sim_comb_name, prefixed_reg_name);
-
-    bu_free(prefixed_name, "simulate : prefixed_name");
-    bu_free(prefixed_reg_name, "simulate : prefixed_reg_name");
-
-    return GED_OK;
-
-}
-
-
-/**
- * This function inserts a manifold comb as reported by Bullet.
- *
- * TODO: this should be used with a debugging flag
- * TODO: this function will be lowered to librt
- */
-int
-insert_manifolds(struct ged *gedp, struct simulation_params *sim_params, 
struct rigid_body *rb)
-{
-    char* cmd_args[28];
-    char buffer[20];
-    int rv, num_args;
-    char *prefixed_name, *prefixed_reg_name, *prefixed_normal_name;
-    char *prefix = "mf_";
-    char *prefix_reg = "mf_reg_";
-    char *prefix_normal = "normal_";
-    struct bu_vls buffer_vls = BU_VLS_INIT_ZERO;
-    char *name;
-    vect_t scaled_normal;
-    point_t from, to;
-    struct sim_manifold *current_manifold;
-    int i;
-
-    for (current_manifold = rb->first_manifold; current_manifold != NULL;
-        current_manifold = current_manifold->next) {
-
-
-       if(current_manifold->num_contacts > 0){
-
-           /* Prepare prefixed bounding box primitive name */
-           bu_vls_sprintf(&buffer_vls, "%s_%s", 
current_manifold->rbA->rb_namep,
-                          current_manifold->rbB->rb_namep);
-           name = bu_vls_addr(&buffer_vls);
-
-           /* Prepare the manifold shape name */
-           prefixed_name = prefix_name(prefix, name);
-
-           /* Prepare prefixed manifold region name */
-           prefixed_reg_name = prefix_name(prefix_reg, name);
-
-           /* Prepare prefixed manifold region name */
-           prefixed_normal_name = prefix_name(prefix_normal, name);
-
-           /* Delete existing manifold prim and region */
-           rv = kill(gedp, prefixed_name);
-           if (rv != GED_OK) {
-               bu_log("insert_manifolds: ERROR Could not delete existing 
bounding box arb8 : %s \
-                                       so NOT attempting to add new bounding 
box\n", prefixed_name);
-               return GED_ERROR;
-           }
-
-           rv = kill(gedp, prefixed_reg_name);
-           if (rv != GED_OK) {
-               bu_log("insert_manifolds: ERROR Could not delete existing 
bounding box region : %s \
-                                       so NOT attempting to add new region\n", 
prefixed_reg_name);
-               return GED_ERROR;
-           }
-
-           /* Setup the simulation result group union-ing the new objects */
-           cmd_args[0] = "in";
-           cmd_args[1] = bu_strdup(prefixed_name);
-           cmd_args[2] = (char *)0;
-           num_args = 2;
-
-           switch(current_manifold->num_contacts) {
-               case 1:
-                   bu_log("1 contact got, no manifold drawn");
-                   break;
-
-               case 2:
-                   cmd_args[2] = "arb4";
-                   sprintf(buffer, "%f", 
current_manifold->rb_contacts[0].ptA[0]);
-                   cmd_args[3] = bu_strdup(buffer);
-                   sprintf(buffer, "%f", 
current_manifold->rb_contacts[0].ptA[1]);
-                   cmd_args[4] = bu_strdup(buffer);
-                   sprintf(buffer, "%f", 
current_manifold->rb_contacts[0].ptA[2]);
-                   cmd_args[5] = bu_strdup(buffer);
-
-                   sprintf(buffer, "%f", 
current_manifold->rb_contacts[1].ptA[0]);
-                   cmd_args[6] = bu_strdup(buffer);
-                   sprintf(buffer, "%f", 
current_manifold->rb_contacts[1].ptA[1]);
-                   cmd_args[7] = bu_strdup(buffer);
-                   sprintf(buffer, "%f", 
current_manifold->rb_contacts[1].ptA[2]);
-                   cmd_args[8] = bu_strdup(buffer);
-
-                   sprintf(buffer, "%f", 
current_manifold->rb_contacts[1].ptB[0]);
-                   cmd_args[9] = bu_strdup(buffer);
-                   sprintf(buffer, "%f", 
current_manifold->rb_contacts[1].ptB[1]);
-                   cmd_args[10] = bu_strdup(buffer);
-                   sprintf(buffer, "%f", 
current_manifold->rb_contacts[1].ptB[2]);
-                   cmd_args[11] = bu_strdup(buffer);
-
-                   sprintf(buffer, "%f", 
current_manifold->rb_contacts[0].ptB[0]);
-                   cmd_args[12] = bu_strdup(buffer);
-                   sprintf(buffer, "%f", 
current_manifold->rb_contacts[0].ptB[1]);
-                   cmd_args[13] = bu_strdup(buffer);
-                   sprintf(buffer, "%f", 
current_manifold->rb_contacts[0].ptB[2]);
-                   cmd_args[14] = bu_strdup(buffer);
-
-                   cmd_args[15] = (char *)0;
-                   num_args = 15;
-
-                   VADD2SCALE(from, current_manifold->rb_contacts[0].ptA,
-                              current_manifold->rb_contacts[1].ptB, 0.5);
-                   break;
-
-               case 3:
-                   bu_log("3 contacts got, no manifold drawn");
-                   break;
-
-               case 4:
-                   cmd_args[2] = "arb8";
-                   for (i=0; i<4; i++) {
-                       sprintf(buffer, "%f", 
current_manifold->rb_contacts[i].ptA[0]);
-                       cmd_args[3+i*3] = bu_strdup(buffer);
-                       sprintf(buffer, "%f", 
current_manifold->rb_contacts[i].ptA[1]);
-                       cmd_args[4+i*3] = bu_strdup(buffer);
-                       sprintf(buffer, "%f", 
current_manifold->rb_contacts[i].ptA[2]);
-                       cmd_args[5+i*3] = bu_strdup(buffer);
-
-                       sprintf(buffer, "%f", 
current_manifold->rb_contacts[i].ptB[0]);
-                       cmd_args[15+i*3] = bu_strdup(buffer);
-                       sprintf(buffer, "%f", 
current_manifold->rb_contacts[i].ptB[1]);
-                       cmd_args[16+i*3] = bu_strdup(buffer);
-                       sprintf(buffer, "%f", 
current_manifold->rb_contacts[i].ptB[2]);
-                       cmd_args[17+i*3] = bu_strdup(buffer);
-
-                       /* 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 
cmd_argsrent_manifold->rb_contacts[i].normalWorldOnB[2]);*/
-                   }
-                   cmd_args[27] = (char *)0;
-                   num_args = 27;
-
-                   VADD2SCALE(from, current_manifold->rb_contacts[0].ptA,
-                              current_manifold->rb_contacts[2].ptB, 0.5);
-                   break;
-
-               default:
-                   bu_log("%d contacts got, no manifold drawn", 
current_manifold->num_contacts);
-                   cmd_args[2] = (char *)0;
-                   num_args = 2;
-           }
-
-           print_command(cmd_args, num_args);
-
-           /* Finally make the manifold primitive, if proper command generated 
*/
-           if (num_args > 2) {
-               rv = ged_in(gedp, num_args, (const char **)cmd_args);
-               if (rv != GED_OK) {
-                   bu_log("insert_manifolds: WARNING Could not draw manifold 
for \"%s\"\n", rb->rb_namep);
-               }
-
-               /* Make the region for the manifold primitive */
-               add_to_comb(gedp, prefixed_reg_name, prefixed_name);
-
-               /* Adjust the material for region to be visible */
-               apply_material(gedp, prefixed_reg_name, "plastic tr 0.9", 210, 
210, 0);
-
-               /* Add the region to the result of the sim so it will be drawn 
too */
-               add_to_comb(gedp, sim_params->sim_comb_name, prefixed_reg_name);
-
-               /* Finally draw the normal */
-               VSCALE(scaled_normal, 
current_manifold->rb_contacts[0].normalWorldOnB, NORMAL_SCALE_FACTOR);
-               VADD2(to, scaled_normal, from);
-
-               bu_log("insert_manifolds: line (%f,%f,%f)-> (%f,%f,%f)-> 
(%f,%f,%f) \n",
-                      V3ARGS(current_manifold->rb_contacts[0].normalWorldOnB),
-                      V3ARGS(to),
-                      V3ARGS(scaled_normal));
-
-               arrow(gedp, prefixed_normal_name, from, to);
-               add_to_comb(gedp, sim_params->sim_comb_name, 
prefixed_normal_name);
-
-           }/*  if-num_args */
-
-           bu_free(prefixed_name, "simulate : prefixed_name");
-           bu_free(prefixed_reg_name, "simulate : prefixed_reg_name");
-
-       }/* if-num_contacts */
-
-    } /* end for-manifold */
-
-
-    return GED_OK;
-
-}
-
-
-/**
  * This function takes the transforms present in the current node and
  * applies them in 3 steps : translate to origin, apply the rotation,
  * then translate to final position with respect to origin(as obtained

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


------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to