本文整理汇总了C#中VRageMath.MatrixI类的典型用法代码示例。如果您正苦于以下问题:C# MatrixI类的具体用法?C# MatrixI怎么用?C# MatrixI使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MatrixI类属于VRageMath命名空间,在下文中一共展示了MatrixI类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMissingBlocks
public bool GetMissingBlocks(out MatrixI transform, List<int> multiBlockIndices)
{
// Fill missing indices.
Debug.Assert(multiBlockIndices.Count == 0);
for (int i = 0; i < MultiBlockDefinition.BlockDefinitions.Length; ++i)
{
if (!Blocks.Any(b => b.MultiBlockIndex == i))
multiBlockIndices.Add(i);
}
// ...and return transform
return GetTransform(out transform);
}
示例2: CopyTo
public void CopyTo(MyGridSkeleton target, MatrixI transformationMatrix, MyCubeGrid targetGrid)
{
Vector3I oldPosition, newPosition;
Vector3 oldBone, newBone;
// transformationMatrix is in cube coordinates, so change it to bone coords
MatrixI BoneOriginToGridOrigin = new MatrixI(new Vector3I(1, 1, 1), Base6Directions.Direction.Forward, Base6Directions.Direction.Up);
MatrixI GridOriginToBoneOrigin = new MatrixI(new Vector3I(-1, -1, -1), Base6Directions.Direction.Forward, Base6Directions.Direction.Up);
transformationMatrix.Translation = transformationMatrix.Translation * BoneDensity;
MatrixI tmp;
MatrixI.Multiply(ref GridOriginToBoneOrigin, ref transformationMatrix, out tmp);
MatrixI.Multiply(ref tmp, ref BoneOriginToGridOrigin, out transformationMatrix);
Matrix orientation;
transformationMatrix.GetBlockOrientation().GetMatrix(out orientation);
foreach (var bone in Bones)
{
oldPosition = bone.Key;
Vector3I.Transform(ref oldPosition, ref transformationMatrix, out newPosition);
Vector3 transformedBone = Vector3.Transform(bone.Value, orientation);
if (target.Bones.TryGetValue(newPosition, out oldBone))
{
newBone = (oldBone + transformedBone) * 0.5f;
target.Bones[newPosition] = newBone;
}
else
{
target.Bones[newPosition] = transformedBone;
}
Vector3I cubePosition = newPosition / BoneDensity;
for (int i = -1; i <= 1; i++)
for (int j = -1; j <= 1; j++)
for (int k = -1; k <= 1; k++)
{
targetGrid.SetCubeDirty(cubePosition + new Vector3I(i, j, k));
}
}
}
示例3: GetTransform
public bool GetTransform(out MatrixI transform)
{
transform = default(MatrixI);
if (Blocks.Count != 0)
{
var refBlock = Blocks.First();
Debug.Assert(refBlock.MultiBlockIndex < MultiBlockDefinition.BlockDefinitions.Length);
if (refBlock.MultiBlockIndex < MultiBlockDefinition.BlockDefinitions.Length)
{
var refBlockDefInfo = MultiBlockDefinition.BlockDefinitions[refBlock.MultiBlockIndex];
transform = MatrixI.CreateRotation(refBlockDefInfo.Forward, refBlockDefInfo.Up, refBlock.Orientation.Forward, refBlock.Orientation.Up);
transform.Translation = refBlock.Position - Vector3I.TransformNormal(refBlockDefInfo.Min, ref transform);
return true;
}
}
return false;
}
示例4: AddBlock
private void AddBlock(MySlimBlock block)
{
Vector3I start = block.Min;
Vector3I end = block.Max;
for (var it = new Vector3I.RangeIterator(ref start, ref end); it.IsValid(); it.GetNext(out start))
{
Debug.Assert(!m_cubeSet.Contains(ref start));
m_cubeSet.Add(ref start);
}
MatrixI transform = new MatrixI(block.Position, block.Orientation.Forward, block.Orientation.Up);
MergeFromAnotherMesh(block.BlockDefinition.NavigationDefinition.Mesh, ref transform);
}
示例5: ComputeMax
/// <summary>
/// Called when block is destroyed before being removed from grid
/// </summary>
//public void OnDestroy()
//{
// if (FatBlock != null)
// {
// Profiler.Begin("MySlimBlock.OnDestroy");
// FatBlock.OnDestroy();
// Profiler.End();
// }
//}
public static void ComputeMax(MyCubeBlockDefinition definition, MyBlockOrientation orientation, ref Vector3I min, out Vector3I max)
{
Vector3I size = definition.Size - 1;
MatrixI localMatrix = new MatrixI(orientation);
Vector3I.TransformNormal(ref size, ref localMatrix, out size);
Vector3I.Abs(ref size, out size);
max = min + size;
}
示例6: ConstraintPositionInGridSpace
private Vector3 ConstraintPositionInGridSpace()
{
var cubeCenter = (Max + Min) * CubeGrid.GridSize * 0.5f;
Vector3 centerOffset = ConnectionPosition - cubeCenter;
centerOffset = Vector3.DominantAxisProjection(centerOffset);
MatrixI orientation = new MatrixI(Vector3I.Zero, this.Orientation.Forward, this.Orientation.Up);
Vector3 outExtents;
Vector3.Transform(ref centerOffset, ref orientation, out outExtents);
return cubeCenter + centerOffset;
}
示例7: CheckConnectivityOnGrid
protected static bool CheckConnectivityOnGrid(MySlimBlock block, ref MatrixI transform, ref MyGridPlacementSettings settings, MyCubeGrid hitGrid)
{
Vector3I position;
Vector3I.Transform(ref block.Position, ref transform, out position);
Vector3I forward = Base6Directions.GetIntVector(transform.GetDirection(block.Orientation.Forward));
Vector3I up = Base6Directions.GetIntVector(transform.GetDirection(block.Orientation.Up));
MyBlockOrientation blockOrientation = new MyBlockOrientation(Base6Directions.GetDirection(forward), Base6Directions.GetDirection(up));
Quaternion rotation;
blockOrientation.GetQuaternion(out rotation);
var blockDefinition = block.BlockDefinition;
return MyCubeGrid.CheckConnectivity(hitGrid, blockDefinition, blockDefinition.GetBuildProgressModelMountPoints(block.BuildLevelRatio), ref rotation, ref position);
}
示例8: ConvertRotatedGridBlockToStatic
/// <summary>
/// Converts the given block with the given matrix for static grid.
/// </summary>
private static void ConvertRotatedGridBlockToStatic(ref MatrixI transform, MyObjectBuilder_CubeBlock origBlock)
{
MyDefinitionId defId = new MyDefinitionId(origBlock.TypeId, origBlock.SubtypeName);
MyCubeBlockDefinition blockDefinition;
MyDefinitionManager.Static.TryGetCubeBlockDefinition(defId, out blockDefinition);
if (blockDefinition == null)
return;
// Orientation quaternion is not setup in origblock
MyBlockOrientation origOrientation = origBlock.BlockOrientation;
Vector3I origMin = origBlock.Min;
Vector3I origMax;
MySlimBlock.ComputeMax(blockDefinition, origOrientation, ref origMin, out origMax);
Vector3I tMin;
Vector3I tMax;
Vector3I.Transform(ref origMin, ref transform, out tMin);
Vector3I.Transform(ref origMax, ref transform, out tMax);
Base6Directions.Direction forward = transform.GetDirection(origOrientation.Forward);
Base6Directions.Direction up = transform.GetDirection(origOrientation.Up);
// Write data
MyBlockOrientation newBlockOrientation = new MyBlockOrientation(forward, up);
Quaternion rotationQuat;
newBlockOrientation.GetQuaternion(out rotationQuat);
origBlock.Orientation = rotationQuat;
origBlock.Min = Vector3I.Min(tMin, tMax);
}
示例9: GetTransformed
public void GetTransformed(ref MatrixI tform, out Vector3 newA, out Vector3 newB, out Vector3 newC)
{
var e = m_navMesh.Mesh.GetFace(m_triIndex).GetVertexEnumerator();
e.MoveNext();
newA = e.Current;
Vector3.Transform(ref newA, ref tform, out newA);
e.MoveNext();
newB = e.Current;
Vector3.Transform(ref newB, ref tform, out newB);
e.MoveNext();
newC = e.Current;
Vector3.Transform(ref newC, ref tform, out newC);
Debug.Assert(e.MoveNext() == false);
}
示例10: OnMergeGridSuccess
private static void OnMergeGridSuccess(MySyncGrid sync, ref MergeMsg msg, MyNetworkClient sender)
{
MyCubeGrid grid = null;
if (MyEntities.TryGetEntityById<MyCubeGrid>(msg.OtherEntityId, out grid))
{
Vector3I gridOffset = msg.GridOffset;
MatrixI transform = new MatrixI(msg.GridOffset, msg.GridForward, msg.GridUp);
sync.Entity.MergeGridInternal(grid, ref transform);
}
}
示例11: FillRotationsForTopology
/// <summary>
/// Fills rotation table for topology. Any arbitrary 90deg. rotation can then be converted to one unique rotation
/// </summary>
/// <param name="topology"></param>
/// <param name="male">Tile which normal is tested to find unique rotations. If -1, all rotations are allowed</param>
private static void FillRotationsForTopology(MyCubeTopology topology, int mainTile)
{
Vector3[] normals = new Vector3[m_allPossible90rotations.Length];
m_uniqueTopologyRotationTable[(int)topology] = new MatrixI[m_allPossible90rotations.Length];
for (int i = 0; i < m_allPossible90rotations.Length; i++)
{
int normalFound = -1;
if (mainTile != -1)
{
Vector3 transformedNormal;
Vector3.TransformNormal(ref m_tileTable[(int)topology].Tiles[mainTile].Normal, ref m_allPossible90rotations[i], out transformedNormal);
normals[i] = transformedNormal;
for (int j = 0; j < i; j++)
{
if (Vector3.Dot(normals[j], transformedNormal) > 0.98f)
{
normalFound = j;
break;
}
}
}
if (normalFound != -1)
{
m_uniqueTopologyRotationTable[(int)topology][i] = m_uniqueTopologyRotationTable[(int)topology][normalFound];
}
else
{
m_uniqueTopologyRotationTable[(int)topology][i] = m_allPossible90rotations[i];
}
}
}
示例12: ProcessChangedGrid
private void ProcessChangedGrid(MyCubeGrid newGrid)
{
Vector3I gridOffset = Vector3I.Round((m_grid.PositionComp.GetPosition() - newGrid.PositionComp.GetPosition()) / m_grid.GridSize);
Vector3 fw = (Vector3)Vector3D.TransformNormal(m_grid.WorldMatrix.Forward, newGrid.PositionComp.WorldMatrixNormalizedInv);
Vector3 up = (Vector3)Vector3D.TransformNormal(m_grid.WorldMatrix.Up, newGrid.PositionComp.WorldMatrixNormalizedInv);
Base6Directions.Direction fwDir = Base6Directions.GetClosestDirection(fw);
Base6Directions.Direction upDir = Base6Directions.GetClosestDirection(up);
if (upDir == fwDir) upDir = Base6Directions.GetPerpendicular(fwDir);
MatrixI transform = new MatrixI(ref gridOffset, fwDir, upDir);
MyGridInfo gridInfo = new MyGridInfo();
gridInfo.Grid = newGrid;
gridInfo.Transform = transform;
m_splitGridInfos.Add(gridInfo);
// Remove from split grid
if (m_removeLocationsForGridSplits.Count > 0)
{
List<int> indexesToRemove = new List<int>();
for (int i = 0; i < m_removeLocationsForGridSplits.Count; ++i)
{
MyGeneratedBlockLocation location = m_removeLocationsForGridSplits[i];
Debug.Assert(location.GeneratedBlockType != MyStringId.NullOrEmpty);
RemoveBlock(location, gridInfo, location.GeneratedBlockType);
}
}
// Add to split grid
List<MySlimBlock> newGridBlocks = new List<MySlimBlock>();
m_addLocations.RemoveWhere(delegate(MyGeneratedBlockLocation loc)
{
if (loc.RefBlock != null && loc.RefBlock.CubeGrid == newGrid)
{
newGridBlocks.Add(loc.RefBlock);
return true;
}
return false;
});
foreach (var newGridBlock in newGridBlocks)
{
Debug.Assert(newGrid == newGridBlock.CubeGrid);
newGridBlock.CubeGrid.AdditionalModelGenerators.ForEach(g => g.UpdateAfterGridSpawn(newGridBlock));
}
}
示例13: CanAddBlock
/// <summary>
/// Check if other block can be added to area of multiblock.
/// </summary>
public bool CanAddBlock(ref Vector3I otherGridPositionMin, ref Vector3I otherGridPositionMax, MyBlockOrientation otherOrientation, MyCubeBlockDefinition otherDefinition)
{
MatrixI transform;
if (!GetTransform(out transform))
return true;
try
{
// Calculate other block position in multiblock space.
MatrixI invTransform;
MatrixI.Invert(ref transform, out invTransform);
Vector3I otherPositionInMultiBlockMinTmp = Vector3I.Transform(otherGridPositionMin, ref invTransform);
Vector3I otherPositionInMultiBlockMaxTmp = Vector3I.Transform(otherGridPositionMax, ref invTransform);
Vector3I otherPositionInMultiBlockMin = Vector3I.Min(otherPositionInMultiBlockMinTmp, otherPositionInMultiBlockMaxTmp);
Vector3I otherPositionInMultiBlockMax = Vector3I.Max(otherPositionInMultiBlockMinTmp, otherPositionInMultiBlockMaxTmp);
// Check intersection with AABB of whole multiblock
if (!Vector3I.BoxIntersects(ref MultiBlockDefinition.Min, ref MultiBlockDefinition.Max, ref otherPositionInMultiBlockMin, ref otherPositionInMultiBlockMax))
return true;
// Other block rotation in multiblock space.
MatrixI otherRotation = new MatrixI(otherOrientation);
MatrixI otherRotationInMultiBlock;
MatrixI.Multiply(ref otherRotation, ref invTransform, out otherRotationInMultiBlock);
MyBlockOrientation otherOrientationInMultiBlock = new MyBlockOrientation(otherRotationInMultiBlock.Forward, otherRotationInMultiBlock.Up);
// Multiblock part (block) definitions in the same position.
m_tmpPartDefinitions.Clear();
foreach (var partDefinition in MultiBlockDefinition.BlockDefinitions)
{
if (Vector3I.BoxIntersects(ref partDefinition.Min, ref partDefinition.Max, ref otherPositionInMultiBlockMin, ref otherPositionInMultiBlockMax))
{
if (otherPositionInMultiBlockMin == otherPositionInMultiBlockMax && partDefinition.Min == partDefinition.Max) // Size = 1
m_tmpPartDefinitions.Add(partDefinition);
else
return false;
}
}
if (m_tmpPartDefinitions.Count == 0)
return true;
// Check if multiblock part blocks and other block can be added together
bool canAdd = true;
foreach (var partDefinition in m_tmpPartDefinitions)
{
MyCubeBlockDefinition blockDefinition;
if (MyDefinitionManager.Static.TryGetCubeBlockDefinition(partDefinition.Id, out blockDefinition) && blockDefinition != null)
{
canAdd &= MyCompoundCubeBlock.CanAddBlocks(blockDefinition, new MyBlockOrientation(partDefinition.Forward, partDefinition.Up),
otherDefinition, otherOrientationInMultiBlock);
if (!canAdd)
break;
}
}
return canAdd;
}
finally
{
m_tmpPartDefinitions.Clear();
}
}
示例14: CalculateBlockDepthBias
public unsafe static void CalculateBlockDepthBias(this MyRenderComponent renderComponent, MyCubeBlock block)
{
if (block.Hierarchy != null)
{
var parentCompound = block.Hierarchy.Parent.Entity as MyCompoundCubeBlock;
if (parentCompound != null)
{
const int offsetCount = 64;
bool* offsets = stackalloc bool[offsetCount];
foreach (var block2 in parentCompound.GetBlocks())
{
if (block2.FatBlock != null && block2.FatBlock != block)
{
var cubeBlockRender = block2.FatBlock.Render as MyRenderComponentBase;
if (cubeBlockRender != null)
offsets[cubeBlockRender.DepthBias] = true;
}
}
int preferedOffset = 0;
var modelStorage = renderComponent.ModelStorage as VRage.Game.Models.MyModel;
if (modelStorage != null)
{
Vector3 blockCenterLocal = modelStorage.BoundingSphere.Center;
MatrixI blockOrientation = new MatrixI(block.SlimBlock.Orientation);
Vector3 blockCenter = new Vector3();
Vector3.Transform(ref blockCenterLocal, ref blockOrientation, out blockCenter);
if (blockCenter.LengthSquared() > 0.5f)
{
if (Math.Abs(blockCenter.X) > Math.Abs(blockCenter.Y))
{
if (Math.Abs(blockCenter.X) > Math.Abs(blockCenter.Z))
{
preferedOffset = blockCenter.X > 0 ? 2 : 4;
}
else
{
preferedOffset = blockCenter.Z > 0 ? 10 : 12;
}
}
else
{
if (Math.Abs(blockCenter.Z) > Math.Abs(blockCenter.Y))
{
preferedOffset = blockCenter.Z > 0 ? 10 : 12;
}
else
{
preferedOffset = blockCenter.Y > 0 ? 6 : 8;
}
}
}
}
for (int offsetIndex = preferedOffset; offsetIndex < offsetCount; ++offsetIndex)
{
if (!offsets[offsetIndex])
{
renderComponent.DepthBias = (byte)offsetIndex;
break;
}
}
}
}
}
示例15: Multiply
public static void Multiply(ref MatrixI leftMatrix, ref MatrixI rightMatrix, out MatrixI result)
{
result = default(MatrixI);
Vector3I right = leftMatrix.RightVector;
Vector3I up = leftMatrix.UpVector;
Vector3I backward = leftMatrix.BackwardVector;
Vector3I newRight, newUp, newBackward;
Vector3I.TransformNormal(ref right, ref rightMatrix, out newRight);
Vector3I.TransformNormal(ref up, ref rightMatrix, out newUp);
Vector3I.TransformNormal(ref backward, ref rightMatrix, out newBackward);
Vector3I.Transform(ref leftMatrix.Translation, ref rightMatrix, out result.Translation);
result.RightVector = newRight;
result.UpVector = newUp;
result.BackwardVector = newBackward;
}