Jump to content

Tips&Tricks


photo

Recommended Posts

Swizzled access to the user defined functions return value:

 

vec3 foo() { return vec3(1.0f,2.0f,3.0f); }
printf("%f %f\n",foo().x,foo()[0]);
printf("%f %f\n",translate(1.0f,2.0f,3.0f).m23,translate(1.0f,2.0f,3.0f)[14]);

 

Class construction by literal name:

 

File file = new("File");
LightOmni light = new("LightOmni",vec4_one,vec3_one);

 

Call destructor for all array elements and clear array:

 

Foo array[] = ( new Foo(), new Foo() );
array.delete();

 

Add element into the vector after specified position:

 

int array[] = ( 0,1 );
array.append(1,13);			// 0,13,1
array.append(3,13);			// 0,13,1,13

 

Manual casting of classes:

 

class Foo {
   void foo() { }
};
int foo = new Foo();
Foo(foo).foo();				// manually set of class type
//foo.foo();				// compilation error

 

Variable number of call() function arguments:

 

int args[] = ("%s\n","hello world");
call("printf",args);			// prints "hello world"

 

Automatic memory management for extern classes:

 

File file = class_manage(new File());
file = 0;				// deletes file because of zero class references

 

Check class type:

 

File file = new File();
is_base_class("File",file);		// returns 1 because File is File
is_base_class("Stream",file);		// returns 1 because Stream is a base class for File
is_base_class("Socket",file);		// returns 0 because Socket is not a base class for File

 

Extended swizzlers:

 

vec4 v = vec4(10.0f,11.0f,12.0f,13.0f);
printf("%s\n",typeinfo(v.xyzw));	// prints "10 11 12 13"
printf("%s\n",typeinfo(v.10zw));	// prints "1 0 12 13"
printf("%s\n",typeinfo(v.xy10));	// prints "10 11 1 0"

  • Like 2
Link to comment

To call base class parametrized constructor use fllowing constuct:

class Foo // base class
{
Foo(vec3 vec)
{
..
}
};

class Bar : Foo // derived class
{
Bar(vec3 vec)
{
	__Foo__(vec);
..
}
};

Link to comment
×
×
  • Create New...