godotengine / godot-cpp

C++ bindings for the Godot script API
MIT License
1.7k stars 528 forks source link

Attempting to rotate a vector by a quaternion in GDExtension #1453

Closed samanthabeilman closed 4 months ago

samanthabeilman commented 4 months ago

Godot version

v4.1.4.stable.official

godot-cpp version

v4.1.4.stable.official

System information

Windows 11

Issue description

Multiplying a Quaternion and Vector3 should result in a Vector3, but it is returning a Quaternion. https://docs.godotengine.org/en/stable/classes/class_quaternion.html#class-quaternion-operator-mul-vector3:~:text=Vector3%20operator%20*%20(%20Vector3%20right%20)

The following error is encountered when compiling with SCons:

error C2440: 'initializing': cannot convert from 'godot::Quaternion' to 'godot::Vector3'
note: 'godot::Vector3::Vector3': no overloaded function could convert all the argument types
godot-cpp\include\godot_cpp/variant/vector3.hpp(184): note: could be 'godot::Vector3::Vector3(godot::Vector3 &&)'
note: 'godot::Vector3::Vector3(godot::Vector3 &&)': cannot convert argument 1 from 'godot::Quaternion' to 'godot::Vector3 &&'
note: Reason: cannot convert from 'godot::Quaternion' to 'godot::Vector3'
note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
godot-cpp\include\godot_cpp/variant/vector3.hpp(184): note: or       'godot::Vector3::Vector3(const godot::Vector3 &)'
note: 'godot::Vector3::Vector3(const godot::Vector3 &)': cannot convert argument 1 from 'godot::Quaternion' to 'const godot::Vector3 &'
note: Reason: cannot convert from 'godot::Quaternion' to 'const godot::Vector3'
note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
note: while trying to match the argument list '(godot::Quaternion)' 

I am still a student, and it is definitely possible that I have made a mistake or misunderstood how to use these data types, so any help is appreciated! This is my first time doing a Bug Report, so I apologize if I haven't done everything 100% correctly. :)

Steps to reproduce

I have tried a few variations, but the simplest is to add the one-liner to any function. The headers used are included as well.

(using namespace godot if you are not already)

#include <godot_cpp/variant/vector3.hpp>
#include <godot_cpp/variant/quaternion.hpp>

...

Vector3 example_vector = Quaternion(Vector3(1, 0, 0), 1.0) * Vector3(1, 0, 0);

Minimal reproduction project

N/A

AThousandShips commented 4 months ago

You need to use xform

AThousandShips commented 4 months ago

This is to match the behaviour in C++, see https://github.com/godotengine/godot-cpp/issues/1222#issuecomment-1686613171

Thank you for reporting

samanthabeilman commented 4 months ago

This is to match the behaviour in C++, see #1222 (comment)

Thank you for reporting

Thank you for your time and the reference! Have a great day. :)