示例#1
0
 public override void BlurTerrain(SlimDX.Vector3 pos, bool lower)
 {
     foreach (var chunk in mChunks)
     {
         chunk.BlurTerrain(pos, lower);
     }
 }
        public void Evaluate(int SpreadMax)
        {
            if (this.bodies.IsConnected)
            {
                this.position.SliceCount    = bodies.SliceCount;
                this.orientation.SliceCount = bodies.SliceCount;

                var pos = this.position.Stream.Buffer;
                var rot = this.orientation.Stream.Buffer;

                for (int i = 0; i < SpreadMax; i++)
                {
                    RigidBody body = this.bodies[i];
                    pos[i] = new SlimDX.Vector3(body.MotionState.WorldTransform.M41, body.MotionState.WorldTransform.M42, body.MotionState.WorldTransform.M43);

                    Quaternion r = body.Orientation;
                    rot[i] = new SlimDX.Quaternion(r.X, r.Y, r.Z, r.W);
                }
                this.position.Flush(true);
                this.orientation.Flush(true);
            }
            else
            {
                this.position.SliceCount    = 0;
                this.orientation.SliceCount = 0;
            }
        }
示例#3
0
        public void DrawAgroLine(Clio.Utilities.Vector3 center, float heading, float width, float height, Color color, Color pointColor)
        {
            var newCenter = new Vector3(center.X, center.Y, center.Z);

            float heightBack = width;

            float diag     = (float)Math.Sqrt(height * height + width * width) / 2;
            float diagBack = (float)Math.Sqrt(heightBack * heightBack + width * width) / 2;

            float subangle = (float)Math.Atan2(width / 2, height / 2);


            float h = (float)(((Math.PI * 2) - heading) + (Math.PI / 2));

            float r1 = h - subangle;
            float r2 = h + ((float)Math.PI / 4) + (float)Math.PI;
            float r3 = h - ((float)Math.PI / 4) + (float)Math.PI;
            float r4 = h + subangle;

            _vertexBuffer[0] = new ColoredVertex(newCenter, pointColor);
            _vertexBuffer[1] = new ColoredVertex(newCenter + new Vector3((float)Math.Cos(r1) * diag, 0, (float)Math.Sin(r1) * diag), pointColor);
            _vertexBuffer[2] = new ColoredVertex(newCenter + new Vector3((float)Math.Cos(r2) * diagBack, 0, (float)Math.Sin(r2) * diagBack), color);
            _vertexBuffer[3] = new ColoredVertex(newCenter + new Vector3((float)Math.Cos(r3) * diagBack, 0, (float)Math.Sin(r3) * diagBack), color);
            _vertexBuffer[4] = new ColoredVertex(newCenter + new Vector3((float)Math.Cos(r4) * diag, 0, (float)Math.Sin(r4) * diag), pointColor);
            _vertexBuffer[5] = _vertexBuffer[1];

            SetDeclaration();
            Device.DrawUserPrimitives(PrimitiveType.TriangleFan, 4, _vertexBuffer);
        }
示例#4
0
        public override void OnJumpToMap()
        {
            if (null == mTrigger)
            {
                return;
            }

            PlanesInstance planes = mHostMap.Planes;

            OnLeaveMap();
            MapInstance map   = null;
            ushort      mapId = (ushort)mTrigger.TriggerData.mapId;

            map = planes.GetGlobalMap(mapId);
            if (map == null)
            {
                map = Planes.MapInstanceManager.Instance.CreateMapInstance(planes, 0, mapId, null);
                if (map == null)
                {
                    map = Planes.MapInstanceManager.Instance.GetDefaultMapInstance(planes);
                }
                planes.AddGlobalMap(mapId, map);
            }
            SlimDX.Vector3 newPos = new SlimDX.Vector3(mTrigger.TriggerData.targetX, 0, mTrigger.TriggerData.targetZ);
            Placement.SetLocation(ref newPos);
            OnEnterMap(map);
        }
示例#5
0
        public static uint AddInstance(string name, SlimDX.Vector3 pos, uint uniqueId, SlimDX.Vector3 rotation)
        {
            pos.X -= Utils.Metrics.MidPoint;
            float tmpY = pos.Z - Utils.Metrics.MidPoint;
            float tmpZ = pos.Y;

            pos.Y = tmpY;
            pos.Z = tmpZ;

            int hash = name.ToLower().GetHashCode();

            lock (lockobj)
            {
                if (mRenders.ContainsKey(hash))
                {
                    return(mRenders[hash].PushInstance(uniqueId, pos, rotation));
                }
                else
                {
                    WMORender rdr = new WMORender(name);
                    mRenders.Add(hash, rdr);
                    return(rdr.PushInstance(uniqueId, pos, rotation));
                }
            }
        }
示例#6
0
        /// Bulletの世界を作る
        /// </summary>
        /// <param name="gravity">重力</param>
        /// <returns>Bulletの世界</returns>
        public DiscreteDynamicsWorld CreateDynamicsWorld(SlimDX.Vector3 gravity)
        {
            var dynamicsWorld = new DiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);

            dynamicsWorld.Gravity = gravity;
            return(dynamicsWorld);
        }
示例#7
0
        public override bool SetLocation(ref SlimDX.Vector3 loc)
        {
            base.SetLocation(ref loc);

            OnUpdatePosition(ref mLocation);
            return(true);
        }
示例#8
0
        /// <summary>
        /// Updates sample state.
        /// </summary>
        private void Update()
        {
            FrameDelta = clock.Update();
            userInterface.Container.Update();

            if (EnableCamera)
            {
                float cameraDist = cameraVelocity * FrameDelta;
                if (cameraForwardDirection != 0)
                {
                    cameraPosition = cameraPosition + cameraForward * cameraDist * cameraForwardDirection;
                }

                if (cameraStrafeDirection != 0)
                {
                    cameraPosition = cameraPosition + cameraRight * cameraDist * cameraStrafeDirection;
                }

                if (cameraRaiseDirection != 0)
                {
                    cameraPosition = cameraPosition + cameraUp * cameraDist * cameraRaiseDirection;
                }
            }

            OnUpdate();
        }
