Cage opened this issue on Dec 20, 2006 · 1232 posts
Spanki posted Sat, 15 March 2008 at 4:18 PM
...just for completeness-sake, here's the C code version of that earlier test routine...
static PyObject *timetest1(PyObject *self, PyObject
*args)<br></br>
{<br></br>
PyListObject *pVectorList; // the passed in vector list
(list-of-Vectors)<br></br>
VECTOR *pVector;<br></br>
double ray[3] = {0.0, 1.0, 0.0};<br></br>
double pn[3] = {0.0, 1.0, 0.0};<br></br>
double point[3];<br></br>
double *v;<br></br>
double *v0,*v1,*v2;<br></br>
double intersect = 1.0;<br></br>
double ndota, ndotv;<br></br>
long vCount, pi, vi;
// start by deconstructing the args<br></br>
if (!PyArg_ParseTuple(args, "iO", &vCount,
&pVectorList ))<br></br>
onError("timetest requires a count and a list of
vectors");
if(!PyList_Check(pVectorList))<br></br>
onError("timetest requires a list of vectors as
second arg");
// try to modify each vertex...<br></br>
for(pi=0; pi<100; pi++)<br></br>
{<br></br>
for(vi=0; vi<vCount; vi++)<br></br>
{<br></br>
double eu[3], ev[3], wx[3];<br></br>
double uu, vv, uv, wu, wv;
// get each vertex/vector...<br></br>
pVector = (VECTOR
*)pVectorList->ob_item[vi]; //PyList_GET_ITEM(pVectorList,
i);<br></br>
if(!isVector(pVector))<br></br>
onError("timetest requires a list of
vectors as second arg");<br></br>
v = &pVector->v[0];
ndota = V3_DOT(pn, ray);<br></br>
ndotv = V3_DOT(pn, v);
point[0] = v[0] + (ray[0] *
intersect);<br></br>
point[1] = v[1] + (ray[1] * intersect);<br></br>
point[2] = v[2] + (ray[2] *
intersect);
v0 = &((VECTOR
*)pVectorList->ob_item[0])->v[0]; //PyList_GET_ITEM(pVectorList,
0);<br></br>
v1 = &((VECTOR
*)pVectorList->ob_item[1])->v[0]; //PyList_GET_ITEM(pVectorList,
1);<br></br>
v2 = &((VECTOR
*)pVectorList->ob_item[2])->v[0]; //PyList_GET_ITEM(pVectorList,
2);
V3_SUB(v1, v0, eu); //
vecsub(v1,v0)<br></br>
V3_SUB(v2, v0, ev); //
vecsub(v2,v0)<br></br>
uu = V3_DOT(eu, eu); //
vector_dotproduct(eu,eu)<br></br>
vv = V3_DOT(ev, ev); //
vector_dotproduct(ev,ev)<br></br>
uv = V3_DOT(eu, ev); //
vector_dotproduct(eu,ev)<br></br>
V3_SUB(point, v0, wx); //
vecsub(point,v0)<br></br>
wu = V3_DOT(wx, eu); //
vector_dotproduct(wx,eu)<br></br>
wv = V3_DOT(wx, ev); //
vector_dotproduct(wx,ev)<br></br>
}<br></br>
}
Py_INCREF(Py_None);<br></br>
return Py_None;<br></br>
}<br></br>
...it's not quite as easy to follow as the python code currently, but it's doing the exact same computations.
Cinema4D Plugins (Home of Riptide, Riptide Pro, Undertow, Morph Mill, KyamaSlide and I/Ogre plugins) Poser products Freelance Modelling, Poser Rigging, UV-mapping work for hire.