Пример #1
0
 public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying)
 {
     POSCharacter act = new POSCharacter();
     act.Position = position;
     act.Flying = isFlying;
     _characters.Add(act);
     return act;
 }
Пример #2
0
        public override void RemoveAvatar(PhysicsActor character)
        {
            POSCharacter act = (POSCharacter)character;

            if (_characters.Contains(act))
            {
                _characters.Remove(act);
            }
        }
Пример #3
0
        public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying)
        {
            POSCharacter act = new POSCharacter();

            act.Position = position;
            act.Flying   = isFlying;
            _characters.Add(act);
            return(act);
        }
Пример #4
0
        private bool isColliding(POSCharacter c, POSPrim p)
        {
            Vector3 rotatedPos = new Vector3(c.Position.X - p.Position.X, c.Position.Y - p.Position.Y,
                                             c.Position.Z - p.Position.Z) * Quaternion.Inverse(p.Orientation);
            Vector3 avatarSize = new Vector3(c.Size.X, c.Size.Y, c.Size.Z) * Quaternion.Inverse(p.Orientation);

            return(Math.Abs(rotatedPos.X) < (p.Size.X * 0.5 + Math.Abs(avatarSize.X)) &&
                   Math.Abs(rotatedPos.Y) < (p.Size.Y * 0.5 + Math.Abs(avatarSize.Y)) &&
                   Math.Abs(rotatedPos.Z) < (p.Size.Z * 0.5 + Math.Abs(avatarSize.Z)));
        }
Пример #5
0
        private bool isCollidingWithPrim(POSCharacter c)
        {
            foreach (POSPrim p in _prims)
            {
                if (isColliding(c, p))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #6
0
        private bool isCollidingWithPrim(POSCharacter c)
        {
            for (int i = 0; i < _prims.Count; ++i)
            {
                if (isColliding(c, _prims[i]))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #7
0
        public override float Simulate(float timeStep)
        {
            float fps = 0;

            for (int i = 0; i < _characters.Count; ++i)
            {
                fps++;
                POSCharacter character = _characters[i];

                float oldposX = character.Position.X;
                float oldposY = character.Position.Y;
                float oldposZ = character.Position.Z;

                if (!character.Flying)
                {
                    character._target_velocity.Z += gravity * timeStep;
                }

                Vector3 characterPosition = character.Position;

                characterPosition.X += character._target_velocity.X * timeStep;
                characterPosition.Y += character._target_velocity.Y * timeStep;

                characterPosition.X = Util.Clamp(character.Position.X, 0.01f, Constants.RegionSize - 0.01f);
                characterPosition.Y = Util.Clamp(character.Position.Y, 0.01f, Constants.RegionSize - 0.01f);

                bool forcedZ = false;

                float terrainheight = _heightMap[(int)character.Position.Y * Constants.RegionSize + (int)character.Position.X];
                if (character.Position.Z + (character._target_velocity.Z * timeStep) < terrainheight + 2)
                {
                    characterPosition.Z = terrainheight + character.Size.Z;
                    forcedZ             = true;
                }
                else
                {
                    characterPosition.Z += character._target_velocity.Z * timeStep;
                }

                /// this is it -- the magic you've all been waiting for!  Ladies and gentlemen --
                /// Completely Bogus Collision Detection!!!
                /// better known as the CBCD algorithm

                if (isCollidingWithPrim(character))
                {
                    characterPosition.Z = oldposZ; //  first try Z axis
                    if (isCollidingWithPrim(character))
                    {
                        characterPosition.Z = oldposZ + character.Size.Z / 4.4f; // try harder
                        if (isCollidingWithPrim(character))
                        {
                            characterPosition.Z = oldposZ + character.Size.Z / 2.2f; // try very hard
                            if (isCollidingWithPrim(character))
                            {
                                characterPosition.X = oldposX;
                                characterPosition.Y = oldposY;
                                characterPosition.Z = oldposZ;

                                characterPosition.X += character._target_velocity.X * timeStep;
                                if (isCollidingWithPrim(character))
                                {
                                    characterPosition.X = oldposX;
                                }

                                characterPosition.Y += character._target_velocity.Y * timeStep;
                                if (isCollidingWithPrim(character))
                                {
                                    characterPosition.Y = oldposY;
                                }
                            }
                            else
                            {
                                forcedZ = true;
                            }
                        }
                        else
                        {
                            forcedZ = true;
                        }
                    }
                    else
                    {
                        forcedZ = true;
                    }
                }

                characterPosition.X = Util.Clamp(character.Position.X, 0.01f, Constants.RegionSize - 0.01f);
                characterPosition.Y = Util.Clamp(character.Position.Y, 0.01f, Constants.RegionSize - 0.01f);

                character.Position = characterPosition;

                character._velocity.X = (character.Position.X - oldposX) / timeStep;
                character._velocity.Y = (character.Position.Y - oldposY) / timeStep;

                if (forcedZ)
                {
                    character._velocity.Z                 = 0;
                    character._target_velocity.Z          = 0;
                    ((PhysicsActor)character).IsColliding = true;
                    character.RequestPhysicsterseUpdate();
                }
                else
                {
                    ((PhysicsActor)character).IsColliding = false;
                    character._velocity.Z = (character.Position.Z - oldposZ) / timeStep;
                }
            }
            return(fps);
        }
Пример #8
0
        private bool isCollidingWithPrim(POSCharacter c)
        {
            foreach (POSPrim p in _prims)
            {
                if (isColliding(c, p))
                {
                    return true;
                }
            }

            return false;
        }
Пример #9
0
        private bool isColliding(POSCharacter c, POSPrim p)
        {
            Vector3 rotatedPos = new Vector3(c.Position.X - p.Position.X, c.Position.Y - p.Position.Y,
                                             c.Position.Z - p.Position.Z) * Quaternion.Inverse(p.Orientation);
            Vector3 avatarSize = new Vector3(c.Size.X, c.Size.Y, c.Size.Z) * Quaternion.Inverse(p.Orientation);

            return (Math.Abs(rotatedPos.X) < (p.Size.X*0.5 + Math.Abs(avatarSize.X)) &&
                    Math.Abs(rotatedPos.Y) < (p.Size.Y*0.5 + Math.Abs(avatarSize.Y)) &&
                    Math.Abs(rotatedPos.Z) < (p.Size.Z*0.5 + Math.Abs(avatarSize.Z)));
        }
Пример #10
0
        private bool isCollidingWithPrim(POSCharacter c)
        {
            for (int i = 0; i < _prims.Count; ++i)
            {
                if (isColliding(c, _prims[i]))
                {
                    return true;
                }
            }

            return false;
        }
Пример #11
0
        private bool isColliding(POSCharacter c, POSPrim p)
        {
            Vector3 rotatedPos = new Vector3(c.Position.X - p.Position.X, c.Position.Y - p.Position.Y,
                                             c.Position.Z - p.Position.Z) * Quaternion.Inverse(p.Orientation);
            Vector3 avatarSize = new Vector3(c.Size.X, c.Size.Y, c.Size.Z) * Quaternion.Inverse(p.Orientation);

            if (Math.Abs(rotatedPos.X) >= (p.Size.X*0.5 + Math.Abs(avatarSize.X)) ||
                Math.Abs(rotatedPos.Y) >= (p.Size.Y*0.5 + Math.Abs(avatarSize.Y)) ||
                Math.Abs(rotatedPos.Z) >= (p.Size.Z*0.5 + Math.Abs(avatarSize.Z)))
            {
                return false;
            }
            return true;
        }