示例#9
0
 public void _OnPlacementChanged(ref SlimDX.Vector3 loc)
 {
     if (OnLocationChanged != null)
     {
         OnLocationChanged(ref loc);
     }
 }
示例#10
0
 public static void BlurTerrain(SlimDX.Vector3 pos, bool lower)
 {
     foreach (var file in mActiveFiles)
     {
         file.BlurTerrain(pos, lower);
     }
 }
示例#11
0
        protected override void OnPlacementUpdatePosition(ref SlimDX.Vector3 pos)
        {
            if (!this.HostMap.IsNullMap)
            {
                var mapCell = this.HostMap.GetMapCell(pos.X, pos.Z);
                if (mapCell != null)
                {
                    if (this.HostMapCell != mapCell)
                    {
                        mapCell.AddRole(this);

                        //// 向玩家发送周围格NPC
                        //this.HostMap.UpdateNPCsToClient(this);
                        //// 向玩家发送周围格玩家
                        //this.HostMap.UpdatePlayersToClient(this);
                    }
                }
            }


            if (!this.HostMap.IsNullMap && HostMap.IsSavePos(this))
            {
                SetRoleDetailPos(pos.X, pos.Z);
                PlayerData.RoleDetail.Direction = this.Placement.GetDirection();
            }
        }
示例#12
0
        public void DrawCircleWithPoint(Clio.Utilities.Vector3 center, float heading, float radius, Color color, Color pointColor)
        {
            int slices       = 30;
            var radsPerSlice = (float)(Math.PI * 2 / slices);

            var newCenter = new Vector3(center.X, center.Y, center.Z);

            _vertexBuffer[0] = new ColoredVertex(newCenter, color);
            _vertexBuffer[1] = new ColoredVertex(newCenter + new Vector3(radius, 0, 0), color);

            for (int i = 0; i < slices; i++)
            {
                double h = ((Math.PI * 2) - heading) + (Math.PI / 2);
                if (h > (Math.PI * 2))
                {
                    h = h - (Math.PI * 2);
                }

                bool watchAt = (i * radsPerSlice) < h && h < ((i + 1) * radsPerSlice);

                var sine   = (float)Math.Sin((i + 1) * radsPerSlice);
                var cosine = (float)Math.Cos((i + 1) * radsPerSlice);

                _vertexBuffer[2 + i] =
                    new ColoredVertex(newCenter + new Vector3(cosine * radius, 0, sine * radius),
                                      watchAt ? pointColor.ToArgb() : color.ToArgb());
            }

            SetDeclaration();
            Device.DrawUserPrimitives(PrimitiveType.TriangleFan, slices, _vertexBuffer);
        }
示例#13
0
 public R32G32B32A32F(SlimDX.Vector3 rgb, float a)
 {
     this.r = rgb.X;
     this.g = rgb.Y;
     this.b = rgb.Z;
     this.a = a;
 }
示例#14
0
        public override bool SetLocation(ref SlimDX.Vector3 loc)
        {
            mLocation = loc;

            _OnPlacementChanged(ref loc);

            return(true);
        }
示例#15
0
 /** Adds a control point to the end of the spline. */
 public void AddPoint(ref SlimDX.Vector3 p)
 {
     mPoints.Add(p);
     if (mAutoCalc)
     {
         RecalcTangents();
     }
 }
示例#16
0
 public void Write(SlimDX.Vector3 data)
 {
     unsafe
     {
         SlimDX.Vector3 *pPtr = &data;
         Write((IntPtr)pPtr, sizeof(SlimDX.Vector3));
     }
 }
示例#17
0
 public void InsertPoint(int index, ref SlimDX.Vector3 p)
 {
     mPoints.Insert(index, p);
     if (mAutoCalc)
     {
         RecalcTangents();
     }
 }
示例#18
0
 public static XElement SerializeVector(SlimDX.Vector3 Vector)
 {
     return(new XElement("Vector3",
                         new XElement("X", Vector.X),
                         new XElement("Y", Vector.Y),
                         new XElement("Z", Vector.Z)
                         ));
 }
示例#19
0
 /** Updates a single point in the spline.
  * @remarks
  *  This point must already exist in the spline.
  */
 public void UpdatePoint(UInt16 index, ref SlimDX.Vector3 value)
 {
     System.Diagnostics.Debug.Assert(index < mPoints.Count, "Point index is out of bounds!!");
     mPoints[index] = value;
     if (mAutoCalc)
     {
         RecalcTangents();
     }
 }
示例#20
0
 public Camera()
 {
     Position = new SlimDX.Vector3(0.0f, 0.0f, -5.0f);
     right = new SlimDX.Vector3(1.0f, 0.0f, 0.0f);
     up = new SlimDX.Vector3(0.0f, 1.0f, 0.0f);
     forward = new SlimDX.Vector3(0.0f, 0.0f, 1.0f);
     speed = 2.0f;
     View = SlimDX.Matrix.Identity;
 }
示例#21
0
        public bool ReInitTriggerInstance(MapInfo_Portal td, MapInstance map)
        {
            mTriggerData = td;
            this.OnEnterMap(map);
            var pos = new SlimDX.Vector3(td.posX, 0, td.posZ);

            mPlacement.SetLocation(ref pos);
            return(true);
        }
 public ColladaBoneMatrix(string name,
                          LowLevel.Math.real_point3d translation,
                          LowLevel.Math.real_quaternion rotation,
                          float scale)
 {
     Name = name;
     translationVector  = new SlimDX.Vector3(translation.X, translation.Y, translation.Z);
     rotationQuaternion = new SlimDX.Quaternion(rotation.Vector.I, rotation.Vector.J, rotation.Vector.K, rotation.W);
     scaleAmount        = scale;
 }
