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
