本文整理汇总了C#中IMyControllableEntity.GetHeadMatrix方法的典型用法代码示例。如果您正苦于以下问题:C# IMyControllableEntity.GetHeadMatrix方法的具体用法?C# IMyControllableEntity.GetHeadMatrix怎么用?C# IMyControllableEntity.GetHeadMatrix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMyControllableEntity
的用法示例。
在下文中一共展示了IMyControllableEntity.GetHeadMatrix方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindLookAtEntity
public static void FindLookAtEntity(IMyControllableEntity controlledEntity, bool ignoreOccupiedGrid, bool ignoreProjection, out IMyEntity lookEntity, out double lookDistance, out Vector3D hitPoint, bool findShips, bool findCubes, bool findPlayers, bool findAsteroids, bool findPlanets, bool findReplicable)
{
const float range = 5000000;
Matrix worldMatrix;
Vector3D startPosition;
Vector3D endPosition;
IMyCubeGrid occupiedGrid = null;
if (controlledEntity.Entity.Parent == null)
{
worldMatrix = controlledEntity.GetHeadMatrix(true, true, false); // dead center of player cross hairs, or the direction the player is looking with ALT.
startPosition = worldMatrix.Translation + worldMatrix.Forward * 0.5f;
endPosition = worldMatrix.Translation + worldMatrix.Forward * (range + 0.5f);
}
else
{
occupiedGrid = controlledEntity.Entity.GetTopMostParent() as IMyCubeGrid;
worldMatrix = controlledEntity.Entity.WorldMatrix;
// TODO: need to adjust for position of cockpit within ship.
startPosition = worldMatrix.Translation + worldMatrix.Forward * 1.5f;
endPosition = worldMatrix.Translation + worldMatrix.Forward * (range + 1.5f);
}
//var worldMatrix = MyAPIGateway.Session.Player.PlayerCharacter.Entity.WorldMatrix;
//var position = MyAPIGateway.Session.Player.PlayerCharacter.Entity.GetPosition();
//var position = worldMatrix.Translation + worldMatrix.Forward * 0.5f + worldMatrix.Up * 1.0f;
//MyAPIGateway.Utilities.ShowMessage("Pos", string.Format("x={0:N},y={1:N},z={2:N} x={3:N},y={4:N},z={5:N}", playerPos.X, playerPos.Y, playerPos.Z, playerMatrix.Forward.X, playerMatrix.Forward.Y, playerMatrix.Forward.Z));
// The CameraController.GetViewMatrix appears warped at the moment.
//var position = ((IMyEntity)MyAPIGateway.Session.CameraController).GetPosition();
//var worldMatrix = MyAPIGateway.Session.CameraController.GetViewMatrix();
//var position = worldMatrix.Translation;
//MyAPIGateway.Utilities.ShowMessage("Cam", string.Format("x={0:N},y={1:N},z={2:N} x={3:N},y={4:N},z={5:N}", position.X, position.Y, position.Z, worldMatrix.Forward.X, worldMatrix.Forward.Y, worldMatrix.Forward.Z));
var entites = new HashSet<IMyEntity>();
MyAPIGateway.Entities.GetEntities(entites, e => e != null);
var list = new Dictionary<IMyEntity, double>();
var ray = new RayD(startPosition, worldMatrix.Forward);
foreach (var entity in entites)
{
if (findShips || findCubes)
{
var cubeGrid = entity as Sandbox.ModAPI.IMyCubeGrid;
if (cubeGrid != null)
{
if (ignoreOccupiedGrid && occupiedGrid != null && occupiedGrid.EntityId == cubeGrid.EntityId)
continue;
// TODO: ignore construction. New cube, new ship, new station, new paste.
//if (ignoreConstruction && (MyAPIGateway.CubeBuilder.BlockCreationIsActivated || MyAPIGateway.CubeBuilder.ShipCreationIsActivated || MyAPIGateway.CubeBuilder.CopyPasteIsActivated))
// continue;
// Will ignore Projected grids, new grid/cube placement, and grids in middle of copy/paste.
// TODO: need a better way of determining projection other than Physics, as constructions have no physics either..
if (ignoreProjection && cubeGrid.Physics == null)
continue;
// check if the ray comes anywhere near the Grid before continuing.
if (ray.Intersects(entity.WorldAABB).HasValue)
{
var hit = cubeGrid.RayCastBlocks(startPosition, endPosition);
if (hit.HasValue)
{
var distance = (startPosition - cubeGrid.GridIntegerToWorld(hit.Value)).Length();
var block = cubeGrid.GetCubeBlock(hit.Value);
if (block.FatBlock != null && findCubes)
list.Add(block.FatBlock, distance);
else if (findShips)
list.Add(entity, distance);
}
}
}
}
if (findPlayers)
{
var controller = entity as IMyControllableEntity;
if (controlledEntity.Entity.EntityId != entity.EntityId && controller != null && ray.Intersects(entity.WorldAABB).HasValue)
{
var distance = (startPosition - entity.GetPosition()).Length();
list.Add(entity, distance);
}
}
if (findReplicable)
{
var replicable = entity as Sandbox.Game.Entities.MyInventoryBagEntity;
if (replicable != null && ray.Intersects(entity.WorldAABB).HasValue)
{
var distance = (startPosition - entity.GetPosition()).Length();
list.Add(entity, distance);
}
}
if (findAsteroids)
{
//.........这里部分代码省略.........
示例2: FindLookAtEntity
public static void FindLookAtEntity(IMyControllableEntity controlledEntity, bool ignoreOccupiedGrid, out IMyEntity lookEntity, out double lookDistance, out Vector3D hitPoint, bool findShips, bool findCubes, bool findPlayers, bool findAsteroids, bool findPlanets, bool findReplicable)
{
const float range = 5000000;
Matrix worldMatrix;
Vector3D startPosition;
Vector3D endPosition;
IMyCubeGrid occupiedGrid = null;
if (controlledEntity.Entity.Parent == null)
{
worldMatrix = controlledEntity.GetHeadMatrix(true, true, false); // dead center of player cross hairs, or the direction the player is looking with ALT.
startPosition = worldMatrix.Translation + worldMatrix.Forward * 0.5f;
endPosition = worldMatrix.Translation + worldMatrix.Forward * (range + 0.5f);
}
else
{
occupiedGrid = controlledEntity.Entity.GetTopMostParent() as IMyCubeGrid;
worldMatrix = controlledEntity.Entity.WorldMatrix;
// TODO: need to adjust for position of cockpit within ship.
startPosition = worldMatrix.Translation + worldMatrix.Forward * 1.5f;
endPosition = worldMatrix.Translation + worldMatrix.Forward * (range + 1.5f);
}
//var worldMatrix = MyAPIGateway.Session.Player.PlayerCharacter.Entity.WorldMatrix;
//var position = MyAPIGateway.Session.Player.PlayerCharacter.Entity.GetPosition();
//var position = worldMatrix.Translation + worldMatrix.Forward * 0.5f + worldMatrix.Up * 1.0f;
//MyAPIGateway.Utilities.ShowMessage("Pos", string.Format("x={0:N},y={1:N},z={2:N} x={3:N},y={4:N},z={5:N}", playerPos.X, playerPos.Y, playerPos.Z, playerMatrix.Forward.X, playerMatrix.Forward.Y, playerMatrix.Forward.Z));
// The CameraController.GetViewMatrix appears warped at the moment.
//var position = ((IMyEntity)MyAPIGateway.Session.CameraController).GetPosition();
//var worldMatrix = MyAPIGateway.Session.CameraController.GetViewMatrix();
//var position = worldMatrix.Translation;
//MyAPIGateway.Utilities.ShowMessage("Cam", string.Format("x={0:N},y={1:N},z={2:N} x={3:N},y={4:N},z={5:N}", position.X, position.Y, position.Z, worldMatrix.Forward.X, worldMatrix.Forward.Y, worldMatrix.Forward.Z));
var entites = new HashSet<IMyEntity>();
MyAPIGateway.Entities.GetEntities(entites, e => e != null);
var list = new Dictionary<IMyEntity, double>();
var ray = new RayD(startPosition, worldMatrix.Forward);
foreach (var entity in entites)
{
if (findShips || findCubes)
{
var cubeGrid = entity as Sandbox.ModAPI.IMyCubeGrid;
if (cubeGrid != null)
{
if (ignoreOccupiedGrid && occupiedGrid != null && occupiedGrid.EntityId == cubeGrid.EntityId)
continue;
// check if the ray comes anywhere near the Grid before continuing.
if (ray.Intersects(entity.WorldAABB).HasValue)
{
var hit = cubeGrid.RayCastBlocks(startPosition, endPosition);
if (hit.HasValue)
{
var distance = (startPosition - cubeGrid.GridIntegerToWorld(hit.Value)).Length();
var block = cubeGrid.GetCubeBlock(hit.Value);
if (block.FatBlock != null && findCubes)
list.Add(block.FatBlock, distance);
else if (findShips)
list.Add(entity, distance);
}
}
}
}
if (findPlayers)
{
var controller = entity as IMyControllableEntity;
if (controlledEntity.Entity.EntityId != entity.EntityId && controller != null && ray.Intersects(entity.WorldAABB).HasValue)
{
var distance = (startPosition - entity.GetPosition()).Length();
list.Add(entity, distance);
}
}
if (findReplicable)
{
var replicable = entity as Sandbox.Game.Entities.MyReplicableEntity;
if (replicable != null && ray.Intersects(entity.WorldAABB).HasValue)
{
var distance = (startPosition - entity.GetPosition()).Length();
list.Add(entity, distance);
}
}
if (findAsteroids)
{
var voxelMap = entity as IMyVoxelMap;
if (voxelMap != null)
{
var aabb = new BoundingBoxD(voxelMap.PositionLeftBottomCorner, voxelMap.PositionLeftBottomCorner + voxelMap.Storage.Size);
var hit = ray.Intersects(aabb);
if (hit.HasValue)
{
var center = voxelMap.PositionLeftBottomCorner + (voxelMap.Storage.Size / 2);
var distance = (startPosition - center).Length(); // use distance to center of asteroid.
//.........这里部分代码省略.........