Skip to content

Commit c824ded

Browse files
committed
fix angle transforms
1 parent e7fac41 commit c824ded

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

pkg/bsptracer/bsptracer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func TestMap_TraceRay_de_cache(t *testing.T) {
119119
destination: mgl32.Vec3{138, 396, 1677},
120120
},
121121
want: out{
122-
visible: true,
122+
visible: false,
123123
trace: bsptracer.Trace{AllSolid: true, StartSolid: true, Fraction: 1, EndPos: mgl32.Vec3{138, 396, 1677}},
124124
},
125125
},

pkg/bsptracer/static_props.go

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func vectorITransform(in1 mgl32.Vec3, in2 mgl32.Mat3x4) (out mgl32.Vec3) {
3030
return out
3131
}
3232

33-
func transformPhyVertex(bone *mdl.Bone, vertex mgl32.Vec3) (out mgl32.Vec3) {
33+
func transformPhyVertex(bone *mdl.Bone, vertex mgl32.Vec3, orientation mgl32.Quat) (out mgl32.Vec3) {
3434
out[0] = 1 / 0.0254 * vertex[0]
3535
out[1] = 1 / 0.0254 * vertex[2]
3636
out[2] = 1 / 0.0254 * -vertex[1]
@@ -42,32 +42,24 @@ func transformPhyVertex(bone *mdl.Bone, vertex mgl32.Vec3) (out mgl32.Vec3) {
4242
out[1] = 1 / 0.0254 * -vertex[0]
4343
out[2] = 1 / 0.0254 * -vertex[1]
4444
}
45-
return out
45+
46+
return orientation.Rotate(out)
4647
}
4748

4849
func triangles(prop game.IStaticPropDataLump, phy *phy.Phy) [][3]mgl32.Vec3 {
4950
if phy == nil {
5051
return nil
5152
}
5253

53-
angleMatrices := []mgl32.Mat4{
54-
mgl32.Rotate3DX(prop.GetAngles()[0]).Mat4(),
55-
mgl32.Rotate3DY(prop.GetAngles()[1]).Mat4(),
56-
mgl32.Rotate3DZ(prop.GetAngles()[2]).Mat4(),
57-
}
54+
angles := prop.GetAngles()
55+
orientation := mgl32.AnglesToQuat(mgl32.DegToRad(angles[0]), mgl32.DegToRad(angles[1]), mgl32.DegToRad(angles[2]), mgl32.YZX)
5856

5957
out := make([][3]mgl32.Vec3, len(phy.TriangleFaces))
6058

6159
for i, t := range phy.TriangleFaces {
62-
a := prop.GetOrigin().Add(transformPhyVertex(nil, phy.Vertices[t.V1].Vec3()))
63-
b := prop.GetOrigin().Add(transformPhyVertex(nil, phy.Vertices[t.V2].Vec3()))
64-
c := prop.GetOrigin().Add(transformPhyVertex(nil, phy.Vertices[t.V3].Vec3()))
65-
66-
for _, mat := range angleMatrices {
67-
a = mgl32.TransformCoordinate(a, mat)
68-
b = mgl32.TransformCoordinate(b, mat)
69-
c = mgl32.TransformCoordinate(c, mat)
70-
}
60+
a := prop.GetOrigin().Add(transformPhyVertex(nil, phy.Vertices[t.V1].Vec3(), orientation))
61+
b := prop.GetOrigin().Add(transformPhyVertex(nil, phy.Vertices[t.V2].Vec3(), orientation))
62+
c := prop.GetOrigin().Add(transformPhyVertex(nil, phy.Vertices[t.V3].Vec3(), orientation))
7163

7264
out[i] = [3]mgl32.Vec3{a, b, c}
7365
}

0 commit comments

Comments
 (0)