This little function will form a polygon/triangle between the three input vectors.
form_triangle(vector cor1,vector cor2,vector cor3)
{
///////////////////////////////////
//Open source polygon script /
//Made by Jontte Gremlin /
//DO NOT REMOVE THIS TAG /
///////////////////////////////
//
//This script will rotate and scale the prim so that it forms a triangle between the 3 corners
///////
if(llVecDist(cor2,cor3)>llVecDist(cor1,cor2)&&llVecDist(cor2,cor3)>llVecDist(cor1,cor3))
{
vector tempvec = cor3;
cor3=cor1;
cor1=tempvec;
}
if(llVecDist(cor1,cor3)>llVecDist(cor1,cor2)&&llVecDist(cor1,cor3)>llVecDist(cor2,cor3))
{
vector tempvec = cor3;
cor3=cor2;
cor2=tempvec;
}
//These parts are needed because the shear cant be less than -0.5 or more than 0.5, so it needs to rotate the corners before doing anything.
float height=llSin(llRot2Angle(llRotBetween(cor3-cor1,cor2-cor1)));//calculate the height of the polygon
height*=llVecDist(cor1,cor3);
float shear=llCos(llRot2Angle(llRotBetween(cor3-cor1,cor2-cor1)));//shear calculations
shear*=llVecDist(cor1,cor3);
shear=shear/llVecDist(cor1,cor2);
shear-=0.5;
vector percent=(cor1+(cor2-cor1)*(shear+0.5));//or3 on a line segment from cor1 to cor2
vector normal = llVecNorm(llVecNorm(cor2-cor1) % llVecNorm(cor3-cor1));//triangles normal (vector pointing outside of it)
rotation rot=llAxes2Rot(normal,llVecNorm(cor2-cor1),llVecNorm(cor3-percent));//rotation calculations
vector size=<0.01,llVecDist(cor1,cor2),height>;//size calculations, 0.01 is how thick the triangle will be
vector pos=(cor1+cor2)/2+<0,0,height/2>*rot;//position
if(size.x<0.01)size.x=0.01;//PRIM_SIZE will be ignored if one of these is less than 0.01
if(size.y<0.01)size.y=0.01;
if(size.z<0.01)size.z=0.01;
while(llVecDist(llGetPos(),pos)>5)llSetPos(pos);//move closer position ;). llSetPrimitiveParams will do the rest //you could change this to warpPos
llSetPrimitiveParams([PRIM_TYPE,PRIM_TYPE_BOX,0,<0,1,0>,0.0,<0,0,0>,<1,0,0>,<0,shear,0>,PRIM_ROTATION,rot,PRIM_POSITION,pos,PRIM_SIZE,size]);
//and finally use the variables calculated earlier
}
default
{
state_entry()
{
vector position = llGetPos();
form_triangle(position + <1,0,0>, position + <-1,0,0>, position + <0,0,1>);
}
}
I've made a dome rezzer and a wavefront obj 3D model loader using it, here are some snapshots: