Exemplo n.º 1
0
        protected void UpdateTargetObject()
        {
            //redraw
            targetedEntity = null;

            if (EngineApp.Instance.MouseRelativeMode)
            {
                return;
            }

            Ray ray = RendererWorld.Instance.DefaultCamera.GetCameraToViewportRay(EngineApp.Instance.MousePosition);

            RayCastResult[] results = PhysicsWorld.Instance.RayCastPiercing(ray, (int)ContactGroup.CastOnlyCollision);

            foreach (RayCastResult result in results)
            {
                //terrain
                HeightmapTerrain terrain = HeightmapTerrain.GetTerrainByBody(result.Shape.Body);
                if (terrain != null)
                {
                    targetedEntity = terrain;
                    return;
                }

                //other
                targetedEntity = MapSystemWorld.GetMapObjectByBody(result.Shape.Body);
                return;
            }
        }
Exemplo n.º 2
0
        void ToggleEntity()
        {
            if (EngineApp.Instance.MouseRelativeMode)
            {
                return;
            }

            MapEditorInterface.Instance.SetMapModified();

            Ray ray = RendererWorld.Instance.DefaultCamera.GetCameraToViewportRay(EngineApp.Instance.MousePosition);

            RayCastResult[] results = PhysicsWorld.Instance.RayCastPiercing(ray, (int)ContactGroup.CastOnlyCollision);

            foreach (RayCastResult result in results)
            {
                //heightmapterrain
                HeightmapTerrain terrain = HeightmapTerrain.GetTerrainByBody(result.Shape.Body);
                if (terrain != null)
                {
                    //deselect
                    if (RecastNavigationSystem.Instance.Geometries.Contains(terrain))
                    {
                        //Log.Info("Removed terrain " + terrain.Name + " from geometries.");
                        RecastNavigationSystem.Instance.Geometries.Remove(terrain);
                        return;
                    }

                    //select
                    if (RecastNavigationSystem.Instance.GeometryVerifier(terrain, true))
                    {
                        //Log.Info("Added terrain " + terrain.Name + " to geometries.");
                        RecastNavigationSystem.Instance.Geometries.Add(terrain);
                        return;
                    }
                }

                MapObject mapObject = MapSystemWorld.GetMapObjectByBody(result.Shape.Body);
                if (mapObject != null)
                {
                    //deselect
                    if (RecastNavigationSystem.Instance.Geometries.Contains(mapObject))
                    {
                        RecastNavigationSystem.Instance.Geometries.Remove(mapObject);
                        return;
                    }

                    //select
                    if (RecastNavigationSystem.Instance.GeometryVerifier(mapObject, true))
                    {
                        RecastNavigationSystem.Instance.Geometries.Add(mapObject);
                        return;
                    }
                }

                Log.Error("Unknown entity with collisions, what shenanigans!");
            }

            return;
        }
Exemplo n.º 3
0
        void CreateDirectionalDecal(Shape shape, Vec3 pos, Vec3 normal, int triangleID)
        {
            bool smallDecal = Type.Size < .3f;

            Body body = shape.Body;

            //static objects
            if (shape.ContactGroup == (int)ContactGroup.Collision)
            {
                ShapeTriangleID triangle = new ShapeTriangleID(shape, triangleID);

                //StaticMesh
                {
                    StaticMesh staticMesh = StaticMesh.GetStaticMeshByBody(body);
                    if (staticMesh != null)
                    {
                        if (staticMesh.AllowDecals == StaticMesh.DecalTypes.OnlySmall && smallDecal ||
                            staticMesh.AllowDecals == StaticMesh.DecalTypes.All)
                        {
                            CreateDecalForStaticObject(triangle, pos, normal, null);
                            return;
                        }
                    }
                }

                //HeightmapTerrain
                if (HeightmapTerrain.GetTerrainByBody(body) != null)
                {
                    CreateDecalForStaticObject(triangle, pos, normal, null);
                    return;
                }

                if (Type.ApplyToMapObjects)
                {
                    //MapObject: Attached mesh
                    MapObject mapObject = MapSystemWorld.GetMapObjectByBody(body);
                    if (mapObject != null)
                    {
                        bool isCollision = false;

                        foreach (MapObjectAttachedObject attachedObject in mapObject.AttachedObjects)
                        {
                            MapObjectAttachedMesh attachedMesh = attachedObject as MapObjectAttachedMesh;
                            if (attachedMesh != null && attachedMesh.CollisionBody == body)
                            {
                                isCollision = true;
                                break;
                            }
                        }

                        if (isCollision)
                        {
                            CreateDecalForStaticObject(triangle, pos, normal, mapObject);
                            return;
                        }
                    }
                }
            }

            //dynamic objects
            {
                //not implemented
            }
        }
