top of page
  • Writer's pictureAlibek Jakupov

Virtual Laboratory with Microsoft's .Net XNA

Updated: Nov 19, 2021




Technological basis


When choosing the software environment for development of the virtual physical laboratory the main criterion was the speed of creating projects. Virtual laboratory works have to replace real experimental installations. Therefore, their quantity can be unlimited, which is one of the main advantages of virtual laboratory works in general. When choosing a development platform the review of the existing solutions, such as XNA Framework, Unity 3D Engine, and Unreal Development Kit has been carried out.

Microsoft XNA (from English XNA's Not Acronymed) represents the tools compatible to the manageable runtime environment (.NET), developed by the Microsoft company, which is intended to facilitate the development and management of computer games. The main concept of XNA implies that developers do not need to rewrite “the repeating pattern code”. In addition, XNA provides integration of the majority of game development tools in a single system.

The basis of the XNA Framework consists of .NET Compact Framework 2.0 to develop games for Windows (some of the implementations provide development for the Xbox 360). The framework comes with a set of libraries that are directly used to create interactive games with high graphics, supporting maximum code reuse on all target platforms, which allows developing for different platforms. The execution of the framework takes place on a modified version of the Common Language Runtime, which is optimized for game development, with the purpose of providing a manageable runtime environment. The environment is available for Windows XP, Windows Vista, Windows 7 and Xbox 360 (Winterhalter, 2011).

  • wrapper over DirectX (Direct3d, XINPUT, XACT);

  • classes Game, GameComponent, GameWindow, which are the framework for game applications;

  • set of auxiliary classes / structures for work with vectors, matrixes, beams, quaternions, and different mathematical functions (the functions, which are not implemented in standard System.Math are provided);

  • Content Pipeline structure that determines the specific to XNA system content.

XNA platform has a strong emphasis on the Object-Oriented Programming (OOP) paradigm, which allows optimizing code, accelerating the development process and modifying code in teamwork (C# Language Specification, 2015).


The structure and implementation of the laboratory work

The laboratory work as a game application on XNA consists of the following mainframes:

  • content and its loading (resources for game graphics, texts, audio files, etc.);

  • graphics display (2D in this laboratory work);

  • control processing (game reaction to various events from the mouse, gamepad or keyboard);

  • game logic and interaction of all game components

As a core of the laboratory work, as well as a core of any game on XNA the Game class is used. In the Game class the abstract methods Draw, Update, LoadContent, UnloadContent, Initialize and others are implemented. Thereby, each subsequent application is inherited from this class and overrides the important methods (events of the Game instance) for its purposes. This determines the logic of the future application. Also, the properties of the parent Game class are GameWindow classes, GraphicDevice etc. (Winterhalter, 2011).

The implementation of the base class allows running the game loop, cleaning the screen (filling with a uniform color), and handling the events when pressing certain buttons (closing a game window). Loading the content is carried out in LoadContent method.


Loading the content


Work on XNA assumes specific operations with the content of the system. XNA provides a set of “content processors” and “content of importers” (in addition to the use of standard resources, it is possible to add our own). The content of importers at the compilation stage will transform the content from the external supported format to the internal representation, compatible to XNA (Winterhalter, 2011). Then, the program resources, such as textures in dds, bmp and png formats at the compilation time are converted into the single internal format, uniform for all structures. This approach allows avoiding the dependence on a content format, for example, when using md3 models, it is necessary only to write additional content importer. The content processors are engaged in reformatting the content from internal representation to objects of the managed code, such as loading the content into the memory at the execution stage. Moreover, XNA provides finished importers and processors for the main types of content. As a rule, Solution Explorer studio is used to add the content to the application, into a special folder “Content”. Here, a certain processor and importer are assigned for each resource. The content of managed code is presented in the classes Texture, Texture2D, Model, Model Mesh, Effect, etc.

Loading in a code is made through the class ContentManager (Content Field Class Game), and is carried out in the method LoadContent of the Game class (according to the good programming style).

The standard processors support the following:

  • models;

  • textures;

  • raster fonts;

  • shaders

Graphics display

Graphics and text display is based on the SpriteBatch class. Consequently, the SpriteBatch instance is created, when Draw method is called:

  • SpriteBatch.Begin () begins drawing;

  • SpriteBatch.Draw () is called for drawing of each sprite (drawing of all texture or its fragments);

  • SpriteBatch.End () finishes drawing process

SpriteBatch.Draw () parameters – the position on the screen, where the texture is drawn, rotate, skew, scale. Also, SpriteBatch class performs a sorting by the Z coordinate (automatically). The resource of texture is transferred to the SpriteBatch.Draw() method as a reference to the class Texture2D, which is obtained by uploading the content to the application.


Control

The project of virtual physical laboratory work “Measurement of the horizontal component of the Earth magnetic induction” includes classes, the structure of which and relations between them are given in Figure 2.


In addition to the project classes shown in the figure, there is a special set of classes with static methods, such us Keyboard, Mouse, GamePad, which represent a particular device. Each class has the GetState() method, which returns respectively KeyboardState, MouseState, GamePadState, such as X, Y position of the mouse cursor, or a state of the keyboard key.

The list of the project classes is as follows:

  • Button;

  • Desktop;

  • DesktopElement;

  • Element;

  • Frame;

  • Global;

  • Message;

  • Table;

  • Toolbars;

  • Toolbox;

  • ToolboxElement;

  • Wire

Circuit Testing is performed in the class Button, in the checkCircuit() method. The program determines if the necessary elements are on the screen (the list of items defined in the array) and if they are connected (the connection is defined in the class Wire). Table is a class, which is responsible for displaying the table and information in it.


Figure 2: The class diagram of the virtual laboratory work “Measurement of the horizontal component of the Earth magnetic induction”.

Running the game application on the user's machine.

The list of the software that is needed to run the laboratory work on the user's personal computer is as follows:

  • .NET framework 2.0 Redistributable;

  • XNA Redistributable;

  • DirectX Redistributable

In addition, a video card that supports Shader 1.1 is necessary.

User interaction

The process of conducting the virtual laboratory work is the realization of a certain sequence of actions, which includes input of initial data, start of an experiment and registration of the results. Figure 3 shows a flow chart of user interaction with the laboratory work “Measurement of the horizontal component of the Earth magnetic induction”.


Figure 3: The state diagram of the virtual laboratory work “Measurement of the horizontal component of the Earth magnetic induction”.

The beginning of the scenario signifies an entry point to the laboratory work. After the program is run, the main program menu is displayed to the user, which is designated as Desktop. In addition to the stand simulation for building an electric circuit, the main menu has the Submit button to start the simulation of circuit locking/disjunction and the Help sign. After the circuit is locked, the results of calculations and the readouts of the circuit elements are registered in the table (Table class). All the elements of the project are connected using a special Global class. In case of incorrectly built circuit a special error message (“Circuit is incorrect”) is displayed.

Windows control elements were used for the design of the user interface for this virtual laboratory work. In general, all students are familiar with Microsoft Windows operating system very well. And the usage of usual control elements, such as buttons, input fields, windows, scrollbars, etc. simplifies the process of understanding and conducting the virtual lab. Moreover, the full reference is available to students. The interface model for the laboratory work “Measurement of the horizontal component of the Earth magnetic induction” is given in figure 4.


Figure 4: The model of the interface of the virtual laboratory work “Measurement of the horizontal component of the Earth magnetic induction” (Entry point).

Figure 5: The model of the interface of the virtual laboratory work “Measurement of the horizontal component of the Earth magnetic induction” (Simulation).

Students are given a training simulation stand to build an electrical circuit (Figure 5). In this case, students choose items from the list of tools and place them on the stand. Students need to stretch a wire between the elements to build a circuit. The wire is a tool by default, therefore, if none of the tools is chosen, a working element is the wire. The buttons to begin the simulation and the auxiliary menu are located on the initial screen. If the circuit is built wrong, the error message is appeared. During the simulation, students have the option to stop the simulation and to continue building a circuit from the last saved state.

58 views0 comments

Recent Posts

See All
bottom of page