I’m using opengl to do the math, i’m still learning the basics, until then i really need
to get some work done
what i need is to convert a mesh after
it being transformed by opengl, after i grad the projection matrix and the modelview matrix how can i use them to convert a vertice to 2d screen space?
OK, let’s try this:
let v(x,y,z) be the vertex in world space, modelview be your world/model view matrix and projection be your projection matrix. What you need to do is:
matrix t = projection * modelview;
t.transpose();
vertex s = t.transform(v);
where transfrom() method is defined as:
(actually pasted from my code)
inline vec3_t
matrix_t::transform(const vec3_t& v) const
{
float w = v.xwx + v.ywy + v.zwz + ww;
return vec3_t(
(v.xxx+v.yxy+v.zxz+xw)/w,
(v.xyx+v.yyy+v.zyz+yw)/w,
(v.xzx+v.yzy+v.zzz+zw)/w);
}
now “s” is your vertex in normalized coords;
apply the following:
// where objx, objy, and objz are the world coordinates
winx and winy are the 2d screen coord.
and Bonus, if winz>1 then you are facing away from that point,
and if winz<=1 then you are facing towards.