本文整理汇总了C#中float3.Cross方法的典型用法代码示例。如果您正苦于以下问题:C# float3.Cross方法的具体用法?C# float3.Cross怎么用?C# float3.Cross使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类float3
的用法示例。
在下文中一共展示了float3.Cross方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitializeCamera
public void InitializeCamera( float3 _Position, float3 _Target, float3 _Up )
{
// Build the camera matrix
float3 At = _Target - _Position;
if ( At.LengthSquared > 1e-2f )
{ // Normal case
m_CameraTargetDistance = At.Length;
At /= m_CameraTargetDistance;
}
else
{ // Special bad case
m_CameraTargetDistance = 0.01f;
At = new float3( 0.0f, 0.0f, -1.0f );
}
float3 Ortho = _Up.Cross( At ).Normalized;
float4x4 CameraMat = float4x4.Identity;
CameraMat.r3 = new float4( _Position, 1.0f );
CameraMat.r2 = new float4( At, 0.0f );
CameraMat.r0 = new float4( Ortho, 0.0f );
CameraMat.r1 = new float4( At.Cross( Ortho ), 0.0f );
CameraTransform = CameraMat;
// Setup the normalized target distance
m_NormalizedTargetDistance = NormalizeTargetDistance( m_CameraTargetDistance );
}
示例2: BuildPrimitives
void BuildPrimitives()
{
{ // Post-process quad
List<VertexPt4> Vertices = new List<VertexPt4>();
Vertices.Add( new VertexPt4() { Pt=new float4( -1, +1, 0, 1 ) } );
Vertices.Add( new VertexPt4() { Pt=new float4( -1, -1, 0, 1 ) } );
Vertices.Add( new VertexPt4() { Pt=new float4( +1, +1, 0, 1 ) } );
Vertices.Add( new VertexPt4() { Pt=new float4( +1, -1, 0, 1 ) } );
m_Prim_Quad = new Primitive( m_Device, 4, VertexPt4.FromArray( Vertices.ToArray() ), null, Primitive.TOPOLOGY.TRIANGLE_STRIP, VERTEX_FORMAT.Pt4 );
}
{ // Sphere Primitive
List<VertexP3N3G3T2> Vertices = new List<VertexP3N3G3T2>();
List<uint> Indices = new List<uint>();
const int SUBDIVS_THETA = 80;
const int SUBDIVS_PHI = 160;
for ( int Y=0; Y <= SUBDIVS_THETA; Y++ ) {
double Theta = Y * Math.PI / SUBDIVS_THETA;
float CosTheta = (float) Math.Cos( Theta );
float SinTheta = (float) Math.Sin( Theta );
for ( int X=0; X <= SUBDIVS_PHI; X++ ) {
double Phi = X * 2.0 * Math.PI / SUBDIVS_PHI;
float CosPhi = (float) Math.Cos( Phi );
float SinPhi = (float) Math.Sin( Phi );
float3 N = new float3( SinTheta*SinPhi, CosTheta, SinTheta*CosPhi );
float3 T = new float3( CosPhi, 0.0f, -SinPhi );
float2 UV = new float2( (float) X / SUBDIVS_PHI, (float) Y / SUBDIVS_THETA );
Vertices.Add( new VertexP3N3G3T2() { P=N, N=N, T=T, UV=UV } );
}
}
for ( int Y=0; Y < SUBDIVS_THETA; Y++ ) {
int CurrentLineOffset = Y * (SUBDIVS_PHI+1);
int NextLineOffset = (Y+1) * (SUBDIVS_PHI+1);
for ( int X=0; X <= SUBDIVS_PHI; X++ ) {
Indices.Add( (uint) (CurrentLineOffset + X) );
Indices.Add( (uint) (NextLineOffset + X) );
}
if ( Y < SUBDIVS_THETA-1 ) {
Indices.Add( (uint) (NextLineOffset - 1) ); // Degenerate triangle to end the line
Indices.Add( (uint) NextLineOffset ); // Degenerate triangle to start the next line
}
}
m_Prim_Sphere = new Primitive( m_Device, Vertices.Count, VertexP3N3G3T2.FromArray( Vertices.ToArray() ), Indices.ToArray(), Primitive.TOPOLOGY.TRIANGLE_STRIP, VERTEX_FORMAT.P3N3G3T2 );
}
{ // Build the cube
float3[] Normals = new float3[6] {
-float3.UnitX,
float3.UnitX,
-float3.UnitY,
float3.UnitY,
-float3.UnitZ,
float3.UnitZ,
};
float3[] Tangents = new float3[6] {
float3.UnitZ,
-float3.UnitZ,
float3.UnitX,
-float3.UnitX,
-float3.UnitX,
float3.UnitX,
};
VertexP3N3G3T2[] Vertices = new VertexP3N3G3T2[6*4];
uint[] Indices = new uint[2*6*3];
for ( int FaceIndex=0; FaceIndex < 6; FaceIndex++ ) {
float3 N = Normals[FaceIndex];
float3 T = Tangents[FaceIndex];
float3 B = N.Cross( T );
Vertices[4*FaceIndex+0] = new VertexP3N3G3T2() {
P = N - T + B,
N = N,
T = T,
// B = B,
UV = new float2( 0, 0 )
};
Vertices[4*FaceIndex+1] = new VertexP3N3G3T2() {
P = N - T - B,
N = N,
T = T,
// B = B,
UV = new float2( 0, 1 )
};
Vertices[4*FaceIndex+2] = new VertexP3N3G3T2() {
P = N + T - B,
N = N,
T = T,
// B = B,
UV = new float2( 1, 1 )
};
Vertices[4*FaceIndex+3] = new VertexP3N3G3T2() {
P = N + T + B,
N = N,
//.........这里部分代码省略.........
示例3: CellPolygon
public CellPolygon( float3 _P, float3 _N )
{
m_P = _P;
m_N = _N;
m_T = (float3.UnitY.Cross( m_N )).Normalized;
m_B = m_N.Cross( m_T );
// Start with 4 vertices
const float R = 10.0f;
m_Vertices = new float3[] {
m_P + R * (-m_T + m_B),
m_P + R * (-m_T - m_B),
m_P + R * ( m_T - m_B),
m_P + R * ( m_T + m_B),
};
}
示例4: BuildSurfaceFromTexture
/// <summary>
/// Builds the surface texture from an actual image file
/// </summary>
/// <param name="_textureFileName"></param>
/// <param name="_pixelSize">Size of a pixel, assuming the maximum height is 1</param>
public unsafe void BuildSurfaceFromTexture( string _textureFileName, float _pixelSize )
{
if ( m_Tex_Heightfield != null )
m_Tex_Heightfield.Dispose(); // We will create a new one so dispose of the old one...
// Read the bitmap
int W, H;
float4[,] Content = null;
using ( Bitmap BM = Bitmap.FromFile( _textureFileName ) as Bitmap ) {
W = BM.Width;
H = BM.Height;
Content = new float4[W,H];
BitmapData LockedBitmap = BM.LockBits( new Rectangle( 0, 0, W, H ), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb );
byte R, G, B, A;
for ( int Y=0; Y < H; Y++ ) {
byte* pScanline = (byte*) LockedBitmap.Scan0.ToPointer() + Y*LockedBitmap.Stride;
for ( int X=0; X < W; X++ ) {
// Read in shitty order
B = *pScanline++;
G = *pScanline++;
R = *pScanline++;
A = *pScanline++;
// Use this if you really need RGBA data
// Content[X,Y].Set( R / 255.0f, G / 255.0f, B / 255.0f, A / 255.0f );
// But assuming it's a height field, we only store one component into alpha
Content[X,Y].Set( 0, 0, 0, R / 255.0f ); // Use Red as height
}
}
BM.UnlockBits( LockedBitmap );
}
// Build normal (shitty version)
float Hx0, Hx1, Hy0, Hy1;
float3 dNx = new float3( 2.0f * _pixelSize, 0, 0 );
float3 dNy = new float3( 0, 2.0f * _pixelSize, 0 );
float3 N;
for ( int Y=0; Y < H; Y++ ) {
int pY = (Y+H-1) % H;
int nY = (Y+1) % H;
for ( int X=0; X < W; X++ ) {
int pX = (X+W-1) % W;
int nX = (X+1) % W;
Hx0 = Content[pX,Y].w;
Hx1 = Content[nX,Y].w;
Hy0 = Content[X,pY].w;
Hy1 = Content[X,nY].w;
dNx.z = Hx1 - Hx0;
dNy.z = Hy0 - Hy1; // Assuming +Y is upward
N = dNx.Cross( dNy );
N = N.Normalized;
Content[X,Y].x = N.x;
Content[X,Y].y = N.y;
Content[X,Y].z = N.z;
}
}
// Build the texture from the array
PixelsBuffer Buf = new PixelsBuffer( W*H*16 );
using ( BinaryWriter Writer = Buf.OpenStreamWrite() )
for ( int Y=0; Y < H; Y++ )
for ( int X=0; X < W; X++ ) {
float4 pixel = Content[X,Y];
Writer.Write( pixel.x );
Writer.Write( pixel.y );
Writer.Write( pixel.z );
Writer.Write( pixel.w );
}
Buf.CloseStream();
m_Tex_Heightfield = new Texture2D( m_Device, W, H, 1, 1, PIXEL_FORMAT.RGBA32_FLOAT, false, false, new PixelsBuffer[] { Buf } );
}
示例5: Eval
public double Eval( double[] _newParameters )
{
double lobeTheta = _newParameters[0];
double lobeRoughness = _newParameters[1];
double lobeGlobalScale = _newParameters[2];
double lobeFlatten = _newParameters[3];
double maskingImportance = _newParameters[4];
// Flattening is not linear when using the anisotropic lobe model!
if ( m_lobeType == LOBE_TYPE.MODIFIED_PHONG_ANISOTROPIC )
lobeFlatten = Math.Pow( 2.0, 4.0 * (lobeFlatten - 1.0)); // in [2e-4, 2e4], log space
double invLobeFlatten = 1.0 / lobeFlatten;
// Compute constant masking term due to incoming direction
double maskingIncoming = Masking( m_direction.z, lobeRoughness ); // Masking( incoming )
// Compute lobe's reflection vector and tangent space using new parameters
double cosTheta = Math.Cos( lobeTheta );
double sinTheta = Math.Sin( lobeTheta );
float3 lobe_normal = new float3( (float) (sinTheta * m_incomingDirection_CosPhi), (float) (sinTheta * m_incomingDirection_SinPhi), (float) cosTheta );
float3 lobe_tangent = new float3( (float) -m_incomingDirection_SinPhi, (float) m_incomingDirection_CosPhi, 0.0f ); // Always lying in the X^Y plane
float3 lobe_biTangent = lobe_normal.Cross( lobe_tangent );
// Compute sum
double phi, theta, cosPhi, sinPhi;
double outgoingIntensity_Simulated, length;
double outgoingIntensity_Analytical, lobeIntensity;
double difference;
float3 wsOutgoingDirection = float3.Zero;
float3 wsOutgoingDirection2 = float3.Zero;
float3 lsOutgoingDirection = float3.Zero;
double maskingOutGoing = 0.0;
double maskingShadowing;
double sum = 0.0;
double sum_Simulated = 0.0;
double sum_Analytical = 0.0;
double sqSum_Simulated = 0.0;
double sqSum_Analytical = 0.0;
for ( int Y=0; Y < H; Y++ ) {
// Formerly used wrong stuff!
// // Y = theta bin index = 2.0 * LOBES_COUNT_THETA * pow2( sin( 0.5 * theta ) )
// // We need theta:
// theta = 2.0 * Math.Asin( Math.Sqrt( 0.5 * Y / H ) );
// Y = theta bin index = LOBES_COUNT_THETA * (1 - cos( theta ) )
// // We need theta:
theta = Math.Acos( 1.0 - (float) Y / H );
cosTheta = Math.Cos( theta );
sinTheta = Math.Sin( theta );
for ( int X=0; X < W; X++ ) {
// X = phi bin index = LOBES_COUNT_PHI * X / (2PI)
// We need phi:
phi = 2.0 * Math.PI * X / W;
cosPhi = Math.Cos( phi );
sinPhi = Math.Sin( phi );
// Build simulated microfacet reflection direction in macro-surface space
outgoingIntensity_Simulated = m_histogramData[X,Y];
wsOutgoingDirection.Set( (float) (cosPhi * sinTheta), (float) (sinPhi * sinTheta), (float) cosTheta );
// Compute maksing term due to outgoing direction
maskingOutGoing = Masking( wsOutgoingDirection.z, lobeRoughness ); // Masking( outgoing )
// Compute projection of world space direction onto reflected direction
float Vx = wsOutgoingDirection.Dot( lobe_tangent );
float Vy = wsOutgoingDirection.Dot( lobe_biTangent );
float Vz = wsOutgoingDirection.Dot( lobe_normal );
//Vz = Math.Min( 0.99f, Vz );
float cosTheta_M = Math.Max( 1e-6f, Vz );
// Compute the lobe intensity in local space
lobeIntensity = NDF( cosTheta_M, lobeRoughness );
maskingShadowing = 1.0 + maskingImportance * (maskingIncoming * maskingOutGoing - 1.0); // = 1 when importance = 0, = masking when importance = 1
lobeIntensity *= maskingShadowing; // * Masking terms
lobeIntensity *= lobeGlobalScale;
// Apply additional lobe scaling/flattening
length = m_flatteningEval( Vx, Vy, Vz, lobeFlatten, invLobeFlatten );
outgoingIntensity_Analytical = lobeIntensity * length; // Lobe intensity was estimated in lobe space, account for scaling when converting back in world space
// Sum the difference between simulated intensity and lobe intensity
outgoingIntensity_Analytical *= m_oversizeFactor; // Apply tolerance factor so we're always a bit smaller than the simulated lobe
if ( m_fitUsingCenterOfMass ) {
double difference0 = outgoingIntensity_Simulated - outgoingIntensity_Analytical;
float3 wsLobePosition_Simulated = (float) outgoingIntensity_Simulated * wsOutgoingDirection;
float3 wsLobePosition_Analytical = (float) outgoingIntensity_Analytical * wsOutgoingDirection;
// Subtract center of mass
//.........这里部分代码省略.........
示例6: BuildPrimitives
private void BuildPrimitives()
{
{
VertexPt4[] Vertices = new VertexPt4[4];
Vertices[0] = new VertexPt4() { Pt = new float4( -1, +1, 0, 1 ) }; // Top-Left
Vertices[1] = new VertexPt4() { Pt = new float4( -1, -1, 0, 1 ) }; // Bottom-Left
Vertices[2] = new VertexPt4() { Pt = new float4( +1, +1, 0, 1 ) }; // Top-Right
Vertices[3] = new VertexPt4() { Pt = new float4( +1, -1, 0, 1 ) }; // Bottom-Right
ByteBuffer VerticesBuffer = VertexPt4.FromArray( Vertices );
m_Prim_Quad = new Primitive( m_Device, Vertices.Length, VerticesBuffer, null, Primitive.TOPOLOGY.TRIANGLE_STRIP, VERTEX_FORMAT.Pt4 );
}
{
VertexP3N3G3B3T2[] Vertices = new VertexP3N3G3B3T2[4];
Vertices[0] = new VertexP3N3G3B3T2() { P = new float3( -1, +1, 0 ), N = new float3( 0, 0, 1 ), T = new float3( 1, 0, 0 ), B = new float3( 0, 1, 0 ), UV = new float2( 0, 0 ) }; // Top-Left
Vertices[1] = new VertexP3N3G3B3T2() { P = new float3( -1, -1, 0 ), N = new float3( 0, 0, 1 ), T = new float3( 1, 0, 0 ), B = new float3( 0, 1, 0 ), UV = new float2( 0, 1 ) }; // Bottom-Left
Vertices[2] = new VertexP3N3G3B3T2() { P = new float3( +1, +1, 0 ), N = new float3( 0, 0, 1 ), T = new float3( 1, 0, 0 ), B = new float3( 0, 1, 0 ), UV = new float2( 1, 0 ) }; // Top-Right
Vertices[3] = new VertexP3N3G3B3T2() { P = new float3( +1, -1, 0 ), N = new float3( 0, 0, 1 ), T = new float3( 1, 0, 0 ), B = new float3( 0, 1, 0 ), UV = new float2( 1, 1 ) }; // Bottom-Right
ByteBuffer VerticesBuffer = VertexP3N3G3B3T2.FromArray( Vertices );
m_Prim_Rectangle = new Primitive( m_Device, Vertices.Length, VerticesBuffer, null, Primitive.TOPOLOGY.TRIANGLE_STRIP, VERTEX_FORMAT.P3N3G3B3T2 );
}
{ // Build the sphere
const int W = 41;
const int H = 22;
VertexP3N3G3B3T2[] Vertices = new VertexP3N3G3B3T2[W*H];
for ( int Y=0; Y < H; Y++ ) {
double Theta = Math.PI * Y / (H-1);
float CosTheta = (float) Math.Cos( Theta );
float SinTheta = (float) Math.Sin( Theta );
for ( int X=0; X < W; X++ ) {
double Phi = 2.0 * Math.PI * X / (W-1);
float CosPhi = (float) Math.Cos( Phi );
float SinPhi = (float) Math.Sin( Phi );
float3 N = new float3( SinTheta * SinPhi, CosTheta, SinTheta * CosPhi );
float3 T = new float3( CosPhi, 0.0f, -SinPhi );
float3 B = N.Cross( T );
Vertices[W*Y+X] = new VertexP3N3G3B3T2() {
P = N,
N = N,
T = T,
B = B,
UV = new float2( 2.0f * X / W, 1.0f * Y / H )
};
}
}
ByteBuffer VerticesBuffer = VertexP3N3G3B3T2.FromArray( Vertices );
uint[] Indices = new uint[(H-1) * (2*W+2)-2];
int IndexCount = 0;
for ( int Y=0; Y < H-1; Y++ ) {
for ( int X=0; X < W; X++ ) {
Indices[IndexCount++] = (uint) ((Y+0) * W + X);
Indices[IndexCount++] = (uint) ((Y+1) * W + X);
}
if ( Y < H-2 ) {
Indices[IndexCount++] = (uint) ((Y+1) * W - 1);
Indices[IndexCount++] = (uint) ((Y+1) * W + 0);
}
}
m_Prim_Sphere = new Primitive( m_Device, Vertices.Length, VerticesBuffer, Indices, Primitive.TOPOLOGY.TRIANGLE_STRIP, VERTEX_FORMAT.P3N3G3B3T2 );
}
{ // Build the cube
float3[] Normals = new float3[6] {
-float3.UnitX,
float3.UnitX,
-float3.UnitY,
float3.UnitY,
-float3.UnitZ,
float3.UnitZ,
};
float3[] Tangents = new float3[6] {
float3.UnitZ,
-float3.UnitZ,
float3.UnitX,
-float3.UnitX,
-float3.UnitX,
float3.UnitX,
};
VertexP3N3G3B3T2[] Vertices = new VertexP3N3G3B3T2[6*4];
uint[] Indices = new uint[2*6*3];
for ( int FaceIndex=0; FaceIndex < 6; FaceIndex++ ) {
float3 N = Normals[FaceIndex];
float3 T = Tangents[FaceIndex];
float3 B = N.Cross( T );
Vertices[4*FaceIndex+0] = new VertexP3N3G3B3T2() {
P = N - T + B,
//.........这里部分代码省略.........