Beispiel #1
0
        private void DoShoot(MouseState ms)
        {
            if (CurrentWorld.GetCurrentTimeInMilliseconds() - _lastShot > _cooldown)
            {
                ImmovableTerrain o = HelperIntersection.IsMouseCursorOnAny <ImmovableTerrain>(ms, out Vector3 intersectionPoint, 0, 16);
                Vector3          target;
                if (o != null)
                {
                    target = intersectionPoint;
                }
                else
                {
                    target = HelperIntersection.GetMouseIntersectionPoint(ms, Plane.Camera, -50, 35, 5);
                }

                ShotTerrain s = new ShotTerrain();
                s.SetModel("KWSphere");
                s.SetScale(0.25f);
                s.SetColor(0, 0, 1);
                s.SetGlow(0, 0, 1, 0.25f);
                s.IsCollisionObject = true;
                s.SetPosition(GetCenterPointForAllHitboxes() + GetLookAtVector() * 0.25f);
                s.TurnTowardsXYZ(target);

                CurrentWorld.AddGameObject(s);
                _lastShot = CurrentWorld.GetCurrentTimeInMilliseconds();
            }
        }
Beispiel #2
0
        public override void Act(KeyboardState kb, MouseState ms)
        {
            if (kb[Key.Escape])
            {
                CurrentWindow.SetWorld(new GameWorldStart());
                return;
            }
            Console.WriteLine("Maus ist im Fenser: " + CurrentWindow.IsMouseInWindow);

            CallerCube t = HelperIntersection.IsMouseCursorOnAny <CallerCube>(ms);

            if (t != null)
            {
                coloredItems.Add(t);
                t.SetGlow(1, 1, 0, 1);
            }
            foreach (GameObject g in GetGameObjects())
            {
                if (!coloredItems.Contains(g))
                {
                    g.SetGlow(0, 0, 0, 0);
                }
            }
            coloredItems.Clear();
        }
Beispiel #3
0
        public override void Act(KeyboardState ks, MouseState ms)
        {
            if (ks[Key.Escape])
            {
                CurrentWindow.SetWorld(new GameWorldStart());
                return;
            }

            Vector3 mousepos3d = HelperIntersection.GetMouseIntersectionPoint(ms, Plane.Y, 1);

            _sphere.SetPosition(mousepos3d);
            if (HelperIntersection.IsPointInsideGameObject(mousepos3d, t))
            {
                t.SetGlow(1, 0, 0, 1);
            }
            else
            {
                t.SetGlow(1, 0, 0, 0);
            }
        }
Beispiel #4
0
        internal static List <Vector3> ClipFaces(Hitbox caller, Hitbox collider)
        {
            List <Vector3> callerVertices          = new List <Vector3>(caller.mVertices);
            List <Vector3> collisionVolumeVertices = new List <Vector3>();

            // Clip caller against collider faces:
            for (int colliderFaceIndex = 0; colliderFaceIndex < collider.mMesh.Faces.Length; colliderFaceIndex++)
            {
                GeoMeshFace colliderClippingFace       = collider.mMesh.Faces[colliderFaceIndex];
                Vector3     colliderClippingFaceVertex = collider.mVertices[colliderClippingFace.Vertices[0]];
                Vector3     colliderClippingFaceNormal = colliderClippingFace.Flip ? collider.mNormals[colliderClippingFace.Normal] : -collider.mNormals[colliderClippingFace.Normal];
                for (int callerVertexIndex = 0; callerVertexIndex < callerVertices.Count; callerVertexIndex++)
                {
                    Vector3 callerVertex1 = callerVertices[callerVertexIndex];
                    Vector3 callerVertex2 = callerVertices[(callerVertexIndex + 1) % callerVertices.Count];
                    Vector3 lineDirection = Vector3.NormalizeFast(callerVertex2 - callerVertex1);

                    bool callerVertex1InsideRegion = HelperIntersection.IsInFrontOfPlane(ref callerVertex1, ref colliderClippingFaceNormal, ref colliderClippingFaceVertex);
                    bool callerVertex2InsideRegion = HelperIntersection.IsInFrontOfPlane(ref callerVertex2, ref colliderClippingFaceNormal, ref colliderClippingFaceVertex);

                    if (callerVertex1InsideRegion)
                    {
                        if (callerVertex2InsideRegion)
                        {
                            if (!collisionVolumeVertices.Contains(callerVertex2))
                            {
                                collisionVolumeVertices.Add(callerVertex2);
                            }
                        }
                        else
                        {
                            Vector3?clippedVertex = ClipLineToPlane(ref callerVertex2, ref lineDirection, ref colliderClippingFaceVertex, ref colliderClippingFaceNormal);
                            if (clippedVertex != null && !collisionVolumeVertices.Contains(clippedVertex.Value))
                            {
                                collisionVolumeVertices.Add(clippedVertex.Value);
                            }
                        }
                    }
                    else
                    {
                        if (callerVertex2InsideRegion)
                        {
                            Vector3?clippedVertex = ClipLineToPlane(ref callerVertex1, ref lineDirection, ref colliderClippingFaceVertex, ref colliderClippingFaceNormal);
                            if (clippedVertex != null && !collisionVolumeVertices.Contains(clippedVertex.Value))
                            {
                                collisionVolumeVertices.Add(clippedVertex.Value);
                            }
                            if (!collisionVolumeVertices.Contains(callerVertex2))
                            {
                                collisionVolumeVertices.Add(callerVertex2);
                            }
                        }
                    }
                }
                callerVertices.Clear();
                for (int i = 0; i < collisionVolumeVertices.Count; i++)
                {
                    callerVertices.Add(collisionVolumeVertices[i]);
                }
                collisionVolumeVertices.Clear();
            }
            return(callerVertices);
        }