示例#23
0
		public ColladaBoneMatrix(string name,
			LowLevel.Math.real_point3d translation,
			LowLevel.Math.real_quaternion rotation,
			float scale)
		{
			Name = name;
			translationVector = new SlimDX.Vector3(translation.X, translation.Y, translation.Z);
			rotationQuaternion = new SlimDX.Quaternion(rotation.Vector.I, rotation.Vector.J, rotation.Vector.K, rotation.W);
			scaleAmount = scale;
		}
示例#24
0
        public static bool IsWmoHit(out WMOHitInformation info, out SlimDX.Vector3 hitPos)
        {
            info = null;
            bool hasHit   = false;
            uint uniqueId = 0;
            uint refId    = 0;

            hitPos = SlimDX.Vector3.Zero;
            SlimDX.Matrix modelMatrix = SlimDX.Matrix.Identity;
            WMOFile       hitFile     = null;
            WMORender     renderer    = null;
            uint          instanceID  = 0;

            lock (lockobj)
            {
                float curNear = 99999;

                foreach (var rndr in mRenders)
                {
                    float          curHit  = 0;
                    uint           curInst = 0;
                    uint           curRef  = 0;
                    SlimDX.Vector3 pos;
                    SlimDX.Matrix  tmpMatrix;
                    uint           tmpId = 0;
                    if (rndr.Value.IsInstanceHit(out curHit, out curInst, out curRef, out pos, out tmpMatrix, out tmpId))
                    {
                        hasHit = true;
                        if (curHit < curNear)
                        {
                            curNear     = curHit;
                            uniqueId    = curInst;
                            refId       = curRef;
                            hitPos      = pos;
                            modelMatrix = tmpMatrix;
                            hitFile     = rndr.Value.File;
                            renderer    = rndr.Value;
                            instanceID  = tmpId;
                        }
                    }
                }
            }

            if (hasHit)
            {
                info             = ADT.ADTManager.GetWmoInformation(uniqueId, refId);
                info.HitPoint    = hitPos;
                info.ModelMatrix = modelMatrix;
                info.Model       = hitFile;
                info.Renderer    = renderer;
                info.InstanceID  = instanceID;
            }

            return(hasHit);
        }
示例#25
0
        int mTourRolesCount;    //计算最大广播人数
        public void SendPkg2Clients(RoleActor ignore, SlimDX.Vector3 pos, RPC.PackageWriter pkg)
        {
            //这个range是以pos为中心广播多大范围内的玩家
            UInt32 actorTypes = (1 << (Int32)eActorGameType.Player);
            var    arg        = new PkgSender();

            arg.Pkg         = pkg;
            arg.IgnoreRole  = ignore;
            mTourRolesCount = 0;
            TourRoles(ref pos, RPC.RPCNetworkMgr.Sync2ClientRange, actorTypes, this.OnVisitRole_SendPkg2Client, arg);
        }
示例#26
0
        private void internalDraw(DrawingContext ctx, Vector3 loc)
        {
            var vecCenter = loc + new Vector3(0, 1, 0);

            ctx.DrawOutlinedBox(vecCenter, new Vector3(1.0f * 1.0f), NodeColor);

            ctx.DrawCircleWithPoint(
                vecCenter,
                0.0f,
                Radius,
                RangeColor, RangeColor);
        }
示例#27
0
        private void internalDraw(DrawingContext ctx, Vector3 loc)
        {
            if (OutColor.A > 0)
            {
                ctx.DrawDonut(loc, InRadius, OutRadius, OutColor);
            }

            if (InColor.A > 0)
            {
                ctx.DrawCircle(loc, InRadius, InColor);
            }
        }
示例#28
0
        public bool IsPositionIn(SlimDX.Vector3 pos, SlimDX.Matrix invMat)
        {
            var triggerSpacePos = SlimDX.Vector3.TransformCoordinate(pos, invMat);

            if ((Math.Abs(triggerSpacePos.X) < (0.5f)) &&
                //(Math.Abs(triggerSpacePos.Y) < (0.5f)) &&
                (Math.Abs(triggerSpacePos.Z) < (0.5f)))
            {
                return(true);
            }

            return(false);
        }
示例#29
0
        public void EnterWorld(uint mapid, string continent, float x, float y)
        {
            MapID = mapid;
            foreach (var file in mFiles)
            {
                file.Unload();
            }

            mFiles.Clear();

            int ix = (int)(x / Utils.Metrics.Tilesize);
            int iy = (int)(y / Utils.Metrics.Tilesize);

            for (int i = -1; i < 2; ++i)
            {
                for (int j = -1; j < 2; ++j)
                {
                    int valX = (int)ix + j;
                    int valY = (int)iy + i;
                    if (valX < 0 || valY < 0)
                    {
                        continue;
                    }

                    ADT.IADTFile file = ADT.ADTManager.CreateADT(mWdtManager.getWDT(continent), @"World\Maps\" + continent + @"\" + continent + "_" + valX + "_" + valY + ".adt",
                                                                 (uint)valX, (uint)valY, (i == 0 && j == 0));

                    file.Continent = continent;

                    if (file != null)
                    {
                        mFiles.Add(file);
                    }
                }
            }

            float h = 0.0f;

            GetLandHeightFast(-Utils.Metrics.MidPoint + x, -Utils.Metrics.MidPoint + y, ref h);
            h += 100.0f;
            var inpos = new SlimDX.Vector3(x, y, h);

            inpos.X = -Utils.Metrics.MidPoint + inpos.X;
            inpos.Y = -Utils.Metrics.MidPoint + inpos.Y;
            Game.GameManager.GraphicsThread.GraphicsManager.Camera.SetPosition(inpos);
            isInWorld  = true;
            mContinent = continent;
            Game.GameManager.InformPropertyChanged(GameProperties.Map);
        }
