Godot Version
4.2.1
Question
I’m encountering a problem while trying to get the direction and up vectors of an Editor Camera3D in Godot-cpp 4.2.
I’ve set up the viewport so that the Camera3D is initially pointing approximately in the direction of (0, -1, 0) and looking at the world origin. When I rotate the camera around the world’s Y-axis, I expect the camera’s direction vector to remain unchanged, approximately (0, -1, 0). However, the actual result is (1, 0, 0).
Am I correctly acquiring the camera’s forward direction vector using transform.basis[2] and the up direction vector using transform.basis[1]?
I’m confused about why this is happening and whether it could be a bug in Godot-cpp 4.2. Can anyone help me understand this issue?
...
EditorInterface *editor_interface = EditorInterface::get_singleton();
Node *editor_root_node = editor_interface->get_edited_scene_root();
godot::SubViewport *editor_viewport = nullptr;
godot::Camera3D *editor_camera = nullptr;
std::array<int, 4> indices{ 0, 1, 2, 3 };
for ( int i : indices )
{
editor_viewport = editor_interface->get_editor_viewport_3d( i );
if ( editor_viewport != nullptr )
{
editor_camera = editor_viewport->get_camera_3d();
if ( editor_camera != nullptr )
{
godot::Size2 viewportSize = editor_viewport->get_visible_rect().size;
if ( viewportSize.width > 50 && viewportSize.height > 50 )
{
result.emplace_back(
godotCameraToViewState( pCoordinateSystem, godotWorldToTileset,
editor_camera, viewportSize ) );
}
}
}
}
...
ViewState godotCameraToViewState( const LocalHorizontalCoordinateSystem *pCoordinateSystem,
const glm::dmat4 &godotWorldToTileset,
const godot::Camera3D *camera,
const godot::Size2 viewportSize )
{
godot::Transform3D transform = camera->get_camera_transform();
godot::Vector3 origin = transform.get_origin();
glm::dvec3 cameraPosition =
glm::dvec3( godotWorldToTileset * glm::dvec4( origin.x, origin.y, origin.z, 1.0 ) );
godot::Vector3 cameraDirectionGodot = transform.basis[2];
glm::dvec3 cameraDirection = glm::dvec3(
godotWorldToTileset * glm::dvec4( cameraDirectionGodot.x, cameraDirectionGodot.y,
cameraDirectionGodot.z, 0.0 ) );
godot::Vector3 cameraUpGodot = transform.basis[1];
glm::dvec3 cameraUp =
glm::dvec3( godotWorldToTileset *
glm::dvec4( cameraUpGodot.x, cameraUpGodot.y, cameraUpGodot.z, 0.0 ) );
...