Archive for the ‘.NET’ Category

I’ve constructed a primitive batch based on the Microsoft and Farseer examples that can apply a texture to a 2D polygon.

Texture configuration properties are stored in the ‘user data’ property in the Farseer Body and Fixture objects.

I use the body position to determine the texture coordinates. This allows you to apply rotation and translation to the texture coordinates based on the body, in addition to the stored properties.

As you can see, the textures can be applied across multiple sub fixtures.

alphaEditor_03

Advertisements

XNA Development – Turnip Toss

Posted: December 27, 2012 in .NET, XNA
Tags: , ,

Working on a XNA game I am currently calling “Turnip Toss” using the Farseer physics engine.

The editor is in early alpha stages now.
2 dimensional “bodies” and simple shapes can be created by right clicking a position on the editing surface.

alphaEditor_01

alphaEditor_02

Converting a Frequency to a Midi Note

Posted: December 3, 2012 in .NET

This is a C# method to convert a pitch or frequency to a midi note.
I am shifting detected frequencies to the nearest semi-tone before using this formula.


private double GetMidiNote(float freq)
{
return Math.Ceiling(69 + 12 * (Math.Log(freq/440, 2)));
}

Introduction to Umbraco

Posted: August 27, 2012 in .NET, Umbraco
Tags: ,

I recently hosted the first Fort Worth .NET User’s Group first SIG.

The topic was Umbraco CMS. Here is the deck –

 

(using MVC4 beta)

In some cases it is not easy to alter the header values to negotiate the content type returned from WEBAPI.

There is a QueryStringMapper object you can add to the Media Type Formatter objects that allow you to use a query string to negotiate the content format.

In the example below,  I am adding a query string parameter ‘format’ to the mapping. When ‘format’ == ‘xml’, the content type is ‘text/xml’ and the XmlMediaTypeFormatter is used.

I run this in the ‘Application_Start’ method of the Global.asax 

            foreach (var item in GlobalConfiguration.Configuration.Formatters)
            {
                if (typeof(XmlMediaTypeFormatter) == item.GetType())
                {
                    item.AddQueryStringMapping("format", "xml", "text/xml");
                }
            }

Example api call – http://localhost/api/foo?format=xml

Here is an example of aggregation using LINQ to a collection –

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GroupByExampleLinq
{
    public class Person
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Email { get; set; }
        public string AccountNumber { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Example();
            Console.ReadKey();
        }

        static void Example()
        {
            // Creating new List of Person
            List personCollection = new List()
            {
                //Adding a new Person
                new Person(){
                    AccountNumber = "123123 634566",
                    Email = "qwerty@qwerty.com",
                    FirstName = "John",
                    LastName = "Doe"
                },
                //Adding a new Person
                new Person(){
                    AccountNumber = "123123 678879",
                    Email = "qwerty@qwerty.com",
                    FirstName = "John",
                    LastName = "Doe"
                },
                //Adding a new Person
                new Person(){
                    AccountNumber = "123123 122134",
                    Email = "qwerty@qwerty.com",
                    FirstName = "John",
                    LastName = "Doe"
                },
                //Adding a new Person
                new Person(){
                    AccountNumber = "123123 890980",
                    Email = "asdf@asdf.com",
                    FirstName = "Jane",
                    LastName = "Doe"
                }
            };

            // Using LINQ to query the collection and group them by the email address
            var personQuery = from p in personCollection
                              group p by p.Email into g
                              select new { Email = g.Key, Accounts = g };

            // Output the email address and the count of records for each group
            foreach (var item in personQuery)
            {
                Console.WriteLine("{0} has {1} accounts.", item.Email, item.Accounts.Count());
            }
        }
    }
}

Posted: March 9, 2012 in .NET, SharePoint

Thank you W0ut. This saved me some time.