Do-it-yourself powerful stirling engine. Do-it-yourself mechanical supercharging of the engine: installing a compressor


Do-it-yourself website engine. Option one: if you don’t have a database...

Every site builder at one point suddenly notices that he is no longer engaged so much in preparing new materials for his site, but in banal and routine things: he picked out the menu, replaced it; I saved it there and updated it; here - copy, there - paste, and then save and upload all this. “Well, no,” the webmaster thinks, “this can’t happen anymore! But what to do? And you need to create an engine for the site...

This article is the first of a series of articles I have planned, in which we will try to make something like an engine for simple websites. We will also consider the principles of separating website content from its design (design) and ways to automate webmaster work.

An engine is usually called a set of scripts and programs on the basis of which the site is maintained, lives and is updated. The engine can be like with a simple PHP script and articles stored in text files of a certain format, as well as a complex complex software in conjunction with databases (MySQL, Oracle, etc.) and web services written in Java.

The best (but not the most difficult) option would be to use databases. But most often the database is not available to webmasters, since they provide it (as far as I know) only on paid hostings. Therefore, we will organize our first engine at PHP help and a set of files. At the same time, you can console yourself with the fact that the performance of our site will not be affected by additional risk factors introduced by the use of databases (everyone, I believe, has already heard about the story with a hole in Microsoft SQL Server 2000) (1).

Our engine will be specially adapted for content projects (that is, sites that are regularly updated with original articles or other materials). This means that we will have to do everything for a convenient and quick update site content.

So, first we need to define a couple of functions for reading data from a file. Before bringing source codes, let's look at the tools we have (or rather, in PHP) for working with files (and those who are not in the know will immediately find out).

File reading functions in PHP

...
$strings = file("myfolder/myfile.txt");
$first_string = $strings;
...

Let's make our own homemade database. For it, firstly, we need the following functions: one for reading the page content (for example, the text of an article) from external file- data loading; a function for loading a template from a file - that is, loading a design (design).

function loadTemplate($path)
/* function loads the template at the specified path,
and returns it as a string, for example,
for processing by the parceTemplate() function */
{
$template = fopen($path, "r") or print("Failed to load template file [".$path."]");

if($template)
return fread($template, filesize($path));
else
return false;

Fclose($template);
}

function parceTemplate($template, $params_ value s)
/* function parses the specified pattern,
replacing the names of parameters that serve as indices
array $params_ value s to their values ​​*/
{
while(list($param, $ value) = each($params_ value s))
{
$template = str_replace("¤(".$param.")¤", $ value, $template);
}

Return $template;
}

function readArticle($path)
/* function reads specified file and returns
its contents in the form of an array of article parts,
separated by the construction ¤(part name)¤ */
{
$article = fopen($path, "r") or print("Failed to load article file [".$path."]");

if($article)
{
$astring = fread($article, filesize($path));
$result = split("[¤](1)[(](1)([ a-z_-]*)[)](1)[¤](1)", $astring);

$result = eregi_replace("[ ,]*([ - ](1))[, ]*", " - ", $result);
$result = basename($path);
return $result;
}
else
{
return false;
}
}

Somewhere here we should have screwed a granite slab with the inscription “Regular expressions from grateful fans”, since without this handy thing it would be very difficult to create the above functions. Let's take a closer look at how these expressions are structured.

