Code: Select all
import "ecere"
#define SIDES 3
class Triangle : Object
{
public:
bool Create(DisplaySystem displaySystem)
{
bool result = false;
if(this)
{
InitializeMesh(displaySystem);
if(mesh)
{
if(mesh.Allocate({ vertices = true, texCoords1 = true }, SIDES, displaySystem))
{
Vector3Df vertices[SIDES] =
{
//{1,0,0},
//{-1,0,0},
//{0,-1,0}
{ (float)size.x/2, 0, 0 },
{ -(float)size.x/2, 0, 0 },
{ 0, -(float)size.y/2, 0 }
};
uint16 indices[SIDES] = { 0, 2, 1};
CopyBytes(mesh.vertices, vertices, sizeof(vertices));
{
PrimitiveGroup group;
String name = "triangle";
Material material = displaySystem.AddNamedMaterial(name);
if(material)
{
material.flags = { noFog = true, doubleSided = true, translucent = true };
material.opacity = 0.5f;
material.diffuse.r = material.diffuse.g = material.diffuse.b = 1;
material.ambient = material.diffuse;
}
group = mesh.AddPrimitiveGroup(triStrip, SIDES);
if(group)
{
CopyBytes(group.indices, indices, sizeof(indices));
mesh.UnlockPrimitiveGroup(group);
group.material = material;
}
}
mesh.ComputeNormals();
result = true;
mesh.Unlock(0);
}
SetMinMaxRadius(true);
}
}
return result;
}
property Vector3Df size { set { size = value; } };
private:
Triangle()
{
size = { 1,1,0 };
}
Vector3Df size;
}