| 1068 | |
| 1069 | |
| 1070 | bool ConvertProjectionCoordToWorldPickRay( float x, float y, const Matrix* projMat, const Matrix* viewMat, Vector3* rayStart, Vector3* rayDir ) |
| 1071 | { |
| 1072 | Matrix projection2view; |
| 1073 | Matrix view2world; |
| 1074 | |
| 1075 | if( !Inverse( projection2view, *projMat ) ) |
| 1076 | { |
| 1077 | return false; |
| 1078 | } |
| 1079 | |
| 1080 | if( !Inverse( view2world, *viewMat ) ) |
| 1081 | { |
| 1082 | return false; |
| 1083 | } |
| 1084 | |
| 1085 | // Initialize 'rayStart' with projection coordinates and transform it to world |
| 1086 | rayStart->x = x; |
| 1087 | rayStart->y = y; |
| 1088 | rayStart->z = 0.0f; |
| 1089 | |
| 1090 | // Note that this method does _unprojection_ i.e. divides by w |
| 1091 | *rayStart = TransformCoord( *rayStart, projection2view ); |
| 1092 | *rayStart = TransformCoord( *rayStart, view2world ); |
| 1093 | |
| 1094 | // Initialize 'rayEnd' with projection coordinates and put it halfway into projection space |
| 1095 | Vector3 rayEnd( x, y, 0.5f ); |
| 1096 | rayEnd = TransformCoord( rayEnd, projection2view ); |
| 1097 | rayEnd = TransformCoord( rayEnd, view2world ); |
| 1098 | |
| 1099 | *rayDir = Normalize( rayEnd - *rayStart ); |
| 1100 | |
| 1101 | return true; |
| 1102 | } |
no outgoing calls
no test coverage detected