#### Archived

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

# could someone check my function?

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

## 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 on other sites
I don''t see anything wrong with your code, maybe you''re defining some of your polygons differently (ie. some have the vertexes defined in a clockwise order and others in a counter-clockwise order)?

1. 1
2. 2
3. 3
Rutin
24
4. 4
5. 5
khawk
14

• 11
• 11
• 23
• 10
• 9
• ### Forum Statistics

• Total Topics
633651
• Total Posts
3013129
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!