Face normals
Hey, I have some prob with calc the face normals, my code looks like:
Vertex calcnormal(Vertex V1, Vertex V2, Vertex V3)
{
Vertex p,q;
Vertex n;
float length;
p.x = V2.x - V1.x;
p.y = V2.y - V1.y;
p.z = V2.z - V1.z;
q.x = V3.x - V1.x;
q.y = V3.y - V1.y;
q.z = V3.z - V3.z;
n.x = p.y * q.z - p.z * q.y;
n.y = p.z * q.x - p.x * q.z;
n.z = p.x * q.y - p.y * q.x;
length = sqrt(n.x*n.x + n.y*n.y + n.z*n.z);
if(length != 0)
{
n.x /= length;
n.y /= length;
n.z /= length;
}
return(n);
}
but the resultate is http://brudar.nu/~asmodi/screenshot.jpg
Any one who can see anythign wrong?
/asm0
/asm0
should the line:
q.z = V3.z - V3.z;
not be:
q.z = V3.z - V1.z;
-=[Megahertz]=-
q.z = V3.z - V3.z;
not be:
q.z = V3.z - V1.z;
-=[Megahertz]=-
-=[Megahertz]=-
Hey, he''s got it... Ya, switcht the thing there... V3.z to V1.z... it really stands out when you look at them...
btw... You could declare the operation of vertex (vector) division in one operator function...
Vector operator/ (const Vector vector, const double scalar)
{
return Vector(vector.x / scalar, vector.y / scalar, vector.z / scalar);
}
For instance... Providing your constructor can take three values (x, y, z) to set as the coords....
S.
btw... You could declare the operation of vertex (vector) division in one operator function...
Vector operator/ (const Vector vector, const double scalar)
{
return Vector(vector.x / scalar, vector.y / scalar, vector.z / scalar);
}
For instance... Providing your constructor can take three values (x, y, z) to set as the coords....
S.
Thx f0x
I think it works good now with flat shaded, but how does I fix it for smooth shaded?
/asm0
I think it works good now with flat shaded, but how does I fix it for smooth shaded?
/asm0
/asm0
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement