本文整理汇总了C#中Axiom.Math.Matrix4类的典型用法代码示例。如果您正苦于以下问题:C# Matrix4类的具体用法?C# Matrix4怎么用?C# Matrix4使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Matrix4类属于Axiom.Math命名空间,在下文中一共展示了Matrix4类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakeOrthoMatrix
public override void MakeOrthoMatrix( Radian fovy, Real aspectRatio, Real near, Real far, out Matrix4 dest,
bool forGpuPrograms )
{
var thetaY = fovy/2.0f;
var tanThetaY = Utility.Tan( thetaY );
var tanThetaX = tanThetaY*aspectRatio;
var half_w = tanThetaX*near;
var half_h = tanThetaY*near;
var iw = 1.0f/( half_w );
var ih = 1.0f/( half_h );
Real q = 0.0f;
if ( far != 0 )
{
q = 1.0/( far - near );
}
dest = Matrix4.Zero;
dest.m00 = iw;
dest.m11 = ih;
dest.m22 = q;
dest.m23 = -near/( far - near );
dest.m33 = 1;
if ( forGpuPrograms )
{
dest.m22 = -dest.m22;
}
}
示例2: MakeOrthoMatrix
public override void MakeOrthoMatrix(Radian fov, Real aspectRatio, Real near, Real far, out Matrix4 dest, bool forGpuPrograms)
{
float thetaY = Utility.DegreesToRadians(fov / 2.0f);
float tanThetaY = Utility.Tan(thetaY);
float tanThetaX = tanThetaY * aspectRatio;
float halfW = tanThetaX * near;
float halfH = tanThetaY * near;
var w = 1.0f / (halfW);
var h = 1.0f / (halfH);
var q = 0.0f;
if (far != 0)
{
q = 1.0f / (far - near);
}
dest = Matrix4.Zero;
dest.m00 = w;
dest.m11 = h;
dest.m22 = q;
dest.m23 = -near / (far - near);
dest.m33 = 1;
if (forGpuPrograms)
{
dest.m22 = -dest.m22;
}
}
示例3: ConvertProjectionMatrix
public override void ConvertProjectionMatrix(Matrix4 mat, out Matrix4 dest, bool forGpuProgram)
{
dest = new Matrix4(mat.m00, mat.m01, mat.m02, mat.m03,
mat.m10, mat.m11, mat.m12, mat.m13,
mat.m20, mat.m21, mat.m22, mat.m23,
mat.m30, mat.m31, mat.m32, mat.m33);
// Convert depth range from [-1,+1] to [0,1]
dest.m20 = (dest.m20 + dest.m30) / 2.0f;
dest.m21 = (dest.m21 + dest.m31) / 2.0f;
dest.m22 = (dest.m22 + dest.m32) / 2.0f;
dest.m23 = (dest.m23 + dest.m33) / 2.0f;
if ( forGpuProgram )
return;
// Convert right-handed to left-handed
dest.m02 = -dest.m02;
dest.m12 = -dest.m12;
dest.m22 = -dest.m22;
dest.m32 = -dest.m32;
}
示例4: MakeProjectionMatrix
public override void MakeProjectionMatrix(Radian fov, Real aspectRatio, Real near, Real far, out Matrix4 dest, bool forGpuProgram)
{
float theta = Utility.DegreesToRadians((float)fov * 0.5f);
float h = 1.0f / Utility.Tan(theta);
float w = h / aspectRatio;
float q, qn;
if (far == 0)
{
q = 1 - Frustum.InfiniteFarPlaneAdjust;
qn = near * (Frustum.InfiniteFarPlaneAdjust - 1);
}
else
{
q = far / (far - near);
qn = -q * near;
}
dest = Matrix4.Zero;
dest.m00 = w;
dest.m11 = h;
if (forGpuProgram)
{
dest.m22 = -q;
dest.m32 = -1.0f;
}
else
{
dest.m22 = q;
dest.m32 = 1.0f;
}
dest.m23 = qn;
}
示例5: _generateCurvedIllusionPlaneVertexData
private void _generateCurvedIllusionPlaneVertexData( HardwareVertexBuffer vertexBuffer, int ySegments, int xSegments, float xSpace, float halfWidth, float ySpace, float halfHeight, Matrix4 xform, bool firstTime, bool normals, Quaternion orientation, float curvature, float uTiles, float vTiles, int numberOfTexCoordSets, ref Vector3 min, ref Vector3 max, ref float maxSquaredLength )
{
// Imagine a large sphere with the camera located near the top
// The lower the curvature, the larger the sphere
// Use the angle from viewer to the points on the plane
// Credit to Aftershock for the general approach
Real cameraPosition; // Camera position relative to sphere center
// Derive sphere radius
//Vector3 vertPos; // position relative to camera
//Real sphDist; // Distance from camera to sphere along box vertex vector
// Vector3 camToSph; // camera position to sphere
Real sphereRadius;// Sphere radius
// Actual values irrelevant, it's the relation between sphere radius and camera position that's important
Real sphRadius = 100.0f;
Real camDistance = 5.0f;
sphereRadius = sphRadius - curvature;
cameraPosition = sphereRadius - camDistance;
Vector3 vec;
Vector3 norm;
float sphereDistance;
unsafe
{
// lock the vertex buffer
IntPtr data = vertexBuffer.Lock( BufferLocking.Discard );
float* pData = (float*)data.ToPointer();
for ( int y = 0; y < ySegments + 1; ++y )
{
for ( int x = 0; x < xSegments + 1; ++x )
{
// centered on origin
vec.x = ( x * xSpace ) - halfWidth;
vec.y = ( y * ySpace ) - halfHeight;
vec.z = 0.0f;
// transform by orientation and distance
vec = xform * vec;
// assign to geometry
*pData++ = vec.x;
*pData++ = vec.y;
*pData++ = vec.z;
// build bounds as we go
if ( firstTime )
{
min = vec;
max = vec;
maxSquaredLength = vec.LengthSquared;
firstTime = false;
}
else
{
min.Floor( vec );
max.Ceil( vec );
maxSquaredLength = Utility.Max( maxSquaredLength, vec.LengthSquared );
}
if ( normals )
{
norm = Vector3.UnitZ;
norm = orientation * norm;
*pData++ = vec.x;
*pData++ = vec.y;
*pData++ = vec.z;
}
// generate texture coordinates, normalize position, modify by orientation to return +y up
vec = orientation.Inverse() * vec;
vec.Normalize();
// find distance to sphere
sphereDistance = Utility.Sqrt( cameraPosition * cameraPosition * ( vec.y * vec.y - 1.0f ) + sphereRadius * sphereRadius ) - cameraPosition * vec.y;
vec.x *= sphereDistance;
vec.z *= sphereDistance;
// use x and y on sphere as texture coordinates, tiled
float s = vec.x * ( 0.01f * uTiles );
float t = vec.z * ( 0.01f * vTiles );
for ( int i = 0; i < numberOfTexCoordSets; i++ )
{
*pData++ = s;
*pData++ = ( 1 - t );
}
} // x
} // y
// unlock the buffer
vertexBuffer.Unlock();
} // unsafe
}
示例6: _generatePlaneVertexData
private void _generatePlaneVertexData( HardwareVertexBuffer vbuf, int ySegments, int xSegments, float xSpace, float halfWidth, float ySpace, float halfHeight, Matrix4 transform, bool firstTime, bool normals, Matrix4 rotation, int numTexCoordSets, float xTexCoord, float yTexCoord, SubMesh subMesh, ref Vector3 min, ref Vector3 max, ref float maxSquaredLength )
{
Vector3 vec;
unsafe
{
// lock the vertex buffer
IntPtr data = vbuf.Lock( BufferLocking.Discard );
float* pData = (float*)data.ToPointer();
for ( int y = 0; y <= ySegments; y++ )
{
for ( int x = 0; x <= xSegments; x++ )
{
// centered on origin
vec.x = ( x * xSpace ) - halfWidth;
vec.y = ( y * ySpace ) - halfHeight;
vec.z = 0.0f;
vec = transform.TransformAffine( vec );
*pData++ = vec.x;
*pData++ = vec.y;
*pData++ = vec.z;
// Build bounds as we go
if ( firstTime )
{
min = vec;
max = vec;
maxSquaredLength = vec.LengthSquared;
firstTime = false;
}
else
{
min.Floor( vec );
max.Ceil( vec );
maxSquaredLength = Utility.Max( maxSquaredLength, vec.LengthSquared );
}
if ( normals )
{
vec = Vector3.UnitZ;
vec = rotation.TransformAffine( vec );
*pData++ = vec.x;
*pData++ = vec.y;
*pData++ = vec.z;
}
for ( int i = 0; i < numTexCoordSets; i++ )
{
*pData++ = x * xTexCoord;
*pData++ = 1 - ( y * yTexCoord );
} // for texCoords
} // for x
} // for y
// unlock the buffer
vbuf.Unlock();
subMesh.useSharedVertices = true;
} // unsafe
}
示例7: _generateCurvedPlaneVertexData
private void _generateCurvedPlaneVertexData( HardwareVertexBuffer vbuf, int ySegments, int xSegments, float xSpace, float halfWidth, float ySpace, float halfHeight, Matrix4 transform, bool firstTime, bool normals, Matrix4 rotation, float curvature, int numTexCoordSets, float xTexCoord, float yTexCoord, SubMesh subMesh, ref Vector3 min, ref Vector3 max, ref float maxSquaredLength )
{
Vector3 vec;
unsafe
{
// lock the vertex buffer
IntPtr data = vbuf.Lock( BufferLocking.Discard );
float* pData = (float*)data.ToPointer();
for ( int y = 0; y <= ySegments; y++ )
{
for ( int x = 0; x <= xSegments; x++ )
{
// centered on origin
vec.x = ( x * xSpace ) - halfWidth;
vec.y = ( y * ySpace ) - halfHeight;
// Here's where curved plane is different from standard plane. Amazing, I know.
Real diff_x = ( x - ( (Real)xSegments / 2 ) ) / (Real)xSegments;
Real diff_y = ( y - ( (Real)ySegments / 2 ) ) / (Real)ySegments;
Real dist = Utility.Sqrt( diff_x * diff_x + diff_y * diff_y );
vec.z = ( -Utility.Sin( ( 1 - dist ) * ( Utility.PI / 2 ) ) * curvature ) + curvature;
// Transform by orientation and distance
Vector3 pos = transform.TransformAffine( vec );
*pData++ = pos.x;
*pData++ = pos.y;
*pData++ = pos.z;
// Build bounds as we go
if ( firstTime )
{
min = vec;
max = vec;
maxSquaredLength = vec.LengthSquared;
firstTime = false;
}
else
{
min.Floor( vec );
max.Ceil( vec );
maxSquaredLength = Utility.Max( maxSquaredLength, vec.LengthSquared );
}
if ( normals )
{
// This part is kinda 'wrong' for curved planes... but curved planes are
// very valuable outside sky planes, which don't typically need normals
// so I'm not going to mess with it for now.
// Default normal is along unit Z
//vec = Vector3::UNIT_Z;
// Rotate
vec = rotation.TransformAffine( vec );
*pData++ = vec.x;
*pData++ = vec.y;
*pData++ = vec.z;
}
for ( int i = 0; i < numTexCoordSets; i++ )
{
*pData++ = x * xTexCoord;
*pData++ = 1 - ( y * yTexCoord );
} // for texCoords
} // for x
} // for y
// unlock the buffer
vbuf.Unlock();
subMesh.useSharedVertices = true;
} // unsafe
}
示例8: ManualRender
public void ManualRender( RenderOperation op,
Pass pass,
Viewport vp,
Matrix4 worldMatrix,
Matrix4 viewMatrix,
Matrix4 projMatrix )
{
this.ManualRender( op, pass, vp, worldMatrix, viewMatrix, projMatrix, false );
}
示例9: Matrix4
/// <summary>
/// Used to multiply a Matrix4 object by a scalar value..
/// </summary>
/// <returns></returns>
public static Matrix4 operator *( Matrix4 left, Real scalar )
{
Matrix4 result = new Matrix4();
result.m00 = left.m00 * scalar;
result.m01 = left.m01 * scalar;
result.m02 = left.m02 * scalar;
result.m03 = left.m03 * scalar;
result.m10 = left.m10 * scalar;
result.m11 = left.m11 * scalar;
result.m12 = left.m12 * scalar;
result.m13 = left.m13 * scalar;
result.m20 = left.m20 * scalar;
result.m21 = left.m21 * scalar;
result.m22 = left.m22 * scalar;
result.m23 = left.m23 * scalar;
result.m30 = left.m30 * scalar;
result.m31 = left.m31 * scalar;
result.m32 = left.m32 * scalar;
result.m33 = left.m33 * scalar;
return result;
}
示例10: ProcessManualProgramParam
protected static void ProcessManualProgramParam( bool isNamed, string commandName, string[] parameters,
MaterialScriptContext context, int index, string paramName )
{
// NB we assume that the first element of vecparams is taken up with either
// the index or the parameter name, which we ignore
int dims, roundedDims;
bool isReal;
var isMatrix4x4 = false;
var type = parameters[ 1 ].ToLower();
if ( type == "matrix4x4" )
{
dims = 16;
isReal = true;
isMatrix4x4 = true;
}
else if ( type.IndexOf( "float" ) != -1 )
{
if ( type == "float" )
{
dims = 1;
}
else
{
// the first 5 letters are "float", get the dim indicator at the end
// this handles entries like 'float4'
dims = int.Parse( type.Substring( 5 ) );
}
isReal = true;
}
else if ( type.IndexOf( "int" ) != -1 )
{
if ( type == "int" )
{
dims = 1;
}
else
{
// the first 5 letters are "int", get the dim indicator at the end
dims = int.Parse( type.Substring( 3 ) );
}
isReal = false;
}
else
{
LogParseError( context, "Invalid {0} attribute - unrecognized parameter type {1}.", commandName, type );
return;
}
// make sure we have enough params for this type's size
if ( parameters.Length != 2 + dims )
{
LogParseError( context, "Invalid {0} attribute - you need {1} parameters for a parameter of type {2}", commandName,
2 + dims, type );
return;
}
// clear any auto parameter bound to this constant, it would override this setting
// can cause problems overriding materials or changing default params
if ( isNamed )
{
context.programParams.ClearNamedAutoConstant( paramName );
}
else
{
context.programParams.ClearAutoConstant( index );
}
// Round dims to multiple of 4
if ( dims%4 != 0 )
{
roundedDims = dims + 4 - ( dims%4 );
}
else
{
roundedDims = dims;
}
int i;
// now parse all the values
if ( isReal )
{
var realBuffer = new float[roundedDims];
// do specified values
for ( i = 0; i < dims; i++ )
{
realBuffer[ i ] = StringConverter.ParseFloat( parameters[ i + 2 ] );
}
// fill up to multiple of 4 with zero
for ( ; i < roundedDims; i++ )
{
realBuffer[ i ] = 0.0f;
}
//.........这里部分代码省略.........
示例11: GetWorldTransforms
/// <summary>
///
/// </summary>
/// <param name="matrices"></param>
public void GetWorldTransforms( Matrix4[] matrices )
{
overlay.GetWorldTransforms( matrices );
}
示例12: BlendPosVector
public static void BlendPosVector( ref Vector3 accumVec, ref Matrix4 mat, ref Vector3 srcVec, float blendWeight )
{
accumVec.x += ( mat.m00*srcVec.x + mat.m01*srcVec.y + mat.m02*srcVec.z + mat.m03 )*blendWeight;
accumVec.y += ( mat.m10*srcVec.x + mat.m11*srcVec.y + mat.m12*srcVec.z + mat.m13 )*blendWeight;
accumVec.z += ( mat.m20*srcVec.x + mat.m21*srcVec.y + mat.m22*srcVec.z + mat.m23 )*blendWeight;
}
示例13: MakeProjectionMatrix
public override void MakeProjectionMatrix( Real left, Real right, Real bottom, Real top, Real nearPlane, Real farPlane,
out Matrix4 dest, bool forGpuProgram )
{
// Correct position for off-axis projection matrix
if ( !forGpuProgram )
{
var offsetX = left + right;
var offsetY = top + bottom;
left -= offsetX;
right -= offsetX;
top -= offsetY;
bottom -= offsetY;
}
var width = right - left;
var height = top - bottom;
Real q, qn;
if ( farPlane == 0 )
{
q = 1 - Frustum.InfiniteFarPlaneAdjust;
qn = nearPlane*( Frustum.InfiniteFarPlaneAdjust - 1 );
}
else
{
q = farPlane/( farPlane - nearPlane );
qn = -q*nearPlane;
}
dest = Matrix4.Zero;
dest.m00 = 2*nearPlane/width;
dest.m02 = ( right + left )/width;
dest.m11 = 2*nearPlane/height;
dest.m12 = ( top + bottom )/height;
if ( forGpuProgram )
{
dest.m22 = -q;
dest.m32 = -1.0f;
}
else
{
dest.m22 = q;
dest.m32 = 1.0f;
}
dest.m23 = qn;
}
示例14: SoftwareVertexBlend
/// <summary>
/// Performs a software indexed vertex blend, of the kind used for
/// skeletal animation although it can be used for other purposes.
/// </summary>
/// <remarks>
/// This function is supplied to update vertex data with blends
/// done in software, either because no hardware support is available,
/// or that you need the results of the blend for some other CPU operations.
/// </remarks>
/// <param name="sourceVertexData">
/// <see cref="VertexData"/> class containing positions, normals, blend indices and blend weights.
/// </param>
/// <param name="targetVertexData">
/// <see cref="VertexData"/> class containing target position
/// and normal buffers which will be updated with the blended versions.
/// Note that the layout of the source and target position / normal
/// buffers must be identical, ie they must use the same buffer indexes.
/// </param>
/// <param name="matrices">An array of matrices to be used to blend.</param>
/// <param name="blendNormals">If true, normals are blended as well as positions.</param>
/// <param name="blendTangents"></param>
/// <param name="blendBinorms"></param>
public static void SoftwareVertexBlend( VertexData sourceVertexData, VertexData targetVertexData, Matrix4[] matrices,
bool blendNormals, bool blendTangents, bool blendBinorms )
{
// Source vectors
var sourcePos = Vector3.Zero;
var sourceNorm = Vector3.Zero;
var sourceTan = Vector3.Zero;
var sourceBinorm = Vector3.Zero;
// Accumulation vectors
var accumVecPos = Vector3.Zero;
var accumVecNorm = Vector3.Zero;
var accumVecTan = Vector3.Zero;
var accumVecBinorm = Vector3.Zero;
HardwareVertexBuffer srcPosBuf = null, srcNormBuf = null, srcTanBuf = null, srcBinormBuf = null;
HardwareVertexBuffer destPosBuf = null, destNormBuf = null, destTanBuf = null, destBinormBuf = null;
HardwareVertexBuffer srcIdxBuf = null, srcWeightBuf = null;
var weightsIndexesShareBuffer = false;
// Get elements for source
var srcElemPos = sourceVertexData.vertexDeclaration.FindElementBySemantic( VertexElementSemantic.Position );
var srcElemNorm = sourceVertexData.vertexDeclaration.FindElementBySemantic( VertexElementSemantic.Normal );
var srcElemTan = sourceVertexData.vertexDeclaration.FindElementBySemantic( VertexElementSemantic.Tangent );
var srcElemBinorm = sourceVertexData.vertexDeclaration.FindElementBySemantic( VertexElementSemantic.Binormal );
var srcElemBlendIndices =
sourceVertexData.vertexDeclaration.FindElementBySemantic( VertexElementSemantic.BlendIndices );
var srcElemBlendWeights =
sourceVertexData.vertexDeclaration.FindElementBySemantic( VertexElementSemantic.BlendWeights );
Debug.Assert( srcElemPos != null && srcElemBlendIndices != null && srcElemBlendWeights != null,
"You must supply at least positions, blend indices and blend weights" );
// Get elements for target
var destElemPos = targetVertexData.vertexDeclaration.FindElementBySemantic( VertexElementSemantic.Position );
var destElemNorm = targetVertexData.vertexDeclaration.FindElementBySemantic( VertexElementSemantic.Normal );
var destElemTan = targetVertexData.vertexDeclaration.FindElementBySemantic( VertexElementSemantic.Tangent );
var destElemBinorm = targetVertexData.vertexDeclaration.FindElementBySemantic( VertexElementSemantic.Binormal );
// Do we have normals and want to blend them?
var includeNormals = blendNormals && ( srcElemNorm != null ) && ( destElemNorm != null );
var includeTangents = blendTangents && ( srcElemTan != null ) && ( destElemTan != null );
var includeBinormals = blendBinorms && ( srcElemBinorm != null ) && ( destElemBinorm != null );
// Get buffers for source
srcPosBuf = sourceVertexData.vertexBufferBinding.GetBuffer( srcElemPos.Source );
srcIdxBuf = sourceVertexData.vertexBufferBinding.GetBuffer( srcElemBlendIndices.Source );
srcWeightBuf = sourceVertexData.vertexBufferBinding.GetBuffer( srcElemBlendWeights.Source );
if ( includeNormals )
{
srcNormBuf = sourceVertexData.vertexBufferBinding.GetBuffer( srcElemNorm.Source );
}
if ( includeTangents )
{
srcTanBuf = sourceVertexData.vertexBufferBinding.GetBuffer( srcElemTan.Source );
}
if ( includeBinormals )
{
srcBinormBuf = sourceVertexData.vertexBufferBinding.GetBuffer( srcElemBinorm.Source );
}
// note: reference comparison
weightsIndexesShareBuffer = ( srcIdxBuf == srcWeightBuf );
// Get buffers for target
destPosBuf = targetVertexData.vertexBufferBinding.GetBuffer( destElemPos.Source );
if ( includeNormals )
{
destNormBuf = targetVertexData.vertexBufferBinding.GetBuffer( destElemNorm.Source );
}
if ( includeTangents )
{
destTanBuf = targetVertexData.vertexBufferBinding.GetBuffer( destElemTan.Source );
}
if ( includeBinormals )
{
destBinormBuf = targetVertexData.vertexBufferBinding.GetBuffer( destElemBinorm.Source );
}
//.........这里部分代码省略.........
示例15: Subtract
/// <summary>
/// Used to subtract two matrices.
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static Matrix4 Subtract( Matrix4 left, Matrix4 right )
{
return left - right;
}