NOTICE: Account creation on the wiki has been temporarily disabled until the wiki is moved to OpenID. If you need an account before then, please request one here: http://forum.xbmc.org/showthread.php?tid=165868

Vortex Visualization Development

From XBMC
Jump to: navigation, search

Vortex Visualization Development


Contents

1 Coding your own presets and transitions for Vortex

1.1 The filetypes

1.2 The template

<python>//filename - TheTransitionOrPresetFilename.Extension //author - your name void Init() {

 //TODO: put your initializationcode here

}

void Render() {

 //TODO: put your stunning graphics here

}</python>

1.3 The coding

If you did some coding before, go on reading. If not, get your self some knowledge with coding c/c++ and return after that.

1.3.1 The datatypes

1.3.2 The operators and math-functions

Boolean operators

1.3.3 The built-in VORTEX-variables

1.3.4 The built-in VORTEX-constants

1.3.4.1 Blendmodes
1.3.4.2 PrimitiveTypes
1.3.4.3 Fillmodes
1.3.4.4 StandardTextures

1.3.5 The built-in VORTEX-functions

1.3.6 The built-in VORTEX-functions for graphics

1.3.7 The MAP-Datatype

Maps are some special kind of textures. If you use them like textures without any special handling, then all youll get is some black texture. But if you render something to them using the gfxSetRenderTarget-Method you can do some very cool and unique effects.

The map has always a dimension of 32x24!

Now the Step-By-Step-Guide to Maps:

<php> for (int y = 0; y < 24; y++) {

 for (int x = 0; x < 32; x++)
 {
   map.SetValues(x, y, speedX, speedY, attR, attG, attB);
 }  	

} </php> Here we used the SetValues-method of the map datatype. This function is where all the magic happens.

The x and y values only specify the position for the following values.

The speedX and speedY values move the pixel inside the map. if you set all speedX and speedY you'll get 24x32 little icons of what you rendered to the map. if you set them to 0 you see everything you rendered in the last frames on the texture too. So for example to move the last frames slowly to the top you have to set the speedX to 0 (you want no motion along the x axis) and the speed Y to some value other than 0.

The attR, attG, attB values specify how the color of the pixels change over time. For each basecolor you can specify how strong its filtering should be. If set to 0 the basecolor is filtered out, if 1 the basecolor will not be touched.

<php>map.Render();</php> Here the values you applied to the map will be used to transform the previous data in the map.

<php>gfxSetRenderTarget(map);</php>

<php>RenderSomeCoolGraphicsHere();</php>

<php>gfxSetRenderTarget(NULL);</php>

Now you can do something with the map. For example you can just put it on a rectangle and render it to screen.

2 The graphics basics

2.1 The coordinatesystem

The coordinate system used by vortex is a left handed coordinate system. This mean that the x-axis points in the same direction as your screens horizontal edges (from left to right), the y-axis points up and the z-axis point into the screen. The origin of this coordinate system is right in the center of your screen (if no transformation is added to the view matrix)

The texture coordinates have their origin in the top-left corner of the texture. tu points from left to right, tv from top to bottom.

2.2 The matrix transformations

Initially when you didnt apply any transformations the transformation matrix is the identity. This matrix leaves the vertices at their specified position. To get some cool motion into your preset you have to apply some transformation to the matrix. If you want to apply multiple transformations, you have to mind the order in which you apply the transformations: e.g: you want to rotate an object around itself and put further away into the screenspace. so you have to apply the rotation before the translation. in your code it looks like this:

<python> gfxTranslate(0,0,5); // this is the second transformation, it pushes the object into your screen gfxRotate(angle, 1,0,0); // this is the first transformation applied to the object, it rotates the object around the x-axis RenderSomeCoolObjectAtOrigin(); // the initial Object is rendered around the origin </python>

If you look at this code, then you notice, that the order of appliance to exactly the opposite of the appearance order in the code. So the later in the code, the earlier applied on the object.

To store some transformation for returning to it on a later renderingstep, you can use the gfxPushMatrix()-method. This methos pushes the matrix on a stack. I f you want to return to this matrix, then you can pop it off the stack. Remember that only the topmost matrix is popped off the stack. So if you push two matrices on the stack, and you want to return to the first pushed matrix, then you have to pop twice.

