本文整理汇总了C#中Matrix4.Inverted方法的典型用法代码示例。如果您正苦于以下问题:C# Matrix4.Inverted方法的具体用法?C# Matrix4.Inverted怎么用?C# Matrix4.Inverted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix4
的用法示例。
在下文中一共展示了Matrix4.Inverted方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: updateCamera
public void updateCamera(ref Matrix4 rendererWorldMat, ref Vector3 cameraPosLocal)
{
var laserParams = _laser.parameters;
for (int i = 0; i < laserParams.numBeams; ++i) {
var beam = _laser.beam(i);
var flashEmitter = _flashEmitters [i];
var smokeEmitter = _smokeEmitters [i];
// TODO need intersection location
if (beam.hitsAnObstacle) {
var hitPosLocal = Vector3.Transform(beam.endPosWorld, rendererWorldMat.Inverted());
var towardsCamera = (cameraPosLocal - hitPosLocal).Normalized();
flashEmitter.center = hitPosLocal;
flashEmitter.up = towardsCamera;
flashEmitter.particlesPerEmissionMin = laserParams.flashParticlesPerEmissionMin;
flashEmitter.particlesPerEmissionMax = laserParams.flashParticlesPerEmissionMax;
smokeEmitter.center = hitPosLocal;
smokeEmitter.up = towardsCamera;
smokeEmitter.particlesPerEmissionMin = laserParams.flameSmokeParticlesPerEmissionMin;
smokeEmitter.particlesPerEmissionMax = laserParams.flameSmokeParticlesPerEmissionMax;
} else {
// no hit = no particle emissions
flashEmitter.particlesPerEmission = 0;
smokeEmitter.particlesPerEmission = 0;
}
}
_flamesSmokeColorEffector.colorMask = _laser.parameters.backgroundColor;
_flamesSmokeColorEffector.colorMask.A = _laser.envelopeIntensity;
_flashColorEffector.colorMask = _laser.parameters.overlayColor;
_flashColorEffector.colorMask.A = _laser.envelopeIntensity;
}
示例2: MatrixChangedEventArgs
public MatrixChangedEventArgs(Matrix4 beforeMatrix, Matrix4 afterMatrix)
{
Delta = beforeMatrix.Inverted() * afterMatrix;
Matrix = afterMatrix;
}
示例3: viewProjFromLightAlignedBB
protected static void viewProjFromLightAlignedBB(ref SSAABB bb,
ref Matrix4 lightTransform,
ref Vector3 lightY,
out Matrix4 viewMatrix,
out Matrix4 projMatrix)
{
// Use center of AABB in regular coordinates to get the view matrix
Vector3 targetLightSpace = bb.Center();
Vector3 eyeLightSpace = new Vector3 (targetLightSpace.X,
targetLightSpace.Y,
bb.Min.Z);
Vector3 viewTarget = Vector3.Transform(targetLightSpace, lightTransform.Inverted());
Vector3 viewEye = Vector3.Transform(eyeLightSpace, lightTransform.Inverted());
Vector3 viewUp = lightY;
viewMatrix = Matrix4.LookAt(viewEye, viewTarget, viewUp);
// Finish the projection matrix
Vector3 diff = bb.Diff();
float width, height, nearZ, farZ;
width = diff.X;
height = diff.Y;
nearZ = 1f;
farZ = 1f + diff.Z;
projMatrix = Matrix4.CreateOrthographic(width, height, nearZ, farZ);
}
示例4: Setup3D
/// <summary>
/// Setting up 3D matrices<para/>
/// Подготовка матриц проекции
/// </summary>
public static void Setup3D() {
// Rebuild modelview
// Пересчёт матрицы расположения
if (needModelRebuild) {
modelMatrix =
Matrix4.CreateRotationZ(-angles.Z * 0.0174f) *
Matrix4.CreateRotationX(-angles.X * 0.0174f) *
Matrix4.CreateRotationY(-angles.Y * 0.0174f) *
Matrix4.CreateTranslation(position.X, position.Y, -position.Z);
modelInvMatrix = modelMatrix.Inverted();
skyMatrix = modelInvMatrix.ClearTranslation();
needModelRebuild = false;
}
// Rebuild projection
// Пересчёт матрицы проекции
if (needViewRebuild) {
projMatrix =
Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 3f / zoom, size.X/size.Y, CameraNear, farClip);
needViewRebuild = false;
}
// Clearing depth
// Очистка глубины
GL.Clear(ClearBufferMask.DepthBufferBit);
// Update frustum
// Обновление пирамиды отсечения
Frustum.Update(projMatrix, modelInvMatrix);
}
示例5: updateSprites
public void updateSprites(SInstancedSpriteData instanceData, ref RectangleF screenClientRect,
ref Vector3 cameraPos, ref Matrix4 camera3dView, ref Matrix4 camera3dProj)
{
float occDiskScreenAreaUsed = (float)_occDiskObj.OcclusionQueueryResult;
if (occDiskScreenAreaUsed <= 0f) {
// hide all sprites
var nanVec = new Vector2(float.NaN);
instanceData.writePosition(_backgroundSpriteIdx, nanVec);
instanceData.writePosition(_overlaySpriteIdx, nanVec);
return;
}
var laserParams = _laser.parameters;
var beam = _laser.beam(_beamId);
float beamIntensity = _laser.envelopeIntensity * beam.periodicIntensity;
// position sprites at the beam start in screen space
Matrix4 camera3dViewProjMat = camera3dView * camera3dProj;
var beamStartScreen = OpenTKHelper.WorldToScreen(beam.startPos,
ref camera3dViewProjMat, ref screenClientRect);
instanceData.writePosition(_backgroundSpriteIdx, beamStartScreen);
instanceData.writePosition(_overlaySpriteIdx, beamStartScreen);
// compute screen space needed to occupy the area where the start of the middle's crossbeam
// would be displayed
Matrix4 viewInverted = camera3dView.Inverted();
Vector3 viewRight = Vector3.Transform(Vector3.UnitX, viewInverted).Normalized();
Vector3 occRightMost = _occDiskObj.Pos + viewRight * laserParams.middleBackgroundWidth;
Vector2 occRightMostPt = OpenTKHelper.WorldToScreen(occRightMost,
ref camera3dViewProjMat, ref screenClientRect);
Vector2 occCenterPt = OpenTKHelper.WorldToScreen(_occDiskObj.Pos,
ref camera3dViewProjMat, ref screenClientRect);
float crossBeamRadiusScreenPx = Math.Abs(occRightMostPt.X - occCenterPt.X);
// write sprite size big enough to cover up the starting section of the cross beam (middle)
float scale = Math.Max(laserParams.emissionFlareScreenSizeMin, crossBeamRadiusScreenPx * 2.5f)
* beamIntensity;
instanceData.writeMasterScale(_backgroundSpriteIdx, scale * 1.2f);
instanceData.writeMasterScale(_overlaySpriteIdx, scale * 1f);
// add some variety to orientation to make the sprites look less static
instanceData.writeOrientationZ(_backgroundSpriteIdx, beamIntensity * 1f * (float)Math.PI);
instanceData.writeOrientationZ(_overlaySpriteIdx, beamIntensity * 1f * (float)Math.PI);
// color intensity: depends on the dot product between to-camera vector and beam direction;
// also depends on how of the occlusion disk area is visible
float maxScreenArea = (float)Math.PI
* laserParams.emissionOccDiskRadiusPx * laserParams.emissionOccDiskRadiusPx;
float occDiskAreaRatio = occDiskScreenAreaUsed / maxScreenArea;
//System.Console.WriteLine("occDiskAreaRatio = " + occDiskAreaRatio);
Vector3 toCamera = (cameraPos - beam.startPos).Normalized();
float dot = Math.Max(0f, Vector3.Dot(toCamera, beam.direction()));
//System.Console.WriteLine("dot = " + dot);
var alpha = occDiskAreaRatio*1.2f * (float)Math.Pow(beamIntensity, 0.1) * (float)Math.Pow(dot, 0.1);
alpha = Math.Min(alpha, 1f);
// finish background color
var backgroundColor = laserParams.backgroundColor;
backgroundColor.A = alpha;
instanceData.writeColor(_backgroundSpriteIdx, backgroundColor);
// finish overlay color
var overlayColor = laserParams.overlayColor;
overlayColor.A = alpha;
instanceData.writeColor(_overlaySpriteIdx, overlayColor);
}
示例6: Update
public virtual void Update(float deltaTime)
{
if(DirectionLock)
{
Position = Target - Direction * Distance;
}
else
{
Direction = Target - Position;
Distance = Direction.Length;
Direction.Normalize();
rot.X = Vector3.CalculateAngle(Direction, Vector3.UnitZ);
rot.Y = Vector3.CalculateAngle(Direction, Vector3.UnitY);
}
View = Matrix4.LookAt(Position, Target, Up);
InvView = View.Inverted();
VPMatrix = View * Projection;
InvVPMatrix = VPMatrix.Inverted();
var rotation = VPMatrix.ExtractRotation();
NormalMatrix = Matrix3.CreateFromQuaternion(rotation);
Frustum = new BoundingFrustum(VPMatrix);
}
示例7: Perspective
public void Perspective(float width, float height, float fov, float near, float far)
{
float fovy = (float)(Math.PI / 180) * fov;
Projection = Matrix4.CreatePerspectiveFieldOfView(fovy, width / height, near, far);
InvProjection = Projection.Inverted();
}