Vector and color types

Ethanon has special data types that describe some of the most commonly used elements in scripting: coordinates in space, sizes and colors.

Vector objects

The vector2 type can be used to describe a coordinate in a cartesian space, along its x and y axis. Its structure looks like this:

class vector2
{
    float x, y;
}

Example of usage:

vector2 a; // declares the coordinate a
a.x = 100.0f;
b.y = 200.0f;

or use the default constructor that automatically assigns x and y values:

vector2 a(100.0f, 200.0f); // the same as above

Our two-dimensional vector object is also often used to describe rectangular dimensions, where x describes the width and y describes the height:

vector2 entitySize = entity.GetSize();

There is also another vector object variant named vector3, which is equivalent to a vector2 except this one includes an extra float attribute named z:

class vector3
{
    float x, y, z;
}

vector3 is commonly used to describe entity coordinates in world space (more about entity world space). Example:

vector3 pos = entity.GetEntityPosition();
entity2.SetPosition(vector3(10.0f, 20.0f, 0.0f));

The vector3 object can also describe an RGB color value. Where x, y and z are treated as red, green and blue color channels respectively.

When used as a color value, vector3 attributes usually range between 0.0f and 1.0f, which is equivalent to a 0-255 range considering one byte per color channel:

vector3 red(1,0,0);
vector3 green(0,1,0);
vector3 blue(0,0,1);
vector3 brightGray(0.8f, 0.8f, 0.8f);
vector3 darkGray(0.2f, 0.2f, 0.2f);

Some Ethanon native functions and methods require color input as a vector3 color format, sometimes it asks for a raw 32-bit uint color value.

Describing 32-bit color values

It is also possible to describe color values as 32-bit data segments using the uint type. This color format uses 4 bytes, each byte for a specific color channel: Alpha, Red, Green and Blue. Where the alpha value describes a transparency level where 0 means completely invisible and 1 means full opacity.

uint color values are often represented in the hexadecimal format:

uint white = 0xFFFFFFFF;
uint black = 0xFF000000;
uint blue  = 0xFF0000FF;
uint semiTransparentRed = 0xCAFF0000;

The ARGB helper function provides automatic conversion from separate decimal values:

uint white = ARGB(255,255,255,255);
uint black = ARGB(255,0,0,0);
uint blue  = ARGB(255,0,0,255);
uint semiTransparentRed = ARGB(202,255,0,0);