Jeremy Friesner (jfriesne++at++sdcc10.ucsd.edu)
Mon, 20 May 1996 20:40:33 -0700 (PDT)
I want to make an HUD that I can use to "track" 3D objects
in my scene with little 2-D marker boxes.
The problem is:
Given either a DCS matrix or a 3-dimensional set of
world coordinates for an object, how can I calculate
the two dimensional coordinate corresponding to where
that point will be plotted in the viewport?
My current (naive) attempt at a solution looks like:
void
HUDTracker::MapThreeDToTwoD(pfVec3 object, float * screen_x, float * screen_y)
{
pfMatrix viewMat, projMat;
long prevMode;
/* Get the viewing matrix */
viewMat = ship->getViewMatrix();
/* Get the projection matrix */
prevMode = getmmode();
mmode(MPROJECTION);
getmatrix((float (*)[4]) &projMat);
mmode(prevMode);
/* transform 3D world coords to 3D view coords */
object.xformVec(object, viewMat);
/* transform 3D view coords to 2D device coords */
object.xformVec(object, projMat);
/* return the 2D coordinates */
*screen_x = object[0];
*screen_y = object[2];
}
Which would (supposedly) return the proper screen coordinates
in screen_x and screen_y. Unfortunately, it doesn't work. :(
What am I doing wrong? Is there another way to go about this?
-Jeremy
jfriesne++at++ucsd.edu
jaf++at++sdchemw1.ucsd.edu
=======================================================================
List Archives, FAQ, FTP: http://www.sgi.com/Technology/Performer.html
Submissions: info-performer++at++sgi.com
Admin. requests: info-performer-request++at++sgi.com
This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:52:54 PDT