@@ -9,6 +9,9 @@ struct Ground {
99 bgfx::ViewId viewId;
1010 bgfx::VertexBufferHandle m_vbhGround;
1111 bgfx::IndexBufferHandle m_ibhGround;
12+
13+ std::vector<PosColorVertex> gridVerts;
14+ std::vector<uint16_t > gridIndices;
1215 bgfx::VertexBufferHandle m_vbhGrid;
1316 bgfx::IndexBufferHandle m_ibhGrid;
1417
@@ -25,10 +28,10 @@ struct Ground {
2528
2629 void make_ground () {
2730 static PosColorVertex s_groundVertices[4 ] = {
28- { -1 .0f , 1 .0f , 0 .0f , 0xff696969 },
29- { 1 .0f , 1 .0f , 0 .0f , 0xff696969 },
30- { -1 .0f , - 1 .0f , 0 .0f , 0xff696969 },
31- { 1 .0f , - 1 .0f , 0 .0f , 0xff696969 },
31+ { -1 .0f , 0 .0f , 1 .0f , 0xff696969 },
32+ { 1 .0f , 0 .0f , 1 .0f , 0xff696969 },
33+ { -1 .0f , 0 .0f , - 1 .0f , 0xff696969 },
34+ { 1 .0f , 0 .0f , - 1 .0f , 0xff696969 },
3235 };
3336
3437 static const uint16_t s_groundIndices[] = {
@@ -51,35 +54,49 @@ struct Ground {
5154 void make_grid () {
5255 // grid
5356
54- std::vector<PosColorVertex> gridVerts;
55- std::vector<uint16_t > gridIndices;
57+
5658
5759 const int gridSize = 20 ;
58- const float spacing = 1 .0f ;
60+ const float cube = 2 .0f ;
61+ const float offset = 1 .0f ;
62+ const float spacing = cube + offset;
5963
6064 uint16_t idx = 0 ;
61- for (int i = -gridSize; i <= gridSize; ++i) {
65+ for (int i = -gridSize / 2 ; i < gridSize / 2 ; ++i) {
6266 float x = i * spacing;
6367 float zmin = -gridSize * spacing;
6468 float zmax = gridSize * spacing;
6569
66- uint32_t color = (i == 0 ? 0xffffffff : 0xff404040 ) ;
70+ uint32_t color = 0xff404040 ;
6771
68- gridVerts.push_back ({ x, 0 .01f , zmin, color });
69- gridVerts.push_back ({ x, 0 .01f , zmax, color });
70- gridIndices.push_back (idx++);
71- gridIndices.push_back (idx++);
72+ gridVerts.push_back ({ x, 0 .0f , zmin, color });
73+ gridVerts.push_back ({ x + 0 .01f , 0 .0f , zmin, color });
74+ gridVerts.push_back ({ x, 0 .0f , zmax, color });
75+ gridVerts.push_back ({ x + 0 .01f , 0 .0f , zmax, color });
76+ gridIndices.push_back (idx + 0 );
77+ gridIndices.push_back (idx + 1 );
78+ gridIndices.push_back (idx + 2 );
79+ gridIndices.push_back (idx + 1 );
80+ gridIndices.push_back (idx + 3 );
81+ gridIndices.push_back (idx + 2 );
82+ idx += 4 ;
7283
7384 float z = i * spacing;
7485 float xmin = -gridSize * spacing;
7586 float xmax = gridSize * spacing;
7687
77- color = (i == 0 ? 0xffffffff : 0xff404040 );
78-
79- gridVerts.push_back ({ xmin, 0 .01f , z, color });
80- gridVerts.push_back ({ xmax, 0 .01f , z, color });
81- gridIndices.push_back (idx++);
82- gridIndices.push_back (idx++);
88+ gridVerts.push_back ({ xmax, 0 .0f , z, color });
89+ gridVerts.push_back ({ xmax, 0 .0f , z + 0 .01f , color });
90+ gridVerts.push_back ({ xmin, 0 .0f , z, color });
91+ gridVerts.push_back ({ xmin, 0 .0f , z + 0 .01f , color });
92+ gridIndices.push_back (idx + 0 );
93+ gridIndices.push_back (idx + 1 );
94+ gridIndices.push_back (idx + 2 );
95+ gridIndices.push_back (idx + 1 );
96+ gridIndices.push_back (idx + 3 );
97+ gridIndices.push_back (idx + 2 );
98+ idx += 4 ;
99+
83100 }
84101
85102 m_vbhGrid = bgfx::createVertexBuffer (
@@ -94,12 +111,14 @@ struct Ground {
94111
95112 void draw () {
96113 draw_ground ();
97- // draw_grid();
114+ draw_grid ();
98115
99- DebugDrawEncoder dde;
100- dde.begin (viewId); // viewId
116+ // DebugDrawEncoder dde;
117+ // dde.begin(viewId); // viewId
101118
102- dde.drawGrid (Axis::Y, { 0 .0f , 0 .0f , 0 .0f });
119+ // dde.drawGrid(Axis::Y, { 0.0f, 0.0f, 0.0f });
120+
121+
103122 // const int gridSize = 20;
104123 // const float spacing = 1.0f;
105124
@@ -116,16 +135,16 @@ struct Ground {
116135 // // optional axes
117136 // dde.drawAxis(0.0f, 0.0f, 0.0f);
118137
119- dde.end ();
138+ // dde.end();
120139 }
121140
122141 void draw_ground () {
123142 float selMtx[16 ];
124143 bx::mtxIdentity (selMtx);
125144 bx::mtxSRT (selMtx,
126- 10 .0f , 10 .0f , 1 .0f , // scale
145+ 50 .0f , 1 .0f , 50 .0f , // scale
127146 0 .0f , 0 .0f , 0 .0f , // rotation
128- 0 .0f ,0 .0f , - 3 .0f );// translation
147+ 0 .0f ,- 1 .0f , 0 .0f );// translation
129148 // bx::mtxTranslate(selMtx, -12.0f, -12.0f, 0.0f);
130149 bgfx::setTransform (selMtx);
131150
@@ -144,9 +163,30 @@ struct Ground {
144163 }
145164
146165 void draw_grid () {
166+
167+ float selMtx[16 ];
168+ bx::mtxIdentity (selMtx);
169+ bx::mtxSRT (selMtx,
170+ 1 .0f , 1 .0f , 1 .0f , // scale
171+ 0 .0f , 0 .0f , 0 .0f , // rotation
172+ -1 .5f ,-1 .0f , -1 .5f );// translation
173+ // bx::mtxTranslate(selMtx, -12.0f, -12.0f, 0.0f);
174+ bgfx::setTransform (selMtx);
175+
176+ float m_color[4 ];
177+
178+ m_color[0 ] = 0 .1f ;
179+ m_color[1 ] = 0 .1f ;
180+ m_color[2 ] = 0 .1f ;
181+ m_color[3 ] = 1 .0f ;
182+ bgfx::setUniform (u_color, m_color);
183+
147184 bgfx::setVertexBuffer (0 , m_vbhGrid);
148185 bgfx::setIndexBuffer (m_ibhGrid);
149- bgfx::setState (BGFX_STATE_DEFAULT);
186+ bgfx::setState (BGFX_STATE_WRITE_RGB |
187+ BGFX_STATE_DEPTH_TEST_LESS |
188+ BGFX_STATE_CULL_CW |
189+ BGFX_STATE_MSAA);
150190 bgfx::submit (viewId, m_program);
151191 }
152192
0 commit comments