예제 #1
0
        public void OnMouseMove(CollisionManager CollisionManager, Camera ActiveCamera, System.Windows.Forms.MouseEventArgs e)
        {
            var mouse = new
            {
                Near = ActiveCamera.Project(new Vector2(e.X, e.Y), depth: -0.90f),
                Far  = ActiveCamera.Project(new Vector2(e.X, e.Y), depth: 1)
            };

            Matrix4 from = Matrix4.Translation(mouse.Near);
            Matrix4 to   = Matrix4.Translation(mouse.Far);

            var d = (mouse.Far - mouse.Near).Normalized();

            using (var callback = new CollisionWorld.ClosestConvexResultCallback(mouse.Near, mouse.Far))
            {
                callback.CollisionFilterGroup = CollisionFilterGroups.StaticFilter;
                callback.CollisionFilterMask  = CollisionFilterGroups.StaticFilter;

                CollisionManager.World.ConvexSweepTest((ConvexShape)CollisionObject.CollisionShape, from, to, callback);

                var lookingNormal = (callback.ConvexToWorld - callback.ConvexFromWorld).Normalized();
                var dot           = Vector3.Dot(callback.HitNormalWorld, lookingNormal);
                Console.WriteLine(callback.HitNormalWorld);
                if (callback.HasHit)
                {
                    if (!this.Selected)
                    {
                        return;
                    }
                    var matrix    = this.WorldMatrix.ClearTranslation();
                    var collMtrix = this.Model.RenderModel.compressionInfo[0].ToExtentsMatrix();

                    Vector3 linVel, angVel;
                    TransformUtil.CalculateVelocity(from, to, 1.0f, out linVel, out angVel);
                    Matrix4 T;
                    TransformUtil.IntegrateTransform(from, linVel, angVel, callback.ClosestHitFraction, out T);

                    this.WorldMatrix = T;
                }
            }
        }
예제 #2
0
        public DynamicScene( ) : base()
        {
            caster             = new ConvexHullCaster( );
            SceneUpdate       += caster.OnUpdate;
            DrawDebugCollision = false;
            CollisionManager   = new CollisionManager(ProgramManager.DebugShader);
            MousePole          = new TranslationGizmo( );
            MousePole.Show(true);
            Camera.CameraUpdated  += MousePole.OnCameraUpdate;
            SelectedObjectChanged += OnSelectedObjectChanged;
            SelectedObjectChanged += caster.OnSelectedObjectChanged;
            MouseMove             += caster.OnMouseMove;
            MouseUp += caster.OnMouseUp;
            foreach (var item in MousePole.CollisionObjects)
            {
                CollisionManager.World.AddCollisionObject(item, CollisionFilterGroups.SensorTrigger, CollisionFilterGroups.SensorTrigger);
            }

#if DEBUG
            OpenGL.EnableDebugging( );
#endif
        }
예제 #3
0
 public void UpdatePhysics( )
 {
     CollisionManager.Update( );
 }