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


C# Voxel.GetAbsolutePosition方法代码示例

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


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

示例1: 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

示例2: Go


//.........这里部分代码省略.........
						{
							Voxel.Coord coord = new Voxel.Coord { X = x, Y = b.Y + b.Height, Z = z };
							if (coord.Between(ripStart, ripEnd))
								edges.Add(coord);

							coord = new Voxel.Coord { X = x, Y = b.Y - 1, Z = z };
							if (coord.Between(ripStart, ripEnd))
								edges.Add(coord);
						}
					}

					// Outer shell
					for (int y = b.Y; y < b.Y + b.Height; y++)
					{
						// Left and right
						for (int z = b.Z - 1; z <= b.Z + b.Depth; z++)
						{
							Voxel.Coord coord = new Voxel.Coord { X = b.X - 1, Y = y, Z = z };
							if (coord.Between(ripStart, ripEnd))
								edges.Add(coord);

							coord = new Voxel.Coord { X = b.X + b.Width, Y = y, Z = z };
							if (coord.Between(ripStart, ripEnd))
								edges.Add(coord);
						}

						// Backward and forward
						for (int x = b.X; x < b.X + b.Width; x++)
						{
							Voxel.Coord coord = new Voxel.Coord { X = x, Y = y, Z = b.Z - 1 };
							if (coord.Between(ripStart, ripEnd))
								edges.Add(coord);

							coord = new Voxel.Coord { X = x, Y = y, Z = b.Z + b.Depth };
							if (coord.Between(ripStart, ripEnd))
								edges.Add(coord);
						}
					}
				}

				if (edges.Contains(center))
					return false;

				// Top and bottom
				for (int x = ripStart.X; x <= ripEnd.X; x++)
				{
					for (int z = ripStart.Z; z <= ripEnd.Z; z++)
					{
						Voxel.Coord c = new Voxel.Coord { X = x, Y = ripStart.Y, Z = z };
						Voxel.State s = voxel[c];
						if (s != Voxel.States.Empty && !s.Permanent)
							edges.Add(c);
						c = new Voxel.Coord { X = x, Y = ripEnd.Y, Z = z };
						s = voxel[c];
						if (s != Voxel.States.Empty && !s.Permanent)
							edges.Add(c);
					}
				}

				// Sides
				for (int y = ripStart.Y + 1; y <= ripEnd.Y - 1; y++)
				{
					// Left and right
					for (int z = ripStart.Z; z <= ripEnd.Z; z++)
					{
						Voxel.Coord c = new Voxel.Coord { X = ripStart.X, Y = y, Z = z };
						Voxel.State s = voxel[c];
						if (s != Voxel.States.Empty && !s.Permanent)
							edges.Add(c);
						c = new Voxel.Coord { X = ripEnd.X, Y = y, Z = z };
						s = voxel[c];
						if (s != Voxel.States.Empty && !s.Permanent)
							edges.Add(c);
					}

					// Backward and forward
					for (int x = ripStart.X; x <= ripEnd.X; x++)
					{
						Voxel.Coord c = new Voxel.Coord { X = x, Y = y, Z = ripStart.Z };
						Voxel.State s = voxel[c];
						if (s != Voxel.States.Empty && !s.Permanent)
							edges.Add(c);
						c = new Voxel.Coord { X = x, Y = y, Z = ripEnd.Z };
						s = voxel[c];
						if (s != Voxel.States.Empty && !s.Permanent)
							edges.Add(c);
					}
				}

				Propagator p = WorldFactory.Instance.Get<Propagator>();
				foreach (Voxel.Coord c in edges)
					p.SparksLowPriority(voxel.GetAbsolutePosition(c), Propagator.Spark.Dangerous);

				voxel.Empty(edges);

				voxel.Regenerate(callback);
				return true;
			}
			return false;
		}
开发者ID:dsmo7206,项目名称:Lemma,代码行数:101,代码来源:VoxelRip.cs


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