# point normals

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 11/06/2010 at 10:18, xxxxxxxx wrote:

I see that you're still not normalizing the result of polygonNormal() or of polyNormal, after you've divided it... have you tried that?

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 11/06/2010 at 10:25, xxxxxxxx wrote:

yes, that gave me even stranger results. what i dont understand is that it works for most of the points

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 11/06/2010 at 11:30, xxxxxxxx wrote:

Ok, here is some verified working code that I've stripped out to be stand-alone callable routines...

``````
//---------------------------------------------------------------------------------------
//***************************************************************************************
// GetVertexNormals()
//***************************************************************************************
//---------------------------------------------------------------------------------------
Vector *GetVertexNormals(PolygonObject *pObj)
{
LONG numVerts = pObj->GetPointCount();
LONG numPolys = pObj->GetPolygonCount();
const Vector *pVerts = pObj->GetPointR();
const CPolygon *pPolys = pObj->GetPolygonR();

// initialize neighbor class... this is used to compute m_SrcvNorms
Neighbor neighbor;
if( !neighbor.Init(numVerts, pPolys, numPolys, NULL) )
return NULL;

// Allocate array of Normal Vectors to fill in and return
Vector *pNormals = (Vector * )GeAlloc(numVerts * sizeof(Vector));
if( !pNormals )     return NULL;

// Determine a Normal for each vertex of mesh
LONG i, j, faceCnt, *pFaces = NULL;
Vector vNorm;
for(i=0; i<numVerts; i++)
{
vNorm = Vector();          // (re)intitialize
neighbor.GetPointPolys(i, &pFaces;, &faceCnt;);
if( faceCnt )
{
for(j=0; j<faceCnt; j++)
{
Vector n = CalcFaceNormal(pVerts, pPolys[pFaces[j]]);
vNorm += !n;
}
vNorm /= faceCnt;          // average the normal(s)
pNormals[i] = !vNorm;     // normalize and store
}
else
pNormals[i] = Vector(0.0,1.0,0.0);     // default case = Up for any stray verts
}
return pNormals;
}

//---------------------------------------------------------------------------------------
//***************************************************************************************
// AddNormSplineObject()
//***************************************************************************************
//---------------------------------------------------------------------------------------
void AddNormSplineObject(PolygonObject *pObj, LONG splineLen)
{
Vector *pNormals = GetVertexNormals(pObj);
if( !pNormals )     return;

LONG numNorms = pObj->GetPointCount();

// allocate spline object large enough for all points
SplineObject *splineOp = SplineObject::Alloc(2*numNorms,Tlinear);
if( !splineOp || !splineOp->MakeVariableTag(Tsegment,numNorms) )
{
MessageDialog(String("Spline Object Allocation Failed"));
GeFree(pNormals);
return;
}
splineOp->SetName(String("NormSplines"));

Vector *padr = splineOp->GetPointW();
Segment *sadr = splineOp->GetSegmentW();

if( !padr || !sadr )
{
MessageDialog(String("Spline Object Data Setup Failed"));
GeFree(pNormals);
SplineObject::Free(splineOp);
return;
}

const Vector *pVerts = pObj->GetPointR();
Matrix mg = pObj->GetMgn();
LONG normCnt = 0;
LONG vertCnt = 0;
LONG i;
for(i=0; i<numNorms; i++)
{
sadr[normCnt].cnt = 2;
sadr[normCnt++].closed = false;

padr[vertCnt++] = pVerts[i] * mg;
padr[vertCnt++] = (pVerts[i] + (pNormals[i] * splineLen)) * mg;
}
splineOp->GetDataInstance()->SetBool(SPLINEOBJECT_CLOSED,false);

GeFree(pNormals); // done with this now

BaseDocument *pBaseDoc = pObj->GetDocument();
pBaseDoc->InsertObject(splineOp,NULL,NULL);
splineOp->Message(MSG_UPDATE);
}
``````

...just cut/paste that into your code and call the AddNormSplineObject() routine with your PolygonObject. Once you've verified that it's working, you can either use it as-is, or reference it to figure out why yours is not working.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 11/06/2010 at 11:31, xxxxxxxx wrote:

If you have any compile errors or trouble with include files, let me know.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 11/06/2010 at 12:08, xxxxxxxx wrote:

thank you very much.. after first crash, i passed my doc to the function like this,
void AddNormSplineObject(PolygonObject *pObj, LONG splineLen,BaseDocument *doc)

and it works.. now i need to understand why it does :)

again, thank you very very much for your help!

cheers,
ello

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 11/06/2010 at 12:14, xxxxxxxx wrote:

D'oh! I guess that your PolygonObject wasn't yet attached to the scene :). I usually test all results before using pointers like that, but I kinda threw that in there at the last minute when I was stripping out my old Class member code.

Anyway... if you want, you can just use that GetVertexNormals() routine as-is (just be sure to GeFree() the array when you're done with it).

Good luck!

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 11/06/2010 at 12:18, xxxxxxxx wrote:

i now used the pNormals to rotate my clones and now it looks like when i told you how it looked after i used the normalised normals:

any idea? how can this be?? i'll have to recheck my code after the rotation. i just dont understand why it works for polygons, but not for points. very strange

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 11/06/2010 at 12:21, xxxxxxxx wrote:

I'd need to see the rest of your code (where/how you are using the normals), but my guess is that it's something to do with the Matrices.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 11/06/2010 at 12:34, xxxxxxxx wrote:

can i send you the code via mail?

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 11/06/2010 at 13:19, xxxxxxxx wrote:

Sure... typhoon [at] jetbroadband [dot] com