There is no point in writing about the same thing many times, so I will quote one of the articles on regular expressions (Source: http://sitemaker.ru/):

Regular Expressions

A little history

Mathematician Stephen Klin first introduced regular expressions in 1956, as a result of his work with recursive sets in natural language. They were created as syntactic sets used to match patterns in strings, which later helped access emerging technological information, facilitating automation.

Since then, regular expressions have gone through many iterations, and the current standard is maintained by the ISO (International Organization for Standardization) and defined by the Open Group, a collaborative effort of various technical non-profit organizations (2).

Character matching

The difficulty with regular expressions is what you want to look for or what it should match. Without this concept, REs are useless. Each expression will contain some command about what to look for:

Character matching in regular expressions
Operator Description Example Result
. Matches any one character .ord Will match "ford", "lord", "2ord", etc. in the sample.txt file.
Matches any single character enclosed in square brackets ord Will only match "cord", "nord" and "gord"
[^] Matches any single character not enclosed in square brackets [^cn]ord Will match "lord", "2ord", etc., but not "cord" or "nord"
Matches any letter ord Will match "aord", "bord", "Aord", "Bord", etc.
[^0-9] Matches any non-digit in the range 0-9 [^0-9]ord Will match "Aord", "aord", etc., but not "2ord", etc.

Repeat Operators

Repeat operators, or quantifiers, describe how many times to search for a specified string. They are used in conjunction with character-matching syntax to search for multiple occurrences of characters. IN various applications their support may change or be incomplete, so you should read the application documentation if the template does not work as expected.

Repeat operators in regular expressions
Operator Description Example Result
? Matches a specific character once if it exists ?erd Will match "berd", "herd", etc. and "erd"
* Matches a specific character multiple times if it exists n.*rd Will match "nerd", "nrd", "neard", etc.
+ Matches a specific character one or more times [n]+erd Will match "nerd", "nnerd", etc., but not "erd"
(n) Matches a specific character exactly n times (2)erd Will match "cherd", "blerd", etc., but not "nerd", "erd", "buzzerd", etc.
(n,) Matches a specific character at least n times .(2,)erd Will match "cherd" and "buzzerd" but not "nerd"
(n,N) Matches a specific character at least n times, but no more than N times n[e](1,2)rd Will match "nerd" and "neerd"

Anchors describe where to match the pattern. They can be handy when you are looking for common string combinations.

Regular expression anchors
Operator Description Example Result
^ Matches the beginning of a string ereg_replace("^/", "blah") Inserts "blah" at the beginning of a line
$ Matches the end of the string ereg_replace("$/", "blah") Inserts "blah" at the end of the line
< Matches the beginning of a word ereg_replace("<", "blah") Inserts "blah" at the beginning of a word
Matches "blahfield" etc.
> Matches the end of a word ereg_replace(">", "blah") Inserts "blah" at the end of a word
>blah Matches "soupblah" etc.
b Matches the beginning or end of a word bblah Matches "blahcake" and "countblah"
B Matches the middle of a word Bblah Corresponds to "sublahper", etc.

(end of quote, source of description: http://sitemaker.ru/)

So let's continue. The functions we created are useful for reading articles from files and displaying a list of the newest articles. Moreover, to modify all this, we will only need to write a new article in the form of a file with a certain syntax (see below) and add it to a folder on the server.

The symbols ¤( and )¤ are used to separate parts from each other. The name of the part has no meaning and can be any set of characters from the English alphabet, space, underscore or hyphen.

To display a list of articles, a loop is used that iterates through all the files from the desired directory. If he comes across a *.art file, he immediately adds it to the array to celebrate. Depending on the specified parameter, it can either add the name of this file, or the name of the article it contains, or immediately a ready-made link to this article.

Well, a small part of the work on our engine has already been done. This piece of code is the basis of our first engine. For specific purposes you need to attach to it additional functions and create the texts and page templates themselves.

Do-it-yourself website engine. Part two.

Last time we looked at a way to organize a “database” without the actual database itself. Today we will continue the topic of creating a “mySQL-free” website engine by talking about directories, files and includes. There will also be a little theory and practice about the actual operation of such an engine.

Basic principles of work organization

It’s easy to guess that the organization of the engine depends on many factors that vary in each specific example of a site. This includes the expected structure of the information, and the features of the hosting on which the site is located (the presence or absence of tools such as PHP, SSI, the availability of any databases, etc.), and no less when developing a device for the future engine, you need take into account the design of the site, that is, the structure of the pages themselves.

Actually, one of the goals of creating an engine for a site is precisely the organization of convenient work on updating materials, and, as a precondition, the almost complete separation of the site’s design from its actual useful content (turned down). But in any case, the future design must take into account how - more on that a little later.

So, the very word “separation” already implies, at a minimum, the division of a site page into two files - with a design template (which can be common to several pages) and a file with the content itself, that is, information.

In addition to these two files, we need one more, included in all dynamic pages (meaning pages containing PHP code). In this file we will store all the general functions of the engine (in fact, they can be called the “core”), and we will also define some useful global constants.

The main task of the kernel functions will be to read files with article texts, pictures or other site materials, as well as output this content to in the required form to the screen. We do not consider the third function - data entry, since the method of data storage (delimited files) allows you to enter information using standard means(your favorite text editor, for example).

Thus, the scheme for creating new site materials is as follows:

Rice. 1. Text → engine → site page

And by the phrase “take into account the design”, expressed a little higher, we meant the creation of a system of templates, or, more simply put, a set of designs different pages(HTML files, in fact), where places for changeable content (headings, menus, texts - everything that is generated dynamically) are left empty. They will be substituted “on the fly” when the user accesses a specific page. There is even an additional benefit - among other things, the volume of files stored on the server is reduced, since the page design is not repeated in each file, but is stored in one place. I don’t think there’s any need to talk about convenience in case of a possible desire to change the design.

File locations

So, let's return to the actual organization of our system. The basic principle that will be used in our example is the same level of sections. But don't worry - these are just to simplify the examples. If this is too serious a limitation for you, you will just have to wait for the next release, in which we will look for workarounds.

For our engine to work, we need to organize the directory structure in such a way as in Fig. 2 (this example is simply used in the examples described, the structure does not have to be exactly like this).

Rice. 2. Directory structure

So, we have directories, each of which is a section of the site (of course, except for service directories, such as “images”).

This means that each such directory must contain a so-called “index file” - a page that is loaded by default when accessing the section in this way: http://site.com/Razdel. You will need to find out the name of this file (or possible names) from your hoster. Most often these are names such as “index.html”, “index.php”, etc. - the extension depends on the server language used.

This means we have sorted out the file names. But what should we put in these files? Now we move on to the main part of today’s conversation.

At the very beginning of the file, you should insert the code to enable the engine kernel. A similar call in PHP looks like this:

This file contains the same read-output functions described in the previous article. Thus, they are now available for use.

In the same file it is worth describing some more useful features. For example, a function to directly receive a file as a string (may be useful):

function getInclude($path)
{
return str_replace("n", "", (implode(file($path), "")));
}

News system

Another useful function may be to organize a simple news system. But, despite the simplicity of implementation, it has quite convenient features, such as outputting a block with a specified number anywhere on the page latest news and the ability to organize a news archive.

The essence of her work boils down to the following. There is a text file with news separated by a newline character (in other words, each news is in new line). Each line is separated by a vertical bar (“|”) into two fields: the date and, in fact, the news itself.

By defining the news system function in our include file (“core”), we are able to get the required amount of latest news on any page. The first parameter is a part of the path indicating the location of the news file. The number of news items displayed, as you may have guessed, is specified by the second, optional, parameter.

Here is my implementation of the news system function:

Well, that's all for today. To be continued...

The Stirling engine, once famous, was forgotten for a long time due to the widespread use of another engine (internal combustion). But today we hear more and more about him. Maybe he has a chance to become more popular and find his place in new modification in modern world?

Story

The Stirling engine is a heat engine that was invented in the early nineteenth century. The author, as is clear, was a certain Stirling named Robert, a priest from Scotland. The device is an external combustion engine, where the body moves in a closed container, constantly changing its temperature.

Due to the spread of another type of motor, it was almost forgotten. Nevertheless, thanks to its advantages, today the Stirling engine (many amateurs build it at home with their own hands) is making a comeback again.

The main difference from an internal combustion engine is that the heat energy comes from outside, and is not generated in the engine itself, as in an internal combustion engine.

Principle of operation

You can imagine a closed air volume enclosed in a housing with a membrane, that is, a piston. When the housing heats up, the air expands and does work, thus bending the piston. Then cooling occurs and it bends again. This is the cycle of operation of the mechanism.

It is no wonder that many people make their own thermoacoustic Stirling engine at home. This requires the bare minimum of tools and materials, which can be found in everyone’s home. Let's look at two different ways to easily create one.

Materials for work

To make a Stirling engine with your own hands, you will need the following materials:

  • tin;
  • steel spoke;
  • brass tube;
  • hacksaw;
  • file;
  • wooden stand;
  • metal scissors;
  • fastening parts;
  • soldering iron;
  • soldering;
  • solder;
  • machine.

This is all. The rest is a matter of simple technique.

How to do

A firebox and two cylinders for the base are prepared from tin, of which the Stirling engine, made with your own hands, will consist. The dimensions are selected independently, taking into account the purposes for which this device is intended. Let's assume that the motor is being made for demonstration. Then the development of the master cylinder will be from twenty to twenty-five centimeters, no more. The remaining parts must adapt to it.

At the top of the cylinder, two protrusions and holes with a diameter of four to five millimeters are made to move the piston. The elements will act as bearings for the location of the crank device.

Next, they make the working fluid of the motor (it will become ordinary water). Tin circles are soldered to the cylinder, which is rolled into a pipe. Holes are made in them and brass tubes from twenty-five to thirty-five centimeters in length and with a diameter of four to five millimeters are inserted. At the end, they check how sealed the chamber has become by filling it with water.

Next comes the turn of the displacer. For manufacturing, a wooden blank is taken. The machine is used to ensure that it takes the shape of a regular cylinder. The displacer should be slightly smaller than the diameter of the cylinder. The optimal height is selected after the Stirling engine is made with your own hands. Because on at this stage the length should allow for some margin.

The spoke is turned into a cylinder rod. A hole is made in the center of the wooden container that fits the rod, and it is inserted. In the upper part of the rod it is necessary to provide space for the connecting rod device.

Then they take copper tubes four and a half centimeters long and two and a half centimeters in diameter. A circle of tin is soldered to the cylinder. A hole is made on the sides of the walls to connect the container with the cylinder.

The piston is also adjusted on a lathe to the diameter of the large cylinder from the inside. The rod is connected at the top in a hinged manner.

The assembly is completed and the mechanism is adjusted. To do this, the piston is inserted into a larger cylinder and connected to another smaller cylinder.

A crank mechanism is built on a large cylinder. Fix the engine part using a soldering iron. The main parts are fixed on a wooden base.

The cylinder is filled with water and a candle is placed under the bottom. A Stirling engine, made by hand from start to finish, is tested for performance.

Second method: materials

The engine can be made in another way. To do this you will need the following materials:

  • tin;
  • foam;
  • paper clips;
  • disks;
  • two bolts.

How to do

Foam rubber is very often used to make a simple, low-power Stirling engine at home with your own hands. A displacer for the motor is prepared from it. Cut out a foam circle. The diameter should be slightly smaller than that of a tin can, and the height should be slightly more than half.

A hole is made in the center of the cover for the future connecting rod. To ensure that it runs smoothly, the paper clip is rolled into a spiral and soldered to the lid.

The foam circle is pierced in the middle with a thin wire and a screw and secured on top with a washer. Then the piece of paper clip is connected by soldering.

The displacer is pushed into the hole in the lid and connected to the can by soldering to seal it. A small loop is made on the paperclip, and another, larger hole is made in the lid.

The tin sheet is rolled into a cylinder and soldered, and then attached to the can so that there are no cracks left at all.

The paperclip is turned into a crankshaft. The spacing should be exactly ninety degrees. The knee above the cylinder is made slightly larger than the other.

The remaining paper clips are turned into shaft stands. The membrane is made as follows: the cylinder is wrapped in polyethylene film, pressed and secured with thread.

The connecting rod is made from a paper clip, which is inserted into a piece of rubber, and the finished part is attached to the membrane. The length of the connecting rod is made such that at the lower shaft point the membrane is drawn into the cylinder, and at the highest point it is extended. The second part of the connecting rod is made in the same way.

One is then glued to the membrane and the other to the displacer.

The legs for the jar can also be made from paper clips and soldered. For the crank, a CD is used.

Now the whole mechanism is ready. All that remains is to place and light a candle under it, and then give a push through the flywheel.

Conclusion

This is a low-temperature Stirling engine (built with my own hands). Of course, on an industrial scale such devices are manufactured in a completely different way. However, the principle remains the same: the air volume is heated and then cooled. And this is constantly repeated.

Finally, look at these drawings of the Stirling engine (you can make it yourself without any special skills). Maybe you've already got the idea and want to do something similar?

Do-it-yourself website engine. Option one: if you don’t have a database...

Every site builder at one point suddenly notices that he is no longer engaged so much in preparing new materials for his site, but in banal and routine things: he picked out the menu, replaced it; I saved it there and updated it; here - copy, there - paste, and then save and upload all this. “Well, no,” the webmaster thinks, “this can’t happen anymore! But what to do? And you need to create an engine for the site...

This article is the first of a series of articles I have planned, in which we will try to make something like an engine for simple websites. We will also consider the principles of separating website content from its design (design) and ways to automate webmaster work.

An engine is usually called a set of scripts and programs on the basis of which the site is maintained, lives and is updated. The engine can be either a simple PHP script and articles stored in text files of a certain format, or a complex set of software tools in conjunction with databases (MySQL, Oracle, etc.) and web services written in Java.

The best (but not the most difficult) option would be to use databases. But most often the database is not available to webmasters, since it is provided (as far as I know) only on paid hosting sites. Therefore, we organize our first engine using PHP and a set of files. At the same time, we can console ourselves with the fact that the performance of our site will not be affected by additional risk factors introduced by the use of databases (everyone, I believe, has already heard about the story with the hole in Microsoft SQL Server 2000) (1).

Our engine will be specially adapted for content projects (that is, sites that are regularly updated with original articles or other materials). This means that we will have to do everything to conveniently and quickly update the site’s content.

So, first we need to define a couple of functions for reading data from a file. Before presenting the source codes, let’s look at the tools we have (or rather, in PHP) for working with files (and those who are not in the know will immediately find out).

File reading functions in PHP.

...
$strings = file("myfolder/myfile.txt");
$first_string = $strings;
...

Let's make our own homemade database. For it, firstly, we need the following functions: one for reading the content of the page (for example, the text of an article) from an external file - loading data; a function for loading a template from a file - that is, loading a design (design).

function loadTemplate($path)
/* function loads the template at the specified path,
and returns it as a string, for example,
for processing by the parceTemplate() function */
{
$template = fopen($path, "r") or print("Failed to load template file [".$path."]");

If ($template)
return fread($template, filesize($path));
else
return false;

Fclose($template);
}

Function parceTemplate($template, $params_values)
/* function parses the specified pattern,
replacing the names of parameters that serve as indices
array $params_values ​​with their values ​​*/
{
while (list($param, $value) = each($params_values))
{
$template = str_replace("¤(".$param.")¤", $value, $template);
}

Return $template;
}

Function readArticle($path)
/* function reads the specified file and returns
its contents in the form of an array of article parts,
separated by the construction ¤(part name)¤ */
{
$article = fopen($path, "r") or print("Failed to load article file [".$path."]");

If ($article)
{
$astring = fread($article, filesize($path));
$result = split("[¤](1)[(](1)([ a-z_-]*)[)](1)[¤](1)", $astring);

$result = eregi_replace("[ ,]*([ - ](1))[, ]*", " - ", $result);
$result = basename($path);
return $result;
}
else
{
return false;
}
}

Somewhere here we should have screwed a granite slab with the inscription “Regular expressions from grateful fans”, since without this handy thing it would be very difficult to create the above functions. Let's take a closer look at how these expressions are structured.

There is no point in writing about the same thing many times, so I will quote one of the articles on regular expressions (Source: http://sitemaker.ru/):

Regular expressions.

A little history.

Mathematician Stephen Klin first introduced regular expressions in 1956, as a result of his work with recursive sets in natural language. They were created as syntactic sets used to match patterns in strings, which later helped access emerging technological information, facilitating automation.

Since then, regular expressions have gone through many iterations, and the current standard is maintained by the ISO (International Organization for Standardization) and defined by the Open Group, a collaborative effort of various technical non-profit organizations (2).

Character matching.

The difficulty with regular expressions is what you want to look for or what it should match. Without this concept, REs are useless. Each expression will contain some command about what to look for:

Character matching in regular expressions
Operator Description Example Result
. Matches any one character .ord Will match "ford", "lord", "2ord", etc. in the sample.txt file.
Matches any single character enclosed in square brackets ord Will only match "cord", "nord" and "gord"
[^] Matches any single character not enclosed in square brackets [^cn]ord Will match "lord", "2ord", etc., but not "cord" or "nord"
Matches any letter ord Will match "aord", "bord", "Aord", "Bord", etc.
[^0-9] Matches any non-digit in the range 0-9 [^0-9]ord Will match "Aord", "aord", etc., but not "2ord", etc.

Repetition operators.

Repeat operators, or quantifiers, describe how many times to search for a specified string. They are used in conjunction with character-matching syntax to search for multiple occurrences of characters. Support may vary or be incomplete across different applications, so you should read the application's documentation if a template doesn't work as expected.

Repeat operators in regular expressions
Operator Description Example Result
? Matches a specific character once if it exists ?erd Will match "berd", "herd", etc. and "erd"
* Matches a specific character multiple times if it exists n.*rd Will match "nerd", "nrd", "neard", etc.
+ Matches a specific character one or more times [n]+erd Will match "nerd", "nnerd", etc., but not "erd"
(n) Matches a specific character exactly n times (2)erd Will match "cherd", "blerd", etc., but not "nerd", "erd", "buzzerd", etc.
(n,) Matches a specific character at least n times .(2,)erd Will match "cherd" and "buzzerd" but not "nerd"
(n,N) Matches a specific character at least n times, but no more than N times n[e](1,2)rd Will match "nerd" and "neerd"

Anchors describe where to match the pattern. They can be handy when you are looking for common string combinations.

Regular expression anchors
Operator Description Example Result
^ Matches the beginning of a string ereg_replace("^/", "blah") Inserts "blah" at the beginning of a line
$ Matches the end of the string ereg_replace("$/", "blah") Inserts "blah" at the end of the line
\< Matches the beginning of a word ereg_replace("\<", "blah") Inserts "blah" at the beginning of a word
\ Matches "blahfield" etc.
\> Matches the end of a word ereg_replace("\>", "blah") Inserts "blah" at the end of a word
\>blah Matches "soupblah" etc.
\b Matches the beginning or end of a word \bblah Matches "blahcake" and "countblah"
\B Matches the middle of a word \Bblah Corresponds to "sublahper", etc.

(end of quote, source of description: http://sitemaker.ru/)

So let's continue. The functions we created are useful for reading articles from files and displaying a list of the newest articles. Moreover, to modify all this, we will only need to write a new article in the form of a file with a certain syntax (see below) and add it to a folder on the server.

The symbols ¤( and )¤ are used to separate parts from each other. The name of the part has no meaning and can be any set of characters from the English alphabet, space, underscore or hyphen.

To display a list of articles, a loop is used that iterates through all the files from the desired directory. If he comes across a *.art file, he immediately adds it to the array to celebrate. Depending on the specified parameter, he can either add the name of this file, or the title of the article it contains, or immediately a ready-made link to this article.

Well, a small part of the work on our engine has already been done. This piece of code is the basis of our first engine. For specific purposes, you need to attach additional functions to it and create the texts and page templates themselves.

Some time ago we touched on the topic of creating computer games and talked about a unique free 3D engine written in Delphi - GLScene(take the engine from our CD/DVD ). The topic of creating full-fledged three-dimensional computer games was very interesting to you, as could be judged by the number of letters received. However, then we decided that talking about engine programming was too difficult. Since then, your level has increased noticeably (this can also be judged by letters and activity on the magazine forum), you have become more savvy in programming issues. Especially after the publication of the series “ Programmer's Pantry”.
With this issue, we begin publishing a series of articles in which we will look in detail at the various stages of creating a 3D game. You will improve your programming skills and, as they say, look behind the veil of secrecy that separates serious game developers from mere mortals.
The engine of any game consists of many and often independent building blocks: collision control, physical model, game interface, main menu, loading levels and much more. There are specific bricks
which are needed only for one genre. For example, the weather module is important and needed in an aviation or maritime simulator, but in a real-time strategy it is secondary or not needed at all, and in a football simulator there is no need for a gunshot module. But several dozen bricks are present in any game. In a series of articles we will talk about each of these building blocks, show how they are implemented and how to connect them with the others. By the end of the cycle, you will be able to use these bricks to build your own computer game of a fairly high level.

What are you doing here?
For those who missed some of my previous articles (or even all), I will answer any questions you may have. So to speak, a small technical introduction.
Why Delphi? This development environment and programming language Object Pascal flexible enough to create a full-fledged 3D game of almost any genre with modern graphics. Many would argue that the de facto standard for computer game development is MSVC++ or other media based C++. But such standards, as often happens, develop spontaneously. Let's not confuse two concepts - language and development environment.
C++ is definitely more powerful than Object Pascal. But it is also less high-level, that is, many times more difficult. C++ is not suitable for beginners. Object Pascal is not only simple, but also flexible enough that it can be used to develop a full-fledged modern computer game. Now about Wednesdays. You can’t say that categorically here. Development environment- a matter of taste and habit of each individual programmer. I will share my opinion on this matter. MSVC++ generates slightly faster code than Delphi. Actually, this is where the advantages end (I repeat, in my subjective and non-binding opinion). Delphi trumps - high speed compilation (tens and even hundreds of times faster than MSVC++), high quality debugging tools (in most cases, Delphi indicates exactly the line of code that contains the error, while MSVC++ can indicate the line several pages away from the one you are looking for) and user-friendly interface.
Why GLScene? I've seen and tried many free 3D engines, but I settled on this one. Its most important advantage is that GLScene is constantly being improved. The developers have not put an end to it and, most likely, will never do so. The engine is constantly evolving and absorbs all the latest technical progress. This is the only free engine I know about which they will never say “outdated”. Several hundred enthusiasts constantly working on the “engine” will not allow this. As an example: support for the very first shaders appeared in the engine just a few months after NVidia issued the relevant tools.
Another advantage: GLScene comes with its full sources. For beginners, this fact is probably unlikely to be useful. Although it is worth a lot to get acquainted with the source code written by a professional. But experienced programmers feel the main meaning of these words: after all, they will be able to redesign the engine as they please.
at will. The only condition in accordance with the MPL license is that any changes in the source code must be available to the project coordinator (currently the coordinator is Eric Grange). What if your code is useful to someone else?!
Although all the code examples that will be given in this series of articles will be written in Delphi using GLScene, they will also be useful to those who program in other languages ​​and with other graphics libraries. After all general principles The creation of a graphics engine does not depend on either one or the other. So... we begin.

Why do you need a 3D engine?
Fellow newbies, concentrate! Perhaps what I say now will not be very clear the first time. Be sure to re-read and understand: this is one of the basic principles of programming in general and the development of complex systems (and a game is a complex system) in particular. Imagine some simple game. Ping-pong, for example. The programmer wrote it in pure OpenGL, the source codes fit into about 200 lines. What will be the engine, and what will be the main code of the game? You can’t say it right away... But if you think about it, such a division into the engine and the main code is not necessary at all.
Now imagine that we want to make a more or less serious 3D action (tens of thousands of lines of code). And we will program in the same way as if we were doing that same ping-pong. And soon we will get confused! Yes this code willfast, there will be nothing superfluous, but... not every programmer will be able to finish it to the end. And the errors in such dense codesearching is pure hell. This means that it needs to be sorted somehow. The easiest way to do this is with highlighting levels of abstraction.
The abstraction level is one of the most important concepts in modular programming. Imagine that you are a builder and you need to build a house. You operate with bricks: take a brick, place it on the wall under construction, spread it with mortar, take the next brick... Bricks are your level of abstraction. Now imagine that you are a developer. And you need to build a microdistrict. You tell the builder where to build houses, which houses to tear down. Home is your level of abstraction. It would be strange if you told a builder which brick to put where. You said: this is where the house will be. The builder takes care of all other concerns. Well, now imagine that you are the mayor of a city. And you need to give the task to the crowd of developers to give the city so much new housing by such and such a year. It is unlikely that you will personally plan where each house should be. This is the developer's job. The mayor's level of abstraction is the volume of housing stock, which can be increased or decreased, but how this will be accomplished is another matter. By and large, at this level of abstraction, it doesn’t matter what houses are built from: be it bricks or mammoth tusks. And the mayor simply cannot have “ lay a brick”, although any of his commands will lead to this through several levels of abstraction.
In a more or less complex computer program or game it’s the same. Each abstraction level is responsible for its part of the work, relying on the capabilities of the lower level. Each level of abstraction provideshigher level convenient interface for working with objects. In a computer game, the lowest level of abstraction is programming language (although, in fact, you can dig even deeper - to the hardware). Next are the commands OpenGL API(if we program with it). At this level we can issue a command like “ draw a polygon" And " swap the visible and shadow parts of the video buffer" Then - the teams GLScene. At this level we can give commands like “ build a cube”, “download the model in 3ds format" And " apply such and such a texture to the model" And then there’s the game engine. And finally, game code that can give the game engine commands like “ load level”, “shoot such and such a character with such and such a weapon" And " show intro video" Ideally, each level of abstraction uses only the commands of the previous level. This is not always possible. But we must strive for this, since in this case the code will be fast, convenient and easy to read.

Dynamic creation of objects
We looked at the vertical organization of a computer game. But each level of abstraction can be divided into semantic blocks - modules. This division is optional and will always be purely conditional, it’s just easier to program this way. Today we will analyze a small but very important building block - dynamic creation objects, which is present in all games without exception.
Let's say you're creating a weapons module and want to program a burst ofmachine gun. Everything would be fine, but how do you know how many bullets a player can fire in the entire game? You can create any objects using the object editor in the GLScene IDE, but only if you clearly know how many and what objects you need. In most cases this is unacceptable. For example, you have 20 levels in your game, each level has its own set of objects. So, should we create all the objects of all levels before starting the game? It's long and it will take great amount memory. The only way out- create objects directly during the game, dynamically. In GLScene, the dynamic creation of any object consists of two stages - creating an instance of the class of this object and assigning the necessary properties to it. Let's take the already mentioned example of machine gun bursts and dynamically create a bullet. Let's assume that our bullet will be an industrial sphere. The class responsible for spheres in GLScene is TGLSphere. It would seem that one could write it like this:
Sphere:=TGLSphere.Create
However, the command will not work, since each object in GLScene needs to register in the object queue. In addition, an object cannot be created in a “void”; it must be bound to some higher-level object. The highest level root object is glscene1.Objects (if your TGLScene component object is called glscene1). Correct option:
Sphere:=TGLSphere (glscene1.Objects.AddNewChild(TGLSphere))
Let's look at this line piece by piece. At the root object glscene1.Objects we call the method AddNewChild, which adds to the root the object of the class specified in the parameter (in in this case this is the sphere -
TGLSphere). This is also possible: passing not objects, but entire classes as parameters to procedures. Why do you need a type conversion before assignment? TGLSphere? The point is that the method AddNewChild, no matter what you pass to it as a parameter, returns an object of the class TGLBaseSceneObject. This does not suit us, so we convert the type to TGLSphere. The resulting object is assigned to the Sphere variable. Now, using this variable, we can set different parameters for our pool, for example, position in space:
Sphere.Position.X:=
Sphere.Position.Y:=
Sphere.Position.Z:=
Or color:
Sphere.Material.FrontProperties.Diffuse=
We have discussed the dynamic creation of models, and now let’s talk about their dynamic destruction. In fact, a bullet someday hits a wall, a person, or flies off into the blue distance. From now on it is no longer needed. If we leave it like that, it will occupy some memory area. Considering how many shots the average camper fires before his hole is discovered, we don't have enough computer memory to store that many bullets. Therefore, any game objects that have become unnecessary must be immediately destroyed. The only correct way to do this is to call the method Free, For example:
Sphere.Free
It is often necessary to check whether an object exists or has already been destroyed. To do this, we compare the object with the universal constant zero - nil, For example:
If Sphere<>nil then
Begin
(the sphere has not yet been destroyed,
So we're doing something useful here)
End
Or we call the function Assigned, which does the same thing. And here one giant pitfall awaits you, which all programmers have encountered sooner or later. If you freed an object using the method Free, this does not guarantee that the object variable has become equal to nil! That is, under a certain set of circumstances in the example above, even if the sphere is destroyed, the condition will be met. If you handle this area after checking (and this almost always happens), a critical error will occur, which can lead to the game crashing. To ensure that the freed object becomes nil, use a special procedure FreeAndNil, For example:
FreeAndNil(Sphere)
Now you can be sure that you will never access an object that no longer exists. The described procedure for creating and destroying objects can be applied to any GLScene objects.

Why do games need a battery?
Consider the example above with a machine gun. Usually in games, bullets are not just spheres, but complex objects, which also have a texture. Each time you create a bullet, a chunk of memory is freed, installing properties of this bullet, the bullet model is loaded, the texture is loaded (from the hard drive!). All it takes certain time. If the number of bullets that a machine gun spews per second is very large, wild brakes may begin, especially on weak computers. There is the same problem with destroying bullets:you need to unload the object, free up memory... The same applies not only to bullets, but also to any objects that often appear and disappear, for example, raindrops, sparks from electrical wiring... Such wastefulness system resources V computer games unacceptable. You don't want your game to be able to run only on a super cool graphics station, do you?
The solution is simple. Let's estimate how many objects of this kind can exist on average at the same time. Let's say a machine gun can fire several hundred bullets in ten seconds, and in the same ten seconds the bullets will definitely reach the target. Before the game starts, we create all one hundred bullets. The best time to do this is while loading the level. No one will notice a slight delay. Next, the bullets are placed in a list or array, which we call battery. We make bullets invisible or take them somewhere outside the playing space. Once the machine gun starts firing, instead of creating bullets, we move the already created bullets from the battery to the desired location and make them visible. As soon as the bullet reaches the target, we do not destroy it, but make it invisible again and place it in the battery. As a result, for each bullet we save creation time and destruction time. And this is very, very much! What if we were a little wrong in our estimates, the bullets in the battery ran out, but the machine gun continued to fire? There’s nothing you can do about it - you’ll have to create new bullets dynamically until the old ones return to the battery. And we won’t destroy new bullets either, but store them in the battery in case we need them again...

Attack of the Clones
Let us have a large forest in which there are many, many identical trees or, say, many trees of several different species. The example is similar to the previous one, only we are not dynamically creating or destroying anything here - at this level there are always trees. There will be a problem when loading the level. Creating so many trees will take a long time. But they are all the same! That is, we load from the hard drive over and over again and create copies of the same thing in memory. Loaded. Let's play. Before rendering each tree, preparatory procedures are performed. For each tree they will be the same, but we will call them again big number times the number of trees! It turns out wasteful. And memory for each tree must be reserved, and processing each of them takes time.
I wish I could load one single tree, and when I need to display the rest of the trees, just show graphics library, where to get the necessary data. What a saving in resources, what an increase in FPS! Such “false” trees (and not only trees - anything), about which only private information is stored in memory (position in space, rotation angles), and the same information is stored only once, are called proxy objects.
In GLScene there is a special class for creating proxy objects - TGLProxyObject. It's very easy to use. First, we create a source object, that is, a single tree, for example like this:
Tree:=TGLFreeFrom(glscene1.objects.AddNewChild(TGLFreeFrom));
//Load
its model:
Tree.LoadFromFile('Tree.3ds');
//Load its texture:
Tree.Material.Texture.Disabled:=false;
Tree.Material.Texture.Image,LoadFromFile('tree.jpg');
//Now let's create ten clone trees in random places:
for i:=1 to 10 do begin
//Create another proxy object
proxy:=TGLProxyObject(glscene1.objects.AddNewChild(TGLProxyObject));
with proxy do begin
//Write our sample tree to the MasterObject property
MasterObject:=Tree;
//Show that only the structure of the object should be inherited
ProxyOptions:=;
//The orientation of the tree in space must be left unchanged
Direction:= Tree.Direction;
Up:= Tree.Up;
//But we set the position random
Position.X:=Random(100);
Position.Y:=Random(100);
//And rotate the tree to a random angle to make it look better
RollAngle:=Random(360);
end;
end;
Now we have a dozen trees for the price of one. Please note that if we change the original object in any way, this change will instantly affect all clone objects.

* * *
We talked about the first brick. In the following articles, we will give you a truckload of these bricks, from which you can build the 3D game engine of your dreams. Well, to make it easier for you, we are uploading the latest tested version on the compact GLScene.

A homemade engine can be made in several ways. Let's start the review with the bipolar or stepper version, which is an electric motor with a double pole without brushes. It has DC power, divides a full revolution into equal parts. To operate this device you will need a special controller. In addition, the design of the device includes a winding, magnetic elements, transmitters, signaling devices and a control unit with an instrument panel. The main purpose of the unit is to equip milling and grinding machines, as well as to ensure the operation of various household, industrial and transport mechanisms.

Motor types

A homemade engine can have several configurations. Among them:

  • Options with permanent magnet.
  • Combined synchronous model.
  • Variable motor.

The permanent magnet drive is equipped with a main element in the rotor part. The operation of such devices is based on the principle of attraction or repulsion between the stator and rotor of the device. This stepper motor is equipped with a rotor part made of iron. The principle of its operation is based on a fundamental basis, according to which the maximum permissible repulsion is produced with a minimum gap. This promotes the attraction of the rotor points to the stator poles. Combination devices combine both parameters.

Another option is two-phase stepper motors. The device has a simple design, can have two types of winding, and is easily installed in the required location.

Monopolar modifications

A homemade motor of this type consists of a single winding and a central magnetic tap that affects all phases. Each section of the winding is activated to provide a specific magnetic field. Since in such a circuit the pole is able to function without additional switching, switching the path and direction of the current has an elementary device. For a standard motor with average power, one transistor is enough, provided in the equipment of each winding. A typical two-phase motor circuit involves six wires on the output signal and three similar elements on the phase.

The unit microcontroller can be used to activate the transistor in an automatically determined sequence. In this case, the windings are connected by connecting the output wires and a permanent magnet. When the coil terminals interact, the shaft is blocked for rotation. The resistance value between the common wire and the end part of the coil is proportional to the same aspect between the ends of the wiring. In this regard, the length of the common wire is twice as long as the connecting half of the coil.

Bipolar options

A homemade stepper motor of this type is equipped with one phase winding. The flow of current into it is carried out in a turning manner using a magnetic pole, which causes the complication of the circuit. It usually aggregates with a connecting bridge. There are a couple of additional wires that are not common. When the signal from such a motor is mixed at higher frequencies, the friction efficiency of the system decreases.

Three-phase analogues with a narrow specialization are also being created. They are used in the design of CNC machine tools, as well as in some automotive applications. on-board computers and printers.

Design and principle of operation

When voltage is transmitted to the terminals, the motor brushes are driven into continuous rotation. The idle setting is unique because it converts incoming pulses to a predetermined position of the existing drive shaft.

Any pulse signal acts on the shaft at a specific angle. Such a gearbox is most effective if a series of magnetic teeth are placed around a central toothed iron rod or its equivalent. The electric magnets are activated by an external control circuit consisting of a micro-regulator. To start turning the motor shaft, one active electromagnet attracts the teeth of the wheel to its surface. When they are aligned with the leading element, they move slightly towards the next magnetic part.

In a stepper motor, the first magnet must be turned on, and the next element must be deactivated. As a result, the gear will begin to rotate, gradually aligning itself with the previous wheel. The process is repeated alternately the required number of times. Such revolutions are called “constant step”. The rotation speed of the motor can be determined by counting the number of steps for a complete revolution of the unit.

Connection

The connection of a mini-motor made by yourself is carried out according to a certain scheme. The main attention is paid to the number of drive wires, as well as the purpose of the device. Stepper motors can be equipped with 4, 5, 6 or 8 wires. The modification with four wiring elements can be used exclusively with a bipolar device. Any phase winding has two wires. To determine the required connection length in a step-by-step mode, it is recommended to use a regular meter, which allows you to accurately set the required parameter.

The powerful six-wire motor has a pair of wires for each winding and a centering tap that can be connected to a mono or bipolar device. For aggregation with a single device, all six wires are used, and for a paired analogue, one end of the wire and the central tap of each winding will be sufficient.

with your own hands?

To create a basic motor you will need a piece of magnet, a drill, fluoroplastic, copper wire, a microchip, and a wire. Instead of a magnet, you can use an unnecessary cell phone vibration alert.

A drill is used as a rotation part, since the tool is optimally suited to the technical parameters. If the inner radius of the magnet does not match the similar aspect of the shaft, you can use copper wire, winding it in such a way as to remove the shaft play. This operation makes it possible to increase the diameter of the shaft at the point of connection with the rotor.

In the future creation of a homemade engine, you will need to make bushings from fluoroplastic. To do this, take the prepared sheet and make a hole with a diameter of 3 mm. Then construct the sleeve tube. The shaft must be ground to a diameter that allows free movement. This will avoid unnecessary friction.

Final stage

Next, the coils are wound. The frame of the required size is clamped in a yew. To wind 60 turns, you will need 0.9 meters of wire. After the procedure, the coil is treated with an adhesive composition. This delicate procedure is best carried out with a microscope or magnifying glass. After each double winding, a drop of glue is introduced between the sleeve and the wire. One edge of each winding is soldered together, which will make it possible to obtain a single unit with a pair of outputs that are soldered to the microchip.

Technical plan parameters

A DIY mini-engine, depending on its design features, may have various characteristics. Below are the parameters of the most popular step modifications:

  1. SD-1 - has a step of 15 degrees, has 4 phases and a torque of 40 Nt.
  2. DSh-0.04 A - step is 22.5 degrees, number of phases - 4, speed - 100 Nt.
  3. DSHI-200 - 1.8 degrees; 4 phases; 0.25 Nt torque.
  4. DSh-6 - 18/4/2300 (values ​​are indicated by analogy with the previous parameters).

Knowing how to make a motor at home, you need to remember that the speed of the torque indicator of the stepper motor will transform in direct proportion to the same current parameter. The reduction in linear torque at high speeds directly depends on the drive circuit and the inductance of the windings. Motors with degree of protection IP 65 are designed for harsh operating conditions. Compared to servers, stepper models work much longer and are more productive and do not require frequent repairs. However, servo motors have a slightly different focus, so comparing these types doesn't make much sense.

Making a homemade internal combustion engine

You can also make a motor with your own hands using liquid fuel. This does not require complex equipment or professional tools. The necessary one can be taken from a tractor or car fuel pump. The cylinder of the plunger sleeve is created by trimming the thickened element of the loop. Then you should make holes for the exhaust and bypass window, solder a couple of nuts in the upper part intended for the spark plugs. Element type - M-6. The piston is cut from the plunger.

A homemade diesel engine will require the installation of a crankcase. It is made of tin with soldered bearings. Additional strength will be created by a fabric coated with epoxy resin, which covers the element.

The crankshaft is assembled from a thick washer with a pair of holes. The shaft must be pressed into one of them, and the second outermost socket is used for mounting the stud with the connecting rod. The operation is also performed using the pressing method.

Final work on assembling a homemade diesel engine

Below is the procedure for assembling the ignition coil:

  • A part from a car or motorcycle is used.
  • A suitable spark plug is installed.
  • Insulators are installed, fixed with epoxy.

An alternative to a motor with an internal combustion engine system can be a contactless closed-type motor, the design and operating principle of which is a gas reverse exchange system. It is made of a two-section chamber, a piston, a crankshaft, a transmission box, and an ignition system. Knowing how to make an engine with your own hands, you can save a lot and get a necessary and useful item for your household.







2024 gtavrl.ru.