示例#30
0
        public enEnterMapResult PlayerEnterMap(PlayerInstance role, SlimDX.Vector3 pos, bool bTellClient)
        {
            if (mPlayerPool == null)
            {
                return(enEnterMapResult.Error_InvalidMap);
            }

            if (mFreeSlot.Count == 0)
            {
                return(enEnterMapResult.Error_PlayerFull);
            }

            role.Placement.SetLocation(ref pos);

            if (role.HostMap != this)
            {
                if (!role.HostMap.IsNullMap)
                {
                    role.HostMap.PlayerLeaveMap(role, false);
                }
                role._SetIndexInMap(mFreeSlot.Pop());
                System.Diagnostics.Debug.Assert(mPlayerPool[role.IndexInMap] == null);
                mPlayerPool[role.IndexInMap] = role;
                mPlayerDictionary[role.Id]   = role;

                if (AllMapManager.IsInstanceMap(this.MapSourceId) == false)
                {
                    //role.PlayerData.RoleDetail.MapName = this.MapName;
                    role.PlayerData.RoleDetail.DungeonID   = 0;
                    role.PlayerData.RoleDetail.MapSourceId = this.MapSourceId;
                }
                else
                {
                    role.PlayerData.RoleDetail.DungeonID = this.MapInstanceId;
                }

                role.OnEnterMap(this);
            }

            OnRoleEnterMap(role);

            RPC.PackageWriter pkg = new RPC.PackageWriter();
            H_RPCRoot.smInstance.HGet_GateServer(pkg).PlayerEnterMapInPlanes(pkg, role.Id, role.ClientLinkId, role.IndexInMap, this.IndexInServer);
            pkg.DoCommand(role.Planes2GateConnect, RPC.CommandTargetType.DefaultType);

            role.HostMap = this;
            return(enEnterMapResult.Success);
        }
        public void Evaluate(int SpreadMax)
        {
            this.output.SliceCount = SpreadMax;

            fixed(RigidBodyPose *posePtr = &this.output.Stream.Buffer[0])
            {
                for (int i = 0; i < SpreadMax; i++)
                {
                    SlimDX.Vector3    p = position[i];
                    SlimDX.Quaternion q = orientation[i];
                    posePtr[i].Position    = *(BulletSharp.Vector3 *) & p;
                    posePtr[i].Orientation = *(BulletSharp.Quaternion *) & q;
                }
            }

            this.output.Flush(true);
        }
示例#32
0
        void ChangeTerrain(SlimDX.Vector3 mpos, bool lower)
        {
            switch (ChangeType)
            {
            case Logic.ChangeType.Raise:
                ADT.ADTManager.ChangeTerrain(mpos, lower);
                break;

            case Logic.ChangeType.Flatten:
                ADT.ADTManager.FlattenTerrain(mpos, lower);
                break;

            case Logic.ChangeType.Blur:
                ADT.ADTManager.BlurTerrain(mpos, lower);
                break;
            }
        }
        public FlightCamera(SlimDX.Vector3 startPos)
            : base()
        {
            _lastMousePos = new Point(0, 0);
            _isWDown = false;
            _isSDown = false;
            _isADown = false;
            _isDDown = false;
            _isShiftDown = false;

            _isRightMouseDown = false;

            _forwardSpeed = 0.0f;
            _rightSpeed = 0.0f;

            _phi = MathF.PI / 2.0f;
            _theta = 0.0f;

            BasePosition = startPos;

            OutsideSimulatorApp.GetInstance().Subscribe(this);
        }
示例#34
0
        /// <summary>
        /// Updates sample state.
        /// </summary>
        private void Update()
        {
            FrameDelta = clock.Update();
            userInterface.Container.Update();

            if (EnableCamera)
            {
                float cameraDist = cameraVelocity * FrameDelta;
                if (cameraForwardDirection != 0)
                {
                    cameraPosition = cameraPosition + cameraForward * cameraDist * cameraForwardDirection;
                }

                if (cameraStrafeDirection != 0)
                {
                    cameraPosition = cameraPosition + cameraRight * cameraDist * cameraStrafeDirection;
                }

                if (cameraRaiseDirection != 0)
                {
                    cameraPosition = cameraPosition + cameraUp * cameraDist * cameraRaiseDirection;
                }
            }

            OnUpdate();
        }
