Archived

This topic is now archived and is closed to further replies.

could someone check my function

This topic is 6360 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

vertf* normal(vertex* st1,vertex* st2,vertex* st3) { float len; numb1.x=(float)atof(&(st1->vx[0]));numb1.y=(float)atof(&(st1->vy[0]));numb1.z=(float)atof(&(st1->vz[0])); numb2.x=(float)atof(&(st2->vx[0]));numb2.y=(float)atof(&(st2->vy[0]));numb2.z=(float)atof(&(st2->vz[0])); numb3.x=(float)atof(&(st3->vx[0]));numb3.y=(float)atof(&(st3->vy[0]));numb3.z=(float)atof(&(st3->vz[0])); v1.x=numb1.x - numb2.x; v1.y=numb1.y - numb2.y; v1.z=numb1.z - numb2.z; v2.x=numb3.x - numb2.x; v2.y=numb3.y - numb2.y; v2.z=numb3.z - numb2.z; //cross product norm.x=(v1.y*v2.z)-(v2.y*v1.z); norm.y=(v1.z*v2.x)-(v2.z*v1.x); norm.z=(v1.x*v2.y)-(v2.x*v1.y); //normalizziamo!!!!!!!!!!! len=(float)sqrt(potenzaf(norm.x,2)+potenzaf(norm.y,2)+potenzaf(norm.z,2)); if (len==0.0f)len=1.0f; norm.x/=len; norm.y/=len; norm.z/=len; return (&norm); } this function is passed 3 struct : struct vertex { char vx[15],vy[15],vz[15];} and then result a pointer to: struct vertf { float x,y,z;}numb1,numb2,numb3,v1,v2,norm; but it seem don''t works properly because when i try to display the result some polygon are invisible ,so i think the normal aren''t calculated well!

Share this post


Link to post
Share on other sites
mate this is horrendous im not surprised youve got errors , gotta make it easy on yourself by writing clean code

the cross product looks wrong

{
v[0] = p.v[1] * q.v[2] - p.v[2] * q.v[1];
v[1] = p.v[2] * q.v[0] - p.v[0] * q.v[2];
v[2] = p.v[0] * q.v[1] - p.v[1] * q.v[0];
}

try breaking the whole thing into smaller pieces. and why are your vertex stored as text?

Share this post


Link to post
Share on other sites
sorry but your cross product is exactly the same of the mine,
and the vertex are in text format because i''m calculating the normal of a model in a .off file format which is a text file format.

Share this post


Link to post
Share on other sites
youre right sorry about that it is the same. though you should have various maths classes in your project eg taken from kong
http://members.xoom.com/myBollux/home.html

this works out a normal

VECTOR p = newWall->points[1].vertex - newWall->points[0].vertex;
VECTOR q = newWall->points[2].vertex - newWall->points[0].vertex;
VECTOR ans;
ans.Cross(p,q);
ans.Normalize();

u could even simplify further by going someit like

VECTOR norm = giveme_the_normal(vert1, vert2, vert3);

are u getting the right values when u convert the chars to floats
from here numb1.x=(...

Share this post


Link to post
Share on other sites