Godot Version
4.2.1
Question
Hi there, I’m having a bit of trouble rotating a cube in 3d space. The rotation does indeed rotate, but the coordinates are slightly off when rotated, almost as if they’re being sheared. I’m using the normal equations x’ = xsin(0)… , so I’m not sure what I’m doing wrong. Here is a picture of the cube rotated in the y-axis 45 degrees:
And here is my code doing the rotating:
func get_outer_points(shape: MeshInstance3D):
var points = {} # p1, p2, p3, p4, p5, p6
#var transform = shape.global_transform
var transform = shape.global_transform
var center = transform.origin
var deg = transform.basis.get_euler()
var size_x = (shape.scale.x/2.0)*shape.mesh.size.x
var size_y = (shape.scale.y/2.0)*shape.mesh.size.y
var size_z = (shape.scale.z/2.0)*shape.mesh.size.z
for x in [-size_x, size_x]:
for y in [-size_y, size_y]:
for z in [-size_z, size_z]:
var point = Vector3(x, y, z)
print(point)
point = rotate_point(point, deg, center)
print(point)
points[point] = Color(1.0, .5, .3, 0.0)
return points
func rotate_point(p: Vector3, e: Vector3, t: Vector3):
p[0] = p[0]*cos(e[1]) - sin(e[1])*p[2] # I'm only using this part at the moment to check my y-rotation
p[2] = p[0]*sin(e[1]) + cos(e[1])*p[2]
#p[1] = p[1]*sin(e[0]) + cos(e[0])*p[2]
#p[2] = p[1]*cos(e[0]) - sin(e[0])*p[2]
#p[0] = p[0]*cos(e[2]) - sin(e[2])*p[1]
#p[1] = p[0]*sin(e[2]) + cos(e[2])*p[1]
for i in range(3):
p[i] = p[i] + t[i]
return p
If anyone with more math experience could help, I’d be super thankful.