示例#35
0
        void UpdateNetworkIn()
        {
            if (Socket == null) return;
            for (int i = 0; Socket.Available > 0 && i < 100; i++)
            {
                if (state.NetworkIn == null)
                    return;
                //Program.p.updateMutex.WaitOne();
                IPEndPoint ep = new IPEndPoint(IPAddress.Any, 0);
                byte[] data = Socket.Receive(ref ep);
                dataReceivedCounter += data.Length;
                TotDataReceivedCounter += data.Length;
                TotNPackages++;
                if (data == null) return;
                //Console.Title = socket.Client.LocalEndPoint + " >> " + serverendpoint.ToString() + " visible: " + Program.objects.Count;
                MemoryStream m = new MemoryStream(data);
                BinaryReader s = new BinaryReader(m);
                BinaryFormatter bf = new BinaryFormatter();

                byte c = s.ReadByte();
                switch ((Common.S2CProtocol)c)
                {
                    case Common.S2CProtocol.Connected:
                        state.NetworkIn.Connected(ep, s.ReadString());
                        break;
                    case Common.S2CProtocol.PlayerJoined:
                        state.NetworkIn.PlayerJoined(ep, s.ReadString(), s.ReadInt32());
                        break;
                    case Common.S2CProtocol.PlayerChangedSlot:
                        state.NetworkIn.PlayerChangedSlot(ep, s.ReadInt32(), s.ReadInt32());
                        break;
                    case Common.S2CProtocol.StartGame:
                        state.NetworkIn.StartGame(ep);
                        break;
                    case Common.S2CProtocol.EndGame:
                        state.NetworkIn.EndGame(ep, s.ReadString(), (Common.GameStats)bf.Deserialize(m));
                        break;
                    case Common.S2CProtocol.CurrentGameStats:
                        state.NetworkIn.CurrentGameStats(ep, (Common.GameStats)bf.Deserialize(m));
                        break;
                    case Common.S2CProtocol.SetAvatar:
                        state.NetworkIn.SetAvatar(ep, s.ReadBytes((int)(s.BaseStream.Length - s.BaseStream.Position)));
                        break;
                    case Common.S2CProtocol.CombatText:
                        BinaryFormatter f = new BinaryFormatter();
                        state.NetworkIn.CombatMessage(ep, f.Deserialize(s.BaseStream));
                        break;
                    case Common.S2CProtocol.InsertObject:
                        state.NetworkIn.InsertObject(ep, s.ReadBytes((int)(s.BaseStream.Length - s.BaseStream.Position)));
                        break;
                    case Common.S2CProtocol.RemoveObject:
                        state.NetworkIn.RemoveObject(ep, s.ReadString());
                        break;
                    case Common.S2CProtocol.SetUnitFloatStat:
                        state.NetworkIn.SetUnitFloatStat(ep, s.ReadString(), (Common.UnitStats)s.ReadInt32(), s.ReadSingle());
                        break;
                    case Common.S2CProtocol.UpdateUnitClass:
                        state.NetworkIn.UpdateUnitClass(ep, s.ReadString(), s.ReadString());
                        break;
                    case Common.S2CProtocol.SetAbility:
                        state.NetworkIn.SetAbility(ep, s.ReadString(), s.ReadInt32(), s.ReadString());
                        break;
                    case Common.S2CProtocol.UpdateUnitMovement:
                        state.NetworkIn.UpdateUnitMovement(ep, s.ReadString(),
                            new SlimDX.Vector3(s.ReadSingle(), s.ReadSingle(), s.ReadSingle()),
                            new SlimDX.Vector3(s.ReadSingle(), s.ReadSingle(), s.ReadSingle()),
                            s.ReadSingle(), s.ReadBoolean(), s.ReadSingle());
                        break;
                    case Common.S2CProtocol.SetIsDead:
                        state.NetworkIn.SetUnitState(ep, s.ReadString(), (Common.UnitState)s.ReadInt32());
                        break;
                    case Common.S2CProtocol.NPCZombieMove:
                        state.NetworkIn.NPCZombieMove(ep, s.ReadString(),
                            new SlimDX.Vector3(s.ReadSingle(), s.ReadSingle(), s.ReadSingle()),
                            new SlimDX.Vector3(s.ReadSingle(), s.ReadSingle(), s.ReadSingle()));
                        break;
                    case Common.S2CProtocol.NPCZombieStop:
                        state.NetworkIn.NPCZombieStop(ep, s.ReadString(),
                            new SlimDX.Vector3(s.ReadSingle(), s.ReadSingle(), s.ReadSingle()));
                        break;
                    case Common.S2CProtocol.NPCZombiePurchase:
                        state.NetworkIn.NPCZombiePurchase(ep, s.ReadString(),
                            new SlimDX.Vector3(s.ReadSingle(), s.ReadSingle(), s.ReadSingle()),
                            s.ReadString(), s.ReadSingle());
                        break;
                    case Common.S2CProtocol.UpdateCollidingUnitsPosition:
                        {
                            int count = s.ReadInt32();
                            List<Common.Tuple<String, SlimDX.Vector3>> l = new List<Common.Tuple<string, SlimDX.Vector3>>();
                            for (int x = 0; x < count; x++)
                            {
                                String id = s.ReadString();
                                SlimDX.Vector3 pos = new SlimDX.Vector3(s.ReadSingle(), s.ReadSingle(), s.ReadSingle());
                                l.Add(new Common.Tuple<string, SlimDX.Vector3> { First = id, Second = pos });
                            }
                            state.NetworkIn.UpdateCollidingUnitsPosition(ep, l);
                        } break;
                    case Common.S2CProtocol.PlayEffectAtUnit:
                        state.NetworkIn.PlayEffectAtUnit(ep, s.ReadString(), (Common.Effect)s.ReadInt32());
                        break;
                    case Common.S2CProtocol.PlayEffectAtPosition:
                        state.NetworkIn.PlayEffectAtPosition(ep,
                            new SlimDX.Vector3(s.ReadSingle(), s.ReadSingle(), s.ReadSingle()),
                            (Common.Effect)s.ReadInt32());
                        break;
                    case Common.S2CProtocol.PlayEffectMissileToUnit:
                        state.NetworkIn.PlayEffectMissileToUnit(ep,
                            s.ReadString(), s.ReadString(), s.ReadSingle(), (Common.Effect)s.ReadInt32());
                        break;
                    case Common.S2CProtocol.SetTarget:
                        state.NetworkIn.SetTarget(ep, s.ReadString(), s.ReadString(), s.ReadBoolean());
                        break;
                    case Common.S2CProtocol.PlayAnimation:
                        state.NetworkIn.PlayAnimation(ep, s.ReadString(), s.ReadString());
                        break;
                    case Common.S2CProtocol.PlayEffectAtUnitWithLength:
                        state.NetworkIn.PlayEffectAtUnitWithLength(ep, s.ReadString(), (Common.Effect)s.ReadInt32(), s.ReadSingle());
                        break;
                    case Common.S2CProtocol.PlayEffectInAreaWithLength:
                        state.NetworkIn.PlayEffectInAreaWithLength(ep, s.ReadString(), new SlimDX.Vector3(s.ReadSingle(), s.ReadSingle(), s.ReadSingle()), s.ReadSingle(), s.ReadSingle(), (Common.Effect)s.ReadInt32());
                        break;
                    case Common.S2CProtocol.PlayEffectWaveFromUnit:
                        state.NetworkIn.PlayEffectWaveFromUnit(ep, s.ReadString(), s.ReadString(), (Common.Effect)s.ReadInt32());
                        break;
                    case Common.S2CProtocol.StopEffect:
                        state.NetworkIn.StopEffect(ep, s.ReadString(), (Common.Effect)s.ReadInt32());
                        break;
                    case Common.S2CProtocol.AnnounceTierType:
                        state.NetworkIn.AnnounceTierType(ep, s.ReadString());
                        break;
                    case Common.S2CProtocol.AnnounceTierTypeChoice:
                        state.NetworkIn.AnnounceTierTypeChoice(ep);
                        break;
                    case Common.S2CProtocol.AnnounceTierTypeUpgrade:
                        state.NetworkIn.AnnounceTierTypeUpgrade(ep, s.ReadString(), s.ReadInt32());
                        break;
                    //case Common.S2CProtocol.AllyBalanceInformation:
                    //    state.NetworkIn.AllyBalanceInformation(ep, s.ReadBytes((int)(s.BaseStream.Length - s.BaseStream.Position)));
                    //    break;
                    default:
                        {
                            throw new Exception("Urecognized message: " + c);
                        }
                };
                if (Socket == null)
                    return;
            }
        }
