Started working on Sharp3D.Math 2.0

Projects, Sharp3D.Math November 26th, 2004

I started working on Sharp3D.Math v2.0 using using Visual Studio 2005 (.NET 2.0).
I am using TDD (Test Driven Development) to develop the next version to avoid bugs and make the library more efficient and usable…

Among the new features:

  • Better documentation.
  • Support for .NET 2.0 standards (Like adding TryParse in addition to Parse).
  • Revised code.
  • Better integration support. Trapezoid, Simpson, Romberg integration with accuracy\max iterations support.
  • Statistics.
  • Random and distribution dependent number generators.
  • 3D Surfaces
  • 2D\3D Curves
  • And more…

Sharp3D.Math v1.1.2.2 released!

Projects, Sharp3D.Math November 26th, 2004

Few minor bug fixes on this release…

Check it out on the Sharp3D.Math Project Page.

Matrix4 benchmark results – take two

.NET, Projects, Sharp3D.Math, Software Development November 20th, 2004

Here’s an update on my Matrix4 Benchmark Results.

The last test compared the generic class compiled with the new C# 2.0 compiler against the non-generic class (from the Sharp3D.Math library) compiled for .NET 1.1.

I decided to make another test were both generic and non-generic classes are in the same project and compiled for .NET 2.0.

Oddly enough, when I ran the second test on my machine the results showed that the generic class runs faster than the non generic class.
However on my friend’s machine the results were more like the ones in the first test (non-generic slightly faster).

Here’s the test code and executable:
Matrix4PerfTest.zip (26.94 KB)

Started working on the next major version of Sharp3D.Math

Projects, Sharp3D.Math November 16th, 2004

I started working on the next major version of Sharp3D.Math (2.0) using version 2.0 of the .NET Framework.

Some of the features I am adding:

  • Non-uniform real number random generetors.
  • Signal processing framework.
  • Statistics methods.
  • 3D surfaces.
  • and more….

I would appreciate comments, suggestions etc…

 

Matrix4 benchmark results

.NET, Projects, Sharp3D.Math, Software Development November 12th, 2004

The benchmark measured the time (in seconds) of 1,000,000 random matrix multiply operations on the different matrix implementations.
The test used the latest Sharp3D.Math build (compiled using VS2003), DirectX october update and VS2005 beta 1.

The results are:

  1. Sharp3D.Math.Core.Matrix4F – 0.2857308100 seconds
  2. Matrix4<float> C# Kernel – 0.3076677100 seconds
  3. Matrix4<float> DirectX Kernel – 0.9436617200 seconds
  4. DirectX – 0.1269457500 seconds.

As expected, the DirectX CPU optimized code runs the fastest.

I thought that using a DirectX kernel will make Matrix4<float> faster than using a C# implementation but it seems that the Matrix4<float> <–> Microsoft.DirectX.Matrix conversions are killing the performance benefits…

I expected the generic Matrix4 C# implementation to run just as fast as its non-generic counterpart but unfortunately it is slower. This is probably caused by using an interface for the kernel operations…

If anyone has an idea about how to make the conversion too\from DirectX faster and\or how to make the C# implementation just as fast as its non generic counter part I’d appreciate a comment or mail…

Moving on to Sharp3D.Math 2.0 – testing the use of generic types

.NET, Projects, Sharp3D.Math, Software Development November 12th, 2004

I’ve started doing tests on the use of generics (introduced in the new .NET framework 2.0) for the next versio  of Sharp3D.Math.

Doing numerics on generic types is a bit of a problem because unconstrained type parameters are assumed to be of type System.Object which does not define arithmetic operations (like +, – etc…).
Using a constrained type parameter, the interfaces the type parameter has to implement could be defined but it is not possible to define operator constraints.

You can read a detailed discussion about the problem here and at this codeproject article.

The two suggested workarounds for this problems are:

  1. Define an IArithmetic interface that defines the basic operations needed for math calculations (addition etc…) and use it to wrap around numeric types (float, double etc…)
  2. Use a separated type for the operators.

The suggested workaround of using a separate type for the operators could be a good idea for Sharp3D.Math as it can also be used for platform specific performance tuning.
Say an IKernelMatrix4 implements all arithmetics for a 4×4 matrix structure, besides a native .NET implementation of IKernelMatrix4 there could also implementations using platform specific libraries such as the DirectX math library (which uses SSE optimizations for matrix arithmetics), Intel’s Math Kernel library and other unmanaged optimized libraries.

Currently I am implementing a 4×4 matrix structure using the method specified above for the purpose of performance testing:
Generic matrix4×4 (.NET implementation) vs. Generic matrix4×4 (DirectX implementation) vs. Sharp3D.Math.Core.Matrix4F

I’ll post the results soon…

 

Generic numerics with .NET

.NET, Projects, Sharp3D.Math, Software Development October 22nd, 2004

I’ve been playing with .NET generics trying to find a way to convert the current Sharp3D.Math structures to be generic templates.

The problem with .NET generic templates and numerics code is that there is no way to constraint a type parameter to require the existence of static method that we require for calculations (arithmetic operators etc.)

I found a very good workaround in this article.

Though I do not plan on converting Sharp3D.Math to use generics any time soon I assume I will use this solution when the time to move to .NET 2.0 comes…

Sharp3D.Math v1.1.2.1 released!

Projects, Sharp3D.Math September 29th, 2004

You can download the new release from here.
You can also check out the change log and browse the online documentation.

SEHException when serializing value types

.NET, Projects, Sharp3D.Math, Software Development September 25th, 2004

When implementing ISerializable the MSDN documentation recommends on applying the [SecurityPermissionAttribute(SecurityAction.Demand,SerializationFormatter=true)]
attribute on the GetObjectData method (Check out the FxCop rule).

When trying to serialize a structure with the above CAS attribute on its GetObjectData I got a nasty SEHException. When I removed the CAS attribute serialization worked fine…

I’ve included a test code that produces this exception with this post.
I’ve also sent it to Microsoft to see what’s their take on this bug…

In the meanwhile I commented all the CAS attributes on the GetObjectData methods in the Sharp3D.Math library…

SerializationTest.zip (1.05 KB)

Math for 3D Game Programming & Computer Graphics

Game Development, Projects, Sharp3D.Math, Software Development September 19th, 2004

I’ve been thinking about starting a tutorials series about 3D math. I could use Sharp3D.Math for code samples etc…
Anyway, I hope I’ll have an update about that soon.