Skip to content

Commit a56aedb

Browse files
committed
Mapnode: Add rotateAlongYAxisFull supporting 24 facedirs
1 parent 1adc7bf commit a56aedb

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

src/mapnode.cpp

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ v3s16 MapNode::getWallMountedDir(INodeDefManager *nodemgr) const
159159
}
160160
}
161161

162-
void MapNode::rotateAlongYAxis(INodeDefManager *nodemgr, Rotation rot) {
162+
void MapNode::rotateAlongYAxis(INodeDefManager *nodemgr, Rotation rot)
163+
{
163164
ContentParamType2 cpt2 = nodemgr->get(*this).param_type_2;
164165

165166
if (cpt2 == CPT2_FACEDIR) {
@@ -180,6 +181,59 @@ void MapNode::rotateAlongYAxis(INodeDefManager *nodemgr, Rotation rot) {
180181
}
181182
}
182183

184+
void MapNode::rotateAlongYAxisFull(INodeDefManager *nodemgr, Rotation rot)
185+
{
186+
ContentParamType2 cpt2 = nodemgr->get(*this).param_type_2;
187+
188+
if (cpt2 == CPT2_FACEDIR) {
189+
static const u16 rotate_facedir[24 * 4] = {
190+
// Table value = rotated facedir
191+
// Columns: 0, 90, 180, 270 degrees rotation around vertical axis
192+
// Rotation is anticlockwise as seen from above (+Y)
193+
194+
0, 1, 2, 3, // Initial facedir 0 to 3
195+
1, 2, 3, 0,
196+
2, 3, 0, 1,
197+
3, 0, 1, 2,
198+
199+
4, 13, 10, 19, // 4 to 7
200+
5, 14, 11, 16,
201+
6, 15, 8, 17,
202+
7, 12, 9, 18,
203+
204+
8, 17, 6, 15, // 8 to 11
205+
9, 18, 7, 12,
206+
10, 19, 4, 13,
207+
11, 16, 5, 14,
208+
209+
12, 9, 18, 7, // 12 to 15
210+
13, 10, 19, 4,
211+
14, 11, 16, 5,
212+
15, 8, 17, 6,
213+
214+
16, 5, 14, 11, // 16 to 19
215+
17, 6, 15, 8,
216+
18, 7, 12, 9,
217+
19, 4, 13, 10,
218+
219+
20, 23, 22, 21, // 20 to 23
220+
21, 20, 23, 22,
221+
22, 21, 20, 23,
222+
23, 22, 21, 20
223+
};
224+
u16 index = param2 * 4 + rot;
225+
param2 = rotate_facedir[index];
226+
} else if (cpt2 == CPT2_WALLMOUNTED) {
227+
u8 wmountface = (param2 & 7);
228+
if (wmountface <= 1)
229+
return;
230+
231+
Rotation oldrot = wallmounted_to_rot[wmountface - 2];
232+
param2 &= ~7;
233+
param2 |= rot_to_wallmounted[(oldrot - rot) & 3];
234+
}
235+
}
236+
183237
static std::vector<aabb3f> transformNodeBox(const MapNode &n,
184238
const NodeBox &nodebox, INodeDefManager *nodemgr)
185239
{

src/mapnode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ struct MapNode
236236
v3s16 getWallMountedDir(INodeDefManager *nodemgr) const;
237237

238238
void rotateAlongYAxis(INodeDefManager *nodemgr, Rotation rot);
239+
void rotateAlongYAxisFull(INodeDefManager *nodemgr, Rotation rot);
239240

240241
/*
241242
Gets list of node boxes (used for rendering (NDT_NODEBOX))

src/mg_schematic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ void Schematic::blitToVManip(v3s16 p, MMVManip *vm, Rotation rot, bool force_pla
167167
vm->m_data[vi].param1 = 0;
168168

169169
if (rot)
170-
vm->m_data[vi].rotateAlongYAxis(m_ndef, rot);
170+
vm->m_data[vi].rotateAlongYAxisFull(m_ndef, rot);
171171
}
172172
}
173173
y_map++;

0 commit comments

Comments
 (0)