TheOnlyWRT
Member
Hello!
So, working on an isometric terrain generation project, i have been trying to make it so that the user can click on one of the four corners of the tile, or in the center, in order to manipulate the tile. I am using the point_in_triangle function to detect the mouse location within the tile in order to manipulate the tile correctly. However, the point_in_triangle function only works sometimes, and once the tile has been manipulated a little, it just doesnt work at all....
There is an attached image that shows the triangles drawn on the tile (the two blue ones are for the center to make a rectangle/trapezoid in the center of the tile).
Below is the code to see if the mouse is within one of the corners:
Thanks for your help!!
So, working on an isometric terrain generation project, i have been trying to make it so that the user can click on one of the four corners of the tile, or in the center, in order to manipulate the tile. I am using the point_in_triangle function to detect the mouse location within the tile in order to manipulate the tile correctly. However, the point_in_triangle function only works sometimes, and once the tile has been manipulated a little, it just doesnt work at all....
There is an attached image that shows the triangles drawn on the tile (the two blue ones are for the center to make a rectangle/trapezoid in the center of the tile).
Below is the code to see if the mouse is within one of the corners:
Code:
if(point_in_triangle(mouse_x, mouse_y, topLeftX, topLeftY, bottomLeftX, bottomLeftY, bottomRightX, bottomRightY) || point_in_triangle(mouse_x, mouse_y, topLeftX, topLeftY, topRightX, topRightY, bottomRightX, bottomRightY)){
//the mouse is within the center rectangle of the tile
center = 1;
cornerLeft = 0;
cornerTop = 0;
cornerRight = 0;
cornerBottom = 0;
tileSprite = tileCenter;
} else if(point_in_triangle(mouse_x, mouse_y, topLeftX, topLeftY, topX, topY, topRightX, topRightY)){
//the mouse is within the top corner
cornerTop = 1;
cornerLeft = 0;
cornerRight = 0;
cornerBottom = 0;
center = 0;
tileSprite = tileTop;
} else if(point_in_triangle(mouse_x, mouse_y, rightTopX, rightTopY, rightX, rightY, rightBottomX, rightBottomY)){
//the mouse is within the right corner
cornerRight = 1;
cornerLeft = 0;
cornerTop = 0;
cornerBottom = 0;
center = 0;
tileSprite = tileRight;
} else if(point_in_triangle(mouse_x, mouse_y, bottomLeftX, bottomLeftY, bottomX, bottomY, bottomRightX, bottomRightY)){
//the mouse is within the bottom corner
cornerBottom = 1;
cornerLeft = 0;
cornerTop = 0;
cornerRight = 0;
center = 0;
tileSprite = tileBottom;
} else if(point_in_triangle(mouse_x, mouse_y, leftTopX, leftTopY, leftX, leftY, leftBottomX, leftBottomY)){
//the mouse is within the left corner
cornerLeft = 1;
cornerTop = 0;
cornerRight = 0;
cornerBottom = 0;
center = 0;
tileSprite = tileLeft;
} else {
cornerLeft = 0;
cornerTop = 0;
cornerRight = 0;
cornerBottom = 0;
center = 0;
tileSprite = tile;
}
Attachments
-
94 KB Views: 2