summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/global_constants.cpp29
-rw-r--r--core/math/camera_matrix.cpp7
-rw-r--r--core/math/camera_matrix.h2
-rw-r--r--core/math/quat.h39
-rw-r--r--core/math/vector3.h16
-rw-r--r--core/object.cpp10
-rw-r--r--core/object.h2
-rw-r--r--core/variant_call.cpp5
-rw-r--r--core/variant_op.cpp34
9 files changed, 126 insertions, 18 deletions
diff --git a/core/global_constants.cpp b/core/global_constants.cpp
index efa72b6547..ae4abc627d 100644
--- a/core/global_constants.cpp
+++ b/core/global_constants.cpp
@@ -445,15 +445,26 @@ static _GlobalConstant _global_constants[]={
BIND_GLOBAL_CONSTANT( ERR_BUG ), ///< a bug in the software certainly happened ), due to a double check failing or unexpected behavior.
BIND_GLOBAL_CONSTANT( ERR_WTF ),
- BIND_GLOBAL_CONSTANT( PROPERTY_HINT_NONE ),
- BIND_GLOBAL_CONSTANT( PROPERTY_HINT_RANGE ),
- BIND_GLOBAL_CONSTANT( PROPERTY_HINT_EXP_RANGE ),
- BIND_GLOBAL_CONSTANT( PROPERTY_HINT_ENUM ),
- BIND_GLOBAL_CONSTANT( PROPERTY_HINT_LENGTH ),
- BIND_GLOBAL_CONSTANT( PROPERTY_HINT_FLAGS ),
- BIND_GLOBAL_CONSTANT( PROPERTY_HINT_FILE ),
- BIND_GLOBAL_CONSTANT( PROPERTY_HINT_DIR ),
- BIND_GLOBAL_CONSTANT( PROPERTY_HINT_RESOURCE_TYPE ),
+
+ BIND_GLOBAL_CONSTANT( PROPERTY_HINT_NONE ),
+ BIND_GLOBAL_CONSTANT( PROPERTY_HINT_RANGE ),
+ BIND_GLOBAL_CONSTANT( PROPERTY_HINT_EXP_RANGE ),
+ BIND_GLOBAL_CONSTANT( PROPERTY_HINT_ENUM ),
+ BIND_GLOBAL_CONSTANT( PROPERTY_HINT_EXP_EASING ),
+ BIND_GLOBAL_CONSTANT( PROPERTY_HINT_LENGTH ),
+ BIND_GLOBAL_CONSTANT( PROPERTY_HINT_KEY_ACCEL ),
+ BIND_GLOBAL_CONSTANT( PROPERTY_HINT_FLAGS ),
+ BIND_GLOBAL_CONSTANT( PROPERTY_HINT_ALL_FLAGS ),
+ BIND_GLOBAL_CONSTANT( PROPERTY_HINT_FILE ),
+ BIND_GLOBAL_CONSTANT( PROPERTY_HINT_DIR ),
+ BIND_GLOBAL_CONSTANT( PROPERTY_HINT_GLOBAL_FILE ),
+ BIND_GLOBAL_CONSTANT( PROPERTY_HINT_GLOBAL_DIR ),
+ BIND_GLOBAL_CONSTANT( PROPERTY_HINT_RESOURCE_TYPE ),
+ BIND_GLOBAL_CONSTANT( PROPERTY_HINT_MULTILINE_TEXT ),
+ BIND_GLOBAL_CONSTANT( PROPERTY_HINT_COLOR_NO_ALPHA ),
+ BIND_GLOBAL_CONSTANT( PROPERTY_HINT_IMAGE_COMPRESS_LOSSY ),
+ BIND_GLOBAL_CONSTANT( PROPERTY_HINT_IMAGE_COMPRESS_LOSSLESS ),
+
BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_STORAGE ),
BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_STORAGE ),
diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp
index 52d77b6ebc..a60dea7379 100644
--- a/core/math/camera_matrix.cpp
+++ b/core/math/camera_matrix.cpp
@@ -67,9 +67,10 @@ Plane CameraMatrix::xform4(const Plane& p_vec4) {
void CameraMatrix::set_perspective(float p_fovy_degrees, float p_aspect, float p_z_near, float p_z_far,bool p_flip_fov) {
- if (p_flip_fov)
- p_fovy_degrees=get_fovy(p_fovy_degrees,p_aspect);
+ if (p_flip_fov) {
+ p_fovy_degrees=get_fovy(p_fovy_degrees,1.0/p_aspect);
+ }
float sine, cotangent, deltaZ;
float radians = p_fovy_degrees / 2.0 * Math_PI / 180.0;
@@ -110,7 +111,7 @@ void CameraMatrix::set_orthogonal(float p_left, float p_right, float p_bottom, f
void CameraMatrix::set_orthogonal(float p_size, float p_aspect, float p_znear, float p_zfar,bool p_flip_fov) {
- if (p_flip_fov) {
+ if (!p_flip_fov) {
p_size*=p_aspect;
}
diff --git a/core/math/camera_matrix.h b/core/math/camera_matrix.h
index 6ffcb0ed0b..767236ea04 100644
--- a/core/math/camera_matrix.h
+++ b/core/math/camera_matrix.h
@@ -60,7 +60,7 @@ struct CameraMatrix {
static float get_fovy(float p_fovx,float p_aspect) {
- return Math::atan(p_aspect * Math::tan(p_fovx * 0.5))*2.0;
+ return Math::rad2deg(Math::atan(p_aspect * Math::tan(Math::deg2rad(p_fovx) * 0.5))*2.0);
}
float get_z_far() const;
diff --git a/core/math/quat.h b/core/math/quat.h
index d326073033..04901116b8 100644
--- a/core/math/quat.h
+++ b/core/math/quat.h
@@ -64,6 +64,22 @@ public:
Quat operator*(const Quat& q) const;
+
+ Quat operator*(const Vector3& v) const
+ {
+ return Quat( w * v.x + y * v.z - z * v.y,
+ w * v.y + z * v.x - x * v.z,
+ w * v.z + x * v.y - y * v.x,
+ -x * v.x - y * v.y - z * v.z);
+ }
+
+ _FORCE_INLINE_ Vector3 xform(const Vector3& v) {
+
+ Quat q = *this * v;
+ q *= this->inverse();
+ return Vector3(q.x,q.y,q.z);
+ }
+
_FORCE_INLINE_ void operator+=(const Quat& q);
_FORCE_INLINE_ void operator-=(const Quat& q);
_FORCE_INLINE_ void operator*=(const real_t& s);
@@ -87,6 +103,29 @@ public:
x=p_x; y=p_y; z=p_z; w=p_w;
}
Quat(const Vector3& axis, const real_t& angle);
+
+ Quat(const Vector3& v0, const Vector3& v1) // shortest arc
+ {
+ Vector3 c = v0.cross(v1);
+ real_t d = v0.dot(v1);
+
+ if (d < -1.0 + CMP_EPSILON) {
+ x=0;
+ y=1;
+ z=0;
+ w=0;
+ } else {
+
+ real_t s = Math::sqrt((1.0f + d) * 2.0f);
+ real_t rs = 1.0f / s;
+
+ x=c.x*rs;
+ y=c.y*rs;
+ z=c.z*rs;
+ w=s * 0.5;
+ }
+ }
+
inline Quat() {x=y=z=0; w=1; }
diff --git a/core/math/vector3.h b/core/math/vector3.h
index 959f7cd0a8..d2f2408829 100644
--- a/core/math/vector3.h
+++ b/core/math/vector3.h
@@ -111,6 +111,12 @@ struct Vector3 {
_FORCE_INLINE_ real_t distance_to(const Vector3& p_b) const;
_FORCE_INLINE_ real_t distance_squared_to(const Vector3& p_b) const;
+
+
+ _FORCE_INLINE_ Vector3 slide(const Vector3& p_vec) const;
+ _FORCE_INLINE_ Vector3 reflect(const Vector3& p_vec) const;
+
+
/* Operators */
_FORCE_INLINE_ Vector3& operator+=(const Vector3& p_v);
@@ -368,6 +374,16 @@ void Vector3::zero() {
x=y=z=0;
}
+Vector3 Vector3::slide(const Vector3& p_vec) const {
+
+ return p_vec - *this * this->dot(p_vec);
+}
+Vector3 Vector3::reflect(const Vector3& p_vec) const {
+
+ return p_vec - *this * this->dot(p_vec) * 2.0;
+
+}
+
#endif
#endif // VECTOR3_H
diff --git a/core/object.cpp b/core/object.cpp
index b40f4ec151..8a844577a8 100644
--- a/core/object.cpp
+++ b/core/object.cpp
@@ -1286,16 +1286,16 @@ void Object::get_signal_connection_list(const StringName& p_signal,List<Connecti
}
-void Object::connect(const StringName& p_signal, Object *p_to_object, const StringName& p_to_method,const Vector<Variant>& p_binds,uint32_t p_flags) {
+Error Object::connect(const StringName& p_signal, Object *p_to_object, const StringName& p_to_method,const Vector<Variant>& p_binds,uint32_t p_flags) {
- ERR_FAIL_NULL(p_to_object);
+ ERR_FAIL_NULL_V(p_to_object,ERR_INVALID_PARAMETER);
Signal *s = signal_map.getptr(p_signal);
if (!s) {
bool signal_is_valid = ObjectTypeDB::has_signal(get_type_name(),p_signal);
if (!signal_is_valid) {
ERR_EXPLAIN("Attempt to connect to unexisting signal: "+p_signal);
- ERR_FAIL_COND(!signal_is_valid);
+ ERR_FAIL_COND_V(!signal_is_valid,ERR_INVALID_PARAMETER);
}
signal_map[p_signal]=Signal();
s=&signal_map[p_signal];
@@ -1304,7 +1304,7 @@ void Object::connect(const StringName& p_signal, Object *p_to_object, const Stri
Signal::Target target(p_to_object->get_instance_ID(),p_to_method);
if (s->slot_map.has(target)) {
ERR_EXPLAIN("Signal '"+p_signal+"'' already connected to given method '"+p_to_method+"' in that object.");
- ERR_FAIL_COND(s->slot_map.has(target));
+ ERR_FAIL_COND_V(s->slot_map.has(target),ERR_INVALID_PARAMETER);
}
Signal::Slot slot;
@@ -1319,6 +1319,8 @@ void Object::connect(const StringName& p_signal, Object *p_to_object, const Stri
slot.conn=conn;
slot.cE=p_to_object->connections.push_back(conn);
s->slot_map[target]=slot;
+
+ return OK;
}
bool Object::is_connected(const StringName& p_signal, Object *p_to_object, const StringName& p_to_method) const {
diff --git a/core/object.h b/core/object.h
index 6290f9d64b..8e0164b13b 100644
--- a/core/object.h
+++ b/core/object.h
@@ -571,7 +571,7 @@ public:
void get_signal_list(List<MethodInfo> *p_signals ) const;
void get_signal_connection_list(const StringName& p_signal,List<Connection> *p_connections) const;
- void connect(const StringName& p_signal, Object *p_to_object, const StringName& p_to_method,const Vector<Variant>& p_binds=Vector<Variant>(),uint32_t p_flags=0);
+ Error connect(const StringName& p_signal, Object *p_to_object, const StringName& p_to_method,const Vector<Variant>& p_binds=Vector<Variant>(),uint32_t p_flags=0);
void disconnect(const StringName& p_signal, Object *p_to_object, const StringName& p_to_method);
bool is_connected(const StringName& p_signal, Object *p_to_object, const StringName& p_to_method) const;
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index 2697e6f7a7..8fbccc87ae 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -331,6 +331,9 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
VCALL_LOCALMEM0R(Vector3, abs);
VCALL_LOCALMEM1R(Vector3, distance_to);
VCALL_LOCALMEM1R(Vector3, distance_squared_to);
+ VCALL_LOCALMEM1R(Vector3, slide);
+ VCALL_LOCALMEM1R(Vector3, reflect);
+
VCALL_LOCALMEM0R(Plane,normalized);
VCALL_LOCALMEM0R(Plane,center);
@@ -1236,6 +1239,8 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl
ADDFUNC0(VECTOR3,VECTOR3,Vector3,abs,varray());
ADDFUNC1(VECTOR3,REAL,Vector3,distance_to,VECTOR3,"b",varray());
ADDFUNC1(VECTOR3,REAL,Vector3,distance_squared_to,VECTOR3,"b",varray());
+ ADDFUNC1(VECTOR3,VECTOR3,Vector3,slide,VECTOR3,"by",varray());
+ ADDFUNC1(VECTOR3,VECTOR3,Vector3,reflect,VECTOR3,"by",varray());
ADDFUNC0(PLANE,PLANE,Plane,normalized,varray());
ADDFUNC0(PLANE,VECTOR3,Plane,center,varray());
diff --git a/core/variant_op.cpp b/core/variant_op.cpp
index 6c2667c7e9..9c489c5ef2 100644
--- a/core/variant_op.cpp
+++ b/core/variant_op.cpp
@@ -1145,6 +1145,7 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid)
if (p_value.type!=Variant::VECTOR3)
return;
+
if (p_index.get_type()==Variant::STRING) {
//scalar name
@@ -1181,6 +1182,24 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid)
v->set_axis(index,p_value);
return;
}
+ } else if (p_index.get_type()==Variant::STRING) {
+
+ const String *str=reinterpret_cast<const String*>(p_index._data._mem);
+ Matrix3 *v=_data._matrix3;
+
+ if (*str=="x") {
+ valid=true;
+ v->set_axis(0,p_value);
+ return;
+ } else if (*str=="y" ) {
+ valid=true;
+ v->set_axis(1,p_value);
+ return;
+ } else if (*str=="z" ) {
+ valid=true;
+ v->set_axis(2,p_value);
+ return;
+ }
}
} break;
@@ -2021,6 +2040,21 @@ Variant Variant::get(const Variant& p_index, bool *r_valid) const {
valid=true;
return v->get_axis(index);
}
+ } else if (p_index.get_type()==Variant::STRING) {
+
+ const String *str=reinterpret_cast<const String*>(p_index._data._mem);
+ const Matrix3 *v=_data._matrix3;
+
+ if (*str=="x") {
+ valid=true;
+ return v->get_axis(0);
+ } else if (*str=="y" ) {
+ valid=true;
+ return v->get_axis(1);
+ } else if (*str=="z" ) {
+ valid=true;
+ return v->get_axis(2);
+ }
}
} break;