glm: fix pointer indexing warnings (#6215)
parent
995a5fed1f
commit
8e4ee54070
|
@ -64,7 +64,7 @@ pub fn (m Mat4) str() string {
|
|||
s += ' '
|
||||
}
|
||||
for j in 0..4 {
|
||||
val := m.data[i * 4 + j]
|
||||
val := unsafe {m.data[i * 4 + j]}
|
||||
s += '${val:5.2f} '
|
||||
}
|
||||
if i != 3 {
|
||||
|
@ -141,6 +141,7 @@ pub fn translate(m Mat4, v Vec3) Mat4 {
|
|||
x := v.x
|
||||
y := v.y
|
||||
z := v.z
|
||||
unsafe {
|
||||
a00 := a[0] a01 := a[1] a02 := a[2] a03 := a[3]
|
||||
a10 := a[4] a11 := a[5] a12 := a[6] a13 := a[7]
|
||||
a20 := a[8] a21 := a[9] a22 := a[10] a23 := a[11]
|
||||
|
@ -151,6 +152,7 @@ pub fn translate(m Mat4, v Vec3) Mat4 {
|
|||
out[13] = a01 * x + a11 * y + a21 * z + a[13]
|
||||
out[14] = a02 * x + a12 * y + a22 * z + a[14]
|
||||
out[15] = a03 * x + a13 * y + a23 * z + a[15]
|
||||
}
|
||||
return mat4(out)
|
||||
}
|
||||
|
||||
|
@ -166,12 +168,14 @@ pub fn ortho(left, right, bottom, top f32) Mat4 {
|
|||
// mat<4, 4, T, defaultp> Result(static_cast<T>(1));
|
||||
n := 16
|
||||
mut res := f32_calloc(n)
|
||||
unsafe {
|
||||
res[0] = 2.0 / (right - left)
|
||||
res[5] = 2.0 / (top - bottom)
|
||||
res[10] = 1.0
|
||||
res[12] = - (right + left) / (right - left)
|
||||
res[13] = - (top + bottom) / (top - bottom)
|
||||
res[15] = 1.0
|
||||
}
|
||||
return mat4(res)
|
||||
}
|
||||
|
||||
|
@ -181,6 +185,7 @@ pub fn ortho_zo(left, right, bottom, top, zNear, zFar f32) Mat4 {
|
|||
// mat<4, 4, T, defaultp> Result(static_cast<T>(1));
|
||||
n := 16
|
||||
mut res := f32_calloc(n)
|
||||
unsafe {
|
||||
res[0] = 2.0 / (right - left)
|
||||
res[5] = 2.0 / (top - bottom)
|
||||
res[10] = 1.0
|
||||
|
@ -188,6 +193,7 @@ pub fn ortho_zo(left, right, bottom, top, zNear, zFar f32) Mat4 {
|
|||
res[13] = - (top + bottom) / (top - bottom)
|
||||
res[14] = - zNear / (zFar - zNear)
|
||||
res[15] = 1.0
|
||||
}
|
||||
return mat4(res)
|
||||
}
|
||||
|
||||
|
@ -198,6 +204,7 @@ pub fn scale(m Mat4, v Vec3) Mat4 {
|
|||
x := v.x
|
||||
y := v.y
|
||||
z := v.z
|
||||
unsafe {
|
||||
out[0] = a[0] * v.x
|
||||
out[1] = a[1] * x
|
||||
out[2] = a[2] * x
|
||||
|
@ -214,6 +221,7 @@ pub fn scale(m Mat4, v Vec3) Mat4 {
|
|||
out[13] = a[13]
|
||||
out[14] = a[14]
|
||||
out[15] = a[15]
|
||||
}
|
||||
return mat4(out)
|
||||
}
|
||||
|
||||
|
@ -224,11 +232,13 @@ pub fn mult(a, b Mat4) Mat4 {
|
|||
for r in 0..4 {
|
||||
mut prod := f32(0)
|
||||
for c in 0..4 {
|
||||
prod += a.data[c*4+r] * b.data[i*4+c]
|
||||
prod += unsafe {a.data[c*4+r] * b.data[i*4+c]}
|
||||
}
|
||||
unsafe {
|
||||
out[i*4+r] = prod
|
||||
}
|
||||
}
|
||||
}
|
||||
return mat4(out)
|
||||
}
|
||||
|
||||
|
@ -257,7 +267,7 @@ pub fn rotate(angle f32, axis Vec3, src Mat4) Mat4 {
|
|||
f22 := axis.z *axis.z * oneminusc + c
|
||||
|
||||
data := src.data
|
||||
|
||||
unsafe {
|
||||
t00 := data[0] * f00 + data[4] * f01 + data[8] * f02
|
||||
t01 := data[1] * f00 + data[5] * f01 + data[9] * f02
|
||||
t02 := data[2] * f00 + data[6] * f01 + data[10] * f02
|
||||
|
@ -279,6 +289,7 @@ pub fn rotate(angle f32, axis Vec3, src Mat4) Mat4 {
|
|||
dest[4] = t10 dest[5] = t11 dest[6] = t12 dest[7] = t13
|
||||
|
||||
return mat4(dest)
|
||||
}
|
||||
}
|
||||
|
||||
// fn rotate_z(a *f32, rad f32) *f32 {
|
||||
|
@ -287,6 +298,7 @@ pub fn rotate_z(m Mat4, rad f32) Mat4 {
|
|||
mut out := f32_calloc(16)
|
||||
s := f32(math.sin(rad))
|
||||
c := f32(math.cos(rad))
|
||||
unsafe {
|
||||
a00 := a[0]
|
||||
a01 := a[1]
|
||||
a02 := a[2]
|
||||
|
@ -312,6 +324,7 @@ pub fn rotate_z(m Mat4, rad f32) Mat4 {
|
|||
out[5] = a11 * c - a01 * s
|
||||
out[6] = a12 * c - a02 * s
|
||||
out[7] = a13 * c - a03 * s
|
||||
}
|
||||
return mat4(out)
|
||||
}
|
||||
|
||||
|
@ -322,10 +335,12 @@ pub fn identity() Mat4 {
|
|||
// 0 0 0 1
|
||||
n := 16
|
||||
mut res := f32_calloc(int(sizeof(f32)) * n)
|
||||
unsafe {
|
||||
res[0] = 1
|
||||
res[5] = 1
|
||||
res[10] = 1
|
||||
res[15] = 1
|
||||
}
|
||||
return mat4(res)
|
||||
}
|
||||
|
||||
|
@ -357,8 +372,8 @@ fn ortho_js(left, right, bottom, top f32) &f32 {
|
|||
lr := 1.0 / (left - right)
|
||||
bt := 1.0 / (bottom - top)
|
||||
nf := f32(1.0) / 1.0// (mynear -myfar)
|
||||
mut out := &f32(0)
|
||||
unsafe { out = &f32( malloc (int(sizeof(f32) * 16))) }
|
||||
unsafe {
|
||||
mut out := &f32( malloc (int(sizeof(f32) * 16)))
|
||||
out[0] = -2.0 * lr
|
||||
out[1] = 0
|
||||
out[2] = 0
|
||||
|
@ -376,6 +391,7 @@ fn ortho_js(left, right, bottom, top f32) &f32 {
|
|||
out[14] = 1.0 * nf//(far + near) * nf;
|
||||
out[15] = 1
|
||||
return out
|
||||
}
|
||||
//f := 0.0
|
||||
//return &f
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue