当前位置: 首页>>代码示例>>C#>>正文


C# Voxel.GetRelativePosition方法代码示例

本文整理汇总了C#中Voxel.GetRelativePosition方法的典型用法代码示例。如果您正苦于以下问题:C# Voxel.GetRelativePosition方法的具体用法?C# Voxel.GetRelativePosition怎么用?C# Voxel.GetRelativePosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Voxel的用法示例。


在下文中一共展示了Voxel.GetRelativePosition方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Broadphase

		public static bool Broadphase(Voxel m, Voxel.Box start, Voxel.Coord target, Func<Voxel.State, bool> filter, Stack<Voxel.Box> result, int maxIterations = 50)
		{
			BroadphaseEntry closestEntry = null;
			bool found = false;
			lock (m.MutationLock)
			{
				Vector3 targetPos = m.GetRelativePosition(target);
				BroadphaseEntry startEntry = new BroadphaseEntry
				{
					Parent = null,
					Box = start,
					G = 0,
					F = (targetPos - start.GetCenter()).Length(),
					BoxSize = Math.Max(start.Width, Math.Max(start.Height, start.Depth)),
				};
				broadphaseQueue.Push(startEntry);
				broadphaseQueueLookup[start] = startEntry;

				float closestHeuristic = float.MaxValue;

				int iterations = 0;
				while (broadphaseQueue.Count > 0 && iterations < maxIterations)
				{
					iterations++;

					BroadphaseEntry entry = broadphaseQueue.Pop();

					if (entry.Box.Contains(target))
					{
						closestEntry = entry;
						found = true;
						break;
					}

					broadphaseQueueLookup.Remove(entry.Box);

					broadphaseClosed[entry.Box] = entry.G;
					lock (entry.Box.Adjacent)
					{
						for (int i = 0; i < entry.Box.Adjacent.Count; i++)
						{
							Voxel.Box adjacent = entry.Box.Adjacent[i];
							if (adjacent == null || !filter(adjacent.Type))
								continue;

							int boxSize = (int)((adjacent.Width + adjacent.Height + adjacent.Depth) / 3.0f);

							int tentativeGScore = entry.G + boxSize;

							int previousGScore;
							bool hasPreviousGScore = broadphaseClosed.TryGetValue(adjacent, out previousGScore);

							if (hasPreviousGScore && tentativeGScore > previousGScore)
								continue;

							BroadphaseEntry alreadyInQueue;
							broadphaseQueueLookup.TryGetValue(adjacent, out alreadyInQueue);

							if (alreadyInQueue == null || tentativeGScore < previousGScore)
							{
								BroadphaseEntry newEntry = alreadyInQueue != null ? alreadyInQueue : new BroadphaseEntry();

								newEntry.Parent = entry;
								newEntry.G = tentativeGScore;
								float heuristic = (targetPos - adjacent.GetCenter()).Length();
								newEntry.F = tentativeGScore + heuristic;

								if (heuristic < closestHeuristic)
								{
									closestEntry = newEntry;
									closestHeuristic = heuristic;
								}

								if (alreadyInQueue == null)
								{
									newEntry.Box = adjacent;
									newEntry.BoxSize = boxSize;
									broadphaseQueue.Push(newEntry);
									broadphaseQueueLookup[adjacent] = newEntry;
								}
							}
						}
					}
				}
			}
			broadphaseClosed.Clear();
			broadphaseQueue.Clear();
			broadphaseQueueLookup.Clear();
			if (closestEntry != null)
				VoxelAStar.reconstructBroadphasePath(closestEntry, result);
			return found;
		}
开发者ID:dsmo7206,项目名称:Lemma,代码行数:92,代码来源:VoxelAStar.cs

示例2: Consolidate

		public static void Consolidate(Main main, DynamicVoxel voxel, Voxel targetVoxel, Voxel.Coord targetCoord, float interval = 1.0f)
		{
			if (targetVoxel != null)
			{
				// Combine this map with the other one

				Direction x = targetVoxel.GetRelativeDirection(voxel.GetAbsoluteVector(Vector3.Right));
				Direction y = targetVoxel.GetRelativeDirection(voxel.GetAbsoluteVector(Vector3.Up));
				Direction z = targetVoxel.GetRelativeDirection(voxel.GetAbsoluteVector(Vector3.Backward));

				if (x.IsParallel(y))
					x = y.Cross(z);
				else if (y.IsParallel(z))
					y = x.Cross(z);

				Voxel.Coord offset = new Voxel.Coord();
				float closestCoordDistance = float.MaxValue;
				Vector3 closestCoordPosition = targetVoxel.GetAbsolutePosition(targetCoord);
				lock (voxel.MutationLock)
				{
					foreach (Voxel.Coord c in voxel.Chunks.SelectMany(c => c.Boxes).SelectMany(b => b.GetCoords()))
					{
						float distance = (voxel.GetAbsolutePosition(c) - closestCoordPosition).LengthSquared();
						if (distance < closestCoordDistance)
						{
							closestCoordDistance = distance;
							offset = c;
						}
					}
				}
				Vector3 toLevitatingMap = voxel.Transform.Value.Translation - targetVoxel.GetAbsolutePosition(targetCoord);
				offset = offset.Move(voxel.GetRelativeDirection(-toLevitatingMap));

				Quaternion orientation = Quaternion.CreateFromRotationMatrix(voxel.Transform.Value);

				EffectBlockFactory blockFactory = Factory.Get<EffectBlockFactory>();

				int index = 0;
				List<Voxel.Coord> coords;
				lock (voxel.MutationLock)
					coords = voxel.Chunks.SelectMany(c => c.Boxes).SelectMany(b => b.GetCoords()).ToList();
				Voxel.Coord camera = voxel.GetCoordinate(main.Camera.Position);
				foreach (Voxel.Coord c in coords.OrderBy(c2 => new Vector3(c2.X - camera.X, c2.Y - camera.Y, c2.Z - camera.Z).LengthSquared()))
				{
					Voxel.Coord offsetFromCenter = c.Move(-offset.X, -offset.Y, -offset.Z);
					Voxel.Coord targetCoord2 = new Voxel.Coord();
					targetCoord2.SetComponent(x, offsetFromCenter.GetComponent(Direction.PositiveX));
					targetCoord2.SetComponent(y, offsetFromCenter.GetComponent(Direction.PositiveY));
					targetCoord2.SetComponent(z, offsetFromCenter.GetComponent(Direction.PositiveZ));
					targetCoord2 = targetCoord2.Move(targetCoord.X, targetCoord.Y, targetCoord.Z);
					if (targetVoxel[targetCoord2].ID == 0)
					{
						Entity blockEntity = blockFactory.CreateAndBind(main);
						c.Data.ApplyToEffectBlock(blockEntity.Get<ModelInstance>());
						EffectBlock effectBlock = blockEntity.Get<EffectBlock>();
						effectBlock.Offset.Value = targetVoxel.GetRelativePosition(targetCoord2);
						effectBlock.DoScale = false;
						effectBlock.StartPosition = voxel.GetAbsolutePosition(c);
						effectBlock.StartOrientation = orientation;
						effectBlock.TotalLifetime = (0.05f + (index * 0.0075f)) * interval;
						effectBlock.Setup(targetVoxel.Entity, targetCoord2, c.Data.ID);
						main.Add(blockEntity);
						index++;
					}
				}

				// Delete the map
				voxel.Entity.Delete.Execute();
			}
		}
开发者ID:dsmo7206,项目名称:Lemma,代码行数:70,代码来源:VoxelRip.cs

示例3: Narrowphase

		public static void Narrowphase(Voxel m, Voxel.Coord start, Voxel.Box target, Stack<Voxel.Coord> result)
		{
			Voxel.Box currentBox = m.GetBox(start);
			if (currentBox == null)
				return;
			Vector3 targetPos = target.GetCenter();
			NarrowphaseEntry startEntry = new NarrowphaseEntry
			{
				Parent = null,
				Coord = start,
				G = 0,
				F = (targetPos - m.GetRelativePosition(start)).Length(),
			};
			narrowphaseQueue.Push(startEntry);
			narrowphaseQueueLookup[start] = startEntry;

			NarrowphaseEntry closestEntry = null;
			float closestHeuristic = float.MaxValue;

			int iterations = 0;
			while (narrowphaseQueue.Count > 0 && iterations < 80)
			{
				iterations++;

				NarrowphaseEntry entry = narrowphaseQueue.Pop();

				if (m.GetBox(entry.Coord) == target)
				{
					closestEntry = entry;
					break;
				}

				narrowphaseQueueLookup.Remove(entry.Coord);

				narrowphaseClosed[entry.Coord] = entry.G;
				for (int i = 0; i < 6; i++)
				{
					Voxel.Coord adjacent = entry.Coord.Move(DirectionExtensions.Directions[i]);
					if (!currentBox.Contains(adjacent) && !target.Contains(adjacent))
						continue;

					int tentativeGScore = entry.G + 1;

					int previousGScore;
					bool hasPreviousGScore = narrowphaseClosed.TryGetValue(adjacent, out previousGScore);

					if (hasPreviousGScore && tentativeGScore > previousGScore)
						continue;

					NarrowphaseEntry alreadyInQueue;
					narrowphaseQueueLookup.TryGetValue(adjacent, out alreadyInQueue);

					if (alreadyInQueue == null || tentativeGScore < previousGScore)
					{
						NarrowphaseEntry newEntry = alreadyInQueue != null ? alreadyInQueue : new NarrowphaseEntry();

						newEntry.Parent = entry;
						newEntry.G = tentativeGScore;
						float heuristic = (targetPos - m.GetRelativePosition(adjacent)).Length();
						newEntry.F = tentativeGScore + heuristic;

						if (heuristic < closestHeuristic)
						{
							closestEntry = newEntry;
							closestHeuristic = heuristic;
						}

						if (alreadyInQueue == null)
						{
							newEntry.Coord = adjacent;
							narrowphaseQueue.Push(newEntry);
							narrowphaseQueueLookup[adjacent] = newEntry;
						}
					}
				}
			}
			narrowphaseClosed.Clear();
			narrowphaseQueue.Clear();
			narrowphaseQueueLookup.Clear();
			if (closestEntry != null)
				VoxelAStar.reconstructNarrowphasePath(closestEntry, result);
		}
开发者ID:dsmo7206,项目名称:Lemma,代码行数:82,代码来源:VoxelAStar.cs


注:本文中的Voxel.GetRelativePosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。