TODO: Handle opacity
| 812 | |
| 813 | // TODO: Handle opacity |
| 814 | void Renderer::DrawObjectIn2DSpace(int objectNumber, Vector2 pos2D, EulerAngles orient, float scale, float opacity, int meshBits) |
| 815 | { |
| 816 | unsigned int stride = sizeof(Vertex); |
| 817 | unsigned int offset = 0; |
| 818 | |
| 819 | auto screenRes = GetScreenResolution(); |
| 820 | auto factor = Vector2( |
| 821 | screenRes.x / DISPLAY_SPACE_RES.x, |
| 822 | screenRes.y / DISPLAY_SPACE_RES.y); |
| 823 | |
| 824 | pos2D *= factor; |
| 825 | scale *= (factor.x > factor.y) ? factor.y : factor.x; |
| 826 | |
| 827 | int invObjectID = g_Gui.ConvertObjectToInventoryItem(objectNumber); |
| 828 | if (invObjectID != NO_VALUE) |
| 829 | { |
| 830 | const auto& invObject = InventoryObjectTable[invObjectID]; |
| 831 | |
| 832 | pos2D.y += invObject.YOffset * factor.y; |
| 833 | orient += invObject.Orientation; |
| 834 | } |
| 835 | |
| 836 | auto viewMatrix = Matrix::CreateLookAt(Vector3(0.0f, 0.0f, BLOCK(2)), Vector3::Zero, Vector3::Down); |
| 837 | auto projMatrix = Matrix::CreateOrthographic(_screenWidth, _screenHeight, -BLOCK(1), BLOCK(1)); |
| 838 | |
| 839 | auto& moveableObject = _moveableObjects[objectNumber]; |
| 840 | if (!moveableObject.has_value()) |
| 841 | return; |
| 842 | |
| 843 | const auto& object = Objects[objectNumber]; |
| 844 | if (!object.Animations.empty()) |
| 845 | { |
| 846 | auto interpData = KeyframeInterpolationData( |
| 847 | GetAnimData(object, 0).Keyframes[0], |
| 848 | GetAnimData(object, 0).Keyframes[0], |
| 849 | 0.0f); |
| 850 | UpdateAnimation(nullptr, *moveableObject, interpData, UINT_MAX); |
| 851 | } |
| 852 | |
| 853 | auto pos = _viewportToolkit.Unproject(Vector3(pos2D.x, pos2D.y, 1.0f), projMatrix, viewMatrix, Matrix::Identity); |
| 854 | auto color = Vector4(1.0f, 1.0f, 1.0f, opacity); |
| 855 | |
| 856 | // Set vertex buffer. |
| 857 | _context->IASetVertexBuffers(0, 1, _moveablesVertexBuffer.Buffer.GetAddressOf(), &stride, &offset); |
| 858 | _context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); |
| 859 | _context->IASetInputLayout(_inputLayout.Get()); |
| 860 | _context->IASetIndexBuffer(_moveablesIndexBuffer.Buffer.Get(), DXGI_FORMAT_R32_UINT, 0); |
| 861 | |
| 862 | // Set matrices. |
| 863 | auto hudCamera = CCameraMatrixBuffer{}; |
| 864 | hudCamera.CamDirectionWS = -Vector4::UnitZ; |
| 865 | hudCamera.ViewProjection = viewMatrix * projMatrix; |
| 866 | hudCamera.Frame = GlobalCounter; |
| 867 | hudCamera.InterpolatedFrame = (float)GlobalCounter + GetInterpolationFactor(); |
| 868 | UpdateConstantBuffer(hudCamera, _cbCameraMatrices); |
| 869 | BindConstantBufferVS(ConstantBufferRegister::Camera, _cbCameraMatrices.get()); |
| 870 | |
| 871 | _shaders.Bind(Shader::Inventory); |
no test coverage detected