示例#36
0
        private void BuildViewMatrix()
        {
            // Keep camera's axes orthogonal to each other and of unit length
            forward.Normalize();

            up = SlimDX.Vector3.Cross(forward, right);
            up.Normalize();

            right = SlimDX.Vector3.Cross(up, forward);
            right.Normalize();

            // Fill in the view matrix entries
            View[0, 0] = right.X;
            View[1, 0] = right.Y;
            View[2, 0] = right.Z;
            View[3, 0] = -SlimDX.Vector3.Dot(Position, right);

            View[0, 1] = up.X;
            View[1, 1] = up.Y;
            View[2, 1] = up.Z;
            View[3, 1] = -SlimDX.Vector3.Dot(Position, up);

            View[0, 2] = forward.X;
            View[1, 2] = forward.Y;
            View[2, 2] = forward.Z;
            View[3, 2] = -SlimDX.Vector3.Dot(Position, forward);

            View[0, 3] = 0.0f;
            View[1, 3] = 0.0f;
            View[2, 3] = 0.0f;
            View[3, 3] = 1.0f;
        }
示例#37
0
        public void Update(float deltaTime)
        {
            // Find the net direction the camera is traveling in (since the
            // camera could be running and strafing).
            var direction = SlimDX.Vector3.Zero;

            if (MovingForwards)
            {
                direction += forward;
            }

            if (MovingBackwards)
            {
                direction -= forward;
            }

            if (StrafingLeft)
            {
                direction -= right;
            }

            if (StrafingRight)
            {
                direction += right;
            }

            direction.Normalize();

            // Move at mSpeed along net direction
            Position += direction * speed * deltaTime;

            //// We rotate at a fixed speed
            //float pitch = Convert.ToSingle(input.MouseDeltaY()) / sensitivity;
            //float angle = Convert.ToSingle(input.MouseDeltaX()) / sensitivity;

            // Rotate camera's look and up vectors around the camera's right vector
            var rotation = SlimDX.Matrix.RotationAxis(right, Pitch);

            forward = SlimDX.Vector3.TransformCoordinate(forward, rotation);
            up = SlimDX.Vector3.TransformCoordinate(up, rotation);

            // Rotate camera axes about the world's y-axis
            rotation = SlimDX.Matrix.RotationY(Angle);

            right = SlimDX.Vector3.TransformCoordinate(right, rotation);
            up = SlimDX.Vector3.TransformCoordinate(up, rotation);
            forward = SlimDX.Vector3.TransformCoordinate(forward, rotation);

            // Rebuild the view matrix to reflect changes
            BuildViewMatrix();
        }
示例#38
0
        public void EnterWorld(uint mapid, string continent, float x, float y)
        {
            MapID = mapid;
            foreach (var file in mFiles)
            {
                file.Unload();
            }

            mFiles.Clear();

            int ix = (int)(x / Utils.Metrics.Tilesize);
            int iy = (int)(y / Utils.Metrics.Tilesize);

            for (int i = -1; i < 2; ++i)
            {
                for (int j = -1; j < 2; ++j)
                {
                    int valX = (int)ix + j;
                    int valY = (int)iy + i;
                    if (valX < 0 || valY < 0)
                        continue;

                    ADT.IADTFile file = ADT.ADTManager.CreateADT(mWdtManager.getWDT(continent), @"World\Maps\" + continent + @"\" + continent + "_" + valX + "_" + valY + ".adt",
                        (uint)valX, (uint)valY, (i == 0 && j == 0));

                    file.Continent = continent;

                    if (file != null)
                        mFiles.Add(file);
                }
            }

            float h = 0.0f;
            GetLandHeightFast(-Utils.Metrics.MidPoint + x, -Utils.Metrics.MidPoint + y, ref h);
            h += 100.0f;
            var inpos = new SlimDX.Vector3(x, y, h);
            inpos.X = -Utils.Metrics.MidPoint + inpos.X;
            inpos.Y = -Utils.Metrics.MidPoint + inpos.Y;
            Game.GameManager.GraphicsThread.GraphicsManager.Camera.SetPosition(inpos);
            isInWorld = true;
            mContinent = continent;
            Game.GameManager.InformPropertyChanged(GameProperties.Map);
        }
