fix(render): 方格垂直面被背面剔除(立面透明空洞/闪烁)+ 鼠标左右反转
- mesh.faceDef 六面绕序铁律:旧定义只有顶面是窗口空间顺时针 (FrontFace=CW 的正面),底/东/西/南/北五面是逆时针被全部剔除—— 世界只剩顶面、立面透明、移动时面闪烁(数值投影验证 5 面 area>0 被剔) - 覆盖层 cubeFaces(裂纹盒/手持方块)同步反转 - 鼠标右移应右转:yaw=0 朝 -Z,右转朝 +X 需 yaw 减小,dyaw 取反 (原实现 dyaw += dx 左右颠倒)
This commit is contained in:
@@ -97,6 +97,8 @@ func (in *inputState) mouseButtonCallback(_ *glfw.Window, button glfw.MouseButto
|
||||
}
|
||||
|
||||
// cursorCallback 鼠标移动:yaw/pitch 累积(渲染.md §2 主线程消费)。
|
||||
// 约定:鼠标右移 dx>0 应右转(yaw 减小——yaw=0 朝向 -Z,右转朝 +X);
|
||||
// 鼠标上移 dy<0 应抬头(pitch 增大)。
|
||||
func (in *inputState) cursorCallback(_ *glfw.Window, x, y float64) {
|
||||
in.cursorX, in.cursorY = x, y
|
||||
if in.firstMouse {
|
||||
@@ -107,7 +109,7 @@ func (in *inputState) cursorCallback(_ *glfw.Window, x, y float64) {
|
||||
dx, dy := x-in.lastX, y-in.lastY
|
||||
in.lastX, in.lastY = x, y
|
||||
const sens = 0.0025
|
||||
in.dyaw += dx * sens
|
||||
in.dyaw -= dx * sens
|
||||
in.dpitch -= dy * sens
|
||||
}
|
||||
|
||||
|
||||
@@ -69,13 +69,16 @@ type faceDef struct {
|
||||
}
|
||||
|
||||
// faces 六面定义(角顺序与 UV 顶点顺序一致)。
|
||||
// 绕序铁律:所有面必须为「窗口空间顺时针」(FrontFace=CW 的正面)——
|
||||
// 旧定义只有顶面是 CW,垂直面与底面是 CCW 被背面剔除,
|
||||
// 表现为「立面透明的空洞、移动时面闪烁」(方格立面缺失根因)。
|
||||
var faces = [6]faceDef{
|
||||
{dir: [3]int32{0, 1, 0}, corners: [4][3]int32{{0, 1, 0}, {1, 1, 0}, {1, 1, 1}, {0, 1, 1}}}, // 顶
|
||||
{dir: [3]int32{0, -1, 0}, corners: [4][3]int32{{0, 0, 1}, {1, 0, 1}, {1, 0, 0}, {0, 0, 0}}}, // 底
|
||||
{dir: [3]int32{1, 0, 0}, corners: [4][3]int32{{1, 0, 0}, {1, 0, 1}, {1, 1, 1}, {1, 1, 0}}}, // 东(+x)
|
||||
{dir: [3]int32{-1, 0, 0}, corners: [4][3]int32{{0, 0, 1}, {0, 0, 0}, {0, 1, 0}, {0, 1, 1}}}, // 西(-x)
|
||||
{dir: [3]int32{0, 0, 1}, corners: [4][3]int32{{1, 0, 1}, {0, 0, 1}, {0, 1, 1}, {1, 1, 1}}}, // 南(+z)
|
||||
{dir: [3]int32{0, 0, -1}, corners: [4][3]int32{{0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0}}}, // 北(-z)
|
||||
{dir: [3]int32{0, -1, 0}, corners: [4][3]int32{{0, 0, 0}, {1, 0, 0}, {1, 0, 1}, {0, 0, 1}}}, // 底(反向)
|
||||
{dir: [3]int32{1, 0, 0}, corners: [4][3]int32{{1, 1, 0}, {1, 1, 1}, {1, 0, 1}, {1, 0, 0}}}, // 东(+x)(反向)
|
||||
{dir: [3]int32{-1, 0, 0}, corners: [4][3]int32{{0, 1, 1}, {0, 1, 0}, {0, 0, 0}, {0, 0, 1}}}, // 西(-x)(反向)
|
||||
{dir: [3]int32{0, 0, 1}, corners: [4][3]int32{{1, 1, 1}, {0, 1, 1}, {0, 0, 1}, {1, 0, 1}}}, // 南(+z)(反向)
|
||||
{dir: [3]int32{0, 0, -1}, corners: [4][3]int32{{0, 1, 0}, {1, 1, 0}, {1, 0, 0}, {0, 0, 0}}}, // 北(-z)(反向)
|
||||
}
|
||||
|
||||
// faceTexture 面方向 → 注册表纹理面名(block.Registry.Texture 参数)。
|
||||
|
||||
@@ -14,14 +14,15 @@ import (
|
||||
"github.com/go-gl/gl/v3.3-core/gl"
|
||||
)
|
||||
|
||||
// cubeFaces 单位立方体 6 面角顺序(与 mesh.faceDef 一致,CW 绕序为正面)。
|
||||
// cubeFaces 单位立方体 6 面角顺序(与 mesh.faceDef 一致,
|
||||
// 窗口空间 CW 绕序为 FrontFace(CW) 的正面)。
|
||||
var cubeFaces = [6][4][3]float32{
|
||||
{{0, 1, 0}, {1, 1, 0}, {1, 1, 1}, {0, 1, 1}}, // 顶
|
||||
{{0, 0, 1}, {1, 0, 1}, {1, 0, 0}, {0, 0, 0}}, // 底
|
||||
{{1, 0, 0}, {1, 0, 1}, {1, 1, 1}, {1, 1, 0}}, // 东(+x)
|
||||
{{0, 0, 1}, {0, 0, 0}, {0, 1, 0}, {0, 1, 1}}, // 西(-x)
|
||||
{{1, 0, 1}, {0, 0, 1}, {0, 1, 1}, {1, 1, 1}}, // 南(+z)
|
||||
{{0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0}}, // 北(-z)
|
||||
{{0, 0, 0}, {1, 0, 0}, {1, 0, 1}, {0, 0, 1}}, // 底(反向)
|
||||
{{1, 1, 0}, {1, 1, 1}, {1, 0, 1}, {1, 0, 0}}, // 东(+x)(反向)
|
||||
{{0, 1, 1}, {0, 1, 0}, {0, 0, 0}, {0, 0, 1}}, // 西(-x)(反向)
|
||||
{{1, 1, 1}, {0, 1, 1}, {0, 0, 1}, {1, 0, 1}}, // 南(+z)(反向)
|
||||
{{0, 1, 0}, {1, 1, 0}, {1, 0, 0}, {0, 0, 0}}, // 北(-z)(反向)
|
||||
}
|
||||
|
||||
// cubeVerts 按六面 UV 构建单位立方体顶点(mesh.Vertex 格式:pos+uv+light 字节,
|
||||
|
||||
Reference in New Issue
Block a user