/* Transforms all vertices in the specified object into view space, then perspective projects them to screen space and maps them to screen coordinates, storing the results in the object. */ #include #include "polygon.h" void XformAndProjectPoints(double Xform[4][4], struct Object * ObjectToXform) { int i, NumPoints = ObjectToXform->NumVerts; struct Point3 * Points = ObjectToXform->VertexList; struct Point3 * XformedPoints = ObjectToXform->XformedVertexList; struct Point3 * ProjectedPoints = ObjectToXform->ProjectedVertexList; struct Point * ScreenPoints = ObjectToXform->ScreenVertexList; for (i=0; iX = XformedPoints->X / XformedPoints->Z * PROJECTION_RATIO * (SCREEN_WIDTH / 2.0); ProjectedPoints->Y = XformedPoints->Y / XformedPoints->Z * PROJECTION_RATIO * (SCREEN_WIDTH / 2.0); ProjectedPoints->Z = XformedPoints->Z; /* Convert to screen coordinates. The Y coord is negated to flip from increasing Y being up to increasing Y being down, as expected by the polygon filler. Add in half the screen width and height to center on the screen */ ScreenPoints->X = ((int) floor(ProjectedPoints->X + 0.5)) + SCREEN_WIDTH/2; ScreenPoints->Y = (-((int) floor(ProjectedPoints->Y + 0.5))) + SCREEN_HEIGHT/2; } }