本文整理汇总了C#中VRageMath.LineD类的典型用法代码示例。如果您正苦于以下问题:C# LineD类的具体用法?C# LineD怎么用?C# LineD使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LineD类属于VRageMath命名空间,在下文中一共展示了LineD类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetIntersectionWithLine
// Calculates intersection of line with any triangleVertexes in this model instance. Closest intersection and intersected triangleVertexes will be returned.
internal override bool GetIntersectionWithLine(ref LineD line, out MyIntersectionResultLineTriangleEx? t, IntersectionFlags flags = IntersectionFlags.ALL_TRIANGLES)
{
t = null;
return false;
//Matrix invWorld = Matrix.Invert(WorldMatrix);
//Vector3 from = Vector3.Transform(line.From, invWorld);
//Vector3 to = Vector3.Transform(line.To, invWorld);
//Line lineLocal = new Line(from, to);
//bool res = base.GetIntersectionWithLine(ref line, out t, flags);
//if (res)
//{
// var definition = MyDefinitionManager.Static.GetCubeBlockDefinition(new MyDefinitionId(MyObjectBuilderTypeEnum.Ladder));
// if (definition.ExcludedAreaForCamera != null)
// {
// foreach (var b in definition.ExcludedAreaForCamera)
// {
// if (b.Contains(t.Value.IntersectionPointInObjectSpace) == ContainmentType.Contains)
// {
// t = null;
// return false;
// }
// }
// }
//}
//return res;
}
开发者ID:leandro1129,项目名称:SpaceEngineers,代码行数:32,代码来源:MyLadder.cs
示例2: GetShortestDistanceSquared
public static double GetShortestDistanceSquared(LineD line1, LineD line2)
{
Vector3D res1, res2;
Vector3D dP = GetShortestVector(ref line1, ref line2, out res1, out res2);
//return Math.Sqrt(dot(dP, dP));
return Vector3D.Dot(dP, dP);
}
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:8,代码来源:LineD.cs
示例3: GetIntersectionWithLine
public Sandbox.Common.MyIntersectionResultLineTriangleEx? GetIntersectionWithLine(IMyEntity physObject, ref LineD line, ref MatrixD customInvMatrix, IntersectionFlags flags)
{
LineD lineInModelSpace = new LineD(Vector3D.Transform(line.From, ref customInvMatrix), Vector3D.Transform(line.To, ref customInvMatrix));
MyIntersectionResultLineTriangleEx? ret = m_rootNode.GetIntersectionWithLine(physObject, m_model, ref lineInModelSpace, null, flags);
return ret;
}
开发者ID:leandro1129,项目名称:SpaceEngineers,代码行数:8,代码来源:MyModelOctree.cs
示例4: DoWork
public unsafe void DoWork(WorkData workData = null)
{
try
{
//MyEntities.EntityCloseLock.AcquireShared();
if (m_renderObject == null)
return;
if (m_renderObject is MyRenderVoxelCell)
{
}
Vector3 directionToSunNormalized = -MyRender.Sun.Direction;
VisibleFromSun = false;
var line2 = new LineD(m_renderObject.WorldVolume.Center, m_renderObject.WorldVolume.Center + directionToSunNormalized * MyShadowRenderer.SHADOW_MAX_OFFSET * 0.5f);
var result2 = MyRender.GetAnyIntersectionWithLine(MyRender.ShadowPrunning, ref line2, m_renderObject, null, m_overlapList);
VisibleFromSun |= (result2 == null); //if nothing hit, its visible from sun
if (m_renderObject.FastCastShadowResolve)
return;
Vector3D* corners = stackalloc Vector3D[8];
m_renderObject.GetCorners(corners);
for (int i = 0; i < 8; i++)
{
LineD line = new LineD(corners[i], corners[i] + directionToSunNormalized * MyShadowRenderer.SHADOW_MAX_OFFSET * 0.5f);
var result = MyRender.GetAnyIntersectionWithLine(MyRender.ShadowPrunning, ref line, m_renderObject, null, m_overlapList);
VisibleFromSun |= (result == null);
if (VisibleFromSun)
break;
}
if (!VisibleFromSun)
{
}
}
finally
{ /*
if (m_renderObject != null)
{
m_renderObject.OnClose -= m_entity_OnMarkForClose;
}
*/
// MyEntities.EntityCloseLock.ReleaseShared();
}
}
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:52,代码来源:MyCastShadowJob.cs
示例5: MyIntersectionResultLineTriangleEx
public MyIntersectionResultLineTriangleEx(MyIntersectionResultLineTriangle triangle, IMyEntity entity, ref LineD line)
{
Triangle = triangle;
Entity = entity;
InputLineInObjectSpace = line;
NormalInObjectSpace = MyUtils.GetNormalVectorFromTriangle(ref Triangle.InputTriangle);
IntersectionPointInObjectSpace = line.From + line.Direction * Triangle.Distance;
if (Entity is IMyVoxelBase)
{
IntersectionPointInWorldSpace = (Vector3D)IntersectionPointInObjectSpace;
NormalInWorldSpace = NormalInObjectSpace;
// This will move intersection point from world space into voxel map's object space
IntersectionPointInObjectSpace = IntersectionPointInObjectSpace - ((IMyVoxelBase)Entity).PositionLeftBottomCorner;
}
else
{
var worldMatrix = Entity.WorldMatrix;
NormalInWorldSpace = (Vector3)MyUtils.GetTransformNormalNormalized((Vector3D)NormalInObjectSpace, ref worldMatrix);
IntersectionPointInWorldSpace = Vector3D.Transform((Vector3D)IntersectionPointInObjectSpace, ref worldMatrix);
}
}
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:24,代码来源:MyIntersectionResultLineTriangle.cs
示例6: PrefetchShapeOnRay
public void PrefetchShapeOnRay(ref LineD ray)
{
int lod = 1;
Vector3D localStart;
MyVoxelCoordSystems.WorldPositionToLocalPosition(m_voxelMap.PositionLeftBottomCorner, ref ray.From, out localStart);
Vector3D localEnd;
MyVoxelCoordSystems.WorldPositionToLocalPosition(m_voxelMap.PositionLeftBottomCorner, ref ray.To, out localEnd);
var shape = GetShape(lod);
Debug.Assert(shape.Base.IsValid);
if (m_cellsToGenerateBuffer.Length < 64)
{
m_cellsToGenerateBuffer = new Vector3I[64];
}
int requiredCellsCount = shape.GetHitCellsInRange(localStart, localEnd, m_cellsToGenerateBuffer);
if (requiredCellsCount == 0)
{
return;
}
ProfilerShort.Begin("Start Jobs");
for (int i = 0; i < requiredCellsCount; ++i)
{
if (m_workTracker.Exists(new MyCellCoord(lod, m_cellsToGenerateBuffer[i])))
continue;
MyPrecalcJobPhysicsPrefetch.Start(new MyPrecalcJobPhysicsPrefetch.Args
{
TargetPhysics = this,
Tracker = m_workTracker,
GeometryCell = new MyCellCoord(lod, m_cellsToGenerateBuffer[i]),
Storage = m_voxelMap.Storage
});
}
ProfilerShort.End();
}
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:41,代码来源:MyVoxelPhysicsBody.cs
示例7: GetDamageCapsuleLine
public LineD GetDamageCapsuleLine(FlameInfo info)
{
var world = Matrix.CreateFromDir(Vector3.TransformNormal(info.Direction, WorldMatrix));
var halfLenght = ThrustLengthRand * info.Radius / 2;
halfLenght *= BlockDefinition.FlameDamageLengthScale;
var position = Vector3D.Transform(info.Position, WorldMatrix);
if (halfLenght > info.Radius)
return new LineD(position - world.Forward * (info.Radius), position + world.Forward * (2 * halfLenght - info.Radius));
else
{
var l = new LineD(position + world.Forward * halfLenght, position + world.Forward * halfLenght);
l.Direction = world.Forward;
return l;
}
}
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:17,代码来源:MyThrust.cs
示例8: GetIntersectedBlockData
/// <summary>
/// Calculates exact intersection point (in uniform grid coordinates) from stored havok's hit info object obtained during FindClosest grid.
/// Returns position of intersected object in uniform grid coordinates.
/// </summary>
protected Vector3D? GetIntersectedBlockData(ref MatrixD inverseGridWorldMatrix, out Vector3D intersection, out MySlimBlock intersectedBlock, out ushort? compoundBlockId)
{
Debug.Assert(m_hitInfo != null);
//Debug.Assert(m_hitInfo.Value.HkHitInfo.GetEntity() == CurrentGrid);
intersection = Vector3D.Zero;
intersectedBlock = null;
compoundBlockId = null;
double distance = double.MaxValue;
Vector3D? intersectedObjectPos = null;
var line = new LineD(IntersectionStart, IntersectionStart + IntersectionDirection * IntersectionDistance);
Vector3I position = Vector3I.Zero;
if (!CurrentGrid.GetLineIntersectionExactGrid(ref line, ref position, ref distance, m_hitInfo.Value))
return null;
distance = Math.Sqrt(distance);
intersectedObjectPos = position;
intersectedBlock = CurrentGrid.GetCubeBlock(position);
if (intersectedBlock == null)
return null;
// Compound block - get index of internal block for removing
if (intersectedBlock.FatBlock is MyCompoundCubeBlock)
{
MyCompoundCubeBlock compoundBlock = intersectedBlock.FatBlock as MyCompoundCubeBlock;
ushort? idInCompound = null;
ushort blockId;
MyIntersectionResultLineTriangleEx? triIntersection;
if (compoundBlock.GetIntersectionWithLine(ref line, out triIntersection, out blockId))
idInCompound = blockId;
else if (compoundBlock.GetBlocksCount() == 1) // If not intersecting with any internal block and there is only one then set the index to it
idInCompound = compoundBlock.GetBlockId(compoundBlock.GetBlocks()[0]);
compoundBlockId = idInCompound;
}
Debug.Assert(intersectedObjectPos != null);
Vector3D rayStart = Vector3D.Transform(IntersectionStart, inverseGridWorldMatrix);
Vector3D rayDir = Vector3D.Normalize(Vector3D.TransformNormal(IntersectionDirection, inverseGridWorldMatrix));
intersection = rayStart + distance * rayDir;
intersection *= 1.0f / CurrentGrid.GridSize;
return intersectedObjectPos;
}
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:53,代码来源:MyBlockBuilderBase.cs
示例9: IntersectCubes
protected Vector3I? IntersectCubes(MyCubeGrid grid, out double distance)
{
distance = float.MaxValue;
var line = new LineD(IntersectionStart, IntersectionStart + IntersectionDirection * IntersectionDistance);
Vector3I position = Vector3I.Zero;
double dstSqr = double.MaxValue;
if (grid.GetLineIntersectionExactGrid(ref line, ref position, ref dstSqr))
{
distance = Math.Sqrt(dstSqr);
return position;
}
return null;
}
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:15,代码来源:MyBlockBuilderBase.cs
示例10: FindClosestGrid
public MyCubeGrid FindClosestGrid()
{
LineD line = new LineD(IntersectionStart, IntersectionStart + IntersectionDirection * IntersectionDistance);
m_tmpHitList.Clear();
MyPhysics.CastRay(line.From, line.To, m_tmpHitList, MyPhysics.ObjectDetectionCollisionLayer);
// Remove character hits.
m_tmpHitList.RemoveAll(delegate(MyPhysics.HitInfo hit)
{
return (hit.HkHitInfo.GetHitEntity() == MySession.ControlledEntity.Entity);
});
if (m_tmpHitList.Count == 0)
return null;
MyCubeGrid closestGrid = m_tmpHitList[0].HkHitInfo.GetHitEntity() as MyCubeGrid;
return closestGrid;
}
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:18,代码来源:MyBlockBuilderBase.cs
示例11: TryRayCastGrid
public static bool TryRayCastGrid(ref LineD worldRay, out MyCubeGrid hitGrid, out Vector3D worldHitPos)
{
try
{
MyPhysics.CastRay(worldRay.From, worldRay.To, m_tmpHitList);
foreach (var hit in m_tmpHitList)
{
var cubeGrid = hit.HkHitInfo.GetHitEntity() as MyCubeGrid;
if (cubeGrid == null)
continue;
worldHitPos = hit.Position;
VRageRender.MyRenderProxy.DebugDrawAABB(new BoundingBoxD(worldHitPos - 0.01, worldHitPos + 0.01), Color.Wheat.ToVector3(), 1f, 1f, true);
hitGrid = cubeGrid;
return true;
}
hitGrid = default(MyCubeGrid);
worldHitPos = default(Vector3D);
return false;
}
finally
{
m_tmpHitList.Clear();
}
}
开发者ID:ales-vilchytski,项目名称:SpaceEngineers,代码行数:26,代码来源:MyCubeGrid.Static.cs
示例12: GetIntersectionWithLine
/// <summary>
/// Returns closest hit from line start position.
/// </summary>
public bool GetIntersectionWithLine(ref LineD line, ref MyCharacterHitInfo info, IntersectionFlags flags = IntersectionFlags.ALL_TRIANGLES)
{
// TODO: This now uses caspule of physics rigid body on the character, it needs to be changed to ragdoll
// Currently this approach will be used to support Characters with different skeleton than humanoid
if (info == null)
info = new MyCharacterHitInfo();
info.Reset();
bool capsulesReady = UpdateCapsuleBones();
if (!capsulesReady)
return false;
double closestDistanceToHit = double.MaxValue;
Vector3D hitPosition = Vector3D.Zero;
Vector3D hitPosition2 = Vector3D.Zero;
Vector3 hitNormal = Vector3.Zero;
Vector3 hitNormal2 = Vector3.Zero;
int capsuleIndex = -1;
for (int i = 0; i < m_bodyCapsules.Length; i++)
{
CapsuleD capsule = m_bodyCapsules[i];
if (capsule.Intersect(line, ref hitPosition, ref hitPosition2, ref hitNormal, ref hitNormal2))
{
double distanceToHit = Vector3.Distance(hitPosition, line.From);
if (distanceToHit >= closestDistanceToHit)
continue;
closestDistanceToHit = distanceToHit;
capsuleIndex = i;
}
}
if (capsuleIndex != -1)
{
Matrix worldMatrix = PositionComp.WorldMatrix;
int boneIndex = FindBestBone(capsuleIndex, ref hitPosition, ref worldMatrix);
// Transform line to model static position and compute accurate collision there
// 1. Transform line in local coordinates (used later)
Matrix worldMatrixInv = PositionComp.WorldMatrixNormalizedInv;
Vector3 fromTrans = Vector3.Transform(line.From, ref worldMatrixInv);
Vector3 toTrans = Vector3.Transform(line.To, ref worldMatrixInv);
LineD lineLocal = new LineD(fromTrans, toTrans);
// 2. Transform line to to bone pose in binding position
var bone = AnimationController.CharacterBones[boneIndex];
bone.ComputeAbsoluteTransform();
Matrix boneAbsTrans = bone.AbsoluteTransform;
Matrix skinTransform = bone.SkinTransform;
Matrix boneTrans = skinTransform * boneAbsTrans;
Matrix invBoneTrans = Matrix.Invert(boneTrans);
fromTrans = Vector3.Transform(fromTrans, ref invBoneTrans);
toTrans = Vector3.Transform(toTrans, ref invBoneTrans);
// 3. Move back line to world coordinates
LineD lineTransWorld = new LineD(Vector3.Transform(fromTrans, ref worldMatrix), Vector3.Transform(toTrans, ref worldMatrix));
MyIntersectionResultLineTriangleEx? triangle_;
bool success = base.GetIntersectionWithLine(ref lineTransWorld, out triangle_, flags);
if (success)
{
MyIntersectionResultLineTriangleEx triangle = triangle_.Value;
info.CapsuleIndex = capsuleIndex;
info.BoneIndex = boneIndex;
info.Capsule = m_bodyCapsules[info.CapsuleIndex];
info.HitHead = info.CapsuleIndex == 0 && m_bodyCapsules.Length > 1;
info.HitPositionBindingPose = triangle.IntersectionPointInObjectSpace;
info.HitNormalBindingPose = triangle.NormalInObjectSpace;
// 4. Move intersection from binding to dynamic pose
MyTriangle_Vertexes vertices = new MyTriangle_Vertexes();
vertices.Vertex0 = Vector3.Transform(triangle.Triangle.InputTriangle.Vertex0, ref boneTrans);
vertices.Vertex1 = Vector3.Transform(triangle.Triangle.InputTriangle.Vertex1, ref boneTrans);
vertices.Vertex2 = Vector3.Transform(triangle.Triangle.InputTriangle.Vertex2, ref boneTrans);
Vector3 triangleNormal = Vector3.TransformNormal(triangle.Triangle.InputTriangleNormal, boneTrans);
MyIntersectionResultLineTriangle triraw = new MyIntersectionResultLineTriangle(ref vertices, ref triangleNormal, triangle.Triangle.Distance);
Vector3 intersectionLocal = Vector3.Transform(triangle.IntersectionPointInObjectSpace, ref boneTrans);
Vector3 normalLocal = Vector3.TransformNormal(triangle.NormalInObjectSpace, boneTrans);
// 5. Store results
triangle = new MyIntersectionResultLineTriangleEx();
triangle.Triangle = triraw;
triangle.IntersectionPointInObjectSpace = intersectionLocal;
triangle.NormalInObjectSpace = normalLocal;
triangle.IntersectionPointInWorldSpace = Vector3.Transform(intersectionLocal, ref worldMatrix);
triangle.NormalInWorldSpace = Vector3.TransformNormal(normalLocal, worldMatrix);
triangle.InputLineInObjectSpace = lineLocal;
info.Triangle = triangle;
if (MyDebugDrawSettings.ENABLE_DEBUG_DRAW)
{
MyRenderProxy.DebugClearPersistentMessages();
//.........这里部分代码省略.........
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:101,代码来源:MyCharacter.cs
示例13: GetAimedPointFromHead
Vector3D GetAimedPointFromHead()
{
MatrixD headMatrix = GetHeadMatrix(false);
var endPoint = headMatrix.Translation + headMatrix.Forward * 25000;
// Same optimization as the one in GetAimedPointFromCamera.
return endPoint;
if (MySession.Static.ControlledEntity == this)
{
LineD line = new LineD(headMatrix.Translation, endPoint);
//Line line = new Line(MySector.MainCamera.Position, MySector.MainCamera.Position + MySector.MainCamera.ForwardVector * 1000);
var intersection = MyEntities.GetIntersectionWithLine(ref line, this, (MyEntity)m_currentWeapon);
if (intersection.HasValue)
{
return intersection.Value.IntersectionPointInWorldSpace;
}
else
{
return (Vector3D)line.To;
}
}
else
{
return endPoint;
}
}
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:27,代码来源:MyCharacter.cs
示例14: GetIntersectionWithLineAndBoundingSphere
// Calculates intersection of line with any bounding sphere in this model instance. Center of the bounding sphere will be returned.
// It takes boundingSphereRadiusMultiplier argument which serves for extending the influence (radius) for interaction with line.
public virtual Vector3D? GetIntersectionWithLineAndBoundingSphere(ref LineD line, float boundingSphereRadiusMultiplier)
{
if (Render.GetModel() == null)
return null;
BoundingSphereD vol = PositionComp.WorldVolume;
vol.Radius *= boundingSphereRadiusMultiplier;
// Check if line intersects phys object's current bounding sphere, and if not, return 'no intersection'
if (!MyUtils.IsLineIntersectingBoundingSphere(ref line, ref vol))
return null;
return vol.Center;
}
开发者ID:Chrus,项目名称:SpaceEngineers,代码行数:16,代码来源:MyEntity.cs
示例15: GetTargetEntity
/// <summary>
/// Obtain entity that player is aiming/looking at.
/// </summary>
public static MyEntity GetTargetEntity()
{
var line = new LineD(MySector.MainCamera.Position, MySector.MainCamera.Position + MySector.MainCamera.ForwardVector * 10000);
m_tmpHitList.Clear();
MyPhysics.CastRay(line.From, line.To, m_tmpHitList, MyPhysics.CollisionLayers.DefaultCollisionLayer);
// Remove character hits.
m_tmpHitList.RemoveAll(delegate(MyPhysics.HitInfo hit)
{
return (hit.HkHitInfo.GetHitEntity() == MySession.Static.ControlledEntity.Entity);
});
if (m_tmpHitList.Count == 0)
return null;
return m_tmpHitList[0].HkHitInfo.GetHitEntity() as MyEntity;
}
开发者ID:ales-vilchytski,项目名称:SpaceEngineers,代码行数:20,代码来源:MyCubeGrid.Static.cs
示例16: TestPath
private void TestPath()
{
using (m_lock.AcquireExclusiveUsing())
{
if (m_grid.MarkedForClose)
{
CurrentState = State.BlockedPath;
m_cells.Clear();
return;
}
if (CurrentState == State.None)
{
m_cells.Clear();
return;
}
//MyGameTimer timer = new MyGameTimer();
if (m_cells.Count != 0)
{
Vector3D worldPos = m_grid.GridIntegerToWorld(m_cells.Dequeue());
LineD worldLine = new LineD(worldPos, worldPos + m_displacement);
//var createLine = timer.Elapsed;
//timer = new MyGameTimer();
Vector3D? contact;
if (RayCast.RayCastVoxel(ClosestPlanet, worldLine, out contact))
{
//var intersect = timer.Elapsed;
m_logger.debugLog("Intersected line: " + worldLine.From + " to " + worldLine.To + ", at " + contact, Logger.severity.DEBUG);
//m_logger.debugLog("Intersected line: " + worldLine.From + " to " + worldLine.To + ", at " + contact + ", createLine: " + createLine.ToPrettySeconds() + ", intersect: " + intersect.ToPrettySeconds(), "TestPath()", Logger.severity.DEBUG);
ObstructionPoint = contact.Value;
CurrentState = State.BlockedPath;
m_cells.Clear();
return;
}
//else
//{
// var intersect = timer.Elapsed;
// m_logger.debugLog("no intersection with line: " + worldLine.From + " to " + worldLine.To + ", createLine: " + createLine.ToPrettySeconds() + ", intersect: " + intersect.ToPrettySeconds(), "TestPath()", Logger.severity.TRACE);
//}
DoTests.Enqueue(TestPath);
}
else
{
m_logger.debugLog("finished, clear", Logger.severity.DEBUG);
CurrentState = State.Clear;
}
}
}
开发者ID:Souper07,项目名称:Autopilot,代码行数:51,代码来源:PlanetChecker.cs
示例17: UpdatePlacement
public void UpdatePlacement()
{
m_lastUpdate = MySession.Static.GameplayFrameCounter;
m_hitInfo = null;
m_closestGrid = null;
m_closestVoxelMap = null;
LineD line = new LineD(RayStart, RayStart + RayDirection * IntersectionDistance);
MyPhysics.CastRay(line.From, line.To, m_tmpHitList,
MyPhysics.CollisionLayers.ObjectDetectionCollisionLayer);
// Remove character hits.
m_tmpHitList.RemoveAll(delegate(MyPhysics.HitInfo hitInfo)
{
return (hitInfo.HkHitInfo.GetHitEntity() == MySession.Static.ControlledEntity.Entity);
});
if (m_tmpHitList.Count == 0)
return;
var hit = m_tmpHitList[0];
m_closestGrid = hit.HkHitInfo.GetHitEntity() as MyCubeGrid;
if (m_closestGrid != null)
{
//always assign otherwise the block will be completely inside/behind the grid
m_hitInfo = hit;
if (!ClosestGrid.Editable)
m_closestGrid = null;
return;
}
//if (MyFakes.ENABLE_BLOCK_PLACEMENT_ON_VOXEL) // TODO: check this MyFake to remove or what?
//{
m_closestVoxelMap = hit.HkHitInfo.GetHitEntity() as MyVoxelBase;
if (m_closestVoxelMap != null)
m_hitInfo = hit;
//}
}
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:39,代码来源:MyDefaultPlacementProvider.cs
示例18: GetIntersectionWithLine
// Method finds intersection with line and any voxel triangleVertexes in this voxel map. Closes intersection is returned.
internal override bool GetIntersectionWithLine(ref LineD worldLine, out MyIntersectionResultLineTriangleEx? t, IntersectionFlags flags = IntersectionFlags.ALL_TRIANGLES)
{
t = null;
double intersectionDistance;
LineD line = (LineD)worldLine;
if (!PositionComp.WorldAABB.Intersects(line, out intersectionDistance))
return false;
ProfilerShort.Begin("VoxelMap.LineIntersection");
try
{
Line localLine = new Line(worldLine.From - PositionLeftBottomCorner,
worldLine.To - PositionLeftBottomCorner, true);
MyIntersectionResultLineTriangle tmpResult;
if (Storage.Geometry.Intersect(ref localLine, out tmpResult, flags))
{
t = new MyIntersectionResultLineTriangleEx(tmpResult, this, ref worldLine);
var tmp = t.Value.IntersectionPointInWorldSpace;
tmp.AssertIsValid();
return true;
}
else
{
t = null;
return false;
}
}
finally
{
ProfilerShort.End();
}
}
开发者ID:austusross,项目名称:SpaceEngineers,代码行数:34,代码来源:MyVoxelBase.cs
示例19: FindClosestPlacementObject
/// <summary>
/// Finds closest object (grid or voxel map) for placement of blocks .
/// </summary>
public bool FindClosestPlacementObject(out MyCubeGrid closestGrid, out MyVoxelMap closestVoxelMap)
{
closestGrid = null;
closestVoxelMap = null;
if (MySession.ControlledEntity == null) return false;
m_hitInfo = null;
LineD line = new LineD(IntersectionStart, IntersectionStart + IntersectionDirection * IntersectionDistance);
MyPhysics.CastRay(line.From, line.To, m_tmpHitList, MyPhysics.ObjectDetectionCollisionLayer);
// Remove character hits.
m_tmpHitList.RemoveAll(delegate(MyPhysics.HitInfo hitInfo)
{
return (hitInfo.HkHitInfo.GetHitEntity() == MySession.ControlledEntity.Entity);
});
if (m_tmpHitList.Count == 0)
return false;
var hit = m_tmpHitList[0];
closestGrid = hit.HkHitInfo.GetHitEntity() as MyCubeGrid;
if (closestGrid != null)
{
m_hitInfo = hit;
}
if (MyFakes.ENABLE_BLOCK_PLACEMENT_ON_VOXEL)
{
closestVoxelMap = hit.HkHitInfo.GetHitEntity() as MyVoxelMap;
if (closestVoxelMap != null)
m_hitInfo = hit;
}
return closestGrid != null || closestVoxelMap != null;
}
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:41,代码来源:MyBlockBuilderBase.cs
示例20: IntersectExact
/// <summary>
/// Calculates exact intersection point (in uniform grid coordinates) of eye ray with the given grid of all cubes.
/// Returns position of intersected object in uniform grid coordinates
/// </summary>
protected Vector3D? IntersectExact(MyCubeGrid grid, ref MatrixD inverseGridWorldMatrix, out Vector3D intersection, out MySlimBlock intersectedBlock)
{
intersection = Vector3D.Zero;
var line = new LineD(IntersectionStart, IntersectionStart + IntersectionDirection * IntersectionDistance);
double distance;
Vector3D? intersectedObjectPos = grid.GetLineIntersectionExactAll(ref line, out distance, out intersectedBlock);
if (intersectedObjectPos != null)
{
Vector3D rayStart = Vector3D.Transform(IntersectionStart, inverseGridWorldMatrix);
Vector3D rayDir = Vector3D.Normalize(Vector3D.TransformNormal(IntersectionDirection, inverseGridWorldMatrix));
intersection = rayStart + distance * rayDir;
intersection *= 1.0f / grid.GridSize;
}
return intersectedObjectPos;
}
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:21,代码来源:MyBlockBuilderBase.cs
注:本文中的VRageMath.LineD类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论