示例#39
0
        public void EnterWorld(string continent, uint x, uint y)
        {
            foreach (var file in mFiles)
            {
                file.Unload();
            }

            mFiles.Clear();

            for (int i = -1; i < 2; ++i)
            {
                for (int j = -1; j < 2; ++j)
                {
                    int valX = (int)x + j;
                    int valY = (int)y + i;
                    if (valX < 0 || valY < 0)
                        continue;

                    ADT.IADTFile file = ADT.ADTManager.CreateADT(mWdtManager.getWDT(continent), @"World\Maps\" + continent + @"\" + continent + "_" + valX + "_" + valY + ".adt",
                        (uint)valX, (uint)valY);

                    file.Continent = continent;

                    if (file != null)
                        mFiles.Add(file);
                }
            }

            foreach (var file in mFiles)
            {
                file.WaitLoad();
            }

            var inpos = new SlimDX.Vector3(x * Utils.Metrics.Tilesize + 0.5f * Utils.Metrics.Tilesize, y * Utils.Metrics.Tilesize + 0.5f * Utils.Metrics.Tilesize, 100.0f);
            inpos.X = -Utils.Metrics.MidPoint + inpos.X;
            inpos.Y = -Utils.Metrics.MidPoint + inpos.Y;
            Game.GameManager.GraphicsThread.GraphicsManager.Camera.SetPosition(inpos);
            isInWorld = true;
            mContinent = continent;
        }
        public override void Update(float dt)
        {
            base.Update(dt);

            SlimDX.Vector3 ForwardDir = LookAt - Position;
            SlimDX.Vector3 RightDir = SlimDX.Vector3.Cross(ForwardDir, Up) * -1.0f;

            BasePosition += ((ForwardDir * _forwardSpeed * FlyRate) + (RightDir * _rightSpeed * FlyRate)) * dt * ((_isShiftDown) ? 0.03f : 1.0f);

            // Get camera position from polar coords, plus camera origin
            var x = MathF.SinF(_phi) * MathF.CosF(_theta);
            var z = MathF.SinF(_phi) * MathF.SinF(_theta);
            var y = MathF.CosF(_phi);

            Position = BasePosition;
            LookAt = Position + new SlimDX.Vector3(x, y, z);
        }
        private void CreateBone(ModelBone i, int no)
        {
            var boneid  = i.Name.Replace(" ", "_");
            var bone    = new Bone()       { ID= "Bone-"+boneid, Name= i.Name, };
            var bonenode= new VisualNode() { ID= "Node-"+boneid, Name= i.Name, Instance= bone };
            var trn     = new SlimDX.Vector3(i.Params[0], i.Params[1], i.Params[2]);
            var rot     = new SlimDX.Quaternion(i.Params[3], i.Params[4], i.Params[5], -i.Params[6]);
            var mat     = SlimDX.Matrix.RotationQuaternion(rot)
                        * SlimDX.Matrix.Translation(trn);

            bonenode.SID            = "joint" + no;
            bonenode.LocalTransform = mat;

            Bones.Add(bonenode);
            Root.Instances.Add(bone);

            if(i.ParentID < 0)
            {
                bonenode.GlobalTransform= mat;

                Scene.Nodes.Add(bonenode);
            } else
            {
                var parent              = Bones[i.ParentID];
                bonenode.GlobalTransform= mat * parent.GlobalTransform;
                //bonenode.GlobalTransform= parent.GlobalTransform * mat;

                parent.Nodes.Add(bonenode);
            }
        }
