nKast

pixel perf-ect

8. January 2025 13:14
by nKast
0 Comments

What's new in KNI v4.00

8. January 2025 13:14 by nKast | 0 Comments

  The latest release of KNI v4.0.9001 marks a pivotal milestone for the framework. After nine releases over three years, KNI is now production-ready, with most platforms achieving near-parity with XNA 4.0. This update brings significant architectural changes, expanded platform support, and performance improvements. A more detailed list of the changes is available on the changelog.

Download KNI v4.0 today.
See migrate to v4.0 on how to upgrade your current projects.

 

Architecture

 The restructuring of the framework represents the culmination of a long-term plan to improve modularity and streamline development workflows. All components of the framework have now been decoupled, completing an ongoing effort to enhance flexibility and scalability. The final components to be decoupled were the Storage API, Sensor API, and the Virtual reality API. This transition enhances usability for developers while providing a robust foundation for upcoming features.

  • Storage API: Now decoupled into a standalone package, the Storage API is platform-independent and provides a robust foundation. While the API is not finalized and remains subject to change, it lays a strong groundwork for upcoming improvements.

  • Devices API: The Accelerometer and Compass classes are now part of the new Xna.Framework.Devices.Sensors namespace. Previously exclusive to Android and iOS packages, these classes were ports of the deprecated Windows Phone APIs under the Microsoft.Devices.Sensors namespace. A new Haptics class has also been introduced under Xna.Framework.Devices, supporting haptic feedback on mobile devices.

  • XR API: The VR APIs for Meta (OVR) and Google Cardboard have been unified under a new Xna.Framework.XR namespace. This standalone package offers a consistent API across VR platforms. Note that the API has undergone changes, requiring minor porting efforts for existing projects. The API is still evolving, and further updates are anticipated in the future.

To align with the updated architecture, platform NuGet packages have been renamed to follow a consistent naming scheme as a combination of the hosting platform and the graphics backend:

  • nkast.Kni.Platform.Android.GL
  • nkast.Kni.Platform.Blazor.GL
  • nkast.Kni.Platform.Cardboard.GL
  • nkast.Kni.Platform.Oculus.GL
  • nkast.Kni.Platform.SDL2.GL
  • nkast.Kni.Platform.iOS.GL
  • nkast.Kni.Platform.UAP.DX11
  • nkast.Kni.Platform.WinForms.DX11

Support for the legacy Xamarin targets on Android and iOS has been dropped. Additionally, the Blazor target no longer supports .NET 6.

Virtual Reality

  • Native Oculus: With the new Oculus backend, KNI now supports native development for Meta Quest headsets. Meta’s leadership in VR makes this an essential addition, ensuring KNI remains a top choice for developers targeting immersive platforms.

  • WebXR on Blazor: This release introduces VR and AR support for the Blazor.GL target through WebXR.
  •   Special thanks to @squarebananas for providing proof-of-concept experiments and critical feedback throughout development. 
      You can see this in action in a simple game on itch.io, made for VR-Jam#5, or simply click on the iframe below.



    You can also play the port of Ship-Game by @squarebananas at https://squarebananas.github.io/kni-unofficial-webxnar-experiments.github.io/


 

 Performance

  New GetData() implementations for Texture2D, Texture3D, TextureCube, IndexBuffer, and VertexBuffer avoid unnecessary memory allocations and data copies, providing substantial performance benefits for real-time applications.

  The Content Pipeline now supports Brotli compression for .xnb asset files. This reduces app sizes and improves loading times, especially for platforms with slower storage media such as Android and Oculus, as well as loading assets over the Web.

Usage: Enable Brotli compression in your .mgcb file:

/compress:True
/compression:Brotli

Productivity

  The MGCB tool now supports consuming importers and processors from NuGet packages, simplifying content management workflows.

Usage: Add an extension package to your .mgcb file:

/packageReference:KNI.Extended.Content.Pipeline 4.0.3

Or add a package from the content Editor.

 

Sponsors

We’re grateful to our contributors and sponsors for their continued support. By becoming a sponsor, you help ensure the growth and sustainability of the KNI framework. Together, we’re shaping the future of open-source game development.

29. October 2012 03:06
by nKast
0 Comments

Motion API for XNA AR camera

29. October 2012 03:06 by nKast | 0 Comments

One of the coolest things you can do on mobile phones are Augmented reality apps. 
Combining the camera with the Motion API of windows phone is all you need. So, here's what you need to make AR on XNA.

First, Initialize the Motion API
Here I also set the update interval to 60FPS 

motion = new Motion();
motion.TimeBetweenUpdates = TimeSpan.FromMilliseconds(16.666);
motion.Start();
 

The important part is to align your XNA camera to the physical camera. For that we need the Attitude property from the motion API. In order to use it we must first apply some transformations. The last line is needed for landscape apps. Remove it If your app works in portrait mode. 

//corrent the rotation matrix from Motion api 
AttitudeReading attitude = motion.CurrentValue.Attitude;
Matrix orientation = Matrix.Identity;
orientation = Matrix.CreateRotationX(MathHelper.PiOver2); //device->screen cordinate
orientation *= attitude.RotationMatrix; 
orientation *= Matrix.CreateRotationZ(MathHelper.PiOver2); //portrait->landscape cordinate
 

