JasperLeFoox
JasperLeFoox

Reputation: 21

How can I get the true horizontal rotation of the scene camera in VPython?

I'm trying to get the horizontal rotation of the camera, but the scene.camera.axis.x seems to be completely random and makes no sense at all. I need the rotation in degrees because that's what I need to rotate my object to the camera.

Here is what ive tried:

I tried inputting the X in the sin for rotation, and Z in the cos for rotation, which didn't work. I just tried doing only X in both sin and cos for rotation, it seemed random.

This is my code. (model is just an obj files text, but I excluded it and the function source code because those are not the problem, and would make it ridiculously long.)

loadobject(model,size=3)

scene.camera.autoscale = False

sine = 0
rotx = 0
roty = 0
print(offset)

scene.camera.axis = vec(0,0,0)
while True:
  rate(60)
  vertindex = 0
  rotx = scene.camera.axis.x
  
  roty += 1
  for v in verts:
    v.pos.x = (sin(radians(rotx)) * (objectposes[vertindex].z - offset.z)) + (sin(radians(rotx - 90)) * (objectposes[vertindex].x - offset.x))
    v.pos.z = (cos(radians(rotx)) * (objectposes[vertindex].z - offset.z)) + (cos(radians(rotx - 90)) * (objectposes[vertindex].x - offset.x))
    sine += 0.001
    vertindex += 1

Upvotes: 0

Views: 60

Answers (0)

Related Questions