示例#42
0
 void convert(object F)
 {
     const float v_Scale = 65;
     P.startLoading();
     ManagedWorld.NodeLibrary.AddToOcTree = false;
     bool b = FileManager.NotifyOnPhysicalWatch;
     FileManager.NotifyOnPhysicalWatch = false;
     System.IO.FileInfo f0 = new System.IO.FileInfo((string)F);
     SlimDX.Design.Vector3Converter VC = new SlimDX.Design.Vector3Converter();
     SlimDX.Design.QuaternionConverter QC = new SlimDX.Design.QuaternionConverter();
     string[] T = System.IO.File.ReadAllLines((string)F, Encoding.ASCII);
     int l = 0;
     List<ILrentObject> objs = new List<ILrentObject>();
     while (l < T.Length)
     {
         if (T[l++].StartsWith("<Model>"))
         {
             string n = T[l++];
             SlimDX.Vector3 t = (SlimDX.Vector3)VC.ConvertFrom(T[l++]), t2 = new SlimDX.Vector3(-t.Z, t.Y, t.X) * v_Scale;
             SlimDX.Quaternion o = (SlimDX.Quaternion)QC.ConvertFrom(T[l++]), o2 = new SlimDX.Quaternion(-o.Z, o.Y, o.X, o.W);
             SlimDX.Vector3 s = (SlimDX.Vector3)VC.ConvertFrom(T[l++]);
             string p = T[l++], x = p.ToLower().Replace(".obj", "._xmsh"), c = p.ToLower().Replace(".obj", "_COL._xcom"), pf = System.IO.Path.Combine(f0.DirectoryName, p);
             LevelMeshConverter.Convert(P.Device, pf, v_Scale * s, null, null);
             ILrentObject O = newEntityControl.addXMSH(x, c, P.Device, t2, o, P.CurrFile, false);
             objs.Add(O);
             if (l % 5 == 0)
                 P.setPercentage((int)(((float)l / (float)T.Length) * 100.0f));
         }
     }
     FileManager.NotifyOnPhysicalWatch = b;
     update();
     ManagedWorld.NodeLibrary.AddToOcTree = true;
     ManagedWorld.NodeLibrary.OcTree.Build();
     P.endLoading();
     RisenWorld.OnLoadingFinished();
     RisenWorld.OnEntityAdded(objs.ToArray());
 }
        public void ImportOld(string filename, ModelFile model)
        {
            var importer    = new DaeIMImpoter();
            Root            = importer.Import(filename);

            var skins       = Root.Instances.OfType<SkinDeclaraion>    ().ToArray();
            var morphs      = Root.Instances.OfType<MorphingDeclaraion>().ToArray();
            var geoms       = Root.Instances.OfType<Geometry>          ().ToArray();
            Vertices        = new Dictionary<ModelVertex, int>();
            Indices         = new List<int>();
              //Skins           = new Dictionary<int, ModelSkin>();

            if(morphs.Length > 0)
            {
                var geom    = morphs.First().Source as Geometry;
                var mesh    = geom.Get<Mesh>("Data");
                var posch   = mesh.Channels.FirstOrDefault(i => i.Semantic == GeometrySemantic.Position);
                var nrmch   = mesh.Channels.FirstOrDefault(i => i.Semantic == GeometrySemantic.Normal);
                var texch   = mesh.Channels.FirstOrDefault(i => i.Semantic == GeometrySemantic.TexCoord);
                var pos     = posch.GetDataAsList<SlimDX.Vector3>();
                var nrm     = nrmch.GetDataAsList<SlimDX.Vector3>();
                var tex     = texch.GetDataAsList<SlimDX.Vector2>();
                var posface = posch.GetIndicesAsList(mesh);
                var nrmface = nrmch.GetIndicesAsList(mesh);
                var texface = texch.GetIndicesAsList(mesh);
                var numidx  = posface.Count;

                for(int i= 0; i < numidx; ++i)
                {
                    var p   = pos[posface[i]];
                    var n   = nrm[nrmface[i]];
                    var t   = tex[texface[i]];
                    var v   = new ModelVertex()
                    {
                        P   = new Vector3(p.X, p.Y, p.Z),
                        N   = new Vector3(n.X, n.Y, n.Z),
                        T   = new Vector2(t.X, t.Y),
                    };

                    int index;

                    if(!Vertices.TryGetValue(v, out index))
                        Vertices.Add(v, index= Vertices.Count);

                    Indices.Add(index);
                }

                var prims   = new List<ModelPrimitive>();
                var start   = 0;

                foreach(var i in mesh.Primitives)
                {
                    var prim        = new ModelPrimitive();
                    prim.Indices    = Indices.Skip(start).Take(i.Count).Select(j => (ushort)j).ToList();
                    prim.NumIndices = Indices.Count;
                    start           +=Indices.Count;

                    prims.Add(prim);
                }

                model.Mesh.Skins        = Vertices.Keys
                    .Select(i => model.Mesh.Skins[FindClosest(model.Mesh.Vertices, i.P)])
                    .ToList();
                model.Mesh.Vertices     = Vertices.Keys.ToList();
                model.Mesh.NumVerts     = model.Mesh.Vertices.Count;
                model.Mesh.Primitives   = prims;
                model.Mesh.NumPrims     = prims.Count;

                // モーフィング
                model.Params    = model.Params.Where(i => !(i is ParamMorph)).ToList();

                foreach(var i in morphs.First().Channels)
                {
                    var mmesh   = i.Geometry.Get<Mesh>("Data");
                    var mposch  = mmesh.Channels.FirstOrDefault(j => j.Semantic == GeometrySemantic.Position);
                    var mpos    = mposch.GetDataAsList<SlimDX.Vector3>();
                    var mposidx = mposch.GetIndicesAsList(mmesh);
                    var dic     = new Dictionary<int, MorphVertex>();
                    var mnrm    = new SlimDX.Vector3[mpos.Count];

                    // 法線計算
                    for(int j= 0; j < mposidx.Count; j+=3)
                    {
                        var a   = mpos[mposidx[j+0]];
                        var b   = mpos[mposidx[j+1]];
                        var c   = mpos[mposidx[j+2]];
                        var ab  = SlimDX.Vector3.Normalize(SlimDX.Vector3.Subtract(b, a));
                        var ac  = SlimDX.Vector3.Normalize(SlimDX.Vector3.Subtract(c, a));
                        var n   = SlimDX.Vector3.Normalize(SlimDX.Vector3.Cross(ab, ac));

                        mnrm[mposidx[j+0]]  = SlimDX.Vector3.Add(mnrm[mposidx[j+0]], n);
                        mnrm[mposidx[j+1]]  = SlimDX.Vector3.Add(mnrm[mposidx[j+1]], n);
                        mnrm[mposidx[j+2]]  = SlimDX.Vector3.Add(mnrm[mposidx[j+2]], n);
                    }

                    for(int j= 0; j < mnrm.Length; ++j)
                        mnrm[j] = SlimDX.Vector3.Normalize(mnrm[j]);

                    for(int j= 0; j < mposidx.Count; ++j)
                    {
                        var ii  = (ushort)Indices[j];
                        var v   = model.Mesh.Vertices[ii];
                        var p   = mpos[mposidx[j]];
                        var n   = mnrm[mposidx[j]];
                        p.X     -=v.P.X;
                        p.Y     -=v.P.Y;
                        p.Z     -=v.P.Z;
                        n.X     -=v.N.X;
                        n.Y     -=v.N.Y;
                        n.Z     -=v.N.Z;
                        dic[ii] = new MorphVertex(ii, p.X, p.Y, p.Z, n.X, n.Y, n.Z);
                    }

                    var morph   = new ParamMorph()
                    {
                        Name        = i.Geometry.Name,
                        Vertices    = dic.OrderBy(j => j.Key).Select(j => j.Value).ToList(),
                        NumVertices = dic.Count,
                    };

                    model.Params.Insert(0, morph);
                }
            } else
            {
                throw new Exception();
            }

            ModelFile.ToFile(model.FileName, model);

            System.Diagnostics.Debug.Print("終了");
        }
示例#44
0
 /// <summary>
 /// Handles a key down event.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="System.Windows.Forms.KeyEventArgs"/> instance containing the event data.</param>
 private void HandleKeyDown(object sender, KeyEventArgs e)
 {
     if (EnableCamera)
     {
         switch (e.KeyCode)
         {
             case Keys.W:
                 // Move forward in space
                 cameraForwardDirection = 1f;
                 break;
             case Keys.S:
                 // Move backwards in space
                 cameraForwardDirection = -1f;
                 break;
             case Keys.A:
                 // Strafe left
                 cameraStrafeDirection = -1f;
                 break;
             case Keys.D:
                 // Strafe right
                 cameraStrafeDirection = 1f;
                 break;
             case Keys.PageUp:
                 cameraRaiseDirection = 1f;
                 break;
             case Keys.PageDown:
                 cameraRaiseDirection = -1f;
                 break;
             case Keys.R:
                 cameraPosition = new SlimDX.Vector3(0, 0, 10);
                 break;
         }
     }
     OnKeyDown(sender, e);
 }