Hey guys.
I am trying to setup precise image capturing from Camera sensor.
I am a bit confused with the setup of direction and up vectors.
I know that I am able to grab 7th elements array: [position, x, y, z, w] of Camera’s view characteristics using Camera Transform
tool.
(new users may embed only one media in the post…)
And then convert Quaternion (last 4 numbers in array: x, y, z, w) into Direction and Up vectors.
I have tried to use found in Internet formulas and there is no luck.
Then I have found in beamngpy library the useful method: compute_rotation_matrix from beamngpy.misc.quat.
In, general I created the following code:
from beamngpy.misc.quat import compute_rotation_matrix
matrix = compute_rotation_matrix((0.226881, -0.0176147, 0.0753748, 0.970842))
direction_vector = matrix[:, 2]
up_vector = matrix[:, 1]
print(f"Direction: {direction_vector}")
print(f"Up vector: {up_vector}")
And then I put obtained values into Camera setup:
av_a = Vehicle("vehicleA", model="bollard")
client_b = BeamNGpy("localhost", 64256)
client_b.open(launch=False)
running_scenario = client_b.scenario.get_current()
running_scenario.add_vehicle(av_a, pos=(-760.29, 354.34, 157.5))
print(running_scenario.name)
camera = Camera(
"camera1",
client_b,
av_a,
update_priority=1,
requested_update_time=0.00000001,
pos=(0, 0, 3),
dir=(3.88427683e-08, -4.43186255e-01, 8.96429553e-01),
up=(-0.1543468, 0.8856874, 0.43787544),
field_of_view_y=34.5,
near_far_planes=(0.1, 500),
resolution=(640, 640),
is_streaming=True,
is_render_colours=True,
is_render_annotations=False,
is_render_depth=False
)
And the only thing which I received is sky
Obviously, it is not what I need.
In general, I would like to have the following picture. (the FOV here is 32)
Could you please guys suggest me the correct way how to setup Direction and Up vectors for Camera?