diff options
Diffstat (limited to 'scene/3d')
-rw-r--r-- | scene/3d/camera.cpp | 18 | ||||
-rw-r--r-- | scene/3d/camera.h | 2 | ||||
-rw-r--r-- | scene/3d/navigation.cpp | 6 | ||||
-rw-r--r-- | scene/3d/navigation.h | 2 | ||||
-rw-r--r-- | scene/3d/spatial.cpp | 113 | ||||
-rw-r--r-- | scene/3d/spatial.h | 15 |
6 files changed, 132 insertions, 24 deletions
diff --git a/scene/3d/camera.cpp b/scene/3d/camera.cpp index 1109139180..db69182ca0 100644 --- a/scene/3d/camera.cpp +++ b/scene/3d/camera.cpp @@ -680,8 +680,6 @@ void Camera::_bind_methods() { ObjectTypeDB::bind_method( _MD("get_projection"),&Camera::get_projection ); ObjectTypeDB::bind_method( _MD("set_visible_layers","mask"),&Camera::set_visible_layers ); ObjectTypeDB::bind_method( _MD("get_visible_layers"),&Camera::get_visible_layers ); - ObjectTypeDB::bind_method( _MD("look_at","target","up"),&Camera::look_at ); - ObjectTypeDB::bind_method( _MD("look_at_from_pos","pos","target","up"),&Camera::look_at_from_pos ); ObjectTypeDB::bind_method(_MD("set_environment","env:Environment"),&Camera::set_environment); ObjectTypeDB::bind_method(_MD("get_environment:Environment"),&Camera::get_environment); ObjectTypeDB::bind_method(_MD("set_keep_aspect_mode","mode"),&Camera::set_keep_aspect_mode); @@ -752,22 +750,6 @@ Vector<Plane> Camera::get_frustum() const { -void Camera::look_at(const Vector3& p_target, const Vector3& p_up_normal) { - - Transform lookat; - lookat.origin=get_camera_transform().origin; - lookat=lookat.looking_at(p_target,p_up_normal); - set_global_transform(lookat); -} - -void Camera::look_at_from_pos(const Vector3& p_pos,const Vector3& p_target, const Vector3& p_up_normal) { - - Transform lookat; - lookat.origin=p_pos; - lookat=lookat.looking_at(p_target,p_up_normal); - set_global_transform(lookat); - -} void Camera::set_v_offset(float p_offset) { diff --git a/scene/3d/camera.h b/scene/3d/camera.h index 950688dfda..de03282021 100644 --- a/scene/3d/camera.h +++ b/scene/3d/camera.h @@ -139,8 +139,6 @@ public: void set_keep_aspect_mode(KeepAspect p_aspect); KeepAspect get_keep_aspect_mode() const; - void look_at(const Vector3& p_target, const Vector3& p_up_normal); - void look_at_from_pos(const Vector3& p_pos,const Vector3& p_target, const Vector3& p_up_normal); void set_v_offset(float p_offset); float get_v_offset() const; diff --git a/scene/3d/navigation.cpp b/scene/3d/navigation.cpp index ce002fb44b..6612d6bf12 100644 --- a/scene/3d/navigation.cpp +++ b/scene/3d/navigation.cpp @@ -490,10 +490,10 @@ Vector<Vector3> Navigation::get_simple_path(const Vector3& p_start, const Vector } -Vector3 Navigation::get_closest_point_to_segment(const Vector3& p_from,const Vector3& p_to) { +Vector3 Navigation::get_closest_point_to_segment(const Vector3& p_from,const Vector3& p_to,const bool& p_use_collision) { - bool use_collision=false; + bool use_collision=p_use_collision; Vector3 closest_point; float closest_point_d=1e20; NavMesh *closest_navmesh=NULL; @@ -633,7 +633,7 @@ void Navigation::_bind_methods() { ObjectTypeDB::bind_method(_MD("navmesh_remove","id"),&Navigation::navmesh_remove); ObjectTypeDB::bind_method(_MD("get_simple_path","start","end","optimize"),&Navigation::get_simple_path,DEFVAL(true)); - ObjectTypeDB::bind_method(_MD("get_closest_point_to_segment","start","end"),&Navigation::get_closest_point_to_segment); + ObjectTypeDB::bind_method(_MD("get_closest_point_to_segment","start","end","use_collision"),&Navigation::get_closest_point_to_segment,DEFVAL(false)); ObjectTypeDB::bind_method(_MD("get_closest_point","to_point"),&Navigation::get_closest_point); ObjectTypeDB::bind_method(_MD("get_closest_point_normal","to_point"),&Navigation::get_closest_point_normal); diff --git a/scene/3d/navigation.h b/scene/3d/navigation.h index 69d48531a7..19977c3110 100644 --- a/scene/3d/navigation.h +++ b/scene/3d/navigation.h @@ -135,7 +135,7 @@ public: void navmesh_remove(int p_id); Vector<Vector3> get_simple_path(const Vector3& p_start, const Vector3& p_end,bool p_optimize=true); - Vector3 get_closest_point_to_segment(const Vector3& p_from,const Vector3& p_to); + Vector3 get_closest_point_to_segment(const Vector3& p_from,const Vector3& p_to,const bool& p_use_collision=false); Vector3 get_closest_point(const Vector3& p_point); Vector3 get_closest_point_normal(const Vector3& p_point); diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp index a5b009823c..6e11855543 100644 --- a/scene/3d/spatial.cpp +++ b/scene/3d/spatial.cpp @@ -593,6 +593,97 @@ bool Spatial::_is_visible_() const { return !is_hidden(); } +void Spatial::rotate(const Vector3& p_normal,float p_radians) { + + Transform t =get_transform(); + t.basis.rotate(p_normal,p_radians); + set_transform(t); +} + +void Spatial::rotate_x(float p_radians) { + + Transform t =get_transform(); + t.basis.rotate(Vector3(1,0,0),p_radians); + set_transform(t); + +} + +void Spatial::rotate_y(float p_radians){ + + Transform t =get_transform(); + t.basis.rotate(Vector3(0,1,0),p_radians); + set_transform(t); + +} +void Spatial::rotate_z(float p_radians){ + + Transform t =get_transform(); + t.basis.rotate(Vector3(0,0,1),p_radians); + set_transform(t); + +} + +void Spatial::translate(const Vector3& p_offset){ + + Transform t =get_transform(); + t.origin+=p_offset; + set_transform(t); + +} +void Spatial::scale(const Vector3& p_ratio){ + + Transform t =get_transform(); + t.basis.scale(p_ratio); + set_transform(t); + +} +void Spatial::global_rotate(const Vector3& p_normal,float p_radians){ + + Matrix3 rotation(p_normal,p_radians); + Transform t = get_global_transform(); + t.basis= rotation * t.basis; + set_global_transform(t); + +} +void Spatial::global_translate(const Vector3& p_offset){ + Transform t = get_global_transform(); + t.origin+=p_offset; + set_global_transform(t); + +} + +void Spatial::orthonormalize() { + + Transform t = get_transform(); + t.orthonormalize(); + set_transform(t); + +} + +void Spatial::set_identity() { + + set_transform(Transform()); + +} + + +void Spatial::look_at(const Vector3& p_target, const Vector3& p_up_normal) { + + Transform lookat; + lookat.origin=get_global_transform().origin; + lookat=lookat.looking_at(p_target,p_up_normal); + set_global_transform(lookat); +} + +void Spatial::look_at_from_pos(const Vector3& p_pos,const Vector3& p_target, const Vector3& p_up_normal) { + + Transform lookat; + lookat.origin=p_pos; + lookat=lookat.looking_at(p_target,p_up_normal); + set_global_transform(lookat); + +} + void Spatial::_bind_methods() { @@ -633,6 +724,28 @@ void Spatial::_bind_methods() { ObjectTypeDB::bind_method(_MD("_set_visible_"), &Spatial::_set_visible_); ObjectTypeDB::bind_method(_MD("_is_visible_"), &Spatial::_is_visible_); + void rotate(const Vector3& p_normal,float p_radians); + void rotate_x(float p_radians); + void rotate_y(float p_radians); + void rotate_z(float p_radians); + void translate(const Vector3& p_offset); + void scale(const Vector3& p_ratio); + void global_rotate(const Vector3& p_normal,float p_radians); + void global_translate(const Vector3& p_offset); + + ObjectTypeDB::bind_method( _MD("rotate","normal","radians"),&Spatial::rotate ); + ObjectTypeDB::bind_method( _MD("global_rotate","normal","radians"),&Spatial::global_rotate ); + ObjectTypeDB::bind_method( _MD("rotate_x","radians"),&Spatial::rotate_x ); + ObjectTypeDB::bind_method( _MD("rotate_y","radians"),&Spatial::rotate_y ); + ObjectTypeDB::bind_method( _MD("rotate_z","radians"),&Spatial::rotate_z ); + ObjectTypeDB::bind_method( _MD("translate","offset"),&Spatial::translate ); + ObjectTypeDB::bind_method( _MD("global_translate","offset"),&Spatial::global_translate ); + ObjectTypeDB::bind_method( _MD("orthonormalize"),&Spatial::orthonormalize ); + ObjectTypeDB::bind_method( _MD("set_identity"),&Spatial::set_identity ); + + ObjectTypeDB::bind_method( _MD("look_at","target","up"),&Spatial::look_at ); + ObjectTypeDB::bind_method( _MD("look_at_from_pos","pos","target","up"),&Spatial::look_at_from_pos ); + BIND_CONSTANT( NOTIFICATION_TRANSFORM_CHANGED ); BIND_CONSTANT( NOTIFICATION_ENTER_WORLD ); BIND_CONSTANT( NOTIFICATION_EXIT_WORLD ); diff --git a/scene/3d/spatial.h b/scene/3d/spatial.h index 49ecf5779b..f2cde8f1e6 100644 --- a/scene/3d/spatial.h +++ b/scene/3d/spatial.h @@ -167,6 +167,21 @@ public: Transform get_relative_transform(const Node *p_parent) const; + void rotate(const Vector3& p_normal,float p_radians); + void rotate_x(float p_radians); + void rotate_y(float p_radians); + void rotate_z(float p_radians); + void translate(const Vector3& p_offset); + void scale(const Vector3& p_ratio); + void global_rotate(const Vector3& p_normal,float p_radians); + void global_translate(const Vector3& p_offset); + + void look_at(const Vector3& p_target, const Vector3& p_up_normal); + void look_at_from_pos(const Vector3& p_pos,const Vector3& p_target, const Vector3& p_up_normal); + + void orthonormalize(); + void set_identity(); + void show(); void hide(); bool is_visible() const; |