Difference between revisions of "Triangle Button"
Jump to navigation
Jump to search
(triangle button functions) |
m (added texture to match button) |
||
Line 26: | Line 26: | ||
default | default | ||
{ | { | ||
state_entry() | |||
{ | |||
llSetTexture("b2977bf6-b9af-c516-2e19-a5c451914227",ALL_SIDES); //Triangle texture to match buttons triangle. | |||
} | |||
touch_start(integer total_number) | touch_start(integer total_number) | ||
{ | { |
Revision as of 15:06, 27 August 2013
This is a function to tell if a point is within a 2d triangle. Code converted from http://www.blackpawn.com/texts/pointinpoly/to LSL by Richardjrn Weatherwax
<lsl> //Converted to LSL by Richardjrn Weatherwax from http://www.blackpawn.com/texts/pointinpoly/ //Done on request of Ezri Fairy (snow.gravois)
vector pointA = <0.17810, 0.36214, 0.00000>; vector pointB = <0.81144, 0.38803, 0.00000>; vector pointC = <0.50132, 0.71068, 0.00000>;
integer SameSide(vector p1, vector p2, vector a, vector b) {
vector cp1 = (b-a)%(p1-a); vector cp2 = (b-a)%(p2-a); if((cp1*cp2)>=0)return TRUE; else return FALSE;
}
integer PointInTriangle(vector p, vector a, vector b, vector c) {
if(SameSide(p,a, b,c)&&SameSide(p,b, a,c)&&SameSide(p,c, a,b))return TRUE; else return FALSE;
}
default {
state_entry() { llSetTexture("b2977bf6-b9af-c516-2e19-a5c451914227",ALL_SIDES); //Triangle texture to match buttons triangle. }
touch_start(integer total_number) { if(PointInTriangle(llDetectedTouchST(0),pointA,pointB,pointC))llOwnerSay("In the triangle"); else llOwnerSay("Outside the triangle"); }
} </lsl>