What you have now is a View matrix. You can use it to draw your stuff with Model.Draw(...) or assign it to Effect.View. 
Sometimes this isn't enough. What I wanted was the actual orientation of the camera/phone as a 3D vector.
My first thought was to use Vector3.Transform(...) and transform a Vector3.Forward using the orientation matrix. That didn't work. Then I tried to get the orientation.Forward & orientation.Up but that didn't work either. Finally i wrote a small method that extracts the two vectors from a view matrix.
As you can see, you can use the results in order to create your own view matrix or use it in your Camera class.  

//extract oriantation from view matrixs
Vector3 cameraForward = Vector3.Zero;
Vector3 cameraUp = Vector3.Zero;
GetViewOrientation(ref orientation, out cameraForward, out cameraUp);
 
view = Matrix.CreateLookAt(cameraPosition, cameraPosition + cameraForward, cameraUp);
 

And here is the method to extracts the Fordward and Up vectors 

public void GetViewOrientation(ref Matrix view, out Vector3 forward, out Vector3 up)
{
    forward = new Vector3(-view.M13, -view.M23, -view.M33);
    up = new Vector3(view.M12, view.M22, view.M32);

}

 

MotionAPI XNA AR.zip (773.14 kb)

19. September 2010 11:52
by nKast
0 Comments

AccelKit, an Augmented Reality Accelerometer Kit for Windows Phone 7 Emulator

19. September 2010 11:52 by nKast | 0 Comments

AccelKit is an Augmented reality tool that simulates an accelerometer sensor for those who develop applications for the upcoming Windows Phone 7.
I used ARToolKit, an open source AR library that can track the position & orientation of a marker moving in front of a webcam.  Those data are then translated into accelerometer measurements and made available to any program through port 88. You can get the source code at accelkit.codeplex.com or just the executable at tainicom.


How to use it
 

Print the Print_This_Cutout.pdf on plain paper and glue it on a sheet of cardboard. 
Then cut out the phones. 

Place your webcam in  straight position, forming a 90o angle with the floor. 

Run the accelKit.exe found inside the Executable folder. 
On the first screen you are asked to select the desired web resolution. Because tracking can be very CPU intensive, select the lowest possible resolution (That screen might vary from webcam to webcam).
You should now see feed from your webcam. If not, check for other video capture devices in your system (like TV tuners for example) and disable them. 
Move the marker smoothly in front of the webcam. If accelKit keeps loosing track of the marker add some more light to the room to improve the image sharpness. If you still have problems, try again with the next resolution until you get consistent results. It is normal to lose track once in a while for a few frames, especial when the marker moves too fast or on extreme angles. 

Open a web browser and go to http://127.0.0.1:88/. You should see something in the form of "-0.068880,-0.997565,-0.010901". In case you are eager to see it in action get the samples at tainicom.net

Now, let's add support for accelKit in your applications. The code below (C#) demonstrates how you can get the accelKit data.

..
WebClient wc;
wc = new WebClient();
wc.AllowReadStreamBuffering = false;
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
wc.DownloadStringAsync(new Uri("http://127.0.0.1:88/"));
..

void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)

if (e.Error != null) { timer.Begin(); return; }
if (e.Result == null) { timer.Begin(); return; }
string[] vc = e.Result.Split(new Char[] {',', ' '});
double x = Convert.ToDouble(vc[0]);
double y = Convert.ToDouble(vc[1]);
double z = Convert.ToDouble(vc[2]);

Inside the release you will find the AccelerometerEmu class that you can use as an in-place replacement of the Accelerometer class. Unfortunately, the Accelerometer is sealed so I couldn't inherit from it and had to use composition instead. AccelerometerEmu connects to the accelKit and retrieves data in a constant rate when run in the Windows Phone 7 emulator. When run in a real device, it uses the real Accelerometer (since I don't have access to a real device I couldn't test how good that works). Here's what you have to do:

Replace all instances of Microsoft.Devices.Sensors.Accelerometer with NKast.Sensors.AccelerometerEmu.

Add an event listener to ReadingEmuChanged.

..  
accelerometer.ReadingEmuChanged += new EventHandler<AccelerometerEmuReadingEventArgs>(accelerometer_ReadingEmuChanged);
..


void accelerometer_ReadingEmuChanged(object sender, NKast.Sensors.AccelerometerEmuReadingEventArgs e)  
{
Deployment.Current.Dispatcher.BeginInvoke(() => MyReadingChanged(e));
}


void MyReadingChanged(AccelerometerEmuReadingEventArgs e)
{
double accelx , accely , accelz;
accelx = e.X; 
accely = e.Y;
accelz = e.Z; 
..

My Plans for the next version

Bug fixes!
Code optimization.
Derive acceleration from the mark movement. Right now it only accounts for orientation, therefore you get only gravity acceleration as if you were rotating the device in a fixed position.
Add a mode where the webcam looks straight down. I understand that's necessary for certain types of games. 

Last notice

  • The simulated accelerometer fires events in fixed intervals. A real device might behave differently.
  • The Timestamp property of AccelerometerEmuReadingEventArgs is not yet emulated.
  • Currently it only returns the gravity acceleration. Not acceleration caused by movement.
  • Do not print the paper cutout on glossy or semigloss paper! The less glare, the better!

 

I hope you find it helpful while developing great games for Windows Phone 7 !