Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 120 files). Show all
Unified · Split
| @@ -33,6 +33,7 @@ · 32 unmodified lines | ||
| 33 | 33 | |
| 34 | 34 | REGISTER_META_OBJECT(DefaultMetavoxelRendererImplementation) |
| 35 | 35 | REGISTER_META_OBJECT(SphereRenderer) |
| 36 | +REGISTER_META_OBJECT(CuboidRenderer) | |
| 36 | 37 | REGISTER_META_OBJECT(StaticModelRenderer) |
| 37 | 38 | |
| 38 | 39 | static int bufferPointVectorMetaTypeId = qRegisterMetaType<BufferPointVector>(); |
| @@ -963,6 +964,12 @@ void HeightfieldPreview::render(const glm::vec3& translation, float scale) const · 924 unmodified lines | ||
| 963 | 964 | Application::getInstance()->getTextureCache()->setPrimaryDrawBuffers(true, false); |
| 964 | 965 | } |
| 965 | 966 | |
| 967 | +void VoxelPoint::setNormal(const glm::vec3& normal) { | |
| 968 | + this->normal[0] = (char)(normal.x * 127.0f); | |
| 969 | + this->normal[1] = (char)(normal.y * 127.0f); | |
| 970 | + this->normal[2] = (char)(normal.z * 127.0f); | |
| 971 | +} | |
| 972 | + | |
| 966 | 973 | VoxelBuffer::VoxelBuffer(const QVector<VoxelPoint>& vertices, const QVector<int>& indices, |
| 967 | 974 | const QVector<SharedObjectPointer>& materials) : |
| 968 | 975 | _vertices(vertices), |
| @@ -1534,8 +1541,21 @@ public: · 565 unmodified lines | ||
| 1534 | 1541 | glm::vec3 normal; |
| 1535 | 1542 | QRgb color; |
| 1536 | 1543 | char material; |
| 1544 | + int axis; | |
| 1537 | 1545 | }; |
| 1538 | 1546 | |
| 1547 | +class AxisIndex { | |
| 1548 | +public: | |
| 1549 | + int x, y, z; | |
| 1550 | + | |
| 1551 | + AxisIndex(int x = -1, int y = -1, int z = -1) : x(x), y(y), z(z) { } | |
| 1552 | +}; | |
| 1553 | + | |
| 1554 | +static glm::vec3 safeNormalize(const glm::vec3& vector) { | |
| 1555 | + float length = glm::length(vector); | |
| 1556 | + return (length > 0.0f) ? (vector / length) : vector; | |
| 1557 | +} | |
| 1558 | + | |
| 1539 | 1559 | int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { |
| 1540 | 1560 | if (!info.isLeaf) { |
| 1541 | 1561 | return DEFAULT_ORDER; |
| @@ -1574,10 +1594,10 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 32 unmodified lines | ||
| 1574 | 1594 | // as we scan down the cube generating vertices between grid points, we remember the indices of the last |
| 1575 | 1595 | // (element, line, section--x, y, z) so that we can connect generated vertices as quads |
| 1576 | 1596 | int expanded = size + 1; |
| 1577 | − QVector<int> lineIndices(expanded, -1); | |
| 1578 | − QVector<int> lastLineIndices(expanded, -1); | |
| 1579 | − QVector<int> planeIndices(expanded * expanded, -1); | |
| 1580 | − QVector<int> lastPlaneIndices(expanded * expanded, -1); | |
| 1597 | + QVector<AxisIndex> lineIndices(expanded); | |
| 1598 | + QVector<AxisIndex> lastLineIndices(expanded); | |
| 1599 | + QVector<AxisIndex> planeIndices(expanded * expanded); | |
| 1600 | + QVector<AxisIndex> lastPlaneIndices(expanded * expanded); | |
| 1581 | 1601 | |
| 1582 | 1602 | const int EDGES_PER_CUBE = 12; |
| 1583 | 1603 | EdgeCrossing crossings[EDGES_PER_CUBE]; |
| @@ -1588,7 +1608,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 4 unmodified lines | ||
| 1588 | 1608 | for (int z = 0; z < expanded; z++) { |
| 1589 | 1609 | const QRgb* colorY = colorZ; |
| 1590 | 1610 | for (int y = 0; y < expanded; y++) { |
| 1591 | − int lastIndex = 0; | |
| 1611 | + AxisIndex lastIndex; | |
| 1592 | 1612 | const QRgb* colorX = colorY; |
| 1593 | 1613 | for (int x = 0; x < expanded; x++) { |
| 1594 | 1614 | int alpha0 = colorX[0] >> ALPHA_OFFSET; |
| @@ -1662,6 +1682,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 67 unmodified lines | ||
| 1662 | 1682 | crossing.material = materialBase[0]; |
| 1663 | 1683 | } |
| 1664 | 1684 | crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f, 0.0f); |
| 1685 | + crossing.axis = 0; | |
| 1665 | 1686 | } |
| 1666 | 1687 | if (middleY) { |
| 1667 | 1688 | if (alpha1 != alpha3) { |
| @@ -1676,6 +1697,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 8 unmodified lines | ||
| 1676 | 1697 | crossing.material = materialBase[1]; |
| 1677 | 1698 | } |
| 1678 | 1699 | crossing.point = glm::vec3(1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f); |
| 1700 | + crossing.axis = 1; | |
| 1679 | 1701 | } |
| 1680 | 1702 | if (alpha2 != alpha3) { |
| 1681 | 1703 | QRgb hermite = hermiteBase[hermiteStride]; |
| @@ -1689,6 +1711,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 7 unmodified lines | ||
| 1689 | 1711 | crossing.material = materialBase[size]; |
| 1690 | 1712 | } |
| 1691 | 1713 | crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f, 0.0f); |
| 1714 | + crossing.axis = 0; | |
| 1692 | 1715 | } |
| 1693 | 1716 | if (middleZ) { |
| 1694 | 1717 | if (alpha3 != alpha7) { |
| @@ -1703,6 +1726,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 8 unmodified lines | ||
| 1703 | 1726 | crossing.material = materialBase[offset3]; |
| 1704 | 1727 | } |
| 1705 | 1728 | crossing.point = glm::vec3(1.0f, 1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL); |
| 1729 | + crossing.axis = 2; | |
| 1706 | 1730 | } |
| 1707 | 1731 | if (alpha5 != alpha7) { |
| 1708 | 1732 | QRgb hermite = hermiteBase[hermiteArea + VoxelHermiteData::EDGE_COUNT + 1]; |
| @@ -1716,6 +1740,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 7 unmodified lines | ||
| 1716 | 1740 | crossing.material = materialBase[offset5]; |
| 1717 | 1741 | } |
| 1718 | 1742 | crossing.point = glm::vec3(1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f); |
| 1743 | + crossing.axis = 1; | |
| 1719 | 1744 | } |
| 1720 | 1745 | if (alpha6 != alpha7) { |
| 1721 | 1746 | QRgb hermite = hermiteBase[hermiteArea + hermiteStride]; |
| @@ -1729,6 +1754,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 7 unmodified lines | ||
| 1729 | 1754 | crossing.material = materialBase[offset6]; |
| 1730 | 1755 | } |
| 1731 | 1756 | crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f, 1.0f); |
| 1757 | + crossing.axis = 0; | |
| 1732 | 1758 | } |
| 1733 | 1759 | } |
| 1734 | 1760 | } |
| @@ -1745,6 +1771,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 10 unmodified lines | ||
| 1745 | 1771 | crossing.material = materialBase[1]; |
| 1746 | 1772 | } |
| 1747 | 1773 | crossing.point = glm::vec3(1.0f, 0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL); |
| 1774 | + crossing.axis = 2; | |
| 1748 | 1775 | } |
| 1749 | 1776 | if (alpha4 != alpha5) { |
| 1750 | 1777 | QRgb hermite = hermiteBase[hermiteArea]; |
| @@ -1758,6 +1785,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 7 unmodified lines | ||
| 1758 | 1785 | crossing.material = materialBase[area]; |
| 1759 | 1786 | } |
| 1760 | 1787 | crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f, 1.0f); |
| 1788 | + crossing.axis = 0; | |
| 1761 | 1789 | } |
| 1762 | 1790 | } |
| 1763 | 1791 | } |
| @@ -1774,6 +1802,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 10 unmodified lines | ||
| 1774 | 1802 | crossing.material = materialBase[0]; |
| 1775 | 1803 | } |
| 1776 | 1804 | crossing.point = glm::vec3(0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f); |
| 1805 | + crossing.axis = 1; | |
| 1777 | 1806 | } |
| 1778 | 1807 | if (middleZ) { |
| 1779 | 1808 | if (alpha2 != alpha6) { |
| @@ -1788,6 +1817,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 8 unmodified lines | ||
| 1788 | 1817 | crossing.material = materialBase[size]; |
| 1789 | 1818 | } |
| 1790 | 1819 | crossing.point = glm::vec3(0.0f, 1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL); |
| 1820 | + crossing.axis = 2; | |
| 1791 | 1821 | } |
| 1792 | 1822 | if (alpha4 != alpha6) { |
| 1793 | 1823 | QRgb hermite = hermiteBase[hermiteArea + 1]; |
| @@ -1801,6 +1831,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 7 unmodified lines | ||
| 1801 | 1831 | crossing.material = materialBase[area]; |
| 1802 | 1832 | } |
| 1803 | 1833 | crossing.point = glm::vec3(0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f); |
| 1834 | + crossing.axis = 1; | |
| 1804 | 1835 | } |
| 1805 | 1836 | } |
| 1806 | 1837 | } |
| @@ -1816,11 +1847,12 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 9 unmodified lines | ||
| 1816 | 1847 | crossing.material = materialBase[0]; |
| 1817 | 1848 | } |
| 1818 | 1849 | crossing.point = glm::vec3(0.0f, 0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL); |
| 1850 | + crossing.axis = 2; | |
| 1819 | 1851 | } |
| 1820 | 1852 | // at present, we simply average the properties of each crossing as opposed to finding the vertex that |
| 1821 | 1853 | // minimizes the quadratic error function as described in the reference paper |
| 1822 | 1854 | glm::vec3 center; |
| 1823 | − glm::vec3 normal; | |
| 1855 | + glm::vec3 axisNormals[3]; | |
| 1824 | 1856 | const int MAX_MATERIALS_PER_VERTEX = 4; |
| 1825 | 1857 | quint8 materials[] = { 0, 0, 0, 0 }; |
| 1826 | 1858 | glm::vec4 materialWeights; |
| @@ -1829,7 +1861,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 2 unmodified lines | ||
| 1829 | 1861 | for (int i = 0; i < crossingCount; i++) { |
| 1830 | 1862 | const EdgeCrossing& crossing = crossings[i]; |
| 1831 | 1863 | center += crossing.point; |
| 1832 | − normal += crossing.normal; | |
| 1864 | + axisNormals[crossing.axis] += crossing.normal; | |
| 1833 | 1865 | red += qRed(crossing.color); |
| 1834 | 1866 | green += qGreen(crossing.color); |
| 1835 | 1867 | blue += qBlue(crossing.color); |
| @@ -1852,16 +1884,18 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 16 unmodified lines | ||
| 1852 | 1884 | } |
| 1853 | 1885 | } |
| 1854 | 1886 | } |
| 1855 | − normal = glm::normalize(normal); | |
| 1887 | + glm::vec3 normal = safeNormalize(axisNormals[0] + axisNormals[1] + axisNormals[2]); | |
| 1856 | 1888 | center /= crossingCount; |
| 1857 | 1889 | |
| 1858 | 1890 | // use a sequence of Givens rotations to perform a QR decomposition |
| 1859 | 1891 | // see http://www.cs.rice.edu/~jwarren/papers/techreport02408.pdf |
| 1860 | 1892 | glm::mat4 r(0.0f); |
| 1861 | 1893 | glm::vec4 bottom; |
| 1894 | + float smallestCosNormal = 1.0f; | |
| 1862 | 1895 | for (int i = 0; i < crossingCount; i++) { |
| 1863 | 1896 | const EdgeCrossing& crossing = crossings[i]; |
| 1864 | 1897 | bottom = glm::vec4(crossing.normal, glm::dot(crossing.normal, crossing.point - center)); |
| 1898 | + smallestCosNormal = qMin(smallestCosNormal, glm::dot(crossing.normal, normal)); | |
| 1865 | 1899 | |
| 1866 | 1900 | for (int j = 0; j < 4; j++) { |
| 1867 | 1901 | float angle = glm::atan(-bottom[j], r[j][j]); |
| @@ -1899,12 +1933,9 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 31 unmodified lines | ||
| 1899 | 1933 | int largestI = (largestIndex == 0) ? 1 : 2; |
| 1900 | 1934 | float sjj = d[largestJ][largestJ]; |
| 1901 | 1935 | float sii = d[largestI][largestI]; |
| 1902 | − float angle = (sii == sjj ? PI_OVER_TWO : glm::atan(2.0f * d[largestJ][largestI], sjj - sii)) / 2.0f; | |
| 1936 | + float angle = glm::atan(2.0f * d[largestJ][largestI], sjj - sii) / 2.0f; | |
| 1903 | 1937 | glm::quat rotation = glm::angleAxis(angle, largestIndex == 0 ? glm::vec3(0.0f, 0.0f, -1.0f) : |
| 1904 | 1938 | (largestIndex == 1 ? glm::vec3(0.0f, 1.0f, 0.0f) : glm::vec3(-1.0f, 0.0f, 0.0f))); |
| 1905 | − if (rotation.w == 0.0f) { | |
| 1906 | − break; | |
| 1907 | − } | |
| 1908 | 1939 | combinedRotation = glm::normalize(rotation * combinedRotation); |
| 1909 | 1940 | glm::mat3 matrix = glm::mat3_cast(combinedRotation); |
| 1910 | 1941 | d = matrix * ata * glm::transpose(matrix); |
| @@ -1933,17 +1964,69 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 22 unmodified lines | ||
| 1933 | 1964 | { materials[0], materials[1], materials[2], materials[3] }, |
| 1934 | 1965 | { (quint8)materialWeights[0], (quint8)materialWeights[1], (quint8)materialWeights[2], |
| 1935 | 1966 | (quint8)materialWeights[3] } }; |
| 1936 | − int index = vertices.size(); | |
| 1937 | − vertices.append(point); | |
| 1967 | + | |
| 1968 | + // determine whether we must "crease" by generating directional normals | |
| 1969 | + const float CREASE_COS_NORMAL = glm::cos(glm::radians(40.0f)); | |
| 1970 | + AxisIndex index(vertices.size(), vertices.size(), vertices.size()); | |
| 1971 | + if (smallestCosNormal > CREASE_COS_NORMAL) { | |
| 1972 | + vertices.append(point); | |
| 1973 | + | |
| 1974 | + } else { | |
| 1975 | + axisNormals[0] = safeNormalize(axisNormals[0]); | |
| 1976 | + axisNormals[1] = safeNormalize(axisNormals[1]); | |
| 1977 | + axisNormals[2] = safeNormalize(axisNormals[2]); | |
| 1978 | + glm::vec3 normalXY(safeNormalize(axisNormals[0] + axisNormals[1])); | |
| 1979 | + glm::vec3 normalXZ(safeNormalize(axisNormals[0] + axisNormals[2])); | |
| 1980 | + glm::vec3 normalYZ(safeNormalize(axisNormals[1] + axisNormals[2])); | |
| 1981 | + if (glm::dot(axisNormals[0], normalXY) > CREASE_COS_NORMAL && | |
| 1982 | + glm::dot(axisNormals[1], normalXY) > CREASE_COS_NORMAL) { | |
| 1983 | + point.setNormal(normalXY); | |
| 1984 | + vertices.append(point); | |
| 1985 | + | |
| 1986 | + point.setNormal(axisNormals[2]); | |
| 1987 | + index.z = vertices.size(); | |
| 1988 | + vertices.append(point); | |
| 1989 | + | |
| 1990 | + } else if (glm::dot(axisNormals[0], normalXZ) > CREASE_COS_NORMAL && | |
| 1991 | + glm::dot(axisNormals[2], normalXZ) > CREASE_COS_NORMAL) { | |
| 1992 | + point.setNormal(normalXZ); | |
| 1993 | + vertices.append(point); | |
| 1994 | + | |
| 1995 | + point.setNormal(axisNormals[1]); | |
| 1996 | + index.y = vertices.size(); | |
| 1997 | + vertices.append(point); | |
| 1998 | + | |
| 1999 | + } else if (glm::dot(axisNormals[1], normalYZ) > CREASE_COS_NORMAL && | |
| 2000 | + glm::dot(axisNormals[2], normalYZ) > CREASE_COS_NORMAL) { | |
| 2001 | + point.setNormal(normalYZ); | |
| 2002 | + vertices.append(point); | |
| 2003 | + | |
| 2004 | + point.setNormal(axisNormals[0]); | |
| 2005 | + index.x = vertices.size(); | |
| 2006 | + vertices.append(point); | |
| 2007 | + | |
| 2008 | + } else { | |
| 2009 | + point.setNormal(axisNormals[0]); | |
| 2010 | + vertices.append(point); | |
| 2011 | + | |
| 2012 | + point.setNormal(axisNormals[1]); | |
| 2013 | + index.y = vertices.size(); | |
| 2014 | + vertices.append(point); | |
| 2015 | + | |
| 2016 | + point.setNormal(axisNormals[2]); | |
| 2017 | + index.z = vertices.size(); | |
| 2018 | + vertices.append(point); | |
| 2019 | + } | |
| 2020 | + } | |
| 1938 | 2021 | |
| 1939 | 2022 | // the first x, y, and z are repeated for the boundary edge; past that, we consider generating |
| 1940 | 2023 | // quads for each edge that includes a transition, using indices of previously generated vertices |
| 1941 | 2024 | if (x != 0 && y != 0 && z != 0) { |
| 1942 | 2025 | if (alpha0 != alpha1) { |
| 1943 | − indices.append(index); | |
| 1944 | − int index1 = lastLineIndices.at(x); | |
| 1945 | − int index2 = lastPlaneIndices.at((y - 1) * expanded + x); | |
| 1946 | − int index3 = lastPlaneIndices.at(y * expanded + x); | |
| 2026 | + indices.append(index.x); | |
| 2027 | + int index1 = lastLineIndices.at(x).x; | |
| 2028 | + int index2 = lastPlaneIndices.at((y - 1) * expanded + x).x; | |
| 2029 | + int index3 = lastPlaneIndices.at(y * expanded + x).x; | |
| 1947 | 2030 | if (alpha0 == 0) { // quad faces negative x |
| 1948 | 2031 | indices.append(index3); |
| 1949 | 2032 | indices.append(index2); |
| @@ -1956,10 +2039,10 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 6 unmodified lines | ||
| 1956 | 2039 | } |
| 1957 | 2040 | |
| 1958 | 2041 | if (alpha0 != alpha2) { |
| 1959 | − indices.append(index); | |
| 1960 | − int index1 = lastIndex; | |
| 1961 | − int index2 = lastPlaneIndices.at(y * expanded + x - 1); | |
| 1962 | − int index3 = lastPlaneIndices.at(y * expanded + x); | |
| 2042 | + indices.append(index.y); | |
| 2043 | + int index1 = lastIndex.y; | |
| 2044 | + int index2 = lastPlaneIndices.at(y * expanded + x - 1).y; | |
| 2045 | + int index3 = lastPlaneIndices.at(y * expanded + x).y; | |
| 1963 | 2046 | if (alpha0 == 0) { // quad faces negative y |
| 1964 | 2047 | indices.append(index1); |
| 1965 | 2048 | indices.append(index2); |
| @@ -1972,10 +2055,10 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 6 unmodified lines | ||
| 1972 | 2055 | } |
| 1973 | 2056 | |
| 1974 | 2057 | if (alpha0 != alpha4) { |
| 1975 | − indices.append(index); | |
| 1976 | − int index1 = lastIndex; | |
| 1977 | − int index2 = lastLineIndices.at(x - 1); | |
| 1978 | − int index3 = lastLineIndices.at(x); | |
| 2058 | + indices.append(index.z); | |
| 2059 | + int index1 = lastIndex.z; | |
| 2060 | + int index2 = lastLineIndices.at(x - 1).z; | |
| 2061 | + int index3 = lastLineIndices.at(x).z; | |
| 1979 | 2062 | if (alpha0 == 0) { // quad faces negative z |
| 1980 | 2063 | indices.append(index3); |
| 1981 | 2064 | indices.append(index2); |
| @@ -2119,7 +2202,8 @@ int SpannerRenderVisitor::visit(MetavoxelInfo& info) { · 137 unmodified lines | ||
| 2119 | 2202 | } |
| 2120 | 2203 | |
| 2121 | 2204 | bool SpannerRenderVisitor::visit(Spanner* spanner, const glm::vec3& clipMinimum, float clipSize) { |
| 2122 | − spanner->getRenderer()->render(1.0f, SpannerRenderer::DEFAULT_MODE, clipMinimum, clipSize); | |
| 2205 | + const glm::vec4 OPAQUE_WHITE(1.0f, 1.0f, 1.0f, 1.0f); | |
| 2206 | + spanner->getRenderer()->render(OPAQUE_WHITE, SpannerRenderer::DEFAULT_MODE, clipMinimum, clipSize); | |
| 2123 | 2207 | return true; |
| 2124 | 2208 | } |
| 2125 | 2209 | |
| @@ -2285,9 +2369,9 @@ static void enableClipPlane(GLenum plane, float x, float y, float z, float w) { · 159 unmodified lines | ||
| 2285 | 2369 | glEnable(plane); |
| 2286 | 2370 | } |
| 2287 | 2371 | |
| 2288 | −void ClippedRenderer::render(float alpha, Mode mode, const glm::vec3& clipMinimum, float clipSize) { | |
| 2372 | +void ClippedRenderer::render(const glm::vec4& color, Mode mode, const glm::vec3& clipMinimum, float clipSize) { | |
| 2289 | 2373 | if (clipSize == 0.0f) { |
| 2290 | − renderUnclipped(alpha, mode); | |
| 2374 | + renderUnclipped(color, mode); | |
| 2291 | 2375 | return; |
| 2292 | 2376 | } |
| 2293 | 2377 | enableClipPlane(GL_CLIP_PLANE0, -1.0f, 0.0f, 0.0f, clipMinimum.x + clipSize); |
| @@ -2297,7 +2381,7 @@ void ClippedRenderer::render(float alpha, Mode mode, const glm::vec3& clipMinimu · 3 unmodified lines | ||
| 2297 | 2381 | enableClipPlane(GL_CLIP_PLANE4, 0.0f, 0.0f, -1.0f, clipMinimum.z + clipSize); |
| 2298 | 2382 | enableClipPlane(GL_CLIP_PLANE5, 0.0f, 0.0f, 1.0f, -clipMinimum.z); |
| 2299 | 2383 | |
| 2300 | − renderUnclipped(alpha, mode); | |
| 2384 | + renderUnclipped(color, mode); | |
| 2301 | 2385 | |
| 2302 | 2386 | glDisable(GL_CLIP_PLANE0); |
| 2303 | 2387 | glDisable(GL_CLIP_PLANE1); |
| @@ -2310,9 +2394,9 @@ void ClippedRenderer::render(float alpha, Mode mode, const glm::vec3& clipMinimu · 6 unmodified lines | ||
| 2310 | 2394 | SphereRenderer::SphereRenderer() { |
| 2311 | 2395 | } |
| 2312 | 2396 | |
| 2313 | −void SphereRenderer::render(float alpha, Mode mode, const glm::vec3& clipMinimum, float clipSize) { | |
| 2397 | +void SphereRenderer::render(const glm::vec4& color, Mode mode, const glm::vec3& clipMinimum, float clipSize) { | |
| 2314 | 2398 | if (clipSize == 0.0f) { |
| 2315 | − renderUnclipped(alpha, mode); | |
| 2399 | + renderUnclipped(color, mode); | |
| 2316 | 2400 | return; |
| 2317 | 2401 | } |
| 2318 | 2402 | // slight performance optimization: don't render if clip bounds are entirely within sphere |
| @@ -2321,29 +2405,50 @@ void SphereRenderer::render(float alpha, Mode mode, const glm::vec3& clipMinimum · 2 unmodified lines | ||
| 2321 | 2405 | for (int i = 0; i < Box::VERTEX_COUNT; i++) { |
| 2322 | 2406 | const float CLIP_PROPORTION = 0.95f; |
| 2323 | 2407 | if (glm::distance(sphere->getTranslation(), clipBox.getVertex(i)) >= sphere->getScale() * CLIP_PROPORTION) { |
| 2324 | − ClippedRenderer::render(alpha, mode, clipMinimum, clipSize); | |
| 2408 | + ClippedRenderer::render(color, mode, clipMinimum, clipSize); | |
| 2325 | 2409 | return; |
| 2326 | 2410 | } |
| 2327 | 2411 | } |
| 2328 | 2412 | } |
| 2329 | 2413 | |
| 2330 | −void SphereRenderer::renderUnclipped(float alpha, Mode mode) { | |
| 2414 | +void SphereRenderer::renderUnclipped(const glm::vec4& color, Mode mode) { | |
| 2331 | 2415 | Sphere* sphere = static_cast<Sphere*>(_spanner); |
| 2332 | − const QColor& color = sphere->getColor(); | |
| 2333 | − glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF() * alpha); | |
| 2416 | + const QColor& ownColor = sphere->getColor(); | |
| 2417 | + glColor4f(ownColor.redF() * color.r, ownColor.greenF() * color.g, ownColor.blueF() * color.b, ownColor.alphaF() * color.a); | |
| 2334 | 2418 | |
| 2335 | 2419 | glPushMatrix(); |
| 2336 | 2420 | const glm::vec3& translation = sphere->getTranslation(); |
| 2337 | 2421 | glTranslatef(translation.x, translation.y, translation.z); |
| 2338 | 2422 | glm::quat rotation = sphere->getRotation(); |
| 2339 | 2423 | glm::vec3 axis = glm::axis(rotation); |
| 2340 | − glRotatef(glm::angle(rotation), axis.x, axis.y, axis.z); | |
| 2424 | + glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); | |
| 2341 | 2425 | |
| 2342 | 2426 | Application::getInstance()->getGeometryCache()->renderSphere(sphere->getScale(), 10, 10); |
| 2343 | 2427 | |
| 2344 | 2428 | glPopMatrix(); |
| 2345 | 2429 | } |
| 2346 | 2430 | |
| 2431 | +CuboidRenderer::CuboidRenderer() { | |
| 2432 | +} | |
| 2433 | + | |
| 2434 | +void CuboidRenderer::renderUnclipped(const glm::vec4& color, Mode mode) { | |
| 2435 | + Cuboid* cuboid = static_cast<Cuboid*>(_spanner); | |
| 2436 | + const QColor& ownColor = cuboid->getColor(); | |
| 2437 | + glColor4f(ownColor.redF() * color.r, ownColor.greenF() * color.g, ownColor.blueF() * color.b, ownColor.alphaF() * color.a); | |
| 2438 | + | |
| 2439 | + glPushMatrix(); | |
| 2440 | + const glm::vec3& translation = cuboid->getTranslation(); | |
| 2441 | + glTranslatef(translation.x, translation.y, translation.z); | |
| 2442 | + glm::quat rotation = cuboid->getRotation(); | |
| 2443 | + glm::vec3 axis = glm::axis(rotation); | |
| 2444 | + glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); | |
| 2445 | + glScalef(1.0f, cuboid->getAspectY(), cuboid->getAspectZ()); | |
| 2446 | + | |
| 2447 | + glutSolidCube(cuboid->getScale() * 2.0f); | |
| 2448 | + | |
| 2449 | + glPopMatrix(); | |
| 2450 | +} | |
| 2451 | + | |
| 2347 | 2452 | StaticModelRenderer::StaticModelRenderer() : |
| 2348 | 2453 | _model(new Model(this)) { |
| 2349 | 2454 | } |
| @@ -2377,21 +2482,21 @@ void StaticModelRenderer::simulate(float deltaTime) { · 27 unmodified lines | ||
| 2377 | 2482 | _model->simulate(deltaTime); |
| 2378 | 2483 | } |
| 2379 | 2484 | |
| 2380 | −void StaticModelRenderer::renderUnclipped(float alpha, Mode mode) { | |
| 2485 | +void StaticModelRenderer::renderUnclipped(const glm::vec4& color, Mode mode) { | |
| 2381 | 2486 | switch (mode) { |
| 2382 | 2487 | case DIFFUSE_MODE: |
| 2383 | − _model->render(alpha, Model::DIFFUSE_RENDER_MODE); | |
| 2488 | + _model->render(color.a, Model::DIFFUSE_RENDER_MODE); | |
| 2384 | 2489 | break; |
| 2385 | 2490 | |
| 2386 | 2491 | case NORMAL_MODE: |
| 2387 | − _model->render(alpha, Model::NORMAL_RENDER_MODE); | |
| 2492 | + _model->render(color.a, Model::NORMAL_RENDER_MODE); | |
| 2388 | 2493 | break; |
| 2389 | 2494 | |
| 2390 | 2495 | default: |
| 2391 | − _model->render(alpha); | |
| 2496 | + _model->render(color.a); | |
| 2392 | 2497 | break; |
| 2393 | 2498 | } |
| 2394 | − _model->render(alpha); | |
| 2499 | + _model->render(color.a); | |
| 2395 | 2500 | } |
| 2396 | 2501 | |
| 2397 | 2502 | bool StaticModelRenderer::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, |