MCPcopy Create free account
hub / github.com/OpenMW/openmw / generateWireCube

Function generateWireCube

components/debug/debugdraw.cpp:30–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28}
29
30static void generateWireCube(osg::Geometry& geom, float dim)
31{
32 osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
33 osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
34
35 osg::Vec2i indexPos[] = { osg::Vec2i(0, 0), osg::Vec2i(1, 0), osg::Vec2i(1, 1), osg::Vec2i(0, 1) };
36
37 for (int i = 0; i < 4; i++)
38 {
39 osg::Vec3 vert1 = osg::Vec3(indexPos[i].x() - 0.5f, indexPos[i].y() - 0.5f, 0.5f);
40 int next = (i + 1) % 4;
41 osg::Vec3 vert2 = osg::Vec3(indexPos[next].x() - 0.5f, indexPos[next].y() - 0.5f, 0.5f);
42
43 vertices->push_back(vert1 * dim);
44 vertices->push_back(vert2 * dim);
45 vert1.z() *= -1;
46 vert2.z() *= -1;
47 vertices->push_back(vert1 * dim);
48 vertices->push_back(vert2 * dim);
49
50 auto vert3 = vert1;
51 vert3.z() *= -1;
52 vertices->push_back(vert1 * dim);
53 vertices->push_back(vert3 * dim);
54 }
55 for (std::size_t i = 0; i < vertices->size(); i++)
56 {
57 normals->push_back(osg::Vec3(1., 1., 1.));
58 }
59
60 geom.setVertexArray(vertices);
61 geom.setNormalArray(normals, osg::Array::BIND_PER_VERTEX);
62 geom.addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, static_cast<GLsizei>(vertices->size())));
63}
64
65static void generateCube(osg::Geometry& geom, float dim)
66{

Callers 1

DebugDrawerMethod · 0.85

Calls 2

Vec3Class · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected