M

#### Marcus Jacobs

that I am about to post. Even with a search of the newsgroup archive,

there are so many subjects about pointers I could search for a long

time and not find an answer to my question.

I am currently integrating the Moller-Trumbore ray/triangle

intersection algorithm

(http://www.ce.chalmers.se/old/staff/tomasm/raytri/raytri.c) into an

existing raytracer. I have basically plagiarized the original code

with some minor modifications to variable names in order integrate it

into the existing raytracer. Below is the source code to the portion

of the source code that I am modifying. The program compiled under

Cygwin using gcc 3.3.3-2. When I run the program, I receive a

"Segmentation Segmentation fault (core dumped)" error. After

recompiling the program using the -ggdb compile option, I executed the

program within gdb in order to find out where the problem is

occurring. At this point, it was determined that the Segmentation

fault occurs at the line that reads:

*u = DOT(tvec, pvec);

Does anyone know if this statement is legal? Moller uses this exact

same code and I am assuming that he has successfully run it. The

reason why I question whether or not this satement is legal is because

I am dereferencing the pointer and setting it value to DOT(tvec,

pvec), since this value is calculated on the fly it has no memory

assigned to it and therefore no address. Am I off base? Is the

original Moller-Trumbore code valid?

Marcus

triangleintersect(o, r) /* compute intersection with polygonal face

*/

OBJREC *o;

register RAY *r;

{

double rdot; /* direction . normal */

double t; /* distance to intersection */

FVECT pisect; /* intersection point */

register FACE *f; /* face record */

register int i;

double *u, *v, *t;

double det, d, inv_det;

double tvec[3], pvec[3], qvec[3], edge1[3], edge2[3];

VSUB(edge1, VERTEX(f,1), VERTEX(f,0));

VSUB(edge2, VERTEX(f,2), VERTEX(f,0));

/* begin calculating determinant - also used to calculate U

parameter */

VCROSS(pvec, r->rdir, edge2);

/* if determinant is near zero, ray lies in plane of triangle */

det = DOT(edge1, pvec);

if (det < FTINY)

return 0;

/* calculate distance from vert0 to ray origin */

VSUB(tvec, r->rorg, VERTEX(f,0));

/* calculate U parameter and test bounds */

*u = DOT(tvec, pvec);

if (*u < 0.0 || *u > det)

return 0;

/* prepare to test V parameter */

VCROSS(qvec, tvec, edge1);

/* calculate V parameter and test bounds */

*v = DOT(r->rdir, qvec) ;

if (*v < 0.0 || *u + *v > det)

return 0;

*t = DOT(edge2,qvec);

inv_det = 1.0/det;

*t *= inv_det;

rdot = -DOT(r->rdir, f->norm);

if (rdot <= FTINY && rdot >= -FTINY) /* ray parallels plane */

t = FHUGE;

//else

// t = (DOT(r->rorg, f->norm) - f->offset) / rdot;

if (t <= FTINY || t >= r->rot) /* not good enough */

return(0);

/* compute intersection */

for (i = 0; i < 3; i++)

pisect

*= r->rorg*

*+ r->rdir*** t;*

r->rot = t;

VCOPY(r->rop, pisect);

r->rod = rdot;

r->ro = o;

VCOPY(r->ron, f->norm);

r->pert[0] = r->pert[1] = r->pert[2] = 0.0;

r->uv[0] = r->uv[1] = 0.0;

r->rox = NULL;

return(1); /* hit */r->rot = t;

VCOPY(r->rop, pisect);

r->rod = rdot;

r->ro = o;

VCOPY(r->ron, f->norm);

r->pert[0] = r->pert[1] = r->pert[2] = 0.0;

r->uv[0] = r->uv[1] = 0.0;

r->rox = NULL;

return(1); /* hit */