Rev 124 | Rev 136 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 124 | Rev 131 | ||
---|---|---|---|
Line 185... | Line 185... | ||
185 | static int initial_height = 0; // initial height of the render surface, in pixels (typically equal to the max displayable size) |
185 | static int initial_height = 0; // initial height of the render surface, in pixels (typically equal to the max displayable size) |
186 | static float current_width = 0.0f; // current width of the client area on which the render surface is rendered, in pixels |
186 | static float current_width = 0.0f; // current width of the client area on which the render surface is rendered, in pixels |
187 | static float current_height = 0.0f; // current height of the client area on which the render surface is rendered, in pixels |
187 | static float current_height = 0.0f; // current height of the client area on which the render surface is rendered, in pixels |
188 | static D3DCOLOR ambient_light; |
188 | static D3DCOLOR ambient_light; |
189 | static vector_t camera_position; |
189 | static vector_t camera_position; |
190 | static |
190 | static vector_t scene_lookatpoint = { 0.0f, 0.0f, 0.0f }; |
191 | static const vector_t upwards_direction = { 0.0f, 0.0f, 1.0f }; |
191 | static const vector_t upwards_direction = { 0.0f, 0.0f, 1.0f }; |
192 | static int best_supported_filter; |
192 | static int best_supported_filter; |
193 | static bool is_fsaa_supported = false; |
193 | static bool is_fsaa_supported = false; |
194 | 194 | ||
195 | static wchar_t printf_buffer[0xffff]; |
195 | static wchar_t printf_buffer[0xffff]; |
Line 625... | Line 625... | ||
625 | d3ddev->LightEnable (light_index, true); // turn on light #index |
625 | d3ddev->LightEnable (light_index, true); // turn on light #index |
626 | } |
626 | } |
627 | 627 | ||
628 | //////////////////////////////// |
628 | //////////////////////////////// |
629 | // View transform |
629 | // View transform |
- | 630 | ||
- | 631 | // update the point looked at |
|
- | 632 | scene_lookatpoint.x = lookatpoint_x; |
|
- | 633 | scene_lookatpoint.y = lookatpoint_y; |
|
630 | 634 | ||
631 | // compute the sine and cosine of the pitch component |
635 | // compute the sine and cosine of the pitch component |
632 | angle = current_pitch * TO_RADIANS; |
636 | angle = current_pitch * TO_RADIANS; |
633 | sin_pitch = sinf (angle); |
637 | sin_pitch = sinf (angle); |
634 | cos_pitch = cosf (angle); |
638 | cos_pitch = cosf (angle); |
Line 637... | Line 641... | ||
637 | angle = current_yaw * TO_RADIANS; |
641 | angle = current_yaw * TO_RADIANS; |
638 | sin_yaw = sinf (angle); |
642 | sin_yaw = sinf (angle); |
639 | cos_yaw = cosf (angle); |
643 | cos_yaw = cosf (angle); |
640 | 644 | ||
641 | // build the camera position |
645 | // build the camera position |
642 | camera_position.x = (float) -(cos_pitch * cos_yaw) * current_distance; |
646 | camera_position.x = scene_lookatpoint.x + (float) -(cos_pitch * cos_yaw) * current_distance; |
643 | camera_position.y = (float) -(cos_pitch * sin_yaw) * current_distance; |
647 | camera_position.y = scene_lookatpoint.y + (float) -(cos_pitch * sin_yaw) * current_distance; |
644 | camera_position.z = (float) sin_pitch * current_distance; |
648 | camera_position.z = (float) sin_pitch * current_distance; |
645 | 649 | ||
646 | // set up a view matrix |
650 | // set up a view matrix |
647 | D3DXMatrixLookAtLH (&view_matrix, |
651 | D3DXMatrixLookAtLH (&view_matrix, |
648 | (D3DXVECTOR3 *) &camera_position, // camera position |
652 | (D3DXVECTOR3 *) &camera_position, // camera position |
649 | (D3DXVECTOR3 *) & |
653 | (D3DXVECTOR3 *) &scene_lookatpoint, // look-at position |
650 | (D3DXVECTOR3 *) &upwards_direction); // up direction |
654 | (D3DXVECTOR3 *) &upwards_direction); // up direction |
651 | 655 | ||
652 | // tell Direct3D about our matrix |
656 | // tell Direct3D about our matrix |
653 | d3ddev->SetTransform (D3DTS_VIEW, &view_matrix); |
657 | d3ddev->SetTransform (D3DTS_VIEW, &view_matrix); |
654 | 658 | ||
Line 1119... | Line 1123... | ||
1119 | vector_t v_intersection; |
1123 | vector_t v_intersection; |
1120 | 1124 | ||
1121 | // find the floor plane (only do it once) |
1125 | // find the floor plane (only do it once) |
1122 | if (!is_planefound) |
1126 | if (!is_planefound) |
1123 | { |
1127 | { |
1124 | D3DXPlaneFromPointNormal (&floor_plane, (D3DXVECTOR3 *) & |
1128 | D3DXPlaneFromPointNormal (&floor_plane, (D3DXVECTOR3 *) &scene_lookatpoint, (D3DXVECTOR3 *) &upwards_direction); |
1125 | is_planefound = true; // once and for all, as this plane will never change |
1129 | is_planefound = true; // once and for all, as this plane will never change |
1126 | } |
1130 | } |
1127 | 1131 | ||
1128 | // get the current projection and view matrices, and invert the view matrix |
1132 | // get the current projection and view matrices, and invert the view matrix |
1129 | d3ddev->GetTransform (D3DTS_PROJECTION, &projection_matrix); |
1133 | d3ddev->GetTransform (D3DTS_PROJECTION, &projection_matrix); |
Line 1384... | Line 1388... | ||
1384 | // quick access to meshes |
1388 | // quick access to meshes |
1385 | mesh = &meshes[sceneobject->mesh_index]; |
1389 | mesh = &meshes[sceneobject->mesh_index]; |
1386 | tile_mesh = &meshes[theme->tile_meshindex]; |
1390 | tile_mesh = &meshes[theme->tile_meshindex]; |
1387 | 1391 | ||
1388 | // set the world transform at location |
1392 | // set the world transform at location |
1389 | D3DXPlaneFromPointNormal (&plane, (D3DXVECTOR3 *) & |
1393 | D3DXPlaneFromPointNormal (&plane, (D3DXVECTOR3 *) &scene_lookatpoint, (D3DXVECTOR3 *) &upwards_direction); |
1390 | D3DXMatrixReflect (&reflect_matrix, &plane); |
1394 | D3DXMatrixReflect (&reflect_matrix, &plane); |
1391 | D3DXMatrixRotationYawPitchRoll (&rotation_matrix, -sceneobject->pitch * TO_RADIANS, 0.0f, -sceneobject->yaw * TO_RADIANS); |
1395 | D3DXMatrixRotationYawPitchRoll (&rotation_matrix, -sceneobject->pitch * TO_RADIANS, 0.0f, -sceneobject->yaw * TO_RADIANS); |
1392 | D3DXMatrixTranslation (&translation_matrix, sceneobject->x, sceneobject->y, -sceneobject->z); |
1396 | D3DXMatrixTranslation (&translation_matrix, sceneobject->x, sceneobject->y, -sceneobject->z); |
1393 | D3DXMatrixScaling (&scaling_matrix, sceneobject->scale, sceneobject->scale, 1.0f); |
1397 | D3DXMatrixScaling (&scaling_matrix, sceneobject->scale, sceneobject->scale, 1.0f); |
1394 | 1398 |