<python> gfxTranslate(0,0,5); // this is the second transformation, it pushes the object into your screen gfxPushMatrix(); // this stores the matrix on the stack gfxRotate(angle, 1,0,0); // this is the first transformation applied to the object, it rotates the object around the x-axis RenderSomeCoolObjectAtOrigin(); // the initial Object is rendered around the origin gfxPopMatrix(); // this gets the topmost matrix from the stack RenderSomeCoolObjectAtOrigin(); // the initial Object is rendered around the origin </python>

the result of this snippet are two objects: the first is rotated and translated, the second is only translated. |}

3 The examples

3.1 The preset

This is an example for a simple preset. it rotates some albumart-textured cube around itself (the rotation is defined by the music). The code for this example is written by MrC (I only put in the comments). <python> // AlbumArtCube.vtx // Author - MrC

float time = 0; float rx,rxamt,ry,ryamt;

void Render() {

 // time stores the the elapsed time since the preset started
 time += TIMEPASS;                                     
 // set the coverart of the current song as texture
 gfxSetTexture(TEXTURE_ALBUMART);  
 // push the object into the screen. the distance is calculated from the current TREBLE-value                    
 gfxTranslate(0, 0, 2.0f - (TREBLE * 0.5));            
 // change the rotation-direction for rotations around the x axis according to the BASS-value
 if (BASS>0.3) rxamt = 1;                              
 if (BASS<-0.3) rxamt = -1;
 // change the rotation-direction for rotations around the y axis according to the TREBLE-value
 if (TREBLE>0.3) ryamt = 1;                            
 if (TREBLE<-0.3) ryamt = -1;
 //calculate the current rotation angle from direction and elapsed time
 rx = rx + (rxamt*TIMEPASS);
 ry = ry + (ryamt*TIMEPASS);
 //add some continuous rotation to the preset
 gfxRotate(-70+(Sin(time)*12),1,0,0);
 // rotate around x-axis. Because of the previous rotation around y you have to put the z axis in here
 gfxRotate(rx*90,0,0,1);
 // this is the first transformation. it rotates around the y axis
 gfxRotate(ry*90,0,1,0);
 // set some color here
 gfxColour(1, 1, 1, 1);
 // render a cube textured with the previously definded texture, the albumart
 gfxCube(-0.25f, -0.25f, -0.25f, 0.25f, 0.25f, 0.25f);

} </python>

3.2 The transition

This transition slides in the new preset. (Code: MrC)

The only difference between presets and transitions is that you have to specify when the transition is over by using the FINISHED variable. <python> // Slide.tra // Author - MrC

int direction; float position;

// here we initialize some variables void Init() { position = 0;

// the direction is randomly chosen direction = Rand() * 4; }

void Render() {

 // calculate the new position from the elapsed time

position += TIMEPASS*0.75;

// end the transition if the position is greater or equal to 1

 if (position >= 1.0f)
 FINISHED = true;
 // set the current preset as texture
 gfxSetTexture(TEXTURE_CURRPRESET);
 gfxSetAspect(0);
 // translate the rectangle (rendered below) to the magic position of 2.414. 
 // If you translate some rectangle with size -1,1,1,-1 by 2.414 into screen 
 // the result is exactly as big as the screen, so you will see no difference 
 // between the previously rendered preset and the transition, that renders the
 // preset on a rectangle.
 gfxTranslate(0, 0, 2.414);
 gfxColour(1, 1, 1, 1);
 gfxTexRect(-1, 1, 1, -1);
  
 // set the next preset as texture
 gfxSetTexture(TEXTURE_NEXTPRESET);
 // choose direction

if (direction == 0) { // Top to bottom float i = -3 + position * 2;

// draws a rectangle initially out of screen and by time it slides down. gfxTexRect(-1, i+2, 1, i); }

// same as above but other direction else if (direction == 1) { // Bottom to top float i = 1 - (position * 2); gfxTexRect(-1, i+2, 1, i); } else if (direction == 2) { // Left to right float i = -3 + position * 2; gfxTexRect(i, 1, i+2, -1); } else { // Right to left float i = 1 - position * 2; gfxTexRect(i, 1, i+2, -1); }

} </python>

Personal tools
Namespaces
Variants
Actions
Navigation
Wiki help
Google Search
Toolbox