PDA

View Full Version : LabView - OpenGL - collision detection



Francisco Porras
09-22-2009, 06:45 PM
Hi, all.

I have spent several months trying to find the way to accomplish some tasks in a project, without success, and I think you may have the solution.

Well, my project is written in LabView, and consists of a 3D scene where it's displayed a robot arm. It has been represented using the 3D Picture Control (LabView toolkit for 3D scene representation). Every mechanical part of the robot is a VRML model (they're not simple geometries) that has been loaded and placed defining relationships between them, and I can control their relative movements with some controls placed on the LabView control panel window.

The representation with the 3D Picture Control has been fairly easy and satisfactory, but now I need to add several advanced capabilities, such as collision detection (between the robot itself, with other objects and with the ground). Since the 3D Picture Control doesn't have these functions, I began to learn OpenGL.

I don't want to redisplay the model again in the OpenGL render window, because it's properly displayed in the 3D Picture Control; but I want to pass geometric data to the C-OpenGL program, rebuilt in this program those mechanical parts that could collide, and use some kind of algorithm for collision detection between them. This code would run once every LabView processing cycle, and check whether there's collision or not.

I have found several problems:

1. I'm trying to execute a C program with OpenGL in LabView. I compile it into a dll and use the Call Library Function Node. I have also replaced the glutMainLoop of GLUT for glutMainLoopEvent of freeGLUT. This is because glutMainLoop never exits the OpenGL main loop and doesn't return the control to the calling function (LabView, in this case); but glutMainLoopEvent does. However, I found that LabView goes wrong when trying to run the program (well, more exactly, the first time I run, it goes OK; but the second, LabView crashes and closes itself).

2. Is it worth learning OpenGL or should I learn OpenSG (OpenSceneGraph, based on C++) since there are high level libraries based on it that detect collisions? Are there efficient algorithms in OpenGL for collision detection? On the other hand, I've found on the internet an OpenSG-based library, called CollDet, that seems to perform these calculations:

CollDet website:
http://cg.in.tu-clausthal.de/research/colldet/index.shtml http://cg.in.tu-clausthal.de/research/colldet/index.shtml



I paste here the code of the OpenGL program:


#include "stdafx.h"
#include <freeglut.h>

extern "C" __declspec(dllexport)int MyFunction();

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,1.0,1.0);
glBegin(GL_POLYGON);
glVertex3f(0.25,0.25,0.0);
glVertex3f(0.75,0.25,0.0);
glVertex3f(0.75,0.75,0.0);
glVertex3f(0.25,0.75,0.0);
glEnd();
glFlush();
}

void init(void)
{
glClearColor(0.0,0.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
}


void MyOpenGL()
{
int argc = 1;
char* argv[1] = {{""}};
glutInit(&amp;argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(250,250);
glutInitWindowPosition(700,100);
glutCreateWindow("My Window");
init();
glutDisplayFunc(display);
glutMainLoopEvent();
}


int MyFunction()
{
MyOpenGL();
return 0;
}


Well, I hope you can help me.

Thanks in advance,
Francisco

ZbuffeR
09-23-2009, 07:41 AM
OpenGL has nothing to do with collision detection, what made you believe that ?

Collision detection (and what to do when it happens) is not a graphic task at all.
It may or may not be a problem for you, but CollDet is not opensource :
http://cg.in.tu-clausthal.de/research/colldet/index.shtml
Instead there is Bullet, with more features :
http://www.bulletphysics.com/wordpress/
or ODE :
http://www.ode.org/

Francisco Porras
09-26-2009, 06:23 AM
Thank you very much for your help, Zbuffer.

Well, in my application, I only want to predict collisions, I mean, to define some kind of distance function between solid parts and create an alert when a certain distance threshold is exceeded. So, it's not needed any physical modelling (it won't be any contact, what I want to do is just prevent from them).

In addition, solid parts are not simple models like cylinders or boxes... instead they're complex mechanical models created in Solid Edge and saved into VRML files.

In that case, which library do you best recommend me, ODE or Bullet?

Is it possible to import such VRML models (or other similar file types) using these libraries?

Thanks again, it was very useful information.

Regards,
Francisco