本文整理汇总了C#中MatrixD.GetOrientation方法的典型用法代码示例。如果您正苦于以下问题:C# MatrixD.GetOrientation方法的具体用法?C# MatrixD.GetOrientation怎么用?C# MatrixD.GetOrientation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MatrixD
的用法示例。
在下文中一共展示了MatrixD.GetOrientation方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawCollisionShape
public static void DrawCollisionShape(HkShape shape, MatrixD worldMatrix, float alpha, ref int shapeIndex, string customText = null, bool isPhantom = false)
{
var color = GetShapeColor(shape.ShapeType, ref shapeIndex, isPhantom);
if (isPhantom) alpha *= alpha;
color.A = (byte)(alpha * 255);
bool shaded = true;
float expandSize = 0.02f;
float expandRatio = 1.035f;
bool drawCustomText = false;
switch (shape.ShapeType)
{
case HkShapeType.Sphere:
{
var sphere = (HkSphereShape)shape;
float radius = sphere.Radius;
VRageRender.MyRenderProxy.DebugDrawSphere(worldMatrix.Translation, radius, color, alpha, true, shaded);
if (isPhantom)
{
VRageRender.MyRenderProxy.DebugDrawSphere(worldMatrix.Translation, radius, color, 1.0f, true, false);
VRageRender.MyRenderProxy.DebugDrawSphere(worldMatrix.Translation, radius, color, 1.0f, true, false, false);
}
drawCustomText = true;
break;
}
case HkShapeType.Capsule:
{
// Sphere and OBB to show cylinder space
var capsule = (HkCapsuleShape)shape;
Vector3D vertexA = Vector3.Transform(capsule.VertexA, worldMatrix);
Vector3D vertexB = Vector3.Transform(capsule.VertexB, worldMatrix);
VRageRender.MyRenderProxy.DebugDrawCapsule(vertexA, vertexB, capsule.Radius, color, true, shaded);
drawCustomText = true;
break;
}
case HkShapeType.Cylinder:
{
// Sphere and OBB to show cylinder space
var cylinder = (HkCylinderShape)shape;
VRageRender.MyRenderProxy.DebugDrawCylinder(worldMatrix, cylinder.VertexA, cylinder.VertexB, cylinder.Radius, color, alpha, true, shaded);
drawCustomText = true;
break;
}
case HkShapeType.Box:
{
var box = (HkBoxShape)shape;
VRageRender.MyRenderProxy.DebugDrawOBB(MatrixD.CreateScale(box.HalfExtents * 2 + new Vector3(expandSize)) * worldMatrix, color, alpha, true, shaded);
if (isPhantom)
{
VRageRender.MyRenderProxy.DebugDrawOBB(Matrix.CreateScale(box.HalfExtents * 2 + new Vector3(expandSize)) * worldMatrix, color, 1.0f, true, false);
VRageRender.MyRenderProxy.DebugDrawOBB(Matrix.CreateScale(box.HalfExtents * 2 + new Vector3(expandSize)) * worldMatrix, color, 1.0f, true, false, false);
}
drawCustomText = true;
break;
}
case HkShapeType.ConvexVertices:
{
var convexShape = (HkConvexVerticesShape)shape;
Vector3 center;
convexShape.GetGeometry(DebugGeometry, out center);
Vector3D transformedCenter = Vector3D.Transform(center, worldMatrix.GetOrientation());
var matrix = worldMatrix;
matrix = MatrixD.CreateScale(expandRatio) * matrix;
matrix.Translation -= transformedCenter * (expandRatio - 1);
//matrix.Translation += transformedCenter;
DrawGeometry(DebugGeometry, matrix, color, true, true);
drawCustomText = true;
break;
}
case HkShapeType.ConvexTranslate:
{
var translateShape = (HkConvexTranslateShape)shape;
DrawCollisionShape((HkShape)translateShape.ChildShape, Matrix.CreateTranslation(translateShape.Translation) * worldMatrix, alpha, ref shapeIndex, customText);
break;
}
case HkShapeType.ConvexTransform:
{
var transformShape = (HkConvexTransformShape)shape;
DrawCollisionShape(transformShape.ChildShape, transformShape.Transform * worldMatrix, alpha, ref shapeIndex, customText);
break;
}
case HkShapeType.Mopp:
//.........这里部分代码省略.........
示例2: AddGizmoCubeParts
private void AddGizmoCubeParts(MyGizmoSpaceProperties gizmoSpace, MyBlockBuilderRenderData renderData, ref MatrixD invGridWorldMatrix, MyCubeBlockDefinition definition)
{
Vector3UByte[] bones = null;
MyTileDefinition[] tiles = null;
MatrixD invGridWorldMatrixOrientation = invGridWorldMatrix.GetOrientation();
float gridSize = 1f;
if (definition != null && definition.Skeleton != null)
{
tiles = MyCubeGridDefinitions.GetCubeTiles(definition);
gridSize = MyDefinitionManager.Static.GetCubeSize(definition.CubeSize);
}
for (int faceIndex = 0; faceIndex < gizmoSpace.m_cubeModelsTemp.Count; faceIndex++)
{
string cubePartModel = gizmoSpace.m_cubeModelsTemp[faceIndex];
gizmoSpace.m_cubeModels.Add(cubePartModel);
gizmoSpace.m_cubeMatrices.Add(gizmoSpace.m_cubeMatricesTemp[faceIndex]);
int tileIndex = faceIndex % tiles.Count();
var invertedTile = Matrix.Transpose(tiles[tileIndex].LocalMatrix);
var onlyOrientation = invertedTile * gizmoSpace.m_cubeMatricesTemp[faceIndex].GetOrientation();
var boneMatrix = onlyOrientation * invGridWorldMatrixOrientation;
if (tiles != null)
{
bones = new Vector3UByte[9];
for (int i = 0; i < 9; i++)
{
bones[i] = new Vector3UByte(128, 128, 128);
}
var model = MyModels.GetModel(cubePartModel);
for (int index = 0; index < Math.Min(model.BoneMapping.Length, 9); index++)
{
var boneOffset = model.BoneMapping[index];
Vector3 centered = boneOffset - Vector3.One;
Vector3I transformedOffset = Vector3I.Round(Vector3.Transform(centered, tiles[tileIndex].LocalMatrix) + Vector3.One);
for (int skeletonIndex = 0; skeletonIndex < definition.Skeleton.Count; skeletonIndex++)
{
BoneInfo skeletonBone = definition.Skeleton[skeletonIndex];
if (skeletonBone.BonePosition == (SerializableVector3I)transformedOffset)
{
Vector3 bone = Vector3UByte.Denormalize(skeletonBone.BoneOffset, gridSize);
Vector3 transformedBone = Vector3.Transform(bone, boneMatrix);
bones[index] = Vector3UByte.Normalize(transformedBone, gridSize);
break;
}
}
}
}
renderData.AddInstance(MyModel.GetId(cubePartModel), gizmoSpace.m_cubeMatricesTemp[faceIndex], ref invGridWorldMatrix, bones: bones, gridSize: gridSize);
}
}
示例3: CreateFracturePiece
public static void CreateFracturePiece(MyEnvironmentItemDefinition itemDefinition, HkdBreakableShape oldBreakableShape, MatrixD worldMatrix, Vector3 hitNormal, List<HkdShapeInstanceInfo> shapeList,
float forceMultiplier, bool canContainFixedChildren)
{
bool containsFixedChildren = false;
if (canContainFixedChildren)
{
foreach (var shapeInst in shapeList)
{
shapeInst.Shape.SetMotionQualityRecursively(HkdBreakableShape.BodyQualityType.QUALITY_DEBRIS);
var t = worldMatrix.Translation + worldMatrix.Up * 1.5f;
var o = Quaternion.CreateFromRotationMatrix(worldMatrix.GetOrientation());
MyPhysics.GetPenetrationsShape(shapeInst.Shape.GetShape(), ref t, ref o, m_tmpResults, MyPhysics.DefaultCollisionLayer);
bool flagSet = false;
foreach (var res in m_tmpResults)
{
var entity = res.GetCollisionEntity();
if (entity is MyVoxelMap)
{
shapeInst.Shape.SetFlagRecursively(HkdBreakableShape.Flags.IS_FIXED);
containsFixedChildren = true;
flagSet = true;
break;
}
if (flagSet)
break;
}
m_tmpResults.Clear();
}
}
HkdBreakableShape compound = new HkdCompoundBreakableShape(oldBreakableShape, shapeList);
((HkdCompoundBreakableShape)compound).RecalcMassPropsFromChildren();
//compound.SetMassRecursively(500);
//compound.SetStrenghtRecursively(5000, 0.7f);
var fp = MyDestructionHelper.CreateFracturePiece(compound, MyPhysics.SingleWorld.DestructionWorld, ref worldMatrix, containsFixedChildren, itemDefinition.Id, true);
if (fp != null && !canContainFixedChildren)
{
ApplyImpulseToTreeFracture(ref worldMatrix, ref hitNormal, shapeList, ref compound, fp, forceMultiplier);
fp.Physics.ForceActivate();
}
}
示例4: CalculateRotationHints
public void CalculateRotationHints(MatrixD drawMatrix, BoundingBoxD worldBox, bool draw, bool fixedAxes = false, bool hideForwardAndUpArrows = false)
{
drawMatrix.Translation = Vector3D.Zero;
MatrixD drawInverse = MatrixD.Invert(drawMatrix);
drawInverse *= drawMatrix.GetOrientation();
drawInverse *= MySector.MainCamera.ViewMatrixAtZero;
MatrixD camWorld = MatrixD.Invert(drawInverse); //MatrixD.Invert(MySector.MainCamera.ViewMatrixAtZero)*MatrixD.Invert(drawMatrix.GetOrientation())*drawMatrix;
m_viewProjection.ViewAtZero = MatrixD.CreateLookAt(Vector3D.Zero, camWorld.Forward, camWorld.Up);
m_viewProjection.ViewAtZero.Translation = new Vector3D(0,0,-6);
m_viewProjection.View = drawInverse;
m_viewProjection.View.Translation += new Vector3D(0, 0, -6);
m_viewProjection.CameraPosition = camWorld.Translation;
Vector2 screenSize = MyGuiManager.GetScreenSizeFromNormalizedSize(Vector2.One);
float previewRatio = 2.5f;
int hintsWidth = (int)(screenSize.X / previewRatio), hintsHeight = (int)(screenSize.Y / previewRatio), hintsXOffset = 0, hintsYOffset = 0;
m_viewProjection.Viewport = new MyViewport(
(int)MySector.MainCamera.Viewport.Width - hintsWidth - hintsXOffset,
hintsYOffset,
hintsWidth,
hintsHeight);
m_viewProjection.DepthRead = false;
m_viewProjection.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, (float)hintsWidth / hintsHeight, 0.1f, 10);
worldBox = new BoundingBoxD(-new Vector3(MyDefinitionManager.Static.GetCubeSize(MyCubeSize.Large) * 0.5f), new Vector3(MyDefinitionManager.Static.GetCubeSize(MyCubeSize.Large)) * 0.5f);
//m_rotationHintsViewProjection.Projection = MySector.MainCamera.ProjectionMatrix;
int projectionId = 0;
VRageRender.MyRenderProxy.AddBillboardViewProjection(projectionId, m_viewProjection);
//MySimpleObjectDraw.DrawTransparentBox(ref drawMatrix,
// ref worldBox, ref Vector4.One, MySimpleObjectRasterizer.Wireframe, 1, 0.04f, null, null, false, 0);
if (draw)
{
var white = Color.White;
MySimpleObjectDraw.DrawTransparentBox(ref drawMatrix,
ref worldBox, ref white, MySimpleObjectRasterizer.Solid, 1, 0.04f, "SquareFullColor", null, false, projectionId, 100);
}
MyOrientedBoundingBoxD rotateHintsBox = new MyOrientedBoundingBoxD(Vector3D.Transform(worldBox.Center, drawMatrix), worldBox.HalfExtents, Quaternion.CreateFromRotationMatrix(drawMatrix));
//VRageRender.MyRenderProxy.DebugDrawOBB(rotateHintsBox, Vector3.One, 1, false, false);
rotateHintsBox.GetCorners(m_cubeVertices, 0);
//for (int vi = 0; vi < 8; vi++)
//{
// VRageRender.MyRenderProxy.DebugDrawText3D(m_cubeVertices[vi], vi.ToString(), Color.White, 0.7f, false);
//}
//for (int vi = 0; vi < 4; vi++)
//{
// VRageRender.MyRenderProxy.DebugDrawText3D((m_cubeVertices[MyOrientedBoundingBox.StartXVertices[vi]] + m_cubeVertices[MyOrientedBoundingBox.EndXVertices[vi]]) * 0.5f, vi.ToString(), Color.Red, 0.7f, false);
// VRageRender.MyRenderProxy.DebugDrawText3D((m_cubeVertices[MyOrientedBoundingBox.StartYVertices[vi]] + m_cubeVertices[MyOrientedBoundingBox.EndYVertices[vi]]) * 0.5f, vi.ToString(), Color.Green, 0.7f, false);
// VRageRender.MyRenderProxy.DebugDrawText3D((m_cubeVertices[MyOrientedBoundingBox.StartZVertices[vi]] + m_cubeVertices[MyOrientedBoundingBox.EndZVertices[vi]]) * 0.5f, vi.ToString(), Color.Blue, 0.7f, false);
//}
int closestXAxis, closestXAxis2;
GetClosestCubeEdge(m_cubeVertices, MyOrientedBoundingBox.StartXVertices, MyOrientedBoundingBox.EndXVertices, out closestXAxis, out closestXAxis2);
Vector3D startXVertex = m_cubeVertices[MyOrientedBoundingBox.StartXVertices[closestXAxis]];
Vector3D endXVertex = m_cubeVertices[MyOrientedBoundingBox.EndXVertices[closestXAxis]];
Vector3D startXVertex2 = m_cubeVertices[MyOrientedBoundingBox.StartXVertices[closestXAxis2]];
Vector3D endXVertex2 = m_cubeVertices[MyOrientedBoundingBox.EndXVertices[closestXAxis2]];
int closestYAxis, closestYAxis2;
GetClosestCubeEdge(m_cubeVertices, MyOrientedBoundingBox.StartYVertices, MyOrientedBoundingBox.EndYVertices, out closestYAxis, out closestYAxis2);
Vector3D startYVertex = m_cubeVertices[MyOrientedBoundingBox.StartYVertices[closestYAxis]];
Vector3D endYVertex = m_cubeVertices[MyOrientedBoundingBox.EndYVertices[closestYAxis]];
Vector3D startYVertex2 = m_cubeVertices[MyOrientedBoundingBox.StartYVertices[closestYAxis2]];
Vector3D endYVertex2 = m_cubeVertices[MyOrientedBoundingBox.EndYVertices[closestYAxis2]];
int closestZAxis, closestZAxis2;
GetClosestCubeEdge(m_cubeVertices, MyOrientedBoundingBox.StartZVertices, MyOrientedBoundingBox.EndZVertices, out closestZAxis, out closestZAxis2);
Vector3D startZVertex = m_cubeVertices[MyOrientedBoundingBox.StartZVertices[closestZAxis]];
Vector3D endZVertex = m_cubeVertices[MyOrientedBoundingBox.EndZVertices[closestZAxis]];
Vector3D startZVertex2 = m_cubeVertices[MyOrientedBoundingBox.StartZVertices[closestZAxis2]];
Vector3D endZVertex2 = m_cubeVertices[MyOrientedBoundingBox.EndZVertices[closestZAxis2]];
m_cubeEdges.Clear();
m_cubeEdges.Add(new BoxEdge() { Axis = 0, Edge = new LineD(startXVertex, endXVertex) });
m_cubeEdges.Add(new BoxEdge() { Axis = 1, Edge = new LineD(startYVertex, endYVertex) });
m_cubeEdges.Add(new BoxEdge() { Axis = 2, Edge = new LineD(startZVertex, endZVertex) });
if (!fixedAxes)
{
int rotDirection;
RotationRightAxis = GetBestAxis(m_cubeEdges, MySector.MainCamera.WorldMatrix.Right, out rotDirection);
//.........这里部分代码省略.........
示例5: DebugDrawShape
private void DebugDrawShape(string blockName, HkShape shape, MatrixD worldMatrix)
{
float expandRatio = 1.05f;
float expandSize = 0.02f;
if (MyPerGameSettings.Game == GameEnum.SE_GAME)
expandSize = 0.1f;
switch (shape.ShapeType)
{
case Havok.HkShapeType.Box:
Havok.HkBoxShape box = (HkBoxShape) shape;
MyRenderProxy.DebugDrawOBB(MatrixD.CreateScale(box.HalfExtents * 2 + new Vector3(expandSize)) * worldMatrix, Color.Red, 0, true, false);
break;
case Havok.HkShapeType.List:
var listShape = (HkListShape)shape;
var iterator = listShape.GetIterator();
int shapeIndex = 0;
while (iterator.IsValid)
{
DebugDrawShape(blockName + shapeIndex++, iterator.CurrentValue, worldMatrix);
iterator.Next();
}
break;
case HkShapeType.Mopp:
var compoundShape = (HkMoppBvTreeShape)shape;
DebugDrawShape(blockName, compoundShape.ShapeCollection, worldMatrix);
break;
case HkShapeType.ConvexTransform:
var transformShape = (HkConvexTransformShape)shape;
DebugDrawShape(blockName, transformShape.ChildShape, transformShape.Transform * worldMatrix);
break;
case HkShapeType.ConvexTranslate:
var translateShape = (HkConvexTranslateShape)shape;
DebugDrawShape(blockName, (HkShape)translateShape.ChildShape, Matrix.CreateTranslation(translateShape.Translation) * worldMatrix);
break;
case HkShapeType.ConvexVertices:
var convexShape = (HkConvexVerticesShape)shape;
GeometryCenterPair geometryCenterPair;
ProfilerShort.Begin("MyExternalPathfinfing.m_cachedGeometry.TryGetValue");
if (!m_cachedGeometry.TryGetValue(blockName, out geometryCenterPair))
{
HkGeometry debugGeometry = new HkGeometry();
Vector3 center;
convexShape.GetGeometry(debugGeometry, out center);
geometryCenterPair = new GeometryCenterPair() { Geometry = debugGeometry, Center = center };
if (!string.IsNullOrEmpty(blockName))
m_cachedGeometry.Add(blockName, geometryCenterPair);
}
ProfilerShort.End();
Vector3D transformedCenter = Vector3D.Transform(geometryCenterPair.Center, worldMatrix.GetOrientation());
var matrix = worldMatrix;
matrix = MatrixD.CreateScale(expandRatio) * matrix;
matrix.Translation -= transformedCenter * (expandRatio - 1);
DrawGeometry(geometryCenterPair.Geometry, matrix, Color.Olive);
break;
default:
// For breakpoint. Don't judge me :(
break;
}
}
示例6: OnWorldPositionChanged
public override void OnWorldPositionChanged(ref MatrixD worldMatrix)
{
m_orientation = Quaternion.CreateFromRotationMatrix(worldMatrix.GetOrientation());
Center = worldMatrix.Translation + worldMatrix.Forward * m_centerOffset;
FrontPoint = Center + worldMatrix.Forward * m_halfExtents.Z;
}