diff options
Changes in BulletXPlugin: Added new class BulletXActor class inherits from PhysicsActor and it's the ancestor for BulletXCharacter and BulletXPrim.
Diffstat (limited to 'OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs | 601 |
1 files changed, 312 insertions, 289 deletions
diff --git a/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs b/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs index 8b05295..6960f4e 100644 --- a/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs +++ b/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs | |||
@@ -633,35 +633,227 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
633 | } | 633 | } |
634 | 634 | ||
635 | /// <summary> | 635 | /// <summary> |
636 | /// PhysicsActor Character Class for BulletX | 636 | /// Generic Physics Actor for BulletX inherit from PhysicActor |
637 | /// </summary> | 637 | /// </summary> |
638 | public class BulletXCharacter : PhysicsActor | 638 | public class BulletXActor : PhysicsActor |
639 | { | 639 | { |
640 | private PhysicsVector _position; | 640 | protected bool flying = false; |
641 | private PhysicsVector _velocity; | 641 | protected bool _physical = true; |
642 | private PhysicsVector _size; | 642 | protected PhysicsVector _position; |
643 | private PhysicsVector _acceleration; | 643 | protected PhysicsVector _velocity; |
644 | private AxiomQuaternion _orientation; | 644 | protected PhysicsVector _size; |
645 | private bool flying; | 645 | protected PhysicsVector _acceleration; |
646 | private bool iscolliding = false; | 646 | protected AxiomQuaternion _orientation; |
647 | private RigidBody rigidBody; | 647 | protected RigidBody rigidBody; |
648 | private Boolean iscolliding = false; | ||
649 | |||
650 | public BulletXActor() | ||
651 | { | ||
652 | } | ||
653 | |||
654 | public override PhysicsVector Position | ||
655 | { | ||
656 | get | ||
657 | { | ||
658 | return _position; | ||
659 | } | ||
660 | set | ||
661 | { | ||
662 | lock (BulletXScene.BulletXLock) | ||
663 | { | ||
664 | _position = value; | ||
665 | Translate(); | ||
666 | } | ||
667 | } | ||
668 | } | ||
669 | public override PhysicsVector Velocity | ||
670 | { | ||
671 | get | ||
672 | { | ||
673 | return _velocity; | ||
674 | } | ||
675 | set | ||
676 | { | ||
677 | lock (BulletXScene.BulletXLock) | ||
678 | { | ||
679 | //Static objects don' have linear velocity | ||
680 | if (_physical) | ||
681 | { | ||
682 | _velocity = value; | ||
683 | Speed(); | ||
684 | } | ||
685 | else | ||
686 | { | ||
687 | _velocity = new PhysicsVector(); | ||
688 | } | ||
689 | } | ||
690 | } | ||
691 | } | ||
692 | public override PhysicsVector Size | ||
693 | { | ||
694 | get | ||
695 | { | ||
696 | return _size; | ||
697 | } | ||
698 | set | ||
699 | { | ||
700 | lock (BulletXScene.BulletXLock) | ||
701 | { | ||
702 | _size = value; | ||
703 | } | ||
704 | } | ||
705 | } | ||
706 | public override PhysicsVector Acceleration | ||
707 | { | ||
708 | get | ||
709 | { | ||
710 | return _acceleration; | ||
711 | } | ||
712 | } | ||
713 | public override AxiomQuaternion Orientation | ||
714 | { | ||
715 | get | ||
716 | { | ||
717 | return _orientation; | ||
718 | } | ||
719 | set | ||
720 | { | ||
721 | lock (BulletXScene.BulletXLock) | ||
722 | { | ||
723 | _orientation = value; | ||
724 | ReOrient(); | ||
725 | } | ||
726 | } | ||
727 | } | ||
728 | public virtual float Mass | ||
729 | { get { return 0; } } | ||
730 | public RigidBody RigidBody | ||
731 | { | ||
732 | get | ||
733 | { | ||
734 | return rigidBody; | ||
735 | } | ||
736 | } | ||
737 | public MonoXnaCompactMaths.Vector3 RigidBodyPosition | ||
738 | { | ||
739 | get { return this.rigidBody.CenterOfMassPosition; } | ||
740 | } | ||
741 | public override bool Flying | ||
742 | { | ||
743 | get | ||
744 | { | ||
745 | return flying; | ||
746 | } | ||
747 | set | ||
748 | { | ||
749 | flying = value; | ||
750 | } | ||
751 | } | ||
752 | public override bool IsColliding | ||
753 | { | ||
754 | get { return iscolliding; } | ||
755 | set { iscolliding = value; } | ||
756 | } | ||
757 | /*public override bool Physical | ||
758 | { | ||
759 | get | ||
760 | { | ||
761 | return _physical; | ||
762 | } | ||
763 | set | ||
764 | { | ||
765 | _physical = value; | ||
766 | } | ||
767 | }*/ | ||
768 | public virtual void SetAcceleration(PhysicsVector accel) | ||
769 | { | ||
770 | lock (BulletXScene.BulletXLock) | ||
771 | { | ||
772 | _acceleration = accel; | ||
773 | } | ||
774 | } | ||
775 | public override bool Kinematic | ||
776 | { | ||
777 | get | ||
778 | { | ||
779 | return false; | ||
780 | } | ||
781 | set | ||
782 | { | ||
783 | |||
784 | } | ||
785 | } | ||
786 | public override void AddForce(PhysicsVector force) | ||
787 | { | ||
648 | 788 | ||
649 | public Vector3 RigidBodyPosition | 789 | } |
790 | public override void SetMomentum(PhysicsVector momentum) | ||
791 | { | ||
792 | } | ||
793 | internal virtual void ValidateHeight(float heighmapPositionValue) | ||
794 | { | ||
795 | } | ||
796 | internal virtual void UpdateKinetics() | ||
650 | { | 797 | { |
651 | get { return rigidBody.CenterOfMassPosition; } | ||
652 | } | 798 | } |
653 | 799 | ||
800 | #region Methods for updating values of RigidBody | ||
801 | internal protected void Translate() | ||
802 | { | ||
803 | Translate(this._position); | ||
804 | } | ||
805 | internal protected void Translate(PhysicsVector _newPos) | ||
806 | { | ||
807 | MonoXnaCompactMaths.Vector3 _translation; | ||
808 | _translation = BulletXMaths.PhysicsVectorToXnaVector3(_newPos) - rigidBody.CenterOfMassPosition; | ||
809 | rigidBody.Translate(_translation); | ||
810 | } | ||
811 | internal protected void Speed() | ||
812 | { | ||
813 | Speed(this._velocity); | ||
814 | } | ||
815 | internal protected void Speed(PhysicsVector _newSpeed) | ||
816 | { | ||
817 | MonoXnaCompactMaths.Vector3 _speed; | ||
818 | _speed = BulletXMaths.PhysicsVectorToXnaVector3(_newSpeed); | ||
819 | rigidBody.LinearVelocity = _speed; | ||
820 | } | ||
821 | internal protected void ReOrient() | ||
822 | { | ||
823 | ReOrient(this._orientation); | ||
824 | } | ||
825 | internal protected void ReOrient(AxiomQuaternion _newOrient) | ||
826 | { | ||
827 | MonoXnaCompactMaths.Quaternion _newOrientation; | ||
828 | _newOrientation = BulletXMaths.AxiomQuaternionToXnaQuaternion(_newOrient); | ||
829 | Matrix _comTransform = rigidBody.CenterOfMassTransform; | ||
830 | BulletXMaths.SetRotation(ref _comTransform, _newOrientation); | ||
831 | rigidBody.CenterOfMassTransform = _comTransform; | ||
832 | } | ||
833 | internal protected void ReSize() | ||
834 | { | ||
835 | ReSize(this._size); | ||
836 | } | ||
837 | internal protected virtual void ReSize(PhysicsVector _newSize) | ||
838 | { | ||
839 | } | ||
840 | #endregion | ||
841 | } | ||
842 | |||
843 | /// <summary> | ||
844 | /// PhysicsActor Character Class for BulletX | ||
845 | /// </summary> | ||
846 | public class BulletXCharacter : BulletXActor | ||
847 | { | ||
654 | public BulletXCharacter(BulletXScene parent_scene, PhysicsVector pos) | 848 | public BulletXCharacter(BulletXScene parent_scene, PhysicsVector pos) |
655 | : this("", parent_scene, pos) | 849 | : this("", parent_scene, pos) |
656 | { | 850 | { |
657 | } | 851 | } |
658 | |||
659 | public BulletXCharacter(String avName, BulletXScene parent_scene, PhysicsVector pos) | 852 | public BulletXCharacter(String avName, BulletXScene parent_scene, PhysicsVector pos) |
660 | : this(avName, parent_scene, pos, new PhysicsVector(), new PhysicsVector(), new PhysicsVector(), | 853 | : this(avName, parent_scene, pos, new PhysicsVector(), new PhysicsVector(), new PhysicsVector(), |
661 | AxiomQuaternion.Identity) | 854 | AxiomQuaternion.Identity) |
662 | { | 855 | { |
663 | } | 856 | } |
664 | |||
665 | public BulletXCharacter(String avName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector velocity, | 857 | public BulletXCharacter(String avName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector velocity, |
666 | PhysicsVector size, PhysicsVector acceleration, AxiomQuaternion orientation) | 858 | PhysicsVector size, PhysicsVector acceleration, AxiomQuaternion orientation) |
667 | { | 859 | { |
@@ -711,95 +903,55 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
711 | 903 | ||
712 | public override PhysicsVector Position | 904 | public override PhysicsVector Position |
713 | { | 905 | { |
714 | get { return _position; } | 906 | get { return base.Position; } |
715 | set | 907 | set { base.Position = value; } |
716 | { | ||
717 | lock (BulletXScene.BulletXLock) | ||
718 | { | ||
719 | _position = value; | ||
720 | Translate(); | ||
721 | } | ||
722 | } | ||
723 | } | 908 | } |
724 | |||
725 | public override PhysicsVector Velocity | 909 | public override PhysicsVector Velocity |
726 | { | 910 | { |
727 | get { return _velocity; } | 911 | get { return base.Velocity; } |
728 | set | 912 | set { base.Velocity = value; } |
729 | { | ||
730 | lock (BulletXScene.BulletXLock) | ||
731 | { | ||
732 | _velocity = value; | ||
733 | Speed(); | ||
734 | } | ||
735 | } | ||
736 | } | 913 | } |
737 | |||
738 | public override PhysicsVector Size | 914 | public override PhysicsVector Size |
739 | { | 915 | { |
740 | get { return _size; } | 916 | get { return base.Size; } |
741 | set | 917 | set { base.Size = value; } |
742 | { | ||
743 | lock (BulletXScene.BulletXLock) | ||
744 | { | ||
745 | _size = value; | ||
746 | } | ||
747 | } | ||
748 | } | 918 | } |
749 | |||
750 | public override PhysicsVector Acceleration | 919 | public override PhysicsVector Acceleration |
751 | { | 920 | { |
752 | get { return _acceleration; } | 921 | get { return base.Acceleration; } |
753 | } | 922 | } |
754 | |||
755 | public override AxiomQuaternion Orientation | 923 | public override AxiomQuaternion Orientation |
756 | { | 924 | { |
757 | get { return _orientation; } | 925 | get { return base.Orientation; } |
758 | set | 926 | set { base.Orientation = value; } |
759 | { | ||
760 | lock (BulletXScene.BulletXLock) | ||
761 | { | ||
762 | _orientation = value; | ||
763 | } | ||
764 | } | ||
765 | } | ||
766 | |||
767 | public RigidBody RigidBody | ||
768 | { | ||
769 | get { return rigidBody; } | ||
770 | } | 927 | } |
771 | |||
772 | public override bool Flying | 928 | public override bool Flying |
773 | { | 929 | { |
774 | get { return flying; } | 930 | get { return base.Flying; } |
775 | set { flying = value; } | 931 | set { base.Flying = value; } |
776 | } | 932 | } |
777 | public override bool IsColliding | 933 | public override bool IsColliding |
778 | { | 934 | { |
779 | get { return iscolliding; } | 935 | get { return base.IsColliding; } |
780 | set { iscolliding = value; } | 936 | set { base.IsColliding = value; } |
781 | } | 937 | } |
782 | 938 | public override bool Kinematic | |
783 | public void SetAcceleration(PhysicsVector accel) | ||
784 | { | 939 | { |
785 | lock (BulletXScene.BulletXLock) | 940 | get { return base.Kinematic; } |
786 | { | 941 | set { base.Kinematic = value; } |
787 | _acceleration = accel; | ||
788 | } | ||
789 | } | 942 | } |
790 | 943 | ||
791 | public override bool Kinematic | 944 | public override void SetAcceleration(PhysicsVector accel) |
792 | { | 945 | { |
793 | get { return false; } | 946 | base.SetAcceleration(accel); |
794 | set { } | ||
795 | } | 947 | } |
796 | |||
797 | public override void AddForce(PhysicsVector force) | 948 | public override void AddForce(PhysicsVector force) |
798 | { | 949 | { |
950 | base.AddForce(force); | ||
799 | } | 951 | } |
800 | |||
801 | public override void SetMomentum(PhysicsVector momentum) | 952 | public override void SetMomentum(PhysicsVector momentum) |
802 | { | 953 | { |
954 | base.SetMomentum(momentum); | ||
803 | } | 955 | } |
804 | 956 | ||
805 | internal void Move(float timeStep) | 957 | internal void Move(float timeStep) |
@@ -835,9 +987,8 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
835 | } | 987 | } |
836 | rigidBody.LinearVelocity = vec; | 988 | rigidBody.LinearVelocity = vec; |
837 | } | 989 | } |
838 | |||
839 | //This validation is very basic | 990 | //This validation is very basic |
840 | internal void ValidateHeight(float heighmapPositionValue) | 991 | internal override void ValidateHeight(float heighmapPositionValue) |
841 | { | 992 | { |
842 | if (rigidBody.CenterOfMassPosition.Z < heighmapPositionValue + _size.Z/2.0f) | 993 | if (rigidBody.CenterOfMassPosition.Z < heighmapPositionValue + _size.Z/2.0f) |
843 | { | 994 | { |
@@ -850,93 +1001,30 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
850 | Speed(new PhysicsVector(rigidBody.LinearVelocity.X, rigidBody.LinearVelocity.Y, 0.0f)); | 1001 | Speed(new PhysicsVector(rigidBody.LinearVelocity.X, rigidBody.LinearVelocity.Y, 0.0f)); |
851 | } | 1002 | } |
852 | } | 1003 | } |
853 | 1004 | internal override void UpdateKinetics() | |
854 | internal void UpdateKinetics() | ||
855 | { | 1005 | { |
856 | _position = BulletXMaths.XnaVector3ToPhysicsVector(rigidBody.CenterOfMassPosition); | 1006 | _position = BulletXMaths.XnaVector3ToPhysicsVector(rigidBody.CenterOfMassPosition); |
857 | _velocity = BulletXMaths.XnaVector3ToPhysicsVector(rigidBody.LinearVelocity); | 1007 | _velocity = BulletXMaths.XnaVector3ToPhysicsVector(rigidBody.LinearVelocity); |
858 | //Orientation it seems that it will be the default. | 1008 | //Orientation it seems that it will be the default. |
859 | ReOrient(); | 1009 | ReOrient(); |
860 | } | 1010 | } |
861 | |||
862 | #region Methods for updating values of RigidBody | ||
863 | |||
864 | private void Translate() | ||
865 | { | ||
866 | Translate(_position); | ||
867 | } | ||
868 | |||
869 | private void Translate(PhysicsVector _newPos) | ||
870 | { | ||
871 | Vector3 _translation; | ||
872 | _translation = BulletXMaths.PhysicsVectorToXnaVector3(_newPos) - rigidBody.CenterOfMassPosition; | ||
873 | rigidBody.Translate(_translation); | ||
874 | } | ||
875 | |||
876 | private void Speed() | ||
877 | { | ||
878 | Speed(_velocity); | ||
879 | } | ||
880 | |||
881 | private void Speed(PhysicsVector _newSpeed) | ||
882 | { | ||
883 | Vector3 _speed; | ||
884 | _speed = BulletXMaths.PhysicsVectorToXnaVector3(_newSpeed); | ||
885 | rigidBody.LinearVelocity = _speed; | ||
886 | } | ||
887 | |||
888 | private void ReOrient() | ||
889 | { | ||
890 | ReOrient(_orientation); | ||
891 | } | ||
892 | |||
893 | private void ReOrient(AxiomQuaternion _newOrient) | ||
894 | { | ||
895 | Quaternion _newOrientation; | ||
896 | _newOrientation = BulletXMaths.AxiomQuaternionToXnaQuaternion(_newOrient); | ||
897 | Matrix _comTransform = rigidBody.CenterOfMassTransform; | ||
898 | BulletXMaths.SetRotation(ref _comTransform, _newOrientation); | ||
899 | rigidBody.CenterOfMassTransform = _comTransform; | ||
900 | } | ||
901 | |||
902 | #endregion | ||
903 | } | 1011 | } |
904 | 1012 | ||
905 | /// <summary> | 1013 | /// <summary> |
906 | /// PhysicsActor Prim Class for BulletX | 1014 | /// PhysicsActor Prim Class for BulletX |
907 | /// </summary> | 1015 | /// </summary> |
908 | public class BulletXPrim : PhysicsActor | 1016 | public class BulletXPrim : BulletXActor |
909 | { | 1017 | { |
910 | private PhysicsVector _position; | ||
911 | private PhysicsVector _velocity; | ||
912 | private PhysicsVector _size; | ||
913 | private PhysicsVector _acceleration; | ||
914 | private AxiomQuaternion _orientation; | ||
915 | //Density it will depends of material. | 1018 | //Density it will depends of material. |
916 | //For now all prims have the same density, all prims are made of water. Be water my friend! :D | 1019 | //For now all prims have the same density, all prims are made of water. Be water my friend! :D |
917 | private const float _density = 1000.0f; | 1020 | private const float _density = 1000.0f; |
918 | private RigidBody rigidBody; | ||
919 | private BulletXScene _parent_scene; | 1021 | private BulletXScene _parent_scene; |
920 | //_physical value will be linked with the prim object value | ||
921 | private Boolean _physical = false; | ||
922 | private Boolean iscolliding = false; | ||
923 | |||
924 | public Vector3 RigidBodyPosition | ||
925 | { | ||
926 | get { return rigidBody.CenterOfMassPosition; } | ||
927 | } | ||
928 | |||
929 | public BulletXPrim(BulletXScene parent_scene, PhysicsVector pos, PhysicsVector size, AxiomQuaternion rotation) | ||
930 | : this("", parent_scene, pos, new PhysicsVector(), size, new PhysicsVector(), rotation, null, null) | ||
931 | { | ||
932 | } | ||
933 | 1022 | ||
934 | public BulletXPrim(String primName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector size, | 1023 | public BulletXPrim(String primName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector size, |
935 | AxiomQuaternion rotation, Mesh mesh, PrimitiveBaseShape pbs) | 1024 | AxiomQuaternion rotation, Mesh mesh, PrimitiveBaseShape pbs) |
936 | : this(primName, parent_scene, pos, new PhysicsVector(), size, new PhysicsVector(), rotation, mesh, pbs) | 1025 | : this(primName, parent_scene, pos, new PhysicsVector(), size, new PhysicsVector(), rotation, mesh, pbs) |
937 | { | 1026 | { |
938 | } | 1027 | } |
939 | |||
940 | public BulletXPrim(String primName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector velocity, | 1028 | public BulletXPrim(String primName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector velocity, |
941 | PhysicsVector size, | 1029 | PhysicsVector size, |
942 | PhysicsVector aceleration, AxiomQuaternion rotation, Mesh mesh, PrimitiveBaseShape pbs) | 1030 | PhysicsVector aceleration, AxiomQuaternion rotation, Mesh mesh, PrimitiveBaseShape pbs) |
@@ -983,41 +1071,20 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
983 | 1071 | ||
984 | public override PhysicsVector Position | 1072 | public override PhysicsVector Position |
985 | { | 1073 | { |
986 | get { return _position; } | 1074 | get { return base.Position; } |
987 | set | 1075 | set { base.Position = value; } |
988 | { | ||
989 | lock (BulletXScene.BulletXLock) | ||
990 | { | ||
991 | _position = value; | ||
992 | Translate(); | ||
993 | } | ||
994 | } | ||
995 | } | 1076 | } |
996 | |||
997 | public override PhysicsVector Velocity | 1077 | public override PhysicsVector Velocity |
998 | { | 1078 | { |
999 | get { return _velocity; } | 1079 | get { return base.Velocity; } |
1000 | set | 1080 | set { base.Velocity = value; } |
1001 | { | ||
1002 | lock (BulletXScene.BulletXLock) | ||
1003 | { | ||
1004 | //Static objects don' have linear velocity | ||
1005 | if (_physical) | ||
1006 | { | ||
1007 | _velocity = value; | ||
1008 | Speed(); | ||
1009 | } | ||
1010 | else | ||
1011 | { | ||
1012 | _velocity = new PhysicsVector(); | ||
1013 | } | ||
1014 | } | ||
1015 | } | ||
1016 | } | 1081 | } |
1017 | |||
1018 | public override PhysicsVector Size | 1082 | public override PhysicsVector Size |
1019 | { | 1083 | { |
1020 | get { return _size; } | 1084 | get |
1085 | { | ||
1086 | return _size; | ||
1087 | } | ||
1021 | set | 1088 | set |
1022 | { | 1089 | { |
1023 | lock (BulletXScene.BulletXLock) | 1090 | lock (BulletXScene.BulletXLock) |
@@ -1027,87 +1094,86 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
1027 | } | 1094 | } |
1028 | } | 1095 | } |
1029 | } | 1096 | } |
1030 | |||
1031 | public override PhysicsVector Acceleration | 1097 | public override PhysicsVector Acceleration |
1032 | { | 1098 | { |
1033 | get { return _acceleration; } | 1099 | get { return base.Acceleration; } |
1034 | } | 1100 | } |
1035 | |||
1036 | public override AxiomQuaternion Orientation | 1101 | public override AxiomQuaternion Orientation |
1037 | { | 1102 | { |
1038 | get { return _orientation; } | 1103 | get { return base.Orientation; } |
1039 | set | 1104 | set { base.Orientation = value; } |
1040 | { | ||
1041 | lock (BulletXScene.BulletXLock) | ||
1042 | { | ||
1043 | _orientation = value; | ||
1044 | ReOrient(); | ||
1045 | } | ||
1046 | } | ||
1047 | } | 1105 | } |
1048 | 1106 | public override float Mass | |
1049 | public float Mass | ||
1050 | { | 1107 | { |
1051 | get | 1108 | get |
1052 | { | 1109 | { |
1053 | //For now all prims are boxes | 1110 | //For now all prims are boxes |
1054 | return (_physical ? 1 : 0)*_density*_size.X*_size.Y*_size.Z; | 1111 | return (_physical ? 1 : 0) * _density * _size.X * _size.Y * _size.Z; |
1055 | } | 1112 | } |
1056 | } | 1113 | } |
1057 | 1114 | public Boolean Physical | |
1058 | public RigidBody RigidBody | ||
1059 | { | 1115 | { |
1060 | get { return rigidBody; } | 1116 | get { return _physical; } |
1117 | set { _physical = value; } | ||
1061 | } | 1118 | } |
1062 | 1119 | /*public override bool Physical | |
1063 | public override bool Flying | ||
1064 | { | 1120 | { |
1065 | get { return false; //no flying prims for you | 1121 | get |
1122 | { | ||
1123 | return base.Physical; | ||
1124 | } | ||
1125 | set | ||
1126 | { | ||
1127 | base.Physical = value; | ||
1128 | if (value) | ||
1129 | { | ||
1130 | //--- | ||
1131 | PhysicsPluginManager.PhysicsPluginMessage("Physical - Recreate", true); | ||
1132 | //--- | ||
1133 | ReCreateRigidBody(this._size); | ||
1134 | } | ||
1135 | else | ||
1136 | { | ||
1137 | //--- | ||
1138 | PhysicsPluginManager.PhysicsPluginMessage("Physical - SetMassProps", true); | ||
1139 | //--- | ||
1140 | this.rigidBody.SetMassProps(Mass, new MonoXnaCompactMaths.Vector3()); | ||
1141 | } | ||
1066 | } | 1142 | } |
1067 | set { } | 1143 | }*/ |
1144 | public override bool Flying | ||
1145 | { | ||
1146 | get { return base.Flying; } | ||
1147 | set { base.Flying = value; } | ||
1068 | } | 1148 | } |
1069 | |||
1070 | public override bool IsColliding | 1149 | public override bool IsColliding |
1071 | { | 1150 | { |
1072 | get { return iscolliding; } | 1151 | get { return base.IsColliding; } |
1073 | set { iscolliding = value; } | 1152 | set { base.IsColliding = value; } |
1074 | } | 1153 | } |
1075 | public Boolean Physical | 1154 | public override bool Kinematic |
1076 | { | 1155 | { |
1077 | get { return _physical; } | 1156 | get { return base.Kinematic; } |
1078 | set { _physical = value; } | 1157 | set { base.Kinematic = value; } |
1079 | } | 1158 | } |
1080 | 1159 | ||
1081 | public void SetAcceleration(PhysicsVector accel) | 1160 | public override void SetAcceleration(PhysicsVector accel) |
1082 | { | 1161 | { |
1083 | lock (BulletXScene.BulletXLock) | 1162 | lock (BulletXScene.BulletXLock) |
1084 | { | 1163 | { |
1085 | _acceleration = accel; | 1164 | _acceleration = accel; |
1086 | } | 1165 | } |
1087 | } | 1166 | } |
1088 | |||
1089 | public override bool Kinematic | ||
1090 | { | ||
1091 | get | ||
1092 | { | ||
1093 | return false; | ||
1094 | //return this._prim.Kinematic; | ||
1095 | } | ||
1096 | set | ||
1097 | { | ||
1098 | //this._prim.Kinematic = value; | ||
1099 | } | ||
1100 | } | ||
1101 | |||
1102 | public override void AddForce(PhysicsVector force) | 1167 | public override void AddForce(PhysicsVector force) |
1103 | { | 1168 | { |
1169 | base.AddForce(force); | ||
1104 | } | 1170 | } |
1105 | |||
1106 | public override void SetMomentum(PhysicsVector momentum) | 1171 | public override void SetMomentum(PhysicsVector momentum) |
1107 | { | 1172 | { |
1173 | base.SetMomentum(momentum); | ||
1108 | } | 1174 | } |
1109 | 1175 | ||
1110 | internal void ValidateHeight(float heighmapPositionValue) | 1176 | internal override void ValidateHeight(float heighmapPositionValue) |
1111 | { | 1177 | { |
1112 | if (rigidBody.CenterOfMassPosition.Z < heighmapPositionValue + _size.Z/2.0f) | 1178 | if (rigidBody.CenterOfMassPosition.Z < heighmapPositionValue + _size.Z/2.0f) |
1113 | { | 1179 | { |
@@ -1122,8 +1188,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
1122 | Speed(new PhysicsVector(rigidBody.LinearVelocity.X, rigidBody.LinearVelocity.Y, 0.0f)); | 1188 | Speed(new PhysicsVector(rigidBody.LinearVelocity.X, rigidBody.LinearVelocity.Y, 0.0f)); |
1123 | } | 1189 | } |
1124 | } | 1190 | } |
1125 | 1191 | internal override void UpdateKinetics() | |
1126 | internal void UpdateKinetics() | ||
1127 | { | 1192 | { |
1128 | if (_physical) //Updates properties. Prim updates its properties physically | 1193 | if (_physical) //Updates properties. Prim updates its properties physically |
1129 | { | 1194 | { |
@@ -1140,44 +1205,8 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
1140 | } | 1205 | } |
1141 | 1206 | ||
1142 | #region Methods for updating values of RigidBody | 1207 | #region Methods for updating values of RigidBody |
1143 | 1208 | internal protected void CreateRigidBody(BulletXScene parent_scene, PhysicsVector pos, PhysicsVector size) | |
1144 | private void Translate() | ||
1145 | { | 1209 | { |
1146 | Translate(_position); | ||
1147 | } | ||
1148 | |||
1149 | private void Translate(PhysicsVector _newPos) | ||
1150 | { | ||
1151 | Vector3 _translation; | ||
1152 | _translation = BulletXMaths.PhysicsVectorToXnaVector3(_newPos) - rigidBody.CenterOfMassPosition; | ||
1153 | rigidBody.Translate(_translation); | ||
1154 | } | ||
1155 | |||
1156 | private void Speed() | ||
1157 | { | ||
1158 | Speed(_velocity); | ||
1159 | } | ||
1160 | |||
1161 | private void Speed(PhysicsVector _newSpeed) | ||
1162 | { | ||
1163 | Vector3 _speed; | ||
1164 | _speed = BulletXMaths.PhysicsVectorToXnaVector3(_newSpeed); | ||
1165 | rigidBody.LinearVelocity = _speed; | ||
1166 | } | ||
1167 | |||
1168 | private void ReSize() | ||
1169 | { | ||
1170 | ReSize(_size); | ||
1171 | } | ||
1172 | |||
1173 | private void ReSize(PhysicsVector _newSize) | ||
1174 | { | ||
1175 | //I wonder to know how to resize with a simple instruction in BulletX. It seems that for now there isn't | ||
1176 | //so i have to do it manually. That's recreating rigidbody | ||
1177 | Vector3 _newsize; | ||
1178 | _newsize = BulletXMaths.PhysicsVectorToXnaVector3(_newSize); | ||
1179 | if ((_newsize.X == 0) || (_newsize.Y == 0) || (_newsize.Z == 0)) throw new Exception("Size 0"); | ||
1180 | |||
1181 | //For RigidBody Constructor. The next values might change | 1210 | //For RigidBody Constructor. The next values might change |
1182 | float _linearDamping = 0.0f; | 1211 | float _linearDamping = 0.0f; |
1183 | float _angularDamping = 0.0f; | 1212 | float _angularDamping = 0.0f; |
@@ -1185,54 +1214,48 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
1185 | float _restitution = 0.0f; | 1214 | float _restitution = 0.0f; |
1186 | Matrix _startTransform = Matrix.Identity; | 1215 | Matrix _startTransform = Matrix.Identity; |
1187 | Matrix _centerOfMassOffset = Matrix.Identity; | 1216 | Matrix _centerOfMassOffset = Matrix.Identity; |
1188 | RigidBody _tmpRigidBody; | 1217 | lock (BulletXScene.BulletXLock) |
1189 | _startTransform.Translation = BulletXMaths.PhysicsVectorToXnaVector3(_position); | 1218 | { |
1190 | //For now all prims are boxes | 1219 | _startTransform.Translation = BulletXMaths.PhysicsVectorToXnaVector3(pos); |
1191 | CollisionShape _collisionShape = new BoxShape(BulletXMaths.PhysicsVectorToXnaVector3(_newSize)/2.0f); | 1220 | //For now all prims are boxes |
1192 | DefaultMotionState _motionState = new DefaultMotionState(_startTransform, _centerOfMassOffset); | 1221 | CollisionShape _collisionShape = new XnaDevRu.BulletX.BoxShape(BulletXMaths.PhysicsVectorToXnaVector3(size) / 2.0f); |
1193 | Vector3 _localInertia = new Vector3(); | 1222 | DefaultMotionState _motionState = new DefaultMotionState(_startTransform, _centerOfMassOffset); |
1194 | if (_physical) _collisionShape.CalculateLocalInertia(Mass, out _localInertia); //Always when mass > 0 | 1223 | MonoXnaCompactMaths.Vector3 _localInertia = new MonoXnaCompactMaths.Vector3(); |
1195 | _tmpRigidBody = | 1224 | if (_physical) _collisionShape.CalculateLocalInertia(Mass, out _localInertia); //Always when mass > 0 |
1196 | new RigidBody(Mass, _motionState, _collisionShape, _localInertia, _linearDamping, _angularDamping, | 1225 | rigidBody = new RigidBody(Mass, _motionState, _collisionShape, _localInertia, _linearDamping, _angularDamping, _friction, _restitution); |
1197 | _friction, _restitution); | 1226 | //rigidBody.ActivationState = ActivationState.DisableDeactivation; |
1198 | //rigidBody.ActivationState = ActivationState.DisableDeactivation; | 1227 | //It's seems that there are a bug with rigidBody constructor and its CenterOfMassPosition |
1199 | //It's seems that there are a bug with rigidBody constructor and its CenterOfMassPosition | 1228 | MonoXnaCompactMaths.Vector3 _vDebugTranslation; |
1200 | Vector3 _vDebugTranslation; | 1229 | _vDebugTranslation = _startTransform.Translation - rigidBody.CenterOfMassPosition; |
1201 | _vDebugTranslation = _startTransform.Translation - rigidBody.CenterOfMassPosition; | 1230 | rigidBody.Translate(_vDebugTranslation); |
1202 | _tmpRigidBody.Translate(_vDebugTranslation); | 1231 | //--- |
1203 | //--- | 1232 | parent_scene.ddWorld.AddRigidBody(rigidBody); |
1233 | } | ||
1234 | } | ||
1235 | internal protected void ReCreateRigidBody(PhysicsVector size) | ||
1236 | { | ||
1204 | //There is a bug when trying to remove a rigidBody that is colliding with something.. | 1237 | //There is a bug when trying to remove a rigidBody that is colliding with something.. |
1205 | try | 1238 | try |
1206 | { | 1239 | { |
1207 | _parent_scene.ddWorld.RemoveRigidBody(rigidBody); | 1240 | this._parent_scene.ddWorld.RemoveRigidBody(rigidBody); |
1208 | } | 1241 | } |
1209 | catch (Exception ex) | 1242 | catch (Exception ex) |
1210 | { | 1243 | { |
1211 | _parent_scene.BulletXMessage(_parent_scene.is_ex_message + ex.Message, true); | 1244 | this._parent_scene.BulletXMessage(this._parent_scene.is_ex_message + ex.Message, true); |
1212 | rigidBody.ActivationState = ActivationState.DisableSimulation; | 1245 | rigidBody.ActivationState = ActivationState.DisableSimulation; |
1213 | _parent_scene.AddForgottenRigidBody(rigidBody); | 1246 | this._parent_scene.AddForgottenRigidBody(rigidBody); |
1214 | } | 1247 | } |
1215 | rigidBody = _tmpRigidBody; | 1248 | CreateRigidBody(this._parent_scene, this._position, size); |
1216 | _parent_scene.ddWorld.AddRigidBody(rigidBody); | 1249 | if (_physical) Speed();//Static objects don't have linear velocity |
1217 | if (_physical) Speed(); //Static objects don't have linear velocity | ||
1218 | ReOrient(); | 1250 | ReOrient(); |
1219 | GC.Collect(); | 1251 | GC.Collect(); |
1220 | } | 1252 | } |
1221 | 1253 | internal protected override void ReSize(PhysicsVector _newSize) | |
1222 | private void ReOrient() | ||
1223 | { | ||
1224 | ReOrient(_orientation); | ||
1225 | } | ||
1226 | |||
1227 | private void ReOrient(AxiomQuaternion _newOrient) | ||
1228 | { | 1254 | { |
1229 | Quaternion _newOrientation; | 1255 | //I wonder to know how to resize with a simple instruction in BulletX. It seems that for now there isn't |
1230 | _newOrientation = BulletXMaths.AxiomQuaternionToXnaQuaternion(_newOrient); | 1256 | //so i have to do it manually. That's recreating rigidbody |
1231 | Matrix _comTransform = rigidBody.CenterOfMassTransform; | 1257 | ReCreateRigidBody(_newSize); |
1232 | BulletXMaths.SetRotation(ref _comTransform, _newOrientation); | ||
1233 | rigidBody.CenterOfMassTransform = _comTransform; | ||
1234 | } | 1258 | } |
1235 | |||
1236 | #endregion | 1259 | #endregion |
1237 | } | 1260 | } |
1238 | 1261 | ||