Cleaned up deprecated methods.

This commit is contained in:
the_fiddler 2009-11-04 20:48:31 +00:00
parent fa81d3daa8
commit 75843147b8
10 changed files with 61 additions and 66 deletions

View file

@ -209,7 +209,7 @@ namespace Examples.Tutorial
{ {
GL.Viewport(ClientRectangle); GL.Viewport(ClientRectangle);
Matrix4 projection = Matrix4.Perspective(45.0f, this.Width / (float)this.Height, 0.1f, 10.0f); Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, this.Width / (float)this.Height, 0.1f, 10.0f);
GL.MatrixMode(MatrixMode.Projection); GL.MatrixMode(MatrixMode.Projection);
GL.LoadMatrix(ref projection); GL.LoadMatrix(ref projection);
} }

View file

@ -31,20 +31,28 @@ namespace Examples.Tutorial
float CameraZoom; float CameraZoom;
float CameraRotX; float CameraRotX;
float CameraRotY; float CameraRotY;
Vector3 EyePosition = new Vector3( 0f, 0f, 5f ); Vector3 EyePosition = new Vector3( 0f, 0f, 15f );
#region Window #region Window
public StencilCSG() public StencilCSG()
: base( 800, 600, new GraphicsMode( new ColorFormat( 8, 8, 8, 8 ), 24, 8 ) ) // request 8-bit stencil buffer : base( 800, 600, new GraphicsMode( new ColorFormat( 8, 8, 8, 8 ), 24, 8 ) ) // request 8-bit stencil buffer
{ {
base.VSync = VSyncMode.Off; base.VSync = VSyncMode.Off;
Keyboard.KeyDown += delegate(object sender, KeyboardKeyEventArgs e)
{
switch (e.Key)
{
case Key.Escape: this.Exit(); break;
case Key.Space: ShowDebugWireFrame = !ShowDebugWireFrame; break;
}
};
} }
protected override void OnResize(EventArgs e ) protected override void OnResize(EventArgs e )
{ {
GL.Viewport( 0, 0, Width, Height ); GL.Viewport( 0, 0, Width, Height );
GL.MatrixMode( MatrixMode.Projection ); GL.MatrixMode( MatrixMode.Projection );
Matrix4 p= Matrix4.Perspective( 45f, Width / (float)Height, 0.1f, 15.0f); Matrix4 p = Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, Width / (float)Height, 0.1f, 64.0f);
GL.LoadMatrix(ref p); GL.LoadMatrix(ref p);
} }
#endregion Window #endregion Window
@ -142,7 +150,7 @@ namespace Examples.Tutorial
for (int i = 0; i < tempVertices.Length; i++) for (int i = 0; i < tempVertices.Length; i++)
{ {
tempVertices[i].Normal.Mult(-1.0); tempVertices[i].Normal *= -1.0;
tempVertices[i].Normal.Normalize(); tempVertices[i].Normal.Normalize();
} }
@ -162,17 +170,6 @@ namespace Examples.Tutorial
protected override void OnUpdateFrame( FrameEventArgs e ) protected override void OnUpdateFrame( FrameEventArgs e )
{ {
if (Keyboard[OpenTK.Input.Key.Escape])
{
this.Exit();
}
if (Keyboard[Key.Space])
{
ShowDebugWireFrame = !ShowDebugWireFrame;
}
#region Magic numbers for camera #region Magic numbers for camera
CameraRotX = -Mouse.X * .5f; CameraRotX = -Mouse.X * .5f;
CameraRotY = Mouse.Y * .5f; CameraRotY = Mouse.Y * .5f;
@ -260,7 +257,7 @@ namespace Examples.Tutorial
protected override void OnRenderFrame( FrameEventArgs e ) protected override void OnRenderFrame( FrameEventArgs e )
{ {
this.Title = WindowTitle + " fps: " + ( 1f / e.Time ); this.Title = WindowTitle + " fps: " + ( 1f / e.Time ).ToString("0.");
MySphereZOffset += (float)( e.Time * 3.1 ); MySphereZOffset += (float)( e.Time * 3.1 );
MySphereXOffset += (float)( e.Time * 4.2 ); MySphereXOffset += (float)( e.Time * 4.2 );
@ -284,9 +281,10 @@ namespace Examples.Tutorial
if ( ShowDebugWireFrame ) if ( ShowDebugWireFrame )
{ {
GL.Color3(System.Drawing.Color.LightGray);
GL.Disable( EnableCap.StencilTest ); GL.Disable( EnableCap.StencilTest );
GL.Disable( EnableCap.Lighting ); GL.Disable( EnableCap.Lighting );
GL.Disable( EnableCap.DepthTest ); //GL.Disable( EnableCap.DepthTest );
GL.PolygonMode( MaterialFace.Front, PolygonMode.Line ); GL.PolygonMode( MaterialFace.Front, PolygonMode.Line );
DrawOperandB(); DrawOperandB();
GL.PolygonMode( MaterialFace.Front, PolygonMode.Fill ); GL.PolygonMode( MaterialFace.Front, PolygonMode.Fill );

View file

@ -78,7 +78,7 @@ namespace Examples.Tutorial
{ {
GL.Viewport(this.ClientRectangle); GL.Viewport(this.ClientRectangle);
Matrix4 projection = Matrix4.Perspective(45.0f, Width / (float)Height, 1.0f, 50.0f); Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, Width / (float)Height, 1.0f, 50.0f);
GL.MatrixMode(MatrixMode.Projection); GL.MatrixMode(MatrixMode.Projection);
GL.LoadMatrix(ref projection); GL.LoadMatrix(ref projection);
} }

View file

@ -49,7 +49,7 @@ namespace Examples.Tutorial
DrawableShape sphere; DrawableShape sphere;
// Camera // Camera
Vector3 EyePos = new Vector3( 0.0f, 0.0f, 3.0f ); Vector3 EyePos = new Vector3( 0.0f, 0.0f, 6.0f );
Vector3 Trackball = Vector3.Zero; Vector3 Trackball = Vector3.Zero;
#endregion internal Fields #endregion internal Fields
@ -60,22 +60,19 @@ namespace Examples.Tutorial
{ {
this.VSync = VSyncMode.Off; this.VSync = VSyncMode.Off;
/*
// Check for necessary capabilities: // Check for necessary capabilities:
if ( !GL.SupportsExtension( "VERSION_2_0" ) ) string extensions = GL.GetString(StringName.Extensions);
if (!GL.GetString(StringName.Extensions).Contains("GL_ARB_shading_language"))
{ {
MessageBox.Show( "You need at least OpenGL 2.0 to run this example. Aborting.", throw new NotSupportedException(String.Format("This example requires OpenGL 2.0. Found {0}. Aborting.",
"GLSL not supported", MessageBoxButtons.OK, MessageBoxIcon.Exclamation ); GL.GetString(StringName.Version).Substring(0, 3)));
this.Exit( );
} }
if ( !GL.SupportsExtension( "GL_ARB_texture_compression" ) || if (!extensions.Contains("GL_ARB_texture_compression") ||
!GL.SupportsExtension( "GL_EXT_texture_compression_s3tc" ) ) !extensions.Contains("GL_EXT_texture_compression_s3tc"))
{ {
MessageBox.Show( "Texture compression extensions not found. Trying to run anyways.", throw new NotSupportedException("This example requires support for texture compression. Aborting.");
"Possible problem", MessageBoxButtons.OK, MessageBoxIcon.Warning );
} }
*/
#region GL State #region GL State
@ -193,7 +190,7 @@ namespace Examples.Tutorial
GL.Viewport( 0, 0, Width, Height ); GL.Viewport( 0, 0, Width, Height );
GL.MatrixMode( MatrixMode.Projection ); GL.MatrixMode( MatrixMode.Projection );
Matrix4 p = Matrix4.Perspective( 45.0f, Width / (float) Height, 0.1f, 10.0f ); Matrix4 p = Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, Width / (float)Height, 0.1f, 10.0f);
GL.LoadMatrix(ref p); GL.LoadMatrix(ref p);
GL.MatrixMode( MatrixMode.Modelview ); GL.MatrixMode( MatrixMode.Modelview );
@ -225,7 +222,7 @@ namespace Examples.Tutorial
/// <remarks>There is no need to call the base implementation.</remarks> /// <remarks>There is no need to call the base implementation.</remarks>
protected override void OnRenderFrame(FrameEventArgs e) protected override void OnRenderFrame(FrameEventArgs e)
{ {
this.Title = "FPS: " + 1 / e.Time; this.Title = "FPS: " + (1 / e.Time).ToString("0.");
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

View file

@ -219,7 +219,7 @@ namespace Examples.Tutorial
GL.Viewport( 0, 0, Width, Height ); GL.Viewport( 0, 0, Width, Height );
GL.MatrixMode( MatrixMode.Projection ); GL.MatrixMode( MatrixMode.Projection );
Matrix4 p = Matrix4.Perspective( 45.0f, Width / (float) Height, 0.1f, 100.0f ); Matrix4 p = Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, Width / (float)Height, 0.1f, 100.0f);
GL.LoadMatrix(ref p); GL.LoadMatrix(ref p);
GL.MatrixMode( MatrixMode.Modelview ); GL.MatrixMode( MatrixMode.Modelview );
@ -281,7 +281,7 @@ namespace Examples.Tutorial
/// <remarks>There is no need to call the base implementation.</remarks> /// <remarks>There is no need to call the base implementation.</remarks>
protected override void OnRenderFrame( FrameEventArgs e ) protected override void OnRenderFrame( FrameEventArgs e )
{ {
this.Title = "FPS: " + 1 / e.Time; this.Title = "FPS: " + (1 / e.Time).ToString("0.");
GL.Clear( ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit ); GL.Clear( ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit );

View file

@ -37,15 +37,15 @@ namespace Examples.Shapes
// find the 3 points AB, BC, CA // find the 3 points AB, BC, CA
Vector3d CenterAB; Vector3d CenterAB;
Vector3d.Add( ref this.APosition, ref this.BPosition, out temp ); Vector3d.Add( ref this.APosition, ref this.BPosition, out temp );
Vector3d.Mult( ref temp, 0.5f, out CenterAB ); Vector3d.Multiply( ref temp, 0.5f, out CenterAB );
Vector3d CenterBC; Vector3d CenterBC;
Vector3d.Add( ref this.BPosition, ref this.CPosition, out temp ); Vector3d.Add( ref this.BPosition, ref this.CPosition, out temp );
Vector3d.Mult( ref temp, 0.5f, out CenterBC ); Vector3d.Multiply( ref temp, 0.5f, out CenterBC );
Vector3d CenterCA; Vector3d CenterCA;
Vector3d.Add( ref this.CPosition, ref this.APosition, out temp ); Vector3d.Add( ref this.CPosition, ref this.APosition, out temp );
Vector3d.Mult( ref temp, 0.5f, out CenterCA ); Vector3d.Multiply( ref temp, 0.5f, out CenterCA );
// find the 3 points AD, BD, CD // find the 3 points AD, BD, CD
Vector3d CenterAD; Vector3d CenterAD;
@ -93,21 +93,21 @@ namespace Examples.Shapes
Vector3d.Lerp( ref this.BPosition, ref this.CPosition, 0.5, out CenterBC ); Vector3d.Lerp( ref this.BPosition, ref this.CPosition, 0.5, out CenterBC );
Vector3d.Lerp( ref this.CPosition, ref this.APosition, 0.5, out CenterCA ); Vector3d.Lerp( ref this.CPosition, ref this.APosition, 0.5, out CenterCA );
CenterD = CenterAB; CenterD = CenterAB;
CenterD.Add( ref CenterBC ); Vector3d.Add(ref CenterD, ref CenterBC, out CenterD);
CenterD.Add( ref CenterCA ); Vector3d.Add(ref CenterD, ref CenterCA, out CenterD);
CenterD.Div( 3.0 ); CenterD /= 3.0;
Vector3d E = CenterD + ( this.Normal * 0.5 ); Vector3d E = CenterD + ( this.Normal * 0.5 );
Vector3d temp = this.Normal; Vector3d temp = this.Normal;
temp.Mult( height ); temp *= height;
CenterD.Add( temp ); Vector3d.Add(ref CenterD, ref temp, out CenterD);
Vector2d.Lerp( ref this.ATexCoord, ref this.BTexCoord, 0.5, out TexCoordAB ); Vector2d.Lerp( ref this.ATexCoord, ref this.BTexCoord, 0.5, out TexCoordAB );
Vector2d.Lerp( ref this.BTexCoord, ref this.CTexCoord, 0.5, out TexCoordBC ); Vector2d.Lerp( ref this.BTexCoord, ref this.CTexCoord, 0.5, out TexCoordBC );
Vector2d.Lerp( ref this.CTexCoord, ref this.ATexCoord, 0.5, out TexCoordCA ); Vector2d.Lerp( ref this.CTexCoord, ref this.ATexCoord, 0.5, out TexCoordCA );
TexCoordD = TexCoordAB; TexCoordD = TexCoordAB;
TexCoordD.Add( ref TexCoordBC ); Vector2d.Add(ref TexCoordD, ref TexCoordBC, out TexCoordD);
TexCoordD.Add( ref TexCoordCA ); Vector2d.Add(ref TexCoordD, ref TexCoordCA, out TexCoordD);
TexCoordD.Div( 3.0 ); TexCoordD /= 3.0;
#region 1 #region 1
first.APosition = this.APosition; first.APosition = this.APosition;
first.ATexCoord = this.ATexCoord; first.ATexCoord = this.ATexCoord;
@ -120,8 +120,8 @@ namespace Examples.Shapes
first.Normal = this.Normal; first.Normal = this.Normal;
temp = ( this.APosition + CenterAB + CenterCA ); temp = ( this.APosition + CenterAB + CenterCA );
temp.Div( 3.0 ); temp /= 3.0;
temp.Add( this.Normal * -1.0 ); temp += this.Normal * -1.0;
first.DPosition = temp; first.DPosition = temp;
#endregion 1 #endregion 1
#region 2 #region 2
@ -137,8 +137,8 @@ namespace Examples.Shapes
second.Normal = this.Normal; second.Normal = this.Normal;
temp = CenterAB + this.BPosition + CenterBC; temp = CenterAB + this.BPosition + CenterBC;
temp.Div( 3.0 ); temp /= 3.0;
temp.Add( this.Normal * -1.0 ); temp += this.Normal * -1.0;
second.DPosition = temp; second.DPosition = temp;
#endregion 2 #endregion 2
@ -154,8 +154,8 @@ namespace Examples.Shapes
third.Normal = this.Normal; third.Normal = this.Normal;
temp = CenterBC + this.CPosition + CenterCA; temp = CenterBC + this.CPosition + CenterCA;
temp.Div( 3.0 ); temp /= 3.0;
temp.Add( this.Normal * -1.0 ); temp += this.Normal * -1.0;
third.DPosition = temp; third.DPosition = temp;
#endregion 3 #endregion 3
#region 4 #region 4

View file

@ -148,24 +148,24 @@ namespace Examples.Shapes
{ {
Vector3d temp1, temp2, temp3; Vector3d temp1, temp2, temp3;
Vector3d.Sub( ref A, ref D, out temp1 ); Vector3d.Subtract( ref A, ref D, out temp1 );
Vector3d.Sub( ref B, ref D, out temp2 ); Vector3d.Subtract( ref B, ref D, out temp2 );
Vector3d.Sub( ref C, ref D, out temp3 ); Vector3d.Subtract( ref C, ref D, out temp3 );
Vector3d.Add( ref temp1, ref temp2, out result ); Vector3d.Add( ref temp1, ref temp2, out result );
result.Add( ref temp3 ); Vector3d.Add(ref result, ref temp3, out result);
result.Normalize(); result.Normalize();
} }
internal static void FindNormal( ref Vector3d A, ref Vector3d B, ref Vector3d C, out Vector3d result ) internal static void FindNormal( ref Vector3d A, ref Vector3d B, ref Vector3d C, out Vector3d result )
{ {
Vector3d temp1, temp2; Vector3d temp1, temp2;
Vector3d.Sub( ref A, ref B, out temp1 ); Vector3d.Subtract( ref A, ref B, out temp1 );
temp1.Normalize(); temp1.Normalize();
Vector3d.Sub( ref C, ref B, out temp2 ); Vector3d.Subtract(ref C, ref B, out temp2);
temp2.Normalize(); temp2.Normalize();
Vector3d.Cross( ref temp1, ref temp2, out result ); Vector3d.Cross( ref temp1, ref temp2, out result );
result.Mult( -1.0 ); result *= -1.0;
result.Normalize(); result.Normalize();
} }

View file

@ -133,7 +133,7 @@ namespace Examples.Shapes
Slerp( ref start, ref end, Multiplier, out temp[i].Normal ); Slerp( ref start, ref end, Multiplier, out temp[i].Normal );
temp[i].Normal.Normalize(); temp[i].Normal.Normalize();
temp[i].Position = temp[i].Normal; temp[i].Position = temp[i].Normal;
temp[i].Position.Mult( scale ); temp[i].Position *= scale;
} }
VertexArray = new VertexT2dN3dV3d[temp.Length * 2]; VertexArray = new VertexT2dN3dV3d[temp.Length * 2];
@ -184,8 +184,8 @@ namespace Examples.Shapes
double t2 = System.Math.Sin( ( 1.0 - factor ) * theta ) * temp; double t2 = System.Math.Sin( ( 1.0 - factor ) * theta ) * temp;
double t3 = System.Math.Sin( factor * theta ) * temp; double t3 = System.Math.Sin( factor * theta ) * temp;
Vector3d v1 = Vector3d.Mult( a, t2); Vector3d v1 = Vector3d.Multiply( a, t2);
Vector3d v2 = Vector3d.Mult( b, t3 ); Vector3d v2 = Vector3d.Multiply( b, t3 );
result = Vector3d.Add( v1, v2 ); result = Vector3d.Add( v1, v2 );
} }

View file

@ -93,7 +93,7 @@ namespace Examples.Shapes
for (int i=0; i<VertexArray.Length;i++) for (int i=0; i<VertexArray.Length;i++)
{ {
VertexArray[i].Position.Add( ref offset ); Vector3d.Add(ref VertexArray[i].Position, ref offset, out VertexArray[i].Position);
} }
} }

View file

@ -44,12 +44,12 @@ namespace Examples.Shapes
#region Find the Torus length #region Find the Torus length
Vector3d result; Vector3d result;
double[] Lengths = new double[pathsteps]; double[] Lengths = new double[pathsteps];
Vector3d.Sub( ref PathPositions[pathsteps - 1], ref PathPositions[0], out result ); Vector3d.Subtract( ref PathPositions[pathsteps - 1], ref PathPositions[0], out result );
Lengths[0] = result.Length; Lengths[0] = result.Length;
double TotalLength = result.Length; double TotalLength = result.Length;
for ( int i = 1; i < pathsteps; i++ ) // skipping for ( int i = 1; i < pathsteps; i++ ) // skipping
{ {
Vector3d.Sub( ref PathPositions[i - 1], ref PathPositions[i], out result ); Vector3d.Subtract( ref PathPositions[i - 1], ref PathPositions[i], out result );
Lengths[i] = result.Length; Lengths[i] = result.Length;
TotalLength += result.Length; TotalLength += result.Length;
} }
@ -72,12 +72,12 @@ namespace Examples.Shapes
else else
last = PathPositions[i - 1]; last = PathPositions[i - 1];
Vector3d.Sub( ref next, ref last, out tangent ); // Guesstimate tangent Vector3d.Subtract( ref next, ref last, out tangent ); // Guesstimate tangent
tangent.Normalize(); tangent.Normalize();
Vector3d.Add( ref next, ref last, out normal ); // Approximate N Vector3d.Add( ref next, ref last, out normal ); // Approximate N
normal.Normalize(); normal.Normalize();
Vector3d.Mult( ref normal, radius, out normal );// scale the shape to desired radius Vector3d.Multiply( ref normal, radius, out normal );// scale the shape to desired radius
for ( uint j = 0; j < shapevertices; j++ ) for ( uint j = 0; j < shapevertices; j++ )
{ {
@ -88,7 +88,7 @@ namespace Examples.Shapes
Vector3d point = Vector3d.TransformVector( normal, RotationMatrix ); Vector3d point = Vector3d.TransformVector( normal, RotationMatrix );
Vector3d.Add( ref PathPositions[i], ref point, out VertexArray[index].Position ); Vector3d.Add( ref PathPositions[i], ref point, out VertexArray[index].Position );
// Since the used shape is a circle, the Vertex normal's heading is easy to find // Since the used shape is a circle, the Vertex normal's heading is easy to find
Vector3d.Sub( ref VertexArray[index].Position, ref PathPositions[i], out VertexArray[index].Normal ); Vector3d.Subtract( ref VertexArray[index].Position, ref PathPositions[i], out VertexArray[index].Normal );
VertexArray[index].Normal.Normalize(); VertexArray[index].Normal.Normalize();
// just generate some semi-useful UVs to fill blanks // just generate some semi-useful UVs to fill blanks
VertexArray[index].TexCoord = new Vector2d( (double)( i / TotalLength/ TexCount ), j / ( shapevertices - 1.0 ) ); VertexArray[index].TexCoord = new Vector2d( (double)( i / TotalLength/ TexCount ), j / ( shapevertices - 1.0 ) );