Ejemplo n.º 1
0
        public Area(string filename)
        {
            this.Set     = 0x584976;
            this.verts   = new List <Vector3>(0);
            this.Names   = new List <string>(0);
            this.Bases   = new List <Vector3[]>(0);
            this.Heights = new List <Vector3>(0);
            this.Links   = new List <Resource>(0);

            this.Type     = Resource.ResourceType.Collision;
            this.Name     = Path.GetFileNameWithoutExtension(filename);
            this.FileName = filename;

            string[]  obj    = File.ReadAllLines(filename);
            string[]  spli   = new string[0];
            Vector3[] plane1 = new Vector3[4];
            Vector3[] plane2 = new Vector3[4];
            plane1[0].X = Single.NaN;
            plane2[0].X = Single.NaN;

            for (int i = 0; i < obj.Length; i++)
            {
                spli = obj[i].Split(' ');
                if (spli[0] == "v")
                {
                    this.verts.Add(new Vector3(MainGame.SingleParse(spli[1]), MainGame.SingleParse(spli[2]), MainGame.SingleParse(spli[3])));
                }

                if (spli[0] == "g")
                {
                    this.Names.Add(spli[1]);
                }
                if (spli[0] == "f")
                {
                    Vector3 v1 = this.verts[int.Parse(spli[1]) - 1];
                    Vector3 v2 = this.verts[int.Parse(spli[2]) - 1];
                    Vector3 v3 = this.verts[int.Parse(spli[3]) - 1];
                    Vector3 v4 = this.verts[int.Parse(spli[4]) - 1];

                    if (Math.Abs(((v1.Y + v2.Y + v3.Y + v4.Y) / 4f) - v1.Y) < 1)
                    {
                        if (Single.IsNaN(plane1[0].X))
                        {
                            plane1[0] = v1;
                            plane1[1] = v2;
                            plane1[2] = v3;
                            plane1[3] = v4;
                        }
                        else if (Single.IsNaN(plane2[0].X))
                        {
                            plane2[0] = v1;
                            plane2[1] = v2;
                            plane2[2] = v3;
                            plane2[3] = v4;

                            if (plane2[0].Y > plane1[0].Y)
                            {
                                this.Bases.Add(plane1);
                                this.Heights.Add(new Vector3(0, plane2[0].Y - plane1[0].Y, 0));
                            }
                            else
                            {
                                this.Bases.Add(plane2);
                                this.Heights.Add(new Vector3(0, plane1[0].Y - plane2[0].Y, 0));
                            }
                            plane1      = new Vector3[4];
                            plane2      = new Vector3[4];
                            plane1[0].X = Single.NaN;
                            plane2[0].X = Single.NaN;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public Scene(string fname)
        {
            this.Commands     = new List <SceneCommand>(0);
            this.Instructions = new List <object>(0);
            this.StartFrames  = new List <int>(0);

            string[] content = File.ReadAllLines(@"Content\Scenes\" + fname + ".txt");
            string[] spli1, spli2;
            for (int i = 0; i < content.Length; i++)
            {
                spli1 = content[i].Split('|');
                spli2 = spli1[2].Split(';');
                int startFrame = int.Parse(spli1[0]);

                switch (spli1[1])
                {
                case "Goto":
                    if (startFrame > this.MaxFrame)
                    {
                        this.MaxFrame = startFrame;
                    }

                    Model mdl_ = null;
                    for (int r = 0; r < MainGame.ResourceFiles.Count; r++)
                    {
                        if (MainGame.ResourceFiles[r].Name == spli2[0])
                        {
                            mdl_ = MainGame.ResourceFiles[r] as Model;
                            break;
                        }
                    }
                    Vector3 dest = new Vector3(MainGame.SingleParse(spli2[1]), MainGame.SingleParse(spli2[2]), MainGame.SingleParse(spli2[3]));

                    this.Instructions.Add(new GotoDest(mdl_, dest));
                    this.Commands.Add(SceneCommand.Goto);
                    break;

                case "SetBGMVolume":
                    if (startFrame > this.MaxFrame)
                    {
                        this.MaxFrame = startFrame;
                    }

                    this.Instructions.Add(new int[] { int.Parse(spli1[2]), int.Parse(spli1[3]) });
                    this.Commands.Add(SceneCommand.SetBGMVolume);
                    break;

                case "ContactCollison":
                    if (startFrame > this.MaxFrame)
                    {
                        this.MaxFrame = startFrame;
                    }

                    this.Instructions.Add(Boolean.Parse(spli2[0]));
                    this.Commands.Add(SceneCommand.ContactCollison);
                    break;

                case "SetCamera":
                    if (startFrame > this.MaxFrame)
                    {
                        this.MaxFrame = startFrame;
                    }
                    Vector3[] insts = new Vector3[spli2.Length / 3];
                    for (int n = 0; n < spli2.Length; n++)
                    {
                        float val = Single.NaN;
                        Single.TryParse(spli2[n], out val);

                        if (n % 3 == 0)
                        {
                            insts[n / 3].X = val;
                        }
                        if (n % 3 == 1)
                        {
                            insts[n / 3].Y = val;
                        }
                        if (n % 3 == 2)
                        {
                            insts[n / 3].Z = val;
                        }
                    }
                    this.Instructions.Add(insts);
                    this.Commands.Add(SceneCommand.SetCamera);
                    break;

                case "Gameplay":
                    if (startFrame > this.MaxFrame)
                    {
                        this.MaxFrame = startFrame;
                    }
                    this.Instructions.Add(null);
                    this.Commands.Add(SceneCommand.Gameplay);
                    break;

                case "PlayAnim":
                    Animation anm = new Animation();

                    for (int n = 0; n < spli2.Length; n += 6)
                    {
                        spli2[n + 0] = spli2[n + 0].Replace("player", Program.game.Player.Name);
                        spli2[n + 1] = spli2[n + 1].Replace("player", Program.game.Player.Name);
                        Model         mdl  = null;
                        BinaryMoveset mset = null;
                        for (int r = 0; r < MainGame.ResourceFiles.Count; r++)
                        {
                            if (MainGame.ResourceFiles[r].Name == spli2[n + 0])
                            {
                                mdl = MainGame.ResourceFiles[r] as Model;
                                break;
                            }
                        }
                        if (mdl == null)
                        {
                            for (int r = 0; r < Program.game.Map.Supp.Count; r++)
                            {
                                if (Program.game.Map.Supp[r].Name == spli2[n + 0])
                                {
                                    mdl = Program.game.Map.Supp[r] as Model;
                                    break;
                                }
                            }
                        }
                        if (mdl == null)
                        {
                            mdl = new DAE(@"Content\Models\" + spli2[n + 0] + @"\" + spli2[n + 0] + ".dae");
                            mdl.Parse();
                            MainGame.ResourceFiles.Add(mdl);
                            mdl.Render = false;
                        }

                        mdl.Cutscene = true;
                        int index = -1;
                        if (mdl.Links.Count > 0)
                        {
                            (mdl.Links[0] as BinaryMoveset).PlayingIndex = -1;
                        }

                        if (int.TryParse(spli2[n + 1], out index))
                        {
                            if (mdl.Links.Count == 0)
                            {
                                mset = new BinaryMoveset(mdl.FileName.Replace(mdl.Name + ".dae", @"\MSET"));
                                mset.Links.Add(mdl);
                                mset.Parse();
                                MainGame.ResourceFiles.Add(mset);
                                mdl.Links.Add(mset);
                            }
                            else
                            {
                                mset = (mdl.Links[0] as BinaryMoveset);
                            }
                        }
                        else
                        {
                            string name = Path.GetFileNameWithoutExtension(@"Content\Scenes\ANB\" + spli2[n + 1]);

                            for (int r = 0; r < MainGame.ResourceFiles.Count; r++)
                            {
                                if (MainGame.ResourceFiles[r].Name == name)
                                {
                                    mset = MainGame.ResourceFiles[r] as BinaryMoveset;
                                }
                            }
                            if (mset == null)
                            {
                                mset = new BinaryMoveset(@"Content\Scenes\ANB\" + spli2[n + 1]);
                                MainGame.ResourceFiles.Add(mset);
                            }
                            index = 0;
                        }
                        mset.Render = true;


                        if (mset.Links.Count == 0)
                        {
                            mset.Links.Add(mdl);
                        }

                        mset.Skeleton = mdl.Skeleton;
                        if (mdl.Links.Count > 0)
                        {
                            mset.Voices = (mdl.Links[0] as Moveset).Voices;
                        }

                        //mset.Parse();

                        Vector3 startPos = Vector3.Zero;
                        startPos.X = MainGame.SingleParse(spli2[n + 2]);
                        startPos.Y = MainGame.SingleParse(spli2[n + 3]);
                        startPos.Z = MainGame.SingleParse(spli2[n + 4]);
                        float rot = MainGame.SingleParse(spli2[n + 5]);
                        anm.Append(mdl, mset, index, startPos, rot);

                        if (startFrame + mset.MaxTick > this.MaxFrame)
                        {
                            this.MaxFrame = startFrame + mset.MaxTick;
                        }
                    }
                    this.Instructions.Add(anm);
                    this.Commands.Add(SceneCommand.PlayAnim);
                    break;
                }
                this.StartFrames.Add(startFrame);
            }
        }
Ejemplo n.º 3
0
        public Collision(string filename)
		{
			this.Type = ResourceType.Collision;
            this.Name = Path.GetFileNameWithoutExtension(filename);
            this.FileName = filename;
            this.cols = new List<Vector3>(0);
            this.norms = new List<Vector3>(0);
            this.indices = new List<int[][]>(0);
            this.StartEnds = new int[1000][];
            this.PolyCount = 0;

            string[] obj = File.ReadAllLines(filename);
            string[] spli = obj[0].Split('#');
            if (spli.Length == 3)
            {
                Program.game.backgroundColor.R = byte.Parse(spli[0]);
                Program.game.backgroundColor.G = byte.Parse(spli[1]);
                Program.game.backgroundColor.B = byte.Parse(spli[2]);
            }

            int lastIndex = -1;

            for (int i=0;i<obj.Length;i++)
            {
                spli = obj[i].Split(' ');
                if (spli[0] == "v")
                {
                    Vector3 v = new Vector3(MainGame.SingleParse(spli[1]), MainGame.SingleParse(spli[2]), MainGame.SingleParse(spli[3]));
                    if (v.X < MinX) MinX = v.X;
                    if (v.Y < MinY) MinY = v.Y;
                    if (v.Z < MinZ) MinZ = v.Z;
                    if (v.X > MaxX) MaxX = v.X;
                    if (v.Y > MaxY) MaxY = v.Y;
                    if (v.Z > MaxZ) MaxZ = v.Z;

                    cols.Add(v);
                }
                if (spli[0] == "vn")
                {
                    norms.Add(new Vector3(MainGame.SingleParse(spli[1]), MainGame.SingleParse(spli[2]), MainGame.SingleParse(spli[3])));
                }
                if (spli[0] == "g")
                {
                    if (spli[1].Contains("poly"))
                    {
                        int index = int.Parse(spli[1].Substring(4, spli[1].Length-4));

                        if (lastIndex>-1)
                        {
                            StartEnds[lastIndex][1] = indices.Count;
                        }
                        StartEnds[index] = new int[] { indices.Count, 0 };
                        this.PolyCount++;
                        lastIndex = index;
                    }
                    if (spli[1].Contains("perimetre"))
                    {
                        int index = 500+int.Parse(spli[1].Substring(9, spli[1].Length - 9));

                        if (lastIndex > -1)
                        {
                            StartEnds[lastIndex][1] = indices.Count;
                        }
                        StartEnds[index] = new int[] { indices.Count ,0};
                        lastIndex = index;
                    }
                }
                if (spli[0] == "f")
                {
                    int[][] vals = new int[][] { new int[2] , new int[2] , new int[2] };

                    string[] spli_ = spli[1].Split('/');
                    vals[0][0] = int.Parse(spli_[0]) - 1;
                    vals[0][1] = int.Parse(spli_[2]) - 1;

                    spli_ = spli[2].Split('/');
                    vals[1][0] = int.Parse(spli_[0]) - 1;
                    vals[1][1] = int.Parse(spli_[2]) - 1;

                    spli_ = spli[3].Split('/');
                    vals[2][0] = int.Parse(spli_[0]) - 1;
                    vals[2][1] = int.Parse(spli_[2]) - 1;

                    

                    this.indices.Add(vals);
                }
            }
            if (PolyCount == 0)
            {
                this.PolyCount = 1;
                StartEnds[0] = new int[] { 0, this.indices.Count };
            }
            if (lastIndex>-1)
            {
                if (lastIndex >= 500)
                {
                    lastIndex -= 500;
                }
				if (StartEnds[lastIndex + 500] == null)
				{
					StartEnds[lastIndex][1] = this.indices.Count;
				}
				else
				{
					StartEnds[lastIndex][1] = StartEnds[lastIndex + 500][0];
					StartEnds[lastIndex + 500][1] = indices.Count;
				}
			}
		}
Ejemplo n.º 4
0
        public static void MonitorCollision(Model sujet, ref Vector3 pos)
        {
			var collision = Program.game.MapSet ? Program.game.Map.Links[0] as Collision : null;

			if (sujet.Epaisseur < 0.1)
				return;

            bool jumping = sujet.Location.Y> sujet.LowestFloor+sujet.StairHeight && pos.Y > sujet.Location.Y;

            Vector3 refPosBottom = pos + new Vector3(0, sujet.StairHeight, 0);
            Vector3 refPosTop = pos + new Vector3(0, sujet.MaxVertex.Y, 0);

            Vector3 inter;
            Vector3 shadowAngle = Vector3.Zero;
            Vector3 globalBone0 = sujet.GetGlobalBone(0, Vector3.Zero);
            globalBone0.Y = sujet.MinVertex.Y;

            float tallest = Single.MinValue;
            float smallest = Single.MaxValue;
            shadowAngle = Vector3.Zero;
			
            Vector3 forwardCliffStart = new Vector3(0, 10f, sujet.Epaisseur * 1.1f);
            Vector3 forwardCliffEnd = new Vector3(0, -10f, sujet.Epaisseur * 1.1f);


            forwardCliffStart = Vector3.Transform(forwardCliffStart, sujet.Rotate_matrix);
            forwardCliffEnd = Vector3.Transform(forwardCliffEnd, sujet.Rotate_matrix);
            cliffBackwards = Vector3.Transform(cliffBackwards, sujet.Rotate_matrix);






			bool pushed = false;


            sujet.Attached = false;
			int moreRes = 0;
			if (Program.game.MapSet)
				moreRes = Program.game.Map.Supp.Count;

			if ((ScenePlayer.ScenePlaying  && ScenePlayer.AllowContactCollision) ||
                !ScenePlayer.ScenePlaying)
            if (!sujet.NPC && sujet.cState != Model.ControlState.Cliff)
            for (int i = 0; i < MainGame.ResourceFiles.Count + moreRes; i++)
            {
                Model mdl = null;
                if (i >= MainGame.ResourceFiles.Count)
                    mdl = Program.game.Map.Supp[i- MainGame.ResourceFiles.Count] as Model;
                else
                    mdl = MainGame.ResourceFiles[i] as Model;

				if (mdl == null) continue;
                if (sujet.ResourceIndex == mdl.ResourceIndex) continue;
				if (mdl.Collision == null)
				{
					if (mdl.Epaisseur < 1) continue;
							if (mdl.NPC || sujet.Masse <= mdl.Masse)
							{
								Vector2 sujetPos = new Vector2(pos.X, pos.Z);
								Vector2 mdlPos = new Vector2(mdl.Location.X, mdl.Location.Z);

								if (sujet.Location.Y > mdl.Location.Y-mdl.StairHeight*2f && sujet.Location.Y<mdl.Location.Y+mdl.MaxVertex.Y)
								{
									float hypo = Vector2.Distance(sujetPos, mdlPos);
									sujetPos -= mdlPos;
									sujetPos /= hypo;
									if (hypo < (mdl.Epaisseur + sujet.Epaisseur))
									{
										sujetPos = mdlPos + sujetPos * (mdl.Epaisseur + sujet.Epaisseur) * 1.1f;
										pos.X = sujetPos.X;
										pos.Z = sujetPos.Y;
									}
									/*else
									if (sujet.ResourceIndex == Program.game.mainCamera.Target.ResourceIndex &&  hypo < (mdl.Epaisseur + sujet.Epaisseur)*2f)
									{
										float val1 = (float)Math.Atan2(sujetPos.X, sujetPos.Y);
										float val2 = sujet.DestRotate + MainGame.PI;
										SrkBinary.MakePrincipal(ref val1);
										SrkBinary.MakePrincipal(ref val2);


										if (Math.Abs(val1-val2) < 1)
										{
											if (Program.game.mainCamera.LXY_read==0)
											{
												Program.game.mainCamera.LXY_read = 10;
												float cam_mdl_diff = (float)(Math.Atan2(Program.game.mainCamera.joyLY_, Program.game.mainCamera.joyLX_) + MathHelper.ToRadians(33));

												Program.game.mainCamera.joyLY_ = (float)Math.Sin(cam_mdl_diff);
												Program.game.mainCamera.joyLX_ = (float)Math.Cos(cam_mdl_diff);
											}
										}
									}*/
								}
							}
				}
				else


				for (int p=0;p< mdl.Collision.PolyCount; p++)
				{
					int start_ = mdl.Collision.StartEnds[p][0];
					int end_ = mdl.Collision.StartEnds[p][1];
					for (int j = start_; j < end_; j++)
					{
						Matrix mt = mdl.Skeleton.Bones[p].LocalMatrix;

						if (Vector3.Distance(mdl.Location,Vector3.Zero) > 0)
							mt = Matrix.Identity;
						Vector3 v1 = Vector3.Transform(
							Vector3.Transform(mdl.Collision.cols[mdl.Collision.indices[j][0][0]], mt), mdl.Rotate_matrix) + mdl.Location;
						Vector3 v2 = Vector3.Transform(
							Vector3.Transform(mdl.Collision.cols[mdl.Collision.indices[j][1][0]], mt), mdl.Rotate_matrix) + mdl.Location;
						Vector3 v3 = Vector3.Transform(
							Vector3.Transform(mdl.Collision.cols[mdl.Collision.indices[j][2][0]], mt), mdl.Rotate_matrix) + mdl.Location;

									var mt_mat = Matrix.CreateFromQuaternion(mt.Rotation);
						Vector3 n1 = Vector3.Transform(mdl.Collision.norms[mdl.Collision.indices[j][0][1]], mt_mat);
						Vector3 n2 = Vector3.Transform(mdl.Collision.norms[mdl.Collision.indices[j][1][1]], mt_mat);
						Vector3 n3 = Vector3.Transform(mdl.Collision.norms[mdl.Collision.indices[j][2][1]], mt_mat);
						Vector3 normal = (n1 + n2 + n3) / 3f;
                        
						if (mdl.NPC || sujet.Masse <= mdl.Masse)
						{
							bool newAttach = false;
							if (!ScenePlayer.ScenePlaying && normal.Y < -0.5)
								if (Inside(refPosTop, v1 - 10f * n1, v2 - 10f * n2, v3 - 10f * n3, v1 + sujet.Epaisseur * n1, v2 + sujet.Epaisseur * n2, v3 + sujet.Epaisseur * n3))
								{
									if (normal.Y < -0.5)
										sujet.JumpCollisionCancel = true;
									Vector3 direction = refPosTop + normal * sujet.Epaisseur;
									if (intersect3D_RayTriangle(refPosTop, direction, v1, v2, v3, out inter) == 1)
									{
										//pos += ((inter + new Vector3(0, -height, 0))- pos)/10f;
										pos = (inter + new Vector3(0, -(sujet.MaxVertex.Y), 0));
										if (pos.Y < sujet.LowestFloor)
											pos.Y = sujet.LowestFloor;

										refPosTop = pos + new Vector3(0, sujet.MaxVertex.Y, 0);
									}
								}
							if (!ScenePlayer.ScenePlaying && Math.Abs(normal.Y) < 0.5f)
							{
								if (Inside(refPosBottom, v1 - 10f * n1, v2 - 10f * n2, v3 - 10f * n3, v1 + sujet.Epaisseur * n1, v2 + sujet.Epaisseur * n2, v3 + sujet.Epaisseur * n3))
								{
									Vector3 direction = refPosBottom + normal * sujet.Epaisseur * 10f;
									if (jumping && normal.Y < -0.5)
										sujet.JumpCollisionCancel = true;
									if (intersect3D_RayTriangle(refPosBottom, direction, v1 + sujet.Epaisseur * n1, v2 + sujet.Epaisseur * n2, v3 + sujet.Epaisseur * n3, out inter) == 1)
									{
										pos.X = inter.X;
										pos.Z = inter.Z;
										refPosBottom = pos + new Vector3(0, sujet.StairHeight, 0);
									}
								}

								if (Inside(refPosTop, v1 - 20f * n1, v2 - 20f * n2, v3 - 20f * n3, v1 + sujet.Epaisseur * n1, v2 + sujet.Epaisseur * n2, v3 + sujet.Epaisseur * n3))
								{
									Vector3 direction = refPosTop + normal * sujet.Epaisseur * 10f;
									if (intersect3D_RayTriangle(refPosTop, direction, v1 + sujet.Epaisseur * n1, v2 + sujet.Epaisseur * n2, v3 + sujet.Epaisseur * n3, out inter) == 1)
									{
										pos.X = inter.X;
										pos.Z = inter.Z;
										refPosTop = pos + new Vector3(0, sujet.MaxVertex.Y, 0);
									}
								}
							}
							else if (normal.Y > 0.5)
							{
								if (intersect3D_RayTriangle(pos + globalBone0 + new Vector3(0, 50000, 0), pos + globalBone0 + new Vector3(0, -50000, 0), v1, v2, v3, out inter) == 1)
								{
									if (Math.Abs(inter.Y-pos.Y)<sujet.StairHeight)
									{
										if (inter.Y < smallest)
										{
											smallest = inter.Y;
										}
										if (inter.Y <= sujet.Location.Y + sujet.StairHeight * 1.5f && inter.Y > tallest)
										{
											shadowAngle = new Vector3(
											0,
											(float)Math.Atan2(normal.Z, normal.Y),
											(float)Math.Atan2(-normal.X, normal.Y));
											tallest = inter.Y;
										}
									}
								}
							}
							if (tallest > Single.MinValue / 2f)
							{
								if (tallest < sujet.Location.Y + sujet.StairHeight * 1.5f)
								{
									sujet.LowestFloor = tallest;
									newAttach = true;
								}
							}
							else if (smallest < Single.MaxValue / 2f)
							{
								if (smallest < sujet.Location.Y + sujet.StairHeight * 1.5f)
								{
									sujet.LowestFloor = smallest;
									newAttach = true;
								}
							}
							if (newAttach && Math.Abs(pos.Y-sujet.LowestFloor)<1)
							{
											if (collision!=null)
												collision.AttachTo(mdl, sujet);
							}
                        
							/*if (!ScenePlayer.ScenePlaying && Math.Abs(normal.Y) < 0.5f)
							{
								if (Inside(refPosBottom, v1 - 20f * n1, v2 - 20f * n2, v3 - 20f * n3, v1 + sujet.Epaisseur * n1, v2 + sujet.Epaisseur * n2, v3 + sujet.Epaisseur * n3))
								{
									Vector3 direction = refPosBottom + normal * sujet.Epaisseur * 10f;

									if (intersect3D_RayTriangle(refPosBottom, direction, v1 + sujet.Epaisseur * n1, v2 + sujet.Epaisseur * n2, v3 + sujet.Epaisseur * n3, out inter) == 1)
									{
										pushed = true;
										pos.X = inter.X;
										pos.Z = inter.Z;
										refPosBottom = pos + new Vector3(0, sujet.StairHeight, 0);
									}
								}

								if (Inside(refPosTop, v1 - 20f * n1, v2 - 20f * n2, v3 - 20f * n3, v1 + sujet.Epaisseur * n1, v2 + sujet.Epaisseur * n2, v3 + sujet.Epaisseur * n3))
								{
									Vector3 direction = refPosTop + normal * sujet.Epaisseur * 10f;
									if (intersect3D_RayTriangle(refPosTop, direction, v1 + sujet.Epaisseur * n1, v2 + sujet.Epaisseur * n2, v3 + sujet.Epaisseur * n3, out inter) == 1)
									{
										pushed = true;
										pos.X = inter.X;
										pos.Z = inter.Z;
										refPosTop = pos + new Vector3(0, sujet.MaxVertex.Y, 0);
									}
								}
							}*/
						}
                    

					}

				}
            }
            sujet.ShadowMatrixSurface = Matrix.CreateFromYawPitchRoll(shadowAngle.X, shadowAngle.Y, shadowAngle.Z);
			bool cliff = sujet.cState == Model.ControlState.Cliff || sujet.cState == Model.ControlState.UnCliff;

			if (collision == null)
				return;
			collision.UpdateIndex(sujet.Location);

			int start = collision.StartEnds[collision.CurrIndex][0];
			int end = collision.StartEnds[collision.CurrIndex][1];
			for (int i = start; i < end; i++)
            {
                Vector3 v1 = collision.cols[collision.indices[i][0][0]];
                Vector3 v2 = collision.cols[collision.indices[i][1][0]];
                Vector3 v3 = collision.cols[collision.indices[i][2][0]];

                Vector3 n1 = collision.norms[collision.indices[i][0][1]];
                Vector3 n2 = collision.norms[collision.indices[i][1][1]];
                Vector3 n3 = collision.norms[collision.indices[i][2][1]];
                Vector3 normal = (n1 + n2 + n3) / 3f;


                if (!cliff && !ScenePlayer.ScenePlaying && normal.Y < -0.5)
                if (Inside(refPosTop, v1 - 20f * n1, v2 - 20f * n2, v3 - 20f * n3, v1 + sujet.Epaisseur * n1, v2 + sujet.Epaisseur * n2, v3 + sujet.Epaisseur * n3))
                {
                    Vector3 direction = refPosTop + normal * sujet.Epaisseur;
                    if (intersect3D_RayTriangle(refPosTop, direction, v1, v2, v3, out inter) == 1)
                    {
                        //pos += ((inter + new Vector3(0, -height, 0))- pos)/10f;
                        pos = (inter + new Vector3(0, -(sujet.MaxVertex.Y), 0));
                        if (pos.Y < sujet.LowestFloor)
                            pos.Y = sujet.LowestFloor;

                        refPosTop = pos + new Vector3(0, sujet.MaxVertex.Y, 0);
                    }
                }
                if (!cliff && !ScenePlayer.ScenePlaying && Math.Abs(normal.Y) < 0.5f)
                {
                    if (Inside(refPosBottom, v1-20f*n1, v2 - 20f * n2, v3 - 20f * n3, v1 + sujet.Epaisseur * n1, v2 + sujet.Epaisseur * n2, v3 + sujet.Epaisseur * n3))
                    {
                        Vector3 direction = refPosBottom + normal * sujet.Epaisseur * 10f;
                        if (jumping && normal.Y < -0.5)
                            sujet.JumpCollisionCancel = true;
                        if (intersect3D_RayTriangle(refPosBottom, direction, v1 + sujet.Epaisseur * n1, v2 + sujet.Epaisseur * n2, v3 + sujet.Epaisseur * n3, out inter) == 1)
                        {
                            pos = (inter + new Vector3(0, -sujet.StairHeight, 0));
                            refPosBottom = pos + new Vector3(0, sujet.StairHeight, 0);
                        }
                    }

                    if (Inside(refPosTop, v1 - 20f * n1, v2 - 20f * n2, v3 - 20f * n3, v1 + sujet.Epaisseur * n1, v2 + sujet.Epaisseur * n2, v3 + sujet.Epaisseur * n3))
                    {
                        Vector3 direction = refPosTop + normal * sujet.Epaisseur * 10f;
                        if (intersect3D_RayTriangle(refPosTop, direction, v1 + sujet.Epaisseur * n1, v2 + sujet.Epaisseur * n2, v3 + sujet.Epaisseur * n3, out inter) == 1)
                        {
                            pos = (inter + new Vector3(0, -(sujet.MaxVertex.Y), 0));
                            if (pos.Y < sujet.LowestFloor)
                                pos.Y = sujet.LowestFloor;

                            refPosTop = pos + new Vector3(0, sujet.MaxVertex.Y, 0);
                        }
                    }
                }
                else if (normal.Y>0.5)
				{
					if (!cliff && !ScenePlayer.ScenePlaying && sujet.cState == Model.ControlState.Fall && !sujet.CliffCancel && (sujet.Links.Count == 0 || sujet.Links[0].ResourceIndex != 39))
                    {
                        if (intersect3D_RayTriangle(refPosTop + forwardCliffStart, refPosTop + forwardCliffEnd, v1, v2, v3, out inter) == 1 && inter.Y > refPosTop.Y + forwardCliffEnd.Y)
                        {
                            Vector3 coin = inter;


							int ordre = 0;  /* V1V2  V2V3  V3V1*/
							float nearest = Single.MaxValue;

							Vector3 va_vb = v1 * 1f;
							Vector3 step_va_vb = (v2 - v1) / Vector3.Distance(v2, v1);
							
							while (Vector3.Distance(va_vb, v2) > sujet.Epaisseur * 2f)
							{
								va_vb += step_va_vb;
								float dist2d = MainGame.Vector3Distance2D(va_vb, refPosTop);
								if (dist2d < nearest)
								{
									coin = va_vb * 1f;
									nearest = dist2d;
									ordre = 0;
								}
							}

							va_vb = v2 * 1f;
							step_va_vb = (v3 - v2) / Vector3.Distance(v3, v2);

							while (Vector3.Distance(va_vb, v3) > sujet.Epaisseur * 2f)
							{
								va_vb += step_va_vb;
								float dist2d = MainGame.Vector3Distance2D(va_vb, refPosTop);
								if (dist2d < nearest)
								{
									coin = va_vb * 1f;
									nearest = dist2d;
									ordre = 1;
								}
							}

							va_vb = v3 * 1f;
							step_va_vb = (v1 - v3) / Vector3.Distance(v1, v3);

							while (Vector3.Distance(va_vb, v1) > sujet.Epaisseur * 2f)
							{
								va_vb += step_va_vb;
								float dist2d = MainGame.Vector3Distance2D(va_vb, refPosTop);
								if (dist2d < nearest)
								{
									coin = va_vb *1f;
									nearest = dist2d;
									ordre = 2;
								}
							}


							float angle = 0;

                            if (ordre == 0)
                            {
                                Vector3 v1v2Base = v2 - v1;
                                v1v2Base /= Vector3.Distance(Vector3.Zero, v1v2Base);
                                angle = (float)Math.Atan2(v1v2Base.X, v1v2Base.Z);
                            }
                            if (ordre == 1)
                            {
                                Vector3 v2v3Base = v3 - v2;
                                v2v3Base /= Vector3.Distance(Vector3.Zero, v2v3Base);
                                angle = (float)Math.Atan2(v2v3Base.X, v2v3Base.Z);
                            }
                            if (ordre == 2)
                            {
                                Vector3 v3v1Base = v1 - v3;
                                v3v1Base /= Vector3.Distance(Vector3.Zero, v3v1Base);
                                angle = (float)Math.Atan2(v3v1Base.X, v3v1Base.Z);
							}


							if (coin.Y > sujet.LowestFloor + sujet.MaxVertex.Y)
                            {
								float newDest = angle + MainGame.PI / 2f;
								SrkBinary.MakePrincipal(ref newDest);

								sujet.DestRotate = newDest;
                                sujet.Rotate = sujet.DestRotate;
                                sujet.cState = Model.ControlState.Cliff;

								//Program.game.cursors[0].Position = coin;
								/*try
                                {
                                    string[] input = File.ReadAllLines("data.txt");
                                    cliffBackwards.X = MainGame.SingleParse(input[0]);
                                    cliffBackwards.Y = MainGame.SingleParse(input[1]);
                                    cliffBackwards.Z = MainGame.SingleParse(input[2]);
                                    cliffBackwards = Vector3.Transform(cliffBackwards, rotYMat);

                                }
                                catch
                                {

                                }*/
								

								/*string[] text = File.ReadAllLines(@"D:\Desktop\KHDebug\KHDebug\bin\DesktopGL\AnyCPU\Debug\Content\Models\P_EX100\Joints.txt");
								text = text[9].Split(':')[1].Split(',');
								sujet.CliffPosition.X = MainGame.SingleParse(text[0]);
								sujet.CliffPosition.Y = MainGame.SingleParse(text[1]);
								sujet.CliffPosition.Z = MainGame.SingleParse(text[2]);*/

								cliffBackwards = Vector3.Transform(sujet.CliffPosition, sujet.Rotate_matrix);
                                pos = coin - cliffBackwards;

								sujet.locBlock = 10;
								sujet.loc = pos;
								sujet.locAction = sujet.loc;

								return;
                            }

                            
                        }

                    }

                    if (intersect3D_RayTriangle(pos + globalBone0+new Vector3(0, 50000, 0), pos + globalBone0 + new Vector3(0, -50000, 0), v1, v2, v3, out inter) ==1)
                    {
						if (Single.IsNaN(sujet.LastLand.X))
						{
							if (inter.Y < smallest)
							{
								smallest = inter.Y;
							}
							if (inter.Y <= sujet.Location.Y + sujet.StairHeight * 1.5f && inter.Y > tallest)
							{
								shadowAngle = new Vector3(
								0,
								(float)Math.Atan2(normal.Z, normal.Y),
								(float)Math.Atan2(-normal.X, normal.Y));
								tallest = inter.Y;
							}
						}
                    }
                }
                if (tallest > Single.MinValue / 2f)
                {
                    if (tallest <sujet.Location.Y + sujet.StairHeight * 1.5f)
                    sujet.LowestFloor = tallest;
                }
                else if (smallest < Single.MaxValue / 2f)
                {
                    if (smallest < sujet.Location.Y + sujet.StairHeight * 1.5f)
                        sujet.LowestFloor = smallest;
                }
            }
            sujet.ShadowMatrixSurface = Matrix.CreateFromYawPitchRoll(shadowAngle.X, shadowAngle.Y, shadowAngle.Z);
            if (pushed && pos.Y<sujet.LowestFloor)
            {
                pos.Y = sujet.LowestFloor;
            }
        }
Ejemplo n.º 5
0
        public static void Load(string filename)
        {
            for (int i = 0; i < MainGame.ResourceFiles.Count; i++)
            {
                if (!(MainGame.ResourceFiles[i] is MAP))
                {
                    MainGame.ResourceFiles[i].Render = false;
                }
            }
            string[] contenu = File.ReadAllLines(filename);
            string[] spli;

            if (Program.game.MapSet && File.Exists(@"Content\Scenes\Behaviours\" + contenu[0]))
            {
                string[] text = File.ReadAllLines(@"Content\Scenes\Behaviours\" + contenu[0]);
                for (int i = 0; i < text.Length; i++)
                {
                    spli = text[i].Split('|');

                    if (spli[0].Length > 1 && spli[0][0] == 'I' && spli[0][1] == 'F')
                    {
                        Action action = new Action();
                        action.parent = Program.game.Map;
                        action.AddCondition(text[i]);
                        while (spli[0] != "ENDIF")
                        {
                            i++;
                            spli = text[i].Split('|');
                            if (spli[0] == "ELSE" || spli[0] == "AND" || spli[0] == "OR")
                            {
                                action.AddCondition(text[i]);
                            }
                            else
                            {
                                action.AddComand(text[i]);
                            }
                        }
                        Program.game.Map.Behaviours[Program.game.Map.BehavioursCount] = action;
                        Program.game.Map.BehavioursCount++;
                    }
                }
            }

            spli = contenu[0 + 2].Split(',');
            LoadCharacter(spli[0], spli[1], ref Program.game.Player);
            spli = contenu[1 + 2].Split(',');
            LoadKeyblade(spli[0], spli[1], ref Program.game.Player);

            if (Program.game.Player != null)
            {
                spli = contenu[2 + 2].Split(',');
                Program.game.Player.Location        = new Vector3(MainGame.SingleParse(spli[0]), MainGame.SingleParse(spli[1]), MainGame.SingleParse(spli[2]));
                Program.game.Player.SpawnedLocation = Program.game.Player.Location;
                Program.game.Player.LowestFloor     = Program.game.Player.Location.Y;
                Program.game.Player.DestRotate      = MainGame.SingleParse(contenu[3 + 2]);
                Program.game.Player.Rotate          = Program.game.Player.DestRotate;
            }

            spli = contenu[5 + 2].Split(',');
            LoadCharacter(spli[0], spli[1], ref Program.game.Partner1);
            spli = contenu[6 + 2].Split(',');
            LoadKeyblade(spli[0], spli[1], ref Program.game.Partner1);

            if (Program.game.Partner1 != null)
            {
                spli = contenu[7 + 2].Split(',');
                Program.game.Partner1.Location        = new Vector3(MainGame.SingleParse(spli[0]), MainGame.SingleParse(spli[1]), MainGame.SingleParse(spli[2]));
                Program.game.Partner1.SpawnedLocation = Program.game.Partner1.Location;
                Program.game.Partner1.LowestFloor     = Program.game.Partner1.Location.Y;
                Program.game.Partner1.DestRotate      = MainGame.SingleParse(contenu[8 + 2]);
                Program.game.Partner1.Rotate          = Program.game.Partner1.DestRotate;
            }

            spli = contenu[10 + 2].Split(',');
            LoadCharacter(spli[0], spli[1], ref Program.game.Partner2);
            spli = contenu[11 + 2].Split(',');
            LoadKeyblade(spli[0], spli[1], ref Program.game.Partner2);

            if (Program.game.Partner2 != null)
            {
                spli = contenu[12 + 2].Split(',');
                Program.game.Partner2.Location        = new Vector3(MainGame.SingleParse(spli[0]), MainGame.SingleParse(spli[1]), MainGame.SingleParse(spli[2]));
                Program.game.Partner2.SpawnedLocation = Program.game.Partner2.Location;
                Program.game.Partner2.LowestFloor     = Program.game.Partner2.Location.Y;
                Program.game.Partner2.DestRotate      = MainGame.SingleParse(contenu[13 + 2]);
                Program.game.Partner2.Rotate          = Program.game.Partner2.DestRotate;
            }


            for (int i = 17; i < contenu.Length; i += 5)
            {
                spli = contenu[i].Split(',');
                LoadCharacter(spli[0], spli[1], ref Program.game.LastLoadedNotParty);
                if (spli[2] == "NPC")
                {
                    Program.game.LastLoadedNotParty.NPC = true;
                }
                spli = contenu[i + 1].Split(',');
                LoadKeyblade(spli[0], spli[1], ref Program.game.LastLoadedNotParty);

                if (Program.game.LastLoadedNotParty != null)
                {
                    spli = contenu[i + 2].Split(',');
                    Program.game.LastLoadedNotParty.Location        = new Vector3(MainGame.SingleParse(spli[0]), MainGame.SingleParse(spli[1]), MainGame.SingleParse(spli[2]));
                    Program.game.LastLoadedNotParty.SpawnedLocation = Program.game.LastLoadedNotParty.Location;
                    Program.game.LastLoadedNotParty.LowestFloor     = Program.game.LastLoadedNotParty.Location.Y;
                    Program.game.LastLoadedNotParty.DestRotate      = MainGame.SingleParse(contenu[i + 3]);
                    Program.game.LastLoadedNotParty.Rotate          = Program.game.LastLoadedNotParty.DestRotate;
                }
            }


            //LoadCharacter(@"P_EX020\P_EX020.dae", @"P_EX020", ref this.Partner1);
            //LoadKeyblade(@"W_EX020\W_EX020.dae", @"W_EX020", ref this.Partner1);

            Program.game.Sora   = Program.game.Player;
            Program.game.Donald = Program.game.Partner1;
            //Program.game.Player.Patches[0].GetPatch(2);

            Program.game.mainCamera.Target = Program.game.Player;
            Model target = Program.game.mainCamera.Target;

            if (target != null)
            {
                Program.game.mainCamera.DestLookAt = target.Location + target.HeadHeight;
                Program.game.mainCamera.LookAt     = Program.game.mainCamera.DestLookAt;
                Program.game.mainCamera.DestYaw    = Program.game.Player.DestRotate - MainGame.PI;
                Program.game.mainCamera.Yaw        = Program.game.mainCamera.DestYaw;
            }
            else
            {
                Program.game.mainCamera.DestLookAt = new Vector3(0, 250, 0);
                Program.game.mainCamera.LookAt     = Program.game.mainCamera.DestLookAt;
                Program.game.mainCamera.DestYaw    = 0f;
                Program.game.mainCamera.Yaw        = Program.game.mainCamera.DestYaw;
            }
        }