Projection problems...

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Eib
Posts: 7
Joined: Wed Apr 15, 2009 4:56 am

Projection problems...

Post by Eib »

I'm trying to project world space coordinates to screen space with the following code.

Code: Select all

        vfpu_identity_matrix(&temp_matrix);
        gumFastInverse(&temp_matrix,cam->view_matrix);

        vfpu_transform_vector(&temp_matrix,sun->position,&temp_vector4d);
        vfpu_transform_vector(cam->proj_matrix,&temp_vector4d,sun->screen);

        if (sun->screen->w!=0.0f) {
           w=1.0f/sun->screen->w;
           sun->screen->x=sun->screen->x*w;
           sun->screen->y=sun->screen->y*w;
           }
        sun->screen->x*=240.0f;
        sun->screen->y*=-136.0f;
        sun->screen->x+=240.0f;
        sun->screen->y+=136.0f;

        // All vectors are 4d. View and projection matrices are ok.
        // sun->position is a world-space position
        // sun->screen is a resulting screen-space position
Results are slightly incorrect. Can someone give a hint please where i made a mistake in this code ?
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

Well it's going to get quite cranky when screen->w is very near or equal to zero, or negative.

The best idea is to clip these polygons before you get anywhere near this stage in the pipeline.

Jim
Post Reply