From f1ddf671143db289f53f51ef12fbb32cefb71940 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Mon, 6 Sep 2021 09:03:26 -0700 Subject: [PATCH] Added initializer types. --- examples/18-ibl/ibl.cpp | 4 +- examples/28-wireframe/wireframe.cpp | 8 +-- examples/29-debugdraw/debugdraw.cpp | 6 +-- examples/36-sky/sky.cpp | 24 +++++---- .../gpudrivenrendering.cpp | 4 +- examples/common/bounds.cpp | 52 +++++++++---------- examples/common/bounds.h | 36 ++++++------- examples/common/camera.cpp | 6 +-- examples/common/debugdraw/debugdraw.cpp | 44 ++++++---------- examples/common/ps/particle_system.cpp | 4 +- tools/geometryc/geometryc.cpp | 30 +++++------ tools/geometryv/geometryv.cpp | 6 +-- 12 files changed, 105 insertions(+), 119 deletions(-) diff --git a/examples/18-ibl/ibl.cpp b/examples/18-ibl/ibl.cpp index f4cf1c591..3e2ab6a90 100644 --- a/examples/18-ibl/ibl.cpp +++ b/examples/18-ibl/ibl.cpp @@ -291,8 +291,8 @@ struct Camera struct Interp3f { - bx::Vec3 curr; - bx::Vec3 dest; + bx::Vec3 curr = bx::init::None; + bx::Vec3 dest = bx::init::None; }; Interp3f m_target; diff --git a/examples/28-wireframe/wireframe.cpp b/examples/28-wireframe/wireframe.cpp index b1c3d30f8..5529b2c24 100644 --- a/examples/28-wireframe/wireframe.cpp +++ b/examples/28-wireframe/wireframe.cpp @@ -29,8 +29,8 @@ struct Camera void reset() { - m_target.curr = { 0.0f, 0.0f, 0.0f }; - m_target.dest = { 0.0f, 0.0f, 0.0f }; + m_target.curr = bx::init::Zero; + m_target.dest = bx::init::Zero; m_pos.curr = { 0.0f, 0.0f, -2.0f }; m_pos.dest = { 0.0f, 0.0f, -2.0f }; @@ -135,8 +135,8 @@ struct Camera struct Interp3f { - bx::Vec3 curr; - bx::Vec3 dest; + bx::Vec3 curr = bx::init::None; + bx::Vec3 dest = bx::init::None; }; Interp3f m_target; diff --git a/examples/29-debugdraw/debugdraw.cpp b/examples/29-debugdraw/debugdraw.cpp index 1b102fc31..f7828b892 100644 --- a/examples/29-debugdraw/debugdraw.cpp +++ b/examples/29-debugdraw/debugdraw.cpp @@ -601,7 +601,7 @@ void initA(Shape& _outShape, Shape::Type::Enum _type, bx::Vec3 _pos) case Shape::Type::Plane: { - bx::Plane plane; + bx::Plane plane(bx::init::None); bx::calcPlane(plane, bx::normalize(bx::Vec3{0.0f, 1.0f, 1.0f}), _pos); _outShape = Shape(plane); } @@ -688,7 +688,7 @@ void initB(Shape& _outShape, Shape::Type::Enum _type, bx::Vec3 _pos) case Shape::Type::Plane: { - bx::Plane plane; + bx::Plane plane(bx::init::None); bx::calcPlane(plane, bx::normalize(bx::Vec3{1.0f, 1.0f, 0.0f}), _pos); _outShape = Shape(plane); } @@ -999,7 +999,7 @@ public: const bx::Vec3 normal = { 0.0f, 1.0f, 0.0f }; const bx::Vec3 pos = { 0.0f, -2.0f, 0.0f }; - bx::Plane plane; + bx::Plane plane(bx::init::None); bx::calcPlane(plane, normal, pos); dde.setColor(false diff --git a/examples/36-sky/sky.cpp b/examples/36-sky/sky.cpp index 40186e18a..7c2d3bb98 100644 --- a/examples/36-sky/sky.cpp +++ b/examples/36-sky/sky.cpp @@ -63,7 +63,7 @@ namespace typedef bx::Vec3 Color; // HDTV rec. 709 matrix. - static float M_XYZ2RGB[] = + static constexpr float M_XYZ2RGB[] = { 3.240479f, -0.969256f, 0.055648f, -1.53715f, 1.875991f, -0.204043f, @@ -73,18 +73,18 @@ namespace // Converts color repesentation from CIE XYZ to RGB color-space. Color xyzToRgb(const Color& xyz) { - Color rgb; + Color rgb(bx::init::None); rgb.x = M_XYZ2RGB[0] * xyz.x + M_XYZ2RGB[3] * xyz.y + M_XYZ2RGB[6] * xyz.z; rgb.y = M_XYZ2RGB[1] * xyz.x + M_XYZ2RGB[4] * xyz.y + M_XYZ2RGB[7] * xyz.z; rgb.z = M_XYZ2RGB[2] * xyz.x + M_XYZ2RGB[5] * xyz.y + M_XYZ2RGB[8] * xyz.z; return rgb; }; - // Precomputed luminance of sunlight in XYZ colorspace. // Computed using code from Game Engine Gems, Volume One, chapter 15. Implementation based on Dr. Richard Bird model. // This table is used for piecewise linear interpolation. Transitions from and to 0.0 at sunset and sunrise are highly inaccurate - static std::map sunLuminanceXYZTable = { + static std::map sunLuminanceXYZTable = + { { 5.0f, { 0.000000f, 0.000000f, 0.000000f } }, { 7.0f, { 12.703322f, 12.989393f, 9.100411f } }, { 8.0f, { 13.202644f, 13.597814f, 11.524929f } }, @@ -107,7 +107,8 @@ namespace // This table is used for piecewise linear interpolation. Day/night transitions are highly inaccurate. // The scale of luminance change in Day/night transitions is not preserved. // Luminance at night was increased to eliminate need the of HDR render. - static std::map skyLuminanceXYZTable = { + static std::map skyLuminanceXYZTable = + { { 0.0f, { 0.308f, 0.308f, 0.411f } }, { 1.0f, { 0.308f, 0.308f, 0.410f } }, { 2.0f, { 0.301f, 0.301f, 0.402f } }, @@ -136,7 +137,7 @@ namespace // Turbidity tables. Taken from: // A. J. Preetham, P. Shirley, and B. Smits. A Practical Analytic Model for Daylight. SIGGRAPH '99 // Coefficients correspond to xyY colorspace. - static Color ABCDE[] = + static constexpr Color ABCDE[] = { { -0.2592f, -0.2608f, -1.4630f }, { 0.0008f, 0.0092f, 0.4275f }, @@ -144,7 +145,8 @@ namespace { -0.8989f, -1.6537f, -2.5771f }, { 0.0452f, 0.0529f, 0.3703f }, }; - static Color ABCDE_t[] = + + static constexpr Color ABCDE_t[] = { { -0.0193f, -0.0167f, 0.1787f }, { -0.0665f, -0.0950f, -0.3554f }, @@ -241,14 +243,14 @@ namespace }; SunController() - : m_latitude(50.0f) + : m_northDir(1.0f, 0.0f, 0.0f) + , m_sunDir(0.0f, -1.0f, 0.0f) + , m_upDir(0.0f, 1.0f, 0.0f) + , m_latitude(50.0f) , m_month(June) , m_eclipticObliquity(bx::toRad(23.4f) ) , m_delta(0.0f) { - m_northDir = { 1.0f, 0.0f, 0.0f }; - m_sunDir = { 0.0f, -1.0f, 0.0f }; - m_upDir = { 0.0f, 1.0f, 0.0f }; } void Update(float _time) diff --git a/examples/37-gpudrivenrendering/gpudrivenrendering.cpp b/examples/37-gpudrivenrendering/gpudrivenrendering.cpp index 55ecb4a6a..9efbac4fa 100644 --- a/examples/37-gpudrivenrendering/gpudrivenrendering.cpp +++ b/examples/37-gpudrivenrendering/gpudrivenrendering.cpp @@ -139,8 +139,8 @@ struct Camera struct Interp3f { - bx::Vec3 curr; - bx::Vec3 dest; + bx::Vec3 curr = bx::init::None; + bx::Vec3 dest = bx::init::None; }; Interp3f m_target; diff --git a/examples/common/bounds.cpp b/examples/common/bounds.cpp index 835062d14..3a249f197 100644 --- a/examples/common/bounds.cpp +++ b/examples/common/bounds.cpp @@ -128,7 +128,8 @@ void aabbTransformToObb(Obb& _obb, const Aabb& _aabb, const float* _mtx) void toAabb(Aabb& _outAabb, const void* _vertices, uint32_t _numVertices, uint32_t _stride) { - Vec3 mn, mx; + Vec3 mn(init::None); + Vec3 mx(init::None); uint8_t* vertex = (uint8_t*)_vertices; mn = mx = load(vertex); @@ -149,7 +150,8 @@ void toAabb(Aabb& _outAabb, const void* _vertices, uint32_t _numVertices, uint32 void toAabb(Aabb& _outAabb, const float* _mtx, const void* _vertices, uint32_t _numVertices, uint32_t _stride) { - Vec3 mn, mx; + Vec3 mn(init::None); + Vec3 mx(init::None); uint8_t* vertex = (uint8_t*)_vertices; mn = mx = mul(load(vertex), _mtx); @@ -282,7 +284,7 @@ void calcMinBoundingSphere(Sphere& _sphere, const void* _vertices, uint32_t _num uint8_t* vertex = (uint8_t*)_vertices; - Vec3 center; + Vec3 center(init::None); float* position = (float*)&vertex[0]; center.x = position[0]; center.y = position[1]; @@ -500,9 +502,7 @@ bool intersect(const Ray& _ray, const Obb& _obb, Hit* _hit) bool intersect(const Ray& _ray, const Disk& _disk, Hit* _hit) { - Plane plane; - plane.normal = _disk.normal; - plane.dist = -dot(_disk.center, _disk.normal); + Plane plane(_disk.normal, -dot(_disk.center, _disk.normal) ); Hit tmpHit; _hit = NULL != _hit ? _hit : &tmpHit; @@ -597,8 +597,8 @@ static bool intersect(const Ray& _ray, const Cylinder& _cylinder, bool _capsule, return intersect(_ray, sphere, _hit); } - Plane plane; - Vec3 pos; + Plane plane(init::None); + Vec3 pos(init::None); if (0.0f >= height) { @@ -907,9 +907,9 @@ Interval projectToAxis(const Vec3& _axis, const Triangle& _triangle) struct Srt { - Quaternion rotation; - Vec3 translation; - Vec3 scale; + Quaternion rotation = init::Identity; + Vec3 translation = init::Zero; + Vec3 scale = init::Zero; }; Srt toSrt(const void* _mtx) @@ -1026,8 +1026,8 @@ bool isNearZero(const Vec3& _v) struct Line { - Vec3 pos; - Vec3 dir; + Vec3 pos = init::None; + Vec3 dir = init::None; }; inline Vec3 getPointAt(const Line& _line, float _t) @@ -1222,7 +1222,7 @@ Vec3 closestPoint(const Obb& _obb, const Vec3& _point) Vec3 closestPoint(const Triangle& _triangle, const Vec3& _point) { - Plane plane; + Plane plane(init::None); calcPlane(plane, _triangle); const Vec3 pos = closestPoint(plane, _point); @@ -1284,7 +1284,7 @@ bool overlap(const Aabb& _aabb, const Triangle& _triangle) return false; } - Plane plane; + Plane plane(init::None); calcPlane(plane, _triangle); if (!overlap(_aabb, plane) ) @@ -1343,7 +1343,7 @@ bool overlap(const Aabb& _aabb, const Disk& _disk) return false; } - Plane plane; + Plane plane(init::None); calcPlane(plane, _disk.normal, _disk.center); return overlap(_aabb, plane); @@ -1500,7 +1500,7 @@ bool overlap(const Cylinder& _cylinder, const Obb& _obb) bool overlap(const Disk& _disk, const Vec3& _pos) { - Plane plane; + Plane plane(init::None); calcPlane(plane, _disk.normal, _disk.center); if (!isNearZero(distance(plane, _pos) ) ) @@ -1513,7 +1513,7 @@ bool overlap(const Disk& _disk, const Vec3& _pos) bool overlap(const Disk& _disk, const Plane& _plane) { - Plane plane; + Plane plane(init::None); calcPlane(plane, _disk.normal, _disk.center); if (!overlap(plane, _plane) ) @@ -1531,7 +1531,7 @@ bool overlap(const Disk& _disk, const Capsule& _capsule) return false; } - Plane plane; + Plane plane(init::None); calcPlane(plane, _disk.normal, _disk.center); return overlap(_capsule, plane); @@ -1539,10 +1539,10 @@ bool overlap(const Disk& _disk, const Capsule& _capsule) bool overlap(const Disk& _diskA, const Disk& _diskB) { - Plane planeA; + Plane planeA(init::None); calcPlane(planeA, _diskA.normal, _diskA.center); - Plane planeB; + Plane planeB(init::None); calcPlane(planeB, _diskB); Line line; @@ -1571,7 +1571,7 @@ bool overlap(const Disk& _disk, const Obb& _obb) return false; } - Plane plane; + Plane plane(init::None); calcPlane(plane, _disk.normal, _disk.center); return overlap(_obb, plane); @@ -1699,7 +1699,7 @@ bool overlap(const Sphere& _sphere, const Plane& _plane) bool overlap(const Sphere& _sphere, const Triangle& _triangle) { - Plane plane; + Plane plane(init::None); calcPlane(plane, _triangle); if (!overlap(_sphere, plane) ) @@ -1737,7 +1737,7 @@ bool overlap(const Sphere& _sphere, const Disk& _disk) return false; } - Plane plane; + Plane plane(init::None); calcPlane(plane, _disk.normal, _disk.center); return overlap(_sphere, plane); @@ -1807,7 +1807,7 @@ bool overlap(const Triangle& _triangleA, const Triangle& _triangleB) template bool overlap(const Triangle& _triangle, const Ty& _ty) { - Plane plane; + Plane plane(init::None); calcPlane(plane, _triangle); plane.normal = neg(plane.normal); @@ -1966,7 +1966,7 @@ bool overlap(const Triangle& _triangle, const Disk& _disk) return false; } - Plane plane; + Plane plane(init::None); calcPlane(plane, _disk.normal, _disk.center); return overlap(_triangle, plane); diff --git a/examples/common/bounds.h b/examples/common/bounds.h index 6c8ef9405..936a244d5 100644 --- a/examples/common/bounds.h +++ b/examples/common/bounds.h @@ -11,39 +11,39 @@ /// struct Aabb { - bx::Vec3 min; - bx::Vec3 max; + bx::Vec3 min = bx::init::None; + bx::Vec3 max = bx::init::None; }; /// struct Capsule { - bx::Vec3 pos; - bx::Vec3 end; + bx::Vec3 pos = bx::init::None; + bx::Vec3 end = bx::init::None; float radius; }; /// struct Cone { - bx::Vec3 pos; - bx::Vec3 end; + bx::Vec3 pos = bx::init::None; + bx::Vec3 end = bx::init::None; float radius; }; /// struct Cylinder { - bx::Vec3 pos; - bx::Vec3 end; + bx::Vec3 pos = bx::init::None; + bx::Vec3 end = bx::init::None; float radius; }; /// struct Disk { - bx::Vec3 center; - bx::Vec3 normal; + bx::Vec3 center = bx::init::None; + bx::Vec3 normal = bx::init::None; float radius; }; @@ -56,30 +56,30 @@ struct Obb /// struct Sphere { - bx::Vec3 center; + bx::Vec3 center = bx::init::None; float radius; }; /// struct Triangle { - bx::Vec3 v0; - bx::Vec3 v1; - bx::Vec3 v2; + bx::Vec3 v0 = bx::init::None; + bx::Vec3 v1 = bx::init::None; + bx::Vec3 v2 = bx::init::None; }; /// struct Ray { - bx::Vec3 pos; - bx::Vec3 dir; + bx::Vec3 pos = bx::init::None; + bx::Vec3 dir = bx::init::None; }; /// struct Hit { - bx::Vec3 pos; - bx::Plane plane; + bx::Vec3 pos = bx::init::None; + bx::Plane plane = bx::init::None; }; /// diff --git a/examples/common/camera.cpp b/examples/common/camera.cpp index 3c154aac1..eb5ed59e8 100644 --- a/examples/common/camera.cpp +++ b/examples/common/camera.cpp @@ -264,9 +264,9 @@ struct Camera MouseCoords m_mouseNow; MouseCoords m_mouseLast; - bx::Vec3 m_eye; - bx::Vec3 m_at; - bx::Vec3 m_up; + bx::Vec3 m_eye = bx::init::Zero; + bx::Vec3 m_at = bx::init::Zero; + bx::Vec3 m_up = bx::init::Zero; float m_horizontalAngle; float m_verticalAngle; diff --git a/examples/common/debugdraw/debugdraw.cpp b/examples/common/debugdraw/debugdraw.cpp index ec0c73474..782e3ddeb 100644 --- a/examples/common/debugdraw/debugdraw.cpp +++ b/examples/common/debugdraw/debugdraw.cpp @@ -295,30 +295,14 @@ uint32_t genSphere(uint8_t _subdiv0, void* _pos0 = NULL, uint16_t _posStride0 = bx::Vec3 getPoint(Axis::Enum _axis, float _x, float _y) { - bx::Vec3 result; - switch (_axis) { - case Axis::X: - result.x = 0.0f; - result.y = _x; - result.z = _y; - break; - - case Axis::Y: - result.x = _y; - result.y = 0.0f; - result.z = _x; - break; - - default: - result.x = _x; - result.y = _y; - result.z = 0.0f; - break; + case Axis::X: return { 0.0f, _x, _y }; + case Axis::Y: return { _y, 0.0f, _x }; + default: break; } - return result; + return { _x, _y, 0.0f }; } #include "vs_debugdraw_lines.bin.h" @@ -1664,7 +1648,7 @@ struct DebugDrawEncoderImpl void drawFrustum(const float* _viewProj) { - bx::Plane planes[6]; + bx::Plane planes[6] = { bx::init::None, bx::init::None, bx::init::None, bx::init::None, bx::init::None, bx::init::None }; buildFrustumPlanes(planes, _viewProj); const bx::Vec3 points[8] = @@ -1761,8 +1745,8 @@ struct DebugDrawEncoderImpl const float step = bx::kPi * 2.0f / num; _weight = bx::clamp(_weight, 0.0f, 2.0f); - bx::Vec3 udir; - bx::Vec3 vdir; + bx::Vec3 udir(bx::init::None); + bx::Vec3 vdir(bx::init::None); bx::calcTangentFrame(udir, vdir, _normal, attrib.m_spin); float xy0[2]; @@ -1833,7 +1817,8 @@ struct DebugDrawEncoderImpl const Attrib& attrib = m_attrib[m_stack]; if (attrib.m_wireframe) { - bx::Vec3 udir, vdir; + bx::Vec3 udir(bx::init::None); + bx::Vec3 vdir(bx::init::None); bx::calcTangentFrame(udir, vdir, _normal, attrib.m_spin); const float halfExtent = _size*0.5f; @@ -1874,7 +1859,8 @@ struct DebugDrawEncoderImpl const Attrib& attrib = m_attrib[m_stack]; - bx::Vec3 udir, vdir; + bx::Vec3 udir(bx::init::None); + bx::Vec3 vdir(bx::init::None); bx::calcTangentFrame(udir, vdir, _normal, attrib.m_spin); const Pack2D& pack = s_dds.m_sprite.get(_handle); @@ -1994,8 +1980,8 @@ struct DebugDrawEncoderImpl if (_thickness > 0.0f) { const bx::Vec3 from = { _x, _y, _z }; - bx::Vec3 mid; - bx::Vec3 to; + bx::Vec3 mid(bx::init::None); + bx::Vec3 to(bx::init::None); setColor(Axis::X == _highlight ? 0xff00ffff : 0xff0000ff); mid = { _x + _len - _thickness, _y, _z }; @@ -2037,8 +2023,8 @@ struct DebugDrawEncoderImpl { const Attrib& attrib = m_attrib[m_stack]; - bx::Vec3 udir; - bx::Vec3 vdir; + bx::Vec3 udir(bx::init::None); + bx::Vec3 vdir(bx::init::None); bx::calcTangentFrame(udir, vdir, _normal, attrib.m_spin); udir = bx::mul(udir, _step); diff --git a/examples/common/ps/particle_system.cpp b/examples/common/ps/particle_system.cpp index 52647d06d..cbcf2b874 100644 --- a/examples/common/ps/particle_system.cpp +++ b/examples/common/ps/particle_system.cpp @@ -248,7 +248,7 @@ namespace ps Particle& particle = m_particles[m_num]; m_num++; - bx::Vec3 pos; + bx::Vec3 pos(bx::init::None); switch (m_shape) { default: @@ -281,7 +281,7 @@ namespace ps break; } - bx::Vec3 dir; + bx::Vec3 dir(bx::init::None); switch (m_direction) { default: diff --git a/tools/geometryc/geometryc.cpp b/tools/geometryc/geometryc.cpp index d2aff270f..d604fd382 100644 --- a/tools/geometryc/geometryc.cpp +++ b/tools/geometryc/geometryc.cpp @@ -589,7 +589,7 @@ void parseObj(char* _data, uint32_t _size, Mesh* _mesh, bool _hasBc) if (0 == bx::strCmp(argv[0], "vn") ) { - bx::Vec3 normal; + bx::Vec3 normal(bx::init::None); bx::fromString(&normal.x, argv[1]); bx::fromString(&normal.y, argv[2]); bx::fromString(&normal.z, argv[3]); @@ -607,7 +607,7 @@ void parseObj(char* _data, uint32_t _size, Mesh* _mesh, bool _hasBc) } else if (0 == bx::strCmp(argv[0], "vt") ) { - bx::Vec3 texcoord; + bx::Vec3 texcoord(bx::init::None); texcoord.y = 0.0f; texcoord.z = 0.0f; @@ -645,15 +645,10 @@ void parseObj(char* _data, uint32_t _size, Mesh* _mesh, bool _hasBc) pw = 1.0f; } - float invW = 1.0f/pw; - px *= invW; - py *= invW; - pz *= invW; + bx::Vec3 pos(px, py, pz); - bx::Vec3 pos; - pos.x = px; - pos.y = py; - pos.z = pz; + const float invW = bx::rcp(pw); + pos = bx::mul(pos, invW); _mesh->m_positions.push_back(pos); } @@ -753,8 +748,9 @@ void processGltfNode(cgltf_node* _node, Mesh* _mesh, Group* _group, bool _hasBc) { _mesh->m_positions.reserve(_mesh->m_positions.size() + accessorCount); - bx::Vec3 pos; - for (cgltf_size v=0;vm_normals.reserve(_mesh->m_normals.size() + accessorCount); hasNormal = true; - bx::Vec3 normal; - for (cgltf_size v=0;vm_texcoords.reserve(_mesh->m_texcoords.size() + accessorCount); hasTexcoord = true; - bx::Vec3 texcoord; - for (cgltf_size v=0;vm_texcoords.push_back(texcoord); diff --git a/tools/geometryv/geometryv.cpp b/tools/geometryv/geometryv.cpp index 52befb53d..adf15b2f3 100644 --- a/tools/geometryv/geometryv.cpp +++ b/tools/geometryv/geometryv.cpp @@ -169,7 +169,7 @@ struct Camera { Camera() { - init(bx::Vec3(0.0f,0.0f,0.0f), 2.0f, 0.01f, 100.0f); + init(bx::init::Zero, 2.0f, 0.01f, 100.0f); } void init(const bx::Vec3& _center, float _distance, float _near, float _far) @@ -265,8 +265,8 @@ struct Camera struct Interp3f { - bx::Vec3 curr; - bx::Vec3 dest; + bx::Vec3 curr = bx::init::None; + bx::Vec3 dest = bx::init::None; }; Interp3f m_target;