本文整理汇总了C#中Axiom.Math.Matrix4类的典型用法代码示例。如果您正苦于以下问题:C# Matrix4类的具体用法?C# Matrix4怎么用?C# Matrix4使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Matrix4类属于Axiom.Math命名空间,在下文中一共展示了Matrix4类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
}
开发者ID:ryan-bunker,项目名称:axiom3d,代码行数:31,代码来源:D3D9RenderSystem.Matrix.cs
示例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;
}
}
开发者ID:WolfgangSt,项目名称:axiom,代码行数:30,代码来源:D3DRenderSystem.Matrix.cs
示例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;
}
开发者ID:WolfgangSt,项目名称:axiom,代码行数:21,代码来源:D3DRenderSystem.Matrix.cs
示例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;
}
开发者ID:WolfgangSt,项目名称:axiom,代码行数:36,代码来源:D3DRenderSystem.Matrix.cs
示例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
}
开发者ID:WolfgangSt,项目名称:axiom,代码行数:97,代码来源:MeshManager.cs
示例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
}
开发者ID:WolfgangSt,项目名称:axiom,代码行数:65,代码来源:MeshManager.cs
示例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
}
开发者ID:WolfgangSt,项目名称:axiom,代码行数:77,代码来源:MeshManager.cs
示例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 );
}
开发者ID:mono-soc-2011,项目名称:axiom,代码行数:9,代码来源:SceneManager.cs
示例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;
}
开发者ID:mono-soc-2011,项目名称:axiom,代码行数:30,代码来源:Matrix4.cs
示例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;
}
//.........这里部分代码省略.........
开发者ID:ryan-bunker,项目名称:axiom3d,代码行数:101,代码来源:MaterialSerializer.cs
示例11: GetWorldTransforms
/// <summary>
///
/// </summary>
/// <param name="matrices"></param>
public void GetWorldTransforms( Matrix4[] matrices )
{
overlay.GetWorldTransforms( matrices );
}
开发者ID:WolfgangSt,项目名称:axiom,代码行数:8,代码来源:OverlayElement.cs
示例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;
}
开发者ID:ryan-bunker,项目名称:axiom3d,代码行数:8,代码来源:Mesh.cs
示例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;
}
开发者ID:ryan-bunker,项目名称:axiom3d,代码行数:45,代码来源:D3D9RenderSystem.Matrix.cs
示例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 );
}
//.........这里部分代码省略.........
开发者ID:ryan-bunker,项目名称:axiom3d,代码行数:101,代码来源:Mesh.cs
示例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;
}
开发者ID:mono-soc-2011,项目名称:axiom,代码行数:10,代码来源:Matrix4.cs
示例16: Add
/// <summary>
/// Used to add two matrices together.
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static Matrix4 Add( Matrix4 left, Matrix4 right )
{
return left + right;
}
开发者ID:mono-soc-2011,项目名称:axiom,代码行数:10,代码来源:Matrix4.cs
示例17: Multiply
/// <summary>
///
/// </summary>
/// <param name="vector"></param>
/// <param name="matrix"></param>
/// <returns></returns>
public static Vector4 Multiply( Vector4 vector, Matrix4 matrix )
{
return vector*matrix;
}
开发者ID:ryan-bunker,项目名称:axiom3d,代码行数:10,代码来源:Vector4.cs
示例18: SetTextureMatrix
public override void SetTextureMatrix( int stage, Matrix4 xform )
{
// the matrix we'll apply after conv. to D3D format
var newMat = xform;
// cache this since it's used often
var autoTexCoordType = this._texStageDesc[ stage ].AutoTexCoordType;
// if a vertex program is bound, we mustn't set texture transforms
if ( vertexProgramBound )
{
_setTextureStageState( stage, D3D9.TextureStage.TextureTransformFlags, (int)TextureTransform.Disable );
return;
}
if ( autoTexCoordType == TexCoordCalcMethod.EnvironmentMap )
{
if ( ( this._deviceManager.ActiveDevice.D3D9DeviceCaps.VertexProcessingCaps &
D3D9.VertexProcessingCaps.TexGenSphereMap ) ==
D3D9.VertexProcessingCaps.TexGenSphereMap )
{
// inverts the texture for a spheremap
var matEnvMap = Matrix4.Identity;
// set env_map values
matEnvMap.m11 = -1.0f;
// concatenate
newMat = newMat*matEnvMap;
}
else
{
/* If envmap is applied, but device doesn't support spheremap,
then we have to use texture transform to make the camera space normal
reference the envmap properly. This isn't exactly the same as spheremap
(it looks nasty on flat areas because the camera space normals are the same)
but it's the best approximation we have in the absence of a proper spheremap */
// concatenate with the xform
newMat = newMat*Matrix4.ClipSpace2DToImageSpace;
}
}
// If this is a cubic reflection, we need to modify using the view matrix
if ( autoTexCoordType == TexCoordCalcMethod.EnvironmentMapReflection )
{
// Get transposed 3x3, ie since D3D is transposed just copy
// We want to transpose since that will invert an orthonormal matrix ie rotation
var viewTransposed = Matrix4.Identity;
viewTransposed.m00 = this._viewMatrix.m00;
viewTransposed.m01 = this._viewMatrix.m10;
viewTransposed.m02 = this._viewMatrix.m20;
viewTransposed.m03 = 0.0f;
viewTransposed.m10 = this._viewMatrix.m01;
viewTransposed.m11 = this._viewMatrix.m11;
viewTransposed.m12 = this._viewMatrix.m21;
viewTransposed.m13 = 0.0f;
viewTransposed.m20 = this._viewMatrix.m02;
viewTransposed.m21 = this._viewMatrix.m12;
viewTransposed.m22 = this._viewMatrix.m22;
viewTransposed.m23 = 0.0f;
viewTransposed.m30 = 0;
viewTransposed.m31 = 0;
viewTransposed.m32 = 0;
viewTransposed.m33 = 1.0f;
// concatenate
newMat = newMat*viewTransposed;
}
if ( autoTexCoordType == TexCoordCalcMethod.ProjectiveTexture )
{
// Derive camera space to projector space transform
// To do this, we need to undo the camera view matrix, then
// apply the projector view & projection matrices
newMat = this._viewMatrix.Inverse();
if ( texProjRelative )
{
Matrix4 viewMatrix;
this._texStageDesc[ stage ].Frustum.CalcViewMatrixRelative( texProjRelativeOrigin, out viewMatrix );
newMat = viewMatrix*newMat;
}
else
{
newMat = this._texStageDesc[ stage ].Frustum.ViewMatrix*newMat;
}
newMat = this._texStageDesc[ stage ].Frustum.ProjectionMatrix*newMat;
newMat = Matrix4.ClipSpace2DToImageSpace*newMat;
newMat = xform*newMat;
}
// need this if texture is a cube map, to invert D3D's z coord
if ( autoTexCoordType != TexCoordCalcMethod.None && autoTexCoordType != TexCoordCalcMethod.ProjectiveTexture )
{
newMat.m20 = -newMat.m20;
newMat.m21 = -newMat.m21;
newMat.m22 = -newMat.m22;
newMat.m23 = -newMat.m23;
//.........这里部分代码省略.........
开发者ID:ryan-bunker,项目名称:axiom3d,代码行数:101,代码来源:D3D9RenderSystem.Matrix.cs
示例19: NotifyWorldTransforms
public override void NotifyWorldTransforms( Matrix4[] xform )
{
base.NotifyWorldTransforms( xform );
// Update children
foreach ( var child in this.children.Values )
{
child.NotifyWorldTransforms( xform );
}
}
开发者ID:ryan-bunker,项目名称:axiom3d,代码行数:10,代码来源:OverlayElementContainer.cs
示例20: ApplyObliqueDepthProjection
public override void ApplyObliqueDepthProjection( ref Matrix4 matrix, Plane plane, bool forGpuProgram )
{
// Thanks to Eric Lenyel for posting this calculation at www.terathon.com
// Calculate the clip-space corner point opposite the clipping plane
// as (sgn(clipPlane.x), sgn(clipPlane.y), 1, 1) and
// transform it into camera space by multiplying it
// by the inverse of the projection matrix
/* generalised version
Vector4 q = matrix.inverse() *
Vector4(Math::Sign(plane.normal.x), Math::Sign(plane.normal.y), 1.0f, 1.0f);
*/
var q = new Vector4();
q.x = System.Math.Sign( plane.Normal.x )/matrix.m00;
q.y = System.Math.Sign( plane.Normal.y )/matrix.m11;
q.z = 1.0f;
// flip the next bit from Lengyel since we're right-handed
if ( forGpuProgram )
{
q.w = ( 1.0f - matrix.m22 )/matrix.m23;
}
else
{
q.w = ( 1.0f + matrix.m22 )/matrix.m23;
}
// Calculate the scaled plane vector
var clipPlane4D = new Vector4( plane.Normal.x, plane.Normal.y, plane.Normal.z, plane.D );
var c = clipPlane4D*( 1.0f/( clipPlane4D.Dot( q ) ) );
// Replace the third row of the projection matrix
matrix.m20 = c.x;
matrix.m21 = c.y;
// flip the next bit from Lengyel since we're right-handed
if ( forGpuProgram )
{
matrix.m22 = c.z;
}
else
{
matrix.m22 = -c.z;
}
matrix.m23 = c.w;
}
开发者ID:ryan-bunker,项目名称:axiom3d,代码行数:49,代码来源:D3D9RenderSystem.Matrix.cs
注:本文中的Axiom.Math.Matrix4类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论