Exemplo n.º 4
0
        private void body_Collision(ref CollisionEvent collisionEvent)
        {
            Body otherBody = collisionEvent.OtherShape.Body;

            if (HeightmapTerrain.GetTerrainByBody(otherBody) != null)
            {
                return;
            }

            if (otherBody.Static && otherBody.Name.Contains("Map")) //LDASH custom map names
            {
                return;
            }

            //Note: Incin ---- Dynamic_Collision needs to be removed

            Body thisBody = collisionEvent.ThisShape.Body;

            //if (!otherBody.Static)
            //    DoForce(thisBody);

            if (otherBody == null && thisBody != null)
            {
                DoForce(null, thisBody);
            }

            if (!otherBody.Static)
            {
                DoForce(otherBody, thisBody); //collisionEvent.Position, collisionEvent.Normal);
            }
            float otherMass = otherBody.Mass;
            float impulse   = 0;

            impulse += thisBody.LastStepLinearVelocity.Length() * thisBody.Mass;

            if (otherMass != 0)
            {
                impulse += otherBody.LastStepLinearVelocity.Length() * otherMass;
            }

            float damage = impulse; // *Type.ImpulseDamageCoefficient;

            MapObject mapobj = MapSystemWorld.GetMapObjectByBody(otherBody);

            if (mapobj != null)
            {
                Dynamic obj = mapobj as Dynamic;
                if (obj != null)
                {
                    if (obj.Name.Contains("House"))
                    {
                        //damage house
                        if (obj.Type.ImpulseDamageCoefficient != 0)
                        {
                            damage = impulse * obj.Type.ImpulseDamageCoefficient;
                        }
                        else
                        {
                            float health = obj.Health / 2;
                            damage = health;
                        }
                        OnDamage(mapobj, collisionEvent.Position, collisionEvent.OtherShape, damage, true);

                        //damage player if too fast
                        if (Type.ImpulseDamageCoefficient != 0)
                        {
                            damage = impulse * Type.ImpulseDamageCoefficient;
                        }
                        else
                        {
                            damage = impulse;
                        }

                        //if minimal damage do player damage
                        ////if (damage >= Type.ImpulseMinimalDamage)
                        ////{
                        ////    //OnDamage(null, collisionEvent.Position, collisionEvent.ThisShape, damage, true);//damage the other guy here
                        ////    OnDamage(null, collisionEvent.Position, collisionEvent.ThisShape, damage, true);
                        ////}
                    }
                    else //still object type damage
                    {
                        if (obj.Type.ImpulseDamageCoefficient != 0)
                        {
                            damage = impulse * obj.Type.ImpulseDamageCoefficient;
                        }
                        else
                        {
                            damage = impulse * 0.5f;
                        }

                        OnDamage(mapobj, collisionEvent.Position, collisionEvent.OtherShape, damage, true);
                    }
                }
            }
            //else  //damage self
            //{
            //    //if (Type.ImpulseDamageCoefficient != 0)
            //    //    damage = impulse * Type.ImpulseDamageCoefficient;
            //    //else
            //    //    damage = impulse;

            //    //if (damage >= Type.ImpulseMinimalDamage)
            //    //{
            //    //    OnDamage(null, collisionEvent.Position, collisionEvent.ThisShape, damage, true);
            //    //}
            //}
        }