Home
RabidHaMsTeR.org
R4 -- [ TUTORIAL - STARTER ]

Custom scenes in R4 are defined in a ".r4" file, in the R4\data\predefines directory. A Scene is made by joining together modules - the 'joints' are actually images, so if you join two texture modules to a snakecube module, you get a snakecube on the background of the first texture with the second texture on its sides.

The .r4 files contain information on how the modules are combined as well as some code in a C-style programming language that tells the modules how to react. In most cases modules will do things without any code (TEXTURE,MEDUSA,SNAKECUBE,etc) but you won't manage anything very exciting if you're not willing to specify what they do with a bit more detail.

A Simple Scene Open Notepad (NOT Wordpad, or Word) and copy and paste the following code into the window:
scene (
   "name" = "Medusa Example";
   "author" = "Your Name";
   SOLID black();
   TEXTURE img();
   MEDUSA med(black,img);
)

void reset() {
}

void init() { 
   // Load a texture
   strcpy(img.filename,"envmap_sky.jpg");
}

void render() {
	med.kick = sounda;
}
Now save the file to the R4\data\predefine directory as "mymedusa.r4". Ok, now for some explanation:
The "..." = "..." bits just insert values into r4's database about the scene. At the moment, only name and author are used, but "desc" for a short description could be used and if i add the feature later r4 will pick it up. The next bits, that have two names and some stuff (maybe) in brackets are module definitions. The first bit is the ID of the module that R4 should load, the second is what you want to call it, and the bits in brackets are the other modules that this module takes input from. The very last module in the list is the one that will be drawn by R4.

The next bits (void reset()...) are bits of code that get executed at different times. init() gets executed when the scene is first loaded, reset() gets called just before a scene is faded to, and render() is called just before every frame is rendered. If you put two slashes '\\' then the rest of that line is ignored by R4 - use it for putting comments in.

So all this example does is when the scene first loads, it uses 'strcpy' to copy the string of characters 'envmap_sky.jpg' to the TEXTURE module called 'img'. After all the code in init() has been executed, all the modules initialise, and TEXTURE loads the texture with the filename that was given. When every frame is rendered, the 'kick' parameter of the medusa is updated to the bass value of the sound - so bass causes the Medusa to spin around. So... if you start R4, and select the 'Medusa Example' scene (you can lock the scene so it doesn't change using the menu option) you should see the medusa on its own, with a blue texture. Thats your first, simple scene.

Now, quit R4, Open the file again, and change 'envmap_sky' to 'redblue_filaments'. This has changed the texture thats loaded. Now also go up to the top of the file and replace:
   SOLID black();
   TEXTURE img();
   MEDUSA med(black,img);
with:
   SOLID black();
   TEXTURE img();
   TUNNEL tun(black,img);
   MEDUSA med(tun,img);
Whats happened now is a tunnel is put in the background. If you save and start R4 you should see a purple tunnel, and the medusa ontop of it. The Medusa is only reflecting the texture though. If you change 'MEDUSA med(tun,img);' to 'MEDUSA med(tun,tun);' The medusa is now on the tunnel, reflecting it.
.
.
.
There isn't very much description in here, but you may well find looking at the other R4 scenes helps you out a lot. If you want R4 to start up on the scene you are working on, just move all the other .r4 files out of the predefine directory into some other directory.